From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id B2F555A4B for ; Thu, 5 Mar 2015 07:45:44 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP; 04 Mar 2015 22:45:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,345,1422950400"; d="scan'208";a="687190117" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by fmsmga002.fm.intel.com with ESMTP; 04 Mar 2015 22:45:41 -0800 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id t256jcVX014860; Thu, 5 Mar 2015 14:45:38 +0800 Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1]) by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id t256jbf8022787; Thu, 5 Mar 2015 14:45:39 +0800 Received: (from yliu84x@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id t256jb5c022783; Thu, 5 Mar 2015 14:45:37 +0800 From: Yong Liu To: dts@dpdk.org Date: Thu, 5 Mar 2015 14:45:35 +0800 Message-Id: <1425537935-22751-1-git-send-email-yong.liu@intel.com> X-Mailer: git-send-email 1.7.4.1 Subject: [dts] [PATCH] framework/ssh: add session buffer flush before every command X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Mar 2015 06:45:45 -0000 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 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