Workaround paramiko timeout problem

Change-Id: I5fda968011465171866f86e11bf4ca98a7215c24
This commit is contained in:
Federico Ressi
2019-10-16 09:47:37 +02:00
parent cd301aacd2
commit 259ad05a9f
2 changed files with 19 additions and 20 deletions

View File

@@ -191,19 +191,20 @@ class ShellProcessFixture(tobiko.SharedFixture):
# Drain all incoming data from STDOUT and STDERR
self.wait(timeout=timeout)
finally:
try:
self._terminate()
except Exception:
LOG.debug('Exception terminating process: %r',
self.command, exc_info=1)
with tobiko.exc_info():
try:
self._terminate()
except Exception:
LOG.exception('Exception terminating process: %r',
self.command, exc_info=1)
def _terminate(self):
self.close_stdout()
self.close_stderr()
try:
exit_status = self.poll_exit_status()
except Exception:
LOG.exception('Error getting exit status')
exit_status = self.get_exit_status(timeout=5.)
except _exception.ShellTimeoutExpired as ex:
LOG.warning('Error getting exit status: %s', ex)
exit_status = None
finally:
if exit_status is None:
@@ -281,13 +282,11 @@ class ShellProcessFixture(tobiko.SharedFixture):
def receive_all(self, **kwargs):
self.communicate(receive_all=True, **kwargs)
def wait(self, timeout=None, receive_all=True, **kwargs):
def wait(self, timeout=None, receive_all=True,
**kwargs):
timeout = shell_process_timeout(timeout=timeout)
try:
self.communicate(timeout=timeout, receive_all=receive_all,
**kwargs)
finally:
self.get_exit_status(timeout=timeout)
self.communicate(timeout=timeout, receive_all=receive_all,
**kwargs)
def communicate(self, stdin=None, stdout=True, stderr=True, timeout=None,
receive_all=False, buffer_size=None):

View File

@@ -117,15 +117,15 @@ class SSHShellProcessFixture(_process.ShellProcessFixture):
def _get_exit_status(self, time_left=None):
process = self.process
if not process.exit_status_ready():
LOG.debug('Waiting for command (%s) exit status', self.command)
# workaround for paramiko timeout problem
time_left = min(time_left, 1.0)
# recv_exit_status method doesn't accept timeout parameter
if process.status_event.wait(timeout=time_left):
assert process.exit_status_ready()
else:
assert not process.exit_status_ready()
LOG.debug('Waiting for command (%s) exit status (time_left=%r)',
self.command, time_left)
if not process.status_event.wait(timeout=time_left):
LOG.debug('Timed out before status event being set')
return None
assert process.exit_status is not None
return process.exit_status
def kill(self):