diff options
author | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2018-10-11 00:24:59 +0200 |
---|---|---|
committer | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2018-10-11 00:24:59 +0200 |
commit | 46f2d091510d129aac14b7d43ef66845649968dc (patch) | |
tree | 5fbc4624d52fa8dad14778e0d3586e6b7decf266 | |
parent | 71281848a3b0e95754f9c148a1ef5dafdc023aed (diff) |
kpov_util: better error reporting for SSH connections
-rwxr-xr-x | kpov_judge/kpov_util.py | 12 |
1 files changed, 9 insertions, 3 deletions
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): |