summaryrefslogtreecommitdiff
path: root/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py
diff options
context:
space:
mode:
authorgasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414>2015-03-31 15:19:26 +0000
committergasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414>2015-03-31 15:19:26 +0000
commita0c78c82a5cb3a69f66a4ed631b555e3df54d6e5 (patch)
tree9ec5790f7ccb961bc242e8c4ae7490f668e66a49 /kpov_judge/tasks/copy_rename_20_files_tail_env/task.py
parent57b460d77fc034ff00555bf674bae5de2a350c1c (diff)
Fixed generation of disk images
git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@294 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414
Diffstat (limited to 'kpov_judge/tasks/copy_rename_20_files_tail_env/task.py')
-rw-r--r--kpov_judge/tasks/copy_rename_20_files_tail_env/task.py55
1 files changed, 40 insertions, 15 deletions
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 504d102..b4f11ef 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
@@ -22,9 +22,6 @@ V domači mapi najdeš imenik {file_rename_dirname} z 20 datotekami.
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
- Namesti paket "cowsay" in ga preizkusi :)
- - 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
- S pomočjo programa cURL preštej število pojavitev niza "images" v html kodi,
ki jo dobiš na naslovu http://localhost/{curl_fname} na malishell in število zapiši
v spremenljivko $images na simpleArbiter v lupini, kjer poganjaš
@@ -52,15 +49,14 @@ In your home folder you will find a directory called {file_rename_dirname}
In addition, the script should count down from 5 to 1 with a 1 second
interval. Store the script in /home/student/syslog_ukaz.sh .
- Install the packet "cowsay" and test it :)
- - Set the variable TEST, which will have the same value as the
- variable USER + the number of variables which do not include the name
- TEST, for example polz37.
- - With the help of cURL count the number of "images" string occurences in the
- page accessible from malishell at http://localhost/{curl_fname}.
+ - With the help of cURL count the number of occurences of the string
+ "images" on the web page accessible from malishell at
+ http://localhost/{curl_fname}.
On simpleArbiter within the shell where you are running test_task.py, set
the environment variable $images to this number.
- In the directory {wc_dirname} there is a file called count.txt. Write the
- number of lines in this file into a file in the same directory.
+ number of lines in this file into the file lines.txt in the same
+ directory.
"""
}
@@ -105,10 +101,15 @@ params_meta = {
'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},
+ 'curl_fname': {'descriptions': {'si': 'ime datoteke, dostopne prek http'}, 'w': False, 'public':True, 'type': 'filename', 'generated': True},
+ 'curl_n_images': {'descriptions': {'si': 'n pojavitev niza images'}, 'w': False, 'public':False, 'type': 'integer', 'generated': True},
+ 'wc_dirname': {'descriptions': {'si': 'imenik, v katerem je datoteka count.txt'}, 'w': False, 'public':True, 'type': 'dirname', 'generated': True},
+ 'wc_n_lines': {'descriptions': {'si': 'n vrstic v count.txt'}, 'w': False, 'public':False, 'type': 'integer', 'generated': True},
}
def task(IP_malishell, file_rename_dirname, mv_src_dir, mv_dst_dir, cowsay_string):
import pxssh
+ import os
# TODO: (polz) this has to be changed! Get a move on!
#
# sv: Z primozem lavricem sva skusala nekaj narediti
@@ -169,6 +170,13 @@ def task(IP_malishell, file_rename_dirname, mv_src_dir, mv_dst_dir, cowsay_strin
conn.sendline('cowsay "{}"'.format(cowsay_string))
conn.prompt()
results['cowsay'] = conn.before
+ results['curl_env'] = os.environ['images']
+ conn.sendline('cat {wc_dirname}/count.txt')
+ conn.prompt()
+ results['wc_origfile'] = conn.before
+ conn.sendline('cat {wc_dirname}/lines.txt')
+ conn.prompt()
+ results['wc_lines'] = conn.before
conn.logout()
#results['curl'] = subprocess.check_output(["cat","/home/student/Desktop/website.txt"])
@@ -195,6 +203,10 @@ def gen_params(user_id, params_meta):
params['mv_dst_dir'] = homedir + "".join([r.choice("ijklmnop") for i in xrange(6)])
params['syslog_n_zmeda'] = str(r.randint(5, 15))
params['cowsay_string'] = kpov_random_helpers.default_generators['short_text'](r)
+ params['curl_fname'] = kpov_random_helpers.default_generators['filename'](r)
+ params['curl_n_images'] = str(r.randint(30,100))
+ params['wc_dirname'] = homedir + "".join([r.choice("rstuvxz") for i in xrange(8)])
+ params['wc_n_lines'] = str(r.randint(200, 600))
#params['phttp'] = "8080"
#params['images'] = subprocess.check_output(["echo","$images"])
return params
@@ -289,22 +301,22 @@ def prepare_disks(templates, params):
r = random.Random(params['file_creator_random_seed'])
# rename
d.mkdir(params['file_rename_dirname'])
- d.chown("student", "student", params['file_rename_dirname'])
+ d.chown(1000, 1000, params['file_rename_dirname'])
for i in xrange(20):
fname = params['file_rename_dirname'] + '/' + "".join(
[r.choice("-abcdefghijk") for j in xrange(8)])
d.touch(fname)
- d.chown("student", "student", fname)
+ d.chown(1000, 1000, fname)
# mv ukaz
d.mkdir(params['mv_src_dir'])
- d.chown("student", "student", params['mv_src_dir'])
+ d.chown(1000, 1000, params['mv_src_dir'])
for i in xrange(40):
fname = params['mv_src_dir'] + '/' +"".join(
[r.choice("123456789abcdefghijk") for j in xrange(8)])
d.touch(fname)
- d.chown("student", "student", fname)
+ d.chown(1000, 1000, fname)
d.mkdir(params['mv_dst_dir'])
- d.chown("student", 'student', params['mv_dst_dir'])
+ d.chown(1000, 1000, params['mv_dst_dir'])
# grep mama
# mama fnames
d.mkdir('/home/student/grep_test_dir')
@@ -328,4 +340,17 @@ def prepare_disks(templates, params):
# sledenje syslog
spammer_source = "#!/bin/sh\n" + int(params['syslog_n_zmeda']) * "logger zmeda\n"
d.write("/usr/local/bin/syslog_spammer", spammer_source)
- d.chmod("0775", "/usr/local/bin/syslog_spammer")
+ d.chmod(0775, "/usr/local/bin/syslog_spammer")
+ # curl
+ l1 = ['images'] * int(params['curl_n_images'])
+ l2 = ['imeges'] * r.randint(30, 100)
+ lx = l1 + l2
+ r.shuffle(lx)
+ d.write("/var/www/html/{}".format(params['curl_fname']), ''.join(lx))
+ d.write("/var/www/html/{}".format(params['curl_fname']), ''.join(lx))
+ # wc
+ lx = ['\n']*int(params['wc_n_lines'])
+ lx += ['a', 'b', 'c', 'repa', 'in', 'krompir',
+ 'raus', 'e', 'patacis'] * r.randint(50, 150)
+ r.shuffle(lx)
+ d.write("{}".format(params['wc_dirname']), "".join(lx))