=== modified file 'lava_dispatcher/client/master.py'
@@ -297,13 +297,58 @@
pre_connect = self.device_option("pre_connect_command")
if pre_connect:
logging_system(pre_connect)
+ self.proc = self._connect_carefully()
+ atexit.register(self._close_logging_spawn)
+
+ def _connect_carefully(self):
cmd = self.device_option("connection_command")
- proc = logging_spawn(cmd, timeout=1200)
- proc.logfile_read = self.sio
- #serial can be slow, races do funny things if you don't increase delay
- proc.delaybeforesend=1
- self.proc = proc
- atexit.register(self._close_logging_spawn)
+
+ retry_count = 0
+ retry_limit = 3
+
+ port_stuck_message = 'Data Buffering Suspended\.'
+ hot_key_message = 'Type the hot key to suspend the connection:.*\r'
+ conn_closed_message = 'Connection closed by foreign host\.'
+
+ expectations = {
+ port_stuck_message: 'reset-port',
+ 'Connected\.\r': 'all-good',
+ hot_key_message: 'all-good',
+ conn_closed_message: 'retry',
+ pexpect.TIMEOUT: 'all-good',
+ }
+ patterns = []
+ results = []
+ for pattern, result in expectations.items():
+ patterns.append(pattern)
+ results.append(result)
+
+ while retry_count < retry_limit:
+ proc = logging_spawn(cmd, timeout=1200)
+ proc.logfile_read = self.sio
+ #serial can be slow, races do funny things if you don't increase delay
+ proc.delaybeforesend=1
+ logging.info('Attempting to connect to device')
+ match = proc.expect(patterns, timeout=10)
+ result = results[match]
+ logging.info('Matched %r which means %s', patterns[match], result)
+ if result == 'retry':
+ proc.close(True)
+ retry_count += 1
+ time.sleep(5)
+ continue
+ elif result == 'all-good':
+ return proc
+ elif result == 'reset-port':
+ reset_port = self.device_option("reset_port_command")
+ if reset_port:
+ logging_system(reset_port)
+ else:
+ raise OperationFailed("no reset_port command configured")
+ proc.close(True)
+ retry_count += 1
+ time.sleep(5)
+ raise OperationFailed("could execute connection_command successfully")
@property
def master_str(self):