Beispiel #1
0
def test_copy_data_collapse(tmpdir, tmp_repo, fake_access, fake_rescan, tmp_db,
                            fake_task, fake_scheduler, monkeypatch,
                            dest_format, sd_version):
    dom = tmp_repo.create_localfs_domain(name="domain", version=sd_version)

    chain_size = 3
    volumes = create_chain(dom, chain_size)
    dest_img_id = str(uuid.uuid4())
    dest_vol_id = str(uuid.uuid4())

    length = MiB

    # Write some data to each layer
    for i, vol in enumerate(volumes):
        qemuio.write_pattern(vol.getVolumePath(),
                             sc.fmt2str(vol.getFormat()),
                             offset=(i * length))

    # The last volume in the chain is the leaf
    source_leaf_vol = volumes[-1]
    dest_vol = create_volume(dom,
                             dest_img_id,
                             dest_vol_id,
                             volFormat=dest_format)

    source = dict(endpoint_type='div',
                  sd_id=source_leaf_vol.sdUUID,
                  img_id=source_leaf_vol.imgUUID,
                  vol_id=source_leaf_vol.volUUID)
    dest = dict(endpoint_type='div',
                sd_id=source_leaf_vol.sdUUID,
                img_id=dest_img_id,
                vol_id=dest_vol_id)

    # Run copy_data from the source chain to dest_vol, essentially
    # executing qemu-img convert
    job = copy_data.Job(str(uuid.uuid4()), 0, source, dest)
    monkeypatch.setattr(guarded, 'context', fake_guarded_context())
    job.run()

    # Source chain and destination image must have the same data but allocation
    # may differ.
    op = qemuimg.compare(source_leaf_vol.getVolumePath(),
                         dest_vol.getVolumePath(),
                         img1_format='qcow2',
                         img2_format=sc.fmt2str(dest_format),
                         strict=False)
    op.run()

    # Destination actual size should be smaller than source chain actual size,
    # since we have only one qcow2 header (qcow2), or no header (raw).
    src_actual_size = sum(
        qemuimg.info(vol.getVolumePath())["actualsize"] for vol in volumes)
    dst_actual_size = qemuimg.info(dest_vol.getVolumePath())["actualsize"]
    assert dst_actual_size < src_actual_size
Beispiel #2
0
    def test_qcow2_collapsed(self, user_mount, dst_compat, create):
        virtual_size = MiB
        # Create empty source chain.
        src_base = os.path.join(user_mount.path, 'src_base.img')
        op = qemuimg.create(
            src_base,
            size=virtual_size,
            format=qemuimg.FORMAT.QCOW2,
            qcow2Compat='1.1'
        )
        op.run()

        src_top = os.path.join(user_mount.path, 'src_top.img')
        op = qemuimg.create(
            src_top,
            size=virtual_size,
            format=qemuimg.FORMAT.QCOW2,
            qcow2Compat='1.1',
            backing=src_base,
            backingFormat='qcow2'
        )
        op.run()

        # Create destination image.
        dst = os.path.join(user_mount.path, 'dst.img')
        op = qemuimg.create(
            dst,
            size=virtual_size,
            format=qemuimg.FORMAT.QCOW2,
            qcow2Compat=dst_compat,
        )
        op.run()

        # Copy src chain to dst.
        op = qemuimg.convert(
            src_top,
            dst,
            srcFormat='qcow2',
            dstFormat='qcow2',
            dstQcow2Compat=dst_compat,
            create=create
        )
        op.run()

        # Since source is empty strict compare should work on both source
        # chain and destination.
        op = qemuimg.compare(
            src_top,
            dst,
            img1_format='qcow2',
            img2_format='qcow2',
            strict=True
        )
        op.run()
Beispiel #3
0
def test_qcow2_compat(user_mount, fake_scheduler, qcow2_compat, sd_version):
    src_fmt = sc.name2type("cow")
    dst_fmt = sc.name2type("cow")
    job_id = make_uuid()
    data_center = os.path.join(user_mount.path, "data-center")

    with make_env("file",
                  src_fmt,
                  dst_fmt,
                  sd_version=sd_version,
                  src_qcow2_compat=qcow2_compat,
                  data_center=data_center) as env:
        src_vol = env.src_chain[0]
        dst_vol = env.dst_chain[0]
        source = dict(endpoint_type='div',
                      sd_id=src_vol.sdUUID,
                      img_id=src_vol.imgUUID,
                      vol_id=src_vol.volUUID)
        dest = dict(endpoint_type='div',
                    sd_id=dst_vol.sdUUID,
                    img_id=dst_vol.imgUUID,
                    vol_id=dst_vol.volUUID)
        job = copy_data.Job(job_id, 0, source, dest)

        job.run()

        dst_info = qemuimg.info(dst_vol.volumePath)
        actual_compat = dst_info['format-specific']['data']['compat']
        assert actual_compat == env.sd_manifest.qcow2_compat()

        # After the copy, images must be exactly the same.
        op = qemuimg.compare(
            src_vol.getVolumePath(),
            dst_vol.getVolumePath(),
            img1_format='qcow2',
            img2_format='qcow2',
            strict=True,
        )
        op.run()
