From b5d39be1881775f141dfb3f10ebe4ae3601b75e6 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 3 May 2021 12:09:09 -0400 Subject: [PATCH] mgr/cephadm: apply hostname/addr checks to 'orch host set-addr' too Signed-off-by: Sage Weil --- src/pybind/mgr/cephadm/module.py | 41 ++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 29373c9e8b87c..fa904b21e3ae8 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1359,25 +1359,18 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, ) ] - def _add_host(self, spec): - # type: (HostSpec) -> str - """ - Add a host to be managed by the orchestrator. - - :param host: host name - """ - assert_valid_host(spec.hostname) + def _check_valid_addr(self, host: str, addr: str) -> None: # make sure hostname is resolvable before trying to make a connection try: - utils.resolve_ip(spec.addr) + utils.resolve_ip(addr) except OrchestratorError as e: msg = str(e) + f''' -You may need to supply an address for {spec.addr} +You may need to supply an address for {addr} Please make sure that the host is reachable and accepts connections using the cephadm SSH key To add the cephadm SSH key to the host: > ceph cephadm get-pub-key > ~/ceph.pub -> ssh-copy-id -f -i ~/ceph.pub {self.ssh_user}@{spec.addr} +> ssh-copy-id -f -i ~/ceph.pub {self.ssh_user}@{addr} To check that the host is reachable open a new shell with the --no-hosts flag: > cephadm shell --no-hosts @@ -1386,19 +1379,30 @@ Then run the following: > ceph cephadm get-ssh-config > ssh_config > ceph config-key get mgr/cephadm/ssh_identity_key > ~/cephadm_private_key > chmod 0600 ~/cephadm_private_key -> ssh -F ssh_config -i ~/cephadm_private_key {self.ssh_user}@{spec.addr}''' +> ssh -F ssh_config -i ~/cephadm_private_key {self.ssh_user}@{addr}''' raise OrchestratorError(msg) - out, err, code = CephadmServe(self)._run_cephadm(spec.hostname, cephadmNoImage, 'check-host', - ['--expect-hostname', spec.hostname], - addr=spec.addr, - error_ok=True, no_fsid=True) + out, err, code = CephadmServe(self)._run_cephadm( + host, cephadmNoImage, 'check-host', + ['--expect-hostname', host], + addr=addr, + error_ok=True, no_fsid=True) if code: # err will contain stdout and stderr, so we filter on the message text to # only show the errors errors = [_i.replace("ERROR: ", "") for _i in err if _i.startswith('ERROR')] - raise OrchestratorError('New host %s (%s) failed check(s): %s' % ( - spec.hostname, spec.addr, errors)) + raise OrchestratorError('Host %s (%s) failed check(s): %s' % ( + host, addr, errors)) + + def _add_host(self, spec): + # type: (HostSpec) -> str + """ + Add a host to be managed by the orchestrator. + + :param host: host name + """ + assert_valid_host(spec.hostname) + self._check_valid_addr(spec.hostname, spec.addr) # prime crush map? if spec.location: @@ -1438,6 +1442,7 @@ Then run the following: @handle_orch_error def update_host_addr(self, host: str, addr: str) -> str: + self._check_valid_addr(host, addr) self.inventory.set_addr(host, addr) self._reset_con(host) self.event.set() # refresh stray health check -- 2.39.5