From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 7FBF65A31 for ; Wed, 13 May 2015 07:49:20 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP; 12 May 2015 22:49:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,419,1427785200"; d="scan'208";a="570533562" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by orsmga003.jf.intel.com with ESMTP; 12 May 2015 22:49:17 -0700 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id t4D5nF1m015704; Wed, 13 May 2015 13:49:15 +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 t4D5nCvc020005; Wed, 13 May 2015 13:49:15 +0800 Received: (from yliu84x@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id t4D5nCxN020001; Wed, 13 May 2015 13:49:12 +0800 From: Yong Liu To: dts@dpdk.org Date: Wed, 13 May 2015 13:49:06 +0800 Message-Id: <1431496146-19962-2-git-send-email-yong.liu@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1431496146-19962-1-git-send-email-yong.liu@intel.com> References: <1431496146-19962-1-git-send-email-yong.liu@intel.com> Subject: [dts] [PATCH 2/2] framework: new function just return dut session message in certain time 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: Wed, 13 May 2015 05:49:21 -0000 From: Marvin Liu Add new function which will return all the output message before timeout. This function will be used in scenario like dut start one application, then tester send packets to dut and need to check the message output from dut. Optimize basic ssh_pexpect module, make sure buffer has been flushed. Optimize basic ssh_pexpect module, when session close will raised expection. Signed-off-by: Marvin Liu diff --git a/framework/crb.py b/framework/crb.py index a699bfc..0b63f24 100644 --- a/framework/crb.py +++ b/framework/crb.py @@ -69,6 +69,12 @@ class Crb(object): return self.session.send_expect(cmds, expected, timeout, verify) + def get_session_output(self, timeout=TIMEOUT): + """ + Get session output message before timeout + """ + return self.session.get_session_before(timeout) + def set_test_types(self, func_tests, perf_tests): """ Enable or disable function/performance test. diff --git a/framework/ssh_connection.py b/framework/ssh_connection.py index 18a6517..7286b14 100644 --- a/framework/ssh_connection.py +++ b/framework/ssh_connection.py @@ -62,6 +62,11 @@ class SSHConnection(object): self.logger.debug(out) return out + def get_session_before(self, timeout=15): + out = self.session.get_session_before(timeout) + self.logger.debug(out) + return out + def close(self): self.session.close() diff --git a/framework/ssh_pexpect.py b/framework/ssh_pexpect.py index 735df44..812d97b 100644 --- a/framework/ssh_pexpect.py +++ b/framework/ssh_pexpect.py @@ -2,7 +2,7 @@ import time import pexpect import pxssh from debugger import ignore_keyintr, aware_keyintr -from exception import TimeoutException, SSHConnectionException +from exception import TimeoutException, SSHConnectionException, SSHSessionDeadException """ Module handle ssh sessions between tester and DUT. @@ -14,7 +14,7 @@ Aslo support transfer files to tester or DUT. class SSHPexpect(object): def __init__(self, host, username, password): - self.magic_prompt = "[MAGIC PROMPT]" + self.magic_prompt = "MAGIC PROMPT" try: self.session = pxssh.pxssh() self.username = username @@ -31,7 +31,7 @@ class SSHPexpect(object): self.logger.config_execution(name) self.logger.info("ssh %s@%s" % (self.username, self.host)) - def send_expect_base(self, command, expected, timeout=15): + def send_expect_base(self, command, expected, timeout): ignore_keyintr() self.__flush() # clear buffer self.session.PROMPT = expected @@ -54,21 +54,44 @@ class SSHPexpect(object): else: return ret - def __flush(self): + def get_session_before(self, timeout): + """ + Get all output before timeout + """ + ignore_keyintr() self.session.PROMPT = self.magic_prompt - self.session.prompt(0.1) + try: + self.session.prompt(timeout) + except Exception as e: + pass + + aware_keyintr() + before = self.get_output_before() + self.__flush() + return before + + def __flush(self): + """ + Clear all session buffer + """ + self.session.buffer = "" + self.session.before = "" def __prompt(self, command, timeout): if not self.session.prompt(timeout): raise TimeoutException(command, self.get_output_all()) def __sendline(self, command): + if not self.isalive(): + raise SSHSessionDeadException(self.host) if len(command) == 2 and command.startswith('^'): self.session.sendcontrol(command[1]) else: self.session.sendline(command) def get_output_before(self): + if not self.isalive(): + raise SSHSessionDeadException(self.host) self.session.flush() before = self.session.before.rsplit('\r\n', 1) if before[0] == "[PEXPECT]": -- 1.9.3