summaryrefslogtreecommitdiff
path: root/kpov_judge
diff options
context:
space:
mode:
authorgasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414>2015-02-10 21:14:37 +0000
committergasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414>2015-02-10 21:14:37 +0000
commit0bd559d148746c2fd74536489080766f458a5dba (patch)
tree5c10d81aa38945aa56c4d9a63b4400bf97bce9f8 /kpov_judge
parente210466fd908c6964d5e354463be9b06dc1cb584 (diff)
Task 7 (smb_nfs) done; only instructions out of date
git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@272 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414
Diffstat (limited to 'kpov_judge')
-rw-r--r--kpov_judge/tasks/smb_nfs/task.py134
1 files changed, 63 insertions, 71 deletions
diff --git a/kpov_judge/tasks/smb_nfs/task.py b/kpov_judge/tasks/smb_nfs/task.py
index 7d6e481..fe264cb 100644
--- a/kpov_judge/tasks/smb_nfs/task.py
+++ b/kpov_judge/tasks/smb_nfs/task.py
@@ -66,97 +66,89 @@ computers = {
networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
params_meta = {
+ 'FILESERVER_IP': {'descriptions': {'si': 'IP streznika'}, 'w': True, 'public':True, 'type': 'IP', 'generated': False},
'FILESERVER_NAME': {'descriptions': {'si': 'Ime streznika'}, 'w': False, 'public':True, 'type': 'hostname', 'generated': True},
- 'SMB_SHARENAME': {'descriptions': {'si': 'Imenik v skupni rabi'}, 'w': False, 'public':True, 'type': 'filename', 'generated': True},
+ 'SMB_SHARENAME': {'descriptions': {'si': 'Ime imenika v skupni rabi prek SMB', 'en': 'SMB sharename'}, 'w': False, 'public':True, 'type': 'filename', 'generated': True},
'NFS_MOUNT': {'descriptions': {'si': 'Imenik, dostopen prek NFS'}, 'w': False, 'public': True, 'type': 'filename', 'generated': True},
- 'SHARED_FILENAME': {'descriptions': {'si': 'Ime datoteke, ki je deljena'}, 'w': False, 'public': True, 'type': 'filename', 'generated': True},
- 'SHARED_FILENAME_CONTENT': {'descriptions': {'si': 'Vsebina datoteke'}, 'w': False, 'public': True, 'type': 'filename', 'generated': True},
+ 'SHARED_FILENAME': {'descriptions': {'si': 'Iskana datoteka'}, 'w': False, 'public': True, 'type': 'filename', 'generated': True},
+ 'SHARED_CONTENT': {'descriptions': {'si': 'Vsebina iskane datoteke'}, 'w': False, 'public': False, 'type': 'short', 'generated': True},
+ 'SHARED_FILE_SEED': {'descriptions': {'si': 'Dodatni podatek za testiranje'}, 'w': False, 'public': True, 'type': 'filename', 'generated': True},
}
-def task(FILESERVER_NAME, NFS_MOUNT, SHARED_FILENAME, SHARED_FILENAME_CONTENT):
- import subprocess
+def task(FILESERVER_IP, FILESERVER_NAME, NFS_MOUNT, SMB_SHARENAME, SHARED_FILE_SEED):
import pexpect
- # Naslov, na katerem se nahaja streznik.
- address = FILESERVER_NAME
+ import random
# TODO: (polz) Try using pexpect instead of subprocess, it's much nicer.
# Tabela vseh mountov.
- mounts = subprocess.check_output("mount").split("\n")
# Samo mounti na streznik.
- srvmounts = []
+ results = dict()
+ results['mount'] = pexpect.run('mount')
results['try_mount_nfs'] = pexpect.run('sudo mount -t nfs {}:/{} /mnt/nfs'.format(
- FILESERVER_NAME, NFS_MOUNT))
- results['try_mount_smb'] = pexpect.run('sudo mount -t cifs //{}/{} /mnt/smb'.format(
- FILESERVER_NAME, SMB_SHARENAME))
+ FILESERVER_IP, NFS_MOUNT))
+ results['try_mount_smb'] = pexpect.run(
+ 'sudo mount -t cifs //{}/{} /mnt/smb -o ip={},guest'.format(
+ FILESERVER_NAME, SMB_SHARENAME, FILESERVER_IP))
+ results['mount_after'] = pexpect.run('mount')
results['ls_smbmount'] = pexpect.run('ls /mnt/smb')
results['ls_nfs'] = pexpect.run('ls /mnt/nfs')
- testfile = kpov_random_helpers.filename_gen()
- pexpect.run('echo "HHAHAHA" > /mnt/nfs/{}'.format(filename_gen))
-
- # Mounti so v formatu:
- # ["//SMB_NAME/<pot_do_direktorija> on NFS_MOUNT type cifs (rw)", ... ]
- # example: ["//192.168.1.92/srv/samba on /mnt/samba type cifs (rw)", ... ]
- # Seznam mora imeti vnos za NFS in SMB, morata biti obesena na pravo pot in (rw)
- # ++ PIKE za namountan SMB/NFS
- # TODO: (polz) prej ali slej tole kodo premaknite v task_check, v results pa porinite
- # le mounts (npr. results['mounts'] = mounts
- #for m in srvmounts:
- # Dobimo pot, filesystem in pravice iz mounta:
- # split = m.split()
- # pot = split[2]
- # fstype = split[4] #mogoče bomo kaj rabli?
- # pravice = split[5]
- # Preverimo če je namountano na pravilen direktorij:
- # if pot == NFS_MOUNT:
- # ++PIKE za pravo pot
- # Pregledamo datoteke v temu direktoriju:
- # ls = subprocess.check_output(["ls", pot]).split()
- # Preverimo ce je v imeniku datoteka:
- # if SHARED_FILENAME in ls:
- # Če je, primerjamo vsebino:
- # cat = subprocess.check_output(["cat", pot+"/"+SHARED_FILENAME])
- # if cat == SHARED_FILENAME_CONTENT:
- # DING DING DING PLUS PIKE ZA PRAVO VSEBINO
- # pass
- # if pravice == "(rw)":
- # BONUS PIKE ZA READ/WRITE PRAVICE
- # pass
-
- # Samo delno stestirano!
- #results = "test"
+ r = random.Random(SHARED_FILE_SEED)
+ testfile = kpov_random_helpers.fname_gen(r)
+ teststring = kpov_random_helpers.alnum_gen(r, 200)
+ with open('/mnt/nfs/{}'.format(testfile),'w') as f:
+ f.write(teststring)
+ results['filestr'] = pexpect.run(
+ 'cat /mnt/smb/{}'.format(testfile))
+ results['filels'] = pexpect.run(
+ 'ls /mnt/smb/'.format(testfile))
+ pexpect.run('rm /mnt/nfs/{}'.format(testfile))
+ results['filels_later'] = pexpect.run('ls /mnt/smb')
+ pexpect.run("sudo umount /mnt/nfs")
+ pexpect.run("sudo umount /mnt/smb")
return results
def gen_params(user_id, params_meta):
- return kpov_random_helpers.default_gen(user_id, params_meta)
+ d = kpov_random_helpers.default_gen(user_id, params_meta)
+ r = random.Random(user_id)
+ d['FILESERVER_NAME'] = kpov_random_helpers.hostname_gen(r)
+ d['SMB_SHARENAME'] = kpov_random_helpers.hostname_gen(r)
+ d['NFS_MOUNT'] = "/srv/nfs/" + kpov_random_helpers.fname_gen(r, False)
+ d['SHARED_FILENAME'] = kpov_random_helpers.fname_gen(r)
+ d['SHARED_CONTENT'] = kpov_random_helpers.fortune(r, 4096)
+ d['SHARED_FILE_SEED'] = kpov_random_helpers.alnum_gen(r, 42)
+ return d
def task_check(results, params):
-
score = 0
- names = []
- for key in results.keys():
- names.append(key)
-
- for i in range(len(names)):
- if results[names[i]] is params[names[i]]:
- score = score + 1
-
- return score
- """
- import re
- score = -9
- if results['NM_nslookup'].find('Server:\t\t{0}\r'.format(params['DNS_NM'])) > -1:
- score += 3
- if results['static_nslookup'].find('Server:\t\t{0}\r'.format(params['DNS_static'])) > -1:
- score += 3
- if re.search(r'eth0 +802-.*connected', results['NM_nmcli']):
+ r = random.Random(params['SHARED_FILE_SEED'])
+ testfile = kpov_random_helpers.fname_gen(r)
+ teststring = kpov_random_helpers.alnum_gen(r, 200)
+ # no need to check results['mount'] or results['try_mount_nfs']
+ # or results['try_mount_smb']
+ if results['mount_after'].find('//{}/{} on /mnt/smb type cifs'.format(
+ params['FILESERVER_NAME'], params['SMB_SHARENAME'])) >= 0:
score += 2
- if not re.search(r'eth0 +802-.*connected', results['static_nmcli']):
+ if results['mount_after'].find('{}:{} on /mnt/nfs type nfs'.format(
+ params['FILESERVER_IP'], params['NFS_MOUNT'])) >= 0:
+ score += 2
+ if results['ls_smbmount'].find(params['SHARED_FILENAME']) >= 0:
+ score += 1
+ if results['ls_nfs'].find(params['SHARED_FILENAME']) >= 0:
+ score += 1
+ if results['filestr'] == teststring:
+ score += 2
+ filels_later = set(results['filels_later'].split())
+ filels = set(results['filels'].split())
+ if "".join(filels - filels_later).find(testfile) >= 0:
score += 2
- score = 0
return score
- """
def prepare_disks(templates, params):
-# d = templates['simpleArbiterDhcp']
-# Asistent je pocasnela :D
- pass
+ d = templates['FileServer']
+ d.mkdir("/srv/nfs")
+ d.mkdir(params['NFS_MOUNT'])
+ d.write(params['NFS_MOUNT'] + "/" + params["SHARED_FILENAME"],
+ params["SHARED_CONTENT"])
+ d = templates['SimpleArbiter']
+ d.mkdir('/mnt/nfs')
+ d.mkdir('/mnt/smb')