Skip to content
Snippets Groups Projects
Commit 8c46f29b authored by Nicolas KAROLAK's avatar Nicolas KAROLAK
Browse files

fix ssh diag on error

parent 4f7c0bab
No related branches found
No related tags found
No related merge requests found
...@@ -31,17 +31,18 @@ def test_ssh(ip): ...@@ -31,17 +31,18 @@ def test_ssh(ip):
cmd = 'ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no %s ls /tmp' % ip cmd = 'ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no %s ls /tmp' % ip
print('Connecting to MediaVault: %s' % cmd) print('Connecting to MediaVault: %s' % cmd)
try: try:
subprocess.check_output(cmd, shell=True, timeout=2) subprocess.check_output(cmd, shell=True, timeout=5)
print('%sLogged in successfully%s' % (GREEN, DEF)) print('%sLogged in successfully%s' % (GREEN, DEF))
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
# do some diagnostics print('%sFailed to login using SSH, run ssh-copy-id %s %s' % (RED, ip, DEF))
return False
except subprocess.TimeoutExpired:
try: try:
cmd_port = 'nc -z -w2 {} 22'.format(ip) cmd_port = 'nc -z -w2 {} 22'.format(ip)
subprocess.check_output(cmd_port, shell=True, timeout=5) subprocess.check_output(cmd_port, shell=True, timeout=5)
except subprocess.CalledProcessError: except Exception:
cmd_ping = 'ping -c2 -w4 {}'.format(ip) cmd_ping = 'ping -c2 -w4 {}'.format(ip)
subprocess.check_output(cmd_ping, shell=True, timeout=5) subprocess.check_output(cmd_ping, shell=True, timeout=15)
print('%sFailed to login using SSH, run ssh-copy-id %s %s' % (RED, ip, DEF))
return False return False
return True return True
......
...@@ -40,14 +40,15 @@ def check_ssh(ip): ...@@ -40,14 +40,15 @@ def check_ssh(ip):
subprocess.check_output(cmd, shell=True, timeout=5) subprocess.check_output(cmd, shell=True, timeout=5)
print('%sLogged in successfully in "%s".%s' % (GREEN, ip, DEF)) print('%sLogged in successfully in "%s".%s' % (GREEN, ip, DEF))
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
# do some diagnostics print('%sFailed to login using SSH, run "ssh-copy-id %s".%s' % (RED, ip, DEF))
return False
except subprocess.TimeoutExpired:
try: try:
cmd_port = 'nc -z -w2 {} 22'.format(ip) cmd_port = 'nc -z -w2 {} 22'.format(ip)
subprocess.check_output(cmd_port, shell=True, timeout=5) subprocess.check_output(cmd_port, shell=True, timeout=5)
except subprocess.CalledProcessError: except Exception:
cmd_ping = 'ping -c2 -w4 {}'.format(ip) cmd_ping = 'ping -c2 -w4 {}'.format(ip)
subprocess.check_output(cmd_ping, shell=True, timeout=5) subprocess.check_output(cmd_ping, shell=True, timeout=15)
print('%sFailed to login using SSH, run "ssh-copy-id %s".%s' % (RED, ip, DEF))
return False return False
return True return True
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment