Workaround paramiko timeout problem
Change-Id: I5fda968011465171866f86e11bf4ca98a7215c24
This commit is contained in:
@@ -191,19 +191,20 @@ class ShellProcessFixture(tobiko.SharedFixture):
|
|||||||
# Drain all incoming data from STDOUT and STDERR
|
# Drain all incoming data from STDOUT and STDERR
|
||||||
self.wait(timeout=timeout)
|
self.wait(timeout=timeout)
|
||||||
finally:
|
finally:
|
||||||
try:
|
with tobiko.exc_info():
|
||||||
self._terminate()
|
try:
|
||||||
except Exception:
|
self._terminate()
|
||||||
LOG.debug('Exception terminating process: %r',
|
except Exception:
|
||||||
self.command, exc_info=1)
|
LOG.exception('Exception terminating process: %r',
|
||||||
|
self.command, exc_info=1)
|
||||||
|
|
||||||
def _terminate(self):
|
def _terminate(self):
|
||||||
self.close_stdout()
|
self.close_stdout()
|
||||||
self.close_stderr()
|
self.close_stderr()
|
||||||
try:
|
try:
|
||||||
exit_status = self.poll_exit_status()
|
exit_status = self.get_exit_status(timeout=5.)
|
||||||
except Exception:
|
except _exception.ShellTimeoutExpired as ex:
|
||||||
LOG.exception('Error getting exit status')
|
LOG.warning('Error getting exit status: %s', ex)
|
||||||
exit_status = None
|
exit_status = None
|
||||||
finally:
|
finally:
|
||||||
if exit_status is None:
|
if exit_status is None:
|
||||||
@@ -281,13 +282,11 @@ class ShellProcessFixture(tobiko.SharedFixture):
|
|||||||
def receive_all(self, **kwargs):
|
def receive_all(self, **kwargs):
|
||||||
self.communicate(receive_all=True, **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)
|
timeout = shell_process_timeout(timeout=timeout)
|
||||||
try:
|
self.communicate(timeout=timeout, receive_all=receive_all,
|
||||||
self.communicate(timeout=timeout, receive_all=receive_all,
|
**kwargs)
|
||||||
**kwargs)
|
|
||||||
finally:
|
|
||||||
self.get_exit_status(timeout=timeout)
|
|
||||||
|
|
||||||
def communicate(self, stdin=None, stdout=True, stderr=True, timeout=None,
|
def communicate(self, stdin=None, stdout=True, stderr=True, timeout=None,
|
||||||
receive_all=False, buffer_size=None):
|
receive_all=False, buffer_size=None):
|
||||||
|
|||||||
@@ -117,15 +117,15 @@ class SSHShellProcessFixture(_process.ShellProcessFixture):
|
|||||||
def _get_exit_status(self, time_left=None):
|
def _get_exit_status(self, time_left=None):
|
||||||
process = self.process
|
process = self.process
|
||||||
if not process.exit_status_ready():
|
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
|
# recv_exit_status method doesn't accept timeout parameter
|
||||||
if process.status_event.wait(timeout=time_left):
|
LOG.debug('Waiting for command (%s) exit status (time_left=%r)',
|
||||||
assert process.exit_status_ready()
|
self.command, time_left)
|
||||||
else:
|
if not process.status_event.wait(timeout=time_left):
|
||||||
assert not process.exit_status_ready()
|
LOG.debug('Timed out before status event being set')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
assert process.exit_status is not None
|
|
||||||
return process.exit_status
|
return process.exit_status
|
||||||
|
|
||||||
def kill(self):
|
def kill(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user