summaryrefslogtreecommitdiff
path: root/kpov_judge/tasks
diff options
context:
space:
mode:
authorgasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414>2016-10-13 12:35:24 +0000
committergasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414>2016-10-13 12:35:24 +0000
commit5d333259666b671f6be9ef4f99dbc91ec72b843c (patch)
treeec17cda105fe751b89348016c039eabf57e8dd89 /kpov_judge/tasks
parent4d30c6493bb746c03cbf7a8b9268b628a6c6dddd (diff)
Fixed the dhcp task.
git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@368 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414
Diffstat (limited to 'kpov_judge/tasks')
-rw-r--r--kpov_judge/tasks/isc_dhcp_live_boot/task.py52
1 files changed, 34 insertions, 18 deletions
diff --git a/kpov_judge/tasks/isc_dhcp_live_boot/task.py b/kpov_judge/tasks/isc_dhcp_live_boot/task.py
index 22d0e79..b7dfbee 100644
--- a/kpov_judge/tasks/isc_dhcp_live_boot/task.py
+++ b/kpov_judge/tasks/isc_dhcp_live_boot/task.py
@@ -14,7 +14,8 @@ SimpleArbiter naj dobi {IP_GW}. DHCP_server naj ga uporabi kot gateway.
Če se zaganja BootableClientB, naj se sistem zažene v datoteko z imenom {BOOT_FNAME}.
Če se zaganja katerikoli drug, naj se sistem zažene z živega USB, ki ga predstavlja
-slika diska bootable_usb.
+slika diska bootable_usb, ime datoteke z zagonskim nalagalnikom pa naj bo
+kakršno koli razen {BOOT_FNAME}.
Živi USB priklopite na na DHCP_server ter z njega poberite datoteke, potrebne za zagon.
Datoteke z nastavitvami za PXELinux, ki jih najdete na živem USB,
@@ -33,7 +34,7 @@ serve it {IP_GW}. DHCP_server should use SimpleArbiter as it's gateway.
If BootableClientB tries to boot over the network, have the DHCP server tell it
to boot from the file {BOOT_FNAME}. If any other system tries to boot over the
network, have it boot from a live USB drive represented by the disk image
-bootable_usb.
+bootable_usb and have the bootloader filename be different from {BOOT_FNAME}.
Connect the live USB to DHCP_server and copy the files neccessarry for it to
boot. The PXELinux configuration files must be the same as the ones found on
@@ -107,6 +108,7 @@ def task(IP_DHCP, IP_GW, MAC_BOOT, BOOT_FNAME):
import re
import tftpy
import StringIO
+ import time
results={}
# TODO (polz): Please use pexpect instead of os.system, it's much nicer.
# Also, test your functions. This function was obviously never run.
@@ -121,21 +123,24 @@ def task(IP_DHCP, IP_GW, MAC_BOOT, BOOT_FNAME):
# dhcping -h MAC_BOOT -c IP_BOOT -V -r
# could work (but you should test it)
ip_str = pexpect.run('ip addr show')
- eth_re_str = "ether (([0-9a-f]{{2}}:){{5}}[0-9a-f]{{2}})(.*)\r\n(.*){}(.*)\s(\w*)\r\n"
- ip_re = re.search(eth_re_str.format(DHCP_IP), ip_str)
+ eth_re_str = r"ether (([0-9a-f]{{2}}:){{5}}[0-9a-f]{{2}})(.*)\r\n(.*){}(.*)\s(\w*)\r\n"
+ # print eth_re_str.format(IP_DHCP)
+ # print ip_str
+ ip_re = re.search(eth_re_str.format(IP_GW), ip_str)
mac_SA = ip_re.group(1)
eth_dev_SA = ip_re.group(6)
dhcpdump = pexpect.spawn("sudo dhcpdump -i {}".format(eth_dev_SA))
- results['dhcping_other'] = pexpect.run('sudo dhcping -s {} -h {}'.format(
- IP_DHCP, MAC_BOOT))
+ time.sleep(2)
+ results['dhcping_other'] = pexpect.run('sudo dhcping -s {} -h {} -c {}'.format(
+ IP_DHCP, MAC_BOOT, IP_GW))
dhcpdump.expect('---------------------------------------------------------------------------')
results['dhcpdump_other_req'] = dhcpdump.before
dhcpdump.expect('---------------------------------------------------------------------------')
results['dhcpdump_other_reply'] = dhcpdump.before
dhcpdump.expect('---------------------------------------------------------------------------')
results['dhcpdump_other_release'] = dhcpdump.before
- results['dhcping_SA'] = pexpect.run('sudo dhcping -s {} -h {}'.format(
- IP_DHCP, mac_SA))
+ results['dhcping_SA'] = pexpect.run('sudo dhcping -s {} -h {} -c {}'.format(
+ IP_DHCP, mac_SA, IP_GW))
dhcpdump.expect('---------------------------------------------------------------------------')
results['dhcpdump_SA_req'] = dhcpdump.before
dhcpdump.expect('---------------------------------------------------------------------------')
@@ -144,8 +149,9 @@ def task(IP_DHCP, IP_GW, MAC_BOOT, BOOT_FNAME):
results['dhcpdump_SA_release'] = dhcpdump.before
dhcpdump.sendintr()
tftp_client = pexpect.spawn('tftp {}'.format(IP_DHCP))
+ tftp_client.expect(r'tftp>')
tftp_client.sendline('get pxelinux.cfg/default /dev/stdout')
- tftp_client.expect(r'Received \d* bytes in \d*\.\d* seconds')
+ tftp_client.expect(r'tftp>')
results['tftp_string'] = tftp_client.before
# check whether the fname served by the dhcp server is correct
# connect to the service in the special ISO
@@ -176,23 +182,32 @@ def task_check(results, params):
score += 1
else:
hints += ["DHCP wrong"]
- p = re.search(r"FNAME:(.*)\r",
+ p = re.search(r"FNAME:(.*)\.\r",
results['dhcpdump_other_reply'])
- other_fname = p.group(1)
+ if p is not None:
+ other_fname = p.group(1).strip()
+ else:
+ other_fname = ''
if other_fname == params['BOOT_FNAME']:
score += 3
else:
- hints += ["special fname wrong"]
- p = re.search(r"FNAME:(.*)\r",
+ hints += ["special fname wrong:" + other_fname]
+ p = re.search(r"FNAME:(.*)\.\r",
results['dhcpdump_SA_reply'])
- sa_fname = p.group(1)
- if sa_fname == params['BOOT_FNAME']:
+ if p is not None:
+ sa_fname = p.group(1).strip()
+ else:
+ sa_fname = ''
+ if sa_fname != params['BOOT_FNAME']:
score += 3
else:
- hints += ["fname wrong"]
- if results['tftp_string'].split('\r\r\n')[-2] == "# " + params['TFTP_STRING']:
+ hints += ["fname wrong:" + sa_fname]
+ try:
+ special_tftp = "# " + params['TFTP_STRING']
+ tftp_end = results['tftp_string'].split('\r\r\n')[-1]
+ assert tftp_end[:len(special_tftp)] == special_tftp
score += 2
- else:
+ except:
hints += ["tftp wrong"]
return score, hints
@@ -207,6 +222,7 @@ default vesamenu.c32
prompt 0
timeout 0
# {}""".format(task_params['TFTP_STRING'])
+ d = templates['bootable_usb']
d.write('/mnt/syslinux.cfg', s)
d = templates['simpleArbiterGW']
s = """auto lo