From 1380c6ea5327e1bb203a6b146101a097c0fd6582 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Tue, 13 Jun 2023 14:24:12 -0600 Subject: [PATCH] Improve error message when there is no SSH key Signed-off-by: Zack Cerza --- teuthology/orchestra/connection.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/teuthology/orchestra/connection.py b/teuthology/orchestra/connection.py index 1e66e8f87..ebfee2fad 100644 --- a/teuthology/orchestra/connection.py +++ b/teuthology/orchestra/connection.py @@ -96,16 +96,23 @@ def connect(user_at_host, host_key=None, keep_alive=False, timeout=60, log.debug(connect_args) - if not retry: - ssh.connect(**connect_args) - else: - # Retries are implemented using safe_while - with safe_while(sleep=1, action='connect to ' + host) as proceed: - while proceed(): - try: + try: + if not retry: + ssh.connect(**connect_args) + else: + # Retries are implemented using safe_while + with safe_while(sleep=1, action='connect to ' + host) as proceed: + while proceed(): ssh.connect(**connect_args) break - except paramiko.AuthenticationException as e: - log.error(f"Error authenticating with {host}: {str(e)}") + except paramiko.AuthenticationException as e: + log.error(f"Error authenticating with {host}: {str(e)}") + except paramiko.SSHException: + msg = f"Error authenticating with {host}" + if not key_filename: + log.error(msg + ": No SSH private key found!") + raise + else: + log.exception(msg) ssh.get_transport().set_keepalive(keep_alive) return ssh -- 2.47.3