mirror of
https://github.com/nix-community/disko.git
synced 2026-12-05 07:23:28 +01:00
tests: refactor into testlib; change config devices via fold
This commit is contained in:
1 parent
f6649d69d9
commit
cd38be93db
2 files changed
+50
-16
No files matched your search
@@ -1,8 +1,8 @@
|
|||||||
{ disks ? [ "/dev/vdb" ], ... }: {
|
{ ... }: {
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
vdb = {
|
vdb = {
|
||||||
device = builtins.elemAt disks 0;
|
device = "/dev/disk/by-id/some-disk-id";
|
||||||
type = "disk";
|
type = "disk";
|
||||||
content = {
|
content = {
|
||||||
type = "gpt";
|
type = "gpt";
|
||||||
|
|||||||
+48
-14
@@ -1,9 +1,36 @@
|
|||||||
{ pkgs ? (import <nixpkgs> { })
|
{ pkgs ? (import <nixpkgs> { })
|
||||||
|
, lib ? pkgs.lib
|
||||||
, makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix>
|
, makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix>
|
||||||
, eval-config ? import <nixpkgs/nixos/lib/eval-config.nix>
|
, eval-config ? import <nixpkgs/nixos/lib/eval-config.nix>
|
||||||
, ...
|
, ...
|
||||||
}:
|
}:
|
||||||
{
|
|
||||||
|
let
|
||||||
|
diskoLib = import ../lib { inherit pkgs lib; };
|
||||||
|
testlib = {
|
||||||
|
# this takes a disko toplevel config and changes the disk devices so we can run them inside the qemu test runner
|
||||||
|
# basically changes all the disk.*.devices to something like /dev/vda or /dev/vdb etc.
|
||||||
|
prepareDiskoConfig = toplevel: devices:
|
||||||
|
let
|
||||||
|
preparedDisks = lib.foldlAttrs (acc: n: v: {
|
||||||
|
devices = lib.tail acc.devices;
|
||||||
|
value = acc.value // {
|
||||||
|
${n} = v // {
|
||||||
|
device = lib.head acc.devices;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}) {
|
||||||
|
inherit devices;
|
||||||
|
value = {};
|
||||||
|
} toplevel.disko.devices.disk;
|
||||||
|
in
|
||||||
|
toplevel // {
|
||||||
|
disko.devices = toplevel.disko.devices // {
|
||||||
|
disk = preparedDisks.value;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# This is the test generator for a disko test
|
||||||
makeDiskoTest =
|
makeDiskoTest =
|
||||||
{ name
|
{ name
|
||||||
, disko-config
|
, disko-config
|
||||||
@@ -17,19 +44,24 @@
|
|||||||
, testBoot ? true # if we actually want to test booting or just create/mount
|
, testBoot ? true # if we actually want to test booting or just create/mount
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
lib = pkgs.lib;
|
|
||||||
makeTest' = args:
|
makeTest' = args:
|
||||||
makeTest args {
|
makeTest args {
|
||||||
inherit pkgs;
|
inherit pkgs;
|
||||||
inherit (pkgs) system;
|
inherit (pkgs) system;
|
||||||
};
|
};
|
||||||
disks = [ "/dev/vda" "/dev/vdb" "/dev/vdc" "/dev/vdd" "/dev/vde" "/dev/vdf" ];
|
devices = [ "/dev/vda" "/dev/vdb" "/dev/vdc" "/dev/vdd" "/dev/vde" "/dev/vdf"];
|
||||||
|
# for installation we skip /dev/vda because it is the test runner disk
|
||||||
|
testConfigInstall = testlib.prepareDiskoConfig (import disko-config { inherit lib; }) (lib.tail devices);
|
||||||
|
# we need to shift the disks by one because the first disk is the /dev/vda of the test runner
|
||||||
|
# so /dev/vdb becomes /dev/vda etc.
|
||||||
|
testConfigBooted = testlib.prepareDiskoConfig (import disko-config { inherit lib; }) devices;
|
||||||
|
|
||||||
tsp-generator = pkgs.callPackage ../. { checked = true; };
|
tsp-generator = pkgs.callPackage ../. { checked = true; };
|
||||||
tsp-create = (tsp-generator.createScript (import disko-config { disks = builtins.tail disks; inherit lib; })) pkgs;
|
tsp-create = (tsp-generator.createScript testConfigInstall) pkgs;
|
||||||
tsp-mount = (tsp-generator.mountScript (import disko-config { disks = builtins.tail disks; inherit lib; })) pkgs;
|
tsp-mount = (tsp-generator.mountScript testConfigInstall) pkgs;
|
||||||
tsp-disko = (tsp-generator.diskoScript (import disko-config { disks = builtins.tail disks; inherit lib; })) pkgs;
|
tsp-disko = (tsp-generator.diskoScript testConfigInstall) pkgs;
|
||||||
tsp-config = tsp-generator.config (import disko-config { inherit disks; inherit lib; });
|
tsp-config = tsp-generator.config testConfigBooted;
|
||||||
num-disks = builtins.length (lib.attrNames (import disko-config { inherit lib; }).disko.devices.disk);
|
num-disks = builtins.length (lib.attrNames testConfigBooted.disko.devices.disk);
|
||||||
installed-system = { modulesPath, ... }: {
|
installed-system = { modulesPath, ... }: {
|
||||||
imports = [
|
imports = [
|
||||||
(lib.optionalAttrs (testMode == "direct" || testMode == "cli") tsp-config)
|
(lib.optionalAttrs (testMode == "direct" || testMode == "cli") tsp-config)
|
||||||
@@ -37,7 +69,7 @@
|
|||||||
disko.enableConfig = true;
|
disko.enableConfig = true;
|
||||||
imports = [
|
imports = [
|
||||||
../module.nix
|
../module.nix
|
||||||
(import disko-config { inherit disks lib; })
|
testConfigBooted
|
||||||
];
|
];
|
||||||
})
|
})
|
||||||
(modulesPath + "/testing/test-instrumentation.nix")
|
(modulesPath + "/testing/test-instrumentation.nix")
|
||||||
@@ -85,14 +117,14 @@
|
|||||||
disko = {
|
disko = {
|
||||||
enableConfig = false;
|
enableConfig = false;
|
||||||
checkScripts = true;
|
checkScripts = true;
|
||||||
devices = (import disko-config { disks = builtins.tail disks; inherit lib; }).disko.devices;
|
devices = testConfigInstall.disko.devices;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
(lib.optionalAttrs (testMode == "cli") {
|
(lib.optionalAttrs (testMode == "cli") {
|
||||||
imports = [ (modulesPath + "/installer/cd-dvd/channel.nix") ];
|
imports = [ (modulesPath + "/installer/cd-dvd/channel.nix") ];
|
||||||
system.extraDependencies = [
|
system.extraDependencies = [
|
||||||
((pkgs.callPackage ../. { checked = true; }).createScript (import disko-config { disks = builtins.tail disks; inherit lib; }) pkgs)
|
((pkgs.callPackage ../. { checked = true; }).createScript testConfigInstall pkgs)
|
||||||
((pkgs.callPackage ../. { checked = true; }).mountScript (import disko-config { disks = builtins.tail disks; inherit lib; }) pkgs)
|
((pkgs.callPackage ../. { checked = true; }).mountScript testConfigInstall pkgs)
|
||||||
];
|
];
|
||||||
})
|
})
|
||||||
(modulesPath + "/profiles/base.nix")
|
(modulesPath + "/profiles/base.nix")
|
||||||
@@ -134,8 +166,8 @@
|
|||||||
return machine
|
return machine
|
||||||
|
|
||||||
machine.start()
|
machine.start()
|
||||||
machine.succeed("echo -n 'secretsecret' > /tmp/secret.key")
|
|
||||||
machine.succeed("echo -n 'additionalSecret' > /tmp/additionalSecret.key")
|
machine.succeed("echo -n 'additionalSecret' > /tmp/additionalSecret.key")
|
||||||
|
machine.succeed("echo -n 'secretsecret' > /tmp/secret.key")
|
||||||
${lib.optionalString (testMode == "direct") ''
|
${lib.optionalString (testMode == "direct") ''
|
||||||
machine.succeed("${tsp-create}")
|
machine.succeed("${tsp-create}")
|
||||||
machine.succeed("${tsp-mount}")
|
machine.succeed("${tsp-mount}")
|
||||||
@@ -188,4 +220,6 @@
|
|||||||
${extraTestScript}
|
${extraTestScript}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
|
in testlib
|
||||||
|
|
||||||
Reference in new issue
Block a user