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-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
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')
-rwxr-xr-xkpov_judge/create_disk_images.py13
-rwxr-xr-xkpov_judge/rm_task.py2
-rw-r--r--kpov_judge/tasks/copy_rename_20_files_tail_env/task.py55
-rw-r--r--kpov_judge/tasks/custom_rdate/task.py2
-rw-r--r--kpov_judge/tasks/openvpn_simple_smb/task.py5
-rw-r--r--kpov_judge/tasks/set_motd/task.py2
-rw-r--r--kpov_judge/tasks/snmp_agent_uptime/task.py2
-rwxr-xr-xkpov_judge/test_prepare_disks.py4
-rwxr-xr-xkpov_judge/web/kpov_judge/kpov_judge.py14
9 files changed, 66 insertions, 33 deletions
diff --git a/kpov_judge/create_disk_images.py b/kpov_judge/create_disk_images.py
index 6fffb77..3e59ed4 100755
--- a/kpov_judge/create_disk_images.py
+++ b/kpov_judge/create_disk_images.py
@@ -11,8 +11,6 @@ import os
import glob
import subprocess
import fcntl
-import pyssh
-import paramiko
def get_prepare_disks(db, task_id):
prepare_disks_source = db.prepare_disks.find_one({'task_id':task_id})['source']
@@ -21,13 +19,13 @@ def get_prepare_disks(db, task_id):
return prepare_disks
def create_snapshot(task_id, student_id, disk_name, overwrite = True, cow = False):
- print(os.path.join(settings.DISK_TEMPLATE_PATH, task_id, disk_name) + '.*')
- template_paths = glob.glob(os.path.join(settings.DISK_TEMPLATE_PATH, task_id, disk_name) + '.*')
+ print(os.path.join(settings.DISK_TEMPLATE_PATH, disk_name) + '.*')
+ template_paths = glob.glob(os.path.join(settings.DISK_TEMPLATE_PATH, disk_name) + '.*')
filtered_paths = filter((lambda x: os.path.splitext(x)[1] == '.' + settings.STUDENT_DISK_FORMAT), template_paths)
if filtered_paths:
- template_path = filtered_paths[0]
+ template_path = filtered_paths[0]
else:
- template_path = template_paths[0]
+ template_path = template_paths[0]
if cow:
d = os.path.join(student_id, task_id, disk_name) + os.path.splitext(template_path)[1]
else:
@@ -77,6 +75,7 @@ if __name__ == '__main__':
computers_by_task_student[(task_id, student_id)] = list()
computers_by_task_student[(task_id, student_id)].append(computer)
for (task_id, student_id), computers in computers_by_task_student.iteritems():
+ print "Creating", task_id, " for ", student_id
l = db.student_computers.find_one({'task_id': task_id, 'student_id':student_id, "disk_urls": {"$exists": False}})
if l is None:
continue
@@ -99,6 +98,8 @@ if __name__ == '__main__':
manual_disks = list()
this_computers_disks = set()
try_automount = False
+ if len(computer['disks']) == 0:
+ continue
g = guestfs.GuestFS()
for disk in computer['disks']:
lock_fp.write("register " + disk['name'] + '\n')
diff --git a/kpov_judge/rm_task.py b/kpov_judge/rm_task.py
index e4b37c7..0083149 100755
--- a/kpov_judge/rm_task.py
+++ b/kpov_judge/rm_task.py
@@ -28,8 +28,10 @@ if __name__ == '__main__':
db.task_checkers.remove({'task_id': task_id})
db.tasks.remove({'task_id': task_id})
db.prepare_disks.remove({'task_id': task_id})
+ db.student_computers.remove({'task_id': task_id})
db.gen_params.remove({'task_id': task_id})
db.task_params_meta.remove({'task_id': task_id})
+ db.task_params.remove({'task_id': task_id})
db.task_instructions.remove({'task_id': task_id})
db.howtos.remove({'task_id': task_id})
db.howto_images.remove({'task_id': task_id})
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))
diff --git a/kpov_judge/tasks/custom_rdate/task.py b/kpov_judge/tasks/custom_rdate/task.py
index 1f73887..3a72b5d 100644
--- a/kpov_judge/tasks/custom_rdate/task.py
+++ b/kpov_judge/tasks/custom_rdate/task.py
@@ -167,4 +167,4 @@ t = time.time() + 2208988800 + offset
sys.stdout.write(struct.pack("!I", int(t)))
"""
d.write('/usr/local/bin/kpovrdate', s2)
- d.chmod('0775', '/usr/local/bin/kpovrdate')
+ d.chmod(0775, '/usr/local/bin/kpovrdate')
diff --git a/kpov_judge/tasks/openvpn_simple_smb/task.py b/kpov_judge/tasks/openvpn_simple_smb/task.py
index e530bf0..edaeef7 100644
--- a/kpov_judge/tasks/openvpn_simple_smb/task.py
+++ b/kpov_judge/tasks/openvpn_simple_smb/task.py
@@ -305,8 +305,9 @@ iface tap0 inet static
templates['SimpleArbiterVPN'].write(
"/srv/smb/" + fname + '.txt',
kpov_random_helpers.fortune(r, 4096))
- templates['VPNClient1'].write("/home/student/" + keyfile, s)
- templates['VPNClient1'].chown("student", "student", "/home/student/" + keyfile)
+ templates['VPNClient1'].write("/home/student/" + keyfile, s)
+ # uid, gid (student = )
+ templates['VPNClient1'].chown(1000, 1000, "/home/student/" + keyfile)
diff --git a/kpov_judge/tasks/set_motd/task.py b/kpov_judge/tasks/set_motd/task.py
index b5d1b3c..3f24cb2 100644
--- a/kpov_judge/tasks/set_motd/task.py
+++ b/kpov_judge/tasks/set_motd/task.py
@@ -46,7 +46,7 @@ string you got in these instructions.
computers = {
'SimpleArbiterDhcpGW': {
'disks': [
- { 'name': 'SimpleArbiterDhcpGW',
+ { 'name': 'simpleArbiterDhcpGW',
},
],
'flavor': 'm1.tiny',
diff --git a/kpov_judge/tasks/snmp_agent_uptime/task.py b/kpov_judge/tasks/snmp_agent_uptime/task.py
index 70cfa1b..b0c4dd9 100644
--- a/kpov_judge/tasks/snmp_agent_uptime/task.py
+++ b/kpov_judge/tasks/snmp_agent_uptime/task.py
@@ -214,4 +214,4 @@ elif action == '-n' and oid < ".{oid}":
print "{val}"
""".format(oid = params['SNMP_CLIENT_OID'], val = params['SNMP_VALUE'])
templates['SNMPServer'].write('/usr/local/bin/snmpext.py', prog)
- templates['SNMPServer'].chmod('766', '/usr/local/bin/snmpext.py')
+ templates['SNMPServer'].chmod(0766, '/usr/local/bin/snmpext.py')
diff --git a/kpov_judge/test_prepare_disks.py b/kpov_judge/test_prepare_disks.py
index 0e9aaac..c810cd2 100755
--- a/kpov_judge/test_prepare_disks.py
+++ b/kpov_judge/test_prepare_disks.py
@@ -28,9 +28,9 @@ class SSHGuestFs:
except:
pass
def chmod(self, mode, path):
- self.conn.exec_command('chmod {} "{}"'.format(mode, path))
+ self.conn.exec_command('chmod {} "{}"'.format(oct(mode, 8), path))
def chown(self, owner, group, path):
- self.conn.exec_command('chown {}.{} "{}"'.format(owner, group, path))
+ self.conn.exec_command('chown {}.{} "{}"'.format(str(owner), str(group), path))
def command(self, arguments):
self.conn.exec_command(arguments)
def cp(self, src, dest):
diff --git a/kpov_judge/web/kpov_judge/kpov_judge.py b/kpov_judge/web/kpov_judge/kpov_judge.py
index 7171c7f..ef7d542 100755
--- a/kpov_judge/web/kpov_judge/kpov_judge.py
+++ b/kpov_judge/web/kpov_judge/kpov_judge.py
@@ -199,18 +199,22 @@ def task_greeting(task_id, lang):
# generate the parameters as soon as the student visits
params, meta = get_params(task_id, student_id, db)
try:
- public_params = dict()
- for k, v in meta:
- if meta.get('public', False):
- public_params[k] = params.get(k, "???")
instructions = db.task_instructions.find({'task_id': task_id})[0]
instructions = instructions.get(lang,
- app.config['DEFAULT_LANG']).format(**public_params)
+ app.config['DEFAULT_LANG'])
except:
try:
instructions = instructions.values()[0]
except Exception, e:
instructions = str(e)
+ try:
+ public_params = dict()
+ for k, v in meta.iteritems():
+ if v.get('public', False):
+ public_params[k] = params.get(k, "???")
+ instructions = instructions.format(**public_params)
+ except Exception, e:
+ instructions = str(e)
computer_list = db.student_computers.find({'task_id':task_id, 'student_id': student_id})
if request.args.get('narediStack', 'false') == 'true':
#db.student_tasks.update({'task_id':task_id, 'student_id': student_id}, {'$set': {'create_openstack': True}}, upsert = True)