1import ./make-test-python.nix ({ pkgs, lib, ... }: {
2 name = "containers-hosts";
3 meta = {
4 maintainers = with lib.maintainers; [ montag451 ];
5 };
6
7 nodes.machine =
8 { lib, ... }:
9 {
10 virtualisation.vlans = [];
11
12 networking.bridges.br0.interfaces = [];
13 networking.interfaces.br0.ipv4.addresses = [
14 { address = "10.11.0.254"; prefixLength = 24; }
15 ];
16
17 # Force /etc/hosts to be the only source for host name resolution
18 environment.etc."nsswitch.conf".text = lib.mkForce ''
19 hosts: files
20 '';
21
22 containers.simple = {
23 autoStart = true;
24 privateNetwork = true;
25 localAddress = "10.10.0.1";
26 hostAddress = "10.10.0.254";
27
28 config = {};
29 };
30
31 containers.netmask = {
32 autoStart = true;
33 privateNetwork = true;
34 hostBridge = "br0";
35 localAddress = "10.11.0.1/24";
36
37 config = {};
38 };
39 };
40
41 testScript = ''
42 start_all()
43 machine.wait_for_unit("default.target")
44
45 with subtest("Ping the containers using the entries added in /etc/hosts"):
46 for host in "simple.containers", "netmask.containers":
47 machine.succeed(f"ping -n -c 1 {host}")
48 '';
49})