]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
qa: replace subvolume.sh with test_subvolume.py 45556/head
authorMilind Changire <mchangir@redhat.com>
Sun, 10 Apr 2022 16:05:23 +0000 (21:35 +0530)
committerMilind Changire <mchangir@redhat.com>
Sun, 10 Apr 2022 16:05:23 +0000 (21:35 +0530)
qa/workunits/fs/misc/subvolume.sh is getting in the way of fs:workload
testing with subvolumes. Hence moved this script to a python test.

Signed-off-by: Milind Changire <mchangir@redhat.com>
qa/suites/fs/volumes/tasks/volumes/test/basic.yaml
qa/tasks/cephfs/test_subvolume.py [new file with mode: 0644]
qa/workunits/fs/misc/subvolume.sh [deleted file]

index 3e54df2a9bb8d499f02cc2be4471f3609aca854b..b4c65cfc58ffb3a2564af572c49f86a737630794 100644 (file)
@@ -5,3 +5,4 @@ tasks:
         - tasks.cephfs.test_volumes.TestVolumes
         - tasks.cephfs.test_volumes.TestSubvolumeGroups
         - tasks.cephfs.test_volumes.TestSubvolumes
+        - tasks.cephfs.test_subvolume.TestSubvolume
diff --git a/qa/tasks/cephfs/test_subvolume.py b/qa/tasks/cephfs/test_subvolume.py
new file mode 100644 (file)
index 0000000..1ebb137
--- /dev/null
@@ -0,0 +1,170 @@
+import logging
+
+from tasks.cephfs.cephfs_test_case import CephFSTestCase
+from teuthology.exceptions import CommandFailedError
+
+log = logging.getLogger(__name__)
+
+
+class TestSubvolume(CephFSTestCase):
+    CLIENTS_REQUIRED = 1
+    MDSS_REQUIRED = 1
+
+    def setUp(self):
+        super().setUp()
+        self.setup_test()
+
+    def tearDown(self):
+        # clean up
+        self.cleanup_test()
+        super().tearDown()
+
+    def setup_test(self):
+        self.mount_a.run_shell(['mkdir', 'group'])
+        self.mount_a.run_shell(['mkdir', 'group/subvol1'])
+        self.mount_a.run_shell(['setfattr', '-n', 'ceph.dir.subvolume',
+                                '-v', '1', 'group/subvol1'])
+        self.mount_a.run_shell(['mv', 'group/subvol1', 'group/subvol2'])
+
+    def cleanup_test(self):
+        self.mount_a.run_shell(['rm', '-rf', 'group'])
+
+    def test_subvolume_move_out_file(self):
+        """
+        To verify that file can't be moved out of subvolume
+        """
+        self.mount_a.run_shell(['touch', 'group/subvol2/file1'])
+
+        # file can't be moved out of a subvolume
+        with self.assertRaises(CommandFailedError):
+            self.mount_a.run_shell(['rename', 'group/subvol2/file1',
+                                    'group/file1', 'group/subvol2/file1'])
+
+
+    def test_subvolume_move_in_file(self):
+        """
+        To verify that file can't be moved into subvolume
+        """
+        # file can't be moved into a subvolume
+        self.mount_a.run_shell(['touch', 'group/file2'])
+        with self.assertRaises(CommandFailedError):
+            self.mount_a.run_shell(['rename', 'group/file2',
+                                    'group/subvol2/file2', 'group/file2'])
+
+    def test_subvolume_hardlink_to_outside(self):
+        """
+        To verify that file can't be hardlinked to outside subvolume
+        """
+        self.mount_a.run_shell(['touch', 'group/subvol2/file1'])
+
+        # create hard link within subvolume
+        self.mount_a.run_shell(['ln',
+                                'group/subvol2/file1', 'group/subvol2/file1_'])
+
+        # hard link can't be created out of subvolume
+        with self.assertRaises(CommandFailedError):
+            self.mount_a.run_shell(['ln',
+                                    'group/subvol2/file1', 'group/file1_'])
+
+    def test_subvolume_hardlink_to_inside(self):
+        """
+        To verify that file can't be hardlinked to inside subvolume
+        """
+        self.mount_a.run_shell(['touch', 'group/subvol2/file1'])
+
+        # create hard link within subvolume
+        self.mount_a.run_shell(['ln',
+                                'group/subvol2/file1', 'group/subvol2/file1_'])
+
+        # hard link can't be created inside subvolume
+        self.mount_a.run_shell(['touch', 'group/file2'])
+        with self.assertRaises(CommandFailedError):
+            self.mount_a.run_shell(['ln',
+                                    'group/file2', 'group/subvol2/file2_'])
+
+    def test_subvolume_snapshot_inside_subvolume_subdir(self):
+        """
+        To verify that snapshot can't be taken for a subvolume subdir
+        """
+        self.mount_a.run_shell(['touch', 'group/subvol2/file1'])
+
+        # create snapshot at subvolume root
+        self.mount_a.run_shell(['mkdir', 'group/subvol2/.snap/s1'])
+
+        # can't create snapshot in a descendent dir of subvolume
+        self.mount_a.run_shell(['mkdir', 'group/subvol2/dir'])
+        with self.assertRaises(CommandFailedError):
+            self.mount_a.run_shell(['mkdir', 'group/subvol2/dir/.snap/s2'])
+
+        # clean up
+        self.mount_a.run_shell(['rmdir', 'group/subvol2/.snap/s1'])
+
+    def test_subvolume_file_move_across_subvolumes(self):
+        """
+        To verify that file can't be moved across subvolumes
+        """
+        self.mount_a.run_shell(['touch', 'group/subvol2/file1'])
+
+        # create another subvol
+        self.mount_a.run_shell(['mkdir', 'group/subvol3'])
+        self.mount_a.run_shell(['setfattr', '-n', 'ceph.dir.subvolume',
+                                '-v', '1', 'group/subvol3'])
+
+        # can't move file across subvolumes
+        with self.assertRaises(CommandFailedError):
+            self.mount_a.run_shell(['rename', 'group/subvol2/file1',
+                                    'group/subvol3/file1',
+                                    'group/subvol2/file1'])
+
+    def test_subvolume_hardlink_across_subvolumes(self):
+        """
+        To verify that hardlink can't be created across subvolumes
+        """
+        self.mount_a.run_shell(['touch', 'group/subvol2/file1'])
+
+        # create another subvol
+        self.mount_a.run_shell(['mkdir', 'group/subvol3'])
+        self.mount_a.run_shell(['setfattr', '-n', 'ceph.dir.subvolume',
+                                '-v', '1', 'group/subvol3'])
+
+        # can't create hard link across subvolumes
+        with self.assertRaises(CommandFailedError):
+            self.mount_a.run_shell(['ln', 'group/subvol2/file1',
+                                    'group/subvol3/file1'])
+
+    def test_subvolume_create_subvolume_inside_subvolume(self):
+        """
+        To verify that subvolume can't be created inside a subvolume
+        """
+        # can't create subvolume inside a subvolume
+        self.mount_a.run_shell(['mkdir', 'group/subvol2/dir'])
+        with self.assertRaises(CommandFailedError):
+            self.mount_a.run_shell(['setfattr', '-n', 'ceph.dir.subvolume',
+                                    '-v', '1', 'group/subvol2/dir'])
+
+    def test_subvolume_create_snapshot_inside_new_subvolume_parent(self):
+        """
+        To verify that subvolume can't be created inside a new subvolume parent
+        """
+        self.mount_a.run_shell(['touch', 'group/subvol2/file1'])
+
+        # clear subvolume flag
+        self.mount_a.run_shell(['setfattr', '-n', 'ceph.dir.subvolume',
+                                '-v', '0', 'group/subvol2'])
+
+        # create a snap
+        self.mount_a.run_shell(['mkdir', 'group/subvol2/dir'])
+        self.mount_a.run_shell(['mkdir', 'group/subvol2/dir/.snap/s2'])
+
+        # override subdir subvolume with parent subvolume
+        self.mount_a.run_shell(['setfattr', '-n', 'ceph.dir.subvolume',
+                                '-v', '1', 'group/subvol2/dir'])
+        self.mount_a.run_shell(['setfattr', '-n', 'ceph.dir.subvolume',
+                                '-v', '1', 'group/subvol2'])
+
+        # can't create a snap in a subdir of a subvol parent
+        with self.assertRaises(CommandFailedError):
+            self.mount_a.run_shell(['mkdir', 'group/subvol2/dir/.snap/s3'])
+
+        # clean up
+        self.mount_a.run_shell(['rmdir', 'group/subvol2/dir/.snap/s2'])
diff --git a/qa/workunits/fs/misc/subvolume.sh b/qa/workunits/fs/misc/subvolume.sh
deleted file mode 100755 (executable)
index 75716a6..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/bin/sh -x
-
-expect_failure() {
-       if "$@"; then return 1; else return 0; fi
-}
-
-set -e
-
-mkdir group
-mkdir group/subvol1
-
-setfattr -n ceph.dir.subvolume -v 1 group/subvol1
-
-# rename subvolume
-mv group/subvol1 group/subvol2
-
-# move file out of the subvolume
-touch group/subvol2/file1
-expect_failure python3 -c "import os; os.rename('group/subvol2/file1', 'group/file1')"
-# move file into the subvolume
-touch group/file2
-expect_failure python3 -c "import os; os.rename('group/file2', 'group/subvol2/file2')"
-
-# create hardlink within subvolume
-ln group/subvol2/file1 group/subvol2/file1_
-
-# create hardlink out of subvolume
-expect_failure ln group/subvol2/file1  group/file1_
-expect_failure ln group/file2 group/subvol1/file2_
-
-# create snapshot at subvolume root
-mkdir group/subvol2/.snap/s1
-
-# create snapshot at descendent dir of subvolume
-mkdir group/subvol2/dir
-expect_failure mkdir group/subvol2/dir/.snap/s2
-
-mkdir group/subvol3
-setfattr -n ceph.dir.subvolume -v 1 group/subvol3
-
-# move file across subvolumes
-expect_failure python3 -c "import os; os.rename('group/subvol2/file1', 'group/subvol3/file1')"
-
-# create hardlink across subvolumes
-expect_failure ln group/subvol2/file1 group/subvol3/file1
-
-# create subvolume inside existing subvolume
-expect_failure setfattr -n ceph.dir.subvolume -v 1 group/subvol2/dir
-
-# clear subvolume flag
-setfattr -n ceph.dir.subvolume -v 0 group/subvol2
-mkdir group/subvol2/dir/.snap/s2
-
-# parent subvolume override child subvolume
-setfattr -n ceph.dir.subvolume -v 1 group/subvol2/dir
-setfattr -n ceph.dir.subvolume -v 1 group/subvol2
-expect_failure mkdir group/subvol2/dir/.snap/s3
-
-rmdir group/subvol2/.snap/s1
-rmdir group/subvol2/dir/.snap/s2
-rm -rf group
-
-echo OK