]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: move _check_for_strays to serve.py
authorSebastian Wagner <sebastian.wagner@suse.com>
Fri, 11 Sep 2020 11:12:21 +0000 (13:12 +0200)
committerSebastian Wagner <sebastian.wagner@suse.com>
Wed, 18 Nov 2020 10:52:17 +0000 (11:52 +0100)
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
(cherry picked from commit 1601b699b36350f5ff21169add6c48e66c61c7eb)

src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/serve.py

index 703d526064ee806e28aa394e2c02acbc080f5021..e7b4f2e4f7d2b13039c355baa87a7dd5ab086170 100644 (file)
@@ -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.
index 95c0425f8c6828b71ceeacbdb813f885438a306f..bf402a9808452a00bd0676c4c5545e6634e471dd 100644 (file)
@@ -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)