* [dts] [PATCH 1/2] framework: add exception for closed session
@ 2015-05-13 5:49 Yong Liu
2015-05-13 5:49 ` [dts] [PATCH 2/2] framework: new function just return dut session message in certain time Yong Liu
0 siblings, 1 reply; 2+ messages in thread
From: Yong Liu @ 2015-05-13 5:49 UTC (permalink / raw)
To: dts
From: Marvin Liu <yong.liu@intel.com>
Signed-off-by: Marvin Liu <yong.liu@intel.com>
diff --git a/framework/exception.py b/framework/exception.py
index be38c16..17bfccf 100644
--- a/framework/exception.py
+++ b/framework/exception.py
@@ -46,3 +46,17 @@ class SSHConnectionException(Exception):
def __str__(self):
return 'Error trying to connect with %s' % self.host
+
+
+class SSHSessionDeadException(Exception):
+
+ """
+ SSH session is not alive.
+ It can no longer be used.
+ """
+
+ def __init__(self, host):
+ self.host = host
+
+ def __str__(self):
+ return 'SSH session with %s has been dead' % self.host
--
1.9.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* [dts] [PATCH 2/2] framework: new function just return dut session message in certain time
2015-05-13 5:49 [dts] [PATCH 1/2] framework: add exception for closed session Yong Liu
@ 2015-05-13 5:49 ` Yong Liu
0 siblings, 0 replies; 2+ messages in thread
From: Yong Liu @ 2015-05-13 5:49 UTC (permalink / raw)
To: dts
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-05-13 5:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-13 5:49 [dts] [PATCH 1/2] framework: add exception for closed session Yong Liu
2015-05-13 5:49 ` [dts] [PATCH 2/2] framework: new function just return dut session message in certain time Yong Liu
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).