]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm/tests: Split `test_daemon_action`
authorSebastian Wagner <sebastian.wagner@suse.com>
Wed, 29 Jul 2020 12:09:00 +0000 (14:09 +0200)
committerSebastian Wagner <sebastian.wagner@suse.com>
Wed, 5 Aug 2020 10:51:28 +0000 (12:51 +0200)
Into:

* `test_list_daemons`
* `test_daemon_action` (now without listing daemons)

Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/pybind/mgr/cephadm/tests/test_cephadm.py

index dc60f199656b5ba04b26de62dfd02299f8b674e7..3cd193ea0872f0812a0142b2da0a8c7b967c781a 100644 (file)
@@ -48,6 +48,25 @@ def assert_rm_daemon(cephadm: CephadmOrchestrator, prefix, host):
     match_glob(out, f"Removed {d_names}* from host '{host}'")
 
 
+@contextmanager
+def with_daemon(cephadm_module: CephadmOrchestrator, spec: ServiceSpec, meth, host: str):
+    spec.placement = PlacementSpec(hosts=[host], count=1)
+
+    c = meth(cephadm_module, spec)
+    [out] = wait(cephadm_module, c)
+    match_glob(out, f"Deployed {spec.service_name()}.* on host '{host}'")
+
+    dds = cephadm_module.cache.get_daemons_by_service(spec.service_name())
+    for dd in dds:
+        if dd.hostname == host:
+            yield dd.daemon_id
+            assert_rm_daemon(cephadm_module, spec.service_name(), host)
+            return
+
+    assert False, 'Daemon not found'
+
+
+
 class TestCephadm(object):
 
     def test_get_unique_name(self, cephadm_module):
@@ -164,30 +183,35 @@ class TestCephadm(object):
             )
         ])
     ))
-    def test_daemon_action(self, cephadm_module: CephadmOrchestrator):
-
+    def test_list_daemons(self, cephadm_module: CephadmOrchestrator):
         cephadm_module.service_cache_timeout = 10
         with with_host(cephadm_module, 'test'):
             c = cephadm_module.list_daemons(refresh=True)
-            wait(cephadm_module, c)
-            assert len(c.result) == 1
-            c = cephadm_module.daemon_action('redeploy', 'rgw', 'myrgw.foobar')
-            assert wait(cephadm_module, c) == ["Deployed rgw.myrgw.foobar on host 'test'"]
+            assert wait(cephadm_module, c)[0].name() == 'rgw.myrgw.foobar'
 
-            for what in ('start', 'stop', 'restart'):
-                c = cephadm_module.daemon_action(what, 'rgw', 'myrgw.foobar')
-                assert wait(cephadm_module, c) == [what + " rgw.myrgw.foobar from host 'test'"]
+    @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(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:
 
-            # 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)
+                c = cephadm_module.daemon_action('redeploy', 'rgw', daemon_id)
+                assert wait(cephadm_module, c) == [f"Deployed rgw.{daemon_id} on host 'test'"]
+
+                for what in ('start', 'stop', 'restart'):
+                    c = cephadm_module.daemon_action(what, 'rgw', daemon_id)
+                    assert wait(cephadm_module, c) == [what + f" rgw.{daemon_id} from host 'test'"]
 
-            cephadm_module._check_daemons()
+                # 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()
 
-            assert_rm_daemon(cephadm_module, 'rgw.myrgw.foobar', 'test')
 
     @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('[]'))
     def test_mon_add(self, cephadm_module):
@@ -442,13 +466,8 @@ class TestCephadm(object):
     @mock.patch("cephadm.services.cephadmservice.RgwService.create_realm_zonegroup_zone", lambda _,__,___: None)
     def test_daemon_add(self, spec: ServiceSpec, meth, cephadm_module):
         with with_host(cephadm_module, 'test'):
-            spec.placement = PlacementSpec(hosts=['test'], count=1)
-
-            c = meth(cephadm_module, spec)
-            [out] = wait(cephadm_module, c)
-            match_glob(out, f"Deployed {spec.service_name()}.* on host 'test'")
-
-            assert_rm_daemon(cephadm_module, spec.service_name(), 'test')
+            with with_daemon(cephadm_module, spec, meth, 'test'):
+                pass
 
     @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('{}'))
     @mock.patch("cephadm.module.CephadmOrchestrator.rados", mock.MagicMock())