Skip to content

Commit

Permalink
Reportportal should note guest hostname for investigation
Browse files Browse the repository at this point in the history
It may happen the guest name or role are not set, yet there are multiple
guests reported into the same launch, when reporting multiple tmt runs
into the same RP launch, e.g. when those runs run the same tests but on
different hosts. This is a common case for those running tests on
multiple architectures, e.g. when testing a Koji build.
  • Loading branch information
happz committed Sep 16, 2024
1 parent 4b3394b commit ef86b4c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
24 changes: 21 additions & 3 deletions tmt/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ class ResultGuestData(SerializableContainer):

name: str = f'{tmt.utils.DEFAULT_NAME}-0'
role: Optional[str] = None
primary_address: Optional[str] = None

@classmethod
def from_test_invocation(
cls,
*,
invocation: 'tmt.steps.execute.TestInvocation') -> 'ResultGuestData':
"""
Create a guest data for a result from a test invocation.
A helper for extracting interesting guest data from a given test
invocation.
:param invocation: a test invocation capturing the test run and results.
"""

return ResultGuestData(
name=invocation.guest.name,
role=invocation.guest.role,
primary_address=invocation.guest.primary_address)


# This needs to be a stand-alone function because of the import of `tmt.base`.
Expand Down Expand Up @@ -253,8 +273,6 @@ def from_test_invocation(
default_ids.update(ids)
ids = default_ids

guest_data = ResultGuestData(name=invocation.guest.name, role=invocation.guest.role)

_result = Result(
name=invocation.test.name,
serial_number=invocation.test.serial_number,
Expand All @@ -267,7 +285,7 @@ def from_test_invocation(
duration=invocation.real_duration,
ids=ids,
log=log or [],
guest=guest_data,
guest=ResultGuestData.from_test_invocation(invocation=invocation),
data_path=invocation.relative_test_data_path)

return _result.interpret_result(ResultInterpret(
Expand Down
4 changes: 2 additions & 2 deletions tmt/steps/execute/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ def _process_results_partials(
:returns: list of results.
"""

test, guest = invocation.test, invocation.guest
test, _ = invocation.test, invocation.guest

custom_results = []
for partial_result_data in results:
Expand Down Expand Up @@ -795,7 +795,7 @@ def _process_results_partials(
partial_result.serial_number = test.serial_number

# Enforce the correct guest info
partial_result.guest = ResultGuestData(name=guest.name, role=guest.role)
partial_result.guest = ResultGuestData.from_test_invocation(invocation=invocation)

# For the result representing the test itself, set the important
# attributes to reflect the reality.
Expand Down
9 changes: 8 additions & 1 deletion tmt/steps/report/reportportal.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,14 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:
item_attributes = attributes.copy()
if result:
test_time = result.start_time or self.time()
# for multi-host tests store also provision name and role

# for guests, save their primary address
if result.guest.primary_address:
item_attributes.append({
'key': 'guest_primary_address',
'value': result.guest.primary_address})

# for multi-host tests store also guest name and role
if result.guest.name != 'default-0':
item_attributes.append(
{'key': 'guest_name', 'value': result.guest.name})
Expand Down

0 comments on commit ef86b4c

Please sign in to comment.