summaryrefslogtreecommitdiff
path: root/kpov_judge/tasks/nat_vlc
diff options
context:
space:
mode:
Diffstat (limited to 'kpov_judge/tasks/nat_vlc')
-rw-r--r--kpov_judge/tasks/nat_vlc/task.py52
1 files changed, 17 insertions, 35 deletions
diff --git a/kpov_judge/tasks/nat_vlc/task.py b/kpov_judge/tasks/nat_vlc/task.py
index cf3947b..ffcb6c1 100644
--- a/kpov_judge/tasks/nat_vlc/task.py
+++ b/kpov_judge/tasks/nat_vlc/task.py
@@ -1,7 +1,5 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
+# kpov_util should be imported by add_assignment.py
-# kpov_random_helpers should be imported by add_assignment.py
# Poglej nek film na nekem določenem URL.
# (?md5 vsota filma?)
@@ -20,7 +18,7 @@ ustvarite še uporabnika {IP_NAT_user}.
Poskrbi, da bo SimpleArbiter prek DHCP dobil naslov {IP_simple}.
Poskrbi, da bo NATServer deloval kot prehod za SimpleArbiter in izvajal NAT.
""",
- 'en':"""
+ 'en':"""
Set up two virtual machines - SimpleArbiter (using the disc simpleArbiter) and
NATServer. NATServer should have two network adapters. Connect the first
adapter to SimpleArbiter and the second adapter to the Internet. Configure the
@@ -38,12 +36,7 @@ computers = {
'NATServer': {
'disks': [
{ 'name': 'student-NATServer',
- # attempt automount
},
- #{ 'name': 'CDROM',
- # 'options': {'readonly': True},
- # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
- #},
],
'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
'flavor': 'm1.tiny',
@@ -53,17 +46,11 @@ computers = {
'disks': [
{ 'name': 'simpleArbiter',
},
- #{ 'name': 'CDROM',
- # 'options':{'readonly': True},
- # 'parts': [],# no parts, no mounting.
- #}
],
'network_interfaces': [{'network': 'net1'}],
'flavor': 'm1.tiny',
'config_drive': False
-
},
-
}
networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
@@ -77,24 +64,19 @@ params_meta = {
}
def task(IP_simple, IP_NAT, IP_NAT_user, IP_NAT_passwd):
- from pexpect import pxssh
import pexpect
- results = dict()
- # Connect to NAT
- povezava = pxssh.pxssh()
- povezava.login(IP_NAT,IP_NAT_user,IP_NAT_passwd)
+
+ results = kpov_util.ssh_test(IP_NAT, IP_NAT_user, IP_NAT_passwd, (
+ ('IP_NAT_ip_forward', 'cat /proc/sys/net/ipv4/ip_forward'),
+ ))
+
# Check if If IP_simple is connected to NAT
- results['IP_simple_ping_to_NAT'] = pexpect.run('ping -c 5 {}'.format(IP_NAT))
+ results['IP_simple_ping_to_NAT'] = pexpect.run('ping -c 5 {}'.format(IP_NAT), encoding='utf-8')
# Check routing table on IP_simple
- results['IP_simple_routing_table'] = pexpect.run('/sbin/route -n')
+ results['IP_simple_routing_table'] = pexpect.run('route -n', encoding='utf-8', env={'PATH': '/bin:/sbin'})
# Tracert Check if IP_simple is connected to internet
- povezava.prompt()
- results['IP_simple_to_internet'] = pexpect.run('/usr/sbin/traceroute 8.8.8.8')
- povezava.prompt()
- povezava.sendline('cat /proc/sys/net/ipv4/ip_forward')
- povezava.prompt()
- results['IP_NAT_ip_forward'] = povezava.before
- povezava.logout()
+ results['IP_simple_to_internet'] = pexpect.run('traceroute 8.8.8.8', encoding='utf-8')
+
return results
def gen_params(user_id, params_meta):
@@ -102,12 +84,12 @@ def gen_params(user_id, params_meta):
r = random.Random(user_id)
# IP_NM, DNS_NM, IP_static, DNS_static)
# dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
- net = kpov_random_helpers.IPv4_net_gen(r, 253, True, False)
+ net = kpov_util.IPv4_net_gen(r, 253, True, False)
# params['DNS_NM'] = r.choice(dns_servers)
- params['IP_NAT'], params['IP_simple'] = kpov_random_helpers.IPv4_addr_gen(r, net, 2)
- params['IP_NAT_user'] = kpov_random_helpers.default_generators['username'](r)
+ params['IP_NAT'], params['IP_simple'] = kpov_util.IPv4_addr_gen(r, net, 2)
+ params['IP_NAT_user'] = kpov_util.default_generators['username'](r)
# params['IP_NM']
- # params['IP_simple'] = kpov_random_helpers.IPv4_addr_gen(r, net, 1)
+ # params['IP_simple'] = kpov_util.IPv4_addr_gen(r, net, 1)
# params['DNS_static'] = r.choice(dns_servers)
return params
@@ -121,8 +103,8 @@ def task_check(results, params):
score += 3
else:
hints.append("Ping to NAT incorrect")
- if results['IP_NAT_ip_forward']=="cat /proc/sys/net/ipv4/ip_forward\r\n1\r\n":
- score += 2
+ if results['IP_NAT_ip_forward'].strip() == "1":
+ score += 2
else:
hints.append("ip_forward not set on NAT?")
rs = r"1 +{0} +\({0}\)".format(params['IP_NAT'])