]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: check hostname resolution before adding host
authorDaniel Pivonka <dpivonka@redhat.com>
Mon, 19 Apr 2021 21:21:06 +0000 (17:21 -0400)
committerSage Weil <sage@newdream.net>
Tue, 4 May 2021 16:22:50 +0000 (11:22 -0500)
Signed-off-by: Daniel Pivonka <dpivonka@redhat.com>
(cherry picked from commit 459ffb52a15f8870dd45d3ec163ed27c1467623e)

src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/tests/fixtures.py

index 2c28cd67ab616b901ca5f1f9e3521898adee3646..4a8454e12840f38b19ae910b24b18b9fd0354f74 100644 (file)
@@ -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,
index f3d27b352534bc31d6c00fbbdcd61dc19d47da55..4a8a4e30a9892f93b6f8b1f589effa89d887c9bc 100644 (file)
@@ -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):