mirror of
https://github.com/ansible/awx.git
synced 2026-05-15 21:37:42 -02:30
Pull the correct collection plugin for the product (#15658)
* pull the correct collection plugin for the product * remove unused import and logging line * refactor code to load entry points * reformat method * lint fix * renames for clarity and a lint fix * move function to utils * move the rest of the code into load_inventory_plugins * temp - confirm that tests will pass * revert change caught in merge * change back requirement the related PR has been merged
This commit is contained in:
@@ -2,11 +2,13 @@ import os
|
|||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from awx.main.utils.common import bypass_in_test
|
from awx.main.utils.common import bypass_in_test, load_all_entry_points_for
|
||||||
from awx.main.utils.migration import is_database_synchronized
|
from awx.main.utils.migration import is_database_synchronized
|
||||||
from awx.main.utils.named_url_graph import _customize_graph, generate_graph
|
from awx.main.utils.named_url_graph import _customize_graph, generate_graph
|
||||||
from awx.conf import register, fields
|
from awx.conf import register, fields
|
||||||
|
|
||||||
|
from awx_plugins.interfaces._temporary_private_licensing_api import detect_server_product_name
|
||||||
|
|
||||||
|
|
||||||
class MainConfig(AppConfig):
|
class MainConfig(AppConfig):
|
||||||
name = 'awx.main'
|
name = 'awx.main'
|
||||||
@@ -60,6 +62,17 @@ class MainConfig(AppConfig):
|
|||||||
def load_credential_types_feature(self):
|
def load_credential_types_feature(self):
|
||||||
return self._load_credential_types_feature()
|
return self._load_credential_types_feature()
|
||||||
|
|
||||||
|
def load_inventory_plugins(self):
|
||||||
|
from awx.main.models.inventory import InventorySourceOptions
|
||||||
|
|
||||||
|
is_awx = detect_server_product_name() == 'AWX'
|
||||||
|
extra_entry_point_groups = () if is_awx else ('inventory.supported',)
|
||||||
|
entry_points = load_all_entry_points_for(['inventory', *extra_entry_point_groups])
|
||||||
|
|
||||||
|
for entry_point_name, entry_point in entry_points.items():
|
||||||
|
cls = entry_point.load()
|
||||||
|
InventorySourceOptions.injectors[entry_point_name] = cls
|
||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
super().ready()
|
super().ready()
|
||||||
|
|
||||||
@@ -71,3 +84,4 @@ class MainConfig(AppConfig):
|
|||||||
if not os.environ.get('AWX_SKIP_CREDENTIAL_TYPES_DISCOVER', None):
|
if not os.environ.get('AWX_SKIP_CREDENTIAL_TYPES_DISCOVER', None):
|
||||||
self.load_credential_types_feature()
|
self.load_credential_types_feature()
|
||||||
self.load_named_url_feature()
|
self.load_named_url_feature()
|
||||||
|
self.load_inventory_plugins()
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ from django.db.models import Q
|
|||||||
from rest_framework.exceptions import ParseError
|
from rest_framework.exceptions import ParseError
|
||||||
|
|
||||||
from ansible_base.lib.utils.models import prevent_search
|
from ansible_base.lib.utils.models import prevent_search
|
||||||
from awx_plugins.inventory.plugins import PluginFileInjector
|
|
||||||
|
|
||||||
# AWX
|
# AWX
|
||||||
from awx.api.versioning import reverse
|
from awx.api.versioning import reverse
|
||||||
@@ -1402,7 +1401,3 @@ class CustomInventoryScript(CommonModelNameNotUnique):
|
|||||||
|
|
||||||
def get_absolute_url(self, request=None):
|
def get_absolute_url(self, request=None):
|
||||||
return reverse('api:inventory_script_detail', kwargs={'pk': self.pk}, request=request)
|
return reverse('api:inventory_script_detail', kwargs={'pk': self.pk}, request=request)
|
||||||
|
|
||||||
|
|
||||||
for cls in PluginFileInjector.__subclasses__():
|
|
||||||
InventorySourceOptions.injectors[cls.__name__] = cls
|
|
||||||
|
|||||||
@@ -196,9 +196,6 @@ def create_reference_data(source_dir, env, content):
|
|||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@pytest.mark.parametrize('this_kind', discover_available_cloud_provider_plugin_names())
|
@pytest.mark.parametrize('this_kind', discover_available_cloud_provider_plugin_names())
|
||||||
def test_inventory_update_injected_content(product_name, this_kind, inventory, fake_credential_factory, mock_me):
|
def test_inventory_update_injected_content(product_name, 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='Control Plane EE', managed=True)
|
||||||
ExecutionEnvironment.objects.create(name='Default Job EE', managed=False)
|
ExecutionEnvironment.objects.create(name='Default Job EE', managed=False)
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import contextlib
|
|||||||
import tempfile
|
import tempfile
|
||||||
import functools
|
import functools
|
||||||
from importlib.metadata import version as _get_version
|
from importlib.metadata import version as _get_version
|
||||||
|
from importlib.metadata import entry_points, EntryPoint
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.core.exceptions import ObjectDoesNotExist, FieldDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist, FieldDoesNotExist
|
||||||
@@ -1215,3 +1216,7 @@ def cleanup_new_process(func):
|
|||||||
|
|
||||||
def unified_job_class_to_event_table_name(job_class):
|
def unified_job_class_to_event_table_name(job_class):
|
||||||
return f'main_{job_class().event_class.__name__.lower()}'
|
return f'main_{job_class().event_class.__name__.lower()}'
|
||||||
|
|
||||||
|
|
||||||
|
def load_all_entry_points_for(entry_point_subsections: list[str], /) -> dict[str, EntryPoint]:
|
||||||
|
return {ep.name: ep for entry_point_category in entry_point_subsections for ep in entry_points(group=f'awx_plugins.{entry_point_category}')}
|
||||||
|
|||||||
Reference in New Issue
Block a user