1import ./make-test-python.nix ({ pkgs, lib, ... }: {
2 name = "containers-extra_veth";
3 meta = {
4 maintainers = with lib.maintainers; [ kampfschlaefer ];
5 };
6
7 nodes.machine =
8 { pkgs, ... }:
9 { imports = [ ../modules/installer/cd-dvd/channel.nix ];
10 virtualisation.writableStore = true;
11 virtualisation.vlans = [];
12
13 networking.useDHCP = false;
14 networking.bridges = {
15 br0 = {
16 interfaces = [];
17 };
18 br1 = { interfaces = []; };
19 };
20 networking.interfaces = {
21 br0 = {
22 ipv4.addresses = [{ address = "192.168.0.1"; prefixLength = 24; }];
23 ipv6.addresses = [{ address = "fc00::1"; prefixLength = 7; }];
24 };
25 br1 = {
26 ipv4.addresses = [{ address = "192.168.1.1"; prefixLength = 24; }];
27 };
28 };
29
30 containers.webserver =
31 {
32 autoStart = true;
33 privateNetwork = true;
34 hostBridge = "br0";
35 localAddress = "192.168.0.100/24";
36 localAddress6 = "fc00::2/7";
37 extraVeths = {
38 veth1 = { hostBridge = "br1"; localAddress = "192.168.1.100/24"; };
39 veth2 = { hostAddress = "192.168.2.1"; localAddress = "192.168.2.100"; };
40 };
41 config =
42 {
43 networking.firewall.allowedTCPPorts = [ 80 ];
44 };
45 };
46
47 virtualisation.additionalPaths = [ pkgs.stdenv ];
48 };
49
50 testScript =
51 ''
52 machine.wait_for_unit("default.target")
53 assert "webserver" in machine.succeed("nixos-container list")
54
55 with subtest("Status of the webserver container is up"):
56 assert "up" in machine.succeed("nixos-container status webserver")
57
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"
61 )
62 assert "state UP" in machine.succeed(
63 "nixos-container run webserver -- ip link show veth2"
64 )
65
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")
69
70 with subtest("Ensure the veth1 is part of br1 on the host"):
71 assert "master br1" in machine.succeed("ip link show veth1")
72
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")
76
77 with subtest("Ping on the first extra veth"):
78 machine.succeed("ping -n -c 1 192.168.1.100 >&2")
79
80 with subtest("Ping on the second extra veth"):
81 machine.succeed("ping -n -c 1 192.168.2.100 >&2")
82
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")
87
88 with subtest("Destroying a declarative container should fail"):
89 machine.fail("nixos-container destroy webserver")
90 '';
91})