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 20:21:31 +0200
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2018-10-07 20:21:31 +0200
commit80f050080ce11c6a0cce67c9b0281c09702b00d6 (patch)
treeb486e1f6342bc757dda87df4856084f652895791 /kpov_judge/tasks/dhcp_dns_predefined_ip
parent43d7ef057b4ae752a60b947e523b3a56782bf5cd (diff)
parentdbf585c2a59dbcb7f6d803d5756826b562cd7f43 (diff)
Merge branch 'fix-tasks'
Fixes pexpect usage in most tasks. Several other cleanups and minor refactoring.
Diffstat (limited to 'kpov_judge/tasks/dhcp_dns_predefined_ip')
-rw-r--r--kpov_judge/tasks/dhcp_dns_predefined_ip/task.py52
1 files changed, 15 insertions, 37 deletions
diff --git a/kpov_judge/tasks/dhcp_dns_predefined_ip/task.py b/kpov_judge/tasks/dhcp_dns_predefined_ip/task.py
index 40507d5..fb0de84 100644
--- a/kpov_judge/tasks/dhcp_dns_predefined_ip/task.py
+++ b/kpov_judge/tasks/dhcp_dns_predefined_ip/task.py
@@ -1,7 +1,4 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-# kpov_random_helpers should be imported by add_assignment.py
+# kpov_util should be imported by add_assignment.py
instructions = {
'si':"""
@@ -65,47 +62,28 @@ 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()
r = random.Random(user_id+"bla")
- net = kpov_random_helpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
- params['IP_server'], params['IP_client'], params['IP_X'] = kpov_random_helpers.IPv4_addr_gen(r, net, 3)
+ net = kpov_util.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['IP_server'], params['IP_client'], params['IP_X'] = kpov_util.IPv4_addr_gen(r, net, 3)
params['HOSTNAME_X'] = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ') for i in range(5)])
return params
-
def task_check(results, params):
import re
score = 0