1import ./make-test-python.nix (
2 { lib, ... }:
3 {
4 name = "systemd-initrd-vlan";
5 meta.maintainers = [ lib.maintainers.majiir ];
6
7 # Tests VLAN interface configuration in systemd-initrd.
8 #
9 # Two nodes are configured for a tagged VLAN. (Note that they also still have
10 # their ordinary eth0 and eth1 interfaces, which are not VLAN-tagged.)
11 #
12 # The 'server' node waits forever in initrd (stage 1) with networking
13 # enabled. The 'client' node pings it to test network connectivity.
14
15 nodes =
16 let
17 network = id: {
18 networking = {
19 vlans."eth1.10" = {
20 id = 10;
21 interface = "eth1";
22 };
23 interfaces."eth1.10" = {
24 ipv4.addresses = [
25 {
26 address = "192.168.10.${id}";
27 prefixLength = 24;
28 }
29 ];
30 };
31 };
32 };
33 in
34 {
35 # Node that will use initrd networking.
36 server = network "1" // {
37 boot.initrd.systemd.enable = true;
38 boot.initrd.network.enable = true;
39 boot.initrd.systemd.services.boot-blocker = {
40 before = [ "initrd.target" ];
41 wantedBy = [ "initrd.target" ];
42 script = "sleep infinity";
43 serviceConfig.Type = "oneshot";
44 };
45 };
46
47 # Node that will ping the server.
48 client = network "2";
49 };
50
51 testScript = ''
52 start_all()
53 client.wait_for_unit("network.target")
54
55 # Wait for the regular (untagged) interface to be up.
56 def server_is_up(_) -> bool:
57 status, _ = client.execute("ping -n -c 1 server >&2")
58 return status == 0
59 with client.nested("waiting for server to come up"):
60 retry(server_is_up)
61
62 # Try to ping the (tagged) VLAN interface.
63 client.succeed("ping -n -w 10 -c 1 192.168.10.1 >&2")
64 '';
65 }
66)