From b5b35faea7f4205f353f57178ddc795b7dce5043 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sun, 7 Oct 2018 19:02:26 +0200 Subject: Refactor SSH testing code out of individual tasks Catch SSH errors and report failures as hints. Also some cleanups and 2to3 fixes. --- kpov_judge/tasks/set_ip_static_dhcp/task.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'kpov_judge/tasks/set_ip_static_dhcp') 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): -- cgit v1.2.1