1# SPDX-License-Identifier: BSD-3-Clause 2# Copyright(c) 2010-2014 Intel Corporation 3# Copyright(c) 2022 PANTHEON.tech s.r.o. 4# Copyright(c) 2022 University of New Hampshire 5 6""" 7A node is a generic host that DTS connects to and manages. 8""" 9 10from framework.config import NodeConfiguration 11from framework.logger import DTSLOG, getLogger 12from framework.remote_session import RemoteSession, create_remote_session 13from framework.settings import SETTINGS 14 15 16class Node(object): 17 """ 18 Basic module for node management. This module implements methods that 19 manage a node, such as information gathering (of CPU/PCI/NIC) and 20 environment setup. 21 """ 22 23 name: str 24 main_session: RemoteSession 25 logger: DTSLOG 26 _config: NodeConfiguration 27 _other_sessions: list[RemoteSession] 28 29 def __init__(self, node_config: NodeConfiguration): 30 self._config = node_config 31 self._other_sessions = [] 32 33 self.name = node_config.name 34 self.logger = getLogger(self.name) 35 self.logger.info(f"Created node: {self.name}") 36 self.main_session = create_remote_session(self._config, self.name, self.logger) 37 38 def send_command(self, cmds: str, timeout: float = SETTINGS.timeout) -> str: 39 """ 40 Send commands to node and return string before timeout. 41 """ 42 43 return self.main_session.send_command(cmds, timeout) 44 45 def create_session(self, name: str) -> RemoteSession: 46 connection = create_remote_session( 47 self._config, 48 name, 49 getLogger(name, node=self.name), 50 ) 51 self._other_sessions.append(connection) 52 return connection 53 54 def node_exit(self) -> None: 55 """ 56 Recover all resource before node exit 57 """ 58 if self.main_session: 59 self.main_session.close() 60 for session in self._other_sessions: 61 session.close() 62 self.logger.logger_exit() 63