From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 3F5E35B19 for ; Tue, 27 Jan 2015 06:22:41 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 26 Jan 2015 21:22:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,472,1418112000"; d="scan'208";a="668082368" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by fmsmga002.fm.intel.com with ESMTP; 26 Jan 2015 21:22:38 -0800 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id t0R5Mboq022812; Tue, 27 Jan 2015 13:22:37 +0800 Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1]) by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id t0R5MYsM014017; Tue, 27 Jan 2015 13:22:36 +0800 Received: (from dayuqiu@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id t0R5MYxd014013; Tue, 27 Jan 2015 13:22:34 +0800 From: Michael Qiu To: dts@dpdk.org Date: Tue, 27 Jan 2015 13:22:33 +0800 Message-Id: <1422336153-13982-1-git-send-email-michael.qiu@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1421156540-25810-5-git-send-email-michael.qiu@intel.com> References: <1421156540-25810-5-git-send-email-michael.qiu@intel.com> Subject: [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: Tue, 27 Jan 2015 05:22:41 -0000 ssh command exection never try to verify the failure or success, It should be very dangerous when execute command both in dut and tester machine without check the status, maybe unexpected error happens. This patch add this ability to verify the status. Signed-off-by: Michael Qiu --- v2 --> v1 add error log when return error code for that can be track in log. framework/ssh_connection.py | 4 ++-- framework/ssh_pexpect.py | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) 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) - def send_expect(self, cmds, expected, timeout=15): + def send_expect(self, cmds, expected, timeout=15, verify=False): self.logger.info(cmds) - out = self.session.send_expect(cmds, expected, timeout) + out = self.session.send_expect(cmds, expected, timeout, verify=False) self.logger.debug(out) return out 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)) - def send_expect(self, command, expected, timeout=15): + def send_expect_base(self, command, expected, timeout=15): self.session.PROMPT = expected self.__sendline(command) self.__prompt(command, timeout) return self.get_output_before() + def send_expect(self, command, expected, timeout=15, verify=False): + ret = self.send_expect_base(command, expected, timeout) + if verify: + ret_status = 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