From abdee9f67971ee23a847665e0a1d58d0a30c46b7 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 25 Jun 2018 13:25:18 -0500 Subject: [PATCH] mgr/devicehealth: only fetch osdmap once from check_health Signed-off-by: Sage Weil --- src/pybind/mgr/devicehealth/module.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pybind/mgr/devicehealth/module.py b/src/pybind/mgr/devicehealth/module.py index 920403ae104..ab621e3183a 100644 --- a/src/pybind/mgr/devicehealth/module.py +++ b/src/pybind/mgr/devicehealth/module.py @@ -328,6 +328,9 @@ class Module(MgrModule): 'DEVICE_HEALTH_IN_USE': [], } devs = self.get("devices") + now = datetime.now() + osdmap = self.get("osd_map") + assert osdmap is not None for dev in devs['devices']: devid = dev['devid'] if 'life_expectancy_min' not in dev: @@ -340,7 +343,6 @@ class Module(MgrModule): '%Y-%m-%d %H:%M:%S.%f') self.log.debug('device %s expectancy min %s', dev, life_expectancy_min) - now = datetime.now() if life_expectancy_min - now <= mark_out_threshold_td: if self.self_heal: @@ -352,7 +354,7 @@ class Module(MgrModule): osds_in = [] osds_out = [] for _id in osd_ids: - if self.is_osd_in(_id): + if self.is_osd_in(osdmap, _id): osds_in.append(_id) else: osds_out.append(_id) @@ -397,9 +399,7 @@ class Module(MgrModule): self.set_health_checks(checks) return (0,"","") - def is_osd_in(self, osd_id): - osdmap = self.get("osd_map") - assert osdmap is not None + def is_osd_in(self, osdmap, osd_id): for osd in osdmap['osds']: if str(osd_id) == str(osd['osd']): return bool(osd['in']) -- 2.39.5