]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/cephfs: don't inherit CephFSTestCase in CapTester
authorRishabh Dave <ridave@redhat.com>
Thu, 13 Apr 2023 19:08:33 +0000 (00:38 +0530)
committerRishabh Dave <ridave@redhat.com>
Tue, 18 Apr 2023 14:04:40 +0000 (19:34 +0530)
Inheritting CephFSTestCase in CapTester just for methods assertEqual()
and assertIn() from class unittest.TestCase is odd and heavy-weight.
Don't inherit CephFSTestCase and use simple assert instead.

Reference: https://github.com/ceph/ceph/pull/50882#discussion_r1160611549.

To avoid code duplication, a couple of similar methods have been added
instead.

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

index 5519786876da44b93a3d47d0fbd88294cbd112ca..8f42da0626488b124fa94fb1f672cfc03e576081 100644 (file)
@@ -3,8 +3,7 @@ Helper methods to test that MON and MDS caps are enforced properly.
 """
 from os.path import join as os_path_join
 from logging import getLogger
-
-from tasks.cephfs.cephfs_test_case import CephFSTestCase
+from textwrap import dedent
 
 from teuthology.orchestra.run import Raw
 
@@ -89,7 +88,23 @@ def gen_mds_cap_str(caps):
     return mds_cap
 
 
-class CapTester(CephFSTestCase):
+def assert_equal(first, second):
+    msg = f'Variables are not equal.\nfirst = {first}\nsecond = {second}'
+    assert first == second, msg
+
+
+def assert_in(member, container):
+    msg = dedent(f'''
+        First value is absent in second value.
+        First value -
+        {member}
+        Second value -
+        {container}
+        ''')
+    assert member in container, msg
+
+
+class CapTester:
     """
     Test that MON and MDS caps are enforced.
 
@@ -205,14 +220,15 @@ class CapTester(CephFSTestCase):
             fsls_admin = get_cluster_cmd_op(args='fs ls')
             log.info('output of fs ls cmd run by admin -\n{fsls_admin}')
 
-            self.assertEqual(fsls, fsls_admin)
+            assert_equal(fsls, fsls_admin)
             return
 
         log.info('FS names are mentioned in moncap. moncap -\n{moncap}')
         log.info('testing for presence of these FS names in output of '
                  '"fs ls" command run by client.')
         for fsname in self._get_fsnames_from_moncap(moncap):
-            self.assertIn('name: ' + fsname, fsls)
+            fsname_cap_str = f'name: {fsname}'
+            assert_in(fsname_cap_str, fsls)
 
     def run_mds_cap_tests(self, perm, mntpt=None):
         """
@@ -243,7 +259,7 @@ class CapTester(CephFSTestCase):
             log.info(f'test read perm: read file {path} and expect data '
                      f'"{data}"')
             contents = mount.read_file(path)
-            self.assertEqual(data, contents)
+            assert_equal(data, contents)
             log.info(f'read perm was tested successfully: "{data}" was '
                      f'successfully read from path {path}')
 
@@ -253,7 +269,7 @@ class CapTester(CephFSTestCase):
                      f'file {path}.')
             mount.write_file(path=path, data=data)
             contents = mount.read_file(path=path)
-            self.assertEqual(data, contents)
+            assert_equal(data, contents)
             log.info(f'write perm was tested was successfully: data '
                      f'"{data}" was successfully written to file "{path}".')