Beispiel #4
0
def compare_images(a, b, strict=False):
    op = qemuimg.compare(a, b, strict=strict)
    op.run()
Beispiel #5
0
    def test_qcow2(self, user_mount, dst_compat, create):
        virtual_size = MiB
        # Create source chain.
        src_base = os.path.join(user_mount.path, 'src_base.img')
        op = qemuimg.create(
            src_base,
            size=virtual_size,
            format=qemuimg.FORMAT.QCOW2,
            qcow2Compat='1.1'
        )
        op.run()

        src_top = os.path.join(user_mount.path, 'src_top.img')
        op = qemuimg.create(
            src_top,
            size=virtual_size,
            format=qemuimg.FORMAT.QCOW2,
            qcow2Compat='1.1',
            backing=src_base,
            backingFormat='qcow2'
        )
        op.run()

        # Create dest chain
        dst_base = os.path.join(user_mount.path, 'dst_base.img')
        op = qemuimg.create(
            dst_base,
            size=virtual_size,
            format=qemuimg.FORMAT.QCOW2,
            qcow2Compat=dst_compat,
        )
        op.run()

        dst_top = os.path.join(user_mount.path, 'dst_top.img')
        op = qemuimg.create(
            dst_top,
            size=virtual_size,
            format=qemuimg.FORMAT.QCOW2,
            qcow2Compat=dst_compat,
            backing=dst_base,
            backingFormat='qcow2'
        )
        op.run()

        # Write data to the source chain.
        cluster_size = 64 * KiB
        for i, path in enumerate([src_base, src_top]):
            qemuio.write_pattern(
                path,
                "qcow2",
                offset=i * cluster_size,
                len=cluster_size,
                pattern=0xf0 + i)

        # Copy base to base.
        op = qemuimg.convert(
            src_base,
            dst_base,
            srcFormat='qcow2',
            dstFormat='qcow2',
            dstQcow2Compat=dst_compat,
            create=create
        )
        op.run()

        # Copy top to top.
        op = qemuimg.convert(
            src_top,
            dst_top,
            srcFormat='qcow2',
            dstFormat='qcow2',
            backing=dst_base,
            backingFormat='qcow2',
            dstQcow2Compat=dst_compat,
            # With a backing we can always use False.
            create=False
        )
        op.run()

        # Run comparisons, if there is a mismatch in content or size
        # op.run() will raise and fail the test.
        op = qemuimg.compare(
            src_base,
            dst_base,
            img1_format='qcow2',
            img2_format='qcow2',
            strict=True
        )
        op.run()

        op = qemuimg.compare(
            src_top,
            dst_top,
            img1_format='qcow2',
            img2_format='qcow2',
            strict=True
        )
        op.run()
Beispiel #6
0
    def test_qcow2_backing_file_without_creation(self):
        virtual_size = MiB
        with namedTemporaryDir() as tmpdir:
            # Create source chain.
            src_base = os.path.join(tmpdir, 'src_base.img')
            op = qemuimg.create(
                src_base,
                size=virtual_size,
                format=qemuimg.FORMAT.QCOW2,
                qcow2Compat='1.1'
            )
            op.run()

            src_top = os.path.join(tmpdir, 'src_top.img')
            op = qemuimg.create(
                src_top,
                size=virtual_size,
                format=qemuimg.FORMAT.QCOW2,
                qcow2Compat='1.1',
                backing=src_base,
                backingFormat='qcow2'
            )
            op.run()

            # Create dest chain
            dst_base = os.path.join(tmpdir, 'dst_base.img')
            op = qemuimg.create(
                dst_base,
                size=virtual_size,
                format=qemuimg.FORMAT.QCOW2,
                qcow2Compat='1.1'
            )
            op.run()

            dst_top = os.path.join(tmpdir, 'dst_top.img')
            op = qemuimg.create(
                dst_top,
                size=virtual_size,
                format=qemuimg.FORMAT.QCOW2,
                qcow2Compat='1.1',
                backing=dst_base,
                backingFormat='qcow2'
            )
            op.run()

            # Write data to the source chain.
            cluster_size = 64 * KiB
            for i, path in enumerate([src_base, src_top]):
                qemuio.write_pattern(
                    path,
                    "qcow2",
                    offset=i * cluster_size,
                    len=cluster_size,
                    pattern=0xf0 + i)

            # Copy base to base.
            op = qemuimg.convert(
                src_base,
                dst_base,
                srcFormat='qcow2',
                dstFormat='qcow2',
                dstQcow2Compat='1.1',
                create=False
            )
            op.run()

            # Copy top to top.
            op = qemuimg.convert(
                src_top,
                dst_top,
                srcFormat='qcow2',
                dstFormat='qcow2',
                backing=dst_base,
                dstQcow2Compat='1.1',
                create=False
            )
            op.run()

            # Run comparisons, if there is a mismatch in content or size
            # op.run() will raise and fail the test.
            op = qemuimg.compare(
                src_base,
                dst_base,
                img1_format='qcow2',
                img2_format='qcow2',
                strict=True
            )
            op.run()

            op = qemuimg.compare(
                src_top,
                dst_top,
                img1_format='qcow2',
                img2_format='qcow2',
                strict=True
            )
            op.run()