]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: Add unittest for service_action 32209/head
authorSebastian Wagner <sebastian.wagner@suse.com>
Fri, 13 Dec 2019 10:37:03 +0000 (11:37 +0100)
committerSebastian Wagner <sebastian.wagner@suse.com>
Fri, 13 Dec 2019 10:37:03 +0000 (11:37 +0100)
(That was missing previously)

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

index 07f2d24d0cdc9705d900b049687c2b3dcdc0bed9..3ef2858e202fde137ff0e0c71010d30aa5cf108d 100644 (file)
@@ -808,6 +808,8 @@ class CephadmOrchestrator(MgrModule, orchestrator.Orchestrator):
             return trivial_result(["Reload is a no-op"])
 
         def _proc_daemons(daemons):
+            if service_name is None and service_id is None:
+                raise ValueError('service_name or service_id required')
             args = []
             for d in daemons:
                 args.append((d.service_type, d.service_instance,
@@ -858,7 +860,7 @@ class CephadmOrchestrator(MgrModule, orchestrator.Orchestrator):
                 error_ok=True)
             self.service_cache.invalidate(host)
             self.log.debug('_service_action code %s out %s' % (code, out))
-        return trivial_result("{} {} from host '{}'".format(action, name, host))
+        return "{} {} from host '{}'".format(action, name, host)
 
     def get_inventory(self, node_filter=None, refresh=False):
         """
index 396c5610ab4d62c05961baea9b72c0e2ba6edf2e..c93353d5bd8e528fcd5cb92b0518d81fdec296cc 100644 (file)
@@ -38,13 +38,25 @@ class TestCephadm(object):
     def _wait(self, m, c):
         # type: (CephadmOrchestrator, Completion) -> Any
         m.process([c])
-        m.process([c])
 
-        for _ in range(30):
-            if c.is_finished:
-                raise_if_exception(c)
-                return c.result
-            time.sleep(0.1)
+        try:
+            import pydevd  # if in debugger
+            while True:    # don't timeout
+                if c.is_finished:
+                    raise_if_exception(c)
+                    return c.result
+                time.sleep(0.1)
+        except ImportError:  # not in debugger
+            for i in range(30):
+                if i % 10 == 0:
+                    m.process([c])
+                if c.is_finished:
+                    raise_if_exception(c)
+                    return c.result
+                time.sleep(0.1)
+        assert False, "timeout" + str(c._state)
+
+        m.process([c])
         assert False, "timeout" + str(c._state)
 
     @contextmanager
@@ -79,6 +91,33 @@ class TestCephadm(object):
             c = cephadm_module.get_inventory()
             assert self._wait(cephadm_module, c) == [InventoryNode('test')]
 
+    @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm(
+        json.dumps([
+            dict(
+                name='rgw.myrgw.foobar',
+                style='cephadm',
+                fsid='fsid',
+                container_id='container_id',
+                version='version',
+                state='running',
+            )
+        ])
+    ))
+    @mock.patch("cephadm.module.CephadmOrchestrator.send_command")
+    @mock.patch("cephadm.module.CephadmOrchestrator.mon_command", mon_command)
+    @mock.patch("cephadm.module.CephadmOrchestrator._get_connection")
+    def test_service_action(self, _send_command, _get_connection, cephadm_module):
+        cephadm_module._cluster_fsid = "fsid"
+        cephadm_module.service_cache_timeout = 10
+        with self._with_host(cephadm_module, 'test'):
+            c = cephadm_module.service_action('redeploy', 'rgw', service_id='myrgw.foobar')
+            assert self._wait(cephadm_module, c) == ["(Re)deployed rgw.myrgw.foobar on host 'test'"]
+
+            for what in ('start', 'stop', 'restart'):
+                c = cephadm_module.service_action(what, 'rgw', service_id='myrgw.foobar')
+                assert self._wait(cephadm_module, c) == [what + " rgw.myrgw.foobar from host 'test'"]
+
+
     @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('[]'))
     @mock.patch("cephadm.module.CephadmOrchestrator.send_command")
     @mock.patch("cephadm.module.CephadmOrchestrator.mon_command", mon_command)