]> git.apps.os.sepia.ceph.com Git - ceph-ci.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>
Thu, 4 Apr 2024 11:39:42 +0000 (17:09 +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>
(cherry picked from commit e8bdf94b814eb09f859e6d1e31d53e826a7bffcc)

Conflicts:
  qa/tasks/cephfs/caps_helper.py
  - Conflict occured because code on Reef branch changed due to merging of
    commit 59c9104c54d6.

qa/tasks/cephfs/caps_helper.py

index d8a2d8f67c4240335f12a649f85201ca9baf81b5..37ea6c4fbd9733b793d64fea29fa85295b227caa 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
 
@@ -113,7 +112,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.
 
@@ -229,14 +244,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):
         """
@@ -267,7 +283,7 @@ class CapTester(CephFSTestCase):
             log.info(f'test read perm: read file {path} and expect data '
                      f'"{data}"')
             contents = mount.read_file(path, sudo_read)
-            self.assertEqual(data, contents)
+            assert_equal(data, contents)
             log.info(f'read perm was tested successfully: "{data}" was '
                      f'successfully read from path {path}')
 
@@ -277,7 +293,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}".')