Example #1
0
def test_volume_type_file_env(vol_type):
    with fake_file_env() as env:
        img_id = make_uuid()
        vol_id = make_uuid()
        make_file_volume(env.sd_manifest, 0, img_id, vol_id, vol_type=vol_type)
        vol = env.sd_manifest.produceVolume(img_id, vol_id)
        assert vol.getVolType() == sc.type2name(vol_type)
Example #2
0
 def fake_volume(self, vol_fmt, sd_version=3):
     with fake_file_env(sd_version=sd_version) as env:
         img_id = make_uuid()
         vol_id = make_uuid()
         make_file_volume(env.sd_manifest, self.SIZE, img_id, vol_id,
                          vol_format=vol_fmt)
         yield env.sd_manifest.produceVolume(img_id, vol_id)
Example #3
0
 def test_cow_vm_conf_disk(self):
     """
     When a VM configuration disk is actually COW format report it correctly
     """
     with fake_file_env() as env:
         vol = make_volume(env, VM_CONF_SIZE, md_fmt='cow', real_fmt='cow')
         self.assertFalse(workarounds.invalid_vm_conf_disk(vol))
Example #4
0
 def fake_volume(self, vol_fmt, sd_version=3):
     with fake_file_env(sd_version=sd_version) as env:
         img_id = make_uuid()
         vol_id = make_uuid()
         make_file_volume(env.sd_manifest, self.SIZE, img_id, vol_id,
                          vol_format=vol_fmt)
         yield env.sd_manifest.produceVolume(img_id, vol_id)
Example #5
0
 def test_volume_type(self, vol_type):
     with fake_file_env() as env:
         img_id = make_uuid()
         vol_id = make_uuid()
         make_file_volume(env.sd_manifest, 0, img_id, vol_id,
                          vol_type=vol_type)
         vol = env.sd_manifest.produceVolume(img_id, vol_id)
         self.assertEqual(vol.getVolType(), sc.type2name(vol_type))
Example #6
0
 def test_bad_format_other_size(self):
     """
     When the volume size does not match the VM configuration disk size then
     the workaround will not be activated even when the formats don't match
     """
     size = 2 * VM_CONF_SIZE
     with fake_file_env() as env:
         vol = make_volume(env, size, md_fmt='cow', real_fmt='raw')
         self.assertFalse(workarounds.invalid_vm_conf_disk(vol))
Example #7
0
 def test_bad_format_vm_conf_disk(self):
     """
     When the volume size matches the VM configuration disk size and the
     source volume reports COW even though qemuimg reports RAW then we
     expect the workaround to report both volumes as RAW.
     """
     with fake_file_env() as env:
         vol = make_volume(env, VM_CONF_SIZE, md_fmt='cow', real_fmt='raw')
         self.assertTrue(workarounds.invalid_vm_conf_disk(vol))
Example #8
0
    def test_domain_metadata_io(self):
        with fake_file_env() as env:
            desc = 'foo'
            set_domain_metaparams(env.sd_manifest, {sd.DMDK_DESCRIPTION: desc})

            # Test that metadata is persisted to our temporary storage area
            domain_dir = env.sd_manifest.domaindir
            manifest = fileSD.FileStorageDomainManifest(domain_dir)
            self.assertEqual(desc, manifest.getMetaParam(sd.DMDK_DESCRIPTION))
Example #9
0
def test_domain_metadata_io_file_env():
    with fake_file_env() as env:
        desc = 'foo'
        set_domain_metaparams(env.sd_manifest, {sd.DMDK_DESCRIPTION: desc})

        # Test that metadata is persisted to our temporary storage area.
        domain_dir = env.sd_manifest.domaindir
        manifest = fileSD.FileStorageDomainManifest(domain_dir)
        assert desc == manifest.getMetaParam(sd.DMDK_DESCRIPTION)
Example #10
0
 def test_missing_backing_file(self):
     with fake_file_env() as env:
         vol = make_qemu_chain(env, self.SIZE, sc.COW_FORMAT, 2)[1]
         # Simulate upload of image without backing file to a a snapshot
         qemuimg.create(vol.volumePath,
                        size=self.SIZE,
                        format=qemuimg.FORMAT.QCOW2)
         h = FakeHSM()
         self.assertRaises(se.ImageVerificationError,
                           h.verify_untrusted_volume, 'sp', vol.sdUUID,
                           vol.imgUUID, vol.volUUID)
