1import ./make-test-python.nix (
2 {
3 name = "zrepl";
4
5 nodes.host = {config, pkgs, ...}: {
6 config = {
7 # Prerequisites for ZFS and tests.
8 boot.supportedFilesystems = [ "zfs" ];
9 environment.systemPackages = [ pkgs.zrepl ];
10 networking.hostId = "deadbeef";
11 services.zrepl = {
12 enable = true;
13 settings = {
14 # Enable Prometheus output for status assertions.
15 global.monitoring = [{
16 type = "prometheus";
17 listen = ":9811";
18 }];
19 # Create a periodic snapshot job for an ephemeral zpool.
20 jobs = [{
21 name = "snap_test";
22 type = "snap";
23
24 filesystems."test" = true;
25 snapshotting = {
26 type = "periodic";
27 prefix = "zrepl_";
28 interval = "1s";
29 };
30
31 pruning.keep = [{
32 type = "last_n";
33 count = 8;
34 }];
35 }];
36 };
37 };
38 };
39 };
40
41 testScript = ''
42 start_all()
43
44 with subtest("Wait for zrepl and network ready"):
45 host.systemctl("start network-online.target")
46 host.wait_for_unit("network-online.target")
47 host.wait_for_unit("zrepl.service")
48
49 with subtest("Create test zpool"):
50 # ZFS requires 64MiB minimum pool size.
51 host.succeed("fallocate -l 64MiB /root/zpool.img")
52 host.succeed("zpool create test /root/zpool.img")
53
54 with subtest("Check for completed zrepl snapshot"):
55 # zrepl periodic snapshot job creates a snapshot with this prefix.
56 host.wait_until_succeeds("zfs list -t snapshot | grep -q zrepl_")
57
58 with subtest("Verify HTTP monitoring server is configured"):
59 out = host.succeed("curl -f localhost:9811/metrics")
60
61 assert (
62 "zrepl_start_time" in out
63 ), "zrepl start time metric was not found in Prometheus output"
64
65 assert (
66 "zrepl_zfs_snapshot_duration_count{filesystem=\"test\"}" in out
67 ), "zrepl snapshot counter for test was not found in Prometheus output"
68 '';
69 })