From: Sebastian Wagner Date: Mon, 2 Dec 2019 10:20:53 +0000 (+0100) Subject: mgr/ssh: `test_mon_update` needs to set a mon name X-Git-Tag: v15.1.0~700^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=118626e8fdced976a65ae4f22cbc3e84596326ec;p=ceph-ci.git mgr/ssh: `test_mon_update` needs to set a mon name ... 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 --- diff --git a/src/pybind/mgr/orchestrator.py b/src/pybind/mgr/orchestrator.py index 15a41750655..f3528c6426f 100644 --- a/src/pybind/mgr/orchestrator.py +++ b/src/pybind/mgr/orchestrator.py @@ -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. diff --git a/src/pybind/mgr/ssh/module.py b/src/pybind/mgr/ssh/module.py index 92f0d980302..306b500d85c 100644 --- a/src/pybind/mgr/ssh/module.py +++ b/src/pybind/mgr/ssh/module.py @@ -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): diff --git a/src/pybind/mgr/ssh/tests/test_ssh.py b/src/pybind/mgr/ssh/tests/test_ssh.py index d1e8803048c..878788f7801 100644 --- a/src/pybind/mgr/ssh/tests/test_ssh.py +++ b/src/pybind/mgr/ssh/tests/test_ssh.py @@ -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")