summaryrefslogtreecommitdiff
path: root/kpov_judge/tasks/custom_rdate
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2018-10-07 19:02:26 +0200
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2018-10-07 19:04:21 +0200
commitb5b35faea7f4205f353f57178ddc795b7dce5043 (patch)
treef8531a61d236ea0abc4e9dc80692abdc36c6579a /kpov_judge/tasks/custom_rdate
parent42076466e00aa066769050bb2e2b4d98e9cc4d20 (diff)
Refactor SSH testing code out of individual tasks
Catch SSH errors and report failures as hints. Also some cleanups and 2to3 fixes.
Diffstat (limited to 'kpov_judge/tasks/custom_rdate')
-rw-r--r--kpov_judge/tasks/custom_rdate/task.py55
1 files changed, 16 insertions, 39 deletions
diff --git a/kpov_judge/tasks/custom_rdate/task.py b/kpov_judge/tasks/custom_rdate/task.py
index 51f5baa..da8313c 100644
--- a/kpov_judge/tasks/custom_rdate/task.py
+++ b/kpov_judge/tasks/custom_rdate/task.py
@@ -39,10 +39,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 +48,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 +66,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.
@@ -124,7 +104,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 +119,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 +128,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 +147,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)