diff options
Diffstat (limited to 'kpov_judge/tasks/custom_rdate')
-rw-r--r-- | kpov_judge/tasks/custom_rdate/task.py | 61 |
1 files changed, 18 insertions, 43 deletions
diff --git a/kpov_judge/tasks/custom_rdate/task.py b/kpov_judge/tasks/custom_rdate/task.py index b84a2b7..4959266 100644 --- a/kpov_judge/tasks/custom_rdate/task.py +++ b/kpov_judge/tasks/custom_rdate/task.py @@ -1,7 +1,5 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- +# kpov_util should be imported by add_assignment.py -# kpov_random_helpers should be imported by add_assignment.py # TODO: finish this! instructions = { 'si':""" @@ -39,10 +37,6 @@ computers = { 'disks': [ { 'name': 'student-rdate', }, - #{ 'name': 'CDROM', - # 'options':{'readonly': True}, - # 'parts': [],# no parts, no mounting. - #} ], 'network_interfaces': [{'network': 'net1'}], 'flavor': 'm1.tiny', @@ -52,12 +46,7 @@ computers = { 'SimpleArbiter': { 'disks': [ { 'name': 'simpleArbiterDhcpGWRdate', - # attempt automount }, - #{ 'name': 'CDROM', - # 'options': {'readonly': True}, - # 'parts': [{'dev': 'b1', 'path': '/cdrom'}], - #}, ], 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}], 'flavor': 'm1.tiny', @@ -75,37 +64,26 @@ params_meta = { } def task(IP_RDATECLIENT, PROGRAM_FILENAME): - import pexpect - import paramiko - from paramiko import SSHClient + import collections + import base64 import random import struct - import base64 - results = dict() - peer_user = 'test' - peer_passwd = 'test' - client = SSHClient() - client.load_system_host_keys() - client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - client.connect(IP_RDATECLIENT, username=peer_user, password=peer_passwd) - #client.login(IP_RDATECLIENT, peer_user, peer_passwd) + import pexpect + r = random.Random(PROGRAM_FILENAME) + results = collections.defaultdict(str) + tests = [] for i in range(10): - stdin, stdout, stderr = client.exec_command( - '~/{}'.format(PROGRAM_FILENAME)) data = struct.pack("!I", r.randint(0, 2**32)) - stdin.write(data) - results['in_' + str(i)] = base64.encodestring(data) - results['out_' + str(i)] = stdout.read() - stdin, stdout, stderr = client.exec_command( - 'date -u +"%s"') - #client.sendline('date -u "%s"') - #client.prompt() - results['date'] = stdout.read() + results['in_'+str(i)] = data_ascii = base64.encodestring(data) + tests += [('out_'+str(i), 'echo "{}" | base64 -d | ~/{}'.format(data_ascii.decode().strip(), PROGRAM_FILENAME))] + tests += [('date', 'date -u +"%s"')] + + results.update( + kpov_util.ssh_test(IP_RDATECLIENT, 'test', 'test', tests)) results['ldate'] = pexpect.run('date -u +"%s"') - client.close() - return results + return results #Dolocil sem tri parametre in sicer jih lahko vidite v prams_meta, #zato prosim da jih upostevate v naslednih nalogah. @@ -116,7 +94,7 @@ def gen_params(user_id, params_meta): import datetime params = dict() r = random.Random(user_id) - params['PROGRAM_FILENAME'] = kpov_random_helpers.fname_gen(r, False) + params['PROGRAM_FILENAME'] = kpov_util.fname_gen(r, False) params['RDATE_OFFSET'] = str(r.randint(-2**24, 2**24)) return params @@ -124,7 +102,7 @@ def task_check(results, params): import random import struct import base64 - # print results + r = random.Random(params['PROGRAM_FILENAME']) score = 0.0 hints = [] @@ -139,7 +117,7 @@ def task_check(results, params): score += 0.5 else: hints += ["wrong convert"] - # print str(struct.unpack("!I", data)[0]), res.strip() + if abs(int(results['ldate']) + \ int(params['RDATE_OFFSET']) - int(results['date'])) < 3: score += 5 @@ -148,9 +126,6 @@ def task_check(results, params): return score, hints def prepare_disks(templates, task_params, global_params): -# d = templates['simpleArbiterDhcp'] -# print templates -# print params d = templates['simpleArbiterDhcpGWRdate'] s1 = """service "time_tcp" {{ enabled yes; @@ -170,7 +145,7 @@ import time import sys offset = int(sys.argv[1]) -t = time.time() + 2208988800 + offset +t = time.time() + offset # used to have + 2208988800 sys.stdout.write(struct.pack("!I", int(t))) """ d.write('/usr/local/bin/kpovrdate', s2) |