test suite reviews and discussions
 help / color / mirror / Atom feed
* [dts] [PATCH] framework/ssh: add session buffer flush before every command
@ 2015-03-05  6:45 Yong Liu
  0 siblings, 0 replies; only message in thread
From: Yong Liu @ 2015-03-05  6:45 UTC (permalink / raw)
  To: dts

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@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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-03-05  6:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-05  6:45 [dts] [PATCH] framework/ssh: add session buffer flush before every command Yong Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).