mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-06-22 16:26:09 +01:00
more robust exit_code handling for ssh interface
Background processes may produce output on STDOUT. This could get captured when obtaining the result of "echo $?" to get previos command's exit code. So it's not safe to assume that output will always be an int. Attempt to strip out superflous output before doing the int conversion and, on failure, log a warning but don't error out.
This commit is contained in:
@ -147,10 +147,14 @@ class SshShell(object):
|
||||
with self.lock:
|
||||
output = self._execute_and_wait_for_prompt(command, timeout, as_root, strip_colors)
|
||||
if check_exit_code:
|
||||
exit_code = int(self._execute_and_wait_for_prompt('echo $?', strip_colors=strip_colors, log=False))
|
||||
exit_code_text = self._execute_and_wait_for_prompt('echo $?', strip_colors=strip_colors, log=False)
|
||||
try:
|
||||
exit_code = int(exit_code_text.split()[0])
|
||||
if exit_code:
|
||||
message = 'Got exit code {}\nfrom: {}\nOUTPUT: {}'
|
||||
raise DeviceError(message.format(exit_code, command, output))
|
||||
except ValueError:
|
||||
logger.warning('Could not get exit code for "{}",\ngot: "{}"'.format(command, exit_code_text))
|
||||
return output
|
||||
|
||||
def logout(self):
|
||||
|
Reference in New Issue
Block a user