From e8afdac06e3cdbb52885ec15660ea265e62d63ab Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Thu, 10 Mar 2022 16:54:57 -0800 Subject: [PATCH] ansible-test - Fix delegation inventory path. --- .../ansible-test-delegation-inventory.yaml | 2 ++ .../_internal/commands/integration/__init__.py | 13 +++++++++++++ .../_internal/commands/integration/network.py | 8 ++++++-- .../_internal/commands/integration/windows.py | 8 ++++++-- 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/ansible-test-delegation-inventory.yaml diff --git a/changelogs/fragments/ansible-test-delegation-inventory.yaml b/changelogs/fragments/ansible-test-delegation-inventory.yaml new file mode 100644 index 00000000000..20af2631ff9 --- /dev/null +++ b/changelogs/fragments/ansible-test-delegation-inventory.yaml @@ -0,0 +1,2 @@ +bugfixes: + - ansible-test - Fix ``windows-integration`` and ``network-integration`` when used with the ``--docker`` option and user-provided inventory. diff --git a/test/lib/ansible_test/_internal/commands/integration/__init__.py b/test/lib/ansible_test/_internal/commands/integration/__init__.py index 391716ee23b..247bce08209 100644 --- a/test/lib/ansible_test/_internal/commands/integration/__init__.py +++ b/test/lib/ansible_test/_internal/commands/integration/__init__.py @@ -92,6 +92,7 @@ from ...data import ( ) from ...host_configs import ( + InventoryConfig, OriginConfig, ) @@ -183,6 +184,18 @@ def check_inventory(args, inventory_path): # type: (IntegrationConfig, str) -> display.warning('Use of "ansible_ssh_private_key_file" in inventory with the --docker or --remote option is unsupported and will likely fail.') +def get_inventory_absolute_path(args: IntegrationConfig, target: InventoryConfig) -> str: + """Return the absolute inventory path used for the given integration configuration or target inventory config (if provided).""" + path = target.path or os.path.basename(get_inventory_relative_path(args)) + + if args.host_path: + path = os.path.join(data_context().content.root, path) # post-delegation, path is relative to the content root + else: + path = os.path.join(data_context().content.root, data_context().content.integration_path, path) + + return path + + def get_inventory_relative_path(args): # type: (IntegrationConfig) -> str """Return the inventory path used for the given integration configuration relative to the content root.""" inventory_names = { diff --git a/test/lib/ansible_test/_internal/commands/integration/network.py b/test/lib/ansible_test/_internal/commands/integration/network.py index f9953144a3e..778384f41c0 100644 --- a/test/lib/ansible_test/_internal/commands/integration/network.py +++ b/test/lib/ansible_test/_internal/commands/integration/network.py @@ -23,6 +23,7 @@ from ...config import ( from . import ( command_integration_filter, command_integration_filtered, + get_inventory_absolute_path, get_inventory_relative_path, check_inventory, delegate_inventory, @@ -46,8 +47,11 @@ def command_network_integration(args): # type: (NetworkIntegrationConfig) -> No template_path = os.path.join(ANSIBLE_TEST_CONFIG_ROOT, os.path.basename(inventory_relative_path)) + '.template' if issubclass(args.target_type, NetworkInventoryConfig): - inventory_path = os.path.join(data_context().content.root, data_context().content.integration_path, - args.only_target(NetworkInventoryConfig).path or os.path.basename(inventory_relative_path)) + target = args.only_target(NetworkInventoryConfig) + inventory_path = get_inventory_absolute_path(args, target) + + if args.delegate or not target.path: + target.path = inventory_relative_path else: inventory_path = os.path.join(data_context().content.root, inventory_relative_path) diff --git a/test/lib/ansible_test/_internal/commands/integration/windows.py b/test/lib/ansible_test/_internal/commands/integration/windows.py index f6b4494245a..d14ae11bc03 100644 --- a/test/lib/ansible_test/_internal/commands/integration/windows.py +++ b/test/lib/ansible_test/_internal/commands/integration/windows.py @@ -34,6 +34,7 @@ from ...host_configs import ( from . import ( command_integration_filter, command_integration_filtered, + get_inventory_absolute_path, get_inventory_relative_path, check_inventory, delegate_inventory, @@ -52,8 +53,11 @@ def command_windows_integration(args): # type: (WindowsIntegrationConfig) -> No template_path = os.path.join(ANSIBLE_TEST_CONFIG_ROOT, os.path.basename(inventory_relative_path)) + '.template' if issubclass(args.target_type, WindowsInventoryConfig): - inventory_path = os.path.join(data_context().content.root, data_context().content.integration_path, - args.only_target(WindowsInventoryConfig).path or os.path.basename(inventory_relative_path)) + target = args.only_target(WindowsInventoryConfig) + inventory_path = get_inventory_absolute_path(args, target) + + if args.delegate or not target.path: + target.path = inventory_relative_path else: inventory_path = os.path.join(data_context().content.root, inventory_relative_path)