summaryrefslogtreecommitdiff
path: root/kpov_judge/tasks/set_ip_static_dhcp
diff options
context:
space:
mode:
Diffstat (limited to 'kpov_judge/tasks/set_ip_static_dhcp')
-rw-r--r--kpov_judge/tasks/set_ip_static_dhcp/task.py68
1 files changed, 31 insertions, 37 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..f400b6e 100644
--- a/kpov_judge/tasks/set_ip_static_dhcp/task.py
+++ b/kpov_judge/tasks/set_ip_static_dhcp/task.py
@@ -84,37 +84,29 @@ params_meta = {
}
def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import collections
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()
+
+ tests = ['nmcli -c no d', 'nslookup www.arnes.si']
+ results = collections.defaultdict(str)
+
+ for name, host in [('nm', IP_NM), ('static', IP_static)]:
+ try:
+ s = pxssh.pxssh(encoding='utf-8')
+ s.login(host, 'student', 'vaje')
+ results['ssh-'+name] = True
+ for test in tests:
+ s.sendline(test)
+ s.prompt()
+ results[test.split()[0]+'-'+name] = s.before
+ s.logout()
+ except Exception as ex:
+ results['ssh'] = str(ex)
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)
params['DNS_NM'] = r.choice(dns_servers)
@@ -126,29 +118,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)
-