mirror of
https://github.com/ansible/awx.git
synced 2026-06-21 06:37:45 -02:30
Move plugin loading to lazy-on-first-access, DB sync to dispatcher Remove credential type and inventory plugin loading from Django's app.ready() path. In-memory registries (ManagedCredentialType.registry and InventorySourceOptions.injectors) are now populated lazily on first access via LazyLoadDict, a dict subclass that calls a loader function on the first read operation. This ensures web workers, dispatcher workers, and management commands all get the registries populated exactly when needed, without eager loading at startup. The DB sync (CredentialType.setup_tower_managed_defaults) is moved to the dispatcher's startup task, where it only needs to run once per deployment rather than in every Django process. Co-Authored-By: Alan Rominger <arominge@redhat.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
import pytest
|
|
|
|
# AWX context managers for testing
|
|
from awx.main.signals import disable_activity_stream, disable_computed_fields
|
|
from awx.main.tasks.system import update_inventory_computed_fields
|
|
|
|
# AWX models
|
|
from awx.main.models.organization import Organization
|
|
from awx.main.models import ActivityStream, Job
|
|
from awx.main.tests.functional import immediate_on_commit
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_disable_activity_stream():
|
|
with disable_activity_stream():
|
|
Organization.objects.create(name='test-organization')
|
|
assert ActivityStream.objects.filter(organization__isnull=False).count() == 0
|
|
|
|
|
|
@pytest.mark.django_db
|
|
class TestComputedFields:
|
|
def test_computed_fields_normal_use(self, mocker, inventory):
|
|
job = Job.objects.create(name='fake-job', inventory=inventory)
|
|
with immediate_on_commit():
|
|
mocker.patch.object(update_inventory_computed_fields, 'delay')
|
|
job.delete()
|
|
update_inventory_computed_fields.delay.assert_called_once_with(inventory.id)
|
|
|
|
def test_disable_computed_fields(self, mocker, inventory):
|
|
job = Job.objects.create(name='fake-job', inventory=inventory)
|
|
with disable_computed_fields():
|
|
mocker.patch.object(update_inventory_computed_fields, 'delay')
|
|
job.delete()
|
|
update_inventory_computed_fields.delay.assert_not_called()
|