@@ -117,13 +117,31 @@ def run_command(self, command, timeout=60):
117
117
console = self .get_console ()
118
118
console .sendline (command )
119
119
console .expect ("\n " ) # from us
120
- rc = console .expect (["\[console-pexpect\]#$" ,pexpect .TIMEOUT ], timeout )
121
- output = console .before
122
-
123
- console .sendline ("echo $?" )
124
- console .expect ("\n " ) # from us
125
- rc = console .expect (["\[console-pexpect\]#$" ,pexpect .TIMEOUT ], timeout )
126
- exitcode = int (console .before )
120
+ rc = None
121
+ output = None
122
+ exitcode = None
123
+ try :
124
+ rc = console .expect (["\[console-pexpect\]#$" ], timeout )
125
+ output = console .before
126
+ console .sendline ("echo $?" )
127
+ console .expect ("\n " ) # from us
128
+ rc = console .expect (["\[console-pexpect\]#$" ], timeout )
129
+ exitcode = int (console .before )
130
+ except pexpect .TIMEOUT as e :
131
+ print e
132
+ print "# TIMEOUT waiting for command to finish."
133
+ print "# Attempting to control-c"
134
+ try :
135
+ console .sendcontrol ('c' )
136
+ rc = console .expect (["\[console-pexpect\]#$" ], 10 )
137
+ if rc == 0 :
138
+ raise CommandFailed (command , "TIMEOUT" , - 1 )
139
+ except pexpect .TIMEOUT :
140
+ print "# Timeout trying to kill timed-out command."
141
+ print "# Failing current command and attempting to continue"
142
+ self .terminate ()
143
+ raise CommandFailed ("ssh -p 2222" , "timeout" , - 1 )
144
+ raise e
127
145
128
146
if rc == 0 :
129
147
res = output
0 commit comments