3 networking.firewall.enable = false;
5 containers.webserver = {
10 networking.firewall.enable = false;
11 networking.interfaces.eth0.ipv4.addresses = [
12 { address = "192.168.1.122"; prefixLength = 24; }
17 in import ./make-test-python.nix ({ pkgs, lib, ... }:
19 name = "containers-restart_networking";
21 maintainers = with lib.maintainers; [ kampfschlaefer ];
25 client = { lib, ... }: client_base // {
26 virtualisation.vlans = [ 1 ];
28 networking.bridges.br0 = {
32 networking.interfaces = {
33 eth1.ipv4.addresses = lib.mkOverride 0 [ ];
34 br0.ipv4.addresses = [ { address = "192.168.1.1"; prefixLength = 24; } ];
38 client_eth1 = { lib, ... }: client_base // {
39 networking.bridges.br0 = {
40 interfaces = [ "eth1" ];
43 networking.interfaces = {
44 eth1.ipv4.addresses = lib.mkOverride 0 [ ];
45 br0.ipv4.addresses = [ { address = "192.168.1.2"; prefixLength = 24; } ];
48 client_eth1_rstp = { lib, ... }: client_base // {
49 networking.bridges.br0 = {
50 interfaces = [ "eth1" ];
53 networking.interfaces = {
54 eth1.ipv4.addresses = lib.mkOverride 0 [ ];
55 br0.ipv4.addresses = [ { address = "192.168.1.2"; prefixLength = 24; } ];
60 testScript = {nodes, ...}: let
61 originalSystem = nodes.client.config.system.build.toplevel;
62 eth1_bridged = nodes.client_eth1.config.system.build.toplevel;
63 eth1_rstp = nodes.client_eth1_rstp.config.system.build.toplevel;
67 client.wait_for_unit("default.target")
69 with subtest("Initial configuration connectivity check"):
70 client.succeed("ping 192.168.1.122 -c 1 -n >&2")
71 client.succeed("nixos-container run webserver -- ping -c 1 -n 192.168.1.1 >&2")
73 client.fail("ip l show eth1 |grep 'master br0' >&2")
74 client.fail("grep eth1 /run/br0.interfaces >&2")
76 with subtest("Bridged configuration without STP preserves connectivity"):
78 "${eth1_bridged}/bin/switch-to-configuration test >&2"
82 "ping 192.168.1.122 -c 1 -n >&2",
83 "nixos-container run webserver -- ping -c 1 -n 192.168.1.2 >&2",
84 "ip l show eth1 |grep 'master br0' >&2",
85 "grep eth1 /run/br0.interfaces >&2",
88 # activating rstp needs another service, therefore the bridge will restart and the container will lose its connectivity
89 # with subtest("Bridged configuration with STP"):
90 # client.succeed("${eth1_rstp}/bin/switch-to-configuration test >&2")
91 # client.execute("ip -4 a >&2")
92 # client.execute("ip l >&2")
95 # "ping 192.168.1.122 -c 1 -n >&2",
96 # "nixos-container run webserver -- ping -c 1 -n 192.168.1.2 >&2",
97 # "ip l show eth1 |grep 'master br0' >&2",
98 # "grep eth1 /run/br0.interfaces >&2",
101 with subtest("Reverting to initial configuration preserves connectivity"):
103 "${originalSystem}/bin/switch-to-configuration test >&2"
106 client.succeed("ping 192.168.1.122 -c 1 -n >&2")
107 client.succeed("nixos-container run webserver -- ping -c 1 -n 192.168.1.1 >&2")
109 client.fail("ip l show eth1 |grep 'master br0' >&2")
110 client.fail("grep eth1 /run/br0.interfaces >&2")