mgr/cephadm: apply hostname/addr checks to 'orch host set-addr' too

Signed-off-by: Sage Weil <sage@newdream.net>
This commit is contained in:
Sage Weil 2021-05-03 12:09:09 -04:00
parent a8acc354dc
commit b5d39be188

View File

@ -1359,25 +1359,18 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule,
) )
] ]
def _add_host(self, spec): def _check_valid_addr(self, host: str, addr: str) -> None:
# type: (HostSpec) -> str
"""
Add a host to be managed by the orchestrator.
:param host: host name
"""
assert_valid_host(spec.hostname)
# make sure hostname is resolvable before trying to make a connection # make sure hostname is resolvable before trying to make a connection
try: try:
utils.resolve_ip(spec.addr) utils.resolve_ip(addr)
except OrchestratorError as e: except OrchestratorError as e:
msg = str(e) + f''' 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 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: To add the cephadm SSH key to the host:
> ceph cephadm get-pub-key > ~/ceph.pub > 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: To check that the host is reachable open a new shell with the --no-hosts flag:
> cephadm shell --no-hosts > cephadm shell --no-hosts
@ -1386,19 +1379,30 @@ Then run the following:
> ceph cephadm get-ssh-config > ssh_config > ceph cephadm get-ssh-config > ssh_config
> ceph config-key get mgr/cephadm/ssh_identity_key > ~/cephadm_private_key > ceph config-key get mgr/cephadm/ssh_identity_key > ~/cephadm_private_key
> chmod 0600 ~/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) raise OrchestratorError(msg)
out, err, code = CephadmServe(self)._run_cephadm(spec.hostname, cephadmNoImage, 'check-host', out, err, code = CephadmServe(self)._run_cephadm(
['--expect-hostname', spec.hostname], host, cephadmNoImage, 'check-host',
addr=spec.addr, ['--expect-hostname', host],
error_ok=True, no_fsid=True) addr=addr,
error_ok=True, no_fsid=True)
if code: if code:
# err will contain stdout and stderr, so we filter on the message text to # err will contain stdout and stderr, so we filter on the message text to
# only show the errors # only show the errors
errors = [_i.replace("ERROR: ", "") for _i in err if _i.startswith('ERROR')] errors = [_i.replace("ERROR: ", "") for _i in err if _i.startswith('ERROR')]
raise OrchestratorError('New host %s (%s) failed check(s): %s' % ( raise OrchestratorError('Host %s (%s) failed check(s): %s' % (
spec.hostname, spec.addr, errors)) 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? # prime crush map?
if spec.location: if spec.location:
@ -1438,6 +1442,7 @@ Then run the following:
@handle_orch_error @handle_orch_error
def update_host_addr(self, host: str, addr: str) -> str: def update_host_addr(self, host: str, addr: str) -> str:
self._check_valid_addr(host, addr)
self.inventory.set_addr(host, addr) self.inventory.set_addr(host, addr)
self._reset_con(host) self._reset_con(host)
self.event.set() # refresh stray health check self.event.set() # refresh stray health check