Skip to content

Commit

Permalink
OpenBMC: Properly handle timed-out commands running on host
Browse files Browse the repository at this point in the history
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
stewartsmith committed Nov 15, 2017
1 parent d1b760d commit fe00973
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions common/OpTestOpenBMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,31 @@ def run_command(self, command, timeout=60):
console = self.get_console()
console.sendline(command)
console.expect("\n") # from us
rc = console.expect(["\[console-pexpect\]#$",pexpect.TIMEOUT], timeout)
output = console.before

console.sendline("echo $?")
console.expect("\n") # from us
rc = console.expect(["\[console-pexpect\]#$",pexpect.TIMEOUT], timeout)
exitcode = int(console.before)
rc = None
output = None
exitcode = None
try:
rc = console.expect(["\[console-pexpect\]#$"], timeout)
output = console.before
console.sendline("echo $?")
console.expect("\n") # from us
rc = console.expect(["\[console-pexpect\]#$"], timeout)
exitcode = int(console.before)
except pexpect.TIMEOUT as e:
print e
print "# TIMEOUT waiting for command to finish."
print "# Attempting to control-c"
try:
console.sendcontrol('c')
rc = console.expect(["\[console-pexpect\]#$"], 10)
if rc == 0:
raise CommandFailed(command, "TIMEOUT", -1)
except pexpect.TIMEOUT:
print "# Timeout trying to kill timed-out command."
print "# Failing current command and attempting to continue"
self.terminate()
raise CommandFailed("ssh -p 2222", "timeout", -1)
raise e

if rc == 0:
res = output
Expand Down

0 comments on commit fe00973

Please sign in to comment.