]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: check hostname resolution before adding host 40924/head
authorDaniel Pivonka <dpivonka@redhat.com>
Mon, 19 Apr 2021 21:21:06 +0000 (17:21 -0400)
committerDaniel Pivonka <dpivonka@redhat.com>
Mon, 19 Apr 2021 21:23:22 +0000 (17:23 -0400)
Signed-off-by: Daniel Pivonka <dpivonka@redhat.com>
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/tests/fixtures.py

index 75e65804aac9edcca6009c7c5f62b00706f7d048..bf2eb977032fe573ab07335b28b26edeca7e4536 100644 (file)
@@ -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,
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):