diff options
| author | Juraj Linkeš <[email protected]> | 2023-03-03 11:24:58 +0100 |
|---|---|---|
| committer | Thomas Monjalon <[email protected]> | 2023-03-19 16:28:32 +0100 |
| commit | 785345060df0b7d8a25882b5672fb9ddc4c7a623 (patch) | |
| tree | b3139b535ba252b038e377b16a1d87e021406ed0 /dts/framework/testbed_model/node.py | |
| parent | b28c6196b132d1f25cb8c1bf781520fc41556b3a (diff) | |
dts: add node and OS abstractions
The abstraction model in DTS is as follows:
Node, defining and implementing methods common to and the base of SUT
(system under test) Node and TG (traffic generator) Node.
Remote Session, defining and implementing methods common to any remote
session implementation, such as SSH Session.
OSSession, defining and implementing methods common to any operating
system/distribution, such as Linux.
OSSession uses a derived Remote Session and Node in turn uses a derived
OSSession. This split delegates OS-specific and connection-specific code
to specialized classes designed to handle the differences.
The base classes implement the methods or parts of methods that are
common to all implementations and defines abstract methods that must be
implemented by derived classes.
Part of the abstractions is the DTS test execution skeleton:
execution setup, build setup and then test execution.
Signed-off-by: Juraj Linkeš <[email protected]>
Tested-by: Bruce Richardson <[email protected]>
Tested-by: Chenyu Huang <[email protected]>
Tested-by: Patrick Robb <[email protected]>
Diffstat (limited to 'dts/framework/testbed_model/node.py')
| -rw-r--r-- | dts/framework/testbed_model/node.py | 109 |
1 files changed, 83 insertions, 26 deletions
diff --git a/dts/framework/testbed_model/node.py b/dts/framework/testbed_model/node.py index 8437975416..e1f06bc389 100644 --- a/dts/framework/testbed_model/node.py +++ b/dts/framework/testbed_model/node.py @@ -1,62 +1,119 @@ # 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 +# Copyright(c) 2022-2023 PANTHEON.tech s.r.o. +# Copyright(c) 2022-2023 University of New Hampshire """ A node is a generic host that DTS connects to and manages. """ -from framework.config import NodeConfiguration +from framework.config import ( + BuildTargetConfiguration, + ExecutionConfiguration, + NodeConfiguration, +) from framework.logger import DTSLOG, getLogger -from framework.remote_session import RemoteSession, create_remote_session -from framework.settings import SETTINGS +from framework.remote_session import OSSession, create_session class Node(object): """ - Basic module for node management. This module implements methods that + Basic class for node management. This class implements methods that manage a node, such as information gathering (of CPU/PCI/NIC) and environment setup. """ + main_session: OSSession + config: NodeConfiguration name: str - main_session: RemoteSession - logger: DTSLOG - _config: NodeConfiguration - _other_sessions: list[RemoteSession] + _logger: DTSLOG + _other_sessions: list[OSSession] def __init__(self, node_config: NodeConfiguration): - self._config = node_config + self.config = node_config + self.name = node_config.name + self._logger = getLogger(self.name) + self.main_session = create_session(self.config, self.name, self._logger) + self._other_sessions = [] - 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._logger.info(f"Created node: {self.name}") - def send_command(self, cmds: str, timeout: float = SETTINGS.timeout) -> str: + def set_up_execution(self, execution_config: ExecutionConfiguration) -> None: """ - Send commands to node and return string before timeout. + Perform the execution setup that will be done for each execution + this node is part of. """ + self._set_up_execution(execution_config) - return self.main_session.send_command(cmds, timeout) + def _set_up_execution(self, execution_config: ExecutionConfiguration) -> None: + """ + This method exists to be optionally overwritten by derived classes and + is not decorated so that the derived class doesn't have to use the decorator. + """ - def create_session(self, name: str) -> RemoteSession: - connection = create_remote_session( - self._config, - name, - getLogger(name, node=self.name), + def tear_down_execution(self) -> None: + """ + Perform the execution teardown that will be done after each execution + this node is part of concludes. + """ + self._tear_down_execution() + + def _tear_down_execution(self) -> None: + """ + This method exists to be optionally overwritten by derived classes and + is not decorated so that the derived class doesn't have to use the decorator. + """ + + def set_up_build_target( + self, build_target_config: BuildTargetConfiguration + ) -> None: + """ + Perform the build target setup that will be done for each build target + tested on this node. + """ + self._set_up_build_target(build_target_config) + + def _set_up_build_target( + self, build_target_config: BuildTargetConfiguration + ) -> None: + """ + This method exists to be optionally overwritten by derived classes and + is not decorated so that the derived class doesn't have to use the decorator. + """ + + def tear_down_build_target(self) -> None: + """ + Perform the build target teardown that will be done after each build target + tested on this node. + """ + self._tear_down_build_target() + + def _tear_down_build_target(self) -> None: + """ + This method exists to be optionally overwritten by derived classes and + is not decorated so that the derived class doesn't have to use the decorator. + """ + + def create_session(self, name: str) -> OSSession: + """ + Create and return a new OSSession tailored to the remote OS. + """ + session_name = f"{self.name} {name}" + connection = create_session( + self.config, + session_name, + getLogger(session_name, node=self.name), ) self._other_sessions.append(connection) return connection - def node_exit(self) -> None: + def close(self) -> None: """ - Recover all resource before node exit + Close all connections and free other resources. """ if self.main_session: self.main_session.close() for session in self._other_sessions: session.close() - self.logger.logger_exit() + self._logger.logger_exit() |
