diff options
-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): |