From fb1ebb9dc1071a96b3b2e4e85be5744e4a18416c Mon Sep 17 00:00:00 2001 From: Adam King Date: Tue, 30 Jun 2020 17:49:09 -0400 Subject: [PATCH] mgr/cephadm: check-host should not fail as hard using fqdn Print error message instead of traceback when check-host fails in due to host address not being found Fixes: https://tracker.ceph.com/issues/45724 Signed-off-by: Adam King --- src/pybind/mgr/cephadm/module.py | 21 +++++++++++++------- src/pybind/mgr/cephadm/tests/test_cephadm.py | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 0f1ca5a266060..c83d0d2e17304 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -844,12 +844,17 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): 'name=addr,type=CephString,req=false', 'Check whether we can access and manage a remote host') def check_host(self, host, addr=None): - out, err, code = self._run_cephadm(host, 'client', 'check-host', - ['--expect-hostname', host], - addr=addr, - error_ok=True, no_fsid=True) - if code: - return 1, '', ('check-host failed:\n' + '\n'.join(err)) + try: + out, err, code = self._run_cephadm(host, 'client', 'check-host', + ['--expect-hostname', host], + addr=addr, + error_ok=True, no_fsid=True) + if code: + return 1, '', ('check-host failed:\n' + '\n'.join(err)) + except OrchestratorError as e: + self.log.exception(f"check-host failed for '{host}'") + return 1, '', ('check-host failed:\n' + + f"Host '{host}' not found. Use 'ceph orch host ls' to see all managed hosts.") # if we have an outstanding health alert for this host, give the # serve thread a kick if 'CEPHADM_HOST_CHECK_FAILED' in self.health_checks: @@ -878,7 +883,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): self.event.set() return 0, '%s (%s) ok' % (host, addr), err - def _get_connection(self, host): + def _get_connection(self, host: str): """ Setup a connection for running commands on remote host. """ @@ -933,6 +938,8 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): try: try: + if not addr: + raise OrchestratorError("host address is empty") conn, connr = self._get_connection(addr) except OSError as e: self._reset_con(host) diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index ad7f510d990e6..c3938af945a19 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -579,7 +579,7 @@ class TestCephadm(object): _get_connection.side_effect = HostNotFound code, out, err = cephadm_module.check_host('test') assert out == '' - assert 'Failed to connect to test (test)' in err + assert "Host 'test' not found" in err out = wait(cephadm_module, cephadm_module.get_hosts())[0].to_json() assert out == HostSpec('test', 'test', status='Offline').to_json() -- 2.39.5