Esempio n. 1
0
def test_process_isolation_and_directory_isolation(mock_makedirs,
                                                   mock_copytree, mock_mkdtemp,
                                                   mock_chmod):
    rc = RunnerConfig('/')
    rc.artifact_dir = '/tmp/artifacts'
    rc.directory_isolation_path = '/tmp/dirisolation'
    rc.playbook = 'main.yaml'
    rc.command = 'ansible-playbook'
    rc.process_isolation = True
    rc.prepare()

    assert rc.command == [
        'bwrap',
        '--unshare-pid',
        '--dev-bind',
        '/',
        '/',
        '--proc',
        '/proc',
        '--bind',
        '/',
        '/',
        '--chdir',
        '/tmp/dirisolation/foo',
        'ansible-playbook',
        '-i',
        '/inventory',
        'main.yaml',
    ]
Esempio n. 2
0
def test_prepare_env_directory_isolation():
    with patch('os.path.exists') as path_exists:
        path_exists.return_value=True
        rc = RunnerConfig('/')
        rc.directory_isolation_path = '/tmp/foo'
        rc.prepare_env()
        assert rc.cwd == '/tmp/foo'
def test_process_isolation_and_directory_isolation(mock_makedirs,
                                                   mock_copytree, mock_mkdtemp,
                                                   mock_chmod, mock_rmtree):
    def new_exists(path):
        if path == "/project":
            return False
        return True

    rc = RunnerConfig('/')
    rc.artifact_dir = '/tmp/artifacts'
    rc.directory_isolation_path = '/tmp/dirisolation'
    rc.playbook = 'main.yaml'
    rc.command = 'ansible-playbook'
    rc.process_isolation = True
    with patch('os.path.exists', new=new_exists):
        rc.prepare()

    assert rc.command == [
        'bwrap',
        '--unshare-pid',
        '--dev-bind',
        '/',
        '/',
        '--proc',
        '/proc',
        '--bind',
        '/',
        '/',
        '--chdir',
        os.path.realpath(rc.directory_isolation_path),
        'ansible-playbook',
        '-i',
        '/inventory',
        'main.yaml',
    ]