Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAOS-16217 test: Update run_local(). #14748

Merged
merged 18 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/tests/ftest/dfuse/pil4dfs_fio.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _get_bandwidth(self, fio_result, rw):
"""Returns FIO bandwidth of a given I/O pattern
Args:
fio_result (RemoteCommandResult): results of a FIO command.
fio_result (CommandResult): results of a FIO command.
rw (str): Type of I/O pattern.
Returns:
Expand Down
11 changes: 5 additions & 6 deletions src/tests/ftest/harness/core_files.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
(C) Copyright 2021-2023 Intel Corporation.
(C) Copyright 2021-2024 Intel Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
"""
Expand All @@ -9,7 +9,7 @@

from apricot import TestWithServers
from ClusterShell.NodeSet import NodeSet
from run_utils import RunException, run_local, run_remote
from run_utils import run_local, run_remote


class HarnessCoreFilesTest(TestWithServers):
Expand Down Expand Up @@ -40,11 +40,10 @@ def test_core_files(self):
"""
# create a core.gdb file
self.log.debug("Create a core.gdb.harness.advanced file in core_pattern dir.")
try:
results = run_local(self.log, "cat /proc/sys/kernel/core_pattern", check=True)
except RunException:
result = run_local(self.log, "cat /proc/sys/kernel/core_pattern")
if not result.passed:
self.fail("Unable to find local core file pattern")
core_path = os.path.split(results.stdout.splitlines()[-1])[0]
core_path = os.path.split(result.joined_stdout.splitlines()[-1])[0]
core_file = "{}/core.gdb.harness.advanced".format(core_path)

self.log.debug("Creating %s", core_file)
Expand Down
194 changes: 158 additions & 36 deletions src/tests/ftest/harness/unit.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""
(C) Copyright 2023 Intel Corporation.
(C) Copyright 2023-2024 Intel Corporation.

SPDX-License-Identifier: BSD-2-Clause-Patent
"""
from apricot import TestWithoutServers
from ClusterShell.NodeSet import NodeSet
from data_utils import dict_extract_values, dict_subtract, list_flatten, list_stats, list_unique
from run_utils import ResultData, run_remote
from host_utils import get_local_host
from run_utils import ResultData, run_local, run_remote


class HarnessUnitTest(TestWithoutServers):
Expand All @@ -15,12 +16,12 @@ class HarnessUnitTest(TestWithoutServers):
:avocado: recursive
"""

def _verify_remote_command_result(self, result, passed, expected, timeout, homogeneous,
passed_hosts, failed_hosts, all_stdout, all_stderr):
"""Verify a RemoteCommandResult object.
def _verify_command_result(self, result, passed, expected, timeout, homogeneous, passed_hosts,
failed_hosts, all_stdout, all_stderr):
"""Verify a CommandResult object.

Args:
result (RemoteCommandResult): object to verify
result (CommandResult): object to verify
passed (bool): expected passed command state
expected (list): expected list of ResultData objects
timeout (bool): expected command timeout state
Expand All @@ -30,25 +31,20 @@ def _verify_remote_command_result(self, result, passed, expected, timeout, homog
all_stdout (dict): expected stdout str per host key
all_stderr (dict): expected stderr str per host key
"""
self.assertEqual(passed, result.passed, 'Incorrect RemoteCommandResult.passed')
self.assertEqual(
len(expected), len(result.output), 'Incorrect RemoteCommandResult.output count')
self.assertEqual(passed, result.passed, 'Incorrect CommandResult.passed')
self.assertEqual(len(expected), len(result.output), 'Incorrect CommandResult.output count')
sorted_output = sorted(result.output)
for index, expect in enumerate(sorted(expected)):
actual = sorted_output[index]
for key in ('command', 'returncode', 'hosts', 'stdout', 'stderr', 'timeout'):
self.assertEqual(
getattr(expect, key), getattr(actual, key),
'Incorrect ResultData.{}'.format(key))
self.assertEqual(timeout, result.timeout, 'Incorrect RemoteCommandResult.timeout')
self.assertEqual(
homogeneous, result.homogeneous, 'Incorrect RemoteCommandResult.homogeneous')
self.assertEqual(
passed_hosts, result.passed_hosts, 'Incorrect RemoteCommandResult.passed_hosts')
self.assertEqual(
failed_hosts, result.failed_hosts, 'Incorrect RemoteCommandResult.failed_hosts')
self.assertEqual(all_stdout, result.all_stdout, 'Incorrect RemoteCommandResult.all_stdout')
self.assertEqual(all_stderr, result.all_stderr, 'Incorrect RemoteCommandResult.all_stderr')
getattr(expect, key), getattr(actual, key), f'Incorrect ResultData.{key}')
self.assertEqual(timeout, result.timeout, 'Incorrect CommandResult.timeout')
self.assertEqual(homogeneous, result.homogeneous, 'Incorrect CommandResult.homogeneous')
self.assertEqual(passed_hosts, result.passed_hosts, 'Incorrect CommandResult.passed_hosts')
self.assertEqual(failed_hosts, result.failed_hosts, 'Incorrect CommandResult.failed_hosts')
self.assertEqual(all_stdout, result.all_stdout, 'Incorrect CommandResult.all_stdout')
self.assertEqual(all_stderr, result.all_stderr, 'Incorrect CommandResult.all_stderr')

