From e33085889f26c76587fdab2ad600ed336dc028b5 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sat, 6 Oct 2018 23:35:00 +0200 Subject: Improve ssh error reporting in some tasks --- kpov_judge/tasks/set_motd/task.py | 41 ++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'kpov_judge/tasks/set_motd') diff --git a/kpov_judge/tasks/set_motd/task.py b/kpov_judge/tasks/set_motd/task.py index eadcca7..2e83ead 100644 --- a/kpov_judge/tasks/set_motd/task.py +++ b/kpov_judge/tasks/set_motd/task.py @@ -76,35 +76,36 @@ params_meta = { def task(peer_ip, peer_user, peer_passwd, niz): "Check whether ssh works" + import collections from pexpect import pxssh - import pexpect - # return {"hello": 'kitty'} - results = dict() - s = pxssh.pxssh() - #TODO (polz): tole bi utegnilo delovati http://pexpect.sourceforge.net/pxssh.html. Testirajte - s.login (peer_ip, peer_user, peer_passwd, original_prompt=r'{0}@.*:\~\$'.format(peer_user),auto_prompt_reset=False) - # print s.before - # s.prompt() - #Ce na serverju iz datoteke /var/run/motd.dynamic pobrisemo znak '#' bi moralo delovati. - - # temp = s.before # print everything before the prompt. - #TODO (polz): tole ni pravi pristop. Problem je bil v tem, da pxssh ni prav zaznal, kdaj je prijavljen. Glej link zgoraj. - results['motd'] = s.before # print everything before the prompt. + results = collections.defaultdict(str) + try: + s = pxssh.pxssh(encoding='utf-8') + s.login(peer_ip, peer_user, peer_passwd, + original_prompt=r'{0}@.*:\~\$'.format(peer_user), + auto_prompt_reset=False) + results['ssh'] = True + results['motd'] = s.before + s.logout() + except Exception as ex: + results['ssh'] = str(ex) return results - # - + def gen_params(user_id, params_meta): return kpov_random_helpers.default_gen(user_id, params_meta) def task_check(results, params): - #print task_url - #print params - #print results niz = params['niz'] score = 0 hints = [] - if (results['motd'].find(niz) > -1): - score += 10 + if results['ssh'] is True: + score += 2 + else: + hints += ['ssh failed: ' + results['ssh']] + if niz in results['motd']: + score += 8 + else: + hints += ['wrong motd:\n' + results['motd'] + '\n'] return score, hints def prepare_disks(templates, task_params, global_params): -- cgit v1.2.1 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/set_motd/task.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'kpov_judge/tasks/set_motd') diff --git a/kpov_judge/tasks/set_motd/task.py b/kpov_judge/tasks/set_motd/task.py index 2e83ead..956f570 100644 --- a/kpov_judge/tasks/set_motd/task.py +++ b/kpov_judge/tasks/set_motd/task.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # bson.son.SON an -# kpov_random_helpers should be imported by add_assignment.py +# kpov_util should be imported by add_assignment.py # OrderedDict = SON instructions = { @@ -92,7 +92,7 @@ def task(peer_ip, peer_user, peer_passwd, niz): return results def gen_params(user_id, params_meta): - return kpov_random_helpers.default_gen(user_id, params_meta) + return kpov_util.default_gen(user_id, params_meta) def task_check(results, params): niz = params['niz'] -- 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/set_motd/task.py | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'kpov_judge/tasks/set_motd') diff --git a/kpov_judge/tasks/set_motd/task.py b/kpov_judge/tasks/set_motd/task.py index 956f570..5f1b0b3 100644 --- a/kpov_judge/tasks/set_motd/task.py +++ b/kpov_judge/tasks/set_motd/task.py @@ -76,20 +76,7 @@ params_meta = { def task(peer_ip, peer_user, peer_passwd, niz): "Check whether ssh works" - import collections - from pexpect import pxssh - results = collections.defaultdict(str) - try: - s = pxssh.pxssh(encoding='utf-8') - s.login(peer_ip, peer_user, peer_passwd, - original_prompt=r'{0}@.*:\~\$'.format(peer_user), - auto_prompt_reset=False) - results['ssh'] = True - results['motd'] = s.before - s.logout() - except Exception as ex: - results['ssh'] = str(ex) - return results + return kpov_util.ssh_test(peer_ip, peer_user, peer_passwd) def gen_params(user_id, params_meta): return kpov_util.default_gen(user_id, params_meta) -- 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/set_motd/task.py | 1 - 1 file changed, 1 deletion(-) (limited to 'kpov_judge/tasks/set_motd') diff --git a/kpov_judge/tasks/set_motd/task.py b/kpov_judge/tasks/set_motd/task.py index 5f1b0b3..e50716b 100644 --- a/kpov_judge/tasks/set_motd/task.py +++ b/kpov_judge/tasks/set_motd/task.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- # bson.son.SON an # kpov_util should be imported by add_assignment.py -- 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/set_motd/task.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'kpov_judge/tasks/set_motd') diff --git a/kpov_judge/tasks/set_motd/task.py b/kpov_judge/tasks/set_motd/task.py index e50716b..f2b65fb 100644 --- a/kpov_judge/tasks/set_motd/task.py +++ b/kpov_judge/tasks/set_motd/task.py @@ -1,8 +1,4 @@ -#!/usr/bin/env python - -# bson.son.SON an # kpov_util should be imported by add_assignment.py -# OrderedDict = SON instructions = { "si":""" -- cgit v1.2.1