1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-21 13:10:33 +00:00
nixpkgs/nixos/tests/zfs.nix

108 lines
3.3 KiB
Nix
Raw Normal View History

{ system ? builtins.currentSystem,
config ? {},
pkgs ? import ../.. { inherit system config; }
}:
2017-11-13 18:56:03 +00:00
2020-01-28 07:54:17 +00:00
with import ../lib/testing-python.nix { inherit system pkgs; };
2017-11-13 18:56:03 +00:00
let
makeZfsTest = name:
{ kernelPackage ? if enableUnstable then pkgs.linuxPackages_latest else pkgs.linuxPackages
2017-11-13 18:56:03 +00:00
, enableUnstable ? false
, extraTest ? ""
}:
makeTest {
name = "zfs-" + name;
meta = with pkgs.lib.maintainers; {
2017-11-13 18:56:03 +00:00
maintainers = [ adisbladis ];
};
machine = { pkgs, lib, ... }: {
2020-01-28 07:54:17 +00:00
virtualisation.emptyDiskImages = [ 4096 ];
networking.hostId = "deadbeef";
boot.kernelPackages = kernelPackage;
boot.supportedFilesystems = [ "zfs" ];
boot.zfs.enableUnstable = enableUnstable;
2017-11-13 18:56:03 +00:00
2020-01-28 07:54:17 +00:00
environment.systemPackages = [ pkgs.parted ];
# Setup regular fileSystems machinery to ensure forceImportAll can be
# tested via the regular service units.
virtualisation.fileSystems = {
"/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";
2020-01-28 07:54:17 +00:00
};
2017-11-13 18:56:03 +00:00
testScript = ''
2019-10-27 12:53:36 +00:00
machine.succeed(
2020-01-28 07:54:17 +00:00
"modprobe zfs",
"zpool status",
"ls /dev",
"mkdir /tmp/mnt",
"udevadm settle",
"parted --script /dev/vdb mklabel msdos",
"parted --script /dev/vdb -- mkpart primary 1024M -1s",
"udevadm settle",
"zpool create rpool /dev/vdb1",
"zfs create -o mountpoint=legacy rpool/root",
"mount -t zfs rpool/root /tmp/mnt",
"udevadm settle",
"umount /tmp/mnt",
"zpool destroy rpool",
"udevadm settle",
2019-10-27 12:53:36 +00:00
)
machine.succeed(
'echo password | zpool create -o altroot="/tmp/mnt" '
+ "-O encryption=aes-256-gcm -O keyformat=passphrase rpool /dev/vdb1",
"zfs create -o mountpoint=legacy rpool/root",
"mount -t zfs rpool/root /tmp/mnt",
"udevadm settle",
"umount /tmp/mnt",
"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",
)
2017-11-13 18:56:03 +00:00
'' + extraTest;
};
in {
stable = makeZfsTest "stable" { };
unstable = makeZfsTest "unstable" {
enableUnstable = true;
};
installer = (import ./installer.nix { }).zfsroot;
}