summaryrefslogtreecommitdiff
path: root/kpov_judge
diff options
context:
space:
mode:
authorzg4121@student.uni-lj.si <zg4121@student.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414>2017-09-18 11:45:43 +0000
committerzg4121@student.uni-lj.si <zg4121@student.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414>2017-09-18 11:45:43 +0000
commit964d6311a41bf337110088a5a36c982fc4152357 (patch)
tree040ea83dc00dab9c40487606cac5677ad214df14 /kpov_judge
parent1a38dfcd64eb8c07d4b0baa024268b50e64a144c (diff)
Popravil sem nalogo dhcp_dns_predefined_ip zan gostic
git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@418 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414
Diffstat (limited to 'kpov_judge')
-rw-r--r--kpov_judge/tasks/dhcp_dns_predefined_ip/task.py115
1 files changed, 43 insertions, 72 deletions
diff --git a/kpov_judge/tasks/dhcp_dns_predefined_ip/task.py b/kpov_judge/tasks/dhcp_dns_predefined_ip/task.py
index 01a9941..b37f0ff 100644
--- a/kpov_judge/tasks/dhcp_dns_predefined_ip/task.py
+++ b/kpov_judge/tasks/dhcp_dns_predefined_ip/task.py
@@ -5,13 +5,7 @@
instructions = {
'si':u"""
-Ustvari tri navidezne računalnike. Za enega (SimpleArbiter) uporabi sliko diska simpleArbiterGW.
-Na drugega (DHCP_server) postavi strežnika DHCP in DNS. Za gateway uporabi IP naslov simple arbiterja.
-Poskrbi, da bo preostali računalnik (DHCP_client) dobil naslov {Client_IP}.
-
-Poskrbi, da bo DNS strežnik za domeno test.net vrnil naslov {HOSTNAME_X_IP}.
-DHCP_server naj za DNS strežnik uporabi {DNS_NM}.
-DHCP_client naj za DNS strežnik uporabi {DNS_static}.
+Ustvari tri navidezne računalnike. Za enega (SimpleArbiter) uporabi sliko diska simpleArbiter. Na drugega (DHCP_server) postavi strežnika DHCP in DNS in poskrbi, da ta računalnik dobi IP naslov {IP_NM}. Poskrbi, da bo preostali računalnik (DHCP_client) dobil naslov {IP_static}, ki mu ga določi DHCP strežnik. Poskrbi še,da DNS strežnik vrne za hostname {HOSTNAME_X} IP naslov {IP_X}.
"""
}
@@ -46,7 +40,7 @@ computers = {
},
'SimpleArbiter': {
'disks': [
- { 'name': 'simpleArbiterGW',
+ { 'name': 'simpleArbiterDhcp',
# attempt automount
},
#{ 'name': 'CDROM',
@@ -63,99 +57,76 @@ computers = {
networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
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_static': {'descriptions': {'si': 'Naslov maliBrezNetworkManager'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True},
- 'DNS_static': {'descriptions': {'si': 'DNS za maliBrezNetworkManager'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True},
- 'HOSTNAME_X_IP': {'descriptions': {'si': 'Naslov HOSTNAME_X'}, 'w': False, 'public':True, 'type': 'IP', 'generated': True},
- 'Client_IP': {'descriptions': {'si': 'Naslov za DHCP_Client'}, 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_NM': {'descriptions': {'si': 'IP naslov DHCP streznika'}, 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_static': {'descriptions': {'si': 'IP naslov DHCP klienta'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'MAC_client': {'descriptions': {'si': 'MAC naslov DHCP klienta'}, 'w': True, 'public': True, 'type': 'MAC', 'generated': False},
+ 'HOSTNAME_X': {'descriptions': {'si': 'Hostname za DNS'}, 'w': False, 'public': True, 'type': 'short_text', 'generated': True},
+ 'IP_X': {'descriptions': {'si': 'Naslov, ki ga vrne DNS'}, 'w': False, 'public': False, 'type': 'IP', 'generated': True},
}
-def task(IP_NM, DNS_NM, IP_static, DNS_static, HOSTNAME_X_IP, Client_IP, MAC_BOOT):
+def task(IP_NM, IP_static, MAC_client, HOSTNAME_X):
from pexpect import pxssh
- import pexpect
+ #import pexpect
results = dict()
peer_user = 'student'
peer_passwd = 'vaje'
sA = pxssh.pxssh()
sB = pxssh.pxssh()
+ #prijavimo se na streznik (IP_NM je IP nalov streznika)
sA.login(IP_NM, peer_user, peer_passwd)
+ #prijavimo se na klienta (IP_static je IP naslov klienta)
sB.login(IP_static, peer_user, peer_passwd)
- # sA
- # make sure NM is not handling eth0
- sA.sendline('nmcli -c no d')
+ # tukaj dobimo podatke iz streznika ce je res klientu dodelil pravi naslov
+ # mogoce tail -5 ni potreben ampak sem razmisljal da bi bilo hitreje, ce bi preverjali samo
+ # zadnjih 5 DHCPACK vnosov
+ sA.sendline('sudo grep DHCPACK /var/log/syslog | tail -5')
+ # in ker gre za sudo ukaz posljemo se geslo uporabnika v tem primeru gre za uporabnika student
+ sA.sendline(peer_passwd)
sA.prompt()
- results['NM_nmcli'] = sA.before
- results['NM_nslookup'] = sA.run('nslookup www.arnes.si')
- # sB
- # check whether NM is handling eth0
- sB.sendline('nmcli -c no d')
+ results['client_IP'] = sA.before
+ # tukaj dobimo podatke, ce je na IP_NM naslovu res postavljen DHCP streznik
+ sB.sendline('sudo dhcping -s {} -h {} -c {}'.format(IP_NM, MAC_client, IP_static))
+ sB.sendline(peer_passwd)
+ sB.prompt()
+ results['dhcp'] = sB.before
+ # tukaj pa dobimo podatek, ce je IP, ki ga vraca DNS streznik za HOSTNAME_X pravilen
+ sB.sendline('nslookup {}'.format(HOSTNAME_X))
sB.prompt()
- results['static_nmcli'] = sB.before
- results['static_nslookup'] = sB.run('nslookup www.arnes.si')
- # test the DNS server
- results['NM_dns_test'] = sA.run('nslookup test.net 127.0.0.1')
- # test DHCP
- results['client_ip'] = sB.run('ifconfig')
+ results['dns_hostname'] = sB.before
sA.logout()
sB.logout()
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']
+ r = random.Random(user_id+"bla")
net = kpov_random_helpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
- params['DNS_NM'] = r.choice(dns_servers)
- params['IP_NM'], params['IP_static'], params['HOSTNAME_X_IP'], params['Client_IP'] = kpov_random_helpers.IPv4_addr_gen(r, net, 4)
- params['DNS_static'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'], params['IP_X'] = kpov_random_helpers.IPv4_addr_gen(r, net, 3)
+ params['HOSTNAME_X'] = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ') for i in xrange(5)])
return params
def task_check(results, params):
import re
score = 0
hints = []
- if results['NM_nslookup'].find('Server:\t\t{0}\r'.format(params['DNS_NM'])) > -1:
- score += 2
- else:
- hints += ["NM DNS wrong"]
- if results['static_nslookup'].find('Server:\t\t{0}\r'.format(params['DNS_static'])) > -1:
- score += 2
- else:
- hints += ["Static DNS wrong"]
- if re.search(r'e(th0|np0s3|ns3) +ethernet +connected', results['NM_nmcli']):
- score += 2
+ # ker je v results[dhcp] shranjen ukaz za dobivanje teh podatkov, kot tudi odgovor streznika
+ # mora biti stevilo pojavitev streznikovega IP naslova (IP_NM) enako ali vecje od 2
+ # enkrat se zagotovo pojavi v ukazu in nato se mora vsaj se enkrat pojaviti tudi v odgovoru
+ if results['dhcp'].count(params['IP_NM']) >= 2:
+ score += 2
else:
- hints += ['nmcli incorrect']
- if re.search(r'e(th0|np0s3|ns3) +ethernet +unmanaged', results['static_nmcli']):
- score += 2
+ hints += ["dhcp wrong"]
+ if results['client_IP'].find("DHCPACK on " + params['IP_static'] + " to " + params['MAC_client']) >= 0:
+ score += 3
else:
- hints += ['nmcli on malibrez incorrect']
- if results['client_ip'].find('inet {0}'.format(params['Client_IP'])) > -1:
- score += 1
+ hints += ["client IP wrong"]
+ if results['dns_hostname'].find(params['IP_X']) >= 0:
+ score += 5
else:
- hints += ['DHCP_Client DHCP incorrect']
- if results['NM_dns_test'].find('Address: {0}'.format(params['HOSTNAME_X_IP'])) > -1:
- score += 1
- else:
- hints += ['DNS query wrong']
+ hints += ['dns wrong']
return score, hints
def prepare_disks(templates, task_params, global_params):
- d = templates['simpleArbiterGW']
- s = """auto lo
-iface lo inet loopback
-
-auto ens3
-iface ens3 inet dhcp
-
-auto enp0s3
-iface enp0s3 inet dhcp
-
-auto enp0s8
-iface enp0s8 inet dhcp
-"""
- d.write("/etc/network/interfaces", s)
- write_default_config(templates['simpleArbiterGW'], global_params)
+ write_default_config(templates['simpleArbiterDhcp'], global_params)