summaryrefslogtreecommitdiff
path: root/kpov_judge/tasks/set_motd
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2018-10-06 23:35:00 +0200
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2018-10-07 00:13:58 +0200
commite33085889f26c76587fdab2ad600ed336dc028b5 (patch)
tree980dd39519bc355aeb17572affcae58d3a0966cd /kpov_judge/tasks/set_motd
parent43d7ef057b4ae752a60b947e523b3a56782bf5cd (diff)
Improve ssh error reporting in some tasks
Diffstat (limited to 'kpov_judge/tasks/set_motd')
-rw-r--r--kpov_judge/tasks/set_motd/task.py41
1 files changed, 21 insertions, 20 deletions
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):