diff --git a/tobiko/shell/sh/_process.py b/tobiko/shell/sh/_process.py index beb72caea..0feba4480 100644 --- a/tobiko/shell/sh/_process.py +++ b/tobiko/shell/sh/_process.py @@ -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): diff --git a/tobiko/shell/sh/_ssh.py b/tobiko/shell/sh/_ssh.py index e6407c674..652582ee2 100644 --- a/tobiko/shell/sh/_ssh.py +++ b/tobiko/shell/sh/_ssh.py @@ -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):