2023-09-20 11:58:30 +02:00
|
|
|
{ system ? builtins.currentSystem
|
|
|
|
, config ? {}
|
|
|
|
, pkgs ? import ../.. { inherit system config; }
|
|
|
|
, lib ? pkgs.lib
|
|
|
|
}:
|
2022-06-29 07:01:59 +02:00
|
|
|
|
2023-09-20 11:58:30 +02:00
|
|
|
with import ../lib/testing-python.nix { inherit system pkgs; };
|
|
|
|
|
|
|
|
let
|
|
|
|
inherit (lib.maintainers) elvishjerricco;
|
|
|
|
|
|
|
|
mkFlushTest = flush: script: makeTest {
|
|
|
|
name = "systemd-initrd-network-${lib.optionalString (!flush) "no-"}flush";
|
|
|
|
meta.maintainers = [ elvishjerricco ];
|
|
|
|
|
|
|
|
nodes.machine = {
|
2023-03-06 19:46:17 +01:00
|
|
|
boot.initrd.systemd.enable = true;
|
|
|
|
boot.initrd.network = {
|
|
|
|
enable = true;
|
|
|
|
flushBeforeStage2 = flush;
|
|
|
|
};
|
|
|
|
systemd.services.check-flush = {
|
|
|
|
requiredBy = ["multi-user.target"];
|
|
|
|
before = ["network-pre.target" "multi-user.target"];
|
2023-06-08 06:24:36 +02:00
|
|
|
wants = ["network-pre.target"];
|
2023-03-06 19:46:17 +01:00
|
|
|
unitConfig.DefaultDependencies = false;
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
path = [ pkgs.iproute2 pkgs.iputils pkgs.gnugrep ];
|
|
|
|
inherit script;
|
|
|
|
};
|
|
|
|
};
|
2023-09-20 11:58:30 +02:00
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
in {
|
|
|
|
basic = makeTest {
|
|
|
|
name = "systemd-initrd-network";
|
|
|
|
meta.maintainers = [ elvishjerricco ];
|
|
|
|
|
|
|
|
nodes.machine = {
|
2022-06-29 07:01:59 +02:00
|
|
|
boot.initrd.network.enable = true;
|
|
|
|
|
|
|
|
boot.initrd.systemd = {
|
|
|
|
enable = true;
|
2022-10-17 01:59:41 +02:00
|
|
|
# Enable network-online to fail the test in case of timeout
|
2022-06-29 07:01:59 +02:00
|
|
|
network.wait-online.timeout = 10;
|
2022-10-17 01:59:41 +02:00
|
|
|
network.wait-online.anyInterface = true;
|
2022-06-29 07:01:59 +02:00
|
|
|
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
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-03-06 19:46:17 +01:00
|
|
|
|
2023-09-20 11:58:30 +02:00
|
|
|
testScript = ''
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
# Make sure the systemd-network user was set correctly in initrd
|
|
|
|
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")
|
2023-03-06 19:46:17 +01:00
|
|
|
'';
|
2022-06-29 07:01:59 +02:00
|
|
|
};
|
|
|
|
|
2023-09-20 11:58:30 +02:00
|
|
|
doFlush = mkFlushTest true ''
|
|
|
|
if ip addr | grep 10.0.2.15; then
|
|
|
|
echo "Network configuration survived switch-root; flushBeforeStage2 failed"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
dontFlush = mkFlushTest false ''
|
|
|
|
if ! (ip addr | grep 10.0.2.15); then
|
|
|
|
echo "Network configuration didn't survive switch-root"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-06-29 07:01:59 +02:00
|
|
|
'';
|
2023-09-20 11:58:30 +02:00
|
|
|
}
|