Skip to content

Commit

Permalink
More thorough detection of connection status
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Peng committed Aug 24, 2019
1 parent ac4f5c4 commit 5855537
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/sos/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def _map_var(self, source):

def test_connection(self):
try:
cmd = cfg_interpolate('ssh -q {host} -p {port} true', {
cmd = cfg_interpolate('ssh {host} -p {port} true', {
'host': self.address,
'port': self.port
})
Expand All @@ -487,9 +487,13 @@ def test_connection(self):
stty_sane()
return f'ssh connection to {self.address} was prompted for password. Please set up public key authentication to the remote host before continue.'
elif i == 2:
if p.before:
env.logger.warning(f'ssh connection to {self.address} returns "{p.before.decode()}"')
return "OK"
p.close()
if p.exitstatus == 0:
return 'OK'
elif p.before:
return p.before.decode()
else:
return f'Command "{cmd}" exits with code {p.exitstatus}'
except pexpect.TIMEOUT:
return f'ssh connection to {self.address} time out with prompt: {str(p.before)}'
except Exception as e:
Expand Down

0 comments on commit 5855537

Please sign in to comment.