Skip to content

Commit

Permalink
nixos/tests/zfs: Test boot.zfs.forceImportAll
Browse files Browse the repository at this point in the history
  • Loading branch information
srhb committed Nov 11, 2020
1 parent d7e7fb7 commit ffe4dbf
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion nixos/tests/zfs.nix
Expand Up @@ -18,14 +18,32 @@ let
maintainers = [ adisbladis ];
};

machine = { pkgs, ... }: {
machine = { pkgs, lib, ... }: {
virtualisation.emptyDiskImages = [ 4096 ];
networking.hostId = "deadbeef";
boot.kernelPackages = kernelPackage;
boot.supportedFilesystems = [ "zfs" ];
boot.zfs.enableUnstable = enableUnstable;

environment.systemPackages = [ pkgs.parted ];

# Setup regular fileSystems machinery to ensure forceImportAll can be
# tested via the regular service units.
fileSystems = lib.mkVMOverride {
"/forcepool" = {
device = "forcepool";
fsType = "zfs";
options = [ "noauto" ];
};
};

# forcepool doesn't exist at first boot, and we need to manually test
# the import after tweaking the hostId.
systemd.services.zfs-import-forcepool.wantedBy = lib.mkVMOverride [];
systemd.targets.zfs.wantedBy = lib.mkVMOverride [];
boot.zfs.forceImportAll = true;
# /dev/disk/by-id doesn't get populated in the NixOS test framework
boot.zfs.devNodes = "/dev/disk/by-uuid";
};

testScript = ''
Expand Down Expand Up @@ -57,6 +75,21 @@ let
"zpool destroy rpool",
"udevadm settle",
)
with subtest("boot.zfs.forceImportAll works"):
machine.succeed(
"rm /etc/hostid",
"zgenhostid deadcafe",
"zpool create forcepool /dev/vdb1 -O mountpoint=legacy",
)
machine.shutdown()
machine.start()
machine.succeed("udevadm settle")
machine.fail("zpool import forcepool")
machine.succeed(
"systemctl start zfs-import-forcepool.service",
"mount -t zfs forcepool /tmp/mnt",
)
'' + extraTest;

};
Expand Down

0 comments on commit ffe4dbf

Please sign in to comment.