Ejemplo n.º 1
0
    def test_chain_after_finalize(self, base_fmt):
        with self.make_env(format=base_fmt, chain_len=3) as env:
            base_vol = env.chain[0]
            # We write data to the base and will read it from the child volume
            # to verify that the chain is valid after qemu-rebase.
            offset = 0
            pattern = 0xf0
            length = 1024
            qemu_pattern_write(base_vol.volumePath,
                               sc.fmt2str(base_vol.getFormat()),
                               offset=offset,
                               len=length,
                               pattern=pattern)

            top_vol = env.chain[1]
            child_vol = env.chain[2]

            subchain_info = dict(sd_id=base_vol.sdUUID,
                                 img_id=base_vol.imgUUID,
                                 base_id=base_vol.volUUID,
                                 top_id=top_vol.volUUID,
                                 base_generation=0)
            subchain = merge.SubchainInfo(subchain_info, 0)

            merge.finalize(subchain)

            qemu_pattern_verify(child_vol.volumePath,
                                sc.fmt2str(child_vol.getFormat()),
                                offset=offset,
                                len=length,
                                pattern=pattern)
Ejemplo n.º 2
0
    def test_one_block(self, offset, length, expected_length, qcow2_compat):
        with namedTemporaryDir() as tmpdir:
            size = 1048576
            image = os.path.join(tmpdir, "base.img")
            qemuimg.create(image, size=size, format=self.FORMAT,
                           qcow2Compat=qcow2_compat)
            qemu_pattern_write(image, self.FORMAT, offset=offset, len=length,
                               pattern=0xf0)

            expected = [
                # run 1 - empty
                {
                    "start": 0,
                    "length": offset,
                    "data": False,
                    "zero": True,
                },
                # run 2 - data
                {
                    "start": offset,
                    "length": expected_length,
                    "data": True,
                    "zero": False,
                },
                # run 3 - empty
                {
                    "start": offset + expected_length,
                    "length": size - offset - expected_length,
                    "data": False,
                    "zero": True,
                },
            ]

            self.check_map(qemuimg.map(image), expected)
Ejemplo n.º 3
0
 def test_no_match(self, img_format):
     with namedTemporaryDir() as tmpdir:
         path = os.path.join(tmpdir, 'test')
         qemuimg.create(path, '1m', img_format)
         qemu_pattern_write(path, img_format, pattern=2)
         self.assertRaises(ChainVerificationError,
                           qemu_pattern_verify, path, img_format, pattern=4)
Ejemplo n.º 4
0
    def test_one_block(self, offset, length, expected_length, qcow2_compat):
        with namedTemporaryDir() as tmpdir:
            size = 1048576
            image = os.path.join(tmpdir, "base.img")
            qemuimg.create(image, size=size, format=self.FORMAT,
                           qcow2Compat=qcow2_compat)
            qemu_pattern_write(image, self.FORMAT, offset=offset, len=length,
                               pattern=0xf0)

            expected = [
                # run 1 - empty
                {
                    "start": 0,
                    "length": offset,
                    "data": False,
                    "zero": True,
                },
                # run 2 - data
                {
                    "start": offset,
                    "length": expected_length,
                    "data": True,
                    "zero": False,
                },
                # run 3 - empty
                {
                    "start": offset + expected_length,
                    "length": size - offset - expected_length,
                    "data": False,
                    "zero": True,
                },
            ]

            self.check_map(qemuimg.map(image), expected)
Ejemplo n.º 5
0
    def test_chain_after_finalize(self, base_fmt):
        with self.make_env(format=base_fmt, chain_len=3) as env:
            base_vol = env.chain[0]
            # We write data to the base and will read it from the child volume
            # to verify that the chain is valid after qemu-rebase.
            offset = 0
            pattern = 0xf0
            length = 1024
            qemu_pattern_write(base_vol.volumePath,
                               sc.fmt2str(base_vol.getFormat()),
                               offset=offset,
                               len=length, pattern=pattern)

            top_vol = env.chain[1]
            child_vol = env.chain[2]

            subchain_info = dict(sd_id=base_vol.sdUUID,
                                 img_id=base_vol.imgUUID,
                                 base_id=base_vol.volUUID,
                                 top_id=top_vol.volUUID,
                                 base_generation=0)
            subchain = merge.SubchainInfo(subchain_info, 0)

            merge.finalize(subchain)

            qemu_pattern_verify(child_vol.volumePath,
                                sc.fmt2str(child_vol.getFormat()),
                                offset=offset,
                                len=length, pattern=pattern)
