summaryrefslogtreecommitdiffstats
path: root/nixos/tests/containers-reloadable.nix
blob: 4e21151978874274622cf17dd3d8a742686e50cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{ pkgs, lib, ... }:
{
  name = "containers-reloadable";
  meta = {
    maintainers = [ ];
  };

  nodes = {
    machine =
      { lib, ... }:
      {
        containers.test1 = {
          autoStart = true;
          config.environment.etc.check.text = "client_base";
          config.nix.enable = false; # disabled by default on the test's host. See all-tests.nix / tag(no-nix-by-default)
        };

        # prevent make-test-python.nix to change IP
        networking.interfaces.eth1.ipv4.addresses = lib.mkOverride 0 [ ];

        specialisation.c1.configuration = {
          containers.test1.config = {
            environment.etc.check.text = lib.mkForce "client_c1";
            services.httpd.enable = true;
            services.httpd.adminAddr = "nixos@example.com";
            nix.enable = false; # disabled by default on the test's host. See all-tests.nix / tag(no-nix-by-default)
          };
        };

        specialisation.c2.configuration = {
          containers.test1.config = {
            environment.etc.check.text = lib.mkForce "client_c2";
            services.nginx.enable = true;
            nix.enable = false; # disabled by default on the test's host. See all-tests.nix / tag(no-nix-by-default)
          };
        };
      };
  };

  testScript = ''
    machine.start()
    machine.wait_for_unit("default.target")

    assert "client_base" in machine.succeed("nixos-container run test1 cat /etc/check")

    with subtest("httpd is available after activating config1"):
        machine.succeed(
            "/run/booted-system/specialisation/c1/bin/switch-to-configuration test >&2",
            "[[ $(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"):
        machine.succeed(
            "/run/booted-system/specialisation/c2/bin/switch-to-configuration test >&2",
            "[[ $(nixos-container run test1 cat /etc/check) == client_c2 ]] >&2",
            "systemctl status nginx -M test1 >&2",
        )
        machine.fail("systemctl status httpd -M test1 >&2")
  '';

}