]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: add test_daemon_check 36753/head
authorSebastian Wagner <sebastian.wagner@suse.com>
Fri, 21 Aug 2020 15:38:33 +0000 (17:38 +0200)
committerSebastian Wagner <sebastian.wagner@suse.com>
Fri, 28 Aug 2020 07:56:13 +0000 (09:56 +0200)
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/pybind/mgr/cephadm/tests/fixtures.py
src/pybind/mgr/cephadm/tests/test_cephadm.py

index 9f7864ccebed4e3fb6c403a166c1b570264a477e..b70469cbbefdc562fcfd25ae5d3791335e65b788 100644 (file)
@@ -7,7 +7,7 @@ from ceph.deployment.service_spec import PlacementSpec, ServiceSpec
 from cephadm.module import CEPH_DATEFMT
 
 try:
-    from typing import Any
+    from typing import Any, Iterator, List
 except ImportError:
     pass
 import pytest
@@ -127,7 +127,7 @@ def assert_rm_service(cephadm, srv_name):
 
 
 @contextmanager
-def with_service(cephadm_module: CephadmOrchestrator, spec: ServiceSpec, meth, host: str):
+def with_service(cephadm_module: CephadmOrchestrator, spec: ServiceSpec, meth, host: str) -> Iterator[List[str]]:
     if spec.placement.is_empty():
         spec.placement = PlacementSpec(hosts=[host], count=1)
     c = meth(cephadm_module, spec)
@@ -138,9 +138,9 @@ def with_service(cephadm_module: CephadmOrchestrator, spec: ServiceSpec, meth, h
     cephadm_module._apply_all_services()
 
     dds = wait(cephadm_module, cephadm_module.list_daemons())
-    names = {dd.service_name() for dd in dds}
-    assert spec.service_name() in names, dds
+    own_dds = [dd for dd in dds if dd.service_name() == spec.service_name()]
+    assert own_dds
 
-    yield
+    yield [dd.name() for dd in own_dds]
 
     assert_rm_service(cephadm_module, spec.service_name())
index 5d53a5f13c4e15eb7a2fcaf7cc722f2cf1d26c7b..ebddee226cb4095e8168149f1863d28afb2df6b8 100644 (file)
@@ -225,6 +225,31 @@ class TestCephadm(object):
 
                     assert 'myerror' in ''.join(evs)
 
+    @pytest.mark.parametrize(
+        "action",
+        [
+            'start',
+            'stop',
+            'restart',
+            'reconfig',
+            'redeploy'
+        ]
+    )
+    @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('{}'))
+    def test_daemon_check(self, cephadm_module: CephadmOrchestrator, action):
+        with with_host(cephadm_module, 'test'):
+            with with_service(cephadm_module, ServiceSpec(service_type='grafana'), CephadmOrchestrator.apply_grafana, 'test') as d_names:
+                [daemon_name] = d_names
+
+                cephadm_module._schedule_daemon_action(daemon_name, action)
+
+                assert cephadm_module.cache.get_scheduled_daemon_action(
+                    'test', daemon_name) == action
+
+                cephadm_module._check_daemons()
+
+                assert cephadm_module.cache.get_scheduled_daemon_action('test', daemon_name) is None
+
     @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('{}'))
     def test_daemon_check_post(self, cephadm_module: CephadmOrchestrator):
         with with_host(cephadm_module, 'test'):