switch-to-configuration-ng: various mount-related fixes (#443001)

This commit is contained in:
Will Fancher
2025-10-12 19:27:44 +00:00
committed by GitHub
2 changed files with 85 additions and 23 deletions

View File

@@ -91,6 +91,14 @@ in
virtualisation.fileSystems."/".device = lib.mkForce "auto";
};
automount.configuration = {
virtualisation.fileSystems."/testauto" = {
device = "tmpfs";
fsType = "tmpfs";
options = [ "x-systemd.automount" ];
};
};
swap.configuration.swapDevices = lib.mkVMOverride [
{
device = "/swapfile";
@@ -627,6 +635,17 @@ in
(pkgs.writeText "dbus-reload-dummy" "dbus reload dummy")
];
};
generators.configuration =
{ lib, pkgs, ... }:
{
systemd.generators.simple-generator = pkgs.writeShellScript "simple-generator" ''
${lib.getExe' pkgs.coreutils "cat"} >$1/simple-generated.service <<EOF
[Service]
ExecStart=${lib.getExe' pkgs.coreutils "sleep"} infinity
EOF
'';
};
};
};
@@ -826,9 +845,21 @@ in
assert_lacks(out, "\nrestarting the following units:")
assert_lacks(out, "\nstarting the following units:")
assert_lacks(out, "the following new units were started:")
# add an automount
out = switch_to_specialisation("${machine}", "automount")
assert_lacks(out, "stopping the following units:")
assert_lacks(out, "\nrestarting the following units:")
assert_lacks(out, "\nstarting the following units:")
assert_contains(out, "the following new units were started: testauto.automount\n")
# remove the automount
out = switch_to_specialisation("${machine}", "")
assert_contains(out, "stopping the following units: testauto.automount\n")
assert_lacks(out, "reloading the following units:")
assert_lacks(out, "\nrestarting the following units:")
assert_lacks(out, "\nstarting the following units:")
assert_lacks(out, "the following new units were started:")
with subtest("swaps"):
switch_to_specialisation("${machine}", "")
# add a swap
out = switch_to_specialisation("${machine}", "swap")
assert_lacks(out, "stopping the following units:")
@@ -1520,5 +1551,13 @@ in
assert_lacks(out, "\nrestarting the following units:")
assert_lacks(out, "\nstarting the following units:")
assert_lacks(out, "the following new units were started:")
with subtest("generators"):
out = switch_to_specialisation("${machine}", "generators")
# The service is not started by anything, so we start it manually
machine.succeed("systemctl start simple-generated.service && systemctl is-active simple-generated.service")
out = switch_to_specialisation("${machine}", "")
# Assert switching to a different generation doesn't touch units created by generators
machine.succeed("systemctl is-active simple-generated.service")
'';
}