blob: 5bfe274af97338a9a8d0d8d819f1173efd58aa30 [file] [log] [blame]
Pier6a0c4de2018-03-18 16:01:30 -07001#!/usr/bin/env python
2"""
3Copyright 2018 Open Networking Foundation (ONF)
4
5Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
6the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
7or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
8
9TestON is free software: you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation, either version 2 of the License, or
12( at your option ) any later version.
13
14TestON is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with TestON. If not, see <http://www.gnu.org/licenses/>.
21"""
22
23import pexpect
24import re
Pier6a0c4de2018-03-18 16:01:30 -070025import os
You Wang4cc61912018-08-28 10:10:58 -070026from drivers.common.cli.emulator.scapyclidriver import ScapyCliDriver
Pier6a0c4de2018-03-18 16:01:30 -070027
You Wang4cc61912018-08-28 10:10:58 -070028class HostDriver( ScapyCliDriver ):
Pier6a0c4de2018-03-18 16:01:30 -070029 """
30 This class is created as a standalone host driver.
31 """
32 def __init__( self ):
33 super( HostDriver, self ).__init__()
34 self.handle = self
35 self.name = None
36 self.shortName = None
You Wangb1665b52019-02-01 15:49:48 -080037 self.interfaces = []
Pier6a0c4de2018-03-18 16:01:30 -070038 self.home = None
You Wang4cc61912018-08-28 10:10:58 -070039 self.inband = False
40 self.prompt = "\$"
41 self.scapyPrompt = ">>>"
Jon Hall62ab6752021-08-22 16:47:43 -070042 self.tempRoutes = []
Pier6a0c4de2018-03-18 16:01:30 -070043
44 def connect( self, **connectargs ):
45 """
46 Creates ssh handle for host.
47 NOTE:
48 The ip_address would come from the topo file using the host tag, the
49 value can be an environment variable as well as a "localhost" to get
50 the ip address needed to ssh to the "bench"
51 """
52 try:
53 for key in connectargs:
54 vars( self )[ key ] = connectargs[ key ]
55 self.name = self.options[ 'name' ]
56 self.shortName = self.options[ 'shortName' ]
You Wangb1665b52019-02-01 15:49:48 -080057 self.interfaces.append( { 'ips': [ self.options[ 'ip' ] ],
58 'isUp': True,
59 'mac': self.options[ 'mac' ],
Jon Hall4d956de2021-06-09 10:09:20 -070060 'dhcp': self.options.get( 'dhcp', "False" ),
Jon Hall8a99e8d2021-09-01 11:18:12 -070061 'name': self.options.get( 'ifaceName', None ) } )
Pier6a0c4de2018-03-18 16:01:30 -070062
63 try:
64 if os.getenv( str( self.ip_address ) ) is not None:
65 self.ip_address = os.getenv( str( self.ip_address ) )
66 else:
67 main.log.info( self.name +
68 ": Trying to connect to " +
69 self.ip_address )
70 except KeyError:
71 main.log.info( "Invalid host name," +
72 " connecting to local host instead" )
73 self.ip_address = 'localhost'
74 except Exception as inst:
75 main.log.error( "Uncaught exception: " + str( inst ) )
76
77 self.handle = super(
78 HostDriver,
79 self ).connect(
80 user_name=self.user_name,
81 ip_address=self.ip_address,
82 port=None,
83 pwd=self.pwd )
84
Jon Hallceed0a32021-06-08 11:07:00 -070085 # Update IP of interfaces if using dhcp
86 for intf in self.interfaces:
87 if intf[ 'dhcp' ].lower() == "true":
88 ip = self.getIPAddress( iface=intf[ 'name' ] )
89 if ip:
90 intf['ips'] = [ ip ]
91 else:
92 main.log.warn( self.name + ": Could not find IP of %s" % intf[ 'name' ] )
93
Pier6a0c4de2018-03-18 16:01:30 -070094 if self.handle:
95 main.log.info( "Connection successful to the " +
96 self.user_name +
97 "@" +
98 self.ip_address )
99 self.handle.sendline( "" )
100 self.handle.expect( self.prompt )
101 return main.TRUE
102 else:
103 main.log.error( "Connection failed to " +
104 self.user_name +
105 "@" +
106 self.ip_address )
107 return main.FALSE
108 except pexpect.EOF:
109 main.log.error( self.name + ": EOF exception found" )
110 main.log.error( self.name + ": " + self.handle.before )
111 main.cleanAndExit()
112 except Exception:
113 main.log.exception( self.name + ": Uncaught exception!" )
114 main.cleanAndExit()
115
116 def disconnect( self, **connectargs ):
117 """
118 Called when test is complete to disconnect the handle.
119 """
120 response = main.TRUE
121 try:
122 if self.handle:
Jon Hall49d781c2021-07-29 11:23:46 -0700123 self.preDisconnect()
Jon Hall62ab6752021-08-22 16:47:43 -0700124 if self.tempRoutes:
125 for r in self.tempRoutes:
126 self.deleteRoute( *r )
Pier6a0c4de2018-03-18 16:01:30 -0700127 # Disconnect from the host
Jon Hall026bd712021-08-31 16:30:09 -0700128 if not self.options.get( 'inband', False ) == 'True':
You Wangb1665b52019-02-01 15:49:48 -0800129 self.handle.sendline( "" )
130 self.handle.expect( self.prompt )
131 self.handle.sendline( "exit" )
132 i = self.handle.expect( [ "closed", pexpect.TIMEOUT ] )
133 if i == 1:
134 main.log.error( self.name + ": timeout when waiting for response" )
Jon Hall43060f62020-06-23 13:13:33 -0700135 main.log.error( self.name + ": response: " + str( self.handle.before ) )
You Wangb1665b52019-02-01 15:49:48 -0800136 else:
137 self.handle.sendline( "" )
138 i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ], timeout=2 )
139 if i == 1:
140 main.log.warn( self.name + ": timeout when waiting for response" )
Jon Hall43060f62020-06-23 13:13:33 -0700141 main.log.warn( self.name + ": response: " + str( self.handle.before ) )
You Wangb1665b52019-02-01 15:49:48 -0800142 self.handle.sendline( "exit" )
143 i = self.handle.expect( [ "closed", pexpect.TIMEOUT ], timeout=2 )
144 if i == 1:
145 main.log.warn( self.name + ": timeout when waiting for response" )
Jon Hall43060f62020-06-23 13:13:33 -0700146 main.log.warn( self.name + ": response: " + str( self.handle.before ) )
You Wangb1665b52019-02-01 15:49:48 -0800147 return main.TRUE
Pier6a0c4de2018-03-18 16:01:30 -0700148 except TypeError:
149 main.log.exception( self.name + ": Object not as expected" )
150 response = main.FALSE
151 except pexpect.EOF:
152 main.log.error( self.name + ": EOF exception found" )
153 main.log.error( self.name + ": " + self.handle.before )
154 except ValueError:
155 main.log.exception( "Exception in disconnect of " + self.name )
156 response = main.TRUE
157 except Exception:
158 main.log.exception( self.name + ": Connection failed to the host" )
159 response = main.FALSE
160 return response
161
You Wang4cc61912018-08-28 10:10:58 -0700162 def connectInband( self ):
163 """
164 ssh to the host using its data plane IP
165 """
166 try:
167 if not self.options[ 'inband' ] == 'True':
168 main.log.info( "Skip connecting the host via data plane" )
169 return main.TRUE
170 self.handle.sendline( "" )
171 self.handle.expect( self.prompt )
172 self.handle.sendline( "ssh {}@{}".format( self.options[ 'username' ],
173 self.options[ 'ip' ] ) )
174 i = self.handle.expect( [ "password:|Password:", self.prompt, pexpect.TIMEOUT ], timeout=30 )
175 if i == 0:
176 self.handle.sendline( self.options[ 'password' ] )
177 j = self.handle.expect( [ "password:|Password:", self.prompt, pexpect.TIMEOUT ], timeout=10 )
178 if j != 1:
179 main.log.error( "Incorrect password" )
180 return main.FALSE
181 elif i == 1:
182 main.log.info( "Password not required logged in" )
183 else:
184 main.log.error( "Failed to connect to the host" )
185 return main.FALSE
186 self.inband = True
187 return main.TRUE
188 except KeyError:
189 main.log.error( self.name + ": host component not as expected" )
190 main.log.error( self.name + ": " + self.handle.before )
191 return main.FALSE
192 except pexpect.EOF:
193 main.log.error( self.name + ": EOF exception found" )
194 main.log.error( self.name + ": " + self.handle.before )
195 return main.FALSE
196 except Exception:
197 main.log.exception( self.name + ": Uncaught exception!" )
198 main.log.error( self.name + ": " + self.handle.before )
199 return main.FALSE
200
201 def disconnectInband( self ):
202 """
203 Terminate the ssh connection to the host's data plane IP
204 """
205 try:
206 if not self.options[ 'inband' ] == 'True':
207 main.log.info( "Skip disconnecting the host via data plane" )
208 return main.TRUE
209 self.handle.sendline( "" )
You Wangb1665b52019-02-01 15:49:48 -0800210 self.handle.expect( self.prompt, timeout=2 )
You Wang4cc61912018-08-28 10:10:58 -0700211 self.handle.sendline( "exit" )
212 i = self.handle.expect( [ "closed", pexpect.TIMEOUT ], timeout=2 )
213 if i == 1:
214 main.log.error( self.name + ": timeout when waiting for response" )
Jon Hall43060f62020-06-23 13:13:33 -0700215 main.log.error( self.name + ": response: " + str( self.handle.before ) )
You Wang4cc61912018-08-28 10:10:58 -0700216 return main.TRUE
217 except pexpect.EOF:
218 main.log.error( self.name + ": EOF exception found" )
219 main.log.error( self.name + ": " + self.handle.before )
220 return main.FALSE
221 except Exception:
222 main.log.exception( self.name + ": Uncaught exception!" )
223 main.log.error( self.name + ": " + self.handle.before )
224 return main.FALSE
225
Jon Hall62ab6752021-08-22 16:47:43 -0700226 def getRoutes( self ):
227 """
228 Returns the output of 'ip route show' command
229 # TODO: process and return a a list or json object
230 """
231 try:
232 cmd = "ip route show"
233 self.handle.sendline( cmd )
234 i = self.handle.expect( [ "password|Password", self.prompt ] )
235 if i == 0:
236 self.handle.sendline( self.pwd )
237 j = self.handle.expect( [ "password|Password", self.prompt ] )
238 if j != 1:
239 main.log.error( "Incorrect password" )
240 return main.FALSE
241 return self.handle.before
242 except pexpect.EOF:
243 main.log.error( self.name + ": EOF exception found" )
244 main.log.error( self.name + ": " + self.handle.before )
245 return main.FALSE
246 except Exception:
247 main.log.exception( self.name + ": Uncaught exception!" )
248 main.log.error( self.name + ": " + self.handle.before )
249 return main.FALSE
250
Jon Hallc03ade92021-09-13 17:19:10 -0700251 def addRouteToHost( self, route, gw, interface=None, sudoRequired=True, purgeOnDisconnect=True, cmdPath='/sbin/ip' ):
Jon Hall62ab6752021-08-22 16:47:43 -0700252 """
253 Adds a static route to the host
254 Arguments:
255 * route - String, CIDR notation for the destination subnet
256 * gw - String, IP address of gateway
257 Optional Arguments:
258 * interface - String, The interface to use for this route, defaults to None, or the default interface
259 * sudoRequired - Boolean, whether sudo is needed for this command, defaults to True
260 * purgeOnDisconnect - Boolean, remove this route before disconnecting from component
261 """
262 try:
Jon Hallc03ade92021-09-13 17:19:10 -0700263 if cmdPath:
264 cmd = cmdPath
265 else:
266 cmd = "ip"
267 cmd += " route add %s via %s" % ( route, gw )
Jon Hall62ab6752021-08-22 16:47:43 -0700268 if sudoRequired:
269 cmd = "sudo %s" % cmd
270 if interface:
271 cmd = "%s dev %s" % ( cmd, interface )
272 if purgeOnDisconnect:
273 self.tempRoutes.append( (route, gw, interface, sudoRequired ) )
274 self.handle.sendline( cmd )
275 i = self.handle.expect( [ "password|Password", self.prompt, "Error" ] )
276 output = ""
277 if i == 2:
278 output += self.handle.before + self.handle.after
279 self.handle.expect( self.prompt )
280 output += self.handle.before + self.handle.after
281 main.log.error( "%s: Erorr in ip route command: %s" % ( self.name, output ) )
282 return main.FALSE
283 elif i == 0:
284 self.handle.sendline( self.pwd )
285 j = self.handle.expect( [ "password|Password", self.prompt, "Error" ] )
286 if j == 0:
287 main.log.error( "Incorrect password" )
288 return main.FALSE
289 elif j == 2:
290 output += self.handle.before + self.handle.after
291 self.handle.expect( self.prompt )
292 output += self.handle.before + self.handle.after
293 main.log.error( "%s: Erorr in ip route command: %s" % ( self.name, output ) )
294 return main.FALSE
295 output += self.handle.before + self.handle.after
296 main.log.debug( output )
297 return self.handle.before
298 except pexpect.EOF:
299 main.log.error( self.name + ": EOF exception found" )
300 main.log.error( self.name + ": " + self.handle.before )
301 return main.FALSE
302 except Exception:
303 main.log.exception( self.name + ": Uncaught exception!" )
304 main.log.error( self.name + ": " + self.handle.before )
305 return main.FALSE
306
Jon Hallc03ade92021-09-13 17:19:10 -0700307 def deleteRoute( self, route, gw, interface=None, sudoRequired=True, cmdPath='/sbin/ip' ):
Jon Hall62ab6752021-08-22 16:47:43 -0700308 """
309 Deletess a static route from the host
310 Arguments:
311 * route - String, CIDR notation for the destination subnet
312 * gw - String, IP address of gateway
313 Optional Arguments:
314 * interface - String, The interface to use for this route, defaults to None, or the default interface
315 * sudoRequired - Boolean, whether sudo is needed for this command, defaults to True
316 """
317 try:
Jon Hallc03ade92021-09-13 17:19:10 -0700318 if cmdPath:
319 cmd = cmdPath
320 else:
321 cmd = "ip"
322 cmd += " route del %s via %s" % ( route, gw )
Jon Hall62ab6752021-08-22 16:47:43 -0700323 if sudoRequired:
324 cmd = "sudo %s" % cmd
325 if interface:
326 cmd = "%s dev %s" % ( cmd, interface )
327 self.handle.sendline( cmd )
328 i = self.handle.expect( [ "password|Password", self.prompt, "Error" ] )
329 output = ""
330 if i == 2:
331 output += self.handle.before + self.handle.after
332 self.handle.expect( self.prompt )
333 output += self.handle.before + self.handle.after
334 main.log.error( "%s: Erorr in ip route command: %s" % ( self.name, output ) )
335 return main.FALSE
336 elif i == 0:
337 self.handle.sendline( self.pwd )
338 j = self.handle.expect( [ "password|Password", self.prompt, "Error" ] )
339 if j == 0:
340 main.log.error( "Incorrect password" )
341 return main.FALSE
342 elif j == 2:
343 output += self.handle.before + self.handle.after
344 self.handle.expect( self.prompt )
345 output += self.handle.before + self.handle.after
346 main.log.error( "%s: Erorr in ip route command: %s" % ( self.name, output ) )
347 return main.FALSE
348 output += self.handle.before + self.handle.after
349 main.log.debug( output )
350 return self.handle.before
351 except pexpect.EOF:
352 main.log.error( self.name + ": EOF exception found" )
353 main.log.error( self.name + ": " + self.handle.before )
354 return main.FALSE
355 except Exception:
356 main.log.exception( self.name + ": Uncaught exception!" )
357 main.log.error( self.name + ": " + self.handle.before )
358 return main.FALSE
359
Jon Hallceed0a32021-06-08 11:07:00 -0700360 def getIPAddress( self, iface=None, proto='IPV4' ):
361 """
362 Returns IP address of the host
363 """
364 cmd = "ifconfig %s" % iface if iface else ""
365 response = self.command( cmd )
Jon Hall32c90f32021-06-24 16:32:44 -0700366 if "Command 'ifconfig' not found" in response:
367 # ip a show dev
368 cmd = "ip addr show %s" % iface if iface else ""
369 response = self.command( cmd )
370 pattern = ''
371 if proto == 'IPV4':
372 pattern = "inet\s(\d+\.\d+\.\d+\.\d+)/\d+"
373 else:
374 pattern = "inet6\s([\w,:]*)/\d+"
Jon Hallceed0a32021-06-08 11:07:00 -0700375 else:
Jon Hall32c90f32021-06-24 16:32:44 -0700376 pattern = ''
377 if proto == 'IPV4':
378 pattern = "inet\s(\d+\.\d+\.\d+\.\d+)\s\snetmask"
379 else:
380 pattern = "inet6\s([\w,:]*)/\d+\s\sprefixlen"
Jon Hallceed0a32021-06-08 11:07:00 -0700381 ipAddressSearch = re.search( pattern, response )
382 if not ipAddressSearch:
383 return None
384 main.log.info(
385 self.name +
386 ": IP-Address is " +
387 ipAddressSearch.group( 1 ) )
388 return ipAddressSearch.group( 1 )
389
Jon Hall43060f62020-06-23 13:13:33 -0700390 def ping( self, dst, ipv6=False, interface=None, wait=3 ):
Pier6a0c4de2018-03-18 16:01:30 -0700391 """
392 Description:
393 Ping from this host to another
394 Required:
395 dst: IP address of destination host
396 Optional:
397 ipv6: will use ping6 command if True; otherwise use ping command
Jon Hall43060f62020-06-23 13:13:33 -0700398 interface: Specify which interface to use for the ping
Pier6a0c4de2018-03-18 16:01:30 -0700399 wait: timeout for ping command
400 """
401 try:
402 command = "ping6" if ipv6 else "ping"
Jon Hall43060f62020-06-23 13:13:33 -0700403 if interface:
404 command += " -I %s " % interface
Pier6a0c4de2018-03-18 16:01:30 -0700405 command += " -c 1 -i 1 -W " + str( wait ) + " " + str( dst )
406 main.log.info( self.name + ": Sending: " + command )
407 self.handle.sendline( command )
408 i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ],
Jon Halla604fd42018-05-04 14:27:27 -0700409 timeout=wait + 5 )
Jon Hall06fd0df2021-01-25 15:50:06 -0800410 response = self.handle.before
Pier6a0c4de2018-03-18 16:01:30 -0700411 if i == 1:
412 main.log.error(
413 self.name +
414 ": timeout when waiting for response" )
Jon Hall43060f62020-06-23 13:13:33 -0700415 main.log.error( self.name + ": response: " + str( self.handle.before ) )
Pier6a0c4de2018-03-18 16:01:30 -0700416 if re.search( ',\s0\%\spacket\sloss', response ):
417 main.log.info( self.name + ": no packets lost, host is reachable" )
418 return main.TRUE
419 else:
420 main.log.warn(
421 self.name +
422 ": PACKET LOST, HOST IS NOT REACHABLE" )
423 return main.FALSE
424 except pexpect.EOF:
425 main.log.error( self.name + ": EOF exception found" )
426 main.log.error( self.name + ": " + self.handle.before )
427 main.cleanAndExit()
428 except Exception:
429 main.log.exception( self.name + ": Uncaught exception!" )
430 main.cleanAndExit()
431
You Wang0fc21702018-11-02 17:49:18 -0700432 def pingHostSetAlternative( self, dstIPList, wait=1, IPv6=False ):
433 """
434 Description:
435 Ping a set of destination host.
436 Params:
437 dstIPList is a list of destination ip addresses
438 Returns:
439 main.TRUE if the destination host is reachable
440 main.FALSE otherwise
441 """
442 isReachable = main.TRUE
443 wait = int( wait )
444 cmd = "ping"
445 if IPv6:
446 cmd = cmd + "6"
447 cmd = cmd + " -c 1 -i 1 -W " + str( wait )
448 try:
449 for dstIP in dstIPList:
450 pingCmd = cmd + " " + dstIP
451 self.handle.sendline( pingCmd )
452 i = self.handle.expect( [ self.prompt,
453 pexpect.TIMEOUT ],
454 timeout=wait + 5 )
455 if i == 0:
456 response = self.handle.before
457 if not re.search( ',\s0\%\spacket\sloss', response ):
458 main.log.debug( "Ping failed between %s and %s" % ( self.name, dstIP ) )
459 isReachable = main.FALSE
460 elif i == 1:
461 main.log.error( self.name + ": timeout when waiting for response" )
462 isReachable = main.FALSE
463 else:
464 main.log.error( self.name + ": unknown response: " + self.handle.before )
465 isReachable = main.FALSE
466 except pexpect.TIMEOUT:
467 main.log.exception( self.name + ": TIMEOUT exception" )
468 self.exitFromCmd( [ self.prompt ] )
469 isReachable = main.FALSE
470 except pexpect.EOF:
471 main.log.error( self.name + ": EOF exception found" )
472 main.log.error( self.name + ": " + self.handle.before )
473 main.cleanAndExit()
474 except Exception:
475 main.log.exception( self.name + ": Uncaught exception!" )
476 main.cleanAndExit()
477 return isReachable
478
Pier6a0c4de2018-03-18 16:01:30 -0700479 def ifconfig( self, wait=3 ):
480 """
481 Run ifconfig command on host and return output
482 """
483 try:
484 command = "ifconfig"
485 main.log.info( self.name + ": Sending: " + command )
486 self.handle.sendline( command )
Jon Hall32c90f32021-06-24 16:32:44 -0700487 i = self.handle.expect( [ "Command 'ifconfig' not found", self.prompt, pexpect.TIMEOUT ],
Jon Halla604fd42018-05-04 14:27:27 -0700488 timeout=wait + 5 )
Jon Hall32c90f32021-06-24 16:32:44 -0700489 if i == 0:
490 response = self.handle.before
491 self.handle.expect( [ self.prompt, pexpect.TIMEOUT ] )
492 response += str( self.handle.before )
493 main.log.error( self.name + ": Error running ifconfig: %s " % response )
494 return response
495 if i == 2:
Pier6a0c4de2018-03-18 16:01:30 -0700496 main.log.error(
497 self.name +
498 ": timeout when waiting for response" )
Jon Hall43060f62020-06-23 13:13:33 -0700499 main.log.error( self.name + ": response: " + str( self.handle.before ) )
Pier6a0c4de2018-03-18 16:01:30 -0700500 response = self.handle.before
501 return response
502 except pexpect.EOF:
503 main.log.error( self.name + ": EOF exception found" )
504 main.log.error( self.name + ": " + self.handle.before )
505 main.cleanAndExit()
506 except Exception:
You Wang4cc61912018-08-28 10:10:58 -0700507 main.log.exception( self.name + ": uncaught exception!" )
508 main.cleanAndExit()
509
510 def ip( self, options="a", wait=3 ):
511 """
512 Run ip command on host and return output
513 """
514 try:
515 command = "ip {}".format( options )
516 main.log.info( self.name + ": Sending: " + command )
517 self.handle.sendline( command )
518 i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ],
519 timeout=wait + 5 )
520 if i == 1:
521 main.log.error( self.name + ": timeout when waiting for response" )
Jon Hall43060f62020-06-23 13:13:33 -0700522 main.log.error( self.name + ": response: " + str( self.handle.before ) )
You Wang4cc61912018-08-28 10:10:58 -0700523 response = self.handle.before
524 return response
525 except pexpect.EOF:
526 main.log.error( self.name + ": EOF exception found" )
527 main.log.error( self.name + ": " + self.handle.before )
528 main.cleanAndExit()
529 except Exception:
530 main.log.exception( self.name + ": uncaught exception!" )
531 main.cleanAndExit()
532
Jon Hall43060f62020-06-23 13:13:33 -0700533 def command( self, cmd, wait=3, debug=False):
You Wang4cc61912018-08-28 10:10:58 -0700534 """
535 Run shell command on host and return output
536 Required:
537 cmd: command to run on the host
538 """
539 try:
540 main.log.info( self.name + ": Sending: " + cmd )
541 self.handle.sendline( cmd )
542 i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ],
543 timeout=wait + 5 )
Jon Hall43060f62020-06-23 13:13:33 -0700544 response = self.handle.before
545 if debug:
546 main.log.debug( response )
You Wang4cc61912018-08-28 10:10:58 -0700547 if i == 1:
548 main.log.error( self.name + ": timeout when waiting for response" )
Jon Hall43060f62020-06-23 13:13:33 -0700549 main.log.error( self.name + ": response: " + str( response ) )
You Wang4cc61912018-08-28 10:10:58 -0700550 return response
551 except pexpect.EOF:
552 main.log.error( self.name + ": EOF exception found" )
553 main.log.error( self.name + ": " + self.handle.before )
554 main.cleanAndExit()
555 except Exception:
556 main.log.exception( self.name + ": uncaught exception!" )
Pier6a0c4de2018-03-18 16:01:30 -0700557 main.cleanAndExit()