From 9c51bbe5016495c714789f5df01806a6d366e11a Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sat, 6 Oct 2018 23:56:03 +0200 Subject: Rename kpov_random_helpers to kpov_util --- kpov_judge/tasks/basic_network_gcc/task.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'kpov_judge/tasks/basic_network_gcc') diff --git a/kpov_judge/tasks/basic_network_gcc/task.py b/kpov_judge/tasks/basic_network_gcc/task.py index ae690f0..c4f54bd 100644 --- a/kpov_judge/tasks/basic_network_gcc/task.py +++ b/kpov_judge/tasks/basic_network_gcc/task.py @@ -155,14 +155,14 @@ def task(student_IP, net_prog_name, 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 -- cgit v1.2.1 From b5b35faea7f4205f353f57178ddc795b7dce5043 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sun, 7 Oct 2018 19:02:26 +0200 Subject: Refactor SSH testing code out of individual tasks Catch SSH errors and report failures as hints. Also some cleanups and 2to3 fixes. --- kpov_judge/tasks/basic_network_gcc/task.py | 48 +++++++++--------------------- 1 file changed, 14 insertions(+), 34 deletions(-) (limited to 'kpov_judge/tasks/basic_network_gcc') diff --git a/kpov_judge/tasks/basic_network_gcc/task.py b/kpov_judge/tasks/basic_network_gcc/task.py index c4f54bd..8f19ae8 100644 --- a/kpov_judge/tasks/basic_network_gcc/task.py +++ b/kpov_judge/tasks/basic_network_gcc/task.py @@ -118,39 +118,22 @@ 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_stdout', 'cat {}'.format(out_stdout_c)), + ('script_stderr', 'cat {}'.format(out_stderr_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 @@ -198,16 +181,13 @@ def task_check(results, params): expected_script_stdout, expected_script_stderr, rval = test_out_gen( params['arg_c'], env_val ) - expected_script_stderr = 'cat {}\r\n'.format(params['out_stderr_c']) + expected_script_stderr - # hints += [expected_script_stderr, results['script_run'], results['script_stderr'], params['arg_c'], env_val] if expected_script_stderr != results['script_stderr']: hints += ['wrong script stderr'] else: score += 2 split_stdout = expected_script_stdout.split('\r\n') expected_script_stdout = "\r\n".join([ i for i in split_stdout if i.find('ma') >= 0]) - expected_script_stdout = 'cat {}\r\n'.format(params['out_stdout_c']) + expected_script_stdout + "\r\n" - if expected_script_stdout != results['script_stdout']: + if expected_script_stdout != results['script_stdout'].strip(): hints += ['wrong script stdout'] else: score += 2 @@ -288,9 +268,9 @@ done; }& destroyed_c_source += 'QX' destroyed_c_source += c d.write(task_params['P_c'], destroyed_c_source) - d.chown(1000, 1000, params['P_c']) + d.chown(1000, 1000, task_params['P_c']) sh_path = r.choice(['/usr/share/doc', '/var/lib', '/usr/local/share', '/etc/alternatives']) - sh_file = sh_path + '/' + params['net_prog_name'] + sh_file = sh_path + '/' + task_params['net_prog_name'] d.write(sh_file, evil_shell_source) d.chmod(0o775, sh_file) d.write("/etc/rc.local", """#!/bin/sh -e -- cgit v1.2.1 From 3091fc2877600f7926ed6a596c316183499125f8 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sun, 7 Oct 2018 19:11:49 +0200 Subject: Remove coding: lines Python 3 source is utf-8 by default. --- kpov_judge/tasks/basic_network_gcc/task.py | 1 - 1 file changed, 1 deletion(-) (limited to 'kpov_judge/tasks/basic_network_gcc') diff --git a/kpov_judge/tasks/basic_network_gcc/task.py b/kpov_judge/tasks/basic_network_gcc/task.py index 8f19ae8..1ae06ac 100644 --- a/kpov_judge/tasks/basic_network_gcc/task.py +++ b/kpov_judge/tasks/basic_network_gcc/task.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- # # TODO: # - check if everything is filled in (computers, params, preparation) -- cgit v1.2.1 From dbf585c2a59dbcb7f6d803d5756826b562cd7f43 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sun, 7 Oct 2018 19:38:40 +0200 Subject: Fix or remove hashbangs --- kpov_judge/tasks/basic_network_gcc/task.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'kpov_judge/tasks/basic_network_gcc') diff --git a/kpov_judge/tasks/basic_network_gcc/task.py b/kpov_judge/tasks/basic_network_gcc/task.py index 1ae06ac..c4c4393 100644 --- a/kpov_judge/tasks/basic_network_gcc/task.py +++ b/kpov_judge/tasks/basic_network_gcc/task.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # TODO: # - check if everything is filled in (computers, params, preparation) # - improve scoring -- cgit v1.2.1