From 46f2d091510d129aac14b7d43ef66845649968dc Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 11 Oct 2018 00:24:59 +0200 Subject: kpov_util: better error reporting for SSH connections --- kpov_judge/kpov_util.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'kpov_judge') diff --git a/kpov_judge/kpov_util.py b/kpov_judge/kpov_util.py index 8520a2d..2d8ec9e 100755 --- a/kpov_judge/kpov_util.py +++ b/kpov_judge/kpov_util.py @@ -13,10 +13,12 @@ import glob import os def ssh_test(host, user, password, commands=()): + import pexpect from pexpect import pxssh + results = collections.defaultdict(str) try: - s = pxssh.pxssh(encoding='utf-8') + s = pxssh.pxssh(encoding='utf-8', timeout=10) s.login(host, user, password, original_prompt='~[#$] ', auto_prompt_reset=False) @@ -29,8 +31,12 @@ def ssh_test(host, user, password, commands=()): if test: results[test] = s.before[len(command+'\r\n'):] s.logout() - except Exception as ex: - results['ssh'] = str(ex) + except pexpect.exceptions.EOF as e: + results['ssh'] = 'connection to {} as {}/{} failed (EOF)'.format(host, user, password) + except pexpect.exceptions.TIMEOUT as e: + results['ssh'] = 'connection to {} as {}/{} failed (timeout)'.format(host, user, password) + except Exception as e: + results['ssh'] = str(e) return results def alnum_gen(r, l=1): -- cgit v1.2.1