From be32ceb69271797a38b24d07930ac9afcd0c729f Mon Sep 17 00:00:00 2001 From: "gasperfele@fri1.uni-lj.si" Date: Mon, 20 Oct 2014 08:42:08 +0000 Subject: Initial commit git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@1 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414 --- kpov_judge/tasks/set_motd/evaluation/task.py | 72 ++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 kpov_judge/tasks/set_motd/evaluation/task.py (limited to 'kpov_judge/tasks/set_motd/evaluation/task.py') diff --git a/kpov_judge/tasks/set_motd/evaluation/task.py b/kpov_judge/tasks/set_motd/evaluation/task.py new file mode 100644 index 0000000..3338c80 --- /dev/null +++ b/kpov_judge/tasks/set_motd/evaluation/task.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# bson.son.SON an +# kpovRandomHelpers should be imported by add_assignment.py +# OrderedDict = SON + + +instructions = { + "si":u""" +Ustvari dva navidezna računalnika - imenujmo ju Test in Student. Za računalnik Test uporabite +sliko diska, poimenovano Test. Na računalniku Test dobite kratek niz. Poskrbite, da se bo ta +kratki niz pojavil v sporočilu, ki se ob prijavi izpiše na računalniku Student. Temu sporočilu v +angleščini rečemo "message of the day" - MOTD. +""" +} + +computers = { + 'Test': { + 'disks': [ + { 'name': 'Test', + }, + ], + 'flavor': 'm1.tiny', + 'network_interfaces': [{'network': 'net1'}], + 'config_drive': True, + 'userdata': {'string': "#!/bin/bash\nsed -i '/cloud/d' /etc/fstab\npoweroff &\n"} + }, + 'Student': { + 'disks': [ + { 'name': 'Student', } + ], + 'flavor': 'm1.tiny', + 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}], + 'config_drive': True, + 'userdata': {'string': "#!/bin/bash\nsed -i '/cloud/d' /etc/fstab\npoweroff &\n"} + } + +} + +networks = { 'net1': {'public': False}, 'test-net': {'public': True} } + +params_meta = { + 'peer_ip': {'opis': 'IP računalnika', 'w': True, 'public':True, 'type': 'IP', 'generated': False}, + 'peer_user': {'opis': 'ime uporabnika', 'w': False, 'public': True, 'type': 'username', 'generated': True}, + 'peer_passwd': {'opis': 'geslo uporabnika', 'w': True, 'public': True, 'type': 'alnumstr', 'generated': False}, + 'niz': {'w': False, 'public': True, 'type': 'short_text', 'generated': True}, +} + +def task(peer_ip, peer_user, peer_passwd, niz): + "Check whether ssh works" + import pxssh + import pexpect + results = dict() + s = pxssh.pxssh() + s.login (peer_ip, peer_user, peer_passwd, original_prompt=r'{0}@.*:\~\$'.format(peer_user),auto_prompt_reset=False) + results['motd'] = s.before # print everything before the prompt. + return results + +def gen_params(user_id, params_meta): + return kpovRandomHelpers.default_gen(user_id, params_meta) + +def task_check(results, params): + niz = params['niz'] + score = 0 + if (results['motd'].find(niz) > -1): + score += 10 + return score + +def prepare_disks(templates, params): + # print d1.ls('/') + pass -- cgit v1.2.1