2021-03-09 03:18:52 +00:00
|
|
|
import ./make-test-python.nix ({ pkgs, lib, ... }:
|
2024-09-19 14:19:46 +00:00
|
|
|
{
|
2020-09-25 04:45:31 +00:00
|
|
|
name = "containers-reloadable";
|
2021-03-09 03:18:52 +00:00
|
|
|
meta = {
|
|
|
|
maintainers = with lib.maintainers; [ danbst ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nodes = {
|
2024-09-19 14:19:46 +00:00
|
|
|
machine = { lib, ... }: {
|
|
|
|
containers.test1 = {
|
|
|
|
autoStart = true;
|
|
|
|
config.environment.etc.check.text = "client_base";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
# prevent make-test-python.nix to change IP
|
|
|
|
networking.interfaces.eth1.ipv4.addresses = lib.mkOverride 0 [ ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
specialisation.c1.configuration = {
|
|
|
|
containers.test1.config = {
|
|
|
|
environment.etc.check.text = lib.mkForce "client_c1";
|
|
|
|
services.httpd.enable = true;
|
|
|
|
services.httpd.adminAddr = "nixos@example.com";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
specialisation.c2.configuration = {
|
|
|
|
containers.test1.config = {
|
|
|
|
environment.etc.check.text = lib.mkForce "client_c2";
|
|
|
|
services.nginx.enable = true;
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
testScript = ''
|
|
|
|
machine.start()
|
|
|
|
machine.wait_for_unit("default.target")
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
assert "client_base" in machine.succeed("nixos-container run test1 cat /etc/check")
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
with subtest("httpd is available after activating config1"):
|
2024-09-19 14:19:46 +00:00
|
|
|
machine.succeed(
|
|
|
|
"/run/booted-system/specialisation/c1/bin/switch-to-configuration test >&2",
|
2020-04-24 23:36:52 +00:00
|
|
|
"[[ $(nixos-container run test1 cat /etc/check) == client_c1 ]] >&2",
|
|
|
|
"systemctl status httpd -M test1 >&2",
|
|
|
|
)
|
|
|
|
|
|
|
|
with subtest("httpd is not available any longer after switching to config2"):
|
2024-09-19 14:19:46 +00:00
|
|
|
machine.succeed(
|
|
|
|
"/run/booted-system/specialisation/c2/bin/switch-to-configuration test >&2",
|
2020-04-24 23:36:52 +00:00
|
|
|
"[[ $(nixos-container run test1 cat /etc/check) == client_c2 ]] >&2",
|
|
|
|
"systemctl status nginx -M test1 >&2",
|
|
|
|
)
|
2024-09-19 14:19:46 +00:00
|
|
|
machine.fail("systemctl status httpd -M test1 >&2")
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
})
|