From 3048fc80e17a429d0698aa823fc0dec85583c3d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Prchl=C3=ADk?= Date: Mon, 4 Mar 2024 18:01:30 +0100 Subject: [PATCH] squash: more logging and do overwrite results after reboot --- tmt/checks/avc.py | 3 +++ tmt/checks/dmesg.py | 3 +++ tmt/checks/watchdog.py | 15 ++++++++++++++- tmt/steps/execute/internal.py | 14 +++++++------- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/tmt/checks/avc.py b/tmt/checks/avc.py index be235ff252..d77d54c0de 100644 --- a/tmt/checks/avc.py +++ b/tmt/checks/avc.py @@ -330,6 +330,9 @@ def after_test( name='avc', result=ResultOutcome.SKIP)] + if invocation.hard_reboot_requested: + return [CheckResult(name='dmesg', result=ResultOutcome.SKIP)] + assert invocation.phase.step.workdir is not None # narrow type outcome, path = create_final_report(invocation, logger) diff --git a/tmt/checks/dmesg.py b/tmt/checks/dmesg.py index f58719cb0c..9bdc536b05 100644 --- a/tmt/checks/dmesg.py +++ b/tmt/checks/dmesg.py @@ -150,6 +150,9 @@ def after_test( if not invocation.guest.facts.has_capability(GuestCapability.SYSLOG_ACTION_READ_ALL): return [CheckResult(name='dmesg', result=ResultOutcome.SKIP)] + if invocation.hard_reboot_requested: + return [CheckResult(name='dmesg', result=ResultOutcome.SKIP)] + outcome, path = cls._save_dmesg(invocation, CheckEvent.AFTER_TEST, logger) return [CheckResult(name='dmesg', result=outcome, log=[path])] diff --git a/tmt/checks/watchdog.py b/tmt/checks/watchdog.py index 1a6e386f22..1d776a8fc7 100644 --- a/tmt/checks/watchdog.py +++ b/tmt/checks/watchdog.py @@ -395,7 +395,9 @@ def before_test( watchdog_logger.labels.append('watchdog') # Create a guest context for the guest we've been given - guest_context = invocation.check_data[check.how] = GuestContext() + invocation.check_data[check.how] = GuestContext() + + guest_context: GuestContext = invocation.check_data[check.how] if check.ping and not isinstance(invocation.guest, PINGABLE_GUEST_CLASSES): watchdog_logger.warn('Ping against this guest is not supported, disabling.') @@ -410,6 +412,10 @@ def before_test( def watchdog(guest_context: GuestContext) -> None: """ Watchdog thread code """ + tid = threading.get_ident() + + watchdog_logger.debug(f'Watchdog starts in thread {tid}') + while guest_context.keep_running: if check.ping: check.do_ping(invocation, guest_context, watchdog_logger) @@ -419,6 +425,8 @@ def watchdog(guest_context: GuestContext) -> None: time.sleep(check.interval) + watchdog_logger.debug(f'Watchdog finished in thread {tid}') + guest_context.thread = threading.Thread( target=watchdog, args=(guest_context,), @@ -438,9 +446,14 @@ def after_test( environment: Optional[tmt.utils.Environment] = None, logger: tmt.log.Logger) -> list[CheckResult]: + watchdog_logger = logger.clone() + watchdog_logger.labels.append('watchdog') + guest_context: GuestContext = invocation.check_data[check.how] if guest_context.thread: + watchdog_logger.debug(f'Terminating watchdog in thread {guest_context.thread.ident}') + guest_context.keep_running = False guest_context.thread.join() diff --git a/tmt/steps/execute/internal.py b/tmt/steps/execute/internal.py index c5ce893c83..d9140a7278 100644 --- a/tmt/steps/execute/internal.py +++ b/tmt/steps/execute/internal.py @@ -365,7 +365,7 @@ def _save_process( # TODO: do we want timestamps? Yes, we do, leaving that for refactoring later, # to use some reusable decorator. - invocation.check_results += self.run_checks_before_test( + invocation.check_results = self.run_checks_before_test( invocation=invocation, environment=environment, logger=logger @@ -433,13 +433,13 @@ def _save_process( # results after a successful reboot in the middle of a test. invocation.results = self.extract_results(invocation, logger) - if not invocation.hard_reboot_requested: - invocation.check_results += self.run_checks_after_test( - invocation=invocation, - environment=environment, - logger=logger - ) + invocation.check_results += self.run_checks_after_test( + invocation=invocation, + environment=environment, + logger=logger + ) + if not invocation.hard_reboot_requested: # Fetch #2: after-test checks might have produced remote files as well, # we need to fetch them too. guest.pull(