orchestra.run: More consistently notice failures
check_status=True in combination with wait=False resulted in
CommandFailedError never being raised if poll() was used instead of
wait(). Fix that.
@@ -146,8 +146,14 @@ class RemoteProcess(object):
not isinstance(stream_obj, ChannelFile):
stream_obj.seek(0)
+ self._raise_for_status()
+ return status
+
+ def _raise_for_status(self):
+ if self.returncode is None:
+ self._get_exitstatus()
if self.check_status:
- if status is None:
+ if self.returncode in (None, -1):
# command either died due to a signal, or the connection
# was lost
transport = self.client.get_transport()
@@ -159,11 +165,11 @@ class RemoteProcess(object):
# connection seems healthy still, assuming it was a
# signal; sadly SSH does not tell us which signal
raise CommandCrashedError(command=self.command)
- if status != 0:
- raise CommandFailedError(command=self.command,
- exitstatus=status, node=self.hostname,
- label=self.label)
- return status
+ if self.returncode != 0:
+ raise CommandFailedError(
+ command=self.command, exitstatus=self.returncode,
+ node=self.hostname, label=self.label
+ )
def _get_exitstatus(self):
"""
@@ -190,6 +196,7 @@ class RemoteProcess(object):
:returns: self.returncode if the process is finished; else None
"""
if self.finished:
+ self._raise_for_status()
return self.returncode
return None
