nixos/zrepl: Improve tests (#416118)
nixos/zrepl: Improve tests to: * Use a block device for zpool * Have two virtual machines so that source->target replication works
This commit is contained in:
parent
03dd44737a
commit
d50e8abe7e
@ -1,76 +1,178 @@
|
|||||||
{
|
{
|
||||||
name = "zrepl";
|
name = "zrepl";
|
||||||
|
|
||||||
nodes.host =
|
nodes = {
|
||||||
{ pkgs, ... }:
|
source =
|
||||||
{
|
{ nodes, pkgs, ... }:
|
||||||
config = {
|
{
|
||||||
# Prerequisites for ZFS and tests.
|
config = {
|
||||||
boot.supportedFilesystems = [ "zfs" ];
|
# Prerequisites for ZFS and tests.
|
||||||
environment.systemPackages = [ pkgs.zrepl ];
|
virtualisation.emptyDiskImages = [
|
||||||
networking.hostId = "deadbeef";
|
2048
|
||||||
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;
|
boot.supportedFilesystems = [ "zfs" ];
|
||||||
snapshotting = {
|
environment.systemPackages = [
|
||||||
type = "periodic";
|
pkgs.parted
|
||||||
prefix = "zrepl_";
|
pkgs.zrepl
|
||||||
interval = "1s";
|
];
|
||||||
};
|
networking.firewall.allowedTCPPorts = [ 8888 ];
|
||||||
|
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 = "snapshots";
|
||||||
|
type = "snap";
|
||||||
|
|
||||||
pruning.keep = [
|
filesystems."tank/data" = true;
|
||||||
{
|
snapshotting = {
|
||||||
type = "last_n";
|
type = "periodic";
|
||||||
count = 8;
|
prefix = "zrepl_";
|
||||||
}
|
interval = "10s";
|
||||||
];
|
};
|
||||||
}
|
|
||||||
];
|
pruning.keep = [
|
||||||
|
{
|
||||||
|
type = "last_n";
|
||||||
|
count = 8;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
{
|
||||||
|
name = "backup-target";
|
||||||
|
type = "source";
|
||||||
|
|
||||||
|
serve = {
|
||||||
|
type = "tcp";
|
||||||
|
listen = ":8888";
|
||||||
|
|
||||||
|
clients = {
|
||||||
|
"${nodes.target.networking.primaryIPAddress}" = "${nodes.target.networking.hostName}";
|
||||||
|
"${nodes.target.networking.primaryIPv6Address}" = "${nodes.target.networking.hostName}";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
filesystems."tank/data" = true;
|
||||||
|
# Snapshots are handled by the separate snap job
|
||||||
|
snapshotting = {
|
||||||
|
type = "manual";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
target =
|
||||||
|
{ pkgs, ... }:
|
||||||
|
{
|
||||||
|
config = {
|
||||||
|
# Prerequisites for ZFS and tests.
|
||||||
|
virtualisation.emptyDiskImages = [
|
||||||
|
2048
|
||||||
|
];
|
||||||
|
|
||||||
|
boot.supportedFilesystems = [ "zfs" ];
|
||||||
|
environment.systemPackages = [
|
||||||
|
pkgs.parted
|
||||||
|
pkgs.zrepl
|
||||||
|
];
|
||||||
|
networking.hostId = "deadd0d0";
|
||||||
|
services.zrepl = {
|
||||||
|
enable = true;
|
||||||
|
settings = {
|
||||||
|
# Enable Prometheus output for status assertions.
|
||||||
|
global.monitoring = [
|
||||||
|
{
|
||||||
|
type = "prometheus";
|
||||||
|
listen = ":9811";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
jobs = [
|
||||||
|
{
|
||||||
|
name = "source-pull";
|
||||||
|
type = "pull";
|
||||||
|
|
||||||
|
connect = {
|
||||||
|
type = "tcp";
|
||||||
|
address = "source:8888";
|
||||||
|
};
|
||||||
|
root_fs = "tank/zrepl/source";
|
||||||
|
interval = "15s";
|
||||||
|
recv = {
|
||||||
|
placeholder = {
|
||||||
|
encryption = "off";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
pruning = {
|
||||||
|
keep_sender = [
|
||||||
|
{
|
||||||
|
type = "regex";
|
||||||
|
regex = ".*";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
keep_receiver = [
|
||||||
|
{
|
||||||
|
type = "grid";
|
||||||
|
grid = "1x1h(keep=all) | 24x1h";
|
||||||
|
regex = "^zrepl_";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
testScript = ''
|
testScript = ''
|
||||||
start_all()
|
start_all()
|
||||||
|
|
||||||
with subtest("Wait for zrepl and network ready"):
|
with subtest("Wait for zrepl and network ready"):
|
||||||
host.systemctl("start network-online.target")
|
for machine in source, target:
|
||||||
host.wait_for_unit("network-online.target")
|
machine.systemctl("start network-online.target")
|
||||||
host.wait_for_unit("zrepl.service")
|
machine.wait_for_unit("network-online.target")
|
||||||
|
machine.wait_for_unit("zrepl.service")
|
||||||
|
|
||||||
with subtest("Create test zpool"):
|
with subtest("Create tank zpool"):
|
||||||
# ZFS requires 64MiB minimum pool size.
|
for machine in source, target:
|
||||||
host.succeed("fallocate -l 64MiB /root/zpool.img")
|
machine.succeed(
|
||||||
host.succeed("zpool create test /root/zpool.img")
|
"parted --script /dev/vdb mklabel gpt",
|
||||||
|
"zpool create tank /dev/vdb",
|
||||||
|
)
|
||||||
|
|
||||||
with subtest("Check for completed zrepl snapshot"):
|
# Create ZFS datasets
|
||||||
|
source.succeed("zfs create tank/data")
|
||||||
|
target.succeed("zfs create -p tank/zrepl/source")
|
||||||
|
|
||||||
|
with subtest("Check for completed zrepl snapshot on target"):
|
||||||
# zrepl periodic snapshot job creates a snapshot with this prefix.
|
# zrepl periodic snapshot job creates a snapshot with this prefix.
|
||||||
host.wait_until_succeeds("zfs list -t snapshot | grep -q zrepl_")
|
target.wait_until_succeeds("zfs list -t snapshot | grep -q tank/zrepl/source/tank/data@zrepl_")
|
||||||
|
|
||||||
|
with subtest("Check for completed zrepl bookmark on source"):
|
||||||
|
source.wait_until_succeeds("zfs list -t bookmark | grep -q tank/data#zrepl_")
|
||||||
|
|
||||||
with subtest("Verify HTTP monitoring server is configured"):
|
with subtest("Verify HTTP monitoring server is configured"):
|
||||||
out = host.succeed("curl -f localhost:9811/metrics")
|
out = source.succeed("curl -f localhost:9811/metrics")
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
"zrepl_start_time" in out
|
"zrepl_start_time" in out
|
||||||
), "zrepl start time metric was not found in Prometheus output"
|
), "zrepl start time metric was not found in Prometheus output"
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
"zrepl_zfs_snapshot_duration_count{filesystem=\"test\"}" in out
|
"zrepl_zfs_snapshot_duration_count{filesystem=\"tank/data\"}" in out
|
||||||
), "zrepl snapshot counter for test was not found in Prometheus output"
|
), "zrepl snapshot counter for tank/data was not found in Prometheus output"
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user