297
297
pre_connect = self.device_option("pre_connect_command")
299
299
logging_system(pre_connect)
300
self.proc = self._connect_carefully()
301
atexit.register(self._close_logging_spawn)
303
def _connect_carefully(self):
300
304
cmd = self.device_option("connection_command")
301
proc = logging_spawn(cmd, timeout=1200)
302
proc.logfile_read = self.sio
303
#serial can be slow, races do funny things if you don't increase delay
304
proc.delaybeforesend=1
306
atexit.register(self._close_logging_spawn)
309
port_stuck_message = 'Data Buffering Suspended\.'
310
hot_key_message = 'Type the hot key to suspend the connection:.*\r'
311
conn_closed_message = 'Connection closed by foreign host\.'
314
port_stuck_message: 'reset-port',
315
'Connected\.\r': 'all-good',
316
hot_key_message: 'all-good',
317
conn_closed_message: 'retry',
318
pexpect.TIMEOUT: 'all-good',
322
for pattern, result in expectations.items():
323
patterns.append(pattern)
324
results.append(result)
326
while retry_count < retry_limit:
327
proc = logging_spawn(cmd, timeout=1200)
328
proc.logfile_read = self.sio
329
#serial can be slow, races do funny things if you don't increase delay
330
proc.delaybeforesend=1
331
logging.info('Attempting to connect to device')
332
match = proc.expect(patterns, timeout=10)
333
result = results[match]
334
logging.info('Matched %r which means %s', patterns[match], result)
335
if result == 'retry':
340
elif result == 'all-good':
342
elif result == 'reset-port':
343
reset_port = self.device_option("reset_port_command")
345
logging_system(reset_port)
347
raise OperationFailed("no reset_port command configured")
351
raise OperationFailed("could execute connection_command successfully")
309
354
def master_str(self):