def test_containerization_settings(tmpdir, container_runtime): with patch('ansible_runner.runner_config.RunnerConfig.containerized', new_callable=PropertyMock) as mock_containerized: rc = RunnerConfig(tmpdir) rc.ident = 'foo' rc.playbook = 'main.yaml' rc.command = 'ansible-playbook' rc.process_isolation = True rc.process_isolation_executable = container_runtime rc.container_image = 'my_container' rc.container_volume_mounts = [ '/host1:/container1', 'host2:/container2' ] mock_containerized.return_value = True rc.prepare() extra_container_args = [] if container_runtime == 'podman': extra_container_args = ['--quiet'] else: extra_container_args = ['--user={os.getuid()}'] expected_command_start = [container_runtime, 'run', '--rm', '--tty', '--interactive', '--workdir', '/runner/project'] + \ ['-v', '{}:/runner:Z'.format(rc.private_data_dir)] + \ ['-v', '/host1:/container1', '-v', 'host2:/container2'] + \ ['--env-file', '{}/env.list'.format(rc.artifact_dir)] + \ extra_container_args + \ ['--name', 'ansible_runner_foo'] + \ ['my_container', 'ansible-playbook', '-i', '/runner/inventory/hosts', 'main.yaml'] for index, element in enumerate(expected_command_start): if '--user' in element: assert '--user=' in rc.command[index] else: assert rc.command[index] == element
def test_container_volume_mounting_with_Z(tmpdir): rc = RunnerConfig(str(tmpdir)) rc.container_volume_mounts = ['project_path:project_path:Z'] rc.container_name = 'foo' rc.env = {} new_args = rc.wrap_args_for_containerization( ['ansible-playbook', 'foo.yml']) assert new_args[0] == 'podman' for i, entry in enumerate(new_args): if entry == '-v': mount = new_args[i + 1] if mount.endswith(':project_path:Z'): break else: raise Exception( 'Could not find expected mount, args: {}'.format(new_args))