summary refs log tree commit diff
path: root/nixos/tests/zrepl.nix
blob: 0ed73fea34b0d607ba0317c569b945c3faaa777c (plain) (blame)
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
import ./make-test-python.nix (
  {
    name = "zrepl";

    nodes.host = {config, pkgs, ...}: {
      config = {
        # Prerequisites for ZFS and tests.
        boot.supportedFilesystems = [ "zfs" ];
        environment.systemPackages = [ pkgs.zrepl ];
        networking.hostId = "deadbeef";
        services.zrepl = {
          enable = true;
          settings = {
            # Enable Prometheus output for status assertions.
            global.monitoring = [{
              type = "prometheus";
              listen = ":9811";
            }];
            # Create a periodic snapshot job for an ephemeral zpool.
            jobs = [{
              name = "snap_test";
              type = "snap";

              filesystems."test" = true;
              snapshotting = {
                type = "periodic";
                prefix = "zrepl_";
                interval = "1s";
              };

              pruning.keep = [{
                type = "last_n";
                count = 8;
              }];
            }];
          };
        };
      };
    };

    testScript = ''
      start_all()

      with subtest("Wait for zrepl and network ready"):
          host.wait_for_unit("network-online.target")
          host.wait_for_unit("zrepl.service")

      with subtest("Create test zpool"):
          # ZFS requires 64MiB minimum pool size.
          host.succeed("fallocate -l 64MiB /root/zpool.img")
          host.succeed("zpool create test /root/zpool.img")

      with subtest("Check for completed zrepl snapshot"):
          # zrepl periodic snapshot job creates a snapshot with this prefix.
          host.wait_until_succeeds("zfs list -t snapshot | grep -q zrepl_")

      with subtest("Verify HTTP monitoring server is configured"):
          out = host.succeed("curl -f localhost:9811/metrics")

          assert (
              "zrepl_version_daemon" in out
          ), "zrepl version metric was not found in Prometheus output"

          assert (
              "zrepl_zfs_snapshot_duration_count{filesystem=\"test\"}" in out
          ), "zrepl snapshot counter for test was not found in Prometheus output"
    '';
  })