From: Prashant D Date: Wed, 2 Sep 2020 12:33:16 +0000 (-0400) Subject: mgr/mgr_module: fix keyerror for op X-Git-Tag: v16.1.0~1174^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=48a345cfc380e63105087de36d91df4728826bf5;p=ceph.git mgr/mgr_module: fix keyerror for op If rule steps first element is opcode. Fixes: https://tracker.ceph.com/issues/47272 Signed-off-by: Prashant Dhange --- diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 9e8c3ba4ca6..c30e5638c4f 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -234,8 +234,8 @@ class CRUSHMap(ceph_module.BasePyCRUSH): return None try: - first_take = [s for s in rule['steps'] if s['op'] == 'take'][0] - except IndexError: + first_take = next(s for s in rule['steps'] if s.get('op') == 'take') + except StopIteration: logging.warning("CRUSH rule '{0}' has no 'take' step".format( rule_name)) return None