From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 64A475A76 for ; Wed, 14 Jan 2015 02:22:17 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP; 13 Jan 2015 17:17:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.07,753,1413270000"; d="scan'208";a="650738586" Received: from pgsmsx101.gar.corp.intel.com ([10.221.44.78]) by fmsmga001.fm.intel.com with ESMTP; 13 Jan 2015 17:22:15 -0800 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by PGSMSX101.gar.corp.intel.com (10.221.44.78) with Microsoft SMTP Server (TLS) id 14.3.195.1; Wed, 14 Jan 2015 09:18:27 +0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.192]) by shsmsx102.ccr.corp.intel.com ([169.254.2.238]) with mapi id 14.03.0195.001; Wed, 14 Jan 2015 09:18:26 +0800 From: "Liu, Yong" To: "Qiu, Michael" , "dts@dpdk.org" Thread-Topic: [PATCH 3/6] framework: Add login password support Thread-Index: AQHQLzbNHc6AISNfb0uTZavGKfcKWpy+0VaQ Date: Wed, 14 Jan 2015 01:18:25 +0000 Message-ID: <86228AFD5BCD8E4EBFD2B90117B5E81E10D4C242@SHSMSX103.ccr.corp.intel.com> References: <1421156540-25810-1-git-send-email-michael.qiu@intel.com> <1421156540-25810-4-git-send-email-michael.qiu@intel.com> In-Reply-To: <1421156540-25810-4-git-send-email-michael.qiu@intel.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [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: Wed, 14 Jan 2015 01:22:18 -0000 That's good idea. DTS should support both with password and without passwo= rd. > -----Original Message----- > From: Qiu, Michael > Sent: Tuesday, January 13, 2015 9:42 PM > To: dts@dpdk.org > Cc: Liu, Yong; Qiu, Michael > Subject: [PATCH 3/6] framework: Add login password support >=20 > DTS login dut and tester machine via ssh service while > public and private keys are needed. >=20 > That means it can't use the user:password to login, which > should not always be a good idea. >=20 > Add login with password for another choice. >=20 > 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(-) >=20 > 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 =3D [ > '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 =3D 'dut' > self.logger =3D getLogger(self.NAME) > - self.session =3D SSHConnection(self.get_ip_address(), self.NAME) > + self.session =3D SSHConnection(self.get_ip_address(), self.NAME, > + self.get_password()) > self.session.init_log(self.logger) > - self.alt_session =3D SSHConnection(self.get_ip_address(), self.N= AME) > + self.alt_session =3D SSHConnection(self.get_ip_address(), self.N= AME, > + self.get_password()) > self.alt_session.init_log(self.logger) > self.number_of_cores =3D 0 > self.tester =3D None > @@ -120,6 +122,12 @@ class Dut(Crb): > """ > return self.crb['IP'] >=20 > + 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 cas= e. > 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 =3D tester > self.NAME =3D 'ixia' > self.logger =3D 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) >=20 > self.tcl_cmds =3D [] > @@ -170,6 +172,9 @@ class IxiaPacketGenerator(SSHConnection): > def get_ip_address(self): > return self.tester.get_ip_address() >=20 > + 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. > """ >=20 > - def __init__(self, host, session_name): > - self.session =3D SSHPexpect(host, USERNAME) > + def __init__(self, host, session_name, password =3D ''): > + self.session =3D SSHPexpect(host, USERNAME, password) > self.name =3D session_name >=20 > 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. >=20 > class SSHPexpect(object): >=20 > - def __init__(self, host, username): > + def __init__(self, host, username, password): > try: > self.session =3D pxssh.pxssh() > self.username =3D username > self.host =3D host > - self.session.login(self.host, self.username) > + self.password =3D password > + self.session.login(self.host, self.username, > + self.password, original_prompt=3D'[$#>]') > self.send_expect('stty -echo', '# ', timeout=3D2) > except Exception: > raise SSHConnectionException(host) > @@ -69,21 +71,20 @@ class SSHPexpect(object): > Copies a file from a remote place into local. > """ > command =3D 'scp {0}@{1}:{2} .'.format(self.username, self.host,= filename) > - self._spawn_scp(command, password) > + if password =3D=3D '': > + self._spawn_scp(command, self.password) > + else: > + self._spawn_scp(command, password) >=20 > def copy_file_to(self, filename, password=3D''): > """ > Sends a local file to a remote place. > """ > command =3D 'scp {0} {1}@{2}:'.format(filename, self.username, s= elf.host) > - self._spawn_scp(command, password) > - > - def copy_file_from(self, filename, password=3D''): > - """ > - copy a remote file to a local place. > - """ > - command =3D 'scp {1}@{2}:{0} .'.format(filename, self.username, = self.host) > - self._spawn_scp(command, password) > + if password =3D=3D '': > + self._spawn_scp(command, self.password) > + else: > + self._spawn_scp(command, password) >=20 > 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 =3D 'tester' >=20 > self.logger =3D getLogger(self.NAME) > - self.session =3D SSHConnection(self.get_ip_address(), self.NAME) > + self.session =3D SSHConnection(self.get_ip_address(), > + self.NAME, self.get_password()) > self.session.init_log(self.logger) > - self.alt_session =3D SSHConnection(self.get_ip_address(), self.N= AME) > + self.alt_session =3D SSHConnection(self.get_ip_address(), > + self.NAME, self.get_password()) > self.alt_session.init_log(self.logger) >=20 > self.ports_map =3D [] > @@ -88,6 +90,12 @@ class Tester(Crb): > """ > return self.crb['tester IP'] >=20 > + 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