]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/cephadm: move _check_safe_to_destroy_mon to MonService
authorSebastian Wagner <sebastian.wagner@suse.com>
Tue, 9 Jun 2020 12:57:07 +0000 (14:57 +0200)
committerSebastian Wagner <sebastian.wagner@suse.com>
Thu, 18 Jun 2020 12:30:04 +0000 (14:30 +0200)
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/services/cephadmservice.py

index 8bdfe2bdbbcc28399c30d25d59e8031239b65379..04a65d253ca81437e93f30d16736fcba36f3e30b 100644 (file)
@@ -381,28 +381,6 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
         self.log.debug('_kick_serve_loop')
         self.event.set()
 
-    def _check_safe_to_destroy_mon(self, mon_id):
-        # type: (str) -> None
-        ret, out, err = self.check_mon_command({
-            'prefix': 'quorum_status',
-        })
-        try:
-            j = json.loads(out)
-        except Exception as e:
-            raise OrchestratorError('failed to parse quorum status')
-
-        mons = [m['name'] for m in j['monmap']['mons']]
-        if mon_id not in mons:
-            self.log.info('Safe to remove mon.%s: not in monmap (%s)' % (
-                mon_id, mons))
-            return
-        new_mons = [m for m in mons if m != mon_id]
-        new_quorum = [m for m in j['quorum_names'] if m != mon_id]
-        if len(new_quorum) > len(new_mons) / 2:
-            self.log.info('Safe to remove mon.%s: new quorum should be %s (from %s)' % (mon_id, new_quorum, new_mons))
-            return
-        raise OrchestratorError('Removing %s would break mon quorum (new quorum %s, new mons %s)' % (mon_id, new_quorum, new_mons))
-
     def _check_host(self, host):
         if host not in self.inventory:
             return
@@ -1714,15 +1692,8 @@ you may want to run:
         Remove a daemon
         """
         (daemon_type, daemon_id) = name.split('.', 1)
-        if daemon_type == 'mon':
-            self._check_safe_to_destroy_mon(daemon_id)
 
-            # remove mon from quorum before we destroy the daemon
-            self.log.info('Removing monitor %s from monmap...' % name)
-            ret, out, err = self.check_mon_command({
-                'prefix': 'mon rm',
-                'name': daemon_id,
-            })
+        self.cephadm_services[daemon_type].pre_remove(daemon_id)
 
         args = ['--name', name, '--force']
         self.log.info('Removing daemon %s from %s' % (name, host))
index be8f91f782f9bfcecb2b756460e8f8bd2ca0f6fe..581a8c497513a92177236b91e5b41ab533f157f9 100644 (file)
@@ -1,3 +1,4 @@
+import json
 import logging
 from abc import ABCMeta, abstractmethod
 from typing import TYPE_CHECKING, List, Callable, Any
@@ -139,6 +140,11 @@ class CephadmService(metaclass=ABCMeta):
 
         return True
 
+    def pre_remove(self, daemon_id: str) -> None:
+        """
+        Called before the daemon is removed.
+        """
+        pass
 
 class MonService(CephadmService):
     TYPE = 'mon'
@@ -182,6 +188,39 @@ class MonService(CephadmService):
                                        keyring=keyring,
                                        extra_config={'config': extra_config})
 
+    def _check_safe_to_destroy(self, mon_id):
+        # type: (str) -> None
+        ret, out, err = self.mgr.check_mon_command({
+            'prefix': 'quorum_status',
+        })
+        try:
+            j = json.loads(out)
+        except Exception as e:
+            raise OrchestratorError('failed to parse quorum status')
+
+        mons = [m['name'] for m in j['monmap']['mons']]
+        if mon_id not in mons:
+            logger.info('Safe to remove mon.%s: not in monmap (%s)' % (
+                mon_id, mons))
+            return
+        new_mons = [m for m in mons if m != mon_id]
+        new_quorum = [m for m in j['quorum_names'] if m != mon_id]
+        if len(new_quorum) > len(new_mons) / 2:
+            logger.info('Safe to remove mon.%s: new quorum should be %s (from %s)' % (mon_id, new_quorum, new_mons))
+            return
+        raise OrchestratorError('Removing %s would break mon quorum (new quorum %s, new mons %s)' % (mon_id, new_quorum, new_mons))
+
+
+    def pre_remove(self, daemon_id: str) -> None:
+        self._check_safe_to_destroy(daemon_id)
+
+        # remove mon from quorum before we destroy the daemon
+        logger.info('Removing monitor %s from monmap...' % daemon_id)
+        ret, out, err = self.mgr.check_mon_command({
+            'prefix': 'mon rm',
+            'name': daemon_id,
+        })
+
 
 class MgrService(CephadmService):
     TYPE = 'mgr'