test suite reviews and discussions
 help / color / mirror / Atom feed
From: Yong Liu <yong.liu@intel.com>
To: dts@dpdk.org
Subject: [dts] [PATCH] framework/ssh: add session buffer flush before every command
Date: Thu,  5 Mar 2015 14:45:35 +0800	[thread overview]
Message-ID: <1425537935-22751-1-git-send-email-yong.liu@intel.com> (raw)

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

                 reply	other threads:[~2015-03-05  6:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1425537935-22751-1-git-send-email-yong.liu@intel.com \
    --to=yong.liu@intel.com \
    --cc=dts@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).