Example #11
0
def test_volume_structure():
    with fake_file_env() as env:
        img_id = make_uuid()
        vol_id = make_uuid()
        make_file_volume(env.sd_manifest, 0, img_id, vol_id)
        image_dir = env.sd_manifest.getImagePath(img_id)
        files = (vol_id, vol_id + sc.LEASE_FILEEXT,
                 vol_id + fileVolume.META_FILEEXT)
        for f in files:
            path = os.path.join(image_dir, f)
            assert os.path.exists(path)
Example #12
0
 def test_volume_structure(self):
     with fake_file_env() as env:
         img_id = make_uuid()
         vol_id = make_uuid()
         make_file_volume(env.sd_manifest, 0, img_id, vol_id)
         image_dir = env.sd_manifest.getImagePath(img_id)
         files = (vol_id, vol_id + sc.LEASE_FILEEXT,
                  vol_id + fileVolume.META_FILEEXT)
         for f in files:
             path = os.path.join(image_dir, f)
             self.assertTrue(os.path.exists(path))
Example #13
0
 def test_missing_backing_file(self):
     with fake_file_env() as env:
         vol = make_qemu_chain(env, self.SIZE, sc.COW_FORMAT, 2)[1]
         # Simulate upload of image without backing file to a a snapshot
         op = qemuimg.create(vol.volumePath, size=self.SIZE,
                             format=qemuimg.FORMAT.QCOW2)
         op.run()
         h = FakeHSM()
         with pytest.raises(se.ImageVerificationError):
             h.verify_untrusted_volume(
                 'sp', vol.sdUUID, vol.imgUUID, vol.volUUID)
Example #14
0
 def test_getallimages(self):
     # The current behavior of getAllImages is to report garbage image
     # directories (perhaps this should be changed).
     with fake_file_env() as env:
         garbage_img_id = sc.REMOVED_IMAGE_PREFIX + self.img_id
         self.assertEqual(set(), env.sd_manifest.getAllImages())
         artifacts = env.sd_manifest.get_volume_artifacts(
             self.img_id, self.vol_id)
         artifacts.create(*BASE_PARAMS[sc.RAW_FORMAT])
         self.assertEqual({garbage_img_id}, env.sd_manifest.getAllImages())
         artifacts.commit()
         self.assertEqual({self.img_id}, env.sd_manifest.getAllImages())
Example #15
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 of wrong image
         op = qemuimg.create(vol.volumePath, size=self.SIZE,
                             format=qemuimg.FORMAT.QCOW2,
                             backing='wrong-uuid')
         op.run()
         h = FakeHSM()
         with pytest.raises(se.ImageVerificationError):
             h.verify_untrusted_volume(
                 'sp', vol.sdUUID, vol.imgUUID, vol.volUUID)
Example #16
0
    def test_volume_metadata_io(self):
        with fake_file_env() as env:
            size = 1 * MB
            img_id = make_uuid()
            vol_id = make_uuid()
            make_file_volume(env.sd_manifest, size, img_id, vol_id)
            vol = env.sd_manifest.produceVolume(img_id, vol_id)
            desc = 'foo'
            vol.setDescription(desc)

            # Test that metadata is persisted to our temporary storage area
            vol = env.sd_manifest.produceVolume(img_id, vol_id)
            self.assertEqual(desc, vol.getDescription())
Example #17
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)
Example #18
0
def test_volume_metadata_io_file_env():
    with fake_file_env() as env:
        size = 1 * MiB
        img_id = make_uuid()
        vol_id = make_uuid()
        make_file_volume(env.sd_manifest, size, img_id, vol_id)
        vol = env.sd_manifest.produceVolume(img_id, vol_id)
        desc = 'foo'
        vol.setDescription(desc)

        # Test that metadata is persisted to our temporary storage area.
        vol = env.sd_manifest.produceVolume(img_id, vol_id)
        assert desc == vol.getDescription()
Example #19
0
    def test_repo_location(self):
        with fake_file_env() as env:
            # Verify that the environment uses expected tmp dir.
            self.assertTrue(env.tmpdir.startswith(TEMPDIR))

            # Verify that global REPO consntats are patched.
            self.assertEqual(sc.REPO_DATA_CENTER, env.tmpdir)
            repo_mnt_dir = os.path.join(sc.REPO_DATA_CENTER, "mnt")
            self.assertEqual(sc.REPO_MOUNT_DIR, repo_mnt_dir)

            # And domain is mounted in the patched envrionment.
            dom = env.sd_manifest
            mountpoint = os.path.join(sc.REPO_MOUNT_DIR, "server:_path")
            self.assertEqual(dom.mountpoint, mountpoint)
