From 726c59be58473cfe53fa3ea63cf35b58ed797886 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 30 Apr 2020 18:07:00 +0800 Subject: [PATCH] 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 --- qa/tasks/mds_thrash.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/qa/tasks/mds_thrash.py b/qa/tasks/mds_thrash.py index 224b1cfc60a34..c7f2e93006410 100644 --- a/qa/tasks/mds_thrash.py +++ b/qa/tasks/mds_thrash.py @@ -186,10 +186,11 @@ class MDSThrasher(Thrasher, 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: @@ -201,14 +202,14 @@ class MDSThrasher(Thrasher, 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 {actives} actives (max_mds is {max_mds}), no MDS can replace rank {rank}".format( - actives=len(actives), max_mds=max_mds, rank=rank)) + 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') -- 2.39.5