]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: Add test_daemon_action_fail
authorSebastian Wagner <sebastian.wagner@suse.com>
Wed, 29 Jul 2020 12:23:06 +0000 (14:23 +0200)
committerSebastian Wagner <sebastian.wagner@suse.com>
Fri, 21 Aug 2020 11:04:01 +0000 (13:04 +0200)
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
(cherry picked from commit f500b8fc747f1767a31e54e6fb4a9a596889d1a1)

src/pybind/mgr/cephadm/inventory.py
src/pybind/mgr/cephadm/tests/fixtures.py
src/pybind/mgr/cephadm/tests/test_cephadm.py
src/pybind/mgr/tests/__init__.py

index 4a76e15058f38df14c98c7993edc79455e0c7277..bf621e0365c8b7c2951e9d65a312e89ce8255b71 100644 (file)
@@ -556,8 +556,8 @@ class EventStore():
         for k_s in unknowns:
             del self.events[k_s]
 
-    def get_for_service(self, name):
+    def get_for_service(self, name) -> List[OrchestratorEvent]:
         return self.events.get('service:' + name, [])
 
-    def get_for_daemon(self, name):
+    def get_for_daemon(self, name) -> List[OrchestratorEvent]:
         return self.events.get('daemon:' + name, [])
index a14917595ebb261e28fe37e2177a90e60ae4228c..05683aa2376942746bbd3a94f430dab64d243343 100644 (file)
@@ -33,9 +33,6 @@ def match_glob(val, pat):
         assert pat in val
 
 
-def mon_command(*args, **kwargs):
-    return 0, '', ''
-
 @contextmanager
 def with_cephadm_module(module_options=None, store=None):
     """
@@ -43,11 +40,9 @@ def with_cephadm_module(module_options=None, store=None):
     :param store: Set the store before module.__init__ is called
     """
     with mock.patch("cephadm.module.CephadmOrchestrator.get_ceph_option", get_ceph_option),\
-             mock.patch("cephadm.module.CephadmOrchestrator.remote"), \
-             mock.patch("cephadm.services.osd.RemoveUtil._run_mon_cmd"), \
-             mock.patch("cephadm.module.CephadmOrchestrator.send_command"), \
-             mock.patch("cephadm.module.CephadmOrchestrator.get_osdmap"), \
-             mock.patch("cephadm.module.CephadmOrchestrator.mon_command", mon_command):
+            mock.patch("cephadm.services.osd.RemoveUtil._run_mon_cmd"), \
+            mock.patch("cephadm.module.CephadmOrchestrator.get_osdmap"), \
+            mock.patch("cephadm.module.CephadmOrchestrator.remote"):
 
         m = CephadmOrchestrator.__new__ (CephadmOrchestrator)
         if module_options is not None:
index 3cd193ea0872f0812a0142b2da0a8c7b967c781a..4d82cea225d651251efb19ecebcf30741868b888 100644 (file)
@@ -22,7 +22,7 @@ from ceph.deployment.inventory import Devices, Device
 from orchestrator import ServiceDescription, DaemonDescription, InventoryHost, \
     HostSpec, OrchestratorError
 from tests import mock
-from .fixtures import cephadm_module, wait, _run_cephadm, mon_command, match_glob, with_host, \
+from .fixtures import cephadm_module, wait, _run_cephadm, match_glob, with_host, \
     with_cephadm_module
 from cephadm.module import CephadmOrchestrator, CEPH_DATEFMT
 
@@ -212,6 +212,28 @@ class TestCephadm(object):
 
                 cephadm_module._check_daemons()
 
+    @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('[]'))
+    @mock.patch("cephadm.services.cephadmservice.RgwService.create_realm_zonegroup_zone", lambda _,__,___: None)
+    def test_daemon_action_fail(self, cephadm_module: CephadmOrchestrator):
+        cephadm_module.service_cache_timeout = 10
+        with with_host(cephadm_module, 'test'):
+            with with_daemon(cephadm_module, RGWSpec(service_id='myrgw.foobar'), CephadmOrchestrator.add_rgw, 'test') as daemon_id:
+                with mock.patch('ceph_module.BaseMgrModule._ceph_send_command') as _ceph_send_command:
+
+                    _ceph_send_command.side_effect = Exception("myerror")
+
+                    # Make sure, _check_daemons does a redeploy due to monmap change:
+                    cephadm_module._store['_ceph_get/mon_map'] = {
+                        'modified': datetime.datetime.utcnow().strftime(CEPH_DATEFMT),
+                        'fsid': 'foobar',
+                    }
+                    cephadm_module.notify('mon_map', None)
+
+                    cephadm_module._check_daemons()
+
+                    evs = [e.message for e in cephadm_module.events.get_for_daemon(f'rgw.{daemon_id}')]
+
+                    assert 'myerror' in ''.join(evs)
 
     @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('[]'))
     def test_mon_add(self, cephadm_module):
index 6ca9315150c87c28bd7044d94c494f1f027c5285..a6f8cc0ff91fc097fc0e327ab6d26060019d27bd 100644 (file)
@@ -70,6 +70,8 @@ if 'UNITTEST' in os.environ:
                 self._store = {}
             return self._store.get(f'_ceph_get/{data_name}', mock.MagicMock())
 
+        def _ceph_send_command(self, ev, *args):
+            ev.complete(0, '', '')
 
         def __init__(self, *args):
             if not hasattr(self, '_store'):