at 23.11-pre 3.7 kB view raw
1let 2 client_base = { 3 networking.firewall.enable = false; 4 5 containers.webserver = { 6 autoStart = true; 7 privateNetwork = true; 8 hostBridge = "br0"; 9 config = { 10 networking.firewall.enable = false; 11 networking.interfaces.eth0.ipv4.addresses = [ 12 { address = "192.168.1.122"; prefixLength = 24; } 13 ]; 14 }; 15 }; 16 }; 17in import ./make-test-python.nix ({ pkgs, lib, ... }: 18{ 19 name = "containers-restart_networking"; 20 meta = { 21 maintainers = with lib.maintainers; [ kampfschlaefer ]; 22 }; 23 24 nodes = { 25 client = { lib, ... }: client_base // { 26 virtualisation.vlans = [ 1 ]; 27 28 networking.bridges.br0 = { 29 interfaces = []; 30 rstp = false; 31 }; 32 networking.interfaces = { 33 eth1.ipv4.addresses = lib.mkOverride 0 [ ]; 34 br0.ipv4.addresses = [ { address = "192.168.1.1"; prefixLength = 24; } ]; 35 }; 36 37 }; 38 client_eth1 = { lib, ... }: client_base // { 39 networking.bridges.br0 = { 40 interfaces = [ "eth1" ]; 41 rstp = false; 42 }; 43 networking.interfaces = { 44 eth1.ipv4.addresses = lib.mkOverride 0 [ ]; 45 br0.ipv4.addresses = [ { address = "192.168.1.2"; prefixLength = 24; } ]; 46 }; 47 }; 48 client_eth1_rstp = { lib, ... }: client_base // { 49 networking.bridges.br0 = { 50 interfaces = [ "eth1" ]; 51 rstp = true; 52 }; 53 networking.interfaces = { 54 eth1.ipv4.addresses = lib.mkOverride 0 [ ]; 55 br0.ipv4.addresses = [ { address = "192.168.1.2"; prefixLength = 24; } ]; 56 }; 57 }; 58 }; 59 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; 64 in '' 65 client.start() 66 67 client.wait_for_unit("default.target") 68 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") 72 73 client.fail("ip l show eth1 |grep 'master br0' >&2") 74 client.fail("grep eth1 /run/br0.interfaces >&2") 75 76 with subtest("Bridged configuration without STP preserves connectivity"): 77 client.succeed( 78 "${eth1_bridged}/bin/switch-to-configuration test >&2" 79 ) 80 81 client.succeed( 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", 86 ) 87 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") 93 # 94 # client.succeed( 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", 99 # ) 100 101 with subtest("Reverting to initial configuration preserves connectivity"): 102 client.succeed( 103 "${originalSystem}/bin/switch-to-configuration test >&2" 104 ) 105 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") 108 109 client.fail("ip l show eth1 |grep 'master br0' >&2") 110 client.fail("grep eth1 /run/br0.interfaces >&2") 111 ''; 112 113})