Skip to content

Commit

Permalink
Print test helper's logs to stderr for interleaving with VM logs
Browse files Browse the repository at this point in the history
  • Loading branch information
yfyf authored and knuton committed Nov 28, 2024
1 parent d9d5265 commit 340078f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions testing/helpers/nixos-test-script-helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import unittest
from colorama import Fore, Style
import re
import sys

# HACK: create writable cow disk overlay (same as in ./run-in-vm --disk)
def create_overlay(disk, overlay_path):
Expand All @@ -13,15 +14,18 @@ def create_overlay(disk, overlay_path):
],
check=True)

def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)

class AbstractTestCheck(object):
def __init__(self, check_kind, test_descr):
self.check_kind = check_kind
self.test_descr = test_descr
self.test_c = unittest.TestCase()

def print_descr(self, outcome=""):
print(f"{Style.BRIGHT}[{self.check_kind}] {self.test_descr}... {outcome}")
print(Style.RESET_ALL)
eprint(f"{Style.BRIGHT}[{self.check_kind}] {self.test_descr}... {outcome}")
eprint(Style.RESET_ALL)

def print_ok(self):
self.print_descr(outcome=f"{Fore.GREEN}OK!")
Expand Down Expand Up @@ -56,10 +60,10 @@ def wait_for_logs(vm, regex, unit=None, timeout=10):
try:
vm.wait_until_succeeds(full_cmd, timeout=timeout)
except Exception as e:
print(f"wait_for_logs ({full_cmd}) failed after {timeout} seconds")
print("Last VM logs:\n")
eprint(f"wait_for_logs ({full_cmd}) failed after {timeout} seconds")
eprint("Last VM logs:\n")
_, output = vm.execute(f"{journal_cmd} | tail -30")
print(output)
eprint(output)
raise e


Expand Down

0 comments on commit 340078f

Please sign in to comment.