nixos/test-driver: provide all machines from read-only allMachines option
This commit is contained in:
@@ -38,19 +38,11 @@ let
|
||||
|
||||
vmMachineNames = map (c: c.system.name) (lib.attrValues config.nodes);
|
||||
containerMachineNames = map (c: c.system.name) (lib.attrValues config.containers);
|
||||
allMachineNames =
|
||||
let
|
||||
overlappingNames = lib.intersectLists vmMachineNames containerMachineNames;
|
||||
in
|
||||
assert (
|
||||
lib.asserts.assertMsg (overlappingNames == [ ])
|
||||
"Names of QEMU VM nodes and systemd-nspawn containers must not overlap. Overlapping names: ${toString overlappingNames}"
|
||||
);
|
||||
vmMachineNames ++ containerMachineNames;
|
||||
|
||||
theOnlyMachine =
|
||||
let
|
||||
exactlyOneMachine = lib.length (lib.attrValues config.nodes) == 1;
|
||||
allMachineNames = map (c: c.system.name) (lib.attrValues config.allMachines);
|
||||
in
|
||||
lib.optional (exactlyOneMachine && !lib.elem "machine" allMachineNames) "machine";
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
{
|
||||
containers,
|
||||
nodes,
|
||||
testModuleArgs@{
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
@@ -24,16 +22,9 @@ let
|
||||
zipLists
|
||||
;
|
||||
|
||||
nodesAndContainers =
|
||||
let
|
||||
nodeNames = lib.attrNames nodes;
|
||||
containerNames = lib.attrNames containers;
|
||||
conflictingNames = lib.intersectLists nodeNames containerNames;
|
||||
message = "`nodes` and `containers` must have unique names. Conflicting names: ${lib.concatStringsSep " " conflictingNames}";
|
||||
in
|
||||
lib.throwIfNot (builtins.length conflictingNames == 0) message (nodes // containers);
|
||||
|
||||
nodeNumbers = listToAttrs (zipListsWith nameValuePair (attrNames nodesAndContainers) (range 1 254));
|
||||
nodeNumbers = listToAttrs (
|
||||
zipListsWith nameValuePair (attrNames testModuleArgs.config.allMachines) (range 1 254)
|
||||
);
|
||||
|
||||
networkModule =
|
||||
{ config, ... }:
|
||||
@@ -93,7 +84,7 @@ let
|
||||
+ optionalString (
|
||||
config.networking.primaryIPv6Address != ""
|
||||
) "${config.networking.primaryIPv6Address} ${hostnames}"
|
||||
) nodesAndContainers;
|
||||
) testModuleArgs.config.allMachines;
|
||||
};
|
||||
|
||||
in
|
||||
|
||||
@@ -176,6 +176,25 @@ in
|
||||
'';
|
||||
};
|
||||
|
||||
allMachines = mkOption {
|
||||
readOnly = true;
|
||||
internal = true;
|
||||
description = ''
|
||||
Basically a merge of [{option}`nodes`](#test-opt-nodes) and [{option}`containers`](#test-opt-containers).
|
||||
|
||||
This ensures that there are no name collisions between nodes and containers.
|
||||
'';
|
||||
default =
|
||||
let
|
||||
overlappingNames = lib.intersectLists (lib.attrNames config.nodes) (
|
||||
lib.attrNames config.containers
|
||||
);
|
||||
in
|
||||
lib.throwIfNot (overlappingNames == [ ])
|
||||
"The following names are used in both `nodes` and `containers`: ${lib.concatStringsSep ", " overlappingNames}"
|
||||
(config.nodes // config.containers);
|
||||
};
|
||||
|
||||
defaults = mkOption {
|
||||
description = ''
|
||||
NixOS configuration that is applied to all [{option}`nodes`](#test-opt-nodes) and [{option}`containers`](#test-opt-containers).
|
||||
|
||||
Reference in New Issue
Block a user