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()
# 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):
"""
:returns: self.returncode if the process is finished; else None
"""
if self.finished:
+ self._raise_for_status()
return self.returncode
return None