diff options
author | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2018-10-07 20:21:31 +0200 |
---|---|---|
committer | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2018-10-07 20:21:31 +0200 |
commit | 80f050080ce11c6a0cce67c9b0281c09702b00d6 (patch) | |
tree | b486e1f6342bc757dda87df4856084f652895791 /kpov_judge/tasks/rename_grep_network | |
parent | 43d7ef057b4ae752a60b947e523b3a56782bf5cd (diff) | |
parent | dbf585c2a59dbcb7f6d803d5756826b562cd7f43 (diff) |
Merge branch 'fix-tasks'
Fixes pexpect usage in most tasks. Several other cleanups and minor
refactoring.
Diffstat (limited to 'kpov_judge/tasks/rename_grep_network')
-rw-r--r-- | kpov_judge/tasks/rename_grep_network/task.py | 89 |
1 files changed, 20 insertions, 69 deletions
diff --git a/kpov_judge/tasks/rename_grep_network/task.py b/kpov_judge/tasks/rename_grep_network/task.py index e8ce0b2..4f8f1ad 100644 --- a/kpov_judge/tasks/rename_grep_network/task.py +++ b/kpov_judge/tasks/rename_grep_network/task.py @@ -1,13 +1,9 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# # TODO: # - check if everything is filled in (computers, params, preparation) # - improve scoring # - test # - switch to a real SSH/SFTP client to properly handle filenames - instructions = { 'si': """ Ustvari dva navidezna računalnika s slikama diskov @@ -139,26 +135,6 @@ params_meta = { 'generated': True, }, - # 'progname': { - # 'descriptions': { - # 'si': 'Ime programa', - # 'en': 'Program filename', - # }, - # 'w': False, - # 'public': True, - # 'type': 'filename', - # 'generated': True, - # }, - 'pubseed': { - 'descriptions': { - 'si': 'Nekaj nepredvidenega', - 'en': 'A random seed', - }, - 'w': False, - 'public': True, - 'type': None, - 'generated': True, - }, 'rndseed': { 'descriptions': { 'si': 'random seed za skrito datoteko', @@ -171,47 +147,25 @@ params_meta = { }, } -def task(testip, testuser, passwd, mntdir, magicstr, pubseed): - from pexpect import pxssh - import random - target = pxssh.pxssh() - target.login(testip, testuser, passwd) - target.sendline('ls ~/') - target.prompt() - home_ls = target.before - target.sendline('cat ~/*I*.txt') - target.prompt() - dst_file_contents = target.before - target.sendline('ls -l ~/*I*.txt') - target.prompt() - dst_ls = target.before - target.sendline('mount') - target.prompt() - mnt = target.before - results = { - 'home_ls': home_ls, - 'dst_ls': dst_ls, - 'mnt': mnt, - 'dst_file_contents': dst_file_contents, - } - target.logout() - return results +def task(testip, testuser, passwd, mntdir, magicstr): + 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'), + )) def gen_params(user_id, params_meta): import random params = dict() r = random.Random(user_id) - params['testip'] = kpov_random_helpers.IPv4_addr_gen(r, + params['testip'] = kpov_util.IPv4_addr_gen(r, network = '10.94.80.0/19', n_generated=1)[0] - params['testuser'] = kpov_random_helpers.default_generators['username'](r) - params['passwd'] = kpov_random_helpers.alnum_gen(r, 8) + params['testuser'] = kpov_util.default_generators['username'](r) + params['passwd'] = kpov_util.alnum_gen(r, 8) params['magicstr'] = "".join([r.choice("qwerztlpoQWERTPOL") for i in range(10)]) - params['mntdir'] = "/" + kpov_random_helpers.default_generators['filename'](r) - # params['progname'] = kpov_random_helpers.default_generators['filename'](r) - # while params['dstfile'] == params['progname']: - # params['progname'] = kpov_random_helpers.default_generators['filename'](r) - params['pubseed'] = kpov_random_helpers.alnum_gen(r, 8) - params['rndseed'] = kpov_random_helpers.alnum_gen(r, 8) + params['mntdir'] = "/" + kpov_util.default_generators['filename'](r) + params['rndseed'] = kpov_util.alnum_gen(r, 8) return params @@ -220,6 +174,8 @@ def task_check(results, params): import re hints = [] score = 0 + if results['ssh'] is not True: + hints += ['ssh failed: ' + results['ssh']] hidden_contents = params['magicstr'] r = random.Random(params['rndseed']) dstfile = "".join([r.choice("qQoOp") for i in range(64)]) + "I.txt" @@ -238,11 +194,10 @@ 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: - diff_pos = "" + diff_pos = (0, "") for i, c in enumerate(results["dst_file_contents"]): if len(expected_contents) < i or c != expected_contents[i]: start = max(0, i-10) @@ -250,9 +205,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: @@ -275,10 +229,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']) @@ -288,6 +239,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'] @@ -296,6 +248,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: @@ -326,6 +280,3 @@ def prepare_disks(templates, task_params, global_params): # TODO create some additional files # write_default_config(templates['simpleArbiterDhcpGW'], global_params) - # finish here - # rename - |