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.wait_for_unit("network-online.target")
46 host.wait_for_unit("zrepl.service")
47
48 with subtest("Create test zpool"):
49 # ZFS requires 64MiB minimum pool size.
50 host.succeed("fallocate -l 64MiB /root/zpool.img")
51 host.succeed("zpool create test /root/zpool.img")
52
53 with subtest("Check for completed zrepl snapshot"):
54 # zrepl periodic snapshot job creates a snapshot with this prefix.
55 host.wait_until_succeeds("zfs list -t snapshot | grep -q zrepl_")
56
57 with subtest("Verify HTTP monitoring server is configured"):
58 out = host.succeed("curl -f localhost:9811/metrics")
59
60 assert (
61 "zrepl_start_time" in out
62 ), "zrepl start time metric was not found in Prometheus output"
63
64 assert (
65 "zrepl_zfs_snapshot_duration_count{filesystem=\"test\"}" in out
66 ), "zrepl snapshot counter for test was not found in Prometheus output"
67 '';
68 })