Пример #1
0
def test_get_port_mappings():
    image_name = "registry.fedoraproject.org/fedora"
    image_tag = "27"
    image = DockerImage(image_name, image_tag)

    command = DockerRunBuilder(additional_opts=["-p", "321:123"])

    try:
        image.get_metadata()
    except Exception:
        image.pull()

    container = image.run_via_binary(command)
    try:
        mappings = container.get_port_mappings(123)

        assert len(mappings) == 1
        assert mappings == [{"HostIp": '0.0.0.0', "HostPort": '321'}]

        mappings = container.get_port_mappings()
        assert len(mappings) == 1
        assert mappings == {
            '123/tcp': [{
                'HostIp': '0.0.0.0',
                'HostPort': '321'
            }]
        }
    finally:
        container.stop()
        container.delete()

    command = DockerRunBuilder()
    container = image.run_via_binary(command)
    try:
        mappings = container.get_port_mappings(123)

        assert not mappings
    finally:
        container.stop()
        container.delete()
Пример #2
0
def test_image():
    """
    Basic tests of interacting with image: inspect, tag, remove
    """
    image = DockerImage(FEDORA_MINIMAL_REPOSITORY,
                        tag=FEDORA_MINIMAL_REPOSITORY_TAG)
    assert "Config" in image.inspect()
    assert "Config" in image.get_metadata()
    assert "fedora-minimal:26" in image.get_full_name()
    assert "registry.fedoraproject.org/fedora-minimal:26" == str(image)
    assert "DockerImage(repository=%s, tag=%s)" % (
        FEDORA_MINIMAL_REPOSITORY,
        FEDORA_MINIMAL_REPOSITORY_TAG) == repr(image)
    assert isinstance(image.get_id(), string_types)
    new_image = image.tag_image(tag="test")
    new_image.rmi(via_name=True)