Ejemplo n.º 6
0
 def test_match_custom_offset_and_len(self, offset, len):
     with namedTemporaryDir() as tmpdir:
         path = os.path.join(tmpdir, 'test')
         qemuimg.create(path, '1m', qemuimg.FORMAT.QCOW2)
         qemu_pattern_write(path, qemuimg.FORMAT.QCOW2,
                            offset=offset, len=len)
         qemu_pattern_verify(path, qemuimg.FORMAT.QCOW2, offset=offset,
                             len=len)
Ejemplo n.º 7
0
 def test_optimal_size_cow_leaf_not_empty(self):
     # verify that optimal size is limited to max size.
     with self.make_volume(size=GIB, format=sc.COW_FORMAT) as vol:
         qemu_pattern_write(path=vol.volumePath,
                            format=sc.fmt2str(vol.getFormat()),
                            len=200 * MEGAB)
         max_size = vol.max_size(GIB, vol.getFormat())
         self.assertEqual(vol.optimal_size(), max_size)
Ejemplo n.º 8
0
 def test_optimal_size_cow_leaf_not_empty(self):
     # verify that optimal size is limited to max size.
     with self.make_volume(size=GIB, format=sc.COW_FORMAT) as vol:
         qemu_pattern_write(path=vol.volumePath,
                            format=sc.fmt2str(vol.getFormat()),
                            len=200 * MEGAB)
         max_size = vol.max_size(GIB, vol.getFormat())
         self.assertEqual(vol.optimal_size(), max_size)
Ejemplo n.º 9
0
 def test_no_match(self, img_format):
     with namedTemporaryDir() as tmpdir:
         path = os.path.join(tmpdir, 'test')
         qemuimg.create(path, '1m', img_format)
         qemu_pattern_write(path, img_format, pattern=2)
         self.assertRaises(ChainVerificationError,
                           qemu_pattern_verify,
                           path,
                           img_format,
                           pattern=4)
Ejemplo n.º 10
0
 def test_match_custom_offset_and_len(self, offset, len):
     with namedTemporaryDir() as tmpdir:
         path = os.path.join(tmpdir, 'test')
         qemuimg.create(path, '1m', qemuimg.FORMAT.QCOW2)
         qemu_pattern_write(path,
                            qemuimg.FORMAT.QCOW2,
                            offset=offset,
                            len=len)
         qemu_pattern_verify(path,
                             qemuimg.FORMAT.QCOW2,
                             offset=offset,
                             len=len)
Ejemplo n.º 11
0
def make_image(path, size, format, index, qcow2_compat, backing=None):
    qemuimg.create(path,
                   size=size,
                   format=format,
                   qcow2Compat=qcow2_compat,
                   backing=backing)
    offset = index * 1024
    qemu_pattern_write(path,
                       format,
                       offset=offset,
                       len=1024,
                       pattern=0xf0 + index)
Ejemplo n.º 12
0
 def test_match(self, img_format):
     with namedTemporaryDir() as tmpdir:
         path = os.path.join(tmpdir, 'test')
         qemuimg.create(path, '1m', img_format)
         qemu_pattern_write(path, img_format)
         qemu_pattern_verify(path, img_format)
Ejemplo n.º 13
0
 def test_match(self, img_format):
     with namedTemporaryDir() as tmpdir:
         path = os.path.join(tmpdir, 'test')
         qemuimg.create(path, '1m', img_format)
         qemu_pattern_write(path, img_format)
         qemu_pattern_verify(path, img_format)
Ejemplo n.º 14
0
def make_image(path, size, format, index, qcow2_compat, backing=None):
    qemuimg.create(path, size=size, format=format, qcow2Compat=qcow2_compat,
                   backing=backing)
    offset = index * 1024
    qemu_pattern_write(path, format, offset=offset, len=1024,
                       pattern=0xf0 + index)