]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/cephfs: add a helper method in caps_helper.py
authorRishabh Dave <ridave@redhat.com>
Thu, 28 Apr 2022 07:31:42 +0000 (13:01 +0530)
committerRishabh Dave <ridave@redhat.com>
Thu, 21 Jul 2022 12:23:16 +0000 (17:53 +0530)
This helper method prevents repeating code to write test files in
test methods for caps.

Signed-off-by: Rishabh Dave <ridave@redhat.com>
qa/tasks/cephfs/caps_helper.py

index 48eae3bdab970e274d703ee920abe0a651ec7961..c26a2e5108d49bf55f93a0fd2bcc6a8b9bbdd431 100644 (file)
@@ -1,12 +1,40 @@
 """
 Helper methods to test that MON and MDS caps are enforced properly.
 """
+from os.path import join as os_path_join
+
 from tasks.cephfs.cephfs_test_case import CephFSTestCase
 
 from teuthology.orchestra.run import Raw
 
 class CapsHelper(CephFSTestCase):
 
+    def write_test_files(self, mounts):
+        """
+        Exercising 'r' and 'w' access levels on a file on CephFS mount is
+        pretty routine across all tests for caps. Adding to method to write
+        that file will reduce clutter in these tests.
+
+        This methods writes a fixed data in a file with a fixed name located
+        at a fixed path for given list of mounts.
+        """
+        filepaths, filedata = [], 'testdata'
+        dirname, filename = 'testdir', 'testfile'
+
+        for mount_x in mounts:
+            dirpath = os_path_join(mount_x.hostfs_mntpt, dirname)
+            mount_x.run_shell(f'mkdir {dirpath}')
+            filepath = os_path_join(dirpath, filename)
+            mount_x.write_file(filepath, filedata)
+            filepaths.append(filepath)
+
+        return filepaths, (filedata,), mounts
+
+    def run_cap_tests(self, filepaths, filedata, mounts, perm):
+        # TODO
+        #self.run_mon_cap_tests()
+        self.run_mds_cap_tests(filepaths, filedata, mounts, perm)
+
     def run_mon_cap_tests(self, moncap, keyring):
         keyring_path = self.fs.admin_remote.mktemp(data=keyring)