3
0
Fork 0
forked from mirrors/nixpkgs

nixos/tests/systemd-initrd-networkd: Use initrdBackdoor

This commit is contained in:
Will Fancher 2023-09-20 06:20:05 -04:00
parent 90e2658693
commit 8900b027c7

View file

@ -9,16 +9,28 @@ with import ../lib/testing-python.nix { inherit system pkgs; };
let
inherit (lib.maintainers) elvishjerricco;
common = {
boot.initrd.systemd = {
enable = true;
network.wait-online.timeout = 10;
network.wait-online.anyInterface = true;
targets.network-online.requiredBy = [ "initrd.target" ];
services.systemd-networkd-wait-online.requiredBy =
[ "network-online.target" ];
initrdBin = [ pkgs.iproute2 pkgs.iputils pkgs.gnugrep ];
};
testing.initrdBackdoor = true;
boot.initrd.network.enable = true;
};
mkFlushTest = flush: script: makeTest {
name = "systemd-initrd-network-${lib.optionalString (!flush) "no-"}flush";
meta.maintainers = [ elvishjerricco ];
nodes.machine = {
boot.initrd.systemd.enable = true;
boot.initrd.network = {
enable = true;
flushBeforeStage2 = flush;
};
imports = [ common ];
boot.initrd.network.flushBeforeStage2 = flush;
systemd.services.check-flush = {
requiredBy = ["multi-user.target"];
before = ["network-pre.target" "multi-user.target"];
@ -31,6 +43,13 @@ let
};
testScript = ''
machine.wait_for_unit("network-online.target")
machine.succeed(
"ip addr | grep 10.0.2.15",
"ping -c1 10.0.2.2",
)
machine.switch_root()
machine.wait_for_unit("multi-user.target")
'';
};
@ -40,36 +59,18 @@ in {
name = "systemd-initrd-network";
meta.maintainers = [ elvishjerricco ];
nodes.machine = {
boot.initrd.network.enable = true;
boot.initrd.systemd = {
enable = true;
# Enable network-online to fail the test in case of timeout
network.wait-online.timeout = 10;
network.wait-online.anyInterface = true;
targets.network-online.requiredBy = [ "initrd.target" ];
services.systemd-networkd-wait-online.requiredBy =
[ "network-online.target" ];
initrdBin = [ pkgs.iproute2 pkgs.iputils pkgs.gnugrep ];
services.check = {
requiredBy = [ "initrd.target" ];
before = [ "initrd.target" ];
after = [ "network-online.target" ];
serviceConfig.Type = "oneshot";
path = [ pkgs.iproute2 pkgs.iputils pkgs.gnugrep ];
script = ''
ip addr | grep 10.0.2.15 || exit 1
ping -c1 10.0.2.2 || exit 1
'';
};
};
};
nodes.machine = common;
testScript = ''
machine.wait_for_unit("multi-user.target")
machine.wait_for_unit("network-online.target")
machine.succeed(
"ip addr | grep 10.0.2.15",
"ping -c1 10.0.2.2",
)
machine.switch_root()
# Make sure the systemd-network user was set correctly in initrd
machine.wait_for_unit("multi-user.target")
machine.succeed("[ $(stat -c '%U,%G' /run/systemd/netif/links) = systemd-network,systemd-network ]")
machine.succeed("ip addr show >&2")
machine.succeed("ip route show >&2")