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: v16.2.5~39^2~4^2^2~5 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=64f7aac1f54c479771cce66e1363024978de6735;p=ceph.git mgr/cephadm: check hostname resolution before adding host Signed-off-by: Daniel Pivonka (cherry picked from commit 459ffb52a15f8870dd45d3ec163ed27c1467623e) --- diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 2c28cd67ab616..4a8454e12840f 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1367,6 +1367,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 f3d27b352534b..4a8a4e30a9892 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):