1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2024-10-06 02:41:11 +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:
Sergei Trofimov 2015-06-05 12:47:01 +01:00
parent b976164ee9
commit c40a7fd644

View File

@ -147,10 +147,14 @@ class SshShell(object):
with self.lock: with self.lock:
output = self._execute_and_wait_for_prompt(command, timeout, as_root, strip_colors) output = self._execute_and_wait_for_prompt(command, timeout, as_root, strip_colors)
if check_exit_code: 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: if exit_code:
message = 'Got exit code {}\nfrom: {}\nOUTPUT: {}' message = 'Got exit code {}\nfrom: {}\nOUTPUT: {}'
raise DeviceError(message.format(exit_code, command, output)) 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 return output
def logout(self): def logout(self):