From: Sebastian Wagner Date: Fri, 11 Sep 2020 11:12:21 +0000 (+0200) Subject: mgr/cephadm: move _check_for_strays to serve.py X-Git-Tag: v15.2.8~14^2~26 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c20f1898b0d4541d24f73b5581cc81e5cd7b3a28;p=ceph.git mgr/cephadm: move _check_for_strays to serve.py Signed-off-by: Sebastian Wagner (cherry picked from commit 1601b699b36350f5ff21169add6c48e66c61c7eb) --- diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 703d526064ee..e7b4f2e4f7d2 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -431,61 +431,6 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): return f"Host {host} failed to login to {url} as {username} with given password" return - def _check_for_strays(self): - self.log.debug('_check_for_strays') - for k in ['CEPHADM_STRAY_HOST', - 'CEPHADM_STRAY_DAEMON']: - if k in self.health_checks: - del self.health_checks[k] - if self.warn_on_stray_hosts or self.warn_on_stray_daemons: - ls = self.list_servers() - managed = self.cache.get_daemon_names() - host_detail = [] # type: List[str] - host_num_daemons = 0 - daemon_detail = [] # type: List[str] - for item in ls: - host = item.get('hostname') - daemons = item.get('services') # misnomer! - missing_names = [] - for s in daemons: - name = '%s.%s' % (s.get('type'), s.get('id')) - if s.get('type') == 'rbd-mirror': - defaults = defaultdict(lambda: None, {'id': None}) - metadata = self.get_metadata("rbd-mirror", s.get('id'), default=defaults) - if metadata['id']: - name = '%s.%s' % (s.get('type'), metadata['id']) - else: - self.log.debug( - "Failed to find daemon id for rbd-mirror service %s" % (s.get('id'))) - if host not in self.inventory: - missing_names.append(name) - host_num_daemons += 1 - if name not in managed: - daemon_detail.append( - 'stray daemon %s on host %s not managed by cephadm' % (name, host)) - if missing_names: - host_detail.append( - 'stray host %s has %d stray daemons: %s' % ( - host, len(missing_names), missing_names)) - if self.warn_on_stray_hosts and host_detail: - self.health_checks['CEPHADM_STRAY_HOST'] = { - 'severity': 'warning', - 'summary': '%d stray host(s) with %s daemon(s) ' - 'not managed by cephadm' % ( - len(host_detail), host_num_daemons), - 'count': len(host_detail), - 'detail': host_detail, - } - if self.warn_on_stray_daemons and daemon_detail: - self.health_checks['CEPHADM_STRAY_DAEMON'] = { - 'severity': 'warning', - 'summary': '%d stray daemons(s) not managed by cephadm' % ( - len(daemon_detail)), - 'count': len(daemon_detail), - 'detail': daemon_detail, - } - self.set_health_checks(self.health_checks) - def serve(self) -> None: """ The main loop of cephadm. diff --git a/src/pybind/mgr/cephadm/serve.py b/src/pybind/mgr/cephadm/serve.py index 95c0425f8c68..bf402a980845 100644 --- a/src/pybind/mgr/cephadm/serve.py +++ b/src/pybind/mgr/cephadm/serve.py @@ -1,7 +1,8 @@ import datetime import json import logging -from typing import TYPE_CHECKING, Optional +from collections import defaultdict +from typing import TYPE_CHECKING, Optional, List try: import remoto @@ -51,7 +52,7 @@ class CephadmServe: self.log.debug('refreshing hosts and daemons') self._refresh_hosts_and_daemons() - self.mgr._check_for_strays() + self._check_for_strays() self.mgr._update_paused_health() @@ -298,3 +299,59 @@ class CephadmServe: except OrchestratorError as e: return f'failed to create /etc/ceph/ceph.conf on {host}: {str(e)}' return None + + def _check_for_strays(self) -> None: + self.log.debug('_check_for_strays') + for k in ['CEPHADM_STRAY_HOST', + 'CEPHADM_STRAY_DAEMON']: + if k in self.mgr.health_checks: + del self.mgr.health_checks[k] + if self.mgr.warn_on_stray_hosts or self.mgr.warn_on_stray_daemons: + ls = self.mgr.list_servers() + managed = self.mgr.cache.get_daemon_names() + host_detail = [] # type: List[str] + host_num_daemons = 0 + daemon_detail = [] # type: List[str] + for item in ls: + host = item.get('hostname') + daemons = item.get('services') # misnomer! + missing_names = [] + for s in daemons: + name = '%s.%s' % (s.get('type'), s.get('id')) + if s.get('type') == 'rbd-mirror': + defaults = defaultdict(lambda: None, {'id': None}) + metadata = self.mgr.get_metadata("rbd-mirror", s.get('id'), default=defaults) + if metadata['id']: + name = '%s.%s' % (s.get('type'), metadata['id']) + else: + self.log.debug( + "Failed to find daemon id for rbd-mirror service %s" % (s.get('id'))) + + if host not in self.mgr.inventory: + missing_names.append(name) + host_num_daemons += 1 + if name not in managed: + daemon_detail.append( + 'stray daemon %s on host %s not managed by cephadm' % (name, host)) + if missing_names: + host_detail.append( + 'stray host %s has %d stray daemons: %s' % ( + host, len(missing_names), missing_names)) + if self.mgr.warn_on_stray_hosts and host_detail: + self.mgr.health_checks['CEPHADM_STRAY_HOST'] = { + 'severity': 'warning', + 'summary': '%d stray host(s) with %s daemon(s) ' + 'not managed by cephadm' % ( + len(host_detail), host_num_daemons), + 'count': len(host_detail), + 'detail': host_detail, + } + if self.mgr.warn_on_stray_daemons and daemon_detail: + self.mgr.health_checks['CEPHADM_STRAY_DAEMON'] = { + 'severity': 'warning', + 'summary': '%d stray daemons(s) not managed by cephadm' % ( + len(daemon_detail)), + 'count': len(daemon_detail), + 'detail': daemon_detail, + } + self.mgr.set_health_checks(self.mgr.health_checks)