From f45d6b224343e52251104a798441a0ce8408ce0d Mon Sep 17 00:00:00 2001 From: Melissa Li Date: Tue, 3 Aug 2021 13:46:21 -0400 Subject: [PATCH] mgr/cephadm: refactor `_refresh_hosts_and_daemons` to use `set_health_warning` and `remove_health_warning` helpers Fixes: https://tracker.ceph.com/issues/44414 Signed-off-by: Melissa Li (cherry picked from commit 2eacd6e7e936636b2eee82bd03ee59f67431cd2e) --- src/pybind/mgr/cephadm/serve.py | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/src/pybind/mgr/cephadm/serve.py b/src/pybind/mgr/cephadm/serve.py index 19ed4a7f22af7..73e43031882f8 100644 --- a/src/pybind/mgr/cephadm/serve.py +++ b/src/pybind/mgr/cephadm/serve.py @@ -323,31 +323,16 @@ class CephadmServe: self.mgr.config_checker.run_checks() - health_changed = False for k in [ 'CEPHADM_HOST_CHECK_FAILED', 'CEPHADM_FAILED_DAEMON', 'CEPHADM_REFRESH_FAILED', ]: - if k in self.mgr.health_checks: - del self.mgr.health_checks[k] - health_changed = True + self.mgr.remove_health_warning(k) if bad_hosts: - self.mgr.health_checks['CEPHADM_HOST_CHECK_FAILED'] = { - 'severity': 'warning', - 'summary': '%d hosts fail cephadm check' % len(bad_hosts), - 'count': len(bad_hosts), - 'detail': bad_hosts, - } - health_changed = True + self.mgr.set_health_warning('CEPHADM_HOST_CHECK_FAILED', f'{len(bad_hosts)} hosts fail cephadm check', len(bad_hosts), bad_hosts) if failures: - self.mgr.health_checks['CEPHADM_REFRESH_FAILED'] = { - 'severity': 'warning', - 'summary': 'failed to probe daemons or devices', - 'count': len(failures), - 'detail': failures, - } - health_changed = True + self.mgr.set_health_warning('CEPHADM_REFRESH_FAILED', 'failed to probe daemons or devices', len(failures), failures) failed_daemons = [] for dd in self.mgr.cache.get_daemons(): if dd.status is not None and dd.status == DaemonDescriptionStatus.error: @@ -355,15 +340,7 @@ class CephadmServe: dd.name(), dd.hostname, dd.status_desc )) if failed_daemons: - self.mgr.health_checks['CEPHADM_FAILED_DAEMON'] = { - 'severity': 'warning', - 'summary': '%d failed cephadm daemon(s)' % len(failed_daemons), - 'count': len(failed_daemons), - 'detail': failed_daemons, - } - health_changed = True - if health_changed: - self.mgr.set_health_checks(self.mgr.health_checks) + self.mgr.set_health_warning('CEPHADM_FAILED_DAEMON', f'{len(failed_daemons)} failed cephadm daemon(s)', len(failed_daemons), failed_daemons) def _check_host(self, host: str) -> Optional[str]: if host not in self.mgr.inventory: -- 2.39.5