def test_volume_accessibility(self): with fake_block_env() as env: sd_id = env.sd_manifest.sdUUID img_id = make_uuid() vol_id = make_uuid() make_block_volume(env.lvm, env.sd_manifest, 1 * MB, img_id, vol_id) self.assertTrue(os.path.isfile(env.lvm.lvPath(sd_id, vol_id))) domain_path = os.path.join(env.sd_manifest.domaindir, sd.DOMAIN_IMAGES, img_id, vol_id) repo_path = os.path.join(env.sd_manifest.getRepoPath(), sd_id, sd.DOMAIN_IMAGES, img_id, vol_id) self.assertNotEqual(repo_path, domain_path) # The links to the dev are created only when producing the volume self.assertFalse(os.path.isfile(domain_path)) self.assertFalse(os.path.isfile(repo_path)) env.sd_manifest.produceVolume(img_id, vol_id) self.assertTrue(os.path.samefile(repo_path, domain_path))
def test_volume_accessibility(self): with fake_block_env() as env: sd_id = env.sd_manifest.sdUUID img_id = make_uuid() vol_id = make_uuid() make_block_volume(env.lvm, env.sd_manifest, 1 * MB, img_id, vol_id) self.assertTrue(os.path.isfile(env.lvm.lvPath(sd_id, vol_id))) domain_path = os.path.join(env.sd_manifest.domaindir, sd.DOMAIN_IMAGES, img_id, vol_id) repo_path = os.path.join(env.sd_manifest.getRepoPath(), sd_id, sd.DOMAIN_IMAGES, img_id, vol_id) self.assertNotEqual(repo_path, domain_path) # The links to the dev are created only when producing the volume self.assertFalse(os.path.isfile(domain_path)) self.assertFalse(os.path.isfile(repo_path)) env.sd_manifest.produceVolume(img_id, vol_id) self.assertTrue(os.path.samefile(repo_path, domain_path))
def test_volume_type(self, vol_type): with fake_block_env() as env: img_id = make_uuid() vol_id = make_uuid() make_block_volume(env.lvm, 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_unaligned_size_raises(self): with fake_block_env() as env: artifacts = env.sd_manifest.get_volume_artifacts( self.img_id, self.vol_id) size, vol_format, disk_type, desc = BASE_PARAMS[sc.RAW_FORMAT] size = MB + 1 self.assertRaises(se.InvalidParameterException, artifacts.create, size, vol_format, disk_type, desc)
def test_volume_type(self, vol_type): with fake_block_env() as env: img_id = make_uuid() vol_id = make_uuid() make_block_volume(env.lvm, 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_block_env(): with fake_block_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. sd_id = env.sd_manifest.sdUUID manifest = blockSD.BlockStorageDomainManifest(sd_id) assert desc == manifest.getMetaParam(sd.DMDK_DESCRIPTION)
def test_domain_metadata_io(self): with fake_block_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 sd_id = env.sd_manifest.sdUUID manifest = blockSD.BlockStorageDomainManifest(sd_id) self.assertEqual(desc, manifest.getMetaParam(sd.DMDK_DESCRIPTION))
def _metaslot_selection(self, used_slots, free_slot, sd_version): with fake_block_env(sd_version=sd_version) as env: for offset in used_slots: lv = make_uuid() sduuid = env.sd_manifest.sdUUID env.lvm.createLV(sduuid, lv, VOLSIZE // MiB) tag = sc.TAG_PREFIX_MD + str(offset) env.lvm.changeLVsTags(sduuid, (lv,), addTags=(tag,)) with env.sd_manifest.acquireVolumeMetadataSlot(None) as mdSlot: assert mdSlot == free_slot
def test_metaslot_selection(self, used_slots, free_slot): with fake_block_env() as env: for offset in used_slots: lv = make_uuid() sduuid = env.sd_manifest.sdUUID env.lvm.createLV(sduuid, lv, VOLSIZE / MB) tag = sc.TAG_PREFIX_MD + str(offset) env.lvm.addtag(sduuid, lv, tag) with env.sd_manifest.acquireVolumeMetadataSlot(None, 1) as mdSlot: self.assertEqual(mdSlot, free_slot)
def _metaslot_selection(self, used_slots, free_slot, sd_version): with fake_block_env(sd_version=sd_version) as env: for offset in used_slots: lv = make_uuid() sduuid = env.sd_manifest.sdUUID env.lvm.createLV(sduuid, lv, VOLSIZE // MB) tag = sc.TAG_PREFIX_MD + str(offset) env.lvm.addtag(sduuid, lv, tag) with env.sd_manifest.acquireVolumeMetadataSlot(None) as mdSlot: assert mdSlot == free_slot
def test_getallimages(self): # The current behavior of getAllImages for block domains does not # report images that contain only artifacts. This differs from the # file implementation. with fake_block_env() as env: 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(set(), env.sd_manifest.getAllImages()) artifacts.commit() self.assertEqual({self.img_id}, env.sd_manifest.getAllImages())
def test_volume_size_alignment(size_param): with fake_block_env() as env: sd_id = env.sd_manifest.sdUUID img_id = make_uuid() vol_id = make_uuid() make_block_volume(env.lvm, env.sd_manifest, size_param, img_id, vol_id) vol = env.sd_manifest.produceVolume(img_id, vol_id) expected_size = utils.round(size_param, sc.VG_EXTENT_SIZE) assert expected_size == vol.getCapacity() assert expected_size == int(env.lvm.getLV(sd_id, vol_id).size) lv_file_size = os.stat(env.lvm.lvPath(sd_id, vol_id)).st_size assert expected_size == lv_file_size
def test_volume_size_alignment(self, size_param): with fake_block_env() as env: sd_id = env.sd_manifest.sdUUID img_id = make_uuid() vol_id = make_uuid() make_block_volume(env.lvm, env.sd_manifest, size_param, img_id, vol_id) vol = env.sd_manifest.produceVolume(img_id, vol_id) extent_size = sc.VG_EXTENT_SIZE_MB * MB expected_size = utils.round(size_param, extent_size) self.assertEqual(expected_size, vol.getCapacity()) self.assertEqual(expected_size, int(env.lvm.getLV(sd_id, vol_id).size)) lv_file_size = os.stat(env.lvm.lvPath(sd_id, vol_id)).st_size self.assertEqual(expected_size, lv_file_size)
def test_size_rounded_up(self): # If the underlying device is larger the size will be updated with fake_block_env() as env: sd_id = env.sd_manifest.sdUUID vg = env.lvm.getVG(sd_id) expected_size = int(vg.extent_size) requested_size = expected_size - MB artifacts = env.sd_manifest.get_volume_artifacts( self.img_id, self.vol_id) artifacts.create(requested_size, sc.RAW_FORMAT, image.SYSTEM_DISK_TYPE, 'raw_volume') artifacts.commit() vol = env.sd_manifest.produceVolume(self.img_id, self.vol_id) self.assertEqual(expected_size // sc.BLOCK_SIZE, vol.getSize()) self.assertEqual(expected_size, int(env.lvm.getLV(sd_id, self.vol_id).size))
def test_volume_size_alignment(self, size_param): with fake_block_env() as env: sd_id = env.sd_manifest.sdUUID img_id = make_uuid() vol_id = make_uuid() make_block_volume(env.lvm, env.sd_manifest, size_param, img_id, vol_id) vol = env.sd_manifest.produceVolume(img_id, vol_id) extent_size = sc.VG_EXTENT_SIZE_MB * MB expected_size = utils.round(size_param, extent_size) self.assertEqual(expected_size // sc.BLOCK_SIZE, vol.getSize()) self.assertEqual(expected_size, int(env.lvm.getLV(sd_id, vol_id).size)) lv_file_size = os.stat(env.lvm.lvPath(sd_id, vol_id)).st_size self.assertEqual(expected_size, lv_file_size)
def test_volume_metadata_io_block_env(): with fake_block_env() as env: sd_id = env.sd_manifest.sdUUID img_id = make_uuid() vol_id = make_uuid() size = sc.VG_EXTENT_SIZE make_block_volume(env.lvm, env.sd_manifest, size, img_id, vol_id) assert vol_id == env.lvm.getLV(sd_id, vol_id).name vol = env.sd_manifest.produceVolume(img_id, vol_id) assert size == vol.getCapacity() 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()
def test_domain_structure_block_env(): with fake_block_env() as env: vg_name = env.sd_manifest.sdUUID md_path = env.lvm.lvPath(vg_name, sd.METADATA) assert os.path.exists(md_path) version = env.sd_manifest.getVersion() for lv in env.sd_manifest.special_volumes(version): assert lv == env.lvm.getLV(vg_name, lv).name images_dir = os.path.join(env.sd_manifest.domaindir, sd.DOMAIN_IMAGES) assert os.path.exists(images_dir) # Check the storage repository. repo_path = env.sd_manifest.getRepoPath() domain_link = os.path.join(repo_path, env.sd_manifest.sdUUID) assert os.path.islink(domain_link) assert env.sd_manifest.domaindir == os.readlink(domain_link)
def test_volume_metadata_io(self): with fake_block_env() as env: sd_id = env.sd_manifest.sdUUID img_id = make_uuid() vol_id = make_uuid() size_mb = sc.VG_EXTENT_SIZE_MB size = size_mb * MB make_block_volume(env.lvm, env.sd_manifest, size, img_id, vol_id) self.assertEqual(vol_id, env.lvm.getLV(sd_id, vol_id).name) vol = env.sd_manifest.produceVolume(img_id, vol_id) self.assertEqual(size, vol.getCapacity()) 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_block_env() as env: vg_name = env.sd_manifest.sdUUID md_path = env.lvm.lvPath(vg_name, sd.METADATA) self.assertTrue(os.path.exists(md_path)) version = env.sd_manifest.getVersion() for lv in env.sd_manifest.special_volumes(version): self.assertEqual(lv, env.lvm.getLV(vg_name, lv).name) images_dir = os.path.join(env.sd_manifest.domaindir, sd.DOMAIN_IMAGES) self.assertTrue(os.path.exists(images_dir)) # Check the storage repository repo_path = env.sd_manifest.getRepoPath() domain_link = os.path.join(repo_path, env.sd_manifest.sdUUID) self.assertTrue(os.path.islink(domain_link)) self.assertEqual(env.sd_manifest.domaindir, os.readlink(domain_link))
def test_domain_structure(self): with fake_block_env() as env: vg_name = env.sd_manifest.sdUUID md_path = env.lvm.lvPath(vg_name, sd.METADATA) self.assertTrue(os.path.exists(md_path)) version = env.sd_manifest.getVersion() for lv in env.sd_manifest.special_volumes(version): self.assertEqual(lv, env.lvm.getLV(vg_name, lv).name) images_dir = os.path.join(env.sd_manifest.domaindir, sd.DOMAIN_IMAGES) self.assertTrue(os.path.exists(images_dir)) # Check the storage repository repo_path = env.sd_manifest.getRepoPath() domain_link = os.path.join(repo_path, env.sd_manifest.sdUUID) self.assertTrue(os.path.islink(domain_link)) self.assertEqual(env.sd_manifest.domaindir, os.readlink(domain_link))
def test_volume_metadata_io(self): with fake_block_env() as env: sd_id = env.sd_manifest.sdUUID img_id = make_uuid() vol_id = make_uuid() size_mb = sc.VG_EXTENT_SIZE_MB size = size_mb * MB size_blk = size_mb * MB // sc.BLOCK_SIZE make_block_volume(env.lvm, env.sd_manifest, size, img_id, vol_id) self.assertEqual(vol_id, env.lvm.getLV(sd_id, vol_id).name) vol = env.sd_manifest.produceVolume(img_id, vol_id) self.assertEqual(size_blk, vol.getSize()) 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_metaslot_lock(self, sd_version): with fake_block_env(sd_version=sd_version) as env: with env.sd_manifest.acquireVolumeMetadataSlot(None): acquired = env.sd_manifest._lvTagMetaSlotLock.acquire(False) assert not acquired
def test_repopath_location(self): with fake_block_env() as env: self.assertTrue(env.sd_manifest.getRepoPath().startswith(TEMPDIR))
def fake_env(self): return fake_block_env()
def test_metaslot_lock(self, sd_version): with fake_block_env(sd_version=sd_version) as env: with env.sd_manifest.acquireVolumeMetadataSlot(None): acquired = env.sd_manifest._lvTagMetaSlotLock.acquire(False) assert not acquired
def test_metaslot_lock(self): with fake_block_env() as env: with env.sd_manifest.acquireVolumeMetadataSlot(None, 1): acquired = env.sd_manifest._lvTagMetaSlotLock.acquire(False) self.assertFalse(acquired)
def test_repopath_location(self): with fake_block_env() as env: self.assertTrue(env.sd_manifest.getRepoPath().startswith(TEMPDIR))
def test_repopath_location(): with fake_block_env() as env: assert env.sd_manifest.getRepoPath().startswith(TEMPDIR)