def make_blocksd_manifest(tmpdir, fake_lvm, sduuid=None, devices=None): 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 for metafile, sizemb in sd.SPECIAL_VOLUME_SIZES_MIB.iteritems(): fake_lvm.createLV(sduuid, metafile, sizemb) fake_lvm.createLV(sduuid, blockSD.MASTERLV, blockSD.MASTERLV_SIZE) # We'll store the domain metadata in the VG's tags metadata = make_sd_metadata(sduuid, 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) manifest.mountpoint = os.path.join(tmpdir, sd.DOMAIN_MNT_POINT, sd.BLOCKSD_DIR) manifest.domaindir = os.path.join(manifest.mountpoint, sduuid) 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): log = logging.getLogger('Storage.DomainMetadataToTags') 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._metadata = 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