1import ./make-test-python.nix (
2 { lib, ... }:
3 {
4 name = "systemd-initrd-bridge";
5 meta.maintainers = [ lib.maintainers.majiir ];
6
7 # Tests bridge interface configuration in systemd-initrd.
8 #
9 # The 'a' and 'b' nodes are connected to a 'bridge' node through different
10 # links. The 'bridge' node configures a bridge across them. It waits forever
11 # in initrd (stage 1) with networking enabled. 'a' and 'b' ping 'bridge' to
12 # test connectivity with the bridge interface. Then, 'a' pings 'b' to test
13 # the bridge itself.
14
15 nodes = {
16 bridge =
17 { config, lib, ... }:
18 {
19 boot.initrd.systemd.enable = true;
20 boot.initrd.network.enable = true;
21 boot.initrd.systemd.services.boot-blocker = {
22 before = [ "initrd.target" ];
23 wantedBy = [ "initrd.target" ];
24 script = "sleep infinity";
25 serviceConfig.Type = "oneshot";
26 };
27
28 networking.primaryIPAddress = "192.168.1.${toString config.virtualisation.test.nodeNumber}";
29
30 virtualisation.vlans = [
31 1
32 2
33 ];
34 networking.bridges.br0.interfaces = [
35 "eth1"
36 "eth2"
37 ];
38
39 networking.interfaces = {
40 eth1.ipv4.addresses = lib.mkForce [ ];
41 eth2.ipv4.addresses = lib.mkForce [ ];
42 br0.ipv4.addresses = [
43 {
44 address = config.networking.primaryIPAddress;
45 prefixLength = 24;
46 }
47 ];
48 };
49 };
50
51 a = {
52 virtualisation.vlans = [ 1 ];
53 };
54
55 b =
56 { config, ... }:
57 {
58 virtualisation.vlans = [ 2 ];
59 networking.primaryIPAddress = lib.mkForce "192.168.1.${toString config.virtualisation.test.nodeNumber}";
60 networking.interfaces.eth1.ipv4.addresses = lib.mkForce [
61 {
62 address = config.networking.primaryIPAddress;
63 prefixLength = 24;
64 }
65 ];
66 };
67 };
68
69 testScript = ''
70 start_all()
71 a.wait_for_unit("network.target")
72 b.wait_for_unit("network.target")
73
74 a.succeed("ping -n -w 10 -c 1 bridge >&2")
75 b.succeed("ping -n -w 10 -c 1 bridge >&2")
76
77 a.succeed("ping -n -w 10 -c 1 b >&2")
78 '';
79 }
80)