From: Yong Liu <yong.liu@intel.com>
To: dts@dpdk.org
Subject: [dts] [PATCH 2/2] framework: new function just return dut session message in certain time
Date: Wed, 13 May 2015 13:49:06 +0800 [thread overview]
Message-ID: <1431496146-19962-2-git-send-email-yong.liu@intel.com> (raw)
In-Reply-To: <1431496146-19962-1-git-send-email-yong.liu@intel.com>
From: Marvin Liu <yong.liu@intel.com>
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 <yong.liu@intel.com>
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
prev parent reply other threads:[~2015-05-13 5:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-13 5:49 [dts] [PATCH 1/2] framework: add exception for closed session Yong Liu
2015-05-13 5:49 ` Yong Liu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1431496146-19962-2-git-send-email-yong.liu@intel.com \
--to=yong.liu@intel.com \
--cc=dts@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).