[dts] [PATCH] framework/ssh: add session buffer flush before every command

Yong Liu yong.liu at intel.com
Thu Mar 5 07:45:35 CET 2015


Sometimes unexpected message will occure in ssh session like kenrel panic.
This patch add function which can flush ssh pty output buffer. The function
should be called before send any command to ssh session.

Signed-off-by: Marvin Liu <yong.liu at intel.com>

diff --git a/framework/ssh_pexpect.py b/framework/ssh_pexpect.py
index d85c2eb..eaa3a42 100644
--- a/framework/ssh_pexpect.py
+++ b/framework/ssh_pexpect.py
@@ -13,6 +13,7 @@ Aslo support transfer files to tester or DUT.
 class SSHPexpect(object):
 
     def __init__(self, host, username, password):
+        self.magic_prompt = "[MAGIC PROMPT]"
         try:
             self.session = pxssh.pxssh()
             self.username = username
@@ -30,6 +31,8 @@ class SSHPexpect(object):
         self.logger.info("ssh %s@%s" % (self.username, self.host))
 
     def send_expect_base(self, command, expected, timeout=15):
+        # clear buffer
+        self.__flush()
         self.session.PROMPT = expected
         self.__sendline(command)
         self.__prompt(command, timeout)
@@ -47,6 +50,10 @@ class SSHPexpect(object):
         else:
             return ret
 
+    def __flush(self):
+        self.session.PROMPT = self.magic_prompt
+        self.session.prompt(0.1)
+
     def __prompt(self, command, timeout):
         if not self.session.prompt(timeout):
             raise TimeoutException(command, self.get_output_all())
-- 
1.9.3



More information about the dts mailing list