]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/ssh: `test_mon_update` needs to set a mon name
authorSebastian Wagner <sebastian.wagner@suse.com>
Mon, 2 Dec 2019 10:20:53 +0000 (11:20 +0100)
committerSebastian Wagner <sebastian.wagner@suse.com>
Mon, 2 Dec 2019 10:22:31 +0000 (11:22 +0100)
... in order to exercise a code path to make use of `_get_services()`

Fixes: https://tracker.ceph.com/issues/43075
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/pybind/mgr/orchestrator.py
src/pybind/mgr/ssh/module.py
src/pybind/mgr/ssh/tests/test_ssh.py

index 15a4175065582aa5cd841acc3d092ce5cdc33327..f3528c6426fdd4e8ef88cdf6d6dbe75d350781cb 100644 (file)
@@ -33,6 +33,8 @@ except ImportError:
 logger = logging.getLogger(__name__)
 
 
+HostSpec = namedtuple('HostSpec', ['hostname', 'network', 'name'])
+
 
 def parse_host_specs(host, require_network=True):
     """
@@ -55,8 +57,6 @@ def parse_host_specs(host, require_network=True):
     # Matches from = to end of string
     name_re = r'=(.*?)$'
 
-    from collections import namedtuple
-    HostSpec = namedtuple('HostSpec', ['hostname', 'network', 'name'])
     # assign defaults
     host_spec = HostSpec('', '', '')
 
@@ -899,7 +899,7 @@ class Orchestrator(object):
         raise NotImplementedError()
 
     def update_mons(self, num, hosts):
-        # type: (int, List[Tuple[str,str,str]]) -> Completion
+        # type: (int, List[HostSpec]) -> Completion
         """
         Update the number of cluster monitors.
 
index 92f0d9803024cb4a1439a918c875bd7d5fc7dac9..306b500d85c3d2c1b53e9e2e3081f41aea50af55 100644 (file)
@@ -1074,6 +1074,7 @@ class SSHOrchestrator(MgrModule, orchestrator.Orchestrator):
                                    extra_args=extra_args)
 
     def update_mons(self, num, host_specs):
+        # type: (int, List[orchestrator.HostSpec]) -> orchestrator.Completion
         """
         Adjust the number of cluster monitors.
         """
@@ -1094,23 +1095,24 @@ class SSHOrchestrator(MgrModule, orchestrator.Orchestrator):
             if not network:
                 raise RuntimeError("Host '{}' is missing a network spec".format(host))
 
-        daemons = self._get_services('mon')
-        for _, _, name in host_specs:
-            if name and len([d for d in daemons if d.service_instance == name]):
-                raise RuntimeError('name %s alrady exists', name)
+        def update_mons_with_daemons(daemons):
+            for _, _, name in host_specs:
+                if name and len([d for d in daemons if d.service_instance == name]):
+                    raise RuntimeError('name %s alrady exists', name)
 
-        # explicit placement: enough hosts provided?
-        num_new_mons = num - num_mons
-        if len(host_specs) < num_new_mons:
-            raise RuntimeError("Error: {} hosts provided, expected {}".format(
-                len(host_specs), num_new_mons))
+            # explicit placement: enough hosts provided?
+            num_new_mons = num - num_mons
+            if len(host_specs) < num_new_mons:
+                raise RuntimeError("Error: {} hosts provided, expected {}".format(
+                    len(host_specs), num_new_mons))
 
-        self.log.info("creating {} monitors on hosts: '{}'".format(
-            num_new_mons, ",".join(map(lambda h: ":".join(h), host_specs))))
+            self.log.info("creating {} monitors on hosts: '{}'".format(
+                num_new_mons, ",".join(map(lambda h: ":".join(h), host_specs))))
 
-        # TODO: we may want to chain the creation of the monitors so they join
-        # the quorum one at a time.
-        return self._create_mon(host_specs)
+            # TODO: we may want to chain the creation of the monitors so they join
+            # the quorum one at a time.
+            return self._create_mon(host_specs)
+        return self._get_services('mon').then(update_mons_with_daemons)
 
     @async_map_completion
     def _create_mgr(self, host, name):
index d1e8803048c92ecda2f75b809ae2e33ff36bfd42..878788f780120624fdbdaead5e6f431897d6195b 100644 (file)
@@ -85,8 +85,8 @@ class TestSSH(object):
     @mock.patch("ssh.module.SSHOrchestrator._get_connection")
     def test_mon_update(self, _send_command, _get_connection, ssh_module):
         with self._with_host(ssh_module, 'test'):
-            c = ssh_module.update_mons(1, [parse_host_specs('test:0.0.0.0')])
-            assert self._wait(ssh_module, c) == ["(Re)deployed mon.test on host 'test'"]
+            c = ssh_module.update_mons(1, [parse_host_specs('test:0.0.0.0=a')])
+            assert self._wait(ssh_module, c) == ["(Re)deployed mon.a on host 'test'"]
 
     @mock.patch("ssh.module.SSHOrchestrator._run_ceph_daemon", _run_ceph_daemon('[]'))
     @mock.patch("ssh.module.SSHOrchestrator.send_command")