mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 23:07:42 -02:30
[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 <noreply@anthropic.com>
This commit is contained in:
@@ -918,6 +918,54 @@ class TestJobCredentials(TestJobExecution):
|
|||||||
assert env['FOO'] == 'BAR'
|
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")
|
@pytest.mark.usefixtures("patch_Organization")
|
||||||
class TestProjectUpdateGalaxyCredentials(TestJobExecution):
|
class TestProjectUpdateGalaxyCredentials(TestJobExecution):
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|||||||
Reference in New Issue
Block a user