From: Daniel Pivonka Date: Mon, 19 Apr 2021 21:21:06 +0000 (-0400) Subject: mgr/cephadm: check hostname resolution before adding host X-Git-Tag: v17.1.0~2121^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=459ffb52a15f8870dd45d3ec163ed27c1467623e;p=ceph.git mgr/cephadm: check hostname resolution before adding host Signed-off-by: Daniel Pivonka --- diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 75e65804aac9..bf2eb977032f 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1286,6 +1286,28 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, :param host: host name """ assert_valid_host(spec.hostname) + # make sure hostname is resolvable before trying to make a connection + try: + utils.resolve_ip(spec.addr) + except OrchestratorError as e: + msg = str(e) + f''' +You may need to supply an address for {spec.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} + +To check that the host is reachable open a new shell with the --no-hosts flag: +> cephadm shell --no-hosts + +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}''' + raise OrchestratorError(msg) + out, err, code = CephadmServe(self)._run_cephadm(spec.hostname, cephadmNoImage, 'check-host', ['--expect-hostname', spec.hostname], addr=spec.addr, diff --git a/src/pybind/mgr/cephadm/tests/fixtures.py b/src/pybind/mgr/cephadm/tests/fixtures.py index f3d27b352534..4a8a4e30a989 100644 --- a/src/pybind/mgr/cephadm/tests/fixtures.py +++ b/src/pybind/mgr/cephadm/tests/fixtures.py @@ -70,11 +70,12 @@ def wait(m, c): @contextmanager def with_host(m: CephadmOrchestrator, name, refresh_hosts=True): # type: (CephadmOrchestrator, str) -> None - wait(m, m.add_host(HostSpec(hostname=name))) - if refresh_hosts: - CephadmServe(m)._refresh_hosts_and_daemons() - yield - wait(m, m.remove_host(name)) + with mock.patch("cephadm.utils.resolve_ip"): + wait(m, m.add_host(HostSpec(hostname=name))) + if refresh_hosts: + CephadmServe(m)._refresh_hosts_and_daemons() + yield + wait(m, m.remove_host(name)) def assert_rm_service(cephadm: CephadmOrchestrator, srv_name):