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