summaryrefslogtreecommitdiff
path: root/kpov_judge/tasks/mock_entrance_exam
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2018-10-07 20:21:31 +0200
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2018-10-07 20:21:31 +0200
commit80f050080ce11c6a0cce67c9b0281c09702b00d6 (patch)
treeb486e1f6342bc757dda87df4856084f652895791 /kpov_judge/tasks/mock_entrance_exam
parent43d7ef057b4ae752a60b947e523b3a56782bf5cd (diff)
parentdbf585c2a59dbcb7f6d803d5756826b562cd7f43 (diff)
Merge branch 'fix-tasks'
Fixes pexpect usage in most tasks. Several other cleanups and minor refactoring.
Diffstat (limited to 'kpov_judge/tasks/mock_entrance_exam')
-rw-r--r--kpov_judge/tasks/mock_entrance_exam/task.py50
1 files changed, 16 insertions, 34 deletions
diff --git a/kpov_judge/tasks/mock_entrance_exam/task.py b/kpov_judge/tasks/mock_entrance_exam/task.py
index a6e3c8c..906df97 100644
--- a/kpov_judge/tasks/mock_entrance_exam/task.py
+++ b/kpov_judge/tasks/mock_entrance_exam/task.py
@@ -1,6 +1,3 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-#
# TODO:
# - check if everything is filled in (computers, params, preparation)
# - improve scoring
@@ -136,51 +133,34 @@ params_meta = {
def task(student_IP, net_prog_name,
P_c, P_executable, arg_c, env_c, out_stderr_c, out_stdout_c, P_script,
param_gen_seed):
- from pexpect import pxssh
import random
- conn = pxssh.pxssh()
- conn.login(student_IP, 'student', 'vaje')
- results = dict()
+
r = random.Random(int(param_gen_seed))
env_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(11)])
-
arg_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(13)])
stdin_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(17)])
- conn.sendline('ls -l {}'.format(P_script))
- conn.prompt()
- results['script_ls'] = conn.before
- conn.sendline('ls -l {}'.format(P_executable))
- conn.prompt()
- results['executable_ls'] = conn.before
- conn.sendline('export {}={}; {}'.format(env_c, env_val, P_script))
- conn.prompt()
- results['script_run'] = conn.before
- conn.sendline('cat {}'.format(out_stderr_c))
- conn.prompt()
- results['script_stderr'] = conn.before
- conn.sendline('cat {}'.format(out_stdout_c))
- conn.prompt()
- results['script_stdout'] = conn.before
- conn.sendline('echo "{}" | {} "{}" 2> /dev/null'.format(stdin_val, P_executable, arg_val))
- conn.prompt()
- results['prog_stdout'] = conn.before
- conn.sendline('echo "{}" | {} "{}" > /dev/null'.format(stdin_val, P_executable, arg_val))
- conn.prompt()
- results['prog_stderr'] = conn.before
- conn.logout()
- return results
+
+ return kpov_util.ssh_test(student_IP, 'student', 'vaje', (
+ ('script_ls', 'ls -l {}'.format(P_script)),
+ ('executable_ls', 'ls -l {}'.format(P_executable)),
+ ('script_run', 'export {}={}; {}'.format(env_c, env_val, P_script)),
+ ('script_stderr', 'cat {}'.format(out_stderr_c)),
+ ('script_stdout', 'cat {}'.format(out_stdout_c)),
+ ('prog_stdout', 'echo "{}" | {} "{}" 2> /dev/null'.format(stdin_val, P_executable, arg_val)),
+ ('prog_stderr', 'echo "{}" | {} "{}" > /dev/null'.format(stdin_val, P_executable, arg_val)),
+ ))
def gen_params(user_id, params_meta):
import random
r = random.Random(user_id+'evil cornholio')
- params = kpov_random_helpers.default_gen(user_id, params_meta)
+ params = kpov_util.default_gen(user_id, params_meta)
homedir = '/home/student/'
params['env_c'] = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ') for i in range(5)])
params['P_c'] = "".join([r.choice('abcdefghijklmnoprst') for i in range(5)]) + ".c"
params['param_gen_seed'] = str(r.randint(0, 2**24))
params['c_destroy_gen_seed'] = str(r.randint(0, 2**24))
- dest_net = kpov_random_helpers.IPv4_subnet_gen(r, '10.0.2.128/26', 26)
- params['student_IP'] = kpov_random_helpers.IPv4_addr_gen(r, dest_net)[0]
+ dest_net = kpov_util.IPv4_subnet_gen(r, '10.0.2.128/26', 26)
+ params['student_IP'] = kpov_util.IPv4_addr_gen(r, dest_net)[0]
for k in ['P_c', 'P_executable', 'out_stderr_c', 'P_script', 'out_stdout_c']:
params[k] = homedir + params[k]
return params
@@ -209,6 +189,8 @@ def task_check(results, params):
return(s_out, s_err, retval)
score = 0
hints = []
+ if results['ssh'] is not True:
+ hints += ['ssh failed: ' + results['ssh']]
r = random.Random(int(params['param_gen_seed']))
env_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(11)])
arg_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(13)])