コード例 #1
0
def test_dirty_bitmap(tmpdir):
    size = 1024**2

    # Create image with empty bitmap.
    img = str(tmpdir.join("img.qcow2"))
    qemu_img.create(img, "qcow2", size=size)
    qemu_img.bitmap_add(img, "b0")

    # Write data to image, modifying the bitmap.
    with qemu_nbd.open(img, "qcow2") as c:
        # This will allocate one cluster. By default bitmap granularity is also
        # one cluster, so this will make the first extent dirty.
        c.write(0, b"a")
        c.flush()

    # Read dirty extents.
    with qemu_nbd.open(img, "qcow2", read_only=True, bitmap="b0") as c:
        extents = c.extents(0, size)[nbd.QEMU_DIRTY_BITMAP + "b0"]

    bitmap = qemu_img.info(img)["format-specific"]["data"]["bitmaps"][0]

    assert extents == [
        nbd.Extent(length=bitmap["granularity"], flags=nbd.EXTENT_DIRTY),
        nbd.Extent(length=size - bitmap["granularity"], flags=0),
    ]
コード例 #2
0
def test_full_backup_guest(tmpdir, base_image):
    base = qemu_img.info(base_image)
    disk_size = base["virtual-size"]

    disk = str(tmpdir.join("disk.qcow2"))
    qemu_img.create(disk,
                    "qcow2",
                    backing_file=base_image,
                    backing_format=base["format"])

    scratch_disk = str(tmpdir.join("scratch.qcow2"))
    qemu_img.create(scratch_disk, "qcow2", size=disk_size)

    backup_disk = str(tmpdir.join("backup.qcow2"))
    qemu_img.create(backup_disk, "qcow2", size=disk_size)

    qmp_sock = nbd.UnixAddress(tmpdir.join("qmp.sock"))
    nbd_sock = nbd.UnixAddress(tmpdir.join("nbd.sock"))

    with qemu.run(disk, "qcow2", qmp_sock, shutdown_timeout=10) as guest, \
            qmp.Client(qmp_sock) as qmp_client:
        guest.login("root", "")

        assert guest.run("touch before-backup; sync") == ""

        with backup.run(qmp_client,
                        nbd_sock,
                        scratch_disk,
                        checkpoint="check1"):

            assert guest.run("touch during-backup; sync") == ""

            backup.copy_disk(nbd_sock.url("sda"), backup_disk)

    verify_backup(backup_disk, ["before-backup"])
コード例 #3
0
def test_add_bitmap(tmpdir):
    size = 10 * 1024**2
    img = str(tmpdir.join("img.qcow2"))
    qemu_img.create(img, "qcow2", size=size)
    qemu_img.bitmap_add(img, "b0")
    bitmaps = qemu_img.info(img)["format-specific"]["data"]["bitmaps"]
    assert bitmaps == [
        {"name": "b0", "flags": ["auto"], "granularity": 65536}
    ]
コード例 #4
0
def test_create_info(tmpdir, fmt):
    size = 1024**2
    image = str(tmpdir.join("image." + fmt))
    qemu_img.create(image, fmt, size=size)
    info = qemu_img.info(image)

    assert info["filename"] == image
    assert info["virtual-size"] == size
    assert info["format"] == fmt
コード例 #5
0
ファイル: backup.py プロジェクト: oVirt/ovirt-imageio
def full_backup(tmpdir, disk, fmt, sock, checkpoint=None):
    """
    Start qemu internal nbd server using address sock, exposing disk for
    full backup, creating temporary files in tmpdir.
    """
    scratch_disk = str(tmpdir.join("scratch.qcow2"))
    qmp_sock = nbd.UnixAddress(tmpdir.join("qmp.sock"))

    disk_size = qemu_img.info(disk)["virtual-size"]
    qemu_img.create(scratch_disk, "qcow2", size=disk_size)

    with qemu.run(disk, fmt, qmp_sock, start_cpu=False, shutdown_timeout=10), \
            qmp.Client(qmp_sock) as c, \
            run(c, sock, scratch_disk, checkpoint=checkpoint):
        yield
コード例 #6
0
def list_bitmaps(image):
    info = qemu_img.info(image)
    return info["format-specific"]["data"]["bitmaps"]