Skip to content

Commit

Permalink
Move abort detection into test invocation
Browse files Browse the repository at this point in the history
Similar to reboot detection, hiding the details from individual
execution plugins.
  • Loading branch information
happz committed Jun 23, 2024
1 parent 6af3b39 commit f5263f8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
11 changes: 11 additions & 0 deletions tmt/steps/execute/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,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 @@ -251,6 +256,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
14 changes: 9 additions & 5 deletions tmt/steps/execute/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,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 @@ -590,11 +591,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

0 comments on commit f5263f8

Please sign in to comment.