diff mbox series

[v2] framework: fix session output

Message ID 1628156514-12397-1-git-send-email-lijuan.tu@intel.com (mailing list archive)
State Superseded
Headers show
Series [v2] framework: fix session output | expand

Checks

Context Check Description
ci/Intel-dts-test fail Testing issues

Commit Message

Tu, Lijuan Aug. 5, 2021, 9:41 a.m. UTC
* 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 <lijuan.tu@intel.com>
Reported-by: Reshma Pattan <reshma.pattan@intel.com>
---
 framework/crb.py         |  7 ++++---
 framework/ssh_pexpect.py | 17 ++++++++---------
 2 files changed, 12 insertions(+), 12 deletions(-)

Comments

Pattan, Reshma Aug. 31, 2021, 9:21 a.m. UTC | #1
> -----Original Message-----
> From: Tu, Lijuan <lijuan.tu@intel.com>
> Sent: Thursday, August 5, 2021 10:42 AM
> To: dts@dpdk.org; Pattan, Reshma <reshma.pattan@intel.com>
> Cc: Tu, Lijuan <Lijuan.Tu@intel.com>
> Subject: [v2,] framework: fix session output
> 
> * 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 <lijuan.tu@intel.com>
> Reported-by: Reshma Pattan <reshma.pattan@intel.com>

You can rebase this and apply. 

Tested-by: Reshma Pattan <reshma.pattan@intel.com>
diff mbox series

Patch

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: