Test that an update keeps upgraded packages
The update test upgrades nixpkgs first; the pin and the lock must survive a rolled-back update, a confirmed one and the rebuild after it. The channel server moves to the shared test helpers. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV9dZrK6nipHkPfyM4F
This commit is contained in:
+42
-2
@@ -89,6 +89,7 @@ let
|
||||
stateVersion = "26.11";
|
||||
};
|
||||
router = {
|
||||
update.channel = "26.05";
|
||||
wan.interface = "eth1";
|
||||
lans.main = {
|
||||
interface = "eth2";
|
||||
@@ -104,12 +105,18 @@ let
|
||||
);
|
||||
|
||||
# Only so the test driver can talk to the installed system; and a short
|
||||
# rollback timeout, so that an unconfirmed update comes back soon.
|
||||
# rollback timeout, so that an unconfirmed update comes back soon. The
|
||||
# channel is a server on the builder, and a newer nixpkgs a copy of the
|
||||
# installed one (see apply.nix): what is tested is that an update keeps it.
|
||||
local = pkgs.writeText "local.nix" ''
|
||||
{ modulesPath, pkgs, ... }:
|
||||
{
|
||||
imports = [ (modulesPath + "/testing/test-instrumentation.nix") ];
|
||||
router.rollback.timeout = "90s";
|
||||
routerSettings.upgrade = {
|
||||
channelsUrl = "http://192.168.10.60:8080";
|
||||
nixpkgsRef = "path:/var/lib/newer-nixpkgs?lastModified=${toString self.inputs.nixpkgs.lastModified}&rev=%rev%";
|
||||
};
|
||||
environment.systemPackages = [ pkgs.jq ];
|
||||
}
|
||||
'';
|
||||
@@ -184,12 +191,15 @@ pkgs.testers.runNixOSTest {
|
||||
release1
|
||||
release2
|
||||
];
|
||||
environment.etc."channels.py".source = common.channelServer pkgs;
|
||||
environment.etc."keys/good.sec".source = "${keys}/good.sec";
|
||||
environment.etc."keys/evil.sec".source = "${keys}/evil.sec";
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
import json
|
||||
|
||||
installer.start()
|
||||
installer.wait_for_unit("multi-user.target")
|
||||
installer.succeed("mkdir -p /root/secrets && cp -r ${configDir} /root/secrets/config")
|
||||
@@ -235,6 +245,33 @@ pkgs.testers.runNixOSTest {
|
||||
assert v1_flake == "path:${v1.src}", v1_flake
|
||||
target.succeed("test -s /etc/router-update-keys")
|
||||
|
||||
with subtest("the packages are upgraded before any update"):
|
||||
target.succeed("cp -r ${self.inputs.nixpkgs} /var/lib/newer-nixpkgs")
|
||||
builder.succeed("mkdir -p /srv/channels/files/nixos-26.05 && printf %s ${self.inputs.nixpkgs.rev} > /srv/channels/files/nixos-26.05/git-revision")
|
||||
builder.succeed("systemd-run --unit=channels /etc/channels.py")
|
||||
builder.wait_for_open_port(8080)
|
||||
# The packages are the same, so there is only something to activate when
|
||||
# the settings change too (an upgrade applies what is saved).
|
||||
target.succeed("sed -i 's/192.168.10.199/192.168.10.198/' /var/lib/router/config/settings.json")
|
||||
target.succeed("router-upgrade preview --force >&2")
|
||||
target.succeed("router-upgrade apply 5min >&2")
|
||||
target.succeed("router-confirm >&2")
|
||||
target.fail("systemctl is-active router-rollback.timer")
|
||||
assert json.loads(target.succeed("cat /var/lib/router/config/nixpkgs-pin.json"))["rev"] == "${self.inputs.nixpkgs.rev}"
|
||||
assert "newer-nixpkgs" in target.succeed("cat /var/lib/router/config/flake.lock")
|
||||
target.succeed("test ! -e /var/lib/router/config.pre-update")
|
||||
|
||||
pin = target.succeed("cat /var/lib/router/config/nixpkgs-pin.json")
|
||||
|
||||
def pinned():
|
||||
assert target.succeed("cat /var/lib/router/config/nixpkgs-pin.json") == pin
|
||||
# The lock names the upgraded nixpkgs, not the one the release brings.
|
||||
lock = json.loads(target.succeed("cat /var/lib/router/config/flake.lock"))
|
||||
node = lock["nodes"][lock["nodes"]["root"]["inputs"]["nixos-router"]]["inputs"]["nixpkgs"]
|
||||
assert lock["nodes"][node]["locked"]["path"] == "/var/lib/newer-nixpkgs", lock["nodes"][node]
|
||||
|
||||
pinned()
|
||||
|
||||
sign("${tool v2 release2}", "evil", "/root/evil")
|
||||
serve("/root/evil", 8001)
|
||||
sign("${tool v2 release2}", "good", "/root/good")
|
||||
@@ -289,6 +326,7 @@ pkgs.testers.runNixOSTest {
|
||||
unchanged()
|
||||
assert "Berlin" not in target.succeed("cat /var/lib/router/config/settings.json")
|
||||
assert target.succeed("readlink /etc/localtime").strip().endswith("/UTC")
|
||||
pinned()
|
||||
target.wait_for_unit("router-webui.service")
|
||||
|
||||
with subtest("the same update, pulled from a server in the web UI, can be confirmed"):
|
||||
@@ -311,7 +349,9 @@ pkgs.testers.runNixOSTest {
|
||||
assert target.succeed("readlink -f /nix/var/nix/profiles/system").strip() == current()
|
||||
assert target.succeed("readlink /etc/localtime").strip().endswith("Europe/Berlin")
|
||||
|
||||
with subtest("the updated router rebuilds to exactly itself, offline"):
|
||||
with subtest("the updated router keeps the upgraded packages and rebuilds to exactly itself, offline"):
|
||||
pinned()
|
||||
assert flake_source() == "path:${v2.src}", flake_source()
|
||||
out = target.succeed("router-apply 2>&1")
|
||||
assert "no changes" in out, out
|
||||
|
||||
|
||||
Reference in New Issue
Block a user