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))
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)
def test_getallimages(self): with fake_file_env() as env: self.assertEqual(set(), env.sd_manifest.getAllImages()) img_id = str(uuid.uuid4()) vol_id = str(uuid.uuid4()) make_file_volume(env.sd_manifest, VOLSIZE, img_id, vol_id) self.assertIn(img_id, env.sd_manifest.getAllImages())
def fake_volume(self, vol_fmt): with fake_file_env() as env: img_id = str(uuid.uuid4()) vol_id = str(uuid.uuid4()) 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)
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))
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))
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))
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))
def test_getallvolumes(self): # Artifacts must not be recognized as volumes until commit is called. with fake_file_env() as env: self.assertEqual({}, env.sd_manifest.getAllVolumes()) artifacts = env.sd_manifest.get_volume_artifacts( self.img_id, self.vol_id) artifacts.create(*BASE_RAW_PARAMS) self.assertEqual({}, env.sd_manifest.getAllVolumes()) artifacts.commit() self.assertIn(self.vol_id, env.sd_manifest.getAllVolumes())
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))
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 = sd.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())
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())
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))
def test_repopath_location(self): with fake_file_env() as env: self.assertTrue(env.sd_manifest.getRepoPath().startswith(TEMPDIR))
def test_no_fakelvm(self): with fake_file_env() as env: self.assertFalse(hasattr(env, 'lvm'))
def test_getmdpath(self): with fake_file_env() as env: sd_manifest = env.sd_manifest mdpath = os.path.join(sd_manifest.domaindir, sd.DOMAIN_META_DATA) self.assertEquals(mdpath, env.sd_manifest.getMDPath())
def test_getvallocsize(self): with fake_file_env() as env: make_file_volume(env.sd_manifest, VOLSIZE, self.img_id, self.vol_id) self.assertEqual(0, env.sd_manifest.getVAllocSize( self.img_id, self.vol_id))
def test_get_monitoring_path(self): with fake_file_env() as env: self.assertEqual(env.sd_manifest.metafile, env.sd_manifest.getMonitoringPath())
def test_getmetaparam(self): with fake_file_env() as env: sd_manifest = env.sd_manifest self.assertEquals(sd_manifest.sdUUID, sd_manifest.getMetaParam(sd.DMDK_SDUUID))
def test_getisodomainimagesdir(self): with fake_file_env() as env: isopath = os.path.join(env.sd_manifest.domaindir, sd.DOMAIN_IMAGES, sd.ISO_IMAGE_UUID) self.assertEquals(isopath, env.sd_manifest.getIsoDomainImagesDir())
def test_getvsize(self): with fake_file_env() as env: make_file_volume(env.sd_manifest, VOLSIZE, self.img_id, self.vol_id) self.assertEqual(VOLSIZE, env.sd_manifest.getVSize( self.img_id, self.vol_id))
def test_getreaddelay(self): with fake_file_env() as env: self.assertIsInstance(env.sd_manifest.getReadDelay(), float)
def test_getvallocsize(self): with fake_file_env() as env: sd_manifest = env.sd_manifest imguuid, voluuid = make_file_volume(sd_manifest.domaindir, VOLSIZE) self.assertEqual(0, sd_manifest.getVAllocSize(imguuid, voluuid))
def fake_env(self): return fake_file_env()