Skip to content

Commit

Permalink
Move abort detection into test invocation (#3040)
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 authored Aug 3, 2024
1 parent d549bd3 commit 63b1035
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
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

@functools.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

0 comments on commit 63b1035

Please sign in to comment.