Fix bug executing a command after loosing SSH connectivity to host

Change-Id: I13b6f55a6271296a9667e4c354342512f69100f0
This commit is contained in:
Federico Ressi 2020-01-28 10:57:27 +01:00
parent 15f7a3df48
commit 7873a4c32f
3 changed files with 23 additions and 8 deletions

View File

@ -18,6 +18,7 @@ from __future__ import absolute_import
from oslo_log import log
import paramiko
from tobiko.shell.sh import _exception
from tobiko.shell.sh import _execute
from tobiko.shell.sh import _io
from tobiko.shell.sh import _local
@ -83,9 +84,23 @@ class SSHShellProcessFixture(_process.ShellProcessFixture):
if isinstance(ssh_client, ssh.SSHClientFixture):
# Connect to SSH server
ssh_client = ssh_client.connect()
process = ssh_client.get_transport().open_session()
command = str(self.command)
timeout = self.timeout and float(self.timeout)
try:
process = ssh_client.get_transport().open_session(timeout=timeout)
except paramiko.SSHException as ex:
LOG.debug('Error executing command %r', command, exc_info=1)
error = str(ex)
if "Timeout opening channel." == error:
raise _exception.ShellTimeoutExpired(command=command,
stdin=None,
stdout=None,
stderr=None,
timeout=timeout)
else:
raise _exception.ShellError(error)
LOG.debug("Execute command %r on remote host (timeout=%r)...",
command, self.timeout)
if parameters.environment:
@ -109,9 +124,8 @@ class SSHShellProcessFixture(_process.ShellProcessFixture):
buffer_size=self.parameters.buffer_size)
def poll_exit_status(self):
process = self.process
exit_status = process.exit_status
if exit_status < 0:
exit_status = getattr(self.process, 'exit_status', None)
if exit_status and exit_status < 0:
exit_status = None
return exit_status

View File

@ -451,7 +451,7 @@ def ssh_connect(hostname, username=None, port=None, connection_interval=None,
time.sleep(sleep_time)
else:
LOG.info("Successfully logged it to %s", login)
LOG.debug("Successfully logged in to %s", login)
return client, proxy_sock

View File

@ -80,6 +80,7 @@ def setup_tobiko_config(conf):
if not paramiko_logger.isEnabledFor(log.DEBUG):
# Print paramiko debugging messages
paramiko_logger.logger.setLevel(log.DEBUG)
elif paramiko_logger.isEnabledFor(log.DEBUG):
# Silence paramiko debugging messages
paramiko_logger.logger.setLevel(log.WARNING)
else:
if paramiko_logger.isEnabledFor(log.ERROR):
# Silence paramiko debugging messages
paramiko_logger.logger.setLevel(log.FATAL)