From 74231387438c0faeb12763afaf53c87482408696 Mon Sep 17 00:00:00 2001 From: "gasperfele@fri1.uni-lj.si" Date: Mon, 18 Sep 2017 12:47:56 +0000 Subject: Changed task parameter names for dhcp_dns_predefined_ip git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@419 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414 --- kpov_judge/tasks/dhcp_dns_predefined_ip/task.py | 36 +++++++++++++------------ 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/kpov_judge/tasks/dhcp_dns_predefined_ip/task.py b/kpov_judge/tasks/dhcp_dns_predefined_ip/task.py index b37f0ff..890c7d0 100644 --- a/kpov_judge/tasks/dhcp_dns_predefined_ip/task.py +++ b/kpov_judge/tasks/dhcp_dns_predefined_ip/task.py @@ -5,7 +5,7 @@ instructions = { 'si':u""" -Ustvari tri navidezne računalnike. Za enega (SimpleArbiter) uporabi sliko diska simpleArbiter. Na drugega (DHCP_server) postavi strežnika DHCP in DNS in poskrbi, da ta računalnik dobi IP naslov {IP_NM}. Poskrbi, da bo preostali računalnik (DHCP_client) dobil naslov {IP_static}, ki mu ga določi DHCP strežnik. Poskrbi še,da DNS strežnik vrne za hostname {HOSTNAME_X} IP naslov {IP_X}. +Ustvari tri navidezne računalnike. Za enega (SimpleArbiter) uporabi sliko diska simpleArbiter. Na drugega (DHCP_server) postavi strežnika DHCP in DNS in poskrbi, da ta računalnik dobi IP naslov {IP_server}. Poskrbi, da bo preostali računalnik (DHCP_client) dobil naslov {IP_client}, ki mu ga določi DHCP strežnik. Poskrbi še,da DNS strežnik vrne za hostname {HOSTNAME_X} IP naslov {IP_X}. """ } @@ -57,14 +57,14 @@ computers = { networks = { 'net1': {'public': False}, 'test-net': {'public': True} } params_meta = { - 'IP_NM': {'descriptions': {'si': 'IP naslov DHCP streznika'}, 'w': False, 'public':True, 'type': 'IP', 'generated': True}, - 'IP_static': {'descriptions': {'si': 'IP naslov DHCP klienta'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True}, + 'IP_server': {'descriptions': {'si': 'IP naslov DHCP streznika'}, 'w': False, 'public':True, 'type': 'IP', 'generated': True}, + 'IP_client': {'descriptions': {'si': 'IP naslov DHCP klienta'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True}, 'MAC_client': {'descriptions': {'si': 'MAC naslov DHCP klienta'}, 'w': True, 'public': True, 'type': 'MAC', 'generated': False}, 'HOSTNAME_X': {'descriptions': {'si': 'Hostname za DNS'}, 'w': False, 'public': True, 'type': 'short_text', 'generated': True}, 'IP_X': {'descriptions': {'si': 'Naslov, ki ga vrne DNS'}, 'w': False, 'public': False, 'type': 'IP', 'generated': True}, } -def task(IP_NM, IP_static, MAC_client, HOSTNAME_X): +def task(IP_server, IP_client, MAC_client, HOSTNAME_X): from pexpect import pxssh #import pexpect results = dict() @@ -73,9 +73,9 @@ def task(IP_NM, IP_static, MAC_client, HOSTNAME_X): sA = pxssh.pxssh() sB = pxssh.pxssh() #prijavimo se na streznik (IP_NM je IP nalov streznika) - sA.login(IP_NM, peer_user, peer_passwd) + sA.login(IP_server, peer_user, peer_passwd) #prijavimo se na klienta (IP_static je IP naslov klienta) - sB.login(IP_static, peer_user, peer_passwd) + sB.login(IP_client, peer_user, peer_passwd) # tukaj dobimo podatke iz streznika ce je res klientu dodelil pravi naslov # mogoce tail -5 ni potreben ampak sem razmisljal da bi bilo hitreje, ce bi preverjali samo # zadnjih 5 DHCPACK vnosov @@ -85,7 +85,7 @@ def task(IP_NM, IP_static, MAC_client, HOSTNAME_X): sA.prompt() results['client_IP'] = sA.before # tukaj dobimo podatke, ce je na IP_NM naslovu res postavljen DHCP streznik - sB.sendline('sudo dhcping -s {} -h {} -c {}'.format(IP_NM, MAC_client, IP_static)) + sB.sendline('sudo dhcping -s {} -h {} -c {}'.format(IP_server, MAC_client, IP_client)) sB.sendline(peer_passwd) sB.prompt() results['dhcp'] = sB.before @@ -97,15 +97,16 @@ def task(IP_NM, IP_static, MAC_client, HOSTNAME_X): sB.logout() 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_NM'], params['IP_static'], params['IP_X'] = kpov_random_helpers.IPv4_addr_gen(r, net, 3) + params['IP_server'], params['IP_client'], params['IP_X'] = kpov_random_helpers.IPv4_addr_gen(r, net, 3) params['HOSTNAME_X'] = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ') for i in xrange(5)]) return params + def task_check(results, params): import re score = 0 @@ -113,20 +114,21 @@ def task_check(results, params): # ker je v results[dhcp] shranjen ukaz za dobivanje teh podatkov, kot tudi odgovor streznika # mora biti stevilo pojavitev streznikovega IP naslova (IP_NM) enako ali vecje od 2 # enkrat se zagotovo pojavi v ukazu in nato se mora vsaj se enkrat pojaviti tudi v odgovoru - if results['dhcp'].count(params['IP_NM']) >= 2: - score += 2 + if results['dhcp'].count(params['IP_server']) >= 2: + score += 2 else: - hints += ["dhcp wrong"] - if results['client_IP'].find("DHCPACK on " + params['IP_static'] + " to " + params['MAC_client']) >= 0: - score += 3 + hints += ["dhcp wrong"] + if results['client_IP'].find("DHCPACK on " + params['IP_client'] + " to " + params['MAC_client']) >= 0: + score += 3 else: - hints += ["client IP wrong"] + hints += ["client IP wrong"] if results['dns_hostname'].find(params['IP_X']) >= 0: - score += 5 + score += 5 else: - hints += ['dns wrong'] + hints += ['dns wrong'] return score, hints + def prepare_disks(templates, task_params, global_params): write_default_config(templates['simpleArbiterDhcp'], global_params) -- cgit v1.2.1