Beispiel #1
0
def test_read_bad_chain_raises(tmpdir):
    # Create a good chain.
    base_qcow2 = str(tmpdir.join("base.qcow2"))
    op = qemuimg.create(base_qcow2, "1m", qemuimg.FORMAT.QCOW2)
    op.run()
    top = str(tmpdir.join("top.qcow2"))
    op = qemuimg.create(top,
                        "1m",
                        qemuimg.FORMAT.QCOW2,
                        backing=base_qcow2,
                        backingFormat=qemuimg.FORMAT.QCOW2)
    op.run()

    # Create a broken chain using unsafe rebase with the wrong backing
    # format.
    base_raw = str(tmpdir.join("base.raw"))
    op = qemuimg.create(base_raw, "1m", qemuimg.FORMAT.RAW)
    op.run()
    operation = qemuimg.rebase(top,
                               backing=base_raw,
                               format=qemuimg.FORMAT.QCOW2,
                               backingFormat=qemuimg.FORMAT.QCOW2,
                               unsafe=True)
    operation.run()
    with pytest.raises(cmdutils.Error):
        qemuio.verify_pattern(top, qemuimg.FORMAT.QCOW2)
Beispiel #2
0
def test_skip_holes_during_merge_bitmaps(tmp_mount, vol_chain):
    virtual_size = MiB
    bitmap = 'bitmap'

    # Create base parent volume
    base_parent_vol = os.path.join(tmp_mount.path, 'base_parent.img')
    op = qemuimg.create(
        base_parent_vol,
        size=virtual_size,
        format=qemuimg.FORMAT.QCOW2,
        qcow2Compat='1.1'
    )
    op.run()

    # Rebase the volume chain on top of base parent volume
    op = qemuimg.rebase(
        vol_chain.base_vol, base_parent_vol, unsafe=True)
    op.run()

    # Add new bitmap to base parent volume
    op = qemuimg.bitmap_add(base_parent_vol, bitmap)
    op.run()
    # Add new bitmap to top volume, base volume is missing that
    # bitmap so there is a hole
    op = qemuimg.bitmap_add(vol_chain.top_vol, bitmap)
    op.run()

    bitmaps.merge_bitmaps(
        vol_chain.base_vol, vol_chain.top_vol,
        base_parent_path=base_parent_vol)

    info = qemuimg.info(vol_chain.base_vol)
    assert 'bitmaps' not in info
Beispiel #3
0
def _rebase_operation(base, child):
    backing = volume.getBackingVolumePath(base.imgUUID, base.volUUID)
    backing_format = sc.fmt2str(base.getFormat())
    operation = qemuimg.rebase(image=child.volumePath,
                               backing=backing,
                               format=qemuimg.FORMAT.QCOW2,
                               backingFormat=backing_format,
                               unsafe=True)
    return operation
Beispiel #4
0
def _rebase_operation(base, child):
    backing = volume.getBackingVolumePath(base.imgUUID, base.volUUID)
    backing_format = sc.fmt2str(base.getFormat())
    operation = qemuimg.rebase(image=child.volumePath,
                               backing=backing,
                               format=qemuimg.FORMAT.QCOW2,
                               backingFormat=backing_format,
                               unsafe=True)
    return operation
Beispiel #5
0
 def test_unexpected_backing_file(self):
     with self.fake_volume(sc.COW_FORMAT) as vol:
         # Simulate upload of qcow2 with unexpected backing file.
         unexpected_volume = os.path.join(os.path.dirname(vol.volumePath),
                                          "unexpected")
         open(unexpected_volume, "w").close()
         op = qemuimg.rebase(vol.volumePath, 'unexpected', unsafe=True)
         op.run()
         h = FakeHSM()
         with pytest.raises(se.ImageVerificationError):
             h.verify_untrusted_volume('sp', vol.sdUUID, vol.imgUUID,
                                       vol.volUUID)
