[dts] [PATCH 2/4] framework: maintain connected session list and disable debug mode in send_expect
Yong Liu
yong.liu at intel.com
Tue Apr 28 16:56:30 CEST 2015
From: Marvin Liu <yong.liu at intel.com>
Signed-off-by: Marvin Liu <yong.liu at intel.com>
---
framework/ssh_connection.py | 7 +++++++
framework/ssh_pexpect.py | 10 +++++++---
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/framework/ssh_connection.py b/framework/ssh_connection.py
index b10cb4f..18a6517 100644
--- a/framework/ssh_connection.py
+++ b/framework/ssh_connection.py
@@ -32,6 +32,10 @@
from ssh_pexpect import SSHPexpect
from settings import USERNAME
+"""
+Global structure for saving connections
+"""
+CONNECTIONS = []
class SSHConnection(object):
@@ -43,6 +47,9 @@ class SSHConnection(object):
def __init__(self, host, session_name, password=''):
self.session = SSHPexpect(host, USERNAME, password)
self.name = session_name
+ connection = {}
+ connection[self.name] = self.session
+ CONNECTIONS.append(connection)
def init_log(self, logger):
self.logger = logger
diff --git a/framework/ssh_pexpect.py b/framework/ssh_pexpect.py
index eaa3a42..735df44 100644
--- a/framework/ssh_pexpect.py
+++ b/framework/ssh_pexpect.py
@@ -1,6 +1,7 @@
import time
import pexpect
import pxssh
+from debugger import ignore_keyintr, aware_keyintr
from exception import TimeoutException, SSHConnectionException
"""
@@ -31,12 +32,15 @@ class SSHPexpect(object):
self.logger.info("ssh %s@%s" % (self.username, self.host))
def send_expect_base(self, command, expected, timeout=15):
- # clear buffer
- self.__flush()
+ ignore_keyintr()
+ self.__flush() # clear buffer
self.session.PROMPT = expected
self.__sendline(command)
self.__prompt(command, timeout)
- return self.get_output_before()
+ aware_keyintr()
+
+ before = self.get_output_before()
+ return before
def send_expect(self, command, expected, timeout=15, verify=False):
ret = self.send_expect_base(command, expected, timeout)
--
1.9.3
More information about the dts
mailing list