Skip to content

Commit 6aea699

Browse files
authored
Fix bug where collectstatic could error due to dispatcherd config (ansible#15999)
* Fix bug where collectstatic could error due to dispatcherd config * Revert test because it will not work in test suite * New publish mocking system * Remove import of unused * Fix default publish broker
1 parent 7ee0aab commit 6aea699

File tree

5 files changed

+34
-21
lines changed

5 files changed

+34
-21
lines changed

awx/main/apps.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from dispatcherd.config import setup as dispatcher_setup
44

55
from django.apps import AppConfig
6+
from django.db import connection
67
from django.utils.translation import gettext_lazy as _
78
from awx.main.utils.common import bypass_in_test, load_all_entry_points_for
89
from awx.main.utils.migration import is_database_synchronized
@@ -78,12 +79,27 @@ def load_inventory_plugins(self):
7879
cls = entry_point.load()
7980
InventorySourceOptions.injectors[entry_point_name] = cls
8081

81-
def ready(self):
82-
super().ready()
82+
def configure_dispatcherd(self):
83+
"""This implements the default configuration for dispatcherd
8384
85+
If running the tasking service like awx-manage run_dispatcher,
86+
some additional config will be applied on top of this.
87+
This configuration provides the minimum such that code can submit
88+
tasks to pg_notify to run those tasks.
89+
"""
8490
from awx.main.dispatch.config import get_dispatcherd_config
8591

86-
dispatcher_setup(get_dispatcherd_config())
92+
if connection.vendor != 'postgresql':
93+
config_dict = get_dispatcherd_config(mock_publish=True)
94+
else:
95+
config_dict = get_dispatcherd_config()
96+
97+
dispatcher_setup(config_dict)
98+
99+
def ready(self):
100+
super().ready()
101+
102+
self.configure_dispatcherd()
87103

88104
"""
89105
Credential loading triggers database operations. There are cases we want to call

awx/main/dispatch/config.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from awx.main.dispatch.pool import get_auto_max_workers
66

77

8-
def get_dispatcherd_config(for_service: bool = False) -> dict:
8+
def get_dispatcherd_config(for_service: bool = False, mock_publish: bool = False) -> dict:
99
"""Return a dictionary config for dispatcherd
1010
1111
Parameters:
@@ -24,20 +24,23 @@ def get_dispatcherd_config(for_service: bool = False) -> dict:
2424
"process_manager_kwargs": {"preload_modules": ['awx.main.dispatch.hazmat']},
2525
},
2626
"brokers": {
27-
"pg_notify": {
28-
"config": get_pg_notify_params(),
29-
"sync_connection_factory": "ansible_base.lib.utils.db.psycopg_connection_from_django",
30-
"default_publish_channel": settings.CLUSTER_HOST_ID, # used for debugging commands
31-
},
3227
"socket": {"socket_path": settings.DISPATCHERD_DEBUGGING_SOCKFILE},
3328
},
34-
"publish": {
35-
"default_control_broker": "socket",
36-
"default_broker": "pg_notify",
37-
},
29+
"publish": {"default_control_broker": "socket"},
3830
"worker": {"worker_cls": "awx.main.dispatch.worker.dispatcherd.AWXTaskWorker"},
3931
}
4032

33+
if mock_publish:
34+
config["brokers"]["noop"] = {}
35+
config["publish"]["default_broker"] = "noop"
36+
else:
37+
config["brokers"]["pg_notify"] = {
38+
"config": get_pg_notify_params(),
39+
"sync_connection_factory": "ansible_base.lib.utils.db.psycopg_connection_from_django",
40+
"default_publish_channel": settings.CLUSTER_HOST_ID, # used for debugging commands
41+
}
42+
config["publish"]["default_broker"] = "pg_notify"
43+
4144
if for_service:
4245
config["producers"] = {
4346
"ScheduledProducer": {"task_schedule": settings.DISPATCHER_SCHEDULE},

awx/main/tests/conftest.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,6 @@ def event_qs(self):
209209
yield _fixture
210210

211211

212-
@pytest.fixture(scope='session', autouse=True)
213-
def mock_dispatcherd_publish():
214-
with mock.patch('dispatcherd.brokers.pg_notify.Broker.publish_message', autospec=True):
215-
yield
216-
217-
218212
@pytest.fixture
219213
def mock_me():
220214
"Allows Instance.objects.me() to work without touching the database"

awx_collection/test/awx/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from ansible.module_utils.six import raise_from
1919

2020
from ansible_base.rbac.models import RoleDefinition, DABPermission
21-
from awx.main.tests.conftest import load_all_credentials, mock_dispatcherd_publish # noqa: F401; pylint: disable=unused-import
21+
from awx.main.tests.conftest import load_all_credentials # noqa: F401; pylint: disable=unused-import
2222
from awx.main.tests.functional.conftest import _request
2323
from awx.main.tests.functional.conftest import credentialtype_scm, credentialtype_ssh # noqa: F401; pylint: disable=unused-import
2424
from awx.main.models import (

requirements/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ deprecated==1.2.15
128128
# opentelemetry-exporter-otlp-proto-http
129129
# opentelemetry-semantic-conventions
130130
# pygithub
131-
dispatcherd==2025.5.12
131+
dispatcherd==2025.5.21
132132
# via -r /awx_devel/requirements/requirements.in
133133
distro==1.9.0
134134
# via -r /awx_devel/requirements/requirements.in

0 commit comments

Comments
 (0)