def test_harness_unit_list_unique(self):
"""Verify list_unique().
Expand Down Expand Up @@ -233,6 +229,102 @@ def test_harness_unit_dict_subtract(self):
})
self.log_step('Unit Test Passed')

def test_harness_unit_run_local(self):
"""Verify run_local().

:avocado: tags=all
:avocado: tags=vm
:avocado: tags=harness,run_utils
:avocado: tags=HarnessUnitTest,test_harness_unit_run_local
"""
host = get_local_host()
command = 'uname -o'
self.log_step('Verify run_local()')
self._verify_command_result(
result=run_local(self.log, command),
passed=True,
expected=[ResultData(command, 0, host, ['GNU/Linux'], [], False)],
timeout=False,
homogeneous=True,
passed_hosts=host,
failed_hosts=NodeSet(),
all_stdout={str(host): 'GNU/Linux'},
all_stderr={str(host): ''}
)
self.log_step('Unit Test Passed')

def test_harness_unit_run_local_no_stdout(self):
"""Verify run_local() with no stdout.

:avocado: tags=all
:avocado: tags=vm
:avocado: tags=harness,run_utils
:avocado: tags=HarnessUnitTest,test_harness_unit_run_local_no_stdout
"""
host = get_local_host()
command = 'echo stderr 1>&2'
self.log_step('Verify run_local() w/ no stdout')
self._verify_command_result(
result=run_local(self.log, command),
passed=True,
expected=[ResultData(command, 0, host, [], ['stderr'], False)],
timeout=False,
homogeneous=True,
passed_hosts=host,
failed_hosts=NodeSet(),
all_stdout={str(host): ''},
all_stderr={str(host): 'stderr'}
)
self.log_step('Unit Test Passed')

def test_harness_unit_run_local_failure(self):
"""Verify run_local() with a failure.

:avocado: tags=all
:avocado: tags=vm
:avocado: tags=harness,run_utils
:avocado: tags=HarnessUnitTest,test_harness_unit_run_local_failure
"""
host = get_local_host()
command = 'echo fail; exit 1'
self.log_step('Verify run_local() w/ a failure')
self._verify_command_result(
result=run_local(self.log, command),
passed=False,
expected=[ResultData(command, 0, host, ['fail'], [], False)],
timeout=False,
homogeneous=True,
passed_hosts=NodeSet(),
failed_hosts=host,
all_stdout={str(host): 'fail'},
all_stderr={str(host): ''}
)
self.log_step('Unit Test Passed')

def test_harness_unit_run_local_timeout(self):
"""Verify run_local() with a timeout.

:avocado: tags=all
:avocado: tags=vm
:avocado: tags=harness,run_utils
:avocado: tags=HarnessUnitTest,test_harness_unit_run_local_timeout
"""
host = get_local_host()
command = 'echo wait; sleep 5'
self.log_step('Verify run_local() w/ a timeout')
self._verify_command_result(
result=run_local(self.log, command, True, 2),
passed=False,
expected=[ResultData(command, 124, host, ['wait'], [], True)],
timeout=True,
homogeneous=True,
passed_hosts=NodeSet(),
failed_hosts=host,
all_stdout={str(host): 'wait'},
all_stderr={str(host): ''}
)
self.log_step('Unit Test Passed')

def test_harness_unit_run_remote_single(self):
"""Verify run_remote() with a single host.

