From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id BF5DAA0C41; Mon, 2 Aug 2021 16:03:02 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AC8EA41147; Mon, 2 Aug 2021 16:03:02 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id EAFF040140 for ; Mon, 2 Aug 2021 16:03:00 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10063"; a="200632032" X-IronPort-AV: E=Sophos;i="5.84,289,1620716400"; d="scan'208";a="200632032" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Aug 2021 07:02:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,289,1620716400"; d="scan'208";a="510169004" Received: from unknown (HELO dpdk-lijuan.sh.intel.com) ([10.67.119.192]) by FMSMGA003.fm.intel.com with ESMTP; 02 Aug 2021 07:02:19 -0700 From: Lijuan Tu To: reshma.pattan@intel.com Cc: dts@dpdk.org, Lijuan Tu Date: Tue, 3 Aug 2021 05:52:04 +0800 Message-Id: <1627941124-172249-1-git-send-email-lijuan.tu@intel.com> X-Mailer: git-send-email 1.8.3.1 Subject: [dts] [PATCH] framework: fix session output X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dts-bounces@dpdk.org Sender: "dts" * it should flush buffer before getting output * fix strip space in all session output * fix some output don't have \r\n before [PEXPECT] Signed-off-by: Lijuan Tu Reported-by: Reshma Pattan --- framework/crb.py | 7 ++++--- framework/ssh_pexpect.py | 15 +++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/framework/crb.py b/framework/crb.py index 3964e21..e029e71 100644 --- a/framework/crb.py +++ b/framework/crb.py @@ -94,10 +94,11 @@ class Crb(object): # sometimes there will be no alt_session like VM dut if alt_session and self.alt_session: - return self.alt_session.session.send_expect(cmds, expected, + out = self.alt_session.session.send_expect(cmds, expected, timeout, verify) - - return self.session.send_expect(cmds, expected, timeout, verify) + else: + out = self.session.send_expect(cmds, expected, timeout, verify) + return out.strip() def create_session(self, name=""): """ diff --git a/framework/ssh_pexpect.py b/framework/ssh_pexpect.py index fbc7dd4..6fcaa20 100644 --- a/framework/ssh_pexpect.py +++ b/framework/ssh_pexpect.py @@ -78,6 +78,8 @@ class SSHPexpect: self.clean_session() self.session.PROMPT = expected self.__sendline(command) + # flush buffer before prompt, else buffer may impact output + self.__flush() self.__prompt(command, timeout) aware_keyintr() @@ -127,13 +129,13 @@ class SSHPexpect: ignore_keyintr() self.session.PROMPT = self.magic_prompt try: + self.__flush() self.session.prompt(timeout) except Exception as e: - pass + raise(e) aware_keyintr() before = self.get_output_all() - self.__flush() return before @@ -159,15 +161,12 @@ class SSHPexpect: def get_output_before(self): if not self.isalive(): raise SSHSessionDeadException(self.host) - before = self.session.before.rsplit('\r\n', 1) - if before[0] == "[PEXPECT]": - before[0] = "" - return before[0] + before = self.session.before.strip('[PEXPECT]') + return before def get_output_all(self): - output = self.session.before - output.replace("[PEXPECT]", "") + output = self.session.before.strip('[PEXPECT]') return output def close(self, force=False): -- 1.8.3.1