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