nixos/tests: format the testing-python.nix file more consistenly

This commit is contained in:
Andreas Rammhold 2020-10-23 23:13:38 +02:00
parent 04100cd281
commit 61b09f552c
No known key found for this signature in database
GPG Key ID: E432E410B5E48C86
1 changed files with 105 additions and 97 deletions

View File

@ -7,7 +7,8 @@
# !!! See comment about args in lib/modules.nix # !!! See comment about args in lib/modules.nix
, specialArgs ? { } , specialArgs ? { }
# Modules to add to each VM # Modules to add to each VM
, extraConfigurations ? [] }: , extraConfigurations ? [ ]
}:
with pkgs; with pkgs;
@ -16,9 +17,11 @@ rec {
inherit pkgs; inherit pkgs;
mkTestDriver = let mkTestDriver =
let
testDriverScript = ./test-driver/test-driver.py; testDriverScript = ./test-driver/test-driver.py;
in qemu_pkg: stdenv.mkDerivation { in
qemu_pkg: stdenv.mkDerivation {
name = "nixos-test-driver"; name = "nixos-test-driver";
nativeBuildInputs = [ makeWrapper ]; nativeBuildInputs = [ makeWrapper ];
@ -75,7 +78,6 @@ rec {
, skipLint ? false , skipLint ? false
, ... , ...
} @ t: } @ t:
let let
# A standard store path to the vm monitor is built like this: # A standard store path to the vm monitor is built like this:
# /tmp/nix-build-vm-test-run-$name.drv-0/vm-state-machine/monitor # /tmp/nix-build-vm-test-run-$name.drv-0/vm-state-machine/monitor
@ -108,7 +110,8 @@ rec {
testDriver = mkTestDriver (if qemu_pkg == null then pkgs.qemu_test else qemu_pkg); testDriver = mkTestDriver (if qemu_pkg == null then pkgs.qemu_test else qemu_pkg);
nodes = build-vms.buildVirtualNetwork ( nodes = build-vms.buildVirtualNetwork (
t.nodes or (if t ? machine then { machine = t.machine; } else { })); t.nodes or (if t ? machine then { machine = t.machine; } else { })
);
vlans = map (m: m.config.virtualisation.vlans) (lib.attrValues nodes); vlans = map (m: m.config.virtualisation.vlans) (lib.attrValues nodes);
vms = map (m: m.config.system.build.vm) (lib.attrValues nodes); vms = map (m: m.config.system.build.vm) (lib.attrValues nodes);
@ -120,7 +123,8 @@ rec {
testDriverName = with builtins; testDriverName = with builtins;
if testNameLen > maxTestNameLen then if testNameLen > maxTestNameLen then
abort ("The name of the test '${name}' must not be longer than ${toString maxTestNameLen} " + abort
("The name of the test '${name}' must not be longer than ${toString maxTestNameLen} " +
"it's currently ${toString testNameLen} characters long.") "it's currently ${toString testNameLen} characters long.")
else else
"nixos-test-driver-${name}"; "nixos-test-driver-${name}";
@ -128,7 +132,8 @@ rec {
warn = if skipLint then lib.warn "Linting is disabled!" else lib.id; warn = if skipLint then lib.warn "Linting is disabled!" else lib.id;
in in
warn (runCommand testDriverName warn (runCommand testDriverName
{ buildInputs = [ makeWrapper]; {
buildInputs = [ makeWrapper ];
testScript = testScript'; testScript = testScript';
preferLocalBuild = true; preferLocalBuild = true;
testName = name; testName = name;
@ -172,7 +177,8 @@ rec {
nodeNames = builtins.attrNames driver.nodes; nodeNames = builtins.attrNames driver.nodes;
invalidNodeNames = lib.filter invalidNodeNames = lib.filter
(node: builtins.match "^[A-z_]([A-z0-9_]+)?$" node == null) nodeNames; (node: builtins.match "^[A-z_]([A-z0-9_]+)?$" node == null)
nodeNames;
in in
if lib.length invalidNodeNames > 0 then if lib.length invalidNodeNames > 0 then
@ -202,8 +208,10 @@ rec {
}; };
vm = build-vms.buildVM { } vm = build-vms.buildVM { }
[ machine [
{ key = "run-in-machine"; machine
{
key = "run-in-machine";
networking.hostName = "client"; networking.hostName = "client";
nix.readOnlyStore = false; nix.readOnlyStore = false;
virtualisation.writableStore = false; virtualisation.writableStore = false;