summaryrefslogtreecommitdiff
path: root/kpov_judge/tasks/nat_vlc/task.py
diff options
context:
space:
mode:
authorgasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414>2016-12-29 23:43:31 +0000
committergasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414>2016-12-29 23:43:31 +0000
commite11077772bf32f25613f4f559feee8c963ea5dda (patch)
treee770210a5e750cf323c77ffc928bdc35115feb14 /kpov_judge/tasks/nat_vlc/task.py
parent110ab9c64c408dce2345f134989f5d15bcce42ae (diff)
Fixes to multiple tasks
git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@377 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414
Diffstat (limited to 'kpov_judge/tasks/nat_vlc/task.py')
-rw-r--r--kpov_judge/tasks/nat_vlc/task.py60
1 files changed, 33 insertions, 27 deletions
diff --git a/kpov_judge/tasks/nat_vlc/task.py b/kpov_judge/tasks/nat_vlc/task.py
index b43dd90..59cceaa 100644
--- a/kpov_judge/tasks/nat_vlc/task.py
+++ b/kpov_judge/tasks/nat_vlc/task.py
@@ -70,13 +70,10 @@ networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
#ne potrebujemo dnsjev in ip za malibreznewtork manager?
params_meta = {
-# 'IP_NM': {'descriptions': {'si': 'Naslov maliNetworkManager'}, 'w': False, 'public':True, 'type': 'IP', 'generated': True},
-# 'DNS_NM': {'descriptions': {'si': 'DNS za maliNetworkManager'}, 'w': False, 'public':True, 'type': 'IP', 'generated': True},
- 'IP_simple': {'descriptions': {'si': 'Naslov SimpleArbiter'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True},
- 'IP_NAT': {'descriptions': {'si': 'Naslov NAT'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True },
- 'IP_NAT_user': {'descriptions': {'si': 'Username na NATServer'}, 'w': False, 'public' : True, 'type' : 'username', 'generated' : True},
- 'IP_NAT_passwd': {'descriptions': {'si': 'Password na NATServer'}, 'w': True,'public' : True, 'type' : 'passwd', 'generated' : False},
-# 'DNS_static': {'descriptions': {'si': 'DNS za maliBrezNetworkManager'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'IP_simple': {'descriptions': {'si': 'Naslov SimpleArbiter', 'en': 'SimpleArbiter address'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'IP_NAT': {'descriptions': {'si': 'Naslov NATServer', 'en': 'NATServer address'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True },
+ 'IP_NAT_user': {'descriptions': {'si': 'Username na NATServer', 'en': 'Username on NATServer'}, 'w': False, 'public' : True, 'type' : 'username', 'generated' : True},
+ 'IP_NAT_passwd': {'descriptions': {'si': 'Password na NATServer', 'en': 'Password on NATServer'}, 'w': True,'public' : True, 'type' : 'passwd', 'generated' : False},
}
def task(IP_simple, IP_NAT, IP_NAT_user, IP_NAT_passwd):
@@ -85,22 +82,19 @@ def task(IP_simple, IP_NAT, IP_NAT_user, IP_NAT_passwd):
results = dict()
# Connect to NAT
povezava = pxssh.pxssh()
- povezava.login(IP_NAT,IP_NAT_user,IP_NAT_passwd)
-
+ povezava.login(IP_NAT,IP_NAT_user,IP_NAT_passwd)
# Check if If IP_simple is connected to NAT
- results['IP_simple ping to NAT'] = run('ping -c 5 IP_NAT')
+ results['IP_simple_ping_to_NAT'] = pexpect.run('ping -c 5 {}'.format(IP_NAT))
# Check routing table on IP_simple
- results['IP_simple routing table'] = run('route -n')
+ results['IP_simple_routing_table'] = pexpect.run('/sbin/route -n')
# Tracert Check if IP_simple is connected to internet
- results['IP_simple to internet'] = run('traceroute 8.8.8.8')
- # Check DNS
- results['IP_simple dns'] = run('nslookup www.google.com')
- # Check if IP_NAT ip forward is not 0
+ 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_NAT_ip_forward'] = povezava.before
+ povezava.logout()
return results
def gen_params(user_id, params_meta):
@@ -111,6 +105,7 @@ def gen_params(user_id, params_meta):
net = kpov_random_helpers.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_NM']
# params['IP_simple'] = kpov_random_helpers.IPv4_addr_gen(r, net, 1)
# params['DNS_static'] = r.choice(dns_servers)
@@ -120,17 +115,28 @@ def task_check(results, params):
import re
score = 0
hints = []
- if re.search(r'0% packet loss',results['IP_simple ping to NAT']):
- score += 2
- if results['IP_NAT ip forward']=='1':
- score += 2
- if not re.search(r'Network is unreachable',results['IP_simple to internet']):
- score += 2
- if re.search(r'94.140.66.250',results['IP_simple dns']):
+ if re.search(
+ "PING.*\r\n64 bytes from {}: icmp_seq=[0-9]+ ttl=64 time=[0-9.]* ms".format(
+ params['IP_NAT']), results['IP_simple_ping_to_NAT']):
+ 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
- gateway='0.0.0.0\t'+params['IP_NAT']
- if re.search(gateway,results['IP_simple routing table']):
- score += 2
+ else:
+ hints.append("ip_forward not set on NAT?")
+ rs = r"1 +{0} +\({0}\)".format(params['IP_NAT'])
+ if re.search(rs,
+ results['IP_simple_to_internet']):
+ score += 3
+ else:
+ hints.append("traceroute not OK")
+ gateway=r'0\.0\.0\.0 +{} +0\.0\.0\.0 +UG'.format(params['IP_NAT'].replace('.', '\.'))
+ if re.search(gateway,results['IP_simple_routing_table']) and \
+ re.search("Kernel IP routing table\r\nDestination", results['IP_simple_routing_table']):
+ score += 2
+ else:
+ hints.append("route not OK")
return score, hints
def prepare_disks(templates, task_params, global_params):