52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
#from pathlib import Path
|
|
#import shlex
|
|
#import textwrap
|
|
from typing import cast, TYPE_CHECKING
|
|
|
|
from beartype import beartype
|
|
|
|
from test_driver.machine import Machine
|
|
from test_driver.errors import RequestedAssertionFailed
|
|
|
|
if TYPE_CHECKING:
|
|
global machine
|
|
machine = cast(Machine, ...)
|
|
assert machine.shell is not None
|
|
|
|
ls = "eza -lah --color=always --group-directories-first"
|
|
|
|
@beartype
|
|
def run_log(machine: Machine, *commands: str, timeout: int | None = 60) -> str:
|
|
output = ""
|
|
for command in commands:
|
|
with machine.nested(f"must succeed: {command}"):
|
|
(status, out) = machine.execute(f"{command} | tee /dev/stderr", timeout=timeout)
|
|
if status != 0:
|
|
machine.log(f"output: {out}")
|
|
raise RequestedAssertionFailed(
|
|
f"command `{command}` failed (exit code {status})",
|
|
)
|
|
output += out
|
|
|
|
return output
|
|
|
|
machine.wait_for_unit("default.target")
|
|
assert "lix" in machine.succeed("nix --version").lower()
|
|
machine.log("INIT")
|
|
|
|
|
|
machine.succeed("nixos-generate-config")
|
|
machine.succeed("mkdir -vp /etc/nixos")
|
|
# Dereference is required since that configuration.nix is probably a symlink to the store.
|
|
machine.succeed("cp -rv --dereference /run/current-system/sw/share/nixos/configuration.nix /etc/nixos/")
|
|
|
|
machine.succeed("env PAGER= nixos-rebuild switch --log-format raw-with-logs --fallback")
|
|
|
|
@beartype
|
|
def get_interval() -> str:
|
|
prop = machine.get_unit_property("tzupdate.timer", "OnCalendar")
|
|
print(f"{prop=}")
|
|
|
|
return prop
|
|
|
|
get_interval()
|