diff options
| author | tv <tv@krebsco.de> | 2026-11-30 18:05:23 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-30 22:03:11 +0000 |
| commit | 2df89c5ff9bb32dab96a504116206ccce1045ccf (patch) | |
| tree | 9c74466dce57a83aad923b8501254c0aadbe6f92 /nix/test.nix | |
| parent | b74359e97643be0f43034c3aeab533a2389a939f (diff) | |
nix: the switch serves the views when there is something to serve
enstate.service reruns on a switch when the schema changes. A unit of
its own, enstate-switch.service, takes what waits otherwise: a
submission in incomingDir, or one staged. switch-to-configuration
restarts sysinit-reactivation.target on every switch, which starts it,
and triggering conditions keep it from running when nothing waits. The
check before a switch uses the new generation's enstate, schema and
configuration, and runs on a host without enstate, too: its first
switch's state can wait in incomingDir. Subtests of the VM test: staged
under an unchanged schema, brought by the switch (without the warning
the activation-restart-list gives); a waiting submission taken by the
switch that needs it; one refused refusing it.
Diffstat (limited to 'nix/test.nix')
| -rw-r--r-- | nix/test.nix | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/nix/test.nix b/nix/test.nix index d2f69d9..4a37ff3 100644 --- a/nix/test.nix +++ b/nix/test.nix @@ -57,6 +57,11 @@ pkgs.testers.runNixOSTest { enstate.channels.secrets.slots."extra.key" = key; }; + # Adds another; its submission waits in the incoming directory. + specialisation.more.configuration = { + enstate.channels.secrets.slots."more.key" = key; + }; + specialisation.retyped.configuration = { enstate.channels.secrets.slots = lib.mkForce { "tinc.key" = key // { @@ -67,7 +72,7 @@ pkgs.testers.runNixOSTest { }; testScript = '' - def submit(name, key): + def submit(name, key, command="--apply"): machine.succeed( f"mkdir -p /root/{name}", f"printf '{key}' > /root/{name}/key", @@ -76,7 +81,7 @@ pkgs.testers.runNixOSTest { f"> /root/{name}/sources.json", f"enstate --pack /root/{name}/sources.json --out /root/{name}/submission", f"enstate --plan /root/{name}/submission", - f"enstate --apply /root/{name}/submission", + f"enstate {command} /root/{name}/submission", ) def seen(expected): @@ -135,10 +140,48 @@ pkgs.testers.runNixOSTest { machine.succeed("/run/booted-system/bin/switch-to-configuration test") machine.succeed("enstate --status | grep -q 'kept extra.key'") + with subtest("staged under an unchanged schema: the switch brings it"): + submit("third", "M", "--stage") + seen("tinc.key L") + machine.succeed("test -e /var/lib/enstate/migrate-due") + out = machine.succeed("/run/current-system/bin/switch-to-configuration test 2>&1") + assert "deprecated" not in out, out + seen("tinc.key M") + machine.fail("test -e /var/lib/enstate/migrate-due") + + with subtest("incoming: a submission waits for the switch that needs it"): + new = "/run/booted-system/specialisation/more" + machine.fail(f"{new}/bin/switch-to-configuration test") + machine.succeed( + "mkdir -p /root/more", + "printf Y > /root/more/key", + """echo '{"channel": "secrets", "items": {"more.key": {"source": {"file": "key"}}}}' """ + "> /root/more/sources.json", + "enstate --pack /root/more/sources.json --out /var/lib/enstate/incoming/1-more", + ) + machine.succeed(f"{new}/bin/switch-to-configuration test") + machine.wait_until_succeeds("grep -qx Y /run/enstate/views/secrets.more.key/more.key") + machine.succeed("test -z \"$(ls -A /var/lib/enstate/incoming)\"") + seen("tinc.key M") + machine.succeed("/run/booted-system/bin/switch-to-configuration test") + + with subtest("incoming: one refused refuses the switch, and stays"): + machine.succeed( + "mkdir -p /var/lib/enstate/incoming/2-bad/channels/secrets", + "printf x > /var/lib/enstate/incoming/2-bad/channels/secrets/nope", + """echo '{"submission": 1, "channel": "secrets", "items": """ + """[{"address": "secrets/nope", "op": "set"}]}' """ + "> /var/lib/enstate/incoming/2-bad/manifest.json", + ) + machine.fail("/run/booted-system/specialisation/more/bin/switch-to-configuration test") + machine.succeed("test -d /var/lib/enstate/incoming/2-bad") + machine.succeed("rm -r /var/lib/enstate/incoming/2-bad") + + with subtest("after a reboot, the views are there again"): machine.shutdown() machine.start() machine.wait_for_unit("consumer.service") - seen("tinc.key L") + seen("tinc.key M") ''; } |
