logger = logging.getLogger(__name__)
+HostSpec = namedtuple('HostSpec', ['hostname', 'network', 'name'])
+
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('', '', '')
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.
extra_args=extra_args)
def update_mons(self, num, host_specs):
+ # type: (int, List[orchestrator.HostSpec]) -> orchestrator.Completion
"""
Adjust the number of cluster monitors.
"""
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):
@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")