···
+
{ config, lib, hostPkgs, ... }:
+
inherit (lib) mkOption types;
+
# Reifies and correctly wraps the python test driver for
+
# the respective qemu version and with or without ocr support
+
testDriver = hostPkgs.callPackage ../test-driver {
+
inherit (config) enableOCR extraPythonPackages;
+
qemu_pkg = config.qemu.package;
+
imagemagick_light = hostPkgs.imagemagick_light.override { inherit (hostPkgs) libtiff; };
+
tesseract4 = hostPkgs.tesseract4.override { enableLanguages = [ "eng" ]; };
+
vlans = map (m: m.virtualisation.vlans) (lib.attrValues config.nodes);
+
vms = map (m: m.system.build.vm) (lib.attrValues config.nodes);
+
nodesList = map (c: c.system.name) (lib.attrValues config.nodes);
+
nodesList ++ lib.optional (lib.length nodesList == 1 && !lib.elem "machine" nodesList) "machine";
+
# TODO: This is an implementation error and needs fixing
+
# the testing famework cannot legitimately restrict hostnames further
+
invalidNodeNames = lib.filter
+
(node: builtins.match "^[A-z_]([A-z0-9_]+)?$" node == null)
+
uniqueVlans = lib.unique (builtins.concatLists vlans);
+
vlanNames = map (i: "vlan${toString i}: VLan;") uniqueVlans;
+
machineNames = map (name: "${name}: Machine;") nodeHostNames;
+
if lib.length invalidNodeNames > 0 then
+
Cannot create machines out of (${lib.concatStringsSep ", " invalidNodeNames})!
+
All machines are referenced as python variables in the testing framework which will break the
+
script when special characters are used.
+
This is an IMPLEMENTATION ERROR and needs to be fixed. Meanwhile,
+
please stick to alphanumeric chars and underscores as separation.
+
lib.warnIf config.skipLint "Linting is disabled";
+
hostPkgs.runCommand "nixos-test-driver-${config.name}"
+
# inherit testName; TODO (roberth): need this?
+
] ++ lib.optionals (!config.skipTypeCheck) [ hostPkgs.mypy ];
+
testScript = config.testScriptString;
+
preferLocalBuild = true;
+
passthru = config.passthru;
+
meta = config.meta // {
+
mainProgram = "nixos-test-driver";
+
vmStartScripts=($(for i in ${toString vms}; do echo $i/bin/run-*-vm; done))
+
${lib.optionalString (!config.skipTypeCheck) ''
+
# prepend type hints so the test script can be type checked with mypy
+
cat "${../test-script-prepend.py}" >> testScriptWithTypes
+
echo "${builtins.toString machineNames}" >> testScriptWithTypes
+
echo "${builtins.toString vlanNames}" >> testScriptWithTypes
+
echo -n "$testScript" >> testScriptWithTypes
+
cat -n testScriptWithTypes
+
# set pythonpath so mypy knows where to find the imports. this requires the py.typed file.
+
export PYTHONPATH='${../test-driver}'
+
mypy --no-implicit-optional \
+
echo -n "$testScript" >> $out/test-script
+
ln -s ${testDriver}/bin/nixos-test-driver $out/bin/nixos-test-driver
+
${testDriver}/bin/generate-driver-symbols
+
${lib.optionalString (!config.skipLint) ''
+
echo -n ${lib.escapeShellArg (lib.concatStringsSep "," nodeHostNames)},
+
< ${lib.escapeShellArg "driver-symbols"}
+
)" ${hostPkgs.python3Packages.pyflakes}/bin/pyflakes $out/test-script
+
# set defaults through environment
+
# see: ./test-driver/test-driver.py argparse implementation
+
wrapProgram $out/bin/nixos-test-driver \
+
--set startScripts "''${vmStartScripts[*]}" \
+
--set testScript "$out/test-script" \
+
--set vlans '${toString vlans}' \
+
${lib.escapeShellArgs (lib.concatMap (arg: ["--add-flags" arg]) config.extraDriverArgs)}
+
description = "Script that runs the test.";
+
defaultText = lib.literalDocBook "set by the test framework";
+
description = "Nixpkgs attrset used outside the nodes.";
+
example = lib.literalExpression ''
+
import nixpkgs { inherit system config overlays; }
+
qemu.package = mkOption {
+
description = "Which qemu package to use.";
+
default = hostPkgs.qemu_test;
+
defaultText = "hostPkgs.qemu_test";
+
Whether to enable Optical Character Recognition functionality for
+
testing graphical programs.
+
extraPythonPackages = mkOption {
+
Python packages to add to the test driver.
+
The argument is a Python package set, similar to `pkgs.pythonPackages`.
+
type = types.functionTo (types.listOf types.package);
+
extraDriverArgs = mkOption {
+
Extra arguments to pass to the test driver.
+
type = types.listOf types.str;
+
skipTypeCheck = mkOption {
+
_module.args.hostPkgs = config.hostPkgs;
+
driver = withChecks driver;
+
# make available on the test runner
+
passthru.driver = config.driver;