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