def test_prepare_with_ssh_key(open_fifo_write_mock): rc = BaseConfig(private_data_dir='/tmp') rc.artifact_dir = '/tmp/artifact' rc.env = {} rc.execution_mode = BaseExecutionMode.ANSIBLE_COMMANDS rc.ssh_key_data = '01234567890' rc.command = 'ansible-playbook' rc.cmdline_args = [] with patch.dict('os.environ', {'AWX_LIB_DIRECTORY': '/tmp/artifact'}): rc._prepare_env() assert rc.ssh_key_path == '/tmp/artifact/ssh_key_data' assert open_fifo_write_mock.called
def test_prepare_with_ssh_key(mocker, tmp_path): open_fifo_write_mock = mocker.patch( 'ansible_runner.config._base.open_fifo_write') custom_artifacts = tmp_path.joinpath('custom_arts') rc = BaseConfig(private_data_dir=tmp_path.as_posix(), artifact_dir=custom_artifacts.as_posix()) rc.artifact_dir = custom_artifacts.as_posix() rc.env = {} rc.execution_mode = BaseExecutionMode.ANSIBLE_COMMANDS rc.ssh_key_data = '01234567890' rc.command = 'ansible-playbook' rc.cmdline_args = [] rc._prepare_env() assert rc.ssh_key_path == custom_artifacts.joinpath( 'ssh_key_data').as_posix() assert open_fifo_write_mock.called
def test_prepare_env_ansible_vars(): rc = BaseConfig(private_data_dir='/tmp') rc.ssh_key_data = None rc.artifact_dir = '/tmp/artifact' rc.env = {} rc.execution_mode = BaseExecutionMode.ANSIBLE_COMMANDS rc._prepare_env() assert not hasattr(rc, 'ssh_key_path') assert not hasattr(rc, 'command') assert rc.env['ANSIBLE_STDOUT_CALLBACK'] == 'awx_display' assert rc.env['ANSIBLE_RETRY_FILES_ENABLED'] == 'False' assert rc.env['ANSIBLE_HOST_KEY_CHECKING'] == 'False' assert rc.env['AWX_ISOLATED_DATA_DIR'] == '/tmp/artifact' assert rc.env['PYTHONPATH'] == '/python_path_via_environ:/awx_lib_directory_via_environ', \ "PYTHONPATH is the union of the env PYTHONPATH and AWX_LIB_DIRECTORY" del rc.env['PYTHONPATH'] os.environ['PYTHONPATH'] = "/foo/bar/python_path_via_environ" rc._prepare_env() assert rc.env['PYTHONPATH'] == "/foo/bar/python_path_via_environ:/awx_lib_directory_via_environ", \ "PYTHONPATH is the union of the explicit env['PYTHONPATH'] override and AWX_LIB_DIRECTORY"