2019-10-27 03:37:30 +00:00
|
|
|
import ./make-test-python.nix ({ pkgs, ... }: let
|
|
|
|
inherit (import ./ssh-keys.nix pkgs)
|
|
|
|
snakeOilPrivateKey snakeOilPublicKey;
|
|
|
|
|
|
|
|
commonConfig = { pkgs, ... }: {
|
|
|
|
virtualisation.emptyDiskImages = [ 2048 ];
|
|
|
|
boot.supportedFilesystems = [ "zfs" ];
|
|
|
|
environment.systemPackages = [ pkgs.parted ];
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
name = "sanoid";
|
2021-01-10 19:08:30 +00:00
|
|
|
meta = with pkgs.lib.maintainers; {
|
2019-10-27 03:37:30 +00:00
|
|
|
maintainers = [ lopsided98 ];
|
|
|
|
};
|
|
|
|
|
|
|
|
nodes = {
|
|
|
|
source = { ... }: {
|
|
|
|
imports = [ commonConfig ];
|
|
|
|
networking.hostId = "daa82e91";
|
|
|
|
|
|
|
|
programs.ssh.extraConfig = ''
|
|
|
|
UserKnownHostsFile=/dev/null
|
|
|
|
StrictHostKeyChecking=no
|
|
|
|
'';
|
|
|
|
|
|
|
|
services.sanoid = {
|
|
|
|
enable = true;
|
|
|
|
templates.test = {
|
|
|
|
hourly = 12;
|
|
|
|
daily = 1;
|
|
|
|
monthly = 1;
|
|
|
|
yearly = 1;
|
|
|
|
|
|
|
|
autosnap = true;
|
|
|
|
};
|
2020-03-31 16:09:59 +00:00
|
|
|
datasets."pool/sanoid".use_template = [ "test" ];
|
2022-08-22 16:53:35 +00:00
|
|
|
datasets."pool/compat".useTemplate = [ "test" ];
|
2020-11-22 19:27:55 +00:00
|
|
|
extraArgs = [ "--verbose" ];
|
2019-10-27 03:37:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
services.syncoid = {
|
|
|
|
enable = true;
|
2020-02-10 00:40:52 +00:00
|
|
|
sshKey = "/var/lib/syncoid/id_ecdsa";
|
2020-11-22 19:27:55 +00:00
|
|
|
commands = {
|
|
|
|
# Sync snapshot taken by sanoid
|
|
|
|
"pool/sanoid" = {
|
|
|
|
target = "root@target:pool/sanoid";
|
2020-09-22 09:29:21 +00:00
|
|
|
extraArgs = [ "--no-sync-snap" "--create-bookmark" ];
|
2020-11-22 19:27:55 +00:00
|
|
|
};
|
|
|
|
# Take snapshot and sync
|
|
|
|
"pool/syncoid".target = "root@target:pool/syncoid";
|
2022-07-04 10:46:37 +00:00
|
|
|
|
|
|
|
# Test pool without parent (regression test for https://github.com/NixOS/nixpkgs/pull/180111)
|
|
|
|
"pool".target = "root@target:pool/full-pool";
|
2022-08-22 16:53:35 +00:00
|
|
|
|
|
|
|
# Test backward compatible options (regression test for https://github.com/NixOS/nixpkgs/issues/181561)
|
|
|
|
"pool/compat" = {
|
|
|
|
target = "root@target:pool/compat";
|
|
|
|
extraArgs = [ "--no-sync-snap" ];
|
|
|
|
};
|
2020-11-22 19:27:55 +00:00
|
|
|
};
|
2019-10-27 03:37:30 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
target = { ... }: {
|
|
|
|
imports = [ commonConfig ];
|
|
|
|
networking.hostId = "dcf39d36";
|
|
|
|
|
|
|
|
services.openssh.enable = true;
|
|
|
|
users.users.root.openssh.authorizedKeys.keys = [ snakeOilPublicKey ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
source.succeed(
|
2020-11-22 19:27:55 +00:00
|
|
|
"mkdir /mnt",
|
2019-10-27 03:37:30 +00:00
|
|
|
"parted --script /dev/vdb -- mklabel msdos mkpart primary 1024M -1s",
|
|
|
|
"udevadm settle",
|
2020-11-22 19:27:55 +00:00
|
|
|
"zpool create pool -R /mnt /dev/vdb1",
|
|
|
|
"zfs create pool/sanoid",
|
2022-08-22 16:53:35 +00:00
|
|
|
"zfs create pool/compat",
|
2020-11-22 19:27:55 +00:00
|
|
|
"zfs create pool/syncoid",
|
2019-10-27 03:37:30 +00:00
|
|
|
"udevadm settle",
|
|
|
|
)
|
|
|
|
target.succeed(
|
2020-11-22 19:27:55 +00:00
|
|
|
"mkdir /mnt",
|
2019-10-27 03:37:30 +00:00
|
|
|
"parted --script /dev/vdb -- mklabel msdos mkpart primary 1024M -1s",
|
|
|
|
"udevadm settle",
|
2020-11-22 19:27:55 +00:00
|
|
|
"zpool create pool -R /mnt /dev/vdb1",
|
2019-10-27 03:37:30 +00:00
|
|
|
"udevadm settle",
|
|
|
|
)
|
|
|
|
|
|
|
|
source.succeed(
|
2020-02-10 00:40:52 +00:00
|
|
|
"mkdir -m 700 -p /var/lib/syncoid",
|
|
|
|
"cat '${snakeOilPrivateKey}' > /var/lib/syncoid/id_ecdsa",
|
|
|
|
"chmod 600 /var/lib/syncoid/id_ecdsa",
|
|
|
|
"chown -R syncoid:syncoid /var/lib/syncoid/",
|
2019-10-27 03:37:30 +00:00
|
|
|
)
|
|
|
|
|
2021-07-26 08:00:14 +00:00
|
|
|
assert len(source.succeed("zfs allow pool")) == 0, "Pool shouldn't have delegated permissions set before snapshotting"
|
|
|
|
assert len(source.succeed("zfs allow pool/sanoid")) == 0, "Sanoid dataset shouldn't have delegated permissions set before snapshotting"
|
|
|
|
assert len(source.succeed("zfs allow pool/syncoid")) == 0, "Syncoid dataset shouldn't have delegated permissions set before snapshotting"
|
|
|
|
|
2020-11-22 19:27:55 +00:00
|
|
|
# Take snapshot with sanoid
|
|
|
|
source.succeed("touch /mnt/pool/sanoid/test.txt")
|
2022-08-22 16:53:35 +00:00
|
|
|
source.succeed("touch /mnt/pool/compat/test.txt")
|
2019-10-27 03:37:30 +00:00
|
|
|
source.systemctl("start --wait sanoid.service")
|
|
|
|
|
2021-07-26 08:00:14 +00:00
|
|
|
assert len(source.succeed("zfs allow pool")) == 0, "Pool shouldn't have delegated permissions set after snapshotting"
|
|
|
|
assert len(source.succeed("zfs allow pool/sanoid")) == 0, "Sanoid dataset shouldn't have delegated permissions set after snapshotting"
|
|
|
|
assert len(source.succeed("zfs allow pool/syncoid")) == 0, "Syncoid dataset shouldn't have delegated permissions set after snapshotting"
|
|
|
|
|
2020-11-22 19:27:55 +00:00
|
|
|
# Sync snapshots
|
2019-10-27 03:37:30 +00:00
|
|
|
target.wait_for_open_port(22)
|
2020-11-22 19:27:55 +00:00
|
|
|
source.succeed("touch /mnt/pool/syncoid/test.txt")
|
2020-09-22 09:29:21 +00:00
|
|
|
source.systemctl("start --wait syncoid-pool-sanoid.service")
|
2020-11-22 19:27:55 +00:00
|
|
|
target.succeed("cat /mnt/pool/sanoid/test.txt")
|
2020-09-22 09:29:21 +00:00
|
|
|
source.systemctl("start --wait syncoid-pool-syncoid.service")
|
2024-01-03 17:38:16 +00:00
|
|
|
source.systemctl("start --wait syncoid-pool-syncoid.service")
|
2020-11-22 19:27:55 +00:00
|
|
|
target.succeed("cat /mnt/pool/syncoid/test.txt")
|
2021-07-26 08:00:14 +00:00
|
|
|
|
2024-01-03 17:38:16 +00:00
|
|
|
assert(len(source.succeed("zfs list -H -t snapshot pool/syncoid").splitlines()) == 1), "Syncoid should only retain one sync snapshot"
|
|
|
|
|
2022-07-04 10:46:37 +00:00
|
|
|
source.systemctl("start --wait syncoid-pool.service")
|
|
|
|
target.succeed("[[ -d /mnt/pool/full-pool/syncoid ]]")
|
|
|
|
|
2022-08-22 16:53:35 +00:00
|
|
|
source.systemctl("start --wait syncoid-pool-compat.service")
|
|
|
|
target.succeed("cat /mnt/pool/compat/test.txt")
|
|
|
|
|
2021-07-26 08:00:14 +00:00
|
|
|
assert len(source.succeed("zfs allow pool")) == 0, "Pool shouldn't have delegated permissions set after syncing snapshots"
|
|
|
|
assert len(source.succeed("zfs allow pool/sanoid")) == 0, "Sanoid dataset shouldn't have delegated permissions set after syncing snapshots"
|
|
|
|
assert len(source.succeed("zfs allow pool/syncoid")) == 0, "Syncoid dataset shouldn't have delegated permissions set after syncing snapshots"
|
2019-10-27 03:37:30 +00:00
|
|
|
'';
|
|
|
|
})
|