コード例 #1
0
def test_daemon_extents_zero(http_server, uhttp_server):
    handler = Daemon(http_server, uhttp_server)

    chunk_size = len(handler.image) // 2
    handler.extents["zero"] = [
        {
            "start": 0,
            "length": chunk_size,
            "zero": False,
            "hole": False,
        },
        {
            "start": chunk_size,
            "length": chunk_size,
            "zero": True,
            "hole": False,
        },
    ]

    with Backend(http_server.url, http_server.cafile) as b:
        # Zero extents are available.
        assert list(b.extents()) == [
            image.ZeroExtent(0, chunk_size, False, False),
            image.ZeroExtent(chunk_size, chunk_size, True, False),
        ]

        # Dirty extents are not available.
        with pytest.raises(errors.UnsupportedOperation):
            list(b.extents("dirty"))
コード例 #2
0
def test_daemon_extents_dirty(http_server, uhttp_server):
    handler = Daemon(http_server, uhttp_server)

    chunk_size = len(handler.image) // 2
    handler.extents["dirty"] = [
        {
            "start": 0,
            "length": chunk_size,
            "dirty": True,
            "hole": False,
        },
        {
            "start": chunk_size,
            "length": chunk_size,
            "dirty": False,
            "hole": False,
        },
    ]

    with Backend(http_server.url, http_server.cafile) as b:
        # Both "zero" and "dirty" extents are available.
        assert list(b.extents("zero")) == [
            image.ZeroExtent(0, b.size(), True, False),
        ]
        assert list(b.extents("dirty")) == [
            image.DirtyExtent(0, chunk_size, True),
            image.DirtyExtent(chunk_size, chunk_size, False),
        ]
コード例 #3
0
def test_daemon_read_from(http_server, uhttp_server):
    handler = Daemon(http_server, uhttp_server)
    with Backend(http_server.url, http_server.cafile) as b:
        check_read_from(handler, b)
        assert handler.dirty
        b.flush()
        assert not handler.dirty
コード例 #4
0
def test_daemon_no_unix_socket_read_from(http_server):
    handler = Daemon(http_server, extents=False)
    with Backend(http_server.url, http_server.cafile) as b:
        check_read_from(handler, b)
        assert handler.dirty
        b.flush()
        assert not handler.dirty
コード例 #5
0
def test_daemon_no_extents_open(http_server, uhttp_server):
    handler = Daemon(http_server, uhttp_server, extents=False)
    with Backend(http_server.url, http_server.cafile) as b:
        assert b.server_address == uhttp_server.server_address
        assert b.tell() == 0
        assert b.size() == len(handler.image)

        # Client emulates extents (all non-zero).
        assert list(
            b.extents()) == [image.ZeroExtent(0, b.size(), False, False)]
コード例 #6
0
def test_old_proxy_open(http_server):
    handler = OldProxy(http_server)
    with Backend(http_server.url, http_server.cafile) as b:
        assert b.server_address == http_server.server_address
        assert b.tell() == 0
        assert b.size() == len(handler.image)

        # Client emulates extents (all non-zero).
        assert list(
            b.extents()) == [image.ZeroExtent(0, b.size(), False, False)]
コード例 #7
0
def test_daemon_readinto_end(http_server, uhttp_server, end_offset):
    _ = Daemon(http_server, uhttp_server)
    with Backend(http_server.url, http_server.cafile) as b:
        offset = b.size() + end_offset
        b.seek(offset)
        buf = bytearray(4096)
        n = b.readinto(buf)

        assert n == 0
        assert b.tell() == offset
コード例 #8
0
def test_daemon_open(http_server, uhttp_server):
    handler = Daemon(http_server, uhttp_server)
    with Backend(http_server.url, http_server.cafile) as b:
        assert b.server_address == uhttp_server.server_address
        assert b.tell() == 0
        assert b.size() == len(handler.image)

        # Client reports server extents (all zero).
        assert list(
            b.extents()) == [image.ZeroExtent(0, b.size(), True, False)]
コード例 #9
0
ファイル: http_test.py プロジェクト: oVirt/ovirt-imageio
def test_daemon_bad_unix_socket_open(http_server):
    handler = Daemon(http_server, extents=False)
    handler.unix_socket = "\0bad/socket"
    with Backend(http_server.url, http_server.cafile) as b:
        assert b.server_address == http_server.server_address
        assert b.tell() == 0
        assert b.size() == len(handler.image)

        # Client emulates extents (all non-zero).
        assert list(b.extents()) == [
            extent.ZeroExtent(0, b.size(), False, False)
        ]
コード例 #10
0
def test_daemon_readinto_short(http_server, uhttp_server, size):
    handler = Daemon(http_server, uhttp_server)
    with Backend(http_server.url, http_server.cafile) as b:
        offset = b.size() - size
        buf = bytearray(8192)

        b.seek(offset)
        n = b.readinto(buf)

        assert n == size
        assert b.tell() == b.size()
        assert buf[:size] == handler.image[offset:]
        assert buf[size:] == b"\0" * (8192 - size)
