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 164C1A0C43; Thu, 5 Aug 2021 03:52:08 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D6CA14014F; Thu, 5 Aug 2021 03:52:07 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id 666E740143 for ; Thu, 5 Aug 2021 03:52:06 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10066"; a="275100587" X-IronPort-AV: E=Sophos;i="5.84,296,1620716400"; d="scan'208";a="275100587" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2021 18:52:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,296,1620716400"; d="scan'208";a="480489856" Received: from unknown (HELO dpdk-lijuan.sh.intel.com) ([10.67.119.192]) by fmsmga008.fm.intel.com with ESMTP; 04 Aug 2021 18:52:03 -0700 From: Lijuan Tu To: dts@dpdk.org, reshma.pattan@intel.com Cc: Lijuan Tu Date: Thu, 5 Aug 2021 17:41:54 +0800 Message-Id: <1628156514-12397-1-git-send-email-lijuan.tu@intel.com> X-Mailer: git-send-email 1.8.3.1 Subject: [dts] [v2,] 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 | 17 ++++++++--------- 2 files changed, 12 insertions(+), 12 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..adc97b5 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,16 +161,13 @@ 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.strip('\r\n') def get_output_all(self): - output = self.session.before - output.replace("[PEXPECT]", "") - return output + output = self.session.before.strip('[PEXPECT]') + return output.strip('\r\n') def close(self, force=False): if force is True: -- 1.8.3.1