Example #20
0
def test_repo_location():
    with fake_file_env() as env:
        # Verify that the environment uses expected tmp dir.
        assert env.tmpdir.startswith(TEMPDIR)

        # Verify that global REPO consntats are patched.
        assert sc.REPO_DATA_CENTER == env.tmpdir
        repo_mnt_dir = os.path.join(sc.REPO_DATA_CENTER, "mnt")
        assert sc.REPO_MOUNT_DIR == repo_mnt_dir

        # And domain is mounted in the patched environment.
        dom = env.sd_manifest
        mountpoint = os.path.join(sc.REPO_MOUNT_DIR, "server:_path")
        assert dom.mountpoint == mountpoint
Example #21
0
    def test_repo_location(self):
        with fake_file_env() as env:
            # Verify that the environment uses expected tmp dir.
            self.assertTrue(env.tmpdir.startswith(TEMPDIR))

            # Verify that global REPO consntats are patched.
            self.assertEqual(sc.REPO_DATA_CENTER, env.tmpdir)
            repo_mnt_dir = os.path.join(sc.REPO_DATA_CENTER, "mnt")
            self.assertEqual(sc.REPO_MOUNT_DIR, repo_mnt_dir)

            # And domain is mounted in the patched envrionment.
            dom = env.sd_manifest
            mountpoint = os.path.join(sc.REPO_MOUNT_DIR, "server:_path")
            self.assertEqual(dom.mountpoint, mountpoint)
Example #22
0
 def test_no_fakelvm(self):
     with fake_file_env() as env:
         self.assertFalse(hasattr(env, 'lvm'))
Example #23
0
 def test_no_fakelvm(self):
     with fake_file_env() as env:
         self.assertFalse(hasattr(env, 'lvm'))
Example #24
0
 def test_valid_with_backingfile(self):
     with fake_file_env() as env:
         vol = make_qemu_chain(env, self.SIZE, sc.COW_FORMAT, 2)[1]
         h = FakeHSM()
         h.verify_untrusted_volume(
             'sp', vol.sdUUID, vol.imgUUID, vol.volUUID)
Example #25
0
 def fake_env(self):
     return fake_file_env()
Example #26
0
 def test_domain_structure(self):
     with fake_file_env() as env:
         self.assertTrue(os.path.exists(env.sd_manifest.metafile))
         images_dir = os.path.dirname(env.sd_manifest.getImagePath('foo'))
         self.assertTrue(os.path.exists(images_dir))
Example #27
0
def test_domain_structure_file_env():
    with fake_file_env() as env:
        assert os.path.exists(env.sd_manifest.metafile)
        images_dir = os.path.dirname(env.sd_manifest.getImagePath('foo'))
        assert os.path.exists(images_dir)
Example #28
0
def test_no_fakelvm():
    with fake_file_env() as env:
        assert not hasattr(env, 'lvm')
Example #29
0
def file_env(request):
    with fake_file_env(remote_path=request.param) as env:
        yield env
Example #30
0
 def test_repopath_location(self):
     with fake_file_env() as env:
         self.assertTrue(env.sd_manifest.getRepoPath().startswith(TEMPDIR))
Example #31
0
 def test_domain_structure(self):
     with fake_file_env() as env:
         self.assertTrue(os.path.exists(env.sd_manifest.metafile))
         images_dir = os.path.dirname(env.sd_manifest.getImagePath('foo'))
         self.assertTrue(os.path.exists(images_dir))
Example #32
0
 def test_valid_without_backingfile(self):
     with fake_file_env() as env:
         vol = make_qemu_chain(env, self.SIZE, sc.COW_FORMAT, 2)[0]
         h = FakeHSM()
         self.assertNotRaises(h.verify_untrusted_volume, 'sp', vol.sdUUID,
                              vol.imgUUID, vol.volUUID)
Example #33
0
 def test_valid_without_backingfile(self):
     with fake_file_env() as env:
         vol = make_qemu_chain(env, self.SIZE, sc.COW_FORMAT, 2)[0]
         h = FakeHSM()
         h.verify_untrusted_volume(
             'sp', vol.sdUUID, vol.imgUUID, vol.volUUID)