From 4bf0ba816aae1b2c4b57ac4e2817a088b33b6639 Mon Sep 17 00:00:00 2001 From: jessicamack Date: Fri, 22 Nov 2024 14:59:33 -0500 Subject: [PATCH 1/2] pull the correct collection plugin for the product --- awx/main/models/inventory.py | 12 ++++++++++-- .../functional/test_inventory_source_injectors.py | 3 --- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index d14e81543de4..30b2470ffb69 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -9,6 +9,7 @@ import copy import os.path from urllib.parse import urljoin +from importlib.metadata import entry_points # Django from django.conf import settings @@ -25,6 +26,7 @@ from ansible_base.lib.utils.models import prevent_search from awx_plugins.inventory.plugins import PluginFileInjector +from awx_plugins.interfaces._temporary_private_licensing_api import detect_server_product_name # AWX from awx.api.versioning import reverse @@ -1404,5 +1406,11 @@ def get_absolute_url(self, request=None): return reverse('api:inventory_script_detail', kwargs={'pk': self.pk}, request=request) -for cls in PluginFileInjector.__subclasses__(): - InventorySourceOptions.injectors[cls.__name__] = cls +awx_entry_points = {ep.name: ep for ep in entry_points(group='awx_plugins.inventory')} +supported_entry_points = {ep.name: ep for ep in entry_points(group='awx_plugins.inventory.supported')} +entry_points = awx_entry_points if detect_server_product_name() == 'AWX' else {**awx_entry_points, **supported_entry_points} +logger.info(entry_points) + +for entry_point_name, entry_point in entry_points.items(): + cls = entry_point.load() + InventorySourceOptions.injectors[entry_point_name] = cls diff --git a/awx/main/tests/functional/test_inventory_source_injectors.py b/awx/main/tests/functional/test_inventory_source_injectors.py index 83d9360ff501..8073dc3940b4 100644 --- a/awx/main/tests/functional/test_inventory_source_injectors.py +++ b/awx/main/tests/functional/test_inventory_source_injectors.py @@ -195,9 +195,6 @@ def create_reference_data(source_dir, env, content): @pytest.mark.django_db @pytest.mark.parametrize('this_kind', discover_available_cloud_provider_plugin_names()) def test_inventory_update_injected_content(this_kind, inventory, fake_credential_factory, mock_me): - if this_kind.endswith('_supported'): - this_kind = this_kind[:-10] - ExecutionEnvironment.objects.create(name='Control Plane EE', managed=True) ExecutionEnvironment.objects.create(name='Default Job EE', managed=False) From bdcc1c4c9f2ab785a0891bd5f3a41ff27c7422c7 Mon Sep 17 00:00:00 2001 From: jessicamack Date: Fri, 22 Nov 2024 21:44:59 -0500 Subject: [PATCH 2/2] remove unused import and logging line --- awx/main/models/inventory.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index 30b2470ffb69..475ed222d28d 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -25,7 +25,6 @@ from rest_framework.exceptions import ParseError from ansible_base.lib.utils.models import prevent_search -from awx_plugins.inventory.plugins import PluginFileInjector from awx_plugins.interfaces._temporary_private_licensing_api import detect_server_product_name # AWX @@ -1409,7 +1408,6 @@ def get_absolute_url(self, request=None): awx_entry_points = {ep.name: ep for ep in entry_points(group='awx_plugins.inventory')} supported_entry_points = {ep.name: ep for ep in entry_points(group='awx_plugins.inventory.supported')} entry_points = awx_entry_points if detect_server_product_name() == 'AWX' else {**awx_entry_points, **supported_entry_points} -logger.info(entry_points) for entry_point_name, entry_point in entry_points.items(): cls = entry_point.load()