The base class implements basic node management methods - connect and execute commands.
Signed-off-by: Juraj Linkeš <juraj.lin...@pantheon.tech> --- 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 -- 2.20.1