def make_file_volume(sd_manifest, size, imguuid, voluuid, parent_vol_id=sc.BLANK_UUID, vol_format=sc.RAW_FORMAT, vol_type=sc.LEAF_VOL, prealloc=sc.SPARSE_VOL, disk_type=image.UNKNOWN_DISK_TYPE, desc='fake volume'): volpath = os.path.join(sd_manifest.domaindir, "images", imguuid, voluuid) mdfiles = [volpath + '.meta', volpath + '.lease'] make_file(volpath, size) for mdfile in mdfiles: make_file(mdfile) size_blk = size // sc.BLOCK_SIZE vol_class = sd_manifest.getVolumeClass() vol_class.newMetadata( (volpath,), sd_manifest.sdUUID, imguuid, parent_vol_id, size_blk, sc.type2name(vol_format), sc.type2name(prealloc), sc.type2name(vol_type), disk_type, desc, sc.LEGAL_VOL)
def _create_lv_file(self, vgName, lvName, activate, size): # Create an LV as a regular file so we have a place to write data if activate: lv_path = self.lvPath(vgName, lvName) else: lv_path = self._lvPathInactive(vgName, lvName) make_file(lv_path, size)
def make_file_volume(sd_manifest, size, imguuid, voluuid, parent_vol_id=sc.BLANK_UUID, vol_format=sc.RAW_FORMAT, vol_type=sc.LEAF_VOL, prealloc=sc.SPARSE_VOL, disk_type=image.UNKNOWN_DISK_TYPE, desc='fake volume'): volpath = os.path.join(sd_manifest.domaindir, "images", imguuid, voluuid) mdfiles = [volpath + '.meta', volpath + '.lease'] make_file(volpath, size) for mdfile in mdfiles: make_file(mdfile) size_blk = size / sc.BLOCK_SIZE vol_class = sd_manifest.getVolumeClass() vol_class.newMetadata( (volpath,), sd_manifest.sdUUID, imguuid, parent_vol_id, size_blk, sc.type2name(vol_format), sc.type2name(prealloc), sc.type2name(vol_type), disk_type, desc, sc.LEGAL_VOL)
def make_blocksd_manifest(tmpdir, fake_lvm, sduuid=None, devices=None, metadata=None): if sduuid is None: sduuid = str(uuid.uuid4()) if devices is None: devices = get_random_devices() if metadata is None: metadata = make_sd_metadata(sduuid) fake_lvm.createVG(sduuid, devices, blockSD.STORAGE_DOMAIN_TAG, blockSD.VG_METADATASIZE) fake_lvm.createLV(sduuid, sd.METADATA, blockSD.SD_METADATA_SIZE) # Create the rest of the special LVs for metafile, sizemb in sd.SPECIAL_VOLUME_SIZES_MIB.iteritems(): fake_lvm.createLV(sduuid, metafile, sizemb) manifest = blockSD.BlockStorageDomainManifest(sduuid, metadata) manifest.domaindir = tmpdir os.makedirs(os.path.join(manifest.domaindir, sduuid, sd.DOMAIN_IMAGES)) metafile_path = fake_lvm.lvPath(sduuid, sd.METADATA) make_file(metafile_path, manifest.metaSize(sduuid)) return manifest
def createLV(self, vgName, lvName, size, activate=True, contiguous=False, initialTags=()): try: vg_md = self.vgmd[vgName] except KeyError: raise se.CannotCreateLogicalVolume(vgName, lvName) # Size is received as a string in MB. We need to convert it to bytes # and round it up to a multiple of the VG extent size. try: size = int(size) << 20 except ValueError: raise se.CannotCreateLogicalVolume(vgName, lvName) size = utils.round(size, int(vg_md['extent_size'])) # devices is hard to emulate properly (must have a PE allocator that # works the same as for LVM). Since we don't need this value, use None devices = None state = 'a' if activate else '-' lv_attr = dict(voltype='-', permission='w', allocations='i', fixedminor='-', state=state, devopen='-', target='-', zero='-') lv_md = dict(uuid=fake_lvm_uuid(), name=lvName, vg_name=vgName, attr=lv_attr, size=str(size), seg_start_pe='0', devices=devices, tags=initialTags, writeable=True, opened=False, active=bool(activate)) lv_count = int(vg_md['lv_count']) + 1 if (vgName, lvName) in self.lvmd: raise se.CannotCreateLogicalVolume(vgName, lvName) self.lvmd[(vgName, lvName)] = lv_md self.vgmd[vgName]['lv_count'] = str(lv_count) # Create an LV as a regular file so we have a place to write data if activate: lv_path = self.lvPath(vgName, lvName) else: lv_path = self._lvPathInactive(vgName, lvName) make_file(lv_path, size)
def test_getreaddelay(self): with namedTemporaryDir() as tmpdir: lvm = FakeLVM(tmpdir) with MonkeyPatchScope([(blockSD, 'lvm', lvm)]): manifest = make_blocksd(tmpdir, lvm) vg_name = manifest.sdUUID make_file(lvm.lvPath(vg_name, 'metadata')) self.assertIsInstance(manifest.getReadDelay(), float)
def make_file_volume(domaindir, size, imguuid=None, voluuid=None): imguuid = imguuid or str(uuid.uuid4()) voluuid = voluuid or str(uuid.uuid4()) volpath = os.path.join(domaindir, "images", imguuid, voluuid) mdfiles = [volpath + '.meta', volpath + '.lease'] make_file(volpath, size) for mdfile in mdfiles: make_file(mdfile) return imguuid, voluuid
def make_filesd_manifest(tmpdir, metadata=None): sduuid = str(uuid.uuid4()) domain_path = os.path.join(tmpdir, sduuid) make_file(get_metafile_path(domain_path)) if metadata is None: metadata = FakeMetadata() manifest = fileSD.FileStorageDomainManifest(domain_path, metadata) os.makedirs(os.path.join(manifest.domaindir, sduuid, sd.DOMAIN_IMAGES)) return manifest
def make_file_volume(sd_manifest, size, imguuid, voluuid, parent_vol_id=sc.BLANK_UUID, vol_format=sc.RAW_FORMAT, vol_type=sc.LEAF_VOL, prealloc=sc.SPARSE_VOL, disk_type=sc.DATA_DISKTYPE, desc='fake volume', qcow2_compat='0.10', legal=True): volpath = os.path.join(sd_manifest.domaindir, "images", imguuid, voluuid) # Create needed path components. make_file(volpath, size) # Create the image. if vol_format == sc.COW_FORMAT: backing = parent_vol_id if parent_vol_id != sc.BLANK_UUID else None if backing: backing_path = os.path.join(sd_manifest.domaindir, "images", imguuid, backing) backing_format = qemuimg.info(backing_path)["format"] else: backing_format = None op = qemuimg.create(volpath, size=size, format=qemuimg.FORMAT.QCOW2, qcow2Compat=qcow2_compat, backing=backing, backingFormat=backing_format) op.run() else: # TODO: Use fallocate helper like the real code. if prealloc == sc.PREALLOCATED_VOL: preallocation = qemuimg.PREALLOCATION.FALLOC else: preallocation = None op = qemuimg.create(volpath, size=size, format=qemuimg.FORMAT.RAW, preallocation=preallocation) op.run() # Create meta files. mdfiles = [volpath + '.meta', volpath + '.lease'] for mdfile in mdfiles: make_file(mdfile) vol_class = sd_manifest.getVolumeClass() vol_class.newMetadata((volpath, ), sd_manifest.sdUUID, imguuid, parent_vol_id, size, sc.type2name(vol_format), sc.type2name(prealloc), sc.type2name(vol_type), disk_type, desc, sc.LEGAL_VOL if legal else sc.ILLEGAL_VOL)
def make_env(self): with namedTemporaryDir() as tmpdir: """ Below we imitate that behaviour by providing two different directories under /rhv/data-center root and one of those directories is a symlink to another one. We fill VolumeChain with real directory and use symlinked directory in XML, emulating libvirt reply. """ dc_base = os.path.join(tmpdir, "dc") run_base = os.path.join(tmpdir, "run") images_path = os.path.join(dc_base, "images") os.makedirs(images_path) os.symlink(dc_base, run_base) dc_top_vol = os.path.join( images_path, "11111111-1111-1111-1111-111111111111") dc_base_vol = os.path.join( images_path, "22222222-2222-2222-2222-222222222222") make_file(dc_top_vol) make_file(dc_base_vol) run_top_vol = os.path.join( run_base, "images", "11111111-1111-1111-1111-111111111111") run_base_vol = os.path.join( run_base, "images", "22222222-2222-2222-2222-222222222222") volume_chain = [ {'path': dc_top_vol, 'volumeID': '11111111-1111-1111-1111-111111111111'}, {'path': dc_base_vol, 'volumeID': '22222222-2222-2222-2222-222222222222'} ] conf = drive_config(volumeChain=volume_chain) drive = Drive(self.log, **conf) drive._blockDev = True yield VolumeChainEnv( drive, run_top_vol, run_base_vol )
def make_filesd_manifest(tmpdir): spuuid = make_uuid() sduuid = make_uuid() domain_path = os.path.join(tmpdir, spuuid, sduuid) metafile = get_metafile_path(domain_path) make_file(metafile) metadata = fileSD.FileSDMetadata(metafile) metadata.update(make_sd_metadata(sduuid, pools=[spuuid])) manifest = fileSD.FileStorageDomainManifest(domain_path, metadata) os.makedirs(os.path.join(manifest.domaindir, sd.DOMAIN_IMAGES)) return manifest
def make_filesd_manifest(tmpdir): spuuid = str(uuid.uuid4()) sduuid = str(uuid.uuid4()) domain_path = os.path.join(tmpdir, spuuid, sduuid) metafile = get_metafile_path(domain_path) make_file(metafile) metadata = fileSD.FileSDMetadata(metafile) metadata.update(make_sd_metadata(sduuid, pools=[spuuid])) manifest = fileSD.FileStorageDomainManifest(domain_path, metadata) os.makedirs(os.path.join(manifest.domaindir, sd.DOMAIN_IMAGES)) return manifest
def make_env(self, disk_type): with namedTemporaryDir() as tmpdir: """ Below we imitate that behaviour by providing two different directories under /rhv/data-center root and one of those directories is a symlink to another one. We fill VolumeChain with real directory and use symlinked directory in XML, emulating libvirt reply. """ dc_base = os.path.join(tmpdir, "dc") run_base = os.path.join(tmpdir, "run") images_path = os.path.join(dc_base, "images") os.makedirs(images_path) os.symlink(dc_base, run_base) dc_top_vol = os.path.join( images_path, "11111111-1111-1111-1111-111111111111") dc_base_vol = os.path.join( images_path, "22222222-2222-2222-2222-222222222222") make_file(dc_top_vol) make_file(dc_base_vol) run_top_vol = os.path.join( run_base, "images", "11111111-1111-1111-1111-111111111111") run_base_vol = os.path.join( run_base, "images", "22222222-2222-2222-2222-222222222222") volume_chain = [ {'path': dc_top_vol, 'volumeID': '11111111-1111-1111-1111-111111111111'}, {'path': dc_base_vol, 'volumeID': '22222222-2222-2222-2222-222222222222'} ] conf = drive_config(volumeChain=volume_chain) drive = Drive(self.log, diskType=disk_type, **conf) yield VolumeChainEnv( drive, run_top_vol, run_base_vol )
def make_filesd_manifest(mnt_dir, sd_version=3): spuuid = make_uuid() sduuid = make_uuid() domain_path = os.path.join(mnt_dir, sduuid) metafile = get_metafile_path(domain_path) make_file(metafile) metadata = fileSD.FileSDMetadata(metafile) metadata.update(make_sd_metadata(sduuid, version=sd_version, pools=[spuuid])) manifest = fileSD.FileStorageDomainManifest(domain_path, metadata) os.makedirs(os.path.join(manifest.domaindir, sd.DOMAIN_IMAGES)) return manifest
def make_file_volume(sd_manifest, size, imguuid, voluuid, parent_vol_id=sc.BLANK_UUID, vol_format=sc.RAW_FORMAT, vol_type=sc.LEAF_VOL, prealloc=sc.SPARSE_VOL, disk_type=image.UNKNOWN_DISK_TYPE, desc='fake volume', qcow2_compat='0.10'): volpath = os.path.join(sd_manifest.domaindir, "images", imguuid, voluuid) # Create needed path components. make_file(volpath, size) # Create qcow2 file if needed. if vol_format == sc.COW_FORMAT: backing = parent_vol_id if parent_vol_id != sc.BLANK_UUID else None op = qemuimg.create( volpath, size=size, format=qemuimg.FORMAT.QCOW2, qcow2Compat=qcow2_compat, backing=backing) op.run() # Create meta files. mdfiles = [volpath + '.meta', volpath + '.lease'] for mdfile in mdfiles: make_file(mdfile) size_blk = size // sc.BLOCK_SIZE vol_class = sd_manifest.getVolumeClass() vol_class.newMetadata( (volpath,), sd_manifest.sdUUID, imguuid, parent_vol_id, size_blk, sc.type2name(vol_format), sc.type2name(prealloc), sc.type2name(vol_type), disk_type, desc, sc.LEGAL_VOL)
def make_file_volume(sd_manifest, size, imguuid, voluuid, parent_vol_id=sc.BLANK_UUID, vol_format=sc.RAW_FORMAT, vol_type=sc.LEAF_VOL, prealloc=sc.SPARSE_VOL, disk_type=sc.DATA_DISKTYPE, desc='fake volume', qcow2_compat='0.10'): volpath = os.path.join(sd_manifest.domaindir, "images", imguuid, voluuid) # Create needed path components. make_file(volpath, size) # Create qcow2 file if needed. if vol_format == sc.COW_FORMAT: backing = parent_vol_id if parent_vol_id != sc.BLANK_UUID else None op = qemuimg.create( volpath, size=size, format=qemuimg.FORMAT.QCOW2, qcow2Compat=qcow2_compat, backing=backing) op.run() # Create meta files. mdfiles = [volpath + '.meta', volpath + '.lease'] for mdfile in mdfiles: make_file(mdfile) size_blk = size // sc.BLOCK_SIZE vol_class = sd_manifest.getVolumeClass() vol_class.newMetadata( (volpath,), sd_manifest.sdUUID, imguuid, parent_vol_id, size_blk, sc.type2name(vol_format), sc.type2name(prealloc), sc.type2name(vol_type), disk_type, desc, sc.LEGAL_VOL)
def test_getreaddelay(self): with fake_block_env() as env: vg_name = env.sd_manifest.sdUUID make_file(env.lvm.lvPath(vg_name, 'metadata')) self.assertIsInstance(env.sd_manifest.getReadDelay(), float)
def _create_lv_file(self, vgName, lvName, active, size): # Create an LV as a regular file so we have a place to write data lv_path = self._fake_lv_path(vgName, lvName, active) make_file(lv_path, size)