Beispiel #1
0
def test_run_via_api():
    with DockerBackend() as backend:
        image = backend.ImageClass(FEDORA_MINIMAL_REPOSITORY,
                                   tag=FEDORA_MINIMAL_REPOSITORY_TAG)
        docker_run_builder = DockerRunBuilder(additional_opts=[
            '-l', 'hello=there', '-l', 'oh=noo', '--name', 'test', '-d',
            '--hostname', 'my_hostname', '--rm', '--memory', '1G', '--workdir',
            '/tmp', '--env', 'ENV1=my_env', '-p', '123:12345', '--cap-add',
            'MKNOD', '--cap-add', 'SYS_ADMIN', '--cap-drop', 'SYS_ADMIN',
            '--dns', 'www.example.com', '--volume', '/tmp:/tmp',
            '--no-healthcheck'
        ],
                                              command=['sleep', '10'])

        parameters = docker_run_builder.get_parameters()

        c = image.run_via_api(parameters)

        try:
            assert "Config" in c.inspect()
            assert c.get_id() == str(c)
            assert repr(c)
            assert isinstance(c.get_id(), string_types)
        finally:
            c.delete(force=True)
Beispiel #2
0
def test_docker_parameters():
    docker_run_builder = DockerRunBuilder(additional_opts=[
        '-l', 'hello=there', '-l', 'oh=noo', '--name', 'test', '-d',
        '--hostname', 'my_hostname', '--rm', '--privileged', '--isolation',
        'default', '--mac-address', '92:d0:c6:0a:29:33', '--memory', '1G',
        '--user', 'my_user', '--workdir', '/tmp', '--env', 'ENV1=my_env', '-p',
        '123:12345', '-p', '1444', '-p', '10.0.0.1::150', '-p',
        '10.0.0.2:2345:7654', '--cap-add', 'MKNOD', '--cap-add', 'SYS_ADMIN',
        '--cap-drop', 'SYS_ADMIN', '--device', '/dev/sdc:/dev/xvdc', '--dns',
        'www.example.com', '--group-add', 'group1', '--group-add', 'group2',
        '--mount', '/tmp', '--volume', '/tmp:/tmp', '--no-healthcheck'
    ],
                                          command=['sleep', '50'])

    parameters = docker_run_builder.get_parameters()

    assert parameters.labels == {'hello': 'there', 'oh': 'noo'}
    assert parameters.name == 'test'
    assert parameters.detach
    assert parameters.privileged
    assert parameters.hostname == 'my_hostname'
    assert parameters.remove
    assert parameters.isolation == 'default'
    assert parameters.mac_address == '92:d0:c6:0a:29:33'
    assert parameters.mem_limit == '1G'
    assert parameters.user == 'my_user'
    assert parameters.working_dir == '/tmp'
    assert 'ENV1=my_env' in parameters.env_variables
    assert parameters.port_mappings == {
        '12345': 123,
        '1444': None,
        '150': ('10.0.0.1', None),
        '7654': ('10.0.0.2', 2345)
    }
    assert parameters.cap_add == ['MKNOD', 'SYS_ADMIN']
    assert parameters.cap_drop == ['SYS_ADMIN']
    assert parameters.devices == ['/dev/sdc:/dev/xvdc']
    assert parameters.dns == ['www.example.com']
    assert parameters.group_add == ['group1', 'group2']
    assert parameters.mounts == ['/tmp']
    assert parameters.volumes == ['/tmp:/tmp']
    assert parameters.command == ['sleep', '50']