2019-11-25 20:58:02 +00:00
|
|
|
import ./make-test-python.nix ({ pkgs, lib, ...} :
|
2017-08-23 09:43:07 +00:00
|
|
|
let
|
2019-08-13 21:52:01 +00:00
|
|
|
client_base = {
|
2019-11-25 20:58:02 +00:00
|
|
|
|
2017-08-23 09:43:07 +00:00
|
|
|
containers.test1 = {
|
|
|
|
autoStart = true;
|
|
|
|
config = {
|
2019-08-13 21:52:01 +00:00
|
|
|
environment.etc.check.text = "client_base";
|
2017-08-23 09:43:07 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-08-23 09:00:35 +00:00
|
|
|
# prevent make-test-python.nix to change IP
|
2017-08-23 09:43:07 +00:00
|
|
|
networking.interfaces = {
|
2017-12-03 04:14:54 +00:00
|
|
|
eth1.ipv4.addresses = lib.mkOverride 0 [ ];
|
2017-08-23 09:43:07 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
name = "cotnainers-reloadable";
|
|
|
|
meta = with pkgs.stdenv.lib.maintainers; {
|
|
|
|
maintainers = [ danbst ];
|
|
|
|
};
|
|
|
|
|
|
|
|
nodes = {
|
2018-07-20 20:56:59 +00:00
|
|
|
client = { ... }: {
|
2017-08-23 09:43:07 +00:00
|
|
|
imports = [ client_base ];
|
|
|
|
};
|
|
|
|
|
2018-07-20 20:56:59 +00:00
|
|
|
client_c1 = { lib, ... }: {
|
2017-08-23 09:43:07 +00:00
|
|
|
imports = [ client_base ];
|
|
|
|
|
|
|
|
containers.test1.config = {
|
2019-08-13 21:52:01 +00:00
|
|
|
environment.etc.check.text = lib.mkForce "client_c1";
|
2017-08-23 09:43:07 +00:00
|
|
|
services.httpd.enable = true;
|
|
|
|
services.httpd.adminAddr = "nixos@example.com";
|
|
|
|
};
|
|
|
|
};
|
2018-07-20 20:56:59 +00:00
|
|
|
client_c2 = { lib, ... }: {
|
2017-08-23 09:43:07 +00:00
|
|
|
imports = [ client_base ];
|
|
|
|
|
|
|
|
containers.test1.config = {
|
2019-08-13 21:52:01 +00:00
|
|
|
environment.etc.check.text = lib.mkForce "client_c2";
|
2017-08-23 09:43:07 +00:00
|
|
|
services.nginx.enable = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = {nodes, ...}: let
|
|
|
|
c1System = nodes.client_c1.config.system.build.toplevel;
|
|
|
|
c2System = nodes.client_c2.config.system.build.toplevel;
|
|
|
|
in ''
|
2019-11-25 20:58:02 +00:00
|
|
|
client.start()
|
|
|
|
client.wait_for_unit("default.target")
|
|
|
|
|
|
|
|
assert "client_base" in client.succeed("nixos-container run test1 cat /etc/check")
|
2017-08-23 09:43:07 +00:00
|
|
|
|
2019-11-25 20:58:02 +00:00
|
|
|
with subtest("httpd is available after activating config1"):
|
|
|
|
client.succeed(
|
|
|
|
"${c1System}/bin/switch-to-configuration test >&2",
|
|
|
|
"[[ $(nixos-container run test1 cat /etc/check) == client_c1 ]] >&2",
|
|
|
|
"systemctl status httpd -M test1 >&2",
|
|
|
|
)
|
2017-08-23 09:43:07 +00:00
|
|
|
|
2019-11-25 20:58:02 +00:00
|
|
|
with subtest("httpd is not available any longer after switching to config2"):
|
|
|
|
client.succeed(
|
|
|
|
"${c2System}/bin/switch-to-configuration test >&2",
|
|
|
|
"[[ $(nixos-container run test1 cat /etc/check) == client_c2 ]] >&2",
|
|
|
|
"systemctl status nginx -M test1 >&2",
|
|
|
|
)
|
|
|
|
client.fail("systemctl status httpd -M test1 >&2")
|
2017-08-23 09:43:07 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
})
|