示例#1
0
def test_localdockerinterface_get_info_disconnected(emitter, responses):
    """No daemon to talk to (see responses used as fixture but no listening)."""
    ldi = LocalDockerdInterface()
    resp = ldi.get_image_info("test-digest")
    assert resp is None

    emitter.assert_trace(
        "Cannot connect to /var/run/docker.sock , please ensure dockerd is running."
    )
示例#2
0
def test_localdockerinterface_get_info_disconnected(caplog, responses):
    """No daemon to talk to (see responses used as fixture but no listening)."""
    caplog.set_level(logging.DEBUG, logger="charmcraft")

    ldi = LocalDockerdInterface()
    resp = ldi.get_image_info("test-digest")
    assert resp is None

    expected = [
        "Cannot connect to /var/run/docker.sock , please ensure dockerd is running.",
    ]
    assert expected == [rec.message for rec in caplog.records]
示例#3
0
def test_localdockerinterface_get_info_bad_response(responses, emitter):
    """Docker answered badly when checking for the image."""
    # weird dockerd behaviour
    responses.add(
        responses.GET,
        LocalDockerdInterface.dockerd_socket_baseurl +
        "/images/test-digest/json",
        status=500,
    )
    ldi = LocalDockerdInterface()
    resp = ldi.get_image_info("test-digest")
    assert resp is None

    emitter.assert_trace("Bad response when validation local image: 500")
示例#4
0
def test_localdockerinterface_get_info_not_found(responses, emitter):
    """Get image info for something that is not there."""
    # return 404, which means that the image was not found
    responses.add(
        responses.GET,
        LocalDockerdInterface.dockerd_socket_baseurl +
        "/images/test-digest/json",
        status=404,
    )
    ldi = LocalDockerdInterface()
    resp = ldi.get_image_info("test-digest")
    assert resp is None

    emitter.assert_interactions(None)
示例#5
0
def test_localdockerinterface_get_info_ok(responses, emitter):
    """Get image info ok."""
    test_image_info = {"some": "stuff"}
    responses.add(
        responses.GET,
        LocalDockerdInterface.dockerd_socket_baseurl +
        "/images/test-digest/json",
        json=test_image_info,
    )
    ldi = LocalDockerdInterface()
    resp = ldi.get_image_info("test-digest")
    assert resp == test_image_info

    emitter.assert_interactions(None)
示例#6
0
def test_localdockerinterface_get_info_not_found(responses, caplog):
    """Get image info for something that is not there."""
    caplog.set_level(logging.DEBUG, logger="charmcraft")

    # return 404, which means that the image was not found
    responses.add(
        responses.GET,
        LocalDockerdInterface.dockerd_socket_baseurl +
        "/images/test-digest/json",
        status=404,
    )
    ldi = LocalDockerdInterface()
    resp = ldi.get_image_info("test-digest")
    assert resp is None

    assert not caplog.records
示例#7
0
def test_localdockerinterface_get_info_ok(responses, caplog):
    """Get image info ok."""
    caplog.set_level(logging.DEBUG, logger="charmcraft")

    test_image_info = {"some": "stuff"}
    responses.add(
        responses.GET,
        LocalDockerdInterface.dockerd_socket_baseurl +
        "/images/test-digest/json",
        json=test_image_info,
    )
    ldi = LocalDockerdInterface()
    resp = ldi.get_image_info("test-digest")
    assert resp == test_image_info

    assert not caplog.records
示例#8
0
def test_localdockerinterface_get_streamed_content(responses):
    """Get the content streamed."""
    test_content = b"123456789"
    responses.add(
        responses.GET,
        LocalDockerdInterface.dockerd_socket_baseurl +
        "/images/test-digest/get",
        body=test_content,
        stream=True,
    )
    ldi = LocalDockerdInterface()
    resp = ldi.get_streamed_image_content("test-digest")
    streamed = resp.iter_content(5)
    assert next(streamed) == b"12345"
    assert next(streamed) == b"6789"
    with pytest.raises(StopIteration):
        next(streamed)
示例#9
0
def test_localdockerinterface_get_info_bad_response(responses, caplog):
    """Docker answered badly when checking for the image."""
    caplog.set_level(logging.DEBUG, logger="charmcraft")

    # weird dockerd behaviour
    responses.add(
        responses.GET,
        LocalDockerdInterface.dockerd_socket_baseurl +
        "/images/test-digest/json",
        status=500,
    )
    ldi = LocalDockerdInterface()
    resp = ldi.get_image_info("test-digest")
    assert resp is None

    expected = [
        "Bad response when validation local image: 500",
    ]
    assert expected == [rec.message for rec in caplog.records]