[PATCH v1] dts: fix ssh timeout and output

Juraj Linkeš juraj.linkes at pantheon.tech
Thu Oct 27 16:09:45 CEST 2022


We were always waiting the full timeout because we always waited for
the MAGIC_PROMPT, which is only usable for cleaning the session of
previous data. That also meant that the actual prompt was appended to
the output, resulting in output being '[PEXPECT]#' when the executed
command produced empty output. Both are fixed by using the MAGIC_PROMPT
only in self._clean_session.

Fixes: e81a070a1c7d ("dts: add ssh session module")

Signed-off-by: Juraj Linkeš <juraj.linkes at pantheon.tech>
---
 dts/framework/remote_session/ssh_session.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/dts/framework/remote_session/ssh_session.py b/dts/framework/remote_session/ssh_session.py
index f71acfb1ca..dc37e9772b 100644
--- a/dts/framework/remote_session/ssh_session.py
+++ b/dts/framework/remote_session/ssh_session.py
@@ -116,7 +116,9 @@ def send_expect_base(self, command: str, prompt: str, timeout: float) -> str:
         return before
 
     def _clean_session(self) -> None:
+        self.session.PROMPT = self.magic_prompt
         self.get_output(timeout=0.01)
+        self.session.PROMPT = self.session.UNIQUE_PROMPT
 
     def _send_line(self, command: str) -> None:
         if not self.is_alive():
@@ -134,7 +136,6 @@ def get_output(self, timeout: float = 15) -> str:
         """
         Get all output before timeout
         """
-        self.session.PROMPT = self.magic_prompt
         try:
             self.session.prompt(timeout)
         except Exception:
@@ -143,7 +144,6 @@ def get_output(self, timeout: float = 15) -> str:
         before = self._get_output()
         self._flush()
 
-        self.logger.debug(before)
         return before
 
     def _get_output(self) -> str:
-- 
2.30.2



More information about the dev mailing list