Inventory: warning on undefined tags, instead of error.

This commit is contained in:
Johannes Kirschbauer
2025-01-08 11:05:13 +01:00
committed by hsjobeki
parent 037549ba38
commit 85d03f106b
3 changed files with 8 additions and 5 deletions

View File

@@ -28,10 +28,10 @@ let
);
in
if tagMembers == [ ] then
throw ''
lib.warn ''
inventory.services.${serviceName}.${instanceName}: - ${roleName} tags: no machine with tag '${tag}' found.
Available tags: ${builtins.toJSON (lib.unique availableTags)}
''
'' []
else
acc ++ tagMembers
) [ ] members.tags or [ ]);

View File

@@ -42,7 +42,7 @@ in
checks = {
lib-inventory-eval = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
export HOME="$(realpath .)"
export NIX_ABORT_ON_WARN=1
nix-unit --eval-store "$HOME" \
--extra-experimental-features flakes \
${inputOverrides} \

View File

@@ -178,6 +178,8 @@ in
msg = "Roles roleXYZ are not defined in the service borgbackup.";
};
};
# Needs NIX_ABORT_ON_WARN=1
# So the lib.warn is turned into abort
test_inventory_tag_doesnt_exist =
let
configs = buildInventory {
@@ -201,8 +203,9 @@ in
{
expr = configs;
expectedError = {
type = "ThrownError";
msg = "no machine with tag '\\w+' found";
type = "Error";
# TODO: Add warning matching in nix-unit
msg = ".*";
};
};
test_inventory_disabled_service =