From: Kefu Chai Date: Wed, 19 Apr 2017 08:13:18 +0000 (+0800) Subject: qa/tasks/ceph_manager: add a "wait_for_pg_stats()" decorator X-Git-Tag: v12.0.2~7^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1207caf3a20012d46f4494ccbbd219f7cee10b53;p=ceph.git qa/tasks/ceph_manager: add a "wait_for_pg_stats()" decorator and accompany it with two helpers to access the pg stats in a more natural way Signed-off-by: Kefu Chai --- diff --git a/qa/tasks/ceph_manager.py b/qa/tasks/ceph_manager.py index 8ff2556a7a0e..2d963e2cc3e2 100644 --- a/qa/tasks/ceph_manager.py +++ b/qa/tasks/ceph_manager.py @@ -1305,6 +1305,23 @@ class CephManager: return int(pg['acting'][-1]) assert False + def wait_for_pg_stats(func): + # both osd_mon_report_interval_min and mgr_stats_period are 5 seconds + # by default, and take the faulty injection in ms into consideration, + # 12 seconds are more than enough + delays = [1, 1, 2, 3, 5, 8, 13] + @wraps(func) + def wrapper(self, *args, **kwargs): + exc = None + for delay in delays: + try: + return func(self, *args, **kwargs) + except AssertionError as e: + time.sleep(delay) + exc = e + raise exc + return wrapper + def get_pg_primary(self, pool, pgnum): """ get primary for pool, pgnum (e.g. (data, 0)->0 @@ -1723,6 +1740,18 @@ class CephManager: stats = self.get_single_pg_stats(pgstr) return 'inconsistent' in stats['state'] + @wait_for_pg_stats + def with_pg_state(self, pool, pgnum, check): + pgstr = self.get_pgid(pool, pgnum) + stats = self.get_single_pg_stats(pgstr) + assert(check(stats['state'])) + + @wait_for_pg_stats + def with_pg(self, pool, pgnum, check): + pgstr = self.get_pgid(pool, pgnum) + stats = self.get_single_pg_stats(pgstr) + return check(stats) + def get_last_scrub_stamp(self, pool, pgnum): """ Get the timestamp of the last scrub.