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 17:09:59 +01:00
|
|
|
datasets."pool/sanoid".use_template = [ "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 10:29:21 +01: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";
|
|
|
|
};
|
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",
|
|
|
|
"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 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"
|
|
|
|
|
2020-11-22 19:27:55 +00:00
|
|
|
# Take snapshot with sanoid
|
|
|
|
source.succeed("touch /mnt/pool/sanoid/test.txt")
|
2019-10-27 03:37:30 +00:00
|
|
|
source.systemctl("start --wait sanoid.service")
|
|
|
|
|
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"
|
|
|
|
|
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")
|
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")
|
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
|
|
|
'';
|
|
|
|
})
|