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 07153A0032; Mon, 11 Jul 2022 16:51:58 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 84AF942B70; Mon, 11 Jul 2022 16:51:37 +0200 (CEST) Received: from lb.pantheon.sk (lb.pantheon.sk [46.229.239.20]) by mails.dpdk.org (Postfix) with ESMTP id 54FC342836 for ; Mon, 11 Jul 2022 16:51:35 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by lb.pantheon.sk (Postfix) with ESMTP id 8F35F243CD1; Mon, 11 Jul 2022 16:51:34 +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 NsbEenskm3fU; Mon, 11 Jul 2022 16:51:33 +0200 (CEST) Received: from entguard.lab.pantheon.local (unknown [46.229.239.141]) by lb.pantheon.sk (Postfix) with ESMTP id 9F769243CE2; Mon, 11 Jul 2022 16:51:29 +0200 (CEST) From: =?UTF-8?q?Juraj=20Linke=C5=A1?= To: thomas@monjalon.net, david.marchand@redhat.com, jerinjacobk@gmail.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: [PATCH v2 4/8] dts: add ssh connection extension Date: Mon, 11 Jul 2022 14:51:22 +0000 Message-Id: <20220711145126.295427-5-juraj.linkes@pantheon.tech> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711145126.295427-1-juraj.linkes@pantheon.tech> References: <20220622121448.3304251-1-juraj.linkes@pantheon.tech> <20220711145126.295427-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 The class adds logging and history records to existing pexpect methods. Signed-off-by: Juraj Linkeš --- dts/framework/ssh_connection.py | 70 +++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 dts/framework/ssh_connection.py diff --git a/dts/framework/ssh_connection.py b/dts/framework/ssh_connection.py new file mode 100644 index 0000000000..0ffde0bc58 --- /dev/null +++ b/dts/framework/ssh_connection.py @@ -0,0 +1,70 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2010-2014 Intel Corporation +# Copyright(c) 2022 PANTHEON.tech s.r.o. +# Copyright(c) 2022 University of New Hampshire +# +import dataclasses +from typing import Any, Optional + +from .logger import DTSLOG +from .ssh_pexpect import SSHPexpect + + +@dataclasses.dataclass(slots=True, frozen=True) +class HistoryRecord: + command: str + name: str + output: str | int + + +class SSHConnection(object): + """ + Module for create session to node. + """ + + name: str + history: list[HistoryRecord] + logger: DTSLOG + session: SSHPexpect | Any + + def __init__( + self, + node: str, + session_name: str, + logger: DTSLOG, + username: str, + password: Optional[str] = "", + sut_id: int = 0, + ): + self.session = SSHPexpect(node, username, password, logger, sut_id=sut_id) + self.name = session_name + self.history = [] + self.logger = logger + + def send_expect( + self, cmds: str, expected: str, timeout: int = 15, verify: bool = False + ) -> str | int: + self.logger.info(cmds) + out = self.session.send_expect(cmds, expected, timeout, verify) + if isinstance(out, str): + self.logger.debug(out.replace(cmds, "")) + self.history.append(HistoryRecord(command=cmds, name=self.name, output=out)) + return out + + def send_command(self, cmds: str, timeout: float = 1) -> str: + self.logger.info(cmds) + out = self.session.send_command(cmds, timeout) + self.logger.debug(out.replace(cmds, "")) + self.history.append(HistoryRecord(command=cmds, name=self.name, output=out)) + return out + + def get_session_before(self, timeout: float = 15) -> str: + out = self.session.get_session_before(timeout) + self.logger.debug(out) + return out + + def close(self, force: bool = False) -> None: + if getattr(self, "logger", None): + self.logger.logger_exit() + + self.session.close(force) -- 2.30.2