diff options
author | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2018-10-07 19:02:26 +0200 |
---|---|---|
committer | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2018-10-07 19:04:21 +0200 |
commit | b5b35faea7f4205f353f57178ddc795b7dce5043 (patch) | |
tree | f8531a61d236ea0abc4e9dc80692abdc36c6579a /kpov_judge/tasks/set_ip_static_dhcp | |
parent | 42076466e00aa066769050bb2e2b4d98e9cc4d20 (diff) |
Refactor SSH testing code out of individual tasks
Catch SSH errors and report failures as hints. Also some cleanups and
2to3 fixes.
Diffstat (limited to 'kpov_judge/tasks/set_ip_static_dhcp')
-rw-r--r-- | kpov_judge/tasks/set_ip_static_dhcp/task.py | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/kpov_judge/tasks/set_ip_static_dhcp/task.py b/kpov_judge/tasks/set_ip_static_dhcp/task.py index 4cdbc14..3a3fcc6 100644 --- a/kpov_judge/tasks/set_ip_static_dhcp/task.py +++ b/kpov_judge/tasks/set_ip_static_dhcp/task.py @@ -85,23 +85,17 @@ params_meta = { def task(IP_NM, DNS_NM, IP_static, DNS_static): import collections - from pexpect import pxssh - tests = ['nmcli -c no d', 'nslookup www.arnes.si'] - results = collections.defaultdict(str) + tests = ( + ('nmcli', 'nmcli -c no d'), + ('nslookup', 'nslookup www.arnes.si'), + ) + results = collections.defaultdict(str) for name, host in [('nm', IP_NM), ('static', IP_static)]: - try: - s = pxssh.pxssh(encoding='utf-8') - s.login(host, 'student', 'vaje') - results['ssh-'+name] = True - for test in tests: - s.sendline(test) - s.prompt() - results[test.split()[0]+'-'+name] = s.before - s.logout() - except Exception as ex: - results['ssh'] = str(ex) + host_results = kpov_util.ssh_test(host, 'student', 'vaje', tests) + for key, value in host_results.items(): + results[key+'-'+name] = value return results def gen_params(user_id, params_meta): |