From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8F82BA04F9; Fri, 27 Dec 2019 08:30:08 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 813941BFF4; Fri, 27 Dec 2019 08:30:08 +0100 (CET) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id A99F81BFE9 for ; Fri, 27 Dec 2019 08:30:06 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Dec 2019 23:30:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,362,1571727600"; d="scan'208";a="243166482" Received: from dpdk-lihong-ub1604.sh.intel.com ([10.67.118.203]) by fmsmga004.fm.intel.com with ESMTP; 26 Dec 2019 23:30:05 -0800 From: lihong To: dts@dpdk.org Cc: zhaoyan.chen@intel.com, lihong Date: Fri, 27 Dec 2019 08:03:05 +0800 Message-Id: <1577404987-1369-2-git-send-email-lihongx.ma@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1577404987-1369-1-git-send-email-lihongx.ma@intel.com> References: <1577404987-1369-1-git-send-email-lihongx.ma@intel.com> Subject: [dts] [PATCH V1 2/4] framework/ssh: add params to ssh scp function 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: , Errors-To: dts-bounces@dpdk.org Sender: "dts" add parameter crb_session to copy_file_from/to, when the parameter is not None, will copy file from/to the crb session, otherwise will copy file from/to current dts env. Signed-off-by: lihong --- framework/ssh_connection.py | 8 ++++---- framework/ssh_pexpect.py | 27 +++++++++++++++++---------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/framework/ssh_connection.py b/framework/ssh_connection.py index 312139e..afeef1c 100644 --- a/framework/ssh_connection.py +++ b/framework/ssh_connection.py @@ -108,8 +108,8 @@ class SSHConnection(object): return True - def copy_file_from(self, src, dst=".", password=''): - self.session.copy_file_from(src, dst, password) + def copy_file_from(self, src, dst=".", password='', crb_session=None): + self.session.copy_file_from(src, dst, password, crb_session) - def copy_file_to(self, src, dst="~/", password=''): - self.session.copy_file_to(src, dst, password) + def copy_file_to(self, src, dst="~/", password='', crb_session=None): + self.session.copy_file_to(src, dst, password, crb_session) diff --git a/framework/ssh_pexpect.py b/framework/ssh_pexpect.py index df8da8a..979327c 100644 --- a/framework/ssh_pexpect.py +++ b/framework/ssh_pexpect.py @@ -163,7 +163,7 @@ class SSHPexpect(object): def isalive(self): return self.session.isalive() - def copy_file_from(self, src, dst=".", password=''): + def copy_file_from(self, src, dst=".", password='', crb_session=None): """ Copies a file from a remote place into local. """ @@ -172,11 +172,11 @@ class SSHPexpect(object): command = 'scp -v -P {0} -o NoHostAuthenticationForLocalhost=yes {1}@{2}:{3} {4}'.format( str(self.port), self.username, self.ip, src, dst) if password == '': - self._spawn_scp(command, self.password) + self._spawn_scp(command, self.password, crb_session) else: - self._spawn_scp(command, password) + self._spawn_scp(command, password, crb_session) - def copy_file_to(self, src, dst="~/", password=''): + def copy_file_to(self, src, dst="~/", password='', crb_session=None): """ Sends a local file to a remote place. """ @@ -188,16 +188,23 @@ class SSHPexpect(object): command = 'scp -v {0} {1}@{2}:{3}'.format( src, self.username, self.host, dst) if password == '': - self._spawn_scp(command, self.password) + self._spawn_scp(command, self.password, crb_session) else: - self._spawn_scp(command, password) + self._spawn_scp(command, password, crb_session) - def _spawn_scp(self, scp_cmd, password): + def _spawn_scp(self, scp_cmd, password, crb_session): """ Transfer a file with SCP """ self.logger.info(scp_cmd) - p = pexpect.spawn(scp_cmd) + # if crb_session is not None, copy file from/to crb env + # if crb_session is None, copy file from/to current dts env + if crb_session is not None: + crb_session.session.clean_session() + crb_session.session.__sendline(scp_cmd) + p = crb_session.session.session + else: + p = pexpect.spawn(scp_cmd) time.sleep(0.5) ssh_newkey = 'Are you sure you want to continue connecting' i = p.expect([ssh_newkey, '[pP]assword', "# ", pexpect.EOF, @@ -212,5 +219,5 @@ class SSHPexpect(object): p.expect("Exit status 0", 60) if i == 4: self.logger.error("SCP TIMEOUT error %d" % i) - - p.close() + if crb_session is None: + p.close() -- 2.7.4