From 9b0a9bd9d6f9c78b9983cbdd2a0c045e99980766 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 10 Jun 2021 20:10:06 +0800 Subject: [PATCH] tasks/ceph_manager: use safe_while() to refactor the wait for quorum for better readability Signed-off-by: Kefu Chai (cherry picked from commit 3908c1f4cd0ebbfdcaae2d9e6de5c1609523cc55) --- qa/tasks/ceph_manager.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/qa/tasks/ceph_manager.py b/qa/tasks/ceph_manager.py index 3e1a2ec51eab9..b212278ff8499 100644 --- a/qa/tasks/ceph_manager.py +++ b/qa/tasks/ceph_manager.py @@ -2560,13 +2560,13 @@ class CephManager: Loop until quorum size is reached. """ self.log('waiting for quorum size %d' % size) - start = time.time() - while not len(self.get_mon_quorum()) == size: - if timeout is not None: - assert time.time() - start < timeout, \ - ('failed to reach quorum size %d ' - 'before timeout expired' % size) - time.sleep(3) + sleep = 3 + with safe_while(sleep=sleep, + tries=timeout // sleep, + action=f'wait for quorum size {size}') as proceed: + while proceed(): + if len(self.get_mon_quorum()) == size: + break self.log("quorum is size %d" % size) def get_mon_health(self, debug=False): -- 2.39.5