コード例 #11
0
def test_daemon_extents_error(http_server, uhttp_server):
    handler = Daemon(http_server, uhttp_server)

    def fail(req, resp, *args):
        raise http.Error(http.FORBIDDEN, "Fake error")

    handler.get = fail

    with pytest.raises(http.Error) as e:
        with Backend(http_server.url, None, secure=False) as b:
            list(b.extents())

    assert e.value.code == http.FORBIDDEN
コード例 #12
0
def test_old_daemon_zero_error(http_server):
    handler = OldDaemon(http_server)

    # With old daemon we emulate zero by putting zeros over the write.

    def fail(req, resp, *args):
        raise http.Error(http.FORBIDDEN, "Fake error")

    handler.put = fail

    with pytest.raises(http.Error) as e:
        with Backend(http_server.url, http_server.cafile) as b:
            b.zero(4096)

    assert e.value.code == http.FORBIDDEN
コード例 #13
0
def test_daemon_open_error(http_server, uhttp_server):
    handler = Daemon(http_server, uhttp_server)

    # Backends is sending OPTIONS request during open.

    def fail(req, resp, *args):
        raise http.Error(http.FORBIDDEN, "Fake error")

    handler.options = fail

    with pytest.raises(http.Error) as e:
        with Backend(http_server.url, None, secure=False):
            pass

    assert e.value.code == http.FORBIDDEN
コード例 #14
0
def test_old_daemon_size_error(http_server):
    handler = OldDaemon(http_server)

    # With old daemon we emulate HEAD with GET. Make it fail to test error
    # handling.

    def fail(req, resp, *args):
        raise http.Error(http.FORBIDDEN, "Fake error")

    handler.get = fail

    with pytest.raises(http.Error) as e:
        with Backend(http_server.url, None, secure=False) as b:
            b.size()

    assert e.value.code == http.FORBIDDEN
コード例 #15
0
ファイル: http_test.py プロジェクト: oVirt/ovirt-imageio
def test_daemon_close(http_server, uhttp_server):
    Daemon(http_server, uhttp_server)
    with Backend(http_server.url, http_server.cafile) as b:
        pass

    # Closing twice does nothing.
    b.close()

    # But other operations should fail.
    error = "Operation on closed backend"

    buf = bytearray(4096)
    with pytest.raises(ValueError) as e:
        b.write(buf)
    assert str(e.value) == error

    with pytest.raises(ValueError) as e:
        b.readinto(buf)
    assert str(e.value) == error
コード例 #16
0
def test_clone_unix(http_server, uhttp_server):
    Daemon(http_server, uhttp_server)
    with Backend(http_server.url, http_server.cafile) as a:
        # Simulate download flow when we get size from server before cloning
        # the backend.
        a.size()

        with a.clone() as b:
            # Backends are created identical.
            assert a.size() == b.size()
            assert list(a.extents()) == list(b.extents())
            assert a.tell() == b.tell()

            # Modifying one backend does not affect the other.
            assert a.write(b"x" * 4096)
            assert a.tell() == 4096
            assert b.tell() == 0

            # But both show the same content.
            buf = bytearray(4096)
            assert b.readinto(buf)
            assert buf == b"x" * 4096
コード例 #17
0
def test_daemon_write_to_error(http_server, uhttp_server):
    handler = Daemon(http_server, uhttp_server)
    with Backend(http_server.url, http_server.cafile) as b:
        check_write_to_error(handler, b)
コード例 #18
0
def test_daemon_read_from_error(http_server, uhttp_server):
    handler = Daemon(http_server, uhttp_server)
    with Backend(http_server.url, http_server.cafile) as b:
        check_read_from_error(handler, b)
コード例 #19
0
def test_old_daemon_read_from(http_server):
    handler = OldDaemon(http_server)
    with Backend(http_server.url, http_server.cafile) as b:
        check_read_from(handler, b)
        assert not handler.dirty
コード例 #20
0
def test_old_daemon_write_to(http_server):
    handler = OldDaemon(http_server)
    with Backend(http_server.url, http_server.cafile) as b:
        check_write_to(handler, b)
コード例 #21
0
def test_daemon_open_insecure(http_server, uhttp_server):
    Daemon(http_server, uhttp_server)
    with Backend(http_server.url, None, secure=False) as b:
        assert b.server_address == uhttp_server.server_address
コード例 #22
0
def test_old_proxy_read_from(http_server):
    handler = OldProxy(http_server)
    with Backend(http_server.url, http_server.cafile) as b:
        check_read_from(handler, b)
        assert not handler.dirty
コード例 #23
0
def test_daemon_no_unix_socket_write_to(http_server):
    handler = Daemon(http_server, extents=False)
    with Backend(http_server.url, http_server.cafile) as b:
        check_write_to(handler, b)
コード例 #24
0
def test_old_proxy_write_to(http_server):
    handler = OldProxy(http_server)
    with Backend(http_server.url, http_server.cafile) as b:
        check_write_to(handler, b)