summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414>2015-01-31 22:00:25 +0000
committergasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414>2015-01-31 22:00:25 +0000
commite690bd20eebfa6c12b603a0e2c5705d4ec355595 (patch)
treeb69fdbb4f52c2cb29cb80ca247959b7288285495
parentd0760e008319975f04444c3fd1f30673f7260d7c (diff)
Added examples for prepare_disks and task. For now, task_check is unfinished.
git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@257 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414
-rwxr-xr-xkpov_judge/kpov_random_helpers.py1
-rw-r--r--kpov_judge/tasks/copy_rename_20_files_tail_env/task.py174
-rwxr-xr-xkpov_judge/test_prepare_disks.py8
3 files changed, 130 insertions, 53 deletions
diff --git a/kpov_judge/kpov_random_helpers.py b/kpov_judge/kpov_random_helpers.py
index c94dcb3..d26c5c6 100755
--- a/kpov_judge/kpov_random_helpers.py
+++ b/kpov_judge/kpov_random_helpers.py
@@ -116,6 +116,7 @@ default_generators = {
'username': username_gen,
'password': lambda r: alnum_gen(r, 8),
'short_text': lambda r: fortune(r, 40),
+ 'uint': lambda r: r.nextint(0, 2**32),
'hostname': lambda r: hostname_gen(r),
None: lambda r: alnum_gen(r, 8),
'': unknown_generator,
diff --git a/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py b/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py
index 112f85d..864d143 100644
--- a/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py
+++ b/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py
@@ -9,8 +9,8 @@ Prijavi se na sistem kot uporabnik student z geslom vaje.
V domači mapi najdeš imenik Mapa z 20 datotekami.
- Preimenuj vse datoteke tako, da zamenjaš minuse s podčrtaji
- Napiši čim krajši ukaz v bash, ki vse datoteke iz enega (izvornega) podanega imenika premakne v drug (ciljni) podani imenik. Spravi ga v /home/student/mv_ukaz. Pazi, da bodo ob testiranju v izvornem imeniku iste datoteke, kot so bile, ko je bila virtualka nova, ciljni imenik pa bo prazen.
- - Napiši ukaz, ki s pomočjo ukaza grep v datoteko "mama.txt" izpiše vse navade (ne skrite) datoteke v trenutnem imeniku, ki vsebujejo niz "mama", v datoteko "napake.txt" pa izpiše vse morebitne napake (npr. to, da so nekateri objekti v trenutnem imeniku dejansko imeniki ali napačne simbolične povezave)
- - Napiši ukaz, ki bo 5s sledil vsebini /var/log/syslog. V primeru, da se v syslogu pojavi niz "zmeda", naj program izpiše "imam ga". Poleg tega naj program med sledenjem syslog-u odšteva od 5 do 1 (vsako sekundo naj se izpiše naslednja številka.
+ - Napiši ukaz, ki s pomočjo ukaza grep v datoteko ~/mama.txt izpiše vse navadne (ne skrite) datoteke v trenutnem imeniku, ki vsebujejo niz "mama", v datoteko ~/napake.txt pa izpiše vse morebitne napake (npr. to, da so nekateri objekti v trenutnem imeniku dejansko imeniki ali napačne simbolične povezave). Ukaz spravite v datoteko /home/student/mama_ukaz.
+ - Napiši program (lahko v bash), ki bo 5s sledil vsebini /var/log/syslog. V primeru, da se v syslogu pojavi niz "zmeda", naj program izpiše "imam ga". Poleg tega naj program med sledenjem syslog-u odšteva od 5 do 1 (vsako sekundo naj se izpiše naslednja številka. Program naj bo v /home/student/syslog_ukaz.sh
- Nastavi okoljsko spremenljivko TEST, da bo imela isto vrednost kot okoljska spremenljivka USER + število okoljskih spremenljivk, ki v imenu ali vrednosti ne vsebujejo besede TEST. Primer: polz37
# tole je zoprno, ker se lahko zelo hitro spremeni. Treba bo izbrati
# neko drugo stran - recimo http://localhost/mojastran.html
@@ -74,12 +74,13 @@ computers = {
networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
params_meta = {
- 'IP_malishell': {'descriptions': {'si': 'Naslov malishell'}, 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_malishell': {'descriptions': {'si': 'Naslov malishell'}, 'w': True, 'public':True, 'type': 'IP', 'generated': False},
'file_creator_random_seed': {'descriptions': {'si': 'random file creator seed'}, 'w': False, 'public':False, 'type': None, 'generated': True},
'20_file_dirname': {'descriptions': {'si': 'imenik z datotekami, ki naj se jih preimenuje'}, 'w': False, 'public':True, 'type': 'dirname', 'generated': True},
'mv_src_dir': {'descriptions': {'si': 'imenik, iz katerega premakni datoteke'}, 'w': False, 'public':True, 'type': 'dirname', 'generated': True},
'mv_dst_dir': {'descriptions': {'si': 'imenik, v katerega premakni datoteke'}, 'w': False, 'public':True, 'type': 'dirname', 'generated': True},
'cowsay_string': {'descriptions': {'si': 'Kaj rece krava?'}, 'w': False, 'public':True, 'type': 'short', 'generated': True},
+ 'syslog_n_zmeda': {'descriptions': {'si': 'st. zapisov zmeda v 5s'}, 'w': False, 'public':True, 'type': 'uint', 'generated': True},
}
def task(IP_malishell, 20_file_dirname, mv_src_dir, mv_dst_dir, cowsay_string):
@@ -95,15 +96,20 @@ def task(IP_malishell, 20_file_dirname, mv_src_dir, mv_dst_dir, cowsay_string):
results = dict()
conn = pxssh.pxssh()
conn.login(IP_malishell, 'student', 'vaje')
- conn.sendline('ls -a {}'.format())
+ # preimenuj datoteke
+ conn.sendline('ls -a {}'.format(20_file_dirname))
conn.prompt()
results['preimenuj'] = conn.before
+ # premakni datoteke s cim krajsim ukazom
conn.sendline('ls -a {}'.format(mv_src_dir))
conn.prompt()
results['pre_mv_src'] = conn.before
conn.sendline('ls -a {}'.format(mv_dst_dir))
conn.prompt()
results['pre_mv_dst'] = conn.before
+ conn.sendline('ls -l ~/mv_ukaz')
+ conn.prompt()
+ results['mv_ls_size'] = conn.before
conn.sendline('. ~/mv_ukaz')
conn.sendline('ls -a {}'.format(mv_src_dir))
conn.prompt()
@@ -111,20 +117,37 @@ def task(IP_malishell, 20_file_dirname, mv_src_dir, mv_dst_dir, cowsay_string):
conn.sendline('ls -a {}'.format(mv_dst_dir))
conn.prompt()
results['post_mv_dst'] = conn.before
-
+ # mama_ukaz
+ #
+ conn.sendline('cd /home/student/grep_test_dir')
+ conn.prompt()
+ conn.sendline('grep "mama" * > /dev/null 2>&1')
+ conn.prompt()
+ results['grep_err'] = conn.before
+ conn.sendline('grep "mama" * 2> /dev/null')
+ conn.prompt()
+ results['grep_stdout'] = conn.before
+ conn.sendline('. ~/mama_ukaz')
+ conn.prompt()
+ conn.sendline('cat ~/mama.txt ~/napake.txt')
+ conn.prompt()
+ results['grep_result'] = conn.before
conn.logout()
- # ta more met mojimenikfile
- # results['novi'] = subprocess.check_output(["ls", "/home/student/Desktop/Mapa/novi"])
-
- # ta more bit prazen
- #results['mojimenik'] = subprocess.check_output(["ls", "/home/student/Desktop/Mapa/mojimenik"])
-
- # ta more met mama2
- #results['mamatxt'] = subprocess.check_output(["cat", "/home/student/Desktop/mama.txt"])
-
- # ta pa grep: mojimenik: Is a directory, grep: novi: Is a directory
- #results['napaketxt'] = subprocess.check_output(["cat", "/home/student/Desktop/napake.txt"])
-
+ # sledenje syslog
+ conn.sendline('date')
+ conn.prompt()
+ conn.sendline('/usr/local/bin/syslog_spammer &')
+ conn.prompt()
+ results['syslog_start_time'] = conn.before
+ conn.sendline('/home/student/syslog_ukaz.sh')
+ conn.prompt()
+ results['syslog_result'] = conn.before
+ conn.sendline('date')
+ conn.prompt()
+ results['syslog_end_time'] = conn.before
+ conn.sendline('cowsay "{}"'.format(cowsay_string))
+ conn.prompt()
+ results['cowsay'] = conn.before
#results['curl'] = subprocess.check_output(["cat","/home/student/Desktop/website.txt"])
#results['chkimages'] = subprocess.check_output(["curl www.24ur.com >> dlg.txt && cat dlg.txt | grep -c ","images"])
@@ -146,47 +169,62 @@ def gen_params(user_id, params_meta):
import random
import subprocess
params = dict()
-
+ homedir = '/home/student/'
r = random.Random(user_id)
- params['cwsay'] = "cowsay"
- params['phttp'] = "8080"
- params['images'] = subprocess.check_output(["echo","$images"])
+ params['file_creator_random_seed'] = str(r.random())
+ params['20_file_dirname'] = homedir + kpov_random_helpers.default_generators['dirname'](r)
+ params['mv_src_dir'] = homedir + "".join([r.choice("abcdefgh") for i in xrange(6)])
+ params['mv_dst_dir'] = homedir + "".join([r.choice("ijklmnop") for i in xrange(6)])
+ params['syslog_n_zmeda'] = r.nextint(5, 15)
+ params['cowsay_string'] = kpov_random_helpers.default_generators['short_text'](r)
+ #params['phttp'] = "8080"
+ #params['images'] = subprocess.check_output(["echo","$images"])
return params
def task_check(results, params):
import re
+ import random
score = 0
-
+ r = random.Random(params['file_creator_random_seed'])
+ fnames = []
+ for i in xrange(20):
+ fnames.append("".join([ r.choice("_abcdefghijk") for j in xrange(8)]))
+ fnames.sort()
+ print fnames
#TO FINISH SCORING WE REQUIRE DICT KEYS AND FUNCTIONS gen_params AND task TO BE FINISHED
#POINTS FOR EACH TASK MAY BE ADJUSTED IN THE FUTURE
#TASK 1
- if results['NoNameATM'].find('NoFormatATM'.format(params['NoNameAtm'])) > -1:
- score += 1
- #TASK 2
- if results['NoNameATM'].find('NoFormatATM'.format(params['NoNameAtm'])) > -1:
- score += 1
- #TASK 3
- if results['NoNameATM'].find('NoFormatATM'.format(params['NoNameAtm'])) > -1:
- score += 1
- #TASK 4
- if results['NoNameATM'].find('NoFormatATM'.format(params['NoNameAtm'])) > -1:
- score += 1
- #TAKS 5
- if results['NoNameATM'].find('NoFormatATM'.format(params['NoNameAtm'])) > -1:
- score += 1
- #TASK 6
- if int(results['chkimages']) == int(params['images']):
- score += 1
- #TASK 7
- if int(results['count'].split()[0]) == int(results['lines'].split()[0]):
- score += 1
- #TASK 8
- if results['cowsay'].find(params['cwsay']) > -1:
- score += 1
- #TASK 9
- if results['phttp'].find(params['phttp']) > -1:
- score += 1
-
+ print( results['preimenuj'])
+ # premakni datoteke s cim krajsim ukazom
+ fnames = []
+ for i in xrange(40):
+ fnames.append("".join([ r.choice("123456789abcdefghijk") for j in xrange(8)]))
+ print( results['pre_mv_src'])
+ print( results['pre_mv_dst'])
+ print( results['mv_ls_size'])
+ print( results['post_mv_src'])
+ print( results['post_mv_dst'])
+ # mama_ukaz
+ #
+ mama_fnames = []
+ for i in xrange(20):
+ fnames.append("".join([ r.choice("123456789abcdefghijk") for j in xrange(8)]))
+ papa_fnames = []
+ for i in xrange(20):
+ fnames.append("".join([ r.choice("123456789abcdefghijk") for j in xrange(8)]))
+ dirnames = []
+ for i in xrange(20):
+ dirnames.append("".join([ r.choice("123456789abcdefghijk") for j in xrange(8)]))
+ linknames = []
+ for i in xrange(20):
+ linknames.append("".join([ r.choice("123456789abcdefghijk") for j in xrange(8)]))
+ print( results['grep_err'])
+ print( results['grep_stdout'])
+ print( results['grep_result'])
+ # sledenje syslog
+ print( results['syslog_start_time'])
+ print( results['syslog_result'])
+ print( results['syslog_end_time'])
return score
def prepare_disks(templates, params):
@@ -197,7 +235,37 @@ def prepare_disks(templates, params):
print templates
d = templates['malishell']
r = random.Random(params['file_creator_random_seed'])
-
- d.mkdir('student', 'www-data', '/home/student/mamica_je_ena_sama.txt')
- pass
-
+ # rename
+ d.mkdir(params['20_file_dirname'])
+ for i in xrange(20):
+ d.touch(params['20_file_dirname'] + '/' + "".join(
+ [r.choice("-abcdefghijk") for j in xrange(8)]))
+ # mv ukaz
+ d.mkdir(params['mv_src_dir'])
+ for i in xrange(40):
+ d.touch(params['mv_src_dir'] + '/' +"".join(
+ [r.choice("123456789abcdefghijk") for j in xrange(8)]))
+ d.mkdir(params['mv_dst_dir'])
+ # grep mama
+ # mama fnames
+ for i in xrange(20):
+ d.write("/home/student/grep_test_dir/" + "".join(
+ [ r.choice("123456789abcdefghijk") for j in xrange(8)]),
+ "mama")
+ # papa fnames
+ for i in xrange(20):
+ d.write("/home/student/grep_test_dir/" + "".join(
+ [ r.choice("123456789abcdefghijk") for j in xrange(8)]),
+ "papa")
+ # dirnames
+ for i in xrange(20):
+ d.mkdir("/home/student/grep_test_dir/" + "".join(
+ [ r.choice("123456789abcdefghijk") for j in xrange(8)]))
+ # linknames
+ for i in xrange(20):
+ d.ln_sf("mali zeleni", "/home/student/grep_test_dir/" + "".join(
+ [ r.choice("123456789abcdefghijk") for j in xrange(8)]))
+ # sledenje syslog
+ spammer_source = "#!/bin/sh\n" + int(params['syslog_n_zmeda']) * "logger zmeda\n"
+ d.write("/usr/local/bin/syslog_spammer")
+ d.chmod("0775", "/usr/local/bin/syslog_spammer")
diff --git a/kpov_judge/test_prepare_disks.py b/kpov_judge/test_prepare_disks.py
index 2df42ec..dfa7b39 100755
--- a/kpov_judge/test_prepare_disks.py
+++ b/kpov_judge/test_prepare_disks.py
@@ -62,6 +62,14 @@ class SSHGuestFs:
def file(self, path):
stdin, stdout, stderr = self.conn.exec_command('file "{}"'.format(path))
return stdin.read()
+ def ln(self, target, linkname):
+ self.conn.exec_command('ln "{}" "{}"'.format(target, linkname))
+ def ln_s(self, target, linkname):
+ self.conn.exec_command('ln -s "{}" "{}"'.format(target, linkname))
+ def ln_f(self, target, linkname):
+ self.conn.exec_command('ln -f "{}" "{}"'.format(target, linkname))
+ def ln_sf(self, target, linkname):
+ self.conn.exec_command('ln -sf "{}" "{}"'.format(target, linkname))
def getxattrs(self, path):
pass
#path = path)