2019-10-27 03:37:30 +00:00
|
|
|
import ./make-test-python.nix (
|
|
|
|
{ pkgs, ... }:
|
|
|
|
let
|
|
|
|
inherit (import ./ssh-keys.nix pkgs)
|
|
|
|
snakeOilPrivateKey
|
|
|
|
snakeOilPublicKey
|
|
|
|
;
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2019-10-27 03:37:30 +00:00
|
|
|
commonConfig =
|
|
|
|
{ pkgs, ... }:
|
|
|
|
{
|
|
|
|
virtualisation.emptyDiskImages = [ 2048 ];
|
2020-03-31 17:09:59 +01:00
|
|
|
boot.supportedFilesystems = [ "zfs" ];
|
2022-08-22 17:53:35 +01:00
|
|
|
environment.systemPackages = [ pkgs.parted ];
|
2019-10-27 03:37:30 +00:00
|
|
|
};
|
2024-12-10 19:26:33 +00:00
|
|
|
in
|
|
|
|
{
|
2019-10-27 03:37:30 +00:00
|
|
|
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 ];
|
2024-12-10 19:26:33 +00:00
|
|
|
};
|
2019-10-27 03:37:30 +00:00
|
|
|
|
|
|
|
nodes = {
|
2024-12-10 19:26:33 +00:00
|
|
|
source =
|
|
|
|
{ ... }:
|
|
|
|
{
|
2019-10-27 03:37:30 +00:00
|
|
|
imports = [ commonConfig ];
|
|
|
|
networking.hostId = "daa82e91";
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2019-10-27 03:37:30 +00:00
|
|
|
programs.ssh.extraConfig = ''
|
|
|
|
UserKnownHostsFile=/dev/null
|
|
|
|
StrictHostKeyChecking=no
|
2024-12-10 19:26:33 +00:00
|
|
|
'';
|
|
|
|
|
2019-10-27 03:37:30 +00:00
|
|
|
services.sanoid = {
|
|
|
|
enable = true;
|
|
|
|
templates.test = {
|
|
|
|
hourly = 12;
|
|
|
|
daily = 1;
|
|
|
|
monthly = 1;
|
2020-02-10 00:40:52 +00:00
|
|
|
yearly = 1;
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2020-11-22 19:27:55 +00:00
|
|
|
autosnap = true;
|
2024-12-10 19:26:33 +00:00
|
|
|
};
|
2020-11-22 19:27:55 +00:00
|
|
|
datasets."pool/sanoid".use_template = [ "test" ];
|
2020-09-22 10:29:21 +01:00
|
|
|
datasets."pool/compat".useTemplate = [ "test" ];
|
|
|
|
extraArgs = [ "--verbose" ];
|
2020-11-22 19:27:55 +00:00
|
|
|
};
|
2022-08-22 17:53:35 +01:00
|
|
|
|
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";
|
|
|
|
extraArgs = [
|
2020-09-22 10:29:21 +01:00
|
|
|
"--no-sync-snap"
|
|
|
|
"--create-bookmark"
|
2024-12-10 19:26:33 +00:00
|
|
|
];
|
|
|
|
};
|
2020-11-22 19:27:55 +00:00
|
|
|
# Take snapshot and sync
|
|
|
|
"pool/syncoid".target = "root@target:pool/syncoid";
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2022-07-04 11:46:37 +01:00
|
|
|
# Test pool without parent (regression test for https://github.com/NixOS/nixpkgs/pull/180111)
|
|
|
|
"pool".target = "root@target:pool/full-pool";
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2022-08-22 17:53:35 +01: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" ];
|
2024-12-10 19:26:33 +00:00
|
|
|
};
|
|
|
|
};
|
2022-08-22 17:53:35 +01:00
|
|
|
};
|
2020-11-22 19:27:55 +00:00
|
|
|
};
|
2024-12-10 19:26:33 +00:00
|
|
|
target =
|
|
|
|
{ ... }:
|
|
|
|
{
|
2019-10-27 03:37:30 +00:00
|
|
|
imports = [ commonConfig ];
|
|
|
|
networking.hostId = "dcf39d36";
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2019-10-27 03:37:30 +00:00
|
|
|
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 17:53:35 +01: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",
|
|
|
|
)
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2019-10-27 03:37:30 +00:00
|
|
|
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
|
|
|
)
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2021-07-26 09:00:14 +01: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"
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2020-11-22 19:27:55 +00:00
|
|
|
# Take snapshot with sanoid
|
|
|
|
source.succeed("touch /mnt/pool/sanoid/test.txt")
|
2022-08-22 17:53:35 +01:00
|
|
|
source.succeed("touch /mnt/pool/compat/test.txt")
|
2019-10-27 03:37:30 +00:00
|
|
|
source.systemctl("start --wait sanoid.service")
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2021-07-26 09:00:14 +01: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"
|
2024-12-10 19:26:33 +00:00
|
|
|
|
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 10:29:21 +01: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")
|
2024-01-03 17:38:16 +00:00
|
|
|
source.systemctl("start --wait syncoid-pool-syncoid.service")
|
2020-09-22 10:29:21 +01: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")
|
2024-12-10 19:26:33 +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"
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2022-07-04 11:46:37 +01:00
|
|
|
source.systemctl("start --wait syncoid-pool.service")
|
|
|
|
target.succeed("[[ -d /mnt/pool/full-pool/syncoid ]]")
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2022-08-22 17:53:35 +01:00
|
|
|
source.systemctl("start --wait syncoid-pool-compat.service")
|
|
|
|
target.succeed("cat /mnt/pool/compat/test.txt")
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2021-07-26 09:00:14 +01: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
|
|
|
'';
|
|
|
|
}
|
|
|
|
)
|