mirror of
https://github.com/nix-community/disko
synced 2024-11-10 06:14:14 +00:00
add tests for module and cli
This commit is contained in:
parent
f1531fb4f3
commit
fec0b14fb5
14 changed files with 115 additions and 19 deletions
|
@ -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");
|
||||
|
|
|
@ -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$'");
|
||||
|
|
28
tests/cli.nix
Normal file
28
tests/cli.nix
Normal file
|
@ -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" ];
|
||||
};
|
||||
}
|
|
@ -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!
|
||||
};
|
||||
|
|
|
@ -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 /");
|
||||
'';
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
'';
|
||||
|
|
|
@ -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 /");
|
||||
|
|
28
tests/module.nix
Normal file
28
tests/module.nix
Normal file
|
@ -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" ];
|
||||
};
|
||||
}
|
|
@ -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 /");
|
||||
'';
|
||||
|
|
|
@ -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 /");
|
||||
'';
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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!
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue