diff options
author | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2018-10-07 20:21:31 +0200 |
---|---|---|
committer | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2018-10-07 20:21:31 +0200 |
commit | 80f050080ce11c6a0cce67c9b0281c09702b00d6 (patch) | |
tree | b486e1f6342bc757dda87df4856084f652895791 /kpov_judge/tasks/set_ip_static_dhcp | |
parent | 43d7ef057b4ae752a60b947e523b3a56782bf5cd (diff) | |
parent | dbf585c2a59dbcb7f6d803d5756826b562cd7f43 (diff) |
Merge branch 'fix-tasks'
Fixes pexpect usage in most tasks. Several other cleanups and minor
refactoring.
Diffstat (limited to 'kpov_judge/tasks/set_ip_static_dhcp')
-rw-r--r-- | kpov_judge/tasks/set_ip_static_dhcp/task.py | 85 |
1 files changed, 29 insertions, 56 deletions
diff --git a/kpov_judge/tasks/set_ip_static_dhcp/task.py b/kpov_judge/tasks/set_ip_static_dhcp/task.py index 0553585..aac93f7 100644 --- a/kpov_judge/tasks/set_ip_static_dhcp/task.py +++ b/kpov_judge/tasks/set_ip_static_dhcp/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 instructions = { 'si':""" Ustvari tri navidezne racunalnike. Za prvega @@ -34,10 +32,6 @@ computers = { 'disks': [ { 'name': 'maliNetworkManager', }, - #{ 'name': 'CDROM', - # 'options':{'readonly': True}, - # 'parts': [],# no parts, no mounting. - #} ], 'network_interfaces': [{'network': 'net1'}], 'flavor': 'm1.tiny', @@ -48,10 +42,6 @@ computers = { 'disks': [ { 'name': 'maliBrezNetworkManager', }, - #{ 'name': 'CDROM', - # 'options':{'readonly': True}, - # 'parts': [],# no parts, no mounting. - #} ], 'network_interfaces': [{'network': 'net1'}], 'flavor': 'm1.tiny', @@ -61,12 +51,7 @@ computers = { 'SimpleArbiter': { 'disks': [ { 'name': 'simpleArbiterDhcpGW', - # attempt automount }, - #{ 'name': 'CDROM', - # 'options': {'readonly': True}, - # 'parts': [{'dev': 'b1', 'path': '/cdrom'}], - #}, ], 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}], 'flavor': 'm1.tiny', @@ -84,41 +69,27 @@ params_meta = { } def task(IP_NM, DNS_NM, IP_static, DNS_static): - from pexpect import pxssh - import pexpect - results = dict() - peer_user = 'student' - peer_passwd = 'vaje' - # sA - network manager - sA = pxssh.pxssh() - sA.login(IP_NM, peer_user, peer_passwd) - sA.sendline('nmcli -c no d') - sA.prompt() - results['NM_nmcli'] = sA.before - sA.sendline('nslookup www.arnes.si') - sA.prompt() - results['NM_nslookup'] = sA.before - sA.logout() - # sB - brez network manager - sB = pxssh.pxssh() - sB.login(IP_static, peer_user, peer_passwd) - sB.sendline('nmcli -c no d') - sB.prompt() - results['static_nmcli'] = sB.before - sB.sendline('nslookup www.arnes.si') - sB.prompt() - results['static_nslookup'] = sB.before - sB.logout() + import collections + + tests = ( + ('nmcli', 'nmcli -c no d'), + ('nslookup', 'nslookup www.arnes.si'), + ) + + results = collections.defaultdict(str) + for name, host in [('nm', IP_NM), ('static', IP_static)]: + host_results = kpov_util.ssh_test(host, 'student', 'vaje', tests) + for key, value in host_results.items(): + results[key+'-'+name] = value return results def gen_params(user_id, params_meta): params = dict() 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_subnet_gen(r, '10.94.96.0/19', 25) + net = kpov_util.IPv4_subnet_gen(r, '10.94.96.0/19', 25) params['DNS_NM'] = r.choice(dns_servers) - params['IP_NM'], params['IP_static'] = kpov_random_helpers.IPv4_addr_gen(r, net, 2) + params['IP_NM'], params['IP_static'] = kpov_util.IPv4_addr_gen(r, net, 2) params['DNS_static'] = r.choice(dns_servers) return params @@ -126,29 +97,31 @@ def task_check(results, params): import re score = 0 hints = [] - #print results, params - if results['NM_nslookup'].find(params['DNS_NM']) > -1: - # print "NM_nslookup OK" + if results['ssh-nm'] is True: + score += 1 + else: + hints += ['mali ssh failed: ' + results['ssh-nm']] + if results['ssh-static'] is True: + score += 1 + else: + hints += ['malibrez ssh failed: ' + results['ssh-static']] + if params['DNS_NM'] in results['nslookup-nm']: score += 2 else: hints += ['NM nslookup incorrect'] - if results['static_nslookup'].find(params['DNS_static']) > -1: - # print "static_nslookup OK" + if params['DNS_static'] in results['nslookup-static']: score += 2 else: hints += ['static nslookup incorrect'] - if re.search(r'e(th0|np0s3|ns3) +ethernet +connected', results['NM_nmcli']): - # print "NM_nmcli OK" - score += 3 + if re.search(r'e(th0|np0s3|ns3) +ethernet +connected', results['nmcli-nm']): + score += 2 else: hints += ['nmcli incorrect'] - if re.search(r'e(th0|np0s3|ns3) +ethernet +unmanaged', results['static_nmcli']): - # print "static_nmcli OK" - score += 3 + if re.search(r'e(th0|np0s3|ns3) +ethernet +unmanaged', results['nmcli-static']): + score += 2 else: hints += ['nmcli on malibrez incorrect'] return score, hints def prepare_disks(templates, task_params, global_params): write_default_config(templates['simpleArbiterDhcpGW'], global_params) - |