From: Kefu Chai Date: Thu, 30 Apr 2020 10:07:00 +0000 (+0800) Subject: qa/tasks: use list comprehension for checking the length X-Git-Tag: v14.2.10~17^2~19 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=daed5c826fb07ebb735c6d273b73a469f9e10b5e;p=ceph.git qa/tasks: use list comprehension for checking the length instead of using filter(), use `sum()` for counting its length, as in Python3, `filter()` actually returns a `filter` object instead of a list. in this change, `filter()` calls are replaced with `sum()` for Python3 compatibility. Signed-off-by: Kyr Shatskyy (cherry picked from commit 726c59be58473cfe53fa3ea63cf35b58ed797886) --- diff --git a/qa/tasks/mds_thrash.py b/qa/tasks/mds_thrash.py index 55d2565ecfda..f3a3962d20d4 100644 --- a/qa/tasks/mds_thrash.py +++ b/qa/tasks/mds_thrash.py @@ -291,10 +291,11 @@ class MDSThrasher(Greenlet): status = self.fs.status() max_mds = status.get_fsmap(self.fs.id)['mdsmap']['max_mds'] ranks = list(status.get_ranks(self.fs.id)) - stopping = filter(lambda info: "up:stopping" == info['state'], ranks) - actives = filter(lambda info: "up:active" == info['state'] and "laggy_since" not in info, ranks) + stopping = sum(1 for _ in ranks if "up:stopping" == _['state']) + actives = sum(1 for _ in ranks + if "up:active" == _['state'] and "laggy_since" not in _) - if not bool(self.config.get('thrash_while_stopping', False)) and len(stopping) > 0: + if not bool(self.config.get('thrash_while_stopping', False)) and stopping > 0: if itercount % 5 == 0: self.log('cluster is considered unstable while MDS are in up:stopping (!thrash_while_stopping)') else: @@ -306,13 +307,14 @@ class MDSThrasher(Greenlet): return status except: pass # no rank present - if len(actives) >= max_mds: + if actives >= max_mds: # no replacement can occur! - self.log("cluster has %d actives (max_mds is %d), no MDS can replace rank %d".format(len(actives), max_mds, rank)) + self.log("cluster has {actives} actives (max_mds is {max_mds}), no MDS can replace rank {rank}".format( + actives=actives, max_mds=max_mds, rank=rank)) return status else: - if len(actives) == max_mds: - self.log('mds cluster has {count} alive and active, now stable!'.format(count = len(actives))) + if actives == max_mds: + self.log('mds cluster has {count} alive and active, now stable!'.format(count = actives)) return status, None if itercount > 300/2: # 5 minutes raise RuntimeError('timeout waiting for cluster to stabilize')