def make_blocksd_manifest(tmpdir, fake_lvm, sduuid=None, devices=None, sd_version=3): if sduuid is None: sduuid = make_uuid() if devices is None: devices = get_random_devices() spuuid = make_uuid() 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 special = blockSD.BlockStorageDomainManifest.special_volumes(sd_version) for name, size_mb in sd.SPECIAL_VOLUME_SIZES_MIB.iteritems(): if name in special: fake_lvm.createLV(sduuid, name, size_mb) fake_lvm.createLV(sduuid, blockSD.MASTERLV, blockSD.MASTER_LV_SIZE_MB) # We'll store the domain metadata in the VG's tags metadata = make_sd_metadata(sduuid, version=sd_version, pools=[spuuid]) assert(metadata[sd.DMDK_VERSION] >= 3) # Tag based MD is V3 and above tag_md = blockSD.TagBasedSDMetadata(sduuid) tag_md.update(metadata) manifest = blockSD.BlockStorageDomainManifest(sduuid, tag_md) os.makedirs(os.path.join(manifest.domaindir, sd.DOMAIN_IMAGES)) # Make the repo directory structure repo_pool_dir = os.path.join(tmpdir, spuuid) os.mkdir(repo_pool_dir) os.symlink(manifest.domaindir, os.path.join(repo_pool_dir, sduuid)) return manifest
def __convertDomainMetadataToTags(domain, targetVersion): newMetadata = blockSD.TagBasedSDMetadata(domain.sdUUID) oldMetadata = domain._metadata # We use _dict to bypass the validators in order to copy all metadata metadata = oldMetadata._dict.copy() metadata[sd.DMDK_VERSION] = str(targetVersion) # Must be a string log.debug("Converting domain %s to tag based metadata", domain.sdUUID) newMetadata._dict.update(metadata) try: # If we can't clear the old metadata we don't have any clue on what # actually happened. We prepare the convertError exception to raise # later on if we discover that the upgrade didn't take place. oldMetadata._dict.clear() except Exception as convertError: log.error("Could not clear the old metadata", exc_info=True) else: # We don't have any valuable information to add here convertError = RuntimeError("Unknown metadata conversion error") # If this fails, there's nothing we can do, let's bubble the exception chkMetadata = blockSD.selectMetadata(domain.sdUUID) if chkMetadata[sd.DMDK_VERSION] == int(targetVersion): # Switching to the newMetadata (successful upgrade), the oldMetadata # was cleared after all. domain.replaceMetadata(chkMetadata) log.debug( "Conversion of domain %s to tag based metadata completed, " "target version = %s", domain.sdUUID, targetVersion) else: # The upgrade failed, cleaning up the new metadata log.error( "Could not convert domain %s to tag based metadata, " "target version = %s", domain.sdUUID, targetVersion) newMetadata._dict.clear() # Raising the oldMetadata_dict.clear() exception or the default one raise convertError