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 0492AA00C2; Mon, 26 Sep 2022 16:18:10 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4593D42B86; Mon, 26 Sep 2022 16:17:30 +0200 (CEST) Received: from lb.pantheon.sk (lb.pantheon.sk [46.229.239.20]) by mails.dpdk.org (Postfix) with ESMTP id 943FB42B6C for ; Mon, 26 Sep 2022 16:17:25 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by lb.pantheon.sk (Postfix) with ESMTP id CC123243CF7; Mon, 26 Sep 2022 16:17:24 +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 3NlDkm4On9Jv; Mon, 26 Sep 2022 16:17:23 +0200 (CEST) Received: from entguard.lab.pantheon.local (unknown [46.229.239.141]) by lb.pantheon.sk (Postfix) with ESMTP id 65D671FF592; Mon, 26 Sep 2022 16:17:18 +0200 (CEST) From: =?UTF-8?q?Juraj=20Linke=C5=A1?= To: thomas@monjalon.net, david.marchand@redhat.com, Honnappa.Nagarahalli@arm.com, ohilyard@iol.unh.edu, lijuan.tu@intel.com, kda@semihalf.com, bruce.richardson@intel.com Cc: dev@dpdk.org, =?UTF-8?q?Juraj=20Linke=C5=A1?= Subject: [PATCH v5 07/10] dts: add node base class Date: Mon, 26 Sep 2022 14:17:10 +0000 Message-Id: <20220926141713.2415010-8-juraj.linkes@pantheon.tech> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220926141713.2415010-1-juraj.linkes@pantheon.tech> References: <20220926141713.2415010-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/testbed_model/__init__.py | 8 +++ dts/framework/testbed_model/node.py | 83 +++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 dts/framework/testbed_model/__init__.py create mode 100644 dts/framework/testbed_model/node.py diff --git a/dts/framework/testbed_model/__init__.py b/dts/framework/testbed_model/__init__.py new file mode 100644 index 0000000000..63b13511a8 --- /dev/null +++ b/dts/framework/testbed_model/__init__.py @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2022 University of New Hampshire +# + +""" +This module contains the classes used to model the physical traffic generator, +sut and any other components that need to be interacted with. +""" diff --git a/dts/framework/testbed_model/node.py b/dts/framework/testbed_model/node.py new file mode 100644 index 0000000000..7bc298d9eb --- /dev/null +++ b/dts/framework/testbed_model/node.py @@ -0,0 +1,83 @@ +# 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 framework.config import NodeConfiguration +from framework.logger import DTSLOG, getLogger +from framework.remote_session import RemoteSession, create_remote_session +from framework.settings import SETTINGS + +""" +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. + """ + + main_session: RemoteSession + name: str + logger: DTSLOG + _config: NodeConfiguration + _other_sessions: list[RemoteSession] + + 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 = create_remote_session(self._config, self.name, self.logger) + self._other_sessions = [] + + 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_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 create_session(self, name: str) -> RemoteSession: + connection = create_remote_session( + self._config, + name, + getLogger(name, node=self.name), + ) + self._other_sessions.append(connection) + return connection + + def node_exit(self) -> None: + """ + Recover all resource before node exit + """ + if self.main_session: + self.main_session.close() + for session in self._other_sessions: + session.close() + self.logger.logger_exit() -- 2.30.2