Expand All @@ -244,7 +336,7 @@ def test_harness_unit_run_remote_single(self):
hosts = self.get_hosts_from_yaml('test_clients', 'partition', 'reservation', '/run/hosts/*')
command = 'uname -o'
self.log_step('Verify run_remote() w/ single host')
self._verify_remote_command_result(
self._verify_command_result(
result=run_remote(self.log, NodeSet(hosts[0]), command),
passed=True,
expected=[ResultData(command, 0, NodeSet(hosts[0]), ['GNU/Linux'], [], False)],
Expand All @@ -268,7 +360,7 @@ def test_harness_unit_run_remote_homogeneous(self):
hosts = self.get_hosts_from_yaml('test_clients', 'partition', 'reservation', '/run/hosts/*')
command = 'uname -o'
self.log_step('Verify run_remote() w/ homogeneous output')
self._verify_remote_command_result(
self._verify_command_result(
result=run_remote(self.log, hosts, command),
passed=True,
expected=[ResultData(command, 0, hosts, ['GNU/Linux'], [], False)],
Expand All @@ -292,7 +384,7 @@ def test_harness_unit_run_remote_heterogeneous(self):
hosts = self.get_hosts_from_yaml('test_clients', 'partition', 'reservation', '/run/hosts/*')
command = 'hostname -s'
self.log_step('Verify run_remote() w/ heterogeneous output')
self._verify_remote_command_result(
self._verify_command_result(
result=run_remote(self.log, hosts, command),
passed=True,
expected=[
Expand Down Expand Up @@ -323,10 +415,9 @@ def test_harness_unit_run_remote_combined(self):
:avocado: tags=HarnessUnitTest,test_harness_unit_run_remote_combined
"""
hosts = self.get_hosts_from_yaml('test_clients', 'partition', 'reservation', '/run/hosts/*')
command = 'echo stdout; if [ $(hostname -s) == \'{}\' ]; then echo stderr 1>&2; fi'.format(
hosts[1])
command = f'echo stdout; if [ $(hostname -s) == \'{hosts[1]}\' ]; then echo stderr 1>&2; fi'
self.log_step('Verify run_remote() w/ separated stdout and stderr')
self._verify_remote_command_result(
self._verify_command_result(
result=run_remote(self.log, hosts, command, stderr=False),
passed=True,
expected=[
Expand Down Expand Up @@ -357,10 +448,9 @@ def test_harness_unit_run_remote_separated(self):
:avocado: tags=HarnessUnitTest,test_harness_unit_run_remote_separated
"""
hosts = self.get_hosts_from_yaml('test_clients', 'partition', 'reservation', '/run/hosts/*')
command = 'echo stdout; if [ $(hostname -s) == \'{}\' ]; then echo stderr 1>&2; fi'.format(
hosts[1])
command = f'echo stdout; if [ $(hostname -s) == \'{hosts[1]}\' ]; then echo stderr 1>&2; fi'
self.log_step('Verify run_remote() w/ separated stdout and stderr')
self._verify_remote_command_result(
self._verify_command_result(
result=run_remote(self.log, hosts, command, stderr=True),
passed=True,
expected=[
Expand All @@ -383,17 +473,17 @@ def test_harness_unit_run_remote_separated(self):
self.log_step('Unit Test Passed')

def test_harness_unit_run_remote_no_stdout(self):
"""Verify run_remote() with separated stdout and stderr.
"""Verify run_remote() with no stdout.

:avocado: tags=all
:avocado: tags=vm
:avocado: tags=harness,run_utils
:avocado: tags=HarnessUnitTest,test_harness_unit_run_remote_no_stdout
"""
hosts = self.get_hosts_from_yaml('test_clients', 'partition', 'reservation', '/run/hosts/*')
command = 'if [ $(hostname -s) == \'{}\' ]; then echo stderr 1>&2; fi'.format(hosts[1])
command = f'if [ $(hostname -s) == \'{hosts[1]}\' ]; then echo stderr 1>&2; fi'
self.log_step('Verify run_remote() w/ no stdout')
self._verify_remote_command_result(
self._verify_command_result(
result=run_remote(self.log, hosts, command, stderr=True),
passed=True,
expected=[
Expand All @@ -416,18 +506,17 @@ def test_harness_unit_run_remote_no_stdout(self):
self.log_step('Unit Test Passed')

def test_harness_unit_run_remote_failure(self):
"""Verify run_remote() with separated stdout and stderr.
"""Verify run_remote() with a failure.

:avocado: tags=all
:avocado: tags=vm
:avocado: tags=harness,run_utils
:avocado: tags=HarnessUnitTest,test_harness_unit_run_remote_failure
"""
hosts = self.get_hosts_from_yaml('test_clients', 'partition', 'reservation', '/run/hosts/*')
command = 'if [ $(hostname -s) == \'{}\' ]; then echo fail; exit 1; fi; echo pass'.format(
hosts[1])
command = f'if [ $(hostname -s) == \'{hosts[1]}\' ]; then echo fail; exit 1; fi; echo pass'
self.log_step('Verify run_remote() w/ a failure')
self._verify_remote_command_result(
self._verify_command_result(
result=run_remote(self.log, hosts, command, stderr=True),
passed=False,
expected=[
Expand All @@ -448,3 +537,36 @@ def test_harness_unit_run_remote_failure(self):
}
)
self.log_step('Unit Test Passed')

def test_harness_unit_run_remote_timeout(self):
"""Verify run_remote() with a timeout.

:avocado: tags=all
:avocado: tags=vm
:avocado: tags=harness,run_utils
:avocado: tags=HarnessUnitTest,test_harness_unit_run_remote_timeout
"""
hosts = self.get_hosts_from_yaml('test_clients', 'partition', 'reservation', '/run/hosts/*')
command = f'if [ $(hostname -s) == \'{hosts[1]}\' ]; then echo wait; sleep 5; fi; echo pass'
self.log_step('Verify run_remote() w/ a timeout')
self._verify_command_result(
result=run_remote(self.log, hosts, command, stderr=True, timeout=2),
passed=False,
expected=[
ResultData(command, 0, NodeSet(hosts[0]), ['pass'], [], False),
ResultData(command, 1, NodeSet(hosts[1]), ['wait'], [], True),
],
timeout=True,
homogeneous=False,
passed_hosts=NodeSet(hosts[0]),
failed_hosts=NodeSet(hosts[1]),
all_stdout={
hosts[0]: 'pass',
hosts[1]: 'wait'
},
all_stderr={
hosts[0]: '',
hosts[1]: ''
}
)
self.log_step('Unit Test Passed')
Loading
Loading