From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 63DE6A0543; Wed, 24 Aug 2022 18:25:17 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A9C184281C; Wed, 24 Aug 2022 18:25:04 +0200 (CEST) Received: from lb.pantheon.sk (lb.pantheon.sk [46.229.239.20]) by mails.dpdk.org (Postfix) with ESMTP id A98474280C for ; Wed, 24 Aug 2022 18:25:01 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by lb.pantheon.sk (Postfix) with ESMTP id 30500CD273; Wed, 24 Aug 2022 18:25:00 +0200 (CEST) X-Virus-Scanned: amavisd-new at siecit.sk Received: from lb.pantheon.sk ([127.0.0.1]) by localhost (lb.pantheon.sk [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rM5oXeHUylfV; Wed, 24 Aug 2022 18:24:59 +0200 (CEST) Received: from entguard.lab.pantheon.local (unknown [46.229.239.141]) by lb.pantheon.sk (Postfix) with ESMTP id 28774CD26F; Wed, 24 Aug 2022 18:24:56 +0200 (CEST) From: =?UTF-8?q?Juraj=20Linke=C5=A1?= To: thomas@monjalon.net, david.marchand@redhat.com, ronan.randles@intel.com, Honnappa.Nagarahalli@arm.com, ohilyard@iol.unh.edu, lijuan.tu@intel.com Cc: dev@dpdk.org, =?UTF-8?q?Juraj=20Linke=C5=A1?= Subject: [RFC PATCH v1 03/10] dts: ssh connection additions for hello world Date: Wed, 24 Aug 2022 16:24:47 +0000 Message-Id: <20220824162454.394285-4-juraj.linkes@pantheon.tech> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220824162454.394285-1-juraj.linkes@pantheon.tech> References: <20220824162454.394285-1-juraj.linkes@pantheon.tech> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org SCP is needed to transfer DPDK tarballs between nodes. Also add keepalive method that testcases use. Signed-off-by: Juraj Linkeš --- dts/framework/ssh_connection.py | 19 ++++++++++ dts/framework/ssh_pexpect.py | 61 +++++++++++++++++++++++++++++++-- 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/dts/framework/ssh_connection.py b/dts/framework/ssh_connection.py index bbf7c8ef01..ec7333e565 100644 --- a/dts/framework/ssh_connection.py +++ b/dts/framework/ssh_connection.py @@ -8,6 +8,7 @@ from typing import Any, Optional from .logger import DTSLOG +from .settings import SETTINGS from .ssh_pexpect import SSHPexpect @@ -68,3 +69,21 @@ def close(self, force: bool = False) -> None: self.logger.logger_exit() self.session.close(force) + + def check_available(self) -> bool: + MAGIC_STR = "DTS_CHECK_SESSION" + out = self.session.send_command("echo %s" % MAGIC_STR, timeout=0.1) + # if not available, try to send ^C and check again + if MAGIC_STR not in out: + self.logger.info("Try to recover session...") + self.session.send_command("^C", timeout=SETTINGS.timeout) + out = self.session.send_command("echo %s" % MAGIC_STR, timeout=0.1) + if MAGIC_STR not in out: + return False + + return True + + def copy_file_to( + self, src: str, dst: str = "~/", password: str = "", node_session: Any = None + ) -> None: + self.session.copy_file_to(src, dst, password, node_session) diff --git a/dts/framework/ssh_pexpect.py b/dts/framework/ssh_pexpect.py index e8f64515c0..b8eb10025e 100644 --- a/dts/framework/ssh_pexpect.py +++ b/dts/framework/ssh_pexpect.py @@ -5,11 +5,16 @@ # import time -from typing import Optional +from typing import Any, Optional +import pexpect from pexpect import pxssh -from .exception import SSHConnectionException, SSHSessionDeadException, TimeoutException +from .exception import ( + SSHConnectionException, + SSHSessionDeadException, + TimeoutException, +) from .logger import DTSLOG from .utils import GREEN, RED @@ -203,3 +208,55 @@ def close(self, force: bool = False) -> None: def isalive(self) -> bool: return self.session.isalive() + + def copy_file_to( + self, src: str, dst: str = "~/", password: str = "", node_session: Any = None + ) -> None: + """ + Sends a local file to a remote place. + """ + command: str + if ":" in self.node: + command = "scp -v -P {0} -o NoHostAuthenticationForLocalhost=yes {1} {2}@{3}:{4}".format( + str(self.port), src, self.username, self.ip, dst + ) + else: + command = "scp -v {0} {1}@{2}:{3}".format( + src, self.username, self.node, dst + ) + if password == "": + self._spawn_scp(command, self.password, node_session) + else: + self._spawn_scp(command, password, node_session) + + def _spawn_scp(self, scp_cmd: str, password: str, node_session: Any) -> None: + """ + Transfer a file with SCP + """ + self.logger.info(scp_cmd) + # if node_session is not None, copy file from/to node env + # if node_session is None, copy file from/to current dts env + p: pexpect.spawn + if node_session is not None: + node_session.session.clean_session() + node_session.session.__sendline(scp_cmd) + p = node_session.session.session + else: + p = pexpect.spawn(scp_cmd) + time.sleep(0.5) + ssh_newkey: str = "Are you sure you want to continue connecting" + i: int = p.expect( + [ssh_newkey, "[pP]assword", "# ", pexpect.EOF, pexpect.TIMEOUT], 120 + ) + if i == 0: # add once in trust list + p.sendline("yes") + i = p.expect([ssh_newkey, "[pP]assword", pexpect.EOF], 2) + + if i == 1: + time.sleep(0.5) + p.sendline(password) + p.expect("Exit status 0", 60) + if i == 4: + self.logger.error("SCP TIMEOUT error %d" % i) + if node_session is None: + p.close() -- 2.30.2