From: Adam King Date: Wed, 15 Mar 2023 17:18:02 +0000 (-0400) Subject: mgr/cephadm: handle HostConnectionError when checking for valid addr X-Git-Tag: v18.1.0~130^2~17 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=81a853be25bf6f52316327e208f4208a836b2ba7;p=ceph.git mgr/cephadm: handle HostConnectionError when checking for valid addr Otherwise, the error is not properly passed back up the chain and the user can get an error message like TypeError: __init__() missing 2 required positional arguments: 'hostname' and 'addr' when trying to add a host, despite the actual problem being cephadm.ssh.HostConnectionError: Failed to connect to vm-01 (192.168.122.248). Permission denied The tracker shows a bit more, but generally trying to add a host that doesn't have the proper pub-key set as an authorized key will get a misleasing error message. With this patch, the error message looks like [ceph: root@vm-00 /]# ceph orch host add vm-01 192.168.122.29 Error EINVAL: Failed to connect to vm-01 (192.168.122.29). Permission denied Log: Opening SSH connection to 192.168.122.29, port 22 [conn=1] Connected to SSH server at 192.168.122.29, port 22 [conn=1] Local address: 192.168.122.156, port 49552 [conn=1] Peer address: 192.168.122.29, port 22 [conn=1] Beginning auth for user root [conn=1] Auth failed for user root [conn=1] Connection failure: Permission denied [conn=1] Aborting connection which is much more useful Fixes: https://tracker.ceph.com/issues/59081 Signed-off-by: Adam King (cherry picked from commit efc6c585562ceda55a37ae591bf3c15ab35cdda8) --- diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 39a2cc83d3ab9..27ddbd5490e53 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1492,19 +1492,22 @@ Then run the following: self.log.debug( f'Received loopback address resolving ip for {host}: {ip_addr}. Falling back to previous address.') ip_addr = self.inventory.get_addr(host) - out, err, code = self.wait_async(CephadmServe(self)._run_cephadm( - host, cephadmNoImage, 'check-host', - ['--expect-hostname', host], - addr=addr, - error_ok=True, no_fsid=True)) - if code: - msg = 'check-host failed:\n' + '\n'.join(err) - # err will contain stdout and stderr, so we filter on the message text to - # only show the errors - errors = [_i.replace("ERROR: ", "") for _i in err if _i.startswith('ERROR')] - if errors: - msg = f'Host {host} ({addr}) failed check(s): {errors}' - raise OrchestratorError(msg) + try: + out, err, code = self.wait_async(CephadmServe(self)._run_cephadm( + host, cephadmNoImage, 'check-host', + ['--expect-hostname', host], + addr=addr, + error_ok=True, no_fsid=True)) + if code: + msg = 'check-host failed:\n' + '\n'.join(err) + # err will contain stdout and stderr, so we filter on the message text to + # only show the errors + errors = [_i.replace("ERROR: ", "") for _i in err if _i.startswith('ERROR')] + if errors: + msg = f'Host {host} ({addr}) failed check(s): {errors}' + raise OrchestratorError(msg) + except ssh.HostConnectionError as e: + raise OrchestratorError(str(e)) return ip_addr def _add_host(self, spec):