1 import ./make-test-python.nix ({ pkgs, lib, ... }:
3 name = "containers-restart_networking";
5 maintainers = with lib.maintainers; [ kampfschlaefer ];
10 virtualisation.vlans = [ 1 ];
12 networking.firewall.enable = false;
14 containers.webserver = {
16 privateNetwork = true;
19 networking.firewall.enable = false;
20 networking.interfaces.eth0.ipv4.addresses = [
21 { address = "192.168.1.122"; prefixLength = 24; }
26 networking.bridges.br0 = {
31 networking.interfaces.br0.ipv4.addresses = [ { address = "192.168.1.1"; prefixLength = 24; } ];
33 specialisation.eth1.configuration = {
34 networking.bridges.br0.interfaces = [ "eth1" ];
35 networking.interfaces = {
36 eth1.ipv4.addresses = lib.mkForce [ ];
37 eth1.ipv6.addresses = lib.mkForce [ ];
38 br0.ipv4.addresses = [ { address = "192.168.1.2"; prefixLength = 24; } ];
42 specialisation.eth1-rstp.configuration = {
43 networking.bridges.br0 = {
44 interfaces = [ "eth1" ];
45 rstp = lib.mkForce true;
48 networking.interfaces = {
49 eth1.ipv4.addresses = lib.mkForce [ ];
50 eth1.ipv6.addresses = lib.mkForce [ ];
51 br0.ipv4.addresses = [ { address = "192.168.1.2"; prefixLength = 24; } ];
60 client.wait_for_unit("default.target")
62 with subtest("Initial configuration connectivity check"):
63 client.succeed("ping 192.168.1.122 -c 1 -n >&2")
64 client.succeed("nixos-container run webserver -- ping -c 1 -n 192.168.1.1 >&2")
66 client.fail("ip l show eth1 |grep 'master br0' >&2")
67 client.fail("grep eth1 /run/br0.interfaces >&2")
69 with subtest("Bridged configuration without STP preserves connectivity"):
71 "/run/booted-system/specialisation/eth1/bin/switch-to-configuration test >&2"
75 "ping 192.168.1.122 -c 1 -n >&2",
76 "nixos-container run webserver -- ping -c 1 -n 192.168.1.2 >&2",
77 "ip l show eth1 |grep 'master br0' >&2",
78 "grep eth1 /run/br0.interfaces >&2",
81 # activating rstp needs another service, therefore the bridge will restart and the container will lose its connectivity
82 # with subtest("Bridged configuration with STP"):
83 # client.succeed("/run/booted-system/specialisation/eth1-rstp/bin/switch-to-configuration test >&2")
84 # client.execute("ip -4 a >&2")
85 # client.execute("ip l >&2")
88 # "ping 192.168.1.122 -c 1 -n >&2",
89 # "nixos-container run webserver -- ping -c 1 -n 192.168.1.2 >&2",
90 # "ip l show eth1 |grep 'master br0' >&2",
91 # "grep eth1 /run/br0.interfaces >&2",
94 with subtest("Reverting to initial configuration preserves connectivity"):
96 "/run/booted-system/bin/switch-to-configuration test >&2"
99 client.succeed("ping 192.168.1.122 -c 1 -n >&2")
100 client.succeed("nixos-container run webserver -- ping -c 1 -n 192.168.1.1 >&2")
102 client.fail("ip l show eth1 |grep 'master br0' >&2")
103 client.fail("grep eth1 /run/br0.interfaces >&2")