2021-03-25 20:29:24 +00:00
|
|
|
{ nixpkgs ? <nixpkgs>
|
|
|
|
, system ? builtins.currentSystem
|
|
|
|
, processManagerModules ? {}
|
|
|
|
, profileSettingModules ? {}
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
pkgs = import nixpkgs { inherit system; };
|
|
|
|
|
|
|
|
tools = import ../../tools {
|
|
|
|
inherit pkgs system;
|
|
|
|
};
|
|
|
|
|
2023-09-20 16:36:07 +00:00
|
|
|
testSystemVariantForProcessManager = {name, processManager, profileSettings, exprFile, extraParams ? {}, nixosConfig ? null, systemPackages ? [], initialTests ? null, readiness ? null, tests ? null, postTests ? null}:
|
2021-03-25 20:29:24 +00:00
|
|
|
let
|
|
|
|
processManagerModule = builtins.getAttr processManager processManagerModules;
|
|
|
|
|
|
|
|
processManagerSettings = import processManagerModule {
|
2021-03-31 20:41:48 +00:00
|
|
|
inherit profileSettings exprFile extraParams pkgs system tools;
|
2021-03-25 20:29:24 +00:00
|
|
|
};
|
|
|
|
|
2021-04-04 12:51:03 +00:00
|
|
|
processesFun = import exprFile;
|
|
|
|
processesFormalArgs = builtins.functionArgs processesFun;
|
|
|
|
|
|
|
|
processesArgs = builtins.intersectAttrs processesFormalArgs ({
|
2021-03-25 20:29:24 +00:00
|
|
|
inherit pkgs system processManager;
|
2021-04-04 15:50:09 +00:00
|
|
|
} // processManagerSettings.params // extraParams);
|
2021-04-04 12:51:03 +00:00
|
|
|
|
|
|
|
processes = processesFun processesArgs;
|
2021-03-25 20:29:24 +00:00
|
|
|
in
|
|
|
|
with import "${nixpkgs}/nixos/lib/testing-python.nix" { inherit system; };
|
|
|
|
|
|
|
|
makeTest {
|
2023-09-20 16:36:07 +00:00
|
|
|
inherit name;
|
|
|
|
|
|
|
|
nodes.machine =
|
2021-03-25 20:29:24 +00:00
|
|
|
{pkgs, lib, ...}:
|
|
|
|
|
|
|
|
{
|
|
|
|
imports =
|
|
|
|
profileSettings.nixosModules
|
|
|
|
++ processManagerSettings.nixosModules
|
|
|
|
++ lib.optional (nixosConfig != null) nixosConfig;
|
|
|
|
|
2022-03-05 12:52:30 +00:00
|
|
|
virtualisation.additionalPaths = processManagerSettings.additionalPaths;
|
2021-03-25 20:29:24 +00:00
|
|
|
|
|
|
|
nix.extraOptions = ''
|
|
|
|
substitute = false
|
|
|
|
'';
|
|
|
|
|
|
|
|
environment.systemPackages = [
|
|
|
|
pkgs.dysnomia
|
|
|
|
tools.common
|
|
|
|
]
|
|
|
|
++ processManagerSettings.systemPackages
|
|
|
|
++ systemPackages;
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript =
|
|
|
|
''
|
|
|
|
start_all()
|
|
|
|
''
|
|
|
|
+ processManagerSettings.deployProcessManager
|
|
|
|
+ processManagerSettings.deploySystem
|
2021-04-19 18:15:49 +00:00
|
|
|
+ pkgs.lib.optionalString (initialTests != null) (initialTests (processManagerSettings.params // { inherit processes; }))
|
2021-03-25 20:29:24 +00:00
|
|
|
|
|
|
|
# Execute readiness check for all process instances
|
2021-04-06 20:36:10 +00:00
|
|
|
+ pkgs.lib.optionalString (readiness != null)
|
|
|
|
(pkgs.lib.concatMapStrings (instanceName:
|
|
|
|
let
|
|
|
|
instance = builtins.getAttr instanceName processes;
|
|
|
|
in
|
|
|
|
readiness ({ inherit instanceName instance; } // processManagerSettings.params)
|
|
|
|
) (builtins.attrNames processes))
|
2021-03-25 20:29:24 +00:00
|
|
|
|
|
|
|
# Execute tests for all process instances
|
2021-04-06 20:36:10 +00:00
|
|
|
+ pkgs.lib.optionalString (tests != null)
|
|
|
|
(pkgs.lib.concatMapStrings (instanceName:
|
|
|
|
let
|
|
|
|
instance = builtins.getAttr instanceName processes;
|
|
|
|
in
|
2023-09-20 16:36:07 +00:00
|
|
|
tests ({ inherit instanceName instance processManager; } // processManagerSettings.params)
|
2021-04-06 20:36:10 +00:00
|
|
|
) (builtins.attrNames processes))
|
|
|
|
|
2021-04-19 18:15:49 +00:00
|
|
|
+ pkgs.lib.optionalString (postTests != null) (postTests (processManagerSettings.params // { inherit processes; }));
|
2021-03-25 20:29:24 +00:00
|
|
|
};
|
|
|
|
in
|
2023-09-20 16:36:07 +00:00
|
|
|
{ name
|
|
|
|
, processManagers
|
2021-03-25 20:29:24 +00:00
|
|
|
, profiles
|
|
|
|
, exprFile
|
2021-03-31 20:41:48 +00:00
|
|
|
, extraParams ? {}
|
2021-03-25 20:29:24 +00:00
|
|
|
, nixosConfig ? null
|
|
|
|
, systemPackages ? []
|
2021-03-30 17:56:27 +00:00
|
|
|
, initialTests ? null
|
2021-04-06 20:36:10 +00:00
|
|
|
, readiness ? null
|
|
|
|
, tests ? null
|
|
|
|
, postTests ? null
|
2021-03-25 20:29:24 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
pkgs.lib.genAttrs profiles (profile:
|
|
|
|
let
|
|
|
|
profileSettingsModule = builtins.getAttr profile profileSettingModules;
|
|
|
|
profileSettings = import profileSettingsModule;
|
|
|
|
in
|
|
|
|
pkgs.lib.genAttrs processManagers (processManager:
|
|
|
|
testSystemVariantForProcessManager {
|
2023-09-20 16:36:07 +00:00
|
|
|
inherit name processManager profileSettings exprFile extraParams nixosConfig systemPackages initialTests readiness tests postTests;
|
2021-03-25 20:29:24 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|