From 903a08e1401bcc0ffc9b592a8219d92b9b7cd847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florent=20Thi=C3=A9ry?= <florent.thiery@ubicast.eu> Date: Fri, 3 Mar 2017 13:33:37 +0100 Subject: [PATCH] add timeout to ssh test --- tests/test_backup.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/test_backup.py b/tests/test_backup.py index 579c551d..bf45f087 100755 --- a/tests/test_backup.py +++ b/tests/test_backup.py @@ -11,11 +11,22 @@ import subprocess import imp from datetime import datetime +GREEN = '\033[92m' +RED = '\033[91m' +DEF = '\033[0m' + os.chdir(os.path.dirname(__file__)) -def test_ssh(server): - status, out = subprocess.getstatusoutput('ssh -o StrictHostKeyChecking=no %s ls /tmp' % server) - return status == 0 +def test_ssh(ip): + cmd = 'ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no %s ls /tmp' % ip + print('Connecting to MediaVault: %s' % cmd) + try: + subprocess.check_output(cmd, shell=True, timeout=2) + print('%sLogged in successfully%s' % (GREEN, DEF)) + except subprocess.CalledProcessError: + print('%sFailed to login using SSH, run ssh-copy-id %s %s' % (RED, ip, DEF)) + return False + return True def test_last_backup_is_recent(server, client): path = '/backup/%s/current' % client @@ -50,4 +61,5 @@ if os.path.isfile('../utils.py'): else: sys.exit(2) else: + print('No BURP_SERVER defined in config, untestable') sys.exit(2) -- GitLab