From patchwork Wed Jun 22 12:14:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Juraj_Linke=C5=A1?= X-Patchwork-Id: 113248 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9BFEEA04FD; Wed, 22 Jun 2022 14:15:19 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 89F9B4282C; Wed, 22 Jun 2022 14:15:00 +0200 (CEST) Received: from lb.pantheon.sk (lb.pantheon.sk [46.229.239.20]) by mails.dpdk.org (Postfix) with ESMTP id 0D149427F3 for ; Wed, 22 Jun 2022 14:14:58 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by lb.pantheon.sk (Postfix) with ESMTP id 300A83146E; Wed, 22 Jun 2022 14:14:57 +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 CE5djd7xp1Xw; Wed, 22 Jun 2022 14:14:56 +0200 (CEST) Received: from entguard.lab.pantheon.local (unknown [46.229.239.141]) by lb.pantheon.sk (Postfix) with ESMTP id CDADC31466; Wed, 22 Jun 2022 14:14:51 +0200 (CEST) From: =?utf-8?q?Juraj_Linke=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_Linke=C5=A1?= Subject: [PATCH v1 5/8] dts: add Node base class Date: Wed, 22 Jun 2022 12:14:45 +0000 Message-Id: <20220622121448.3304251-6-juraj.linkes@pantheon.tech> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220622121448.3304251-1-juraj.linkes@pantheon.tech> References: <20220622121448.3304251-1-juraj.linkes@pantheon.tech> MIME-Version: 1.0 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: Juraj Linkeš --- dts/framework/node.py | 95 +++++++++++++++++++++++++++++++++++++++ dts/framework/settings.py | 8 ++++ 2 files changed, 103 insertions(+) create mode 100644 dts/framework/node.py create mode 100644 dts/framework/settings.py diff --git a/dts/framework/node.py b/dts/framework/node.py new file mode 100644 index 0000000000..ba9e9574bc --- /dev/null +++ b/dts/framework/node.py @@ -0,0 +1,95 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2010-2014 Intel Corporation +# + +from .logger import getLogger +from .settings import TIMEOUT +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. + """ + + def __init__(self, node, sut_id=0, name=None): + self.node = node + + self.logger = getLogger(name) + self.session = SSHConnection( + self.get_ip_address(), + name, + self.get_username(), + self.get_password(), + sut_id, + ) + self.session.init_log(self.logger) + + def get_ip_address(self): + """ + Get SUT's ip address. + """ + return self.node["IP"] + + def get_password(self): + """ + Get SUT's login password. + """ + return self.node["pass"] + + def get_username(self): + """ + Get SUT's login username. + """ + return self.node["user"] + + def send_expect( + self, + cmds, + expected, + timeout=TIMEOUT, + verify=False, + trim_whitespace=True, + ): + """ + 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.session.send_expect(cmds, expected, timeout, verify) + + def send_command(self, cmds, timeout=TIMEOUT): + """ + Send commands to node and return string before timeout. + """ + + return self.session.send_command(cmds, timeout) + + def close(self): + """ + Close ssh session of SUT. + """ + if self.session: + self.session.close() + self.session = None + + def node_exit(self): + """ + Recover all resource before node exit + """ + self.close() + self.logger.logger_exit() diff --git a/dts/framework/settings.py b/dts/framework/settings.py new file mode 100644 index 0000000000..d62083969e --- /dev/null +++ b/dts/framework/settings.py @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2010-2021 Intel Corporation +# + +""" +Default session timeout. +""" +TIMEOUT = 15