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 8D32BA04FD; Fri, 29 Jul 2022 12:56:42 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 98DEA42C30; Fri, 29 Jul 2022 12:56:11 +0200 (CEST) Received: from lb.pantheon.sk (lb.pantheon.sk [46.229.239.20]) by mails.dpdk.org (Postfix) with ESMTP id A532142C15 for ; Fri, 29 Jul 2022 12:56:02 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by lb.pantheon.sk (Postfix) with ESMTP id F3B5A1C1C73; Fri, 29 Jul 2022 12:56:01 +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 zULRDdVf3ZBi; Fri, 29 Jul 2022 12:56:01 +0200 (CEST) Received: from entguard.lab.pantheon.local (unknown [46.229.239.141]) by lb.pantheon.sk (Postfix) with ESMTP id 3585613125C; Fri, 29 Jul 2022 12:55:55 +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: [PATCH v4 7/9] dts: add Node base class Date: Fri, 29 Jul 2022 10:55:48 +0000 Message-Id: <20220729105550.1382664-8-juraj.linkes@pantheon.tech> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220729105550.1382664-1-juraj.linkes@pantheon.tech> References: <20220728100044.1318484-1-juraj.linkes@pantheon.tech> <20220729105550.1382664-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 base class implements basic node management methods - connect and execute commands. Signed-off-by: Owen Hilyard Signed-off-by: Juraj Linkeš --- dts/framework/node.py | 99 +++++++++++++++++++++++++++++++++++++++ dts/framework/settings.py | 11 +++++ 2 files changed, 110 insertions(+) create mode 100644 dts/framework/node.py diff --git a/dts/framework/node.py b/dts/framework/node.py new file mode 100644 index 0000000000..e5c5454ebe --- /dev/null +++ b/dts/framework/node.py @@ -0,0 +1,99 @@ +# 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 +# + +from typing import Optional + +from .config import NodeConfiguration +from .logger import DTSLOG, getLogger +from .settings import SETTINGS +from .ssh_connection import SSHConnection + +""" +A node is a generic host that DTS connects to and manages. +""" + + +class Node(object): + """ + Basic module for node management. This module implements methods that + manage a node, such as information gathering (of CPU/PCI/NIC) and + environment setup. + """ + + _config: NodeConfiguration + logger: DTSLOG + main_session: SSHConnection + name: str + _other_sessions: list[SSHConnection] + + def __init__(self, node_config: NodeConfiguration): + self._config = node_config + self.name = node_config.name + + self.logger = getLogger(self.name) + self.logger.info(f"Created node: {self.name}") + self.main_session = SSHConnection( + self.get_ip_address(), + self.name, + self.logger, + self.get_username(), + self.get_password(), + ) + + def get_ip_address(self) -> str: + """ + Get SUT's ip address. + """ + return self._config.hostname + + def get_password(self) -> Optional[str]: + """ + Get SUT's login password. + """ + return self._config.password + + def get_username(self) -> str: + """ + Get SUT's login username. + """ + return self._config.user + + def send_expect( + self, + command: str, + expected: str, + timeout: float = SETTINGS.timeout, + verify: bool = False, + trim_whitespace: bool = True, + ) -> str | int: + """ + Send commands to node and return string before expected string. If + there's no expected string found before timeout, TimeoutException will + be raised. + + By default, it will trim the whitespace from the expected string. This + behavior can be turned off via the trim_whitespace argument. + """ + + if trim_whitespace: + expected = expected.strip() + + return self.main_session.send_expect(command, expected, timeout, verify) + + def send_command(self, cmds: str, timeout: float = SETTINGS.timeout) -> str: + """ + Send commands to node and return string before timeout. + """ + + return self.main_session.send_command(cmds, timeout) + + def node_exit(self) -> None: + """ + Recover all resource before node exit + """ + if self.main_session: + self.main_session.close() + self.logger.logger_exit() diff --git a/dts/framework/settings.py b/dts/framework/settings.py index 4793d550ac..07952b9f9e 100644 --- a/dts/framework/settings.py +++ b/dts/framework/settings.py @@ -40,6 +40,7 @@ def wrapper(**kwargs) -> _EnvironmentArgument: @dataclass(slots=True, frozen=True) class _Settings: config_file_path: str + timeout: float def _get_parser() -> argparse.ArgumentParser: @@ -52,6 +53,15 @@ def _get_parser() -> argparse.ArgumentParser: help="[DTS_CFG_FILE] configuration file that describes the test cases, SUTs and targets", ) + parser.add_argument( + "-t", + "--timeout", + action=_env_arg("DTS_TIMEOUT"), + default=15, + required=False, + help="[DTS_TIMEOUT] The default timeout for all DTS operations except for compiling DPDK.", + ) + return parser @@ -59,6 +69,7 @@ def _get_settings() -> _Settings: args = _get_parser().parse_args() return _Settings( config_file_path=args.config_file, + timeout=float(args.timeout), ) -- 2.30.2