2021-02-26 15:03:49 +00:00
|
|
|
import ./make-test-python.nix (
|
|
|
|
{ pkgs, lib, ... }:
|
2017-12-03 04:14:54 +00:00
|
|
|
{
|
2016-12-06 22:32:17 +00:00
|
|
|
name = "containers-hosts";
|
|
|
|
meta = {
|
|
|
|
maintainers = with lib.maintainers; [ montag451 ];
|
|
|
|
};
|
|
|
|
|
2022-03-20 23:15:30 +00:00
|
|
|
nodes.machine =
|
2018-07-20 20:56:59 +00:00
|
|
|
{ lib, ... }:
|
2024-12-10 19:26:33 +00:00
|
|
|
{
|
2016-12-06 22:32:17 +00:00
|
|
|
virtualisation.vlans = [ ];
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2016-12-06 22:32:17 +00:00
|
|
|
networking.bridges.br0.interfaces = [ ];
|
2017-12-03 04:14:54 +00:00
|
|
|
networking.interfaces.br0.ipv4.addresses = [
|
2024-12-10 19:26:33 +00:00
|
|
|
{
|
2017-12-03 04:14:54 +00:00
|
|
|
address = "10.11.0.254";
|
|
|
|
prefixLength = 24;
|
2024-12-10 19:26:33 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2016-12-06 22:32:17 +00:00
|
|
|
# Force /etc/hosts to be the only source for host name resolution
|
|
|
|
environment.etc."nsswitch.conf".text = lib.mkForce ''
|
|
|
|
hosts: files
|
2024-12-10 19:26:33 +00:00
|
|
|
'';
|
|
|
|
|
2019-11-25 20:57:46 +00:00
|
|
|
containers.simple = {
|
2016-12-06 22:32:17 +00:00
|
|
|
autoStart = true;
|
|
|
|
privateNetwork = true;
|
|
|
|
localAddress = "10.10.0.1";
|
|
|
|
hostAddress = "10.10.0.254";
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2016-12-06 22:32:17 +00:00
|
|
|
config = { };
|
2024-12-10 19:26:33 +00:00
|
|
|
};
|
|
|
|
|
2019-11-25 20:57:46 +00:00
|
|
|
containers.netmask = {
|
2016-12-06 22:32:17 +00:00
|
|
|
autoStart = true;
|
|
|
|
privateNetwork = true;
|
|
|
|
hostBridge = "br0";
|
|
|
|
localAddress = "10.11.0.1/24";
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2016-12-06 22:32:17 +00:00
|
|
|
config = { };
|
2024-12-10 19:26:33 +00:00
|
|
|
};
|
2016-12-06 22:32:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
2019-11-25 20:57:46 +00:00
|
|
|
start_all()
|
|
|
|
machine.wait_for_unit("default.target")
|
2016-12-06 22:32:17 +00:00
|
|
|
|
2019-11-25 20:57:46 +00:00
|
|
|
with subtest("Ping the containers using the entries added in /etc/hosts"):
|
|
|
|
for host in "simple.containers", "netmask.containers":
|
|
|
|
machine.succeed(f"ping -n -c 1 {host}")
|
2016-12-06 22:32:17 +00:00
|
|
|
'';
|
|
|
|
}
|
|
|
|
)
|