From 9c51bbe5016495c714789f5df01806a6d366e11a Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sat, 6 Oct 2018 23:56:03 +0200 Subject: Rename kpov_random_helpers to kpov_util --- kpov_judge/tasks/nat_vlc/task.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'kpov_judge/tasks/nat_vlc') diff --git a/kpov_judge/tasks/nat_vlc/task.py b/kpov_judge/tasks/nat_vlc/task.py index cf3947b..89d0f13 100644 --- a/kpov_judge/tasks/nat_vlc/task.py +++ b/kpov_judge/tasks/nat_vlc/task.py @@ -1,7 +1,7 @@ #!/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 # Poglej nek film na nekem določenem URL. # (?md5 vsota filma?) @@ -102,12 +102,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 -- cgit v1.2.1 From b5b35faea7f4205f353f57178ddc795b7dce5043 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sun, 7 Oct 2018 19:02:26 +0200 Subject: Refactor SSH testing code out of individual tasks Catch SSH errors and report failures as hints. Also some cleanups and 2to3 fixes. --- kpov_judge/tasks/nat_vlc/task.py | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) (limited to 'kpov_judge/tasks/nat_vlc') diff --git a/kpov_judge/tasks/nat_vlc/task.py b/kpov_judge/tasks/nat_vlc/task.py index 89d0f13..ed24b95 100644 --- a/kpov_judge/tasks/nat_vlc/task.py +++ b/kpov_judge/tasks/nat_vlc/task.py @@ -20,7 +20,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 +38,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 +48,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 +66,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): @@ -121,8 +105,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']) -- cgit v1.2.1 From 3091fc2877600f7926ed6a596c316183499125f8 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sun, 7 Oct 2018 19:11:49 +0200 Subject: Remove coding: lines Python 3 source is utf-8 by default. --- kpov_judge/tasks/nat_vlc/task.py | 1 - 1 file changed, 1 deletion(-) (limited to 'kpov_judge/tasks/nat_vlc') diff --git a/kpov_judge/tasks/nat_vlc/task.py b/kpov_judge/tasks/nat_vlc/task.py index ed24b95..8536fd5 100644 --- a/kpov_judge/tasks/nat_vlc/task.py +++ b/kpov_judge/tasks/nat_vlc/task.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- # kpov_util should be imported by add_assignment.py # Poglej nek film na nekem določenem URL. -- cgit v1.2.1 From dbf585c2a59dbcb7f6d803d5756826b562cd7f43 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sun, 7 Oct 2018 19:38:40 +0200 Subject: Fix or remove hashbangs --- kpov_judge/tasks/nat_vlc/task.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'kpov_judge/tasks/nat_vlc') diff --git a/kpov_judge/tasks/nat_vlc/task.py b/kpov_judge/tasks/nat_vlc/task.py index 8536fd5..ffcb6c1 100644 --- a/kpov_judge/tasks/nat_vlc/task.py +++ b/kpov_judge/tasks/nat_vlc/task.py @@ -1,6 +1,5 @@ -#!/usr/bin/env python - # kpov_util should be imported by add_assignment.py + # Poglej nek film na nekem določenem URL. # (?md5 vsota filma?) -- cgit v1.2.1