Merge pull request #305845 from abathur/resholve_0.10.5
[NixPkgs.git] / nixos / tests / containers-physical_interfaces.nix
blobe203f88786a3ec73fdd08adaf51b9f3dce56dcac
1 import ./make-test-python.nix ({ pkgs, lib, ... }: {
2   name = "containers-physical_interfaces";
3   meta = {
4     maintainers = with lib.maintainers; [ kampfschlaefer ];
5   };
7   nodes = {
8     server = { ... }:
9       {
10         virtualisation.vlans = [ 1 ];
12         containers.server = {
13           privateNetwork = true;
14           interfaces = [ "eth1" ];
16           config = {
17             networking.interfaces.eth1.ipv4.addresses = [
18               { address = "10.10.0.1"; prefixLength = 24; }
19             ];
20             networking.firewall.enable = false;
21           };
22         };
23       };
24     bridged = { ... }: {
25       virtualisation.vlans = [ 1 ];
27       containers.bridged = {
28         privateNetwork = true;
29         interfaces = [ "eth1" ];
31         config = {
32           networking.bridges.br0.interfaces = [ "eth1" ];
33           networking.interfaces.br0.ipv4.addresses = [
34             { address = "10.10.0.2"; prefixLength = 24; }
35           ];
36           networking.firewall.enable = false;
37         };
38       };
39     };
41     bonded = { ... }: {
42       virtualisation.vlans = [ 1 ];
44       containers.bonded = {
45         privateNetwork = true;
46         interfaces = [ "eth1" ];
48         config = {
49           networking.bonds.bond0 = {
50             interfaces = [ "eth1" ];
51             driverOptions.mode = "active-backup";
52           };
53           networking.interfaces.bond0.ipv4.addresses = [
54             { address = "10.10.0.3"; prefixLength = 24; }
55           ];
56           networking.firewall.enable = false;
57         };
58       };
59     };
61     bridgedbond = { ... }: {
62       virtualisation.vlans = [ 1 ];
64       containers.bridgedbond = {
65         privateNetwork = true;
66         interfaces = [ "eth1" ];
68         config = {
69           networking.bonds.bond0 = {
70             interfaces = [ "eth1" ];
71             driverOptions.mode = "active-backup";
72           };
73           networking.bridges.br0.interfaces = [ "bond0" ];
74           networking.interfaces.br0.ipv4.addresses = [
75             { address = "10.10.0.4"; prefixLength = 24; }
76           ];
77           networking.firewall.enable = false;
78         };
79       };
80     };
81   };
83   testScript = ''
84     start_all()
86     with subtest("Prepare server"):
87         server.wait_for_unit("default.target")
88         server.succeed("ip link show dev eth1 >&2")
90     with subtest("Simple physical interface is up"):
91         server.succeed("nixos-container start server")
92         server.wait_for_unit("container@server")
93         server.succeed(
94             "systemctl -M server list-dependencies network-addresses-eth1.service >&2"
95         )
97         # The other tests will ping this container on its ip. Here we just check
98         # that the device is present in the container.
99         server.succeed("nixos-container run server -- ip a show dev eth1 >&2")
101     with subtest("Physical device in bridge in container can ping server"):
102         bridged.wait_for_unit("default.target")
103         bridged.succeed("nixos-container start bridged")
104         bridged.wait_for_unit("container@bridged")
105         bridged.succeed(
106             "systemctl -M bridged list-dependencies network-addresses-br0.service >&2",
107             "systemctl -M bridged status -n 30 -l network-addresses-br0.service",
108             "nixos-container run bridged -- ping -w 10 -c 1 -n 10.10.0.1",
109         )
111     with subtest("Physical device in bond in container can ping server"):
112         bonded.wait_for_unit("default.target")
113         bonded.succeed("nixos-container start bonded")
114         bonded.wait_for_unit("container@bonded")
115         bonded.succeed(
116             "systemctl -M bonded list-dependencies network-addresses-bond0 >&2",
117             "systemctl -M bonded status -n 30 -l network-addresses-bond0 >&2",
118             "nixos-container run bonded -- ping -w 10 -c 1 -n 10.10.0.1",
119         )
121     with subtest("Physical device in bond in bridge in container can ping server"):
122         bridgedbond.wait_for_unit("default.target")
123         bridgedbond.succeed("nixos-container start bridgedbond")
124         bridgedbond.wait_for_unit("container@bridgedbond")
125         bridgedbond.succeed(
126             "systemctl -M bridgedbond list-dependencies network-addresses-br0.service >&2",
127             "systemctl -M bridgedbond status -n 30 -l network-addresses-br0.service",
128             "nixos-container run bridgedbond -- ping -w 10 -c 1 -n 10.10.0.1",
129         )
130   '';