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/rename_grep_network/task.py | 37 ++++++---------------------- 1 file changed, 7 insertions(+), 30 deletions(-) (limited to 'kpov_judge/tasks/rename_grep_network') diff --git a/kpov_judge/tasks/rename_grep_network/task.py b/kpov_judge/tasks/rename_grep_network/task.py index cba9ac9..c1be010 100644 --- a/kpov_judge/tasks/rename_grep_network/task.py +++ b/kpov_judge/tasks/rename_grep_network/task.py @@ -152,30 +152,12 @@ params_meta = { } def task(testip, testuser, passwd, mntdir, magicstr): - import collections - from pexpect import pxssh - - commands = [ + return kpov_util.ssh_test(testip, testuser, passwd, ( ('home_ls', 'ls ~/'), ('dst_file_contents', 'cat ~/*I*.txt'), ('dst_ls', 'ls -l ~/*I*.txt'), ('mnt', 'mount'), - ] - - results = collections.defaultdict(str) - try: - s = pxssh.pxssh(encoding='utf-8') - s.login(testip, testuser, passwd) - results['ssh'] = True - for test, command in commands: - s.sendline(command) - s.prompt() - if test: - results[test] = s.before - s.logout() - except Exception as ex: - results['ssh'] = str(ex) - return results + )) def gen_params(user_id, params_meta): import random @@ -216,7 +198,6 @@ def task_check(results, params): # r"pokakalz\r", # hidden_contents, # re.MULTILINE) - expected_contents = "cat ~/*I*.txt\r\n".format(dstfile) + expected_contents if results["dst_file_contents"] == expected_contents: score += 3 else: @@ -228,9 +209,8 @@ def task_check(results, params): diff_pos = (i, results["dst_file_contents"][start:end]) break hints += ["wrong file contents\n" + str(diff_pos[1])] - #hints += ["wrong file contents"] params['dstfile'] = dstfile - expected_dst_ls = "ls -l ~/\\*I\\*.txt\r\n-rw--w---- 1 {testuser} bilbo .*{dstfile}\r\n".format(**params) + expected_dst_ls = "-rw--w---- 1 {testuser} bilbo .*{dstfile}".format(**params) if re.match(expected_dst_ls, results["dst_ls"]): score += 2 else: @@ -253,10 +233,7 @@ def task_check(results, params): def prepare_disks(templates, task_params, global_params): import random import os - #print "Haha!" - #print params - #print templates - d = templates['smallstudent-personal'] + # first create the file contents to make it easyer to check. hidden_contents = task_params['magicstr'] r = random.Random(task_params['rndseed']) @@ -266,6 +243,7 @@ def prepare_disks(templates, task_params, global_params): x += "".join([r.choice("uiasdfghjkyxcvbnm1234567890ASDFGHJKYZXCVBNM") for i in range(60)]) x += r.choice(["lz", "1z", "Iz", "iz", "l2", "I2", "12"]) hidden_contents += x + "\n" + # create hidden file dir_list = ['Qlipper', 'Thunar', 'blender', 'autostart', 'kazam', 'mc', 'netsurf', 'pulse', 'qupzilla', 'radare2', 'teamviewer', 'texstudio', 'vlc'] ending_list = ['rc', '.conf', '', '.txt'] @@ -274,6 +252,8 @@ def prepare_disks(templates, task_params, global_params): start_list.append("".join([r.choice("qQoOp") for i in range(64)]) + "O") r.shuffle(dir_list) file_letters = ["mod", "co"] + + d = templates['smallstudent-personal'] d.mkdir('/mnt/.hideme') d.mkdir('/media/.hideme') for potential_dir in dir_list: @@ -304,6 +284,3 @@ def prepare_disks(templates, task_params, global_params): # TODO create some additional files # write_default_config(templates['simpleArbiterDhcpGW'], global_params) - # finish here - # rename - -- cgit v1.2.1