]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/cephfs: use safe_while in test_volumes.py
authorRishabh Dave <ridave@redhat.com>
Sat, 20 Apr 2024 05:36:45 +0000 (11:06 +0530)
committerRishabh Dave <ridave@redhat.com>
Wed, 14 Aug 2024 09:35:46 +0000 (15:05 +0530)
Signed-off-by: Rishabh Dave <ridave@redhat.com>
qa/tasks/cephfs/test_volumes.py

index 56410b3a08199dea0a9d421c66febc0ba99e71e9..ef33e96e21b82cd8d92609350bbb013bb3144027 100644 (file)
@@ -13,6 +13,7 @@ from io import StringIO
 
 from tasks.cephfs.cephfs_test_case import CephFSTestCase
 from tasks.cephfs.fuse_mount import FuseMount
+from teuthology.contextutil import safe_while
 from teuthology.exceptions import CommandFailedError
 
 log = logging.getLogger(__name__)
@@ -39,18 +40,22 @@ class TestVolumesHelper(CephFSTestCase):
         if isinstance(states, str):
             states = (states, )
 
-        check = 0
         args = ["clone", "status", self.volname, clone]
         if clone_group:
             args.append(clone_group)
         args = tuple(args)
-        while check < timo:
-            result = json.loads(self._fs_cmd(*args))
-            if result["status"]["state"] in states:
-                break
-            check += 1
-            time.sleep(1)
-        self.assertTrue(check < timo)
+
+        msg = (f'Executed cmd "{args}" {timo} times; clone was never in '
+               f'"{states}" state(s).')
+
+        with safe_while(tries=timo, sleep=1, action=msg) as proceed:
+            while proceed():
+                result = json.loads(self._fs_cmd(*args))
+                current_state = result["status"]["state"]
+
+                log.info(f'current clone state = {current_state}')
+                if current_state in states:
+                    return
 
     def _get_clone_status(self, clone, clone_group=None):
         args = ["clone", "status", self.volname, clone]