From ea2c2783552b6c136be7821946963dfe4e441f1c Mon Sep 17 00:00:00 2001 From: Dirk Julich Date: Tue, 19 May 2026 17:20:42 +0200 Subject: [PATCH] [AAP-74343] Add tests for ANSIBLE_CALLBACKS_ENABLED configuration Verify that indirect_instance_count is always set, user-configured callbacks from ansible.cfg are preserved, and the comma delimiter is used as ansible-core expects. Co-Authored-By: Claude Opus 4.6 --- awx/main/tests/unit/test_tasks.py | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/awx/main/tests/unit/test_tasks.py b/awx/main/tests/unit/test_tasks.py index 41b6ff058b..c70d6cf349 100644 --- a/awx/main/tests/unit/test_tasks.py +++ b/awx/main/tests/unit/test_tasks.py @@ -918,6 +918,54 @@ class TestJobCredentials(TestJobExecution): assert env['FOO'] == 'BAR' +class TestCallbacksEnabled(TestJobExecution): + @pytest.fixture(autouse=True) + def mock_flag_enabled(self): + with mock.patch('awx.main.tasks.jobs.flag_enabled', return_value=False): + yield + + def test_callbacks_enabled_default(self, patch_Job, private_data_dir, execution_environment, mock_me): + job = Job(project=Project(), inventory=Inventory()) + job.execution_environment = execution_environment + + task = jobs.RunJob() + task.instance = job + task._write_extra_vars_file = mock.Mock() + + with mock.patch.object(task, 'build_credentials_list', return_value=[], autospec=True): + env = task.build_env(job, private_data_dir) + + assert env['ANSIBLE_CALLBACKS_ENABLED'] == 'indirect_instance_count' + + def test_callbacks_enabled_preserves_user_config(self, patch_Job, private_data_dir, execution_environment, mock_me): + job = Job(project=Project(), inventory=Inventory()) + job.execution_environment = execution_environment + + task = jobs.RunJob() + task.instance = job + task._write_extra_vars_file = mock.Mock() + + with mock.patch.object(task, 'build_credentials_list', return_value=[], autospec=True): + with mock.patch('awx.main.tasks.jobs.read_ansible_config', return_value={'callbacks_enabled': 'custom_callback,another_callback'}): + env = task.build_env(job, private_data_dir) + + assert env['ANSIBLE_CALLBACKS_ENABLED'] == 'indirect_instance_count,custom_callback,another_callback' + + def test_callbacks_enabled_uses_comma_delimiter(self, patch_Job, private_data_dir, execution_environment, mock_me): + job = Job(project=Project(), inventory=Inventory()) + job.execution_environment = execution_environment + + task = jobs.RunJob() + task.instance = job + task._write_extra_vars_file = mock.Mock() + + with mock.patch.object(task, 'build_credentials_list', return_value=[], autospec=True): + with mock.patch('awx.main.tasks.jobs.read_ansible_config', return_value={'callbacks_enabled': 'my_callback'}): + env = task.build_env(job, private_data_dir) + + assert env['ANSIBLE_CALLBACKS_ENABLED'] == 'indirect_instance_count,my_callback' + + @pytest.mark.usefixtures("patch_Organization") class TestProjectUpdateGalaxyCredentials(TestJobExecution): @pytest.fixture