Beispiel #6
0
def test_no_backing_chain(nbd_env):
    base, top = make_qemu_chain(nbd_env,
                                nbd_env.virtual_size,
                                sc.COW_FORMAT,
                                2,
                                qcow2_compat='1.1')

    # Fill volumes with data.
    qemuio.write_pattern(base.volumePath,
                         "qcow2",
                         offset=1 * MiB,
                         len=64 * KiB,
                         pattern=0xf0)
    qemuio.write_pattern(top.volumePath,
                         "qcow2",
                         offset=2 * MiB,
                         len=64 * KiB,
                         pattern=0xf1)

    # Download base volume.

    config = {
        "sd_id": base.sdUUID,
        "img_id": base.imgUUID,
        "vol_id": base.volUUID,
        "readonly": True,
        "backing_chain": False,
    }

    with nbd_server(config) as nbd_url:
        download_from_nbd(nbd_url, nbd_env.dst)

    compare_images(base.volumePath, nbd_env.dst, strict=True)

    # Download top volume.

    config = {
        "sd_id": top.sdUUID,
        "img_id": top.imgUUID,
        "vol_id": top.volUUID,
        "readonly": True,
        "backing_chain": False,
    }

    with nbd_server(config) as nbd_url:
        download_from_nbd(nbd_url, nbd_env.dst)

    # Remove backing file from top volume, so we can compare to top.
    op = qemuimg.rebase(top.volumePath, "", unsafe=True)
    op.run()

    compare_images(top.volumePath, nbd_env.dst, strict=True)
Beispiel #7
0
 def test_wrong_backingfile(self):
     with fake_file_env() as env:
         vol = make_qemu_chain(env, self.SIZE, sc.COW_FORMAT, 2)[1]
         # Simulate upload image with wrong backing_file.
         wrong_volume = os.path.join(os.path.dirname(vol.volumePath),
                                     "wrong")
         open(wrong_volume, "w").close()
         op = qemuimg.rebase(vol.volumePath, "wrong", unsafe=True)
         op.run()
         h = FakeHSM()
         with pytest.raises(se.ImageVerificationError):
             h.verify_untrusted_volume('sp', vol.sdUUID, vol.imgUUID,
                                       vol.volUUID)
Beispiel #8
0
    def test_read_bad_chain_raises(self):
        with namedTemporaryDir() as tmpdir:
            # Create a good chain.
            base_qcow2 = os.path.join(tmpdir, "base.qcow2")
            qemuimg.create(base_qcow2, "1m", qemuimg.FORMAT.QCOW2)
            top = os.path.join(tmpdir, "top.qcow2")
            qemuimg.create(top,
                           "1m",
                           qemuimg.FORMAT.QCOW2,
                           backing=base_qcow2,
                           backingFormat=qemuimg.FORMAT.QCOW2)

            # Create a broken chain using unsafe rebase with the wrong backing
            # format.
            base_raw = os.path.join(tmpdir, "base.raw")
            qemuimg.create(base_raw, "1m", qemuimg.FORMAT.RAW)
            operation = qemuimg.rebase(top,
                                       backing=base_raw,
                                       format=qemuimg.FORMAT.QCOW2,
                                       backingFormat=qemuimg.FORMAT.QCOW2,
                                       unsafe=True)
            operation.run()
            with self.assertRaises(cmdutils.Error):
                qemu_pattern_verify(top, qemuimg.FORMAT.QCOW2)
Beispiel #9
0
def test_read_bad_chain_raises(tmpdir):
    # Create a good chain.
    base_qcow2 = str(tmpdir.join("base.qcow2"))
    op = qemuimg.create(base_qcow2, "1m", qemuimg.FORMAT.QCOW2)
    op.run()
    top = str(tmpdir.join("top.qcow2"))
    op = qemuimg.create(top, "1m", qemuimg.FORMAT.QCOW2,
                        backing=base_qcow2,
                        backingFormat=qemuimg.FORMAT.QCOW2)
    op.run()

    # Create a broken chain using unsafe rebase with the wrong backing
    # format.
    base_raw = str(tmpdir.join("base.raw"))
    op = qemuimg.create(base_raw, "1m", qemuimg.FORMAT.RAW)
    op.run()
    operation = qemuimg.rebase(top,
                               backing=base_raw,
                               format=qemuimg.FORMAT.QCOW2,
                               backingFormat=qemuimg.FORMAT.QCOW2,
                               unsafe=True)
    operation.run()
    with pytest.raises(cmdutils.Error):
        qemuio.verify_pattern(top, qemuimg.FORMAT.QCOW2)