Exemplo n.º 1
0
def test_extents_zero(nbd_server, user_file, fmt):
    size = 6 * 1024**3
    qemu_img.create(user_file.path, fmt, size=size)

    nbd_server.image = user_file.path
    nbd_server.fmt = fmt
    nbd_server.start()

    with nbd.open(nbd_server.url, "r+") as b:
        # qcow2 extents resolution is cluster size.
        data = b"x" * 64 * 1024
        b.write(data)

        # The second extent length is bigger than NBD maximum length, testing
        # that our extent length is not limited by NBD limits. The backend
        # sends multiple block status commands and merge the returned extents.
        b.seek(5 * 1024**3)
        b.write(data)

        assert list(b.extents()) == [
            image.ZeroExtent(0, len(data), False),
            image.ZeroExtent(len(data), 5 * 1024**3 - len(data), True),
            image.ZeroExtent(5 * 1024**3, len(data), False),
            image.ZeroExtent(5 * 1024**3 + len(data), 1024**3 - len(data),
                             True),
        ]
Exemplo n.º 2
0
 def fake_extents(context="zero"):
     return [
         image.ZeroExtent(0 * chunk_size, chunk_size, False),
         image.ZeroExtent(1 * chunk_size, chunk_size, True),
         image.ZeroExtent(2 * chunk_size, chunk_size, False),
         image.ZeroExtent(3 * chunk_size, chunk_size, True),
     ]
Exemplo n.º 3
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
        },
        {
            "start": chunk_size,
            "length": chunk_size,
            "zero": True
        },
    ]

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

        # Dirty extents are not available.
        with pytest.raises(errors.UnsupportedOperation):
            list(b.extents("dirty"))
Exemplo n.º 4
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
        },
        {
            "start": chunk_size,
            "length": chunk_size,
            "dirty": 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),
        ]
        assert list(b.extents("dirty")) == [
            image.DirtyExtent(0, chunk_size, True),
            image.DirtyExtent(chunk_size, chunk_size, False),
        ]
Exemplo n.º 5
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)]
Exemplo n.º 6
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)]
Exemplo n.º 7
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)]
Exemplo n.º 8
0
def test_extents(user_file):
    size = user_file.sector_size * 2

    with io.open(user_file.path, "wb") as f:
        f.truncate(size)

    with file.open(user_file.url, "r+", sparse=True) as f:
        # We support detecting extents now; empty file reports one data
        # extents.
        assert list(f.extents()) == [image.ZeroExtent(0, size, False)]
def test_extents():
    m = memory.Backend("r+", b"data")
    assert list(m.extents()) == [image.ZeroExtent(0, 4, False)]