summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorlassulus <lassulus@lassul.us>2022-09-30 12:55:28 +0200
committerlassulus <lassulus@lassul.us>2022-10-02 16:41:02 +0200
commit9f7f23abdb161578316d94f45528fbf47982f4d9 (patch)
tree92134db7dbe059a7163571e50045b42798a2aea4 /tests
parenta215a1975938fbc04ae8fb14e474304f3200e15c (diff)
add nixos tests for disko.config, extend/fix existing tests
Diffstat (limited to 'tests')
-rw-r--r--tests/boot-raid1.nix10
-rw-r--r--tests/btrfs-subvolumes.nix4
-rw-r--r--tests/complex.nix17
-rw-r--r--tests/default.nix3
-rw-r--r--tests/gpt-bios-compat.nix5
-rw-r--r--tests/lib.nix117
-rw-r--r--tests/luks-lvm.nix9
-rw-r--r--tests/lvm-raid.nix4
-rw-r--r--tests/mdadm.nix4
-rw-r--r--tests/zfs-over-legacy.nix5
-rw-r--r--tests/zfs.nix10
11 files changed, 147 insertions, 41 deletions
diff --git a/tests/boot-raid1.nix b/tests/boot-raid1.nix
new file mode 100644
index 0000000..6d0a563
--- /dev/null
+++ b/tests/boot-raid1.nix
@@ -0,0 +1,10 @@
+{ pkgs ? (import <nixpkgs> { })
+, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest
+}:
+makeDiskoTest {
+ disko-config = import ../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 3ff4386..e53cf34 100644
--- a/tests/btrfs-subvolumes.nix
+++ b/tests/btrfs-subvolumes.nix
@@ -4,8 +4,8 @@
makeDiskoTest {
disko-config = import ../example/btrfs-subvolumes.nix;
extraTestScript = ''
- machine.succeed("test -e /mnt/test");
- machine.succeed("btrfs subvolume list /mnt | grep -qs 'path test$'");
+ machine.succeed("test -e /test");
+ machine.succeed("btrfs subvolume list / | grep -qs 'path test$'");
'';
}
diff --git a/tests/complex.nix b/tests/complex.nix
index 3fa861e..cd87b3b 100644
--- a/tests/complex.nix
+++ b/tests/complex.nix
@@ -3,16 +3,23 @@
}:
makeDiskoTest {
disko-config = import ../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 /mnt");
- machine.succeed("mountpoint /mnt/zfs_fs");
- machine.succeed("mountpoint /mnt/zfs_legacy_fs");
- machine.succeed("mountpoint /mnt/ext4onzfs");
- machine.succeed("mountpoint /mnt/ext4_on_lvm");
+ 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
index 496a935..c10cf76 100644
--- a/tests/default.nix
+++ b/tests/default.nix
@@ -1,9 +1,10 @@
{ 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; }).makeDiskoTest;
+ makeDiskoTest = (pkgs.callPackage ./lib.nix { inherit makeTest eval-config; }).makeDiskoTest;
evalTest = name: configFile: let
disko-config = import configFile;
diff --git a/tests/gpt-bios-compat.nix b/tests/gpt-bios-compat.nix
index df35335..d9317f9 100644
--- a/tests/gpt-bios-compat.nix
+++ b/tests/gpt-bios-compat.nix
@@ -4,7 +4,8 @@
makeDiskoTest {
disko-config = import ../example/gpt-bios-compat.nix;
extraTestScript = ''
- machine.succeed("mountpoint /mnt");
- machine.succeed("grub-install --target=i386-pc /dev/vdb");
+ machine.succeed("mountpoint /");
'';
+ efi = false;
+ grub-devices = [ "/dev/vdb" ];
}
diff --git a/tests/lib.nix b/tests/lib.nix
index 0bcba2b..fb9d1e9 100644
--- a/tests/lib.nix
+++ b/tests/lib.nix
@@ -1,12 +1,17 @@
{ 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
+ , extraTestScript ? ""
+ , bootCommands ? ""
, extraConfig ? { }
+ , grub-devices ? [ "nodev" ]
+ , efi ? true
+ , enableOCR ? false
}:
let
lib = pkgs.lib;
@@ -15,33 +20,107 @@
inherit pkgs;
inherit (pkgs) system;
};
- tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. { }).create disko-config);
- tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. { }).mount disko-config);
- num-disks = builtins.length (lib.attrNames disko-config.disk);
+ 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; }));
+ tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. { }).mount (disko-config { disks = builtins.tail disks; }));
+ tsp-config = (pkgs.callPackage ../. { }).config (disko-config { inherit disks; });
+ num-disks = builtins.length (lib.attrNames (disko-config {}).disk);
+ installed-system = { modulesPath, ... }: {
+ imports = [
+ tsp-config
+ (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 ];
+ system = "x86_64-linux";
+ }).config.system.build.toplevel;
in
makeTest' {
name = "disko";
- nodes.machine =
- { config, pkgs, modulesPath, ... }:
+ inherit enableOCR;
+ nodes.machine = { config, pkgs, modulesPath, ... }: {
+ imports = [
+ (modulesPath + "/profiles/base.nix")
+ (modulesPath + "/profiles/minimal.nix")
+ extraConfig
+ ];
- {
- imports = [
- (modulesPath + "/profiles/installation-device.nix")
- (modulesPath + "/profiles/base.nix")
- ];
+ # speed-up eval
+ documentation.enable = false;
- # speed-up eval
- documentation.enable = false;
+ nix.settings = {
+ substituters = lib.mkForce [];
+ hashed-mirrors = null;
+ connect-timeout = 1;
+ };
- virtualisation.emptyDiskImages = builtins.genList (_: 512) num-disks;
- } // extraConfig;
+ virtualisation.emptyDiskImages = builtins.genList (_: 4096) num-disks;
+ };
testScript = ''
- machine.succeed("echo 'secret' > /tmp/secret.key");
- machine.succeed("${tsp-create}");
- machine.succeed("${tsp-mount}");
- machine.succeed("${tsp-mount}"); # verify that the command is idempotent
+ 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")
+ 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")
+ 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
index d59f3f4..1a3dc66 100644
--- a/tests/luks-lvm.nix
+++ b/tests/luks-lvm.nix
@@ -4,7 +4,12 @@
makeDiskoTest {
disko-config = import ../example/luks-lvm.nix;
extraTestScript = ''
- machine.succeed("cryptsetup isLuks /dev/vdb2");
- machine.succeed("mountpoint /mnt/home");
+ 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
index 102dcd7..1249b7b 100644
--- a/tests/lvm-raid.nix
+++ b/tests/lvm-raid.nix
@@ -4,9 +4,9 @@
makeDiskoTest {
disko-config = import ../example/lvm-raid.nix;
extraTestScript = ''
- machine.succeed("mountpoint /mnt/home");
+ machine.succeed("mountpoint /home");
'';
extraConfig = {
- boot.kernelModules = [ "dm-raid" "dm-mirror" ];
+ boot.kernelModules = [ "dm-raid0" "dm-mirror" ];
};
}
diff --git a/tests/mdadm.nix b/tests/mdadm.nix
index bd57a00..74a7d5d 100644
--- a/tests/mdadm.nix
+++ b/tests/mdadm.nix
@@ -5,6 +5,8 @@ makeDiskoTest {
disko-config = import ../example/mdadm.nix;
extraTestScript = ''
machine.succeed("test -b /dev/md/raid1");
- machine.succeed("mountpoint /mnt/raid");
+ machine.succeed("mountpoint /");
'';
+ efi = false;
+ grub-devices = [ "/dev/vdb" "/dev/vdc" ];
}
diff --git a/tests/zfs-over-legacy.nix b/tests/zfs-over-legacy.nix
index 13f86a9..50e3796 100644
--- a/tests/zfs-over-legacy.nix
+++ b/tests/zfs-over-legacy.nix
@@ -4,9 +4,8 @@
makeDiskoTest {
disko-config = import ../example/zfs-over-legacy.nix;
extraTestScript = ''
- machine.succeed("test -e /mnt/zfs_fs");
- machine.succeed("mountpoint /mnt");
- machine.succeed("mountpoint /mnt/zfs_fs");
+ machine.succeed("test -e /zfs_fs");
+ machine.succeed("mountpoint /zfs_fs");
'';
}
diff --git a/tests/zfs.nix b/tests/zfs.nix
index 5940c4d..78b64bd 100644
--- a/tests/zfs.nix
+++ b/tests/zfs.nix
@@ -3,6 +3,9 @@
}:
makeDiskoTest {
disko-config = import ../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");
@@ -19,9 +22,8 @@ makeDiskoTest {
assert_property("zroot/zfs_testvolume", "volsize", "10M")
assert_property("zroot/zfs_unmounted_fs", "mountpoint", "none")
- machine.succeed("mountpoint /mnt");
- machine.succeed("mountpoint /mnt/zfs_fs");
- machine.succeed("mountpoint /mnt/zfs_legacy_fs");
- machine.succeed("mountpoint /mnt/ext4onzfs");
+ machine.succeed("mountpoint /zfs_fs");
+ machine.succeed("mountpoint /zfs_legacy_fs");
+ machine.succeed("mountpoint /ext4onzfs");
'';
}