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

Move abort detection into test invocation #3040

Merged
merged 3 commits into from
Aug 3, 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
19 changes: 11 additions & 8 deletions tmt/steps/execute/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ def reboot_request_path(self) -> Path:
""" A path to the reboot request file """
return self.test_data_path / TMT_REBOOT_SCRIPT.created_file

@tmt.utils.cached_property
def abort_request_path(self) -> Path:
""" A path to the abort request file """
return self.test_data_path / TMT_ABORT_SCRIPT.created_file

@property
def soft_reboot_requested(self) -> bool:
""" If set, test requested a reboot """
Expand All @@ -252,6 +257,12 @@ def restart_requested(self) -> bool:

return self.return_code in self.test.restart_on_exit_code

@property
def abort_requested(self) -> bool:
""" Whether a testing abort was requested """

return self.abort_request_path.exists()

@property
def is_guest_healthy(self) -> bool:
"""
Expand Down Expand Up @@ -701,14 +712,6 @@ def extract_results(

return invocation.test.test_framework.extract_results(invocation, logger)

def check_abort_file(self, invocation: TestInvocation) -> bool:
"""
Check for an abort file created by tmt-abort

Returns whether an abort file is present (i.e. abort occurred).
"""
return (invocation.test_data_path / TMT_ABORT_SCRIPT.created_file).exists()

@staticmethod
def format_timestamp(timestamp: datetime.datetime) -> str:
""" Convert timestamp to a human readable format """
Expand Down
14 changes: 9 additions & 5 deletions tmt/steps/execute/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,11 +571,12 @@ def _run_tests(
for result in invocation.results:
result.result = ResultOutcome.ERROR
result.note = 'reboot timeout'
abort = self.check_abort_file(invocation)
if abort:

if invocation.abort_requested:
for result in invocation.results:
# In case of aborted all results in list will be aborted
result.note = 'aborted'

self._results.extend(invocation.results)

# If test duration information is missing, print 8 spaces to keep indentation
Expand All @@ -597,11 +598,14 @@ def _format_duration(result: BaseResult) -> str:
f'({check_result.event.value} check)',
shift=shift)

if (abort or self.data.exit_first and
result.result not in (ResultOutcome.PASS, ResultOutcome.INFO)):
if invocation.abort_requested or (
self.data.exit_first and any(
result.result not in (
ResultOutcome.PASS,
ResultOutcome.INFO) for result in invocation.results)):
# Clear the progress bar before outputting
progress_bar.clear()
what_happened = "aborted" if abort else "failed"
what_happened = "aborted" if invocation.abort_requested else "failed"
self.warn(
f'Test {test.name} {what_happened}, stopping execution.')
break
Expand Down
Loading