summaryrefslogtreecommitdiffstats
path: root/nixos/tests/glance.nix
blob: 9a92f0c458ea4f26017bc8daa6ecb41c52472831 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
{ config, lib, ... }:

{
  name = "glance";

  nodes = {
    machine_default =
      { ... }:
      {
        services.glance = {
          enable = true;
        };
      };

    machine_configured =
      { pkgs, ... }:
      let
        # Do not use this in production. This will make the secret world-readable
        # in the Nix store
        secrets.glance-location.path = toString (pkgs.writeText "location-secret" "Nivelles, Belgium");
      in
      {
        services.glance = {
          enable = true;
          settings = {
            server.port = 5678;
            pages = [
              {
                name = "Home";
                columns = [
                  {
                    size = "full";
                    widgets = [
                      { type = "calendar"; }
                      {
                        type = "weather";
                        location = {
                          _secret = secrets.glance-location.path;
                        };
                      }
                    ];
                  }
                ];
              }
            ];
          };
        };
      };
  };

  extraPythonPackages =
    p: with p; [
      beautifulsoup4
      pyyaml
      types-pyyaml
      types-beautifulsoup4
    ];

  testScript = ''
    from bs4 import BeautifulSoup
    import yaml

    machine_default.start()
    machine_default.wait_for_unit("glance.service")
    machine_default.wait_for_open_port(8080)

    machine_configured.start()
    machine_configured.wait_for_unit("glance.service")
    machine_configured.wait_for_open_port(5678)

    soup = BeautifulSoup(machine_default.succeed("curl http://localhost:8080"))
    expected_version = "v${config.nodes.machine_default.services.glance.package.version}"
    assert any(a.text == expected_version for a in soup.select(".footer a"))

    yaml_contents = machine_configured.succeed("cat /run/glance/glance.yaml")
    yaml_parsed = yaml.load(yaml_contents, Loader=yaml.FullLoader)
    location = yaml_parsed["pages"][0]["columns"][0]["widgets"][1]["location"]
    assert location == "Nivelles, Belgium"
  '';

  meta.maintainers = [ ];
}