1 import ./make-test-python.nix ({ pkgs, lib, ... }: {
2 name = "containers-extra_veth";
4 maintainers = with lib.maintainers; [ kampfschlaefer ];
9 { imports = [ ../modules/installer/cd-dvd/channel.nix ];
10 virtualisation.writableStore = true;
11 virtualisation.vlans = [];
13 networking.useDHCP = false;
14 networking.bridges = {
18 br1 = { interfaces = []; };
20 networking.interfaces = {
22 ipv4.addresses = [{ address = "192.168.0.1"; prefixLength = 24; }];
23 ipv6.addresses = [{ address = "fc00::1"; prefixLength = 7; }];
26 ipv4.addresses = [{ address = "192.168.1.1"; prefixLength = 24; }];
30 containers.webserver =
33 privateNetwork = true;
35 localAddress = "192.168.0.100/24";
36 localAddress6 = "fc00::2/7";
38 veth1 = { hostBridge = "br1"; localAddress = "192.168.1.100/24"; };
39 veth2 = { hostAddress = "192.168.2.1"; localAddress = "192.168.2.100"; };
43 networking.firewall.allowedTCPPorts = [ 80 ];
47 virtualisation.additionalPaths = [ pkgs.stdenv ];
52 machine.wait_for_unit("default.target")
53 assert "webserver" in machine.succeed("nixos-container list")
55 with subtest("Status of the webserver container is up"):
56 assert "up" in machine.succeed("nixos-container status webserver")
58 with subtest("Ensure that the veths are inside the container"):
59 assert "state UP" in machine.succeed(
60 "nixos-container run webserver -- ip link show veth1"
62 assert "state UP" in machine.succeed(
63 "nixos-container run webserver -- ip link show veth2"
66 with subtest("Ensure the presence of the extra veths"):
67 assert "state UP" in machine.succeed("ip link show veth1")
68 assert "state UP" in machine.succeed("ip link show veth2")
70 with subtest("Ensure the veth1 is part of br1 on the host"):
71 assert "master br1" in machine.succeed("ip link show veth1")
73 with subtest("Ping on main veth"):
74 machine.succeed("ping -n -c 1 192.168.0.100")
75 machine.succeed("ping -n -c 1 fc00::2")
77 with subtest("Ping on the first extra veth"):
78 machine.succeed("ping -n -c 1 192.168.1.100 >&2")
80 with subtest("Ping on the second extra veth"):
81 machine.succeed("ping -n -c 1 192.168.2.100 >&2")
83 with subtest("Container can be stopped"):
84 machine.succeed("nixos-container stop webserver")
85 machine.fail("ping -n -c 1 192.168.1.100 >&2")
86 machine.fail("ping -n -c 1 192.168.2.100 >&2")
88 with subtest("Destroying a declarative container should fail"):
89 machine.fail("nixos-container destroy webserver")