diff --git a/lisa/features/serial_console.py b/lisa/features/serial_console.py index a3e77b7824..f666c3b8c0 100644 --- a/lisa/features/serial_console.py +++ b/lisa/features/serial_console.py @@ -195,3 +195,7 @@ def read(self) -> str: def write(self, data: str) -> None: raise NotImplementedError + + def close(self) -> None: + # it's not required to implement close method. + pass diff --git a/lisa/sut_orchestrator/azure/features.py b/lisa/sut_orchestrator/azure/features.py index ec39961dcf..31d7f920a1 100644 --- a/lisa/sut_orchestrator/azure/features.py +++ b/lisa/sut_orchestrator/azure/features.py @@ -345,6 +345,12 @@ def read(self) -> str: self._get_connection() raise e + def close(self) -> None: + if self._ws is not None: + self._log.debug("Closing connection to serial console") + self._get_event_loop().run_until_complete(self._ws.close()) + self._ws = None + def _get_event_loop(self) -> asyncio.AbstractEventLoop: # create asyncio loop if it doesn't exist try: diff --git a/microsoft/testsuites/core/serial_console.py b/microsoft/testsuites/core/serial_console.py index a75a2b0f9e..2867f179cf 100644 --- a/microsoft/testsuites/core/serial_console.py +++ b/microsoft/testsuites/core/serial_console.py @@ -37,13 +37,15 @@ def verify_serial_console(self, log: Logger, node: Node) -> None: serial_console = node.features[SerialConsole] # retry to read serial console output, because it may not be ready - for _ in range(180): + for i in range(180): _ = serial_console.read() serial_console.write(command) output = serial_console.read() # check if the output contains the command if command in output: + serial_console.close() + log.debug(f"called {i} times, get output from serial console: {output}") break # sleep for 1 second