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_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)
def test_getvallocsize(self, file_env): make_file_volume(file_env.sd_manifest, VOLSIZE, self.img_id, self.vol_id) vol = file_env.sd_manifest.produceVolume(self.img_id, self.vol_id) allocated = os.stat(vol.getVolumePath()).st_blocks * 512 assert allocated <= file_env.sd_manifest.getVAllocSize( self.img_id, self.vol_id)
def test_getallimages(self): with self.env() as env: assert 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) assert img_id in env.sd_manifest.getAllImages()
def test_getallimages(self): with self.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 test_getvallocsize(self): with self.env() as env: make_file_volume(env.sd_manifest, VOLSIZE, self.img_id, self.vol_id) # The first block is always allocated even for sparse image. assert 4096 == env.sd_manifest.getVAllocSize( self.img_id, self.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_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_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)
def test_purgeimage_race(self, file_env): sd_id = file_env.sd_manifest.sdUUID img_id = str(uuid.uuid4()) vol_id = str(uuid.uuid4()) make_file_volume(file_env.sd_manifest, VOLSIZE, img_id, vol_id) file_env.sd_manifest.deleteImage(sd_id, img_id, None) # Simulate StorageDomain.imageGarbageCollector by removing the # deleted image directory. deleted_dir = file_env.sd_manifest.getDeletedImagePath(img_id) file_env.sd_manifest.oop.fileUtils.cleanupdir(deleted_dir) # purgeImage should not raise if the image was already removed file_env.sd_manifest.purgeImage(sd_id, img_id, [vol_id], False)
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()
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_purgeimage_race(self): with self.env() as env: sd_id = env.sd_manifest.sdUUID img_id = str(uuid.uuid4()) vol_id = str(uuid.uuid4()) make_file_volume(env.sd_manifest, VOLSIZE, img_id, vol_id) env.sd_manifest.deleteImage(sd_id, img_id, None) # Simulate StorageDomain.imageGarbageCollector by removing the # deleted image directory. deleted_dir = env.sd_manifest.getDeletedImagePath(img_id) env.sd_manifest.oop.fileUtils.cleanupdir(deleted_dir) # purgeImage should not raise if the image was already removed env.sd_manifest.purgeImage(sd_id, img_id, [vol_id], False)
def test_getvallocsize(self): with self.env() as env: make_file_volume(env.sd_manifest, VOLSIZE, self.img_id, self.vol_id) assert 0 == env.sd_manifest.getVAllocSize( self.img_id, self.vol_id)
def test_getallimages(self, file_env): assert set() == file_env.sd_manifest.getAllImages() img_id = str(uuid.uuid4()) vol_id = str(uuid.uuid4()) make_file_volume(file_env.sd_manifest, VOLSIZE, img_id, vol_id) assert img_id in file_env.sd_manifest.getAllImages()
def test_getvsize(self): with self.env() as env: make_file_volume(env.sd_manifest, VOLSIZE, self.img_id, self.vol_id) assert VOLSIZE == env.sd_manifest.getVSize( self.img_id, self.vol_id)
def test_getvallocsize(self): with self.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_getvsize(self, file_env): make_file_volume(file_env.sd_manifest, VOLSIZE, self.img_id, self.vol_id) assert VOLSIZE == file_env.sd_manifest.getVSize( self.img_id, self.vol_id)