Skip to content

Commit

Permalink
Assign a data path and serial number to each test in discover
Browse files Browse the repository at this point in the history
To support both multihost scenarios and/or running a test multiple
times, tmt needs to distinguish test data directories of different test
instances. To allow this, each test instance is given a "serial number"
which we can use in a data directory name.

Note: there can be more elaborate ways for picking the serial numbers,
the patch starts with something really trivial yet functioning.

Another note: the patch does not isolate tests on a phase level, a
single test, executed on different guests, may still land in the same
data directory. Different patch will solve this issue.
  • Loading branch information
happz committed Feb 27, 2023
1 parent 118e9bd commit e49d0ad
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions tmt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,8 @@ class Test(Core, tmt.export.Exportable['Test']):
duration: str = DEFAULT_TEST_DURATION_L1
result: str = 'respect'

serial_number: int = 0

returncode: Optional[int] = None
real_duration: Optional[str] = None
_reboot_count: int = 0
Expand Down
2 changes: 2 additions & 0 deletions tmt/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Result(tmt.utils.SerializableContainer):
""" Describes what tmt knows about a single test result """

name: str
serial_number: Optional[int] = None
result: ResultOutcome = field(
default=ResultOutcome.PASS,
serialize=lambda result: result.value,
Expand Down Expand Up @@ -141,6 +142,7 @@ def from_test(

_result = Result(
name=test.name,
serial_number=test.serial_number,
result=result,
note=note,
duration=duration,
Expand Down
6 changes: 6 additions & 0 deletions tmt/steps/discover/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ def go(self) -> None:
else:
raise GeneralError(f'Unexpected phase in discover step: {phase}')

# TODO: better, more elaborete ways of assigning serial numbers to tests
# can be devised - starting with a really trivial one: each test gets
# one, starting with `1`.
for serial, test in enumerate(self._tests, start=1):
test.serial_number = serial

# Show fmf identifiers for tests discovered in plan
# TODO: This part should go into the 'fmf.py' module
if self.opt('fmf_id'):
Expand Down
6 changes: 4 additions & 2 deletions tmt/steps/execute/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,10 @@ def data_path(
filename not provided) or to the given data file otherwise.
"""
# Prepare directory path, create if requested
assert self.step.workdir is not None
directory = self.step.workdir / TEST_DATA / test.name.lstrip('/')
assert self.step.workdir is not None # narrow type
directory = self.step.workdir \
/ TEST_DATA \
/ f'{test.name.lstrip("/")}-{test.serial_number}'
if create and not directory.is_dir():
directory.joinpath(TEST_DATA).mkdir(parents=True)
if not filename:
Expand Down

0 comments on commit e49d0ad

Please sign in to comment.