diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index dcbdf34e9441..799ce9b4017e 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -274,6 +274,7 @@ in login = handleTest ./login.nix {}; logrotate = handleTest ./logrotate.nix {}; loki = handleTest ./loki.nix {}; + lvm2 = handleTest ./lvm2 {}; lxd = handleTest ./lxd.nix {}; lxd-image = handleTest ./lxd-image.nix {}; lxd-nftables = handleTest ./lxd-nftables.nix {}; diff --git a/nixos/tests/lvm2/default.nix b/nixos/tests/lvm2/default.nix new file mode 100644 index 000000000000..285e14390410 --- /dev/null +++ b/nixos/tests/lvm2/default.nix @@ -0,0 +1,26 @@ +{ system ? builtins.currentSystem +, config ? { } +, pkgs ? import ../../.. { inherit system config; } +, lib ? pkgs.lib +, kernelVersionsToTest ? [ "4.19" "5.4" "5.10" "5.15" "latest" ] +}: + +let + tests = let callTest = p: lib.flip (import p) { inherit system pkgs; }; in { + thinpool = { test = callTest ./thinpool.nix; kernelFilter = lib.id; }; + # we would like to test all versions, but the kernel module currently does not compile against the other versions + vdo = { test = callTest ./vdo.nix; kernelFilter = lib.filter (v: v == "5.15"); }; + }; +in +lib.listToAttrs ( + lib.filter (x: x.value != {}) ( + lib.flip lib.concatMap kernelVersionsToTest (version: + let + v' = lib.replaceStrings [ "." ] [ "_" ] version; + in + lib.flip lib.mapAttrsToList tests (name: t: + lib.nameValuePair "lvm-${name}-linux-${v'}" (lib.optionalAttrs (builtins.elem version (t.kernelFilter kernelVersionsToTest)) (t.test { kernelPackages = pkgs."linuxPackages_${v'}"; })) + ) + ) + ) +) diff --git a/nixos/tests/lvm2/thinpool.nix b/nixos/tests/lvm2/thinpool.nix new file mode 100644 index 000000000000..82c6460a890a --- /dev/null +++ b/nixos/tests/lvm2/thinpool.nix @@ -0,0 +1,32 @@ +{ kernelPackages ? null }: +import ../make-test-python.nix ({ pkgs, ... }: { + name = "lvm2-thinpool"; + meta.maintainers = with pkgs.lib.maintainers; [ ajs124 ]; + + nodes.machine = { pkgs, lib, ... }: { + virtualisation.emptyDiskImages = [ 4096 ]; + services.lvm = { + boot.thin.enable = true; + dmeventd.enable = true; + }; + environment.systemPackages = with pkgs; [ xfsprogs ]; + environment.etc."lvm/lvm.conf".text = '' + activation/thin_pool_autoextend_percent = 10 + activation/thin_pool_autoextend_threshold = 80 + ''; + boot = lib.mkIf (kernelPackages != null) { inherit kernelPackages; }; + }; + + testScript = '' + machine.succeed("vgcreate test_vg /dev/vdb") + machine.succeed("lvcreate -L 512M -T test_vg/test_thin_pool") + machine.succeed("lvcreate -n test_lv -V 16G --thinpool test_thin_pool test_vg") + machine.succeed("mkfs.xfs /dev/test_vg/test_lv") + machine.succeed("mkdir /mnt; mount /dev/test_vg/test_lv /mnt") + assert "/dev/mapper/test_vg-test_lv" == machine.succeed("findmnt -no SOURCE /mnt").strip() + machine.succeed("dd if=/dev/zero of=/mnt/empty.file bs=1M count=1024") + machine.succeed("journalctl -u dm-event.service | grep \"successfully resized\"") + machine.succeed("umount /mnt") + machine.succeed("vgchange -a n") + ''; +}) diff --git a/nixos/tests/lvm2/vdo.nix b/nixos/tests/lvm2/vdo.nix new file mode 100644 index 000000000000..49548d895ca0 --- /dev/null +++ b/nixos/tests/lvm2/vdo.nix @@ -0,0 +1,27 @@ +{ kernelPackages ? null }: +import ../make-test-python.nix ({ pkgs, ... }: { + name = "lvm2-thinpool"; + meta.maintainers = with pkgs.lib.maintainers; [ ajs124 ]; + + nodes.machine = { pkgs, lib, ... }: { + # Minimum required size for VDO volume: 5063921664 bytes + virtualisation.emptyDiskImages = [ 8192 ]; + services.lvm = { + boot.vdo.enable = true; + dmeventd.enable = true; + }; + environment.systemPackages = with pkgs; [ xfsprogs ]; + boot = lib.mkIf (kernelPackages != null) { inherit kernelPackages; }; + }; + + testScript = '' + machine.succeed("vgcreate test_vg /dev/vdb") + machine.succeed("lvcreate --type vdo -n vdo_lv -L 6G -V 12G test_vg/vdo_pool_lv") + machine.succeed("mkfs.xfs -K /dev/test_vg/vdo_lv") + machine.succeed("mkdir /mnt; mount /dev/test_vg/vdo_lv /mnt") + assert "/dev/mapper/test_vg-vdo_lv" == machine.succeed("findmnt -no SOURCE /mnt").strip() + machine.succeed("umount /mnt") + machine.succeed("vdostats") + machine.succeed("vgchange -a n") + ''; +})