From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 3F25B5A8C for ; Tue, 13 Jan 2015 14:42:39 +0100 (CET) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 13 Jan 2015 05:39:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.07,750,1413270000"; d="scan'208";a="636605627" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by orsmga001.jf.intel.com with ESMTP; 13 Jan 2015 05:42:37 -0800 Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com [10.239.29.89]) by shvmail01.sh.intel.com with ESMTP id t0DDgZPc012863; Tue, 13 Jan 2015 21:42:35 +0800 Received: from shecgisg004.sh.intel.com (localhost [127.0.0.1]) by shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id t0DDgXtw025865; Tue, 13 Jan 2015 21:42:35 +0800 Received: (from dayuqiu@localhost) by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id t0DDgX4o025861; Tue, 13 Jan 2015 21:42:33 +0800 From: Michael Qiu To: dts@dpdk.org Date: Tue, 13 Jan 2015 21:42:17 +0800 Message-Id: <1421156540-25810-4-git-send-email-michael.qiu@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1421156540-25810-1-git-send-email-michael.qiu@intel.com> References: <1421156540-25810-1-git-send-email-michael.qiu@intel.com> Cc: yong.liu@intel.com Subject: [dts] [PATCH 3/6] framework: Add login password support X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Jan 2015 13:42:40 -0000 DTS login dut and tester machine via ssh service while public and private keys are needed. That means it can't use the user:password to login, which should not always be a good idea. Add login with password for another choice. Signed-off-by: Michael Qiu --- framework/crbs.py | 1 + framework/dut.py | 12 ++++++++++-- framework/etgen.py | 7 ++++++- framework/ssh_connection.py | 4 ++-- framework/ssh_pexpect.py | 23 ++++++++++++----------- framework/tester.py | 12 ++++++++++-- 6 files changed, 41 insertions(+), 18 deletions(-) diff --git a/framework/crbs.py b/framework/crbs.py index 77446c3..6aa5435 100644 --- a/framework/crbs.py +++ b/framework/crbs.py @@ -10,6 +10,7 @@ crbs = [ 'user': '', 'pass': '', 'tester IP': '', + 'tester pass': '', IXIA: None, 'memory channels': 4, 'bypass core0': True}, diff --git a/framework/dut.py b/framework/dut.py index 4def144..d7099ef 100644 --- a/framework/dut.py +++ b/framework/dut.py @@ -59,9 +59,11 @@ class Dut(Crb): super(Dut, self).__init__(crb, serializer) self.NAME = 'dut' self.logger = getLogger(self.NAME) - self.session = SSHConnection(self.get_ip_address(), self.NAME) + self.session = SSHConnection(self.get_ip_address(), self.NAME, + self.get_password()) self.session.init_log(self.logger) - self.alt_session = SSHConnection(self.get_ip_address(), self.NAME) + self.alt_session = SSHConnection(self.get_ip_address(), self.NAME, + self.get_password()) self.alt_session.init_log(self.logger) self.number_of_cores = 0 self.tester = None @@ -120,6 +122,12 @@ class Dut(Crb): """ return self.crb['IP'] + def get_password(self): + """ + Get DUT's login password. + """ + return self.crb['pass'] + def dut_prerequisites(self): """ Prerequest function should be called before execute any test case. diff --git a/framework/etgen.py b/framework/etgen.py index fe7100c..2f2e975 100644 --- a/framework/etgen.py +++ b/framework/etgen.py @@ -137,7 +137,9 @@ class IxiaPacketGenerator(SSHConnection): self.tester = tester self.NAME = 'ixia' self.logger = getLogger(self.NAME) - super(IxiaPacketGenerator, self).__init__(self.get_ip_address(), self.NAME) + super(IxiaPacketGenerator, self).__init__(self.get_ip_address(), + self.NAME, + self.get_password()) super(IxiaPacketGenerator, self).init_log(self.logger) self.tcl_cmds = [] @@ -170,6 +172,9 @@ class IxiaPacketGenerator(SSHConnection): def get_ip_address(self): return self.tester.get_ip_address() + def get_password(self): + return self.tester.get_password() + def add_tcl_cmd(self, cmd): """ Add one tcl command into command list. diff --git a/framework/ssh_connection.py b/framework/ssh_connection.py index be1fb76..4306162 100644 --- a/framework/ssh_connection.py +++ b/framework/ssh_connection.py @@ -40,8 +40,8 @@ class SSHConnection(object): Implement send_expect/copy function upper SSHPexpet module. """ - def __init__(self, host, session_name): - self.session = SSHPexpect(host, USERNAME) + def __init__(self, host, session_name, password = ''): + self.session = SSHPexpect(host, USERNAME, password) self.name = session_name def init_log(self, logger): diff --git a/framework/ssh_pexpect.py b/framework/ssh_pexpect.py index 8fb441b..9c353e7 100644 --- a/framework/ssh_pexpect.py +++ b/framework/ssh_pexpect.py @@ -12,12 +12,14 @@ Aslo support transfer files to tester or DUT. class SSHPexpect(object): - def __init__(self, host, username): + def __init__(self, host, username, password): try: self.session = pxssh.pxssh() self.username = username self.host = host - self.session.login(self.host, self.username) + self.password = password + self.session.login(self.host, self.username, + self.password, original_prompt='[$#>]') self.send_expect('stty -echo', '# ', timeout=2) except Exception: raise SSHConnectionException(host) @@ -69,21 +71,20 @@ class SSHPexpect(object): Copies a file from a remote place into local. """ command = 'scp {0}@{1}:{2} .'.format(self.username, self.host, filename) - self._spawn_scp(command, password) + if password == '': + self._spawn_scp(command, self.password) + else: + self._spawn_scp(command, password) def copy_file_to(self, filename, password=''): """ Sends a local file to a remote place. """ command = 'scp {0} {1}@{2}:'.format(filename, self.username, self.host) - self._spawn_scp(command, password) - - def copy_file_from(self, filename, password=''): - """ - copy a remote file to a local place. - """ - command = 'scp {1}@{2}:{0} .'.format(filename, self.username, self.host) - self._spawn_scp(command, password) + if password == '': + self._spawn_scp(command, self.password) + else: + self._spawn_scp(command, password) def _spawn_scp(self, scp_cmd, password): """ diff --git a/framework/tester.py b/framework/tester.py index d69503a..0ebe29a 100644 --- a/framework/tester.py +++ b/framework/tester.py @@ -61,9 +61,11 @@ class Tester(Crb): self.NAME = 'tester' self.logger = getLogger(self.NAME) - self.session = SSHConnection(self.get_ip_address(), self.NAME) + self.session = SSHConnection(self.get_ip_address(), + self.NAME, self.get_password()) self.session.init_log(self.logger) - self.alt_session = SSHConnection(self.get_ip_address(), self.NAME) + self.alt_session = SSHConnection(self.get_ip_address(), + self.NAME, self.get_password()) self.alt_session.init_log(self.logger) self.ports_map = [] @@ -88,6 +90,12 @@ class Tester(Crb): """ return self.crb['tester IP'] + def get_password(self): + """ + Get tester login password of tester CRB. + """ + return self.crb['tester pass'] + def has_external_traffic_generator(self): """ Check whether performance test will base on IXIA equipment. -- 1.9.3