From 04946028b7a38836834cb2e78f5fb17b6a2398b4 Mon Sep 17 00:00:00 2001 From: Jathavedhan M Date: Wed, 15 Apr 2026 15:35:02 +0530 Subject: [PATCH] fix: respect user-configured strict option in _set_composite_vars Previously, `_set_composable_vars` hardcoded `strict=True` for the `_set_composite_vars` call while correctly passing the user-configured value to `_add_host_to_composed_groups` and `_add_host_to_keyed_groups`. This meant `strict: false` had no effect on compose expressions. Pass `strict=strict` consistently to all three calls, matching the behavior of Ansible's own `constructed` inventory plugin. Adds a unit test verifying that compose errors are suppressed when `strict: false` is configured. Signed-off-by: Jathavedhan M Assisted-by: Claude --- plugins/inventory/kubevirt.py | 2 +- .../test_kubevirt_set_composable_vars.py | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/plugins/inventory/kubevirt.py b/plugins/inventory/kubevirt.py index aa2e5bc..5cc3415 100644 --- a/plugins/inventory/kubevirt.py +++ b/plugins/inventory/kubevirt.py @@ -920,7 +920,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): trust_compose_groups(self.get_option("compose")), hostvars, hostname, - strict=True, + strict=strict, ) self._add_host_to_composed_groups( trust_compose_groups(self.get_option("groups")), diff --git a/tests/unit/plugins/inventory/blackbox/test_kubevirt_set_composable_vars.py b/tests/unit/plugins/inventory/blackbox/test_kubevirt_set_composable_vars.py index 8978e3c..413871b 100644 --- a/tests/unit/plugins/inventory/blackbox/test_kubevirt_set_composable_vars.py +++ b/tests/unit/plugins/inventory/blackbox/test_kubevirt_set_composable_vars.py @@ -61,3 +61,30 @@ def test_set_composable_vars( assert host in groups["block_migratable_vmis"]["children"] assert "fedora_40" in groups assert host in groups["fedora_40"]["children"] + + +def test_set_composable_vars_strict_false_ignores_compose_errors( + inventory, + groups, + hosts, +): + inventory._options = { + "compose": {"custom_label": "vmi_nonexistent_label"}, + "groups": {}, + "keyed_groups": [], + "strict": False, + } + inventory._populate_inventory( + { + "default_hostname": "test", + "cluster_domain": "test.com", + "namespaces": { + "default": {"vms": [], "vmis": [VMI], "services": {}}, + }, + }, + InventoryOptions(), + ) + + host = f"{DEFAULT_NAMESPACE}-testvmi" + assert host in hosts + assert "custom_label" not in hosts[host]