docs: automate gif generation
This commit is contained in:
1 parent
a39797cbd2
commit
04219bb58e
18 files changed
+375
-153
No files matched your search
@@ -0,0 +1,31 @@
|
||||
{ demoHost }:
|
||||
{
|
||||
name = "bootvine";
|
||||
|
||||
nodes.machine =
|
||||
{ lib, ... }:
|
||||
let
|
||||
waitFor = flag: "/bin/sh -c 'until [ -e /run/${flag} ]; do sleep 0.1; done'";
|
||||
in
|
||||
{
|
||||
imports = [ demoHost ];
|
||||
testing.initrdBackdoor = true;
|
||||
boot.initrd.systemd.services.demo-initrd-probe.serviceConfig.ExecStart = lib.mkForce (
|
||||
waitFor "release-initrd-probe"
|
||||
);
|
||||
systemd = {
|
||||
settings.Manager.ShowStatus = lib.mkForce true;
|
||||
services.demo-db.serviceConfig.ExecStop = lib.mkForce (waitFor "release-demo-db");
|
||||
services.backdoor.before = [ "demo-db.service" ];
|
||||
};
|
||||
virtualisation = {
|
||||
memorySize = 2048;
|
||||
qemu.options = [
|
||||
"-vga none"
|
||||
"-device virtio-vga,xres=1280,yres=800"
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
testScript = builtins.readFile ./console.py + builtins.readFile ./boot.py;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
def console_level():
|
||||
return machine.succeed("cut -f1 /proc/sys/kernel/printk").strip()
|
||||
|
||||
|
||||
def unit_state(unit):
|
||||
return machine.succeed(f"systemctl is-active {unit} || true").strip()
|
||||
|
||||
|
||||
machine.start()
|
||||
|
||||
wait_for_screen("Initrd", "Slow hardware probe")
|
||||
assert_bootvine_in_front()
|
||||
assert_text_visible(font_has_512_glyphs=True)
|
||||
assert console_level() == "1", f"the kernel console was not quieted: {console_level()}"
|
||||
machine.succeed("touch /run/release-initrd-probe")
|
||||
machine.switch_root()
|
||||
|
||||
retry(lambda _: unit_state("demo-db") == "activating", timeout_seconds=60)
|
||||
wait_for_screen("Stage 2", "demo-db")
|
||||
assert_bootvine_in_front()
|
||||
assert_text_visible(font_has_512_glyphs=True)
|
||||
assert console_level() == "1", f"stage 2 sysctl reopened the kernel console: {console_level()}"
|
||||
|
||||
machine.wait_for_unit("greetd.service")
|
||||
retry(lambda _: unit_state("bootvine") == "inactive", timeout_seconds=60)
|
||||
|
||||
journal = bootvine_journal()
|
||||
print(journal)
|
||||
watched = [line for line in journal.splitlines() if line.startswith("bootvine: watching")]
|
||||
assert any(" in Initrd " in line for line in watched), "never ran in the initrd"
|
||||
assert any(" in Stage 2 " in line for line in watched), "never reconnected after the root switch"
|
||||
pids = {line.split(" as pid ")[1].split()[0] for line in watched}
|
||||
assert len(pids) == 1, f"the initrd process did not survive the root switch: {pids}"
|
||||
assert "handing the console over" in journal, "never handed the console over"
|
||||
|
||||
machine.succeed('test "$(systemctl show -p Result --value bootvine)" = success')
|
||||
assert console_level() != "1", f"kernel console level was not restored: {console_level()}"
|
||||
show_status = machine.succeed("systemctl show -p ShowStatus --value").strip()
|
||||
assert show_status == "yes", f"systemd status output was not restored: {show_status}"
|
||||
|
||||
foreground = foreground_terminal()
|
||||
assert foreground != f"tty{BOOTVINE_TERMINAL}", "bootvine kept the console after handing it over"
|
||||
machine.succeed("systemctl restart bootvine")
|
||||
retry(lambda _: unit_state("bootvine") == "inactive", timeout_seconds=10)
|
||||
assert "boot already finished" in bootvine_journal(), "a restart after boot did not stand down"
|
||||
assert foreground_terminal() == foreground, "a restart after boot took the console"
|
||||
|
||||
machine.succeed("systemctl poweroff --no-block")
|
||||
retry(lambda _: unit_state("demo-db") == "deactivating", timeout_seconds=60)
|
||||
wait_for_screen("Shutdown", "demo-db")
|
||||
assert_bootvine_in_front()
|
||||
assert_text_visible(font_has_512_glyphs=True)
|
||||
machine.succeed("touch /run/release-demo-db")
|
||||
machine.wait_for_shutdown()
|
||||
@@ -0,0 +1,69 @@
|
||||
import base64
|
||||
|
||||
BOOTVINE_TERMINAL = 12
|
||||
|
||||
|
||||
def read_terminal():
|
||||
attributed, characters = machine.succeed(
|
||||
f"base64 -w0 /dev/vcsa{BOOTVINE_TERMINAL}; echo; "
|
||||
f"base64 -w0 /dev/vcsu{BOOTVINE_TERMINAL}"
|
||||
).split()
|
||||
attributed = base64.b64decode(attributed)
|
||||
columns = attributed[1]
|
||||
attributes = attributed[5::2]
|
||||
text = base64.b64decode(characters).decode("utf-32-le")
|
||||
return columns, text, attributes
|
||||
|
||||
|
||||
def as_rows(text, columns):
|
||||
return "\n".join(text[start : start + columns] for start in range(0, len(text), columns))
|
||||
|
||||
|
||||
def screen():
|
||||
columns, text, _ = read_terminal()
|
||||
return as_rows(text, columns)
|
||||
|
||||
|
||||
def colours(attribute, font_has_512_glyphs):
|
||||
if font_has_512_glyphs:
|
||||
return (attribute >> 1) & 0x0F, (attribute >> 5) & 0x07
|
||||
return attribute & 0x0F, (attribute >> 4) & 0x07
|
||||
|
||||
|
||||
def assert_text_visible(font_has_512_glyphs=False):
|
||||
columns, text, attributes = read_terminal()
|
||||
|
||||
def is_hidden(character, attribute):
|
||||
foreground, background = colours(attribute, font_has_512_glyphs)
|
||||
return character != " " and foreground == background
|
||||
|
||||
hidden = "".join(
|
||||
"#" if is_hidden(character, attribute) else " "
|
||||
for character, attribute in zip(text, attributes)
|
||||
)
|
||||
assert "#" not in hidden, (
|
||||
f"text drawn in its background colour, marked #:\n{as_rows(hidden, columns)}\n{as_rows(text, columns)}"
|
||||
)
|
||||
|
||||
|
||||
def wait_for_screen(*fragments):
|
||||
def shows_all(last_try):
|
||||
text = screen()
|
||||
if last_try:
|
||||
print(text)
|
||||
return all(fragment in text for fragment in fragments)
|
||||
|
||||
retry(shows_all, timeout_seconds=60)
|
||||
|
||||
|
||||
def foreground_terminal():
|
||||
return machine.succeed("cat /sys/class/tty/tty0/active").strip()
|
||||
|
||||
|
||||
def assert_bootvine_in_front():
|
||||
active = foreground_terminal()
|
||||
assert active == f"tty{BOOTVINE_TERMINAL}", f"bootvine is not in front: {active}"
|
||||
|
||||
|
||||
def bootvine_journal():
|
||||
return machine.succeed("journalctl -b -u bootvine -o cat")
|
||||
@@ -0,0 +1,50 @@
|
||||
{ bootvineModule }:
|
||||
let
|
||||
passphrase = "quietly unlocked";
|
||||
in
|
||||
{
|
||||
name = "bootvine-luks";
|
||||
nodes.machine =
|
||||
{ lib, pkgs, ... }:
|
||||
let
|
||||
secretUuid = "9d1f2a8e-0b7c-4c55-9a8e-6b2f8f3c1d00";
|
||||
secretDisk = pkgs.runCommand "bootvine-luks-disk" { nativeBuildInputs = [ pkgs.cryptsetup ]; } ''
|
||||
truncate -s 32M disk.img
|
||||
echo -n '${passphrase}' | cryptsetup luksFormat -q --disable-locks --type luks2 \
|
||||
--pbkdf pbkdf2 --pbkdf-force-iterations 1000 --uuid ${secretUuid} disk.img -
|
||||
mv disk.img $out
|
||||
'';
|
||||
in
|
||||
{
|
||||
imports = [ bootvineModule ];
|
||||
|
||||
services.bootvine.enable = true;
|
||||
|
||||
testing.initrdBackdoor = true;
|
||||
boot.initrd.systemd.enable = true;
|
||||
boot.initrd.luks.devices = lib.mkVMOverride {
|
||||
secret.device = "/dev/disk/by-uuid/${secretUuid}";
|
||||
};
|
||||
|
||||
virtualisation.qemu.options = [
|
||||
"-vga none"
|
||||
"-device virtio-vga,xres=1280,yres=800"
|
||||
];
|
||||
virtualisation.qemu.drives = [
|
||||
{
|
||||
name = "secret";
|
||||
file = "${secretDisk}";
|
||||
driveExtraOpts = {
|
||||
format = "raw";
|
||||
snapshot = "on";
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
PASSPHRASE = "${passphrase}"
|
||||
''
|
||||
+ builtins.readFile ./console.py
|
||||
+ builtins.readFile ./luks.py;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
def answered_prompts():
|
||||
return bootvine_journal().count("answered a password prompt")
|
||||
|
||||
|
||||
def pending_prompt():
|
||||
listing = machine.succeed("ls /run/systemd/ask-password").split()
|
||||
return next((name for name in listing if name.startswith("ask.")), "")
|
||||
|
||||
|
||||
machine.start()
|
||||
|
||||
retry(lambda _: pending_prompt() != "", timeout_seconds=60)
|
||||
wait_for_screen("passphrase")
|
||||
assert_text_visible()
|
||||
first_prompt = pending_prompt()
|
||||
machine.send_chars("not the passphrase\n")
|
||||
retry(lambda _: answered_prompts() == 1, timeout_seconds=30)
|
||||
retry(lambda _: pending_prompt() not in ("", first_prompt), timeout_seconds=30)
|
||||
wait_for_screen("passphrase")
|
||||
assert_text_visible()
|
||||
machine.screenshot("passphrase")
|
||||
machine.send_chars(f"{PASSPHRASE}\n")
|
||||
machine.wait_for_unit("systemd-cryptsetup@secret.service")
|
||||
machine.switch_root()
|
||||
machine.wait_for_unit("multi-user.target")
|
||||
|
||||
machine.succeed("test -e /dev/mapper/secret")
|
||||
journal = bootvine_journal()
|
||||
print(journal)
|
||||
assert " in Initrd " in journal, "never ran in the initrd"
|
||||
assert journal.count("answered a password prompt") == 2, "did not answer both attempts itself"
|
||||
Reference in new issue
Block a user