diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/boot-raid1.nix | 10 | ||||
-rw-r--r-- | tests/btrfs-subvolumes.nix | 11 | ||||
-rw-r--r-- | tests/cli.nix | 28 | ||||
-rw-r--r-- | tests/complex.nix | 27 | ||||
-rw-r--r-- | tests/default.nix | 28 | ||||
-rw-r--r-- | tests/gpt-bios-compat.nix | 11 | ||||
-rw-r--r-- | tests/lib.nix | 177 | ||||
-rw-r--r-- | tests/luks-lvm.nix | 15 | ||||
-rw-r--r-- | tests/lvm-raid.nix | 12 | ||||
-rw-r--r-- | tests/mdadm.nix | 12 | ||||
-rw-r--r-- | tests/module.nix | 28 | ||||
-rw-r--r-- | tests/multi-device-no-deps.nix | 12 | ||||
-rw-r--r-- | tests/negative-size.nix | 11 | ||||
-rw-r--r-- | tests/simple-efi.nix | 9 | ||||
-rw-r--r-- | tests/swap.nix | 22 | ||||
-rw-r--r-- | tests/test.nix | 97 | ||||
-rw-r--r-- | tests/tmpfs.nix | 10 | ||||
-rw-r--r-- | tests/with-lib.nix | 11 | ||||
-rw-r--r-- | tests/zfs-over-legacy.nix | 11 | ||||
-rw-r--r-- | tests/zfs.nix | 29 |
20 files changed, 474 insertions, 97 deletions
diff --git a/tests/boot-raid1.nix b/tests/boot-raid1.nix new file mode 100644 index 0000000..bea9adb --- /dev/null +++ b/tests/boot-raid1.nix @@ -0,0 +1,10 @@ +{ pkgs ? (import <nixpkgs> { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest +}: +makeDiskoTest { + disko-config = ../example/boot-raid1.nix; + extraTestScript = '' + machine.succeed("test -b /dev/md/boot"); + machine.succeed("mountpoint /boot"); + ''; +} diff --git a/tests/btrfs-subvolumes.nix b/tests/btrfs-subvolumes.nix new file mode 100644 index 0000000..1a62702 --- /dev/null +++ b/tests/btrfs-subvolumes.nix @@ -0,0 +1,11 @@ +{ pkgs ? (import <nixpkgs> { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest +}: +makeDiskoTest { + disko-config = ../example/btrfs-subvolumes.nix; + extraTestScript = '' + machine.succeed("test -e /test"); + machine.succeed("btrfs subvolume list / | grep -qs 'path test$'"); + ''; +} + diff --git a/tests/cli.nix b/tests/cli.nix new file mode 100644 index 0000000..24eb24c --- /dev/null +++ b/tests/cli.nix @@ -0,0 +1,28 @@ +{ pkgs ? (import <nixpkgs> { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest +}: +makeDiskoTest { + disko-config = ../example/complex.nix; + extraConfig = { + fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this! + }; + testMode = "cli"; + extraTestScript = '' + machine.succeed("test -b /dev/zroot/zfs_testvolume"); + machine.succeed("test -b /dev/md/raid1p1"); + + + machine.succeed("mountpoint /zfs_fs"); + machine.succeed("mountpoint /zfs_legacy_fs"); + machine.succeed("mountpoint /ext4onzfs"); + machine.succeed("mountpoint /ext4_on_lvm"); + ''; + enableOCR = true; + bootCommands = '' + machine.wait_for_text("Passphrase for") + machine.send_chars("secret\n") + ''; + extraConfig = { + boot.kernelModules = [ "dm-raid" "dm-mirror" ]; + }; +} diff --git a/tests/complex.nix b/tests/complex.nix new file mode 100644 index 0000000..5fe5efa --- /dev/null +++ b/tests/complex.nix @@ -0,0 +1,27 @@ +{ pkgs ? (import <nixpkgs> { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest +}: +makeDiskoTest { + disko-config = ../example/complex.nix; + extraConfig = { + fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this! + }; + extraTestScript = '' + machine.succeed("test -b /dev/zroot/zfs_testvolume"); + machine.succeed("test -b /dev/md/raid1p1"); + + + machine.succeed("mountpoint /zfs_fs"); + machine.succeed("mountpoint /zfs_legacy_fs"); + machine.succeed("mountpoint /ext4onzfs"); + machine.succeed("mountpoint /ext4_on_lvm"); + ''; + enableOCR = true; + bootCommands = '' + machine.wait_for_text("Passphrase for") + machine.send_chars("secret\n") + ''; + extraConfig = { + boot.kernelModules = [ "dm-raid" "dm-mirror" ]; + }; +} diff --git a/tests/default.nix b/tests/default.nix new file mode 100644 index 0000000..c7c15a5 --- /dev/null +++ b/tests/default.nix @@ -0,0 +1,28 @@ +{ makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix> +, eval-config ? import <nixpkgs/nixos/lib/eval-config.nix> +, pkgs ? (import <nixpkgs> { }) +}@args: +let + lib = pkgs.lib; + makeDiskoTest = (pkgs.callPackage ./lib.nix { inherit makeTest eval-config; }).makeDiskoTest; + + evalTest = name: configFile: let + disko-config = import configFile; + in { + "${name}-tsp-create" = pkgs.writeScript "create" ((pkgs.callPackage ../. { }).create disko-config); + "${name}-tsp-mount" = pkgs.writeScript "mount" ((pkgs.callPackage ../. { }).mount disko-config); + }; + + allTestFilenames = + builtins.map (lib.removeSuffix ".nix") ( + builtins.filter + (x: lib.hasSuffix ".nix" x && x != "default.nix" && x != "lib.nix") + (lib.attrNames (builtins.readDir ./.)) + ); + + allTests = lib.genAttrs (allTestFilenames) (test: import (./. + "/${test}.nix") { inherit makeDiskoTest pkgs; }) // + evalTest "lvm-luks-example" ../example/config.nix // { + standalone = (pkgs.nixos [ ../example/stand-alone/configuration.nix ]).config.system.build.toplevel; + }; +in +allTests diff --git a/tests/gpt-bios-compat.nix b/tests/gpt-bios-compat.nix new file mode 100644 index 0000000..e19c49a --- /dev/null +++ b/tests/gpt-bios-compat.nix @@ -0,0 +1,11 @@ +{ pkgs ? (import <nixpkgs> { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest +}: +makeDiskoTest { + disko-config = ../example/gpt-bios-compat.nix; + extraTestScript = '' + machine.succeed("mountpoint /"); + ''; + efi = false; + grub-devices = [ "/dev/vdb" ]; +} diff --git a/tests/lib.nix b/tests/lib.nix new file mode 100644 index 0000000..80ad0e3 --- /dev/null +++ b/tests/lib.nix @@ -0,0 +1,177 @@ +{ pkgs ? (import <nixpkgs> { }) +, makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix> +, eval-config ? import <nixpkgs/nixos/lib/eval-config.nix> +, ... +}: +{ + makeDiskoTest = + { disko-config + , extraTestScript ? "" + , bootCommands ? "" + , extraConfig ? { } + , grub-devices ? [ "nodev" ] + , efi ? true + , enableOCR ? false + , testMode ? "direct" # can be one of direct module cli + , testBoot ? true # if we actually want to test booting or just create/mount + }: + let + lib = pkgs.lib; + makeTest' = args: + makeTest args { + inherit pkgs; + inherit (pkgs) system; + }; + disks = [ "/dev/vda" "/dev/vdb" "/dev/vdc" "/dev/vdd" "/dev/vde" "/dev/vdf" ]; + tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. { }).create (import disko-config { disks = builtins.tail disks; inherit lib; })); + tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. { }).mount (import disko-config { disks = builtins.tail disks; inherit lib; })); + tsp-config = (pkgs.callPackage ../. { }).config (import disko-config { inherit disks; inherit lib; }); + tsp-disko = pkgs.writeScript "disko" ((pkgs.callPackage ../. { }).zapCreateMount (import disko-config { disks = builtins.tail disks; inherit lib; })); + num-disks = builtins.length (lib.attrNames (import disko-config { inherit lib; }).disk); + installed-system = { modulesPath, ... }: { + imports = [ + (lib.optionalAttrs (testMode == "direct" || testMode == "cli") tsp-config) + (lib.optionalAttrs (testMode == "module") { + imports = [ ../module.nix ]; + disko = { + enableConfig = true; + devices = import disko-config { inherit disks lib; }; + }; + }) + (modulesPath + "/testing/test-instrumentation.nix") + (modulesPath + "/profiles/qemu-guest.nix") + (modulesPath + "/profiles/minimal.nix") + extraConfig + ]; + fileSystems."/nix/store" = { + device = "nix-store"; + fsType = "9p"; + neededForBoot = true; + options = [ "trans=virtio" "version=9p2000.L" "cache=loose" ]; + }; + documentation.enable = false; + hardware.enableAllFirmware = lib.mkForce false; + networking.hostId = "8425e349"; # from profiles/base.nix, needed for zfs + boot.kernelParams = lib.mkAfter [ "console=tty0" ]; # needed to have serial interaction during boot + boot.zfs.devNodes = "/dev/disk/by-uuid"; # needed because /dev/disk/by-id is empty in qemu-vms + + boot.consoleLogLevel = lib.mkForce 100; + boot.loader.grub = { + devices = grub-devices; + efiSupport = efi; + efiInstallAsRemovable = efi; + }; + }; + installedTopLevel = (eval-config { + modules = [ installed-system ]; + inherit (pkgs) system; + }).config.system.build.toplevel; + in + makeTest' { + name = "disko"; + + inherit enableOCR; + nodes.machine = { config, pkgs, modulesPath, ... }: { + imports = [ + (lib.optionalAttrs (testMode == "module") { + imports = [ ../module.nix ]; + disko = { + enableConfig = false; + devices = import disko-config { disks = builtins.tail disks; inherit lib; }; + }; + }) + (lib.optionalAttrs (testMode == "cli") { + imports = [ (modulesPath + "/installer/cd-dvd/channel.nix") ]; + system.extraDependencies = [ + ((pkgs.callPackage ../. { }).createScript (import disko-config { disks = builtins.tail disks; inherit lib; }) pkgs) + ((pkgs.callPackage ../. { }).mountScript (import disko-config { disks = builtins.tail disks; inherit lib; }) pkgs) + ]; + }) + (modulesPath + "/profiles/base.nix") + (modulesPath + "/profiles/minimal.nix") + extraConfig + ]; + environment.systemPackages = [ + pkgs.jq + ]; + + # speed-up eval + documentation.enable = false; + + nix.settings = { + substituters = lib.mkForce []; + hashed-mirrors = null; + connect-timeout = 1; + }; + + virtualisation.emptyDiskImages = builtins.genList (_: 4096) num-disks; + }; + + testScript = { nodes, ... }: '' + def disks(oldmachine, num_disks): + disk_flags = "" + for i in range(num_disks): + disk_flags += f' -drive file={oldmachine.state_dir}/empty{i}.qcow2,id=drive{i + 1},if=none,index={i + 1},werror=report' + disk_flags += f' -device virtio-blk-pci,drive=drive{i + 1}' + return disk_flags + def create_test_machine(oldmachine=None, args={}): # taken from <nixpkgs/nixos/tests/installer.nix> + machine = create_machine({ + "qemuFlags": "-cpu max -m 1024 -virtfs local,path=/nix/store,security_model=none,mount_tag=nix-store" + disks(oldmachine, ${toString num-disks}), + ${lib.optionalString efi ''"bios": "${pkgs.OVMF.fd}/FV/OVMF.fd",''} + } | args) + driver.machines.append(machine) + return machine + + machine.start() + machine.succeed("echo -n 'secret' > /tmp/secret.key") + ${lib.optionalString (testMode == "direct") '' + machine.succeed("${tsp-create}") + machine.succeed("${tsp-mount}") + machine.succeed("${tsp-mount}") # verify that the command is idempotent + machine.succeed("${tsp-disko}") # verify that we can destroy and recreate + ''} + ${lib.optionalString (testMode == "module") '' + machine.succeed("${nodes.machine.system.build.formatScript}") + machine.succeed("${nodes.machine.system.build.mountScript}") + machine.succeed("${nodes.machine.system.build.mountScript}") # verify that the command is idempotent + machine.succeed("${nodes.machine.system.build.disko}") # verify that we can destroy and recreate again + ''} + ${lib.optionalString (testMode == "cli") '' + # TODO use the disko cli here + # machine.succeed("${../.}/disko --no-pkgs --mode create ${disko-config}") + # machine.succeed("${../.}/disko --no-pkgs --mode mount ${disko-config}") + # machine.succeed("${../.}/disko --no-pkgs --mode mount ${disko-config}") # verify that the command is idempotent + # machine.succeed("${../.}/disko --no-pkgs --mode zap_create_mount ${disko-config}") # verify that we can destroy and recreate again + machine.succeed("${tsp-create}") + machine.succeed("${tsp-mount}") + machine.succeed("${tsp-mount}") # verify that the command is idempotent + machine.succeed("${tsp-disko}") # verify that we can destroy and recreate + ''} + + ${lib.optionalString testBoot '' + # mount nix-store in /mnt + machine.succeed("mkdir -p /mnt/nix/store") + machine.succeed("mount --bind /nix/store /mnt/nix/store") + + machine.succeed("nix-store --load-db < ${pkgs.closureInfo {rootPaths = [installedTopLevel];}}/registration") + + # fix "this is not a NixOS installation" + machine.succeed("mkdir -p /mnt/etc") + machine.succeed("touch /mnt/etc/NIXOS") + + machine.succeed("mkdir -p /mnt/nix/var/nix/profiles") + machine.succeed("nix-env -p /mnt/nix/var/nix/profiles/system --set ${installedTopLevel}") + machine.succeed("NIXOS_INSTALL_BOOTLOADER=1 nixos-enter --root /mnt -- ${installedTopLevel}/bin/switch-to-configuration boot") + machine.succeed("sync") + machine.shutdown() + + machine = create_test_machine(oldmachine=machine, args={ "name": "booted_machine" }) + machine.start() + ${bootCommands} + machine.wait_for_unit("local-fs.target") + ''} + + ${extraTestScript} + ''; + }; +} diff --git a/tests/luks-lvm.nix b/tests/luks-lvm.nix new file mode 100644 index 0000000..05d3362 --- /dev/null +++ b/tests/luks-lvm.nix @@ -0,0 +1,15 @@ +{ pkgs ? (import <nixpkgs> { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest +}: +makeDiskoTest { + disko-config = ../example/luks-lvm.nix; + extraTestScript = '' + machine.succeed("cryptsetup isLuks /dev/vda2"); + machine.succeed("mountpoint /home"); + ''; + enableOCR = true; + bootCommands = '' + machine.wait_for_text("Passphrase for") + machine.send_chars("secret\n") + ''; +} diff --git a/tests/lvm-raid.nix b/tests/lvm-raid.nix new file mode 100644 index 0000000..cc73e61 --- /dev/null +++ b/tests/lvm-raid.nix @@ -0,0 +1,12 @@ +{ pkgs ? (import <nixpkgs> { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest +}: +makeDiskoTest { + disko-config = ../example/lvm-raid.nix; + extraTestScript = '' + machine.succeed("mountpoint /home"); + ''; + extraConfig = { + boot.kernelModules = [ "dm-raid0" "dm-mirror" ]; + }; +} diff --git a/tests/mdadm.nix b/tests/mdadm.nix new file mode 100644 index 0000000..2b4442a --- /dev/null +++ b/tests/mdadm.nix @@ -0,0 +1,12 @@ +{ pkgs ? (import <nixpkgs> { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest +}: +makeDiskoTest { + disko-config = ../example/mdadm.nix; + extraTestScript = '' + machine.succeed("test -b /dev/md/raid1"); + machine.succeed("mountpoint /"); + ''; + efi = false; + grub-devices = [ "/dev/vdb" "/dev/vdc" ]; +} diff --git a/tests/module.nix b/tests/module.nix new file mode 100644 index 0000000..ef3b88e --- /dev/null +++ b/tests/module.nix @@ -0,0 +1,28 @@ +{ pkgs ? (import <nixpkgs> { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest +}: +makeDiskoTest { + disko-config = ../example/complex.nix; + extraConfig = { + fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this! + }; + testMode = "module"; + extraTestScript = '' + machine.succeed("test -b /dev/zroot/zfs_testvolume"); + machine.succeed("test -b /dev/md/raid1p1"); + + + machine.succeed("mountpoint /zfs_fs"); + machine.succeed("mountpoint /zfs_legacy_fs"); + machine.succeed("mountpoint /ext4onzfs"); + machine.succeed("mountpoint /ext4_on_lvm"); + ''; + enableOCR = true; + bootCommands = '' + machine.wait_for_text("Passphrase for") + machine.send_chars("secret\n") + ''; + extraConfig = { + boot.kernelModules = [ "dm-raid" "dm-mirror" ]; + }; +} diff --git a/tests/multi-device-no-deps.nix b/tests/multi-device-no-deps.nix new file mode 100644 index 0000000..ef1f7a8 --- /dev/null +++ b/tests/multi-device-no-deps.nix @@ -0,0 +1,12 @@ +# this is a regression test for https://github.com/nix-community/disko/issues/52 +{ pkgs ? (import <nixpkgs> { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest +}: +makeDiskoTest { + disko-config = ../example/multi-device-no-deps.nix; + testBoot = false; + extraTestScript = '' + machine.succeed("mountpoint /mnt/a"); + machine.succeed("mountpoint /mnt/b"); + ''; +} diff --git a/tests/negative-size.nix b/tests/negative-size.nix new file mode 100644 index 0000000..224b00c --- /dev/null +++ b/tests/negative-size.nix @@ -0,0 +1,11 @@ +# this is a regression test for https://github.com/nix-community/disko/issues/52 +{ pkgs ? (import <nixpkgs> { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest +}: +makeDiskoTest { + disko-config = ../example/negative-size.nix; + testBoot = false; + extraTestScript = '' + machine.succeed("mountpoint /mnt"); + ''; +} diff --git a/tests/simple-efi.nix b/tests/simple-efi.nix new file mode 100644 index 0000000..920920f --- /dev/null +++ b/tests/simple-efi.nix @@ -0,0 +1,9 @@ +{ pkgs ? (import <nixpkgs> { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest +}: +makeDiskoTest { + disko-config = ../example/simple-efi.nix; + extraTestScript = '' + machine.succeed("mountpoint /"); + ''; +} diff --git a/tests/swap.nix b/tests/swap.nix new file mode 100644 index 0000000..4861f8d --- /dev/null +++ b/tests/swap.nix @@ -0,0 +1,22 @@ +{ pkgs ? (import <nixpkgs> { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest +}: +makeDiskoTest { + disko-config = ../example/swap.nix; + extraTestScript = '' + machine.succeed("mountpoint /"); + machine.succeed("swapon --show >&2"); + machine.succeed(""" + lsblk --json | + jq -e '.blockdevices[] | + select(.name == "vda") | + .children[] | + select(.name == "vda3") | + .children[0].mountpoints[0] == "[SWAP]" + ' + """); + ''; + extraConfig = { + environment.systemPackages = [ pkgs.jq ]; + }; +} diff --git a/tests/test.nix b/tests/test.nix deleted file mode 100644 index 0f875e6..0000000 --- a/tests/test.nix +++ /dev/null @@ -1,97 +0,0 @@ -import <nixpkgs/nixos/tests/make-test.nix> ({ pkgs, ... }: let - - disko-config = { - type = "devices"; - content = { - vdb = { - type = "table"; - format = "gpt"; - partitions = [ - { - type = "partition"; - part-type = "ESP"; - start = "1MiB"; - end = "100MiB"; - fs-type = "FAT32"; - bootable = true; - content = { - type = "filesystem"; - format = "vfat"; - mountpoint = "/boot"; - options = [ - "defaults" - ]; - }; - } - { - type = "partition"; - part-type = "primary"; - start = "100MiB"; - end = "100%"; - content = { - type = "luks"; - algo = "aes-xts..."; - name = "crypted"; - keyfile = "/tmp/secret.key"; - extraArgs = [ - "--hash sha512" - "--iter-time 5000" - ]; - content = { - type = "lvm"; - name = "pool"; - lvs = { - root = { - type = "lv"; - size = "100M"; - mountpoint = "/"; - content = { - type = "filesystem"; - format = "ext4"; - mountpoint = "/"; - options = [ - "defaults" - ]; - }; - }; - home = { - type = "lv"; - size = "100M"; - content = { - type = "filesystem"; - format = "ext4"; - mountpoint = "/home"; - }; - }; - }; - }; - }; - } - ]; - }; - }; - }; - -in { - name = "disko"; - - machine = - { config, pkgs, ... }: - - { - imports = [ - <nixpkgs/nixos/modules/profiles/installation-device.nix> - <nixpkgs/nixos/modules/profiles/base.nix> - ]; - - virtualisation.emptyDiskImages = [ 512 ]; - }; - - testScript = - '' - $machine->succeed("echo 'secret' > /tmp/secret.key"); - $machine->succeed("${pkgs.writeScript "create" ((import ../lib).create disko-config)}"); - $machine->succeed("${pkgs.writeScript "mount" ((import ../lib).mount disko-config)}"); - ''; - -}) diff --git a/tests/tmpfs.nix b/tests/tmpfs.nix new file mode 100644 index 0000000..10da055 --- /dev/null +++ b/tests/tmpfs.nix @@ -0,0 +1,10 @@ +{ pkgs ? (import <nixpkgs> { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest +}: +makeDiskoTest { + disko-config = ../example/tmpfs.nix; + extraTestScript = '' + machine.succeed("mountpoint /"); + machine.succeed("mountpoint /tmp"); + ''; +} diff --git a/tests/with-lib.nix b/tests/with-lib.nix new file mode 100644 index 0000000..18c422b --- /dev/null +++ b/tests/with-lib.nix @@ -0,0 +1,11 @@ +{ pkgs ? (import <nixpkgs> { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest +}: +makeDiskoTest { + disko-config = ../example/with-lib.nix; + extraTestScript = '' + machine.succeed("mountpoint /"); + ''; + efi = false; + grub-devices = [ "/dev/vdb" ]; +} diff --git a/tests/zfs-over-legacy.nix b/tests/zfs-over-legacy.nix new file mode 100644 index 0000000..09505e5 --- /dev/null +++ b/tests/zfs-over-legacy.nix @@ -0,0 +1,11 @@ +{ pkgs ? (import <nixpkgs> { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest +}: +makeDiskoTest { + disko-config = ../example/zfs-over-legacy.nix; + extraTestScript = '' + machine.succeed("test -e /zfs_fs"); + machine.succeed("mountpoint /zfs_fs"); + ''; +} + diff --git a/tests/zfs.nix b/tests/zfs.nix new file mode 100644 index 0000000..d88070e --- /dev/null +++ b/tests/zfs.nix @@ -0,0 +1,29 @@ +{ pkgs ? (import <nixpkgs> { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest +}: +makeDiskoTest { + disko-config = ../example/zfs.nix; + extraConfig = { + fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this! + }; + extraTestScript = '' + machine.succeed("test -b /dev/zvol/zroot/zfs_testvolume"); + + def assert_property(ds, property, expected_value): + out = machine.succeed(f"zfs get -H {property} {ds} -o value").rstrip() + assert ( + out == expected_value + ), f"Expected {property}={expected_value} on {ds}, got: {out}" + + assert_property("zroot", "compression", "lz4") + assert_property("zroot/zfs_fs", "compression", "lz4") + assert_property("zroot", "com.sun:auto-snapshot", "false") + assert_property("zroot/zfs_fs", "com.sun:auto-snapshot", "true") + assert_property("zroot/zfs_testvolume", "volsize", "10M") + assert_property("zroot/zfs_unmounted_fs", "mountpoint", "none") + + machine.succeed("mountpoint /zfs_fs"); + machine.succeed("mountpoint /zfs_legacy_fs"); + machine.succeed("mountpoint /ext4onzfs"); + ''; +} |