Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions connection/base_executor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Copyright(c) 2019-2021 Intel Corporation
# Copyright(c) 2023-2024 Huawei Technologies Co., Ltd.
# Copyright(c) 2026 Unvertical
# SPDX-License-Identifier: BSD-3-Clause
#

Expand All @@ -12,6 +13,11 @@


class BaseExecutor:
@property
def name(self):
"""Identifies the DUT this executor runs commands on"""
return "localhost"

def _execute(self, command, timeout):
raise NotImplementedError()

Expand Down Expand Up @@ -52,8 +58,7 @@ def run(self, command, timeout: timedelta = timedelta(minutes=30)):
if TestRun.dut and TestRun.dut.env:
command = f"{TestRun.dut.env} && {command}"
command_id = TestRun.LOGGER.get_new_command_id()
ip_info = TestRun.dut.ip if len(TestRun.duts) > 1 else ""
TestRun.LOGGER.write_command_to_command_log(command, command_id, info=ip_info)
TestRun.LOGGER.write_command_to_command_log(command, command_id, info=self.name)
output = self._execute(command, timeout)
TestRun.LOGGER.write_output_to_command_log(output, command_id)
return output
Expand All @@ -62,7 +67,10 @@ def run_in_background(self,
command,
stdout_redirect_path="/dev/null",
stderr_redirect_path="/dev/null"):
command += f" > {stdout_redirect_path} 2> {stderr_redirect_path} &echo $!"
# Subshell makes the redirection cover compound commands too, otherwise their
# earlier parts keep the session output open until they finish. A simple command
# is executed by the subshell directly, so the PID is still the command's one.
command = f"({command}) > {stdout_redirect_path} 2> {stderr_redirect_path} &echo $!"
output = self.run(command)

if output is not None:
Expand Down
4 changes: 4 additions & 0 deletions connection/ssh_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def __init__(self, host, username, port=22):
self.ssh_config = None
self._check_config_for_reboot_timeout()

@property
def name(self):
return self.host

def __del__(self):
self.ssh.close()

Expand Down
14 changes: 3 additions & 11 deletions core/test_run_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import traceback

import pytest
from IPy import IP

import core.test_run
from connection.local_executor import LocalExecutor
Expand Down Expand Up @@ -142,15 +141,8 @@ def __setup_disks(cls):
def __presetup(cls):

if cls.config['type'] == 'ssh':
try:
IP(cls.config['ip'])
if not cls.config['host']:
cls.config['host'] = cls.config['ip']
except ValueError:
TestRun.block("IP address from config is in invalid format.")
except KeyError:
if 'host' not in cls.config:
TestRun.block("No IP address or host defined in config")
if not cls.config.get('host'):
TestRun.block("No host defined in config")

port = cls.config.get('port', 22)

Expand Down Expand Up @@ -185,7 +177,7 @@ def __setup(cls):
except Exception as ex:
raise Exception(f"Failed to setup DUT instance:\n"
f"{str(ex)}\n{traceback.format_exc()}")
cls.dut.ip = cls.dut.ip or cls.executor.resolve_ip_address()
cls.dut.ip = cls.executor.resolve_ip_address()
cls.__setup_disks()

TestRun.LOGGER.info(f"Re-seeding random number generator with seed: {cls.random_seed}")
Expand Down
Loading
Loading