Example #1
0
    def make_env(self,
                 sd_type='block',
                 format='raw',
                 prealloc=sc.SPARSE_VOL,
                 chain_len=2):
        size = 2 * GiB
        base_fmt = sc.name2type(format)
        with fake_env(sd_type) as env:
            with MonkeyPatch().context() as mp:
                mp.setattr(guarded, 'context', fake_guarded_context())
                mp.setattr(merge, 'sdCache', env.sdcache)
                mp.setattr(blockVolume, 'rm', FakeResourceManager())
                mp.setattr(image, 'Image', FakeImage)

                env.chain = make_qemu_chain(env,
                                            size,
                                            base_fmt,
                                            chain_len,
                                            prealloc=prealloc)

                volumes = {(vol.imgUUID, vol.volUUID): FakeVolume()
                           for vol in env.chain}
                env.sdcache.domains[env.sd_manifest.sdUUID].volumes = volumes

                def fake_chain(self, sdUUID, imgUUID, volUUID=None):
                    return env.chain

                image.Image.getChain = fake_chain
                image.Image.syncVolumeChain = FakeSyncVolumeChain()

                yield env
Example #2
0
    def make_env(self, sd_type='block', format='raw', chain_len=2):
        size = 1048576
        base_fmt = sc.name2type(format)
        with fake_env(sd_type) as env:
            rm = FakeResourceManager()
            with MonkeyPatchScope([
                (guarded, 'context', fake_guarded_context()),
                (merge, 'sdCache', env.sdcache),
                (blockVolume, 'rm', rm),
                (image, 'Image', FakeImage),
            ]):
                env.chain = make_qemu_chain(env, size, base_fmt, chain_len)

                volumes = {(vol.imgUUID, vol.volUUID): FakeVolume()
                           for vol in env.chain}
                env.sdcache.domains[env.sd_manifest.sdUUID].volumes = volumes

                def fake_chain(self, sdUUID, imgUUID, volUUID=None):
                    return env.chain

                image.Image.getChain = fake_chain
                image.Image.syncVolumeChain = FakeSyncVolumeChain()

                yield env
Example #3
0
 def test_produce_existing_volume(self):
     fake_vol = FakeVolume()
     sd = FakeSD("fake manifest")
     sd.volumes = {("img_uuid", "vol_uuid"): fake_vol}
     vol = sd.produceVolume("img_uuid", "vol_uuid")
     self.assertIs(vol, fake_vol)