From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 0ED1DB54C for ; Sun, 15 Feb 2015 06:05:31 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 14 Feb 2015 21:05:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,579,1418112000"; d="scan'208";a="666558685" Received: from pgsmsx108.gar.corp.intel.com ([10.221.44.103]) by fmsmga001.fm.intel.com with ESMTP; 14 Feb 2015 21:05:30 -0800 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by PGSMSX108.gar.corp.intel.com (10.221.44.103) with Microsoft SMTP Server (TLS) id 14.3.195.1; Sun, 15 Feb 2015 13:05:28 +0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.197]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.192]) with mapi id 14.03.0195.001; Sun, 15 Feb 2015 13:05:27 +0800 From: "Liu, Yong" To: "Qiu, Michael" , "dts@dpdk.org" Thread-Topic: [dts] [PATCH v2] framework/ssh: Add verify ability for command execution Thread-Index: AQHQOfFVKP/8jcUV10yM5jf3897REZzxRgcA Date: Sun, 15 Feb 2015 05:05:26 +0000 Message-ID: <86228AFD5BCD8E4EBFD2B90117B5E81E10D7CCB2@SHSMSX103.ccr.corp.intel.com> References: <1421156540-25810-5-git-send-email-michael.qiu@intel.com> <1422336153-13982-1-git-send-email-michael.qiu@intel.com> In-Reply-To: <1422336153-13982-1-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 v2] framework/ssh: Add verify ability for command execution 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: Sun, 15 Feb 2015 05:05:32 -0000 Applied, thx. > -----Original Message----- > From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of Michael Qiu > Sent: Tuesday, January 27, 2015 1:23 PM > To: dts@dpdk.org > Subject: [dts] [PATCH v2] framework/ssh: Add verify ability for command > execution >=20 > ssh command exection never try to verify the failure or success, >=20 > It should be very dangerous when execute command both in dut and > tester machine without check the status, maybe unexpected error > happens. >=20 > This patch add this ability to verify the status. >=20 > Signed-off-by: Michael Qiu > --- > v2 --> v1 > add error log when return error code for that > can be track in log. >=20 > framework/ssh_connection.py | 4 ++-- > framework/ssh_pexpect.py | 14 +++++++++++++- > 2 files changed, 15 insertions(+), 3 deletions(-) >=20 > diff --git a/framework/ssh_connection.py b/framework/ssh_connection.py > index 4306162..d0b5e07 100644 > --- a/framework/ssh_connection.py > +++ b/framework/ssh_connection.py > @@ -49,9 +49,9 @@ class SSHConnection(object): > self.logger.config_execution(self.name) > self.session.init_log(logger, self.name) >=20 > - def send_expect(self, cmds, expected, timeout=3D15): > + def send_expect(self, cmds, expected, timeout=3D15, verify=3DFalse): > self.logger.info(cmds) > - out =3D self.session.send_expect(cmds, expected, timeout) > + out =3D self.session.send_expect(cmds, expected, timeout, > verify=3DFalse) > self.logger.debug(out) > return out >=20 > diff --git a/framework/ssh_pexpect.py b/framework/ssh_pexpect.py > index 9c353e7..b7d3475 100644 > --- a/framework/ssh_pexpect.py > +++ b/framework/ssh_pexpect.py > @@ -29,12 +29,24 @@ class SSHPexpect(object): > self.logger.config_execution(name) > self.logger.info("ssh %s@%s" % (self.username, self.host)) >=20 > - def send_expect(self, command, expected, timeout=3D15): > + def send_expect_base(self, command, expected, timeout=3D15): > self.session.PROMPT =3D expected > self.__sendline(command) > self.__prompt(command, timeout) > return self.get_output_before() >=20 > + def send_expect(self, command, expected, timeout=3D15, verify=3DFals= e): > + ret =3D self.send_expect_base(command, expected, timeout) > + if verify: > + ret_status =3D self.send_expect_base("echo $?", expected) > + if not int(ret_status): > + return ret > + else: > + self.logger.error("Command: %s failure!" % command) > + return -1 > + else: > + return ret > + > def __prompt(self, command, timeout): > if not self.session.prompt(timeout): > raise TimeoutException(command, self.get_output_all()) > -- > 1.9.3