summaryrefslogtreecommitdiff
path: root/kpov_judge/tasks/dhcp_dns_predefined_ip
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2018-10-07 19:02:26 +0200
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2018-10-07 19:04:21 +0200
commitb5b35faea7f4205f353f57178ddc795b7dce5043 (patch)
treef8531a61d236ea0abc4e9dc80692abdc36c6579a /kpov_judge/tasks/dhcp_dns_predefined_ip
parent42076466e00aa066769050bb2e2b4d98e9cc4d20 (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/dhcp_dns_predefined_ip')
-rw-r--r--kpov_judge/tasks/dhcp_dns_predefined_ip/task.py43
1 files changed, 12 insertions, 31 deletions
diff --git a/kpov_judge/tasks/dhcp_dns_predefined_ip/task.py b/kpov_judge/tasks/dhcp_dns_predefined_ip/task.py
index 2559507..9d98ea4 100644
--- a/kpov_judge/tasks/dhcp_dns_predefined_ip/task.py
+++ b/kpov_judge/tasks/dhcp_dns_predefined_ip/task.py
@@ -65,37 +65,19 @@ params_meta = {
}
def task(IP_server, IP_client, MAC_client, HOSTNAME_X):
- from pexpect import pxssh
- #import pexpect
- results = dict()
- peer_user = 'student'
- peer_passwd = 'vaje'
- sA = pxssh.pxssh()
- sB = pxssh.pxssh()
- #prijavimo se na streznik (IP_NM je IP nalov streznika)
- sA.login(IP_server, peer_user, peer_passwd)
- #prijavimo se na klienta (IP_static je IP naslov klienta)
- sB.login(IP_client, peer_user, peer_passwd)
- sA.sendline('sudo ps -A')
- sA.sendline(peer_passwd)
- sA.prompt()
- results['dhcp_proces'] = sA.before
- # tukaj dobimo podatke, ce je na IP_NM naslovu res postavljen DHCP streznik
- sB.sendline('sudo dhcping -s {} -h {} -c {}'.format(IP_server, MAC_client, IP_client))
- sB.sendline(peer_passwd)
- sB.prompt()
- results['dhcp'] = sB.before
- # tukaj pa dobimo podatek, ce je IP, ki ga vraca DNS streznik za HOSTNAME_X pravilen
- sB.sendline('nslookup {}'.format(HOSTNAME_X))
- sB.prompt()
- results['dns_hostname'] = sB.before
- sB.sendline('/sbin/ifconfig')
- sB.prompt()
- results['client_IP'] = sB.before
- sA.logout()
- sB.logout()
- return results
+ tests = {
+ IP_server: (
+ ('dhcp_proces', 'sudo ps -A')),
+ IP_client: (
+ ('dhcp', 'sudo dhcping -s {} -h {} -c {}'.format(IP_server, MAC_client, IP_client)),
+ ('dns_hostname', 'nslookup {}'.format(HOSTNAME_X)),
+ ('client_IP', '/sbin/ifconfig')),
+ }
+ results = collections.defaultdict(str)
+ for host, host_tests in tests.items():
+ results.update(kpov_util.ssh_test(host, 'student', 'vaje', host_tests))
+ return results
def gen_params(user_id, params_meta):
params = dict()
@@ -105,7 +87,6 @@ def gen_params(user_id, params_meta):
params['HOSTNAME_X'] = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ') for i in range(5)])
return params
-
def task_check(results, params):
import re
score = 0