diff options
-rw-r--r-- | tests/boot-raid1.nix | 2 | ||||
-rw-r--r-- | tests/btrfs-subvolumes.nix | 2 | ||||
-rw-r--r-- | tests/cli.nix | 28 | ||||
-rw-r--r-- | tests/complex.nix | 2 | ||||
-rw-r--r-- | tests/gpt-bios-compat.nix | 2 | ||||
-rw-r--r-- | tests/lib.nix | 56 | ||||
-rw-r--r-- | tests/luks-lvm.nix | 2 | ||||
-rw-r--r-- | tests/lvm-raid.nix | 2 | ||||
-rw-r--r-- | tests/mdadm.nix | 2 | ||||
-rw-r--r-- | tests/module.nix | 28 | ||||
-rw-r--r-- | tests/simple-efi.nix | 2 | ||||
-rw-r--r-- | tests/with-lib.nix | 2 | ||||
-rw-r--r-- | tests/zfs-over-legacy.nix | 2 | ||||
-rw-r--r-- | tests/zfs.nix | 2 |
14 files changed, 115 insertions, 19 deletions
diff --git a/tests/boot-raid1.nix b/tests/boot-raid1.nix index 6d0a563..bea9adb 100644 --- a/tests/boot-raid1.nix +++ b/tests/boot-raid1.nix @@ -2,7 +2,7 @@ , makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest }: makeDiskoTest { - disko-config = import ../example/boot-raid1.nix; + 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 index e53cf34..1a62702 100644 --- a/tests/btrfs-subvolumes.nix +++ b/tests/btrfs-subvolumes.nix @@ -2,7 +2,7 @@ , makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest }: makeDiskoTest { - disko-config = import ../example/btrfs-subvolumes.nix; + 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 index cd87b3b..5fe5efa 100644 --- a/tests/complex.nix +++ b/tests/complex.nix @@ -2,7 +2,7 @@ , makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest }: makeDiskoTest { - disko-config = import ../example/complex.nix; + disko-config = ../example/complex.nix; extraConfig = { fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this! }; diff --git a/tests/gpt-bios-compat.nix b/tests/gpt-bios-compat.nix index d9317f9..e19c49a 100644 --- a/tests/gpt-bios-compat.nix +++ b/tests/gpt-bios-compat.nix @@ -2,7 +2,7 @@ , makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest }: makeDiskoTest { - disko-config = import ../example/gpt-bios-compat.nix; + disko-config = ../example/gpt-bios-compat.nix; extraTestScript = '' machine.succeed("mountpoint /"); ''; diff --git a/tests/lib.nix b/tests/lib.nix index b3b3009..b9e75dd 100644 --- a/tests/lib.nix +++ b/tests/lib.nix @@ -12,6 +12,7 @@ , grub-devices ? [ "nodev" ] , efi ? true , enableOCR ? false + , testMode ? "direct" # can be one of direct module cli }: let lib = pkgs.lib; @@ -21,13 +22,21 @@ inherit (pkgs) system; }; disks = [ "/dev/vda" "/dev/vdb" "/dev/vdc" "/dev/vdd" "/dev/vde" "/dev/vdf" ]; - tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. { }).create (disko-config { disks = builtins.tail disks; inherit lib; })); - tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. { }).mount (disko-config { disks = builtins.tail disks; inherit lib; })); - tsp-config = (pkgs.callPackage ../. { }).config (disko-config { inherit disks; inherit lib; }); - num-disks = builtins.length (lib.attrNames (disko-config { inherit lib; }).disk); + 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; }); + num-disks = builtins.length (lib.attrNames (import disko-config { inherit lib; }).disk); installed-system = { modulesPath, ... }: { imports = [ - tsp-config + (lib.optionalAttrs (testMode == "direct" || testMode == "cli") tsp-config) + (lib.optionalAttrs (testMode == "module") { + imports = [ ../module.nix ]; + disko = { + addScripts = false; + enableConfig = true; + devices = import disko-config { inherit disks lib; }; + }; + }) (modulesPath + "/testing/test-instrumentation.nix") (modulesPath + "/profiles/qemu-guest.nix") (modulesPath + "/profiles/minimal.nix") @@ -63,6 +72,21 @@ inherit enableOCR; nodes.machine = { config, pkgs, modulesPath, ... }: { imports = [ + (lib.optionalAttrs (testMode == "module") { + imports = [ ../module.nix ]; + disko = { + addScripts = true; + 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 @@ -97,9 +121,25 @@ machine.start() machine.succeed("echo -n 'secret' > /tmp/secret.key") - machine.succeed("${tsp-create}") - machine.succeed("${tsp-mount}") - machine.succeed("${tsp-mount}") # verify that the command is idempotent + ${lib.optionalString (testMode == "direct") '' + machine.succeed("${tsp-create}") + machine.succeed("${tsp-mount}") + machine.succeed("${tsp-mount}") # verify that the command is idempotent + ''} + ${lib.optionalString (testMode == "module") '' + machine.succeed("disko-create") + machine.succeed("disko-mount") + machine.succeed("disko-mount") # verify that the command is idempotent + ''} + ${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("${tsp-create}") + machine.succeed("${tsp-mount}") + machine.succeed("${tsp-mount}") # verify that the command is idempotent + ''} # mount nix-store in /mnt machine.succeed("mkdir -p /mnt/nix/store") diff --git a/tests/luks-lvm.nix b/tests/luks-lvm.nix index 1a3dc66..05d3362 100644 --- a/tests/luks-lvm.nix +++ b/tests/luks-lvm.nix @@ -2,7 +2,7 @@ , makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest }: makeDiskoTest { - disko-config = import ../example/luks-lvm.nix; + disko-config = ../example/luks-lvm.nix; extraTestScript = '' machine.succeed("cryptsetup isLuks /dev/vda2"); machine.succeed("mountpoint /home"); diff --git a/tests/lvm-raid.nix b/tests/lvm-raid.nix index 1249b7b..cc73e61 100644 --- a/tests/lvm-raid.nix +++ b/tests/lvm-raid.nix @@ -2,7 +2,7 @@ , makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest }: makeDiskoTest { - disko-config = import ../example/lvm-raid.nix; + disko-config = ../example/lvm-raid.nix; extraTestScript = '' machine.succeed("mountpoint /home"); ''; diff --git a/tests/mdadm.nix b/tests/mdadm.nix index 74a7d5d..2b4442a 100644 --- a/tests/mdadm.nix +++ b/tests/mdadm.nix @@ -2,7 +2,7 @@ , makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest }: makeDiskoTest { - disko-config = import ../example/mdadm.nix; + disko-config = ../example/mdadm.nix; extraTestScript = '' machine.succeed("test -b /dev/md/raid1"); machine.succeed("mountpoint /"); 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/simple-efi.nix b/tests/simple-efi.nix index 2d3b92d..920920f 100644 --- a/tests/simple-efi.nix +++ b/tests/simple-efi.nix @@ -2,7 +2,7 @@ , makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest }: makeDiskoTest { - disko-config = import ../example/simple-efi.nix; + disko-config = ../example/simple-efi.nix; extraTestScript = '' machine.succeed("mountpoint /"); ''; diff --git a/tests/with-lib.nix b/tests/with-lib.nix index e94cf00..18c422b 100644 --- a/tests/with-lib.nix +++ b/tests/with-lib.nix @@ -2,7 +2,7 @@ , makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest }: makeDiskoTest { - disko-config = import ../example/with-lib.nix; + disko-config = ../example/with-lib.nix; extraTestScript = '' machine.succeed("mountpoint /"); ''; diff --git a/tests/zfs-over-legacy.nix b/tests/zfs-over-legacy.nix index 50e3796..09505e5 100644 --- a/tests/zfs-over-legacy.nix +++ b/tests/zfs-over-legacy.nix @@ -2,7 +2,7 @@ , makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest }: makeDiskoTest { - disko-config = import ../example/zfs-over-legacy.nix; + 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 index 78b64bd..d88070e 100644 --- a/tests/zfs.nix +++ b/tests/zfs.nix @@ -2,7 +2,7 @@ , makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest }: makeDiskoTest { - disko-config = import ../example/zfs.nix; + disko-config = ../example/zfs.nix; extraConfig = { fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this! }; |