def test_glance_rename_and_back(self): old = '_rename_test' self.common_start() self.assertFalse(glance.glance_exists(self._IMG_NAME + old)) self.assertTrue(glance.glance_rename(self._IMG_NAME, self._IMG_NAME + old)) self.assertFalse(glance.glance_exists(self._IMG_NAME)) self.assertTrue(glance.glance_exists(self._IMG_NAME + old)) self.assertTrue(glance.glance_rename(self._IMG_NAME + old, self._IMG_NAME)) self.assertFalse(glance.glance_exists(self._IMG_NAME + old)) self.assertTrue(glance.glance_exists(self._IMG_NAME))
def test_glance_rename_and_back(self): old = '_rename_test' self.common_start() self.assertFalse(glance.glance_exists(self._IMG_NAME + old)) self.assertTrue( glance.glance_rename(self._IMG_NAME, self._IMG_NAME + old)) self.assertFalse(glance.glance_exists(self._IMG_NAME)) self.assertTrue(glance.glance_exists(self._IMG_NAME + old)) self.assertTrue( glance.glance_rename(self._IMG_NAME + old, self._IMG_NAME)) self.assertFalse(glance.glance_exists(self._IMG_NAME + old)) self.assertTrue(glance.glance_exists(self._IMG_NAME))
def needs_upgrade(mpid, old, new, meta_file): '''Handle an image already put in glance in a previous run ''' old_md5 = old['checksum'] old_name = old['name'] old_ver = old['version'] new_md5 = new['checksums']['md5'] new_name = new['title'] new_ver = new['version'] if new_md5 == old_md5: vprint("Same image: same md5, no upload") update_properties(mpid, old, new) else: vprint("md5 differ") if new_ver > old_ver: vprint("New image version") if not glance.glance_rename(old_name, old_name + '_old'): vprint('Warning: Cannot rename old image, will need manual ' 'intervention') vprint("Previous image renamed to: " + old_name + '_old') upload_image(mpid, new_name, meta_file) update_properties(mpid, old, new) elif new_ver < old_ver: vprint("NO-OP: downgraded image") else: vprint("NO-OP: corrupted image (same version, md5 differ)")
def needs_upgrade(mpid, old, new, meta_file): '''Handle an image already put in glance in a previous run ''' old_md5 = old['checksum'] old_name = old['name'] old_ver = old['version'] new_md5 = new['checksums']['md5'] new_name = new['title'] new_ver = new['version'] if new_md5 == old_md5: vprint("Same image: same md5, no upload") update_properties(mpid, old, new) else: vprint("md5 differ") if new_ver > old_ver: vprint("New image version") if not glance.glance_rename(old_name, old_name + '_old'): vprint('Warning: Cannot rename old image, will need manual ' 'intervention') vprint("Previous image renamed to: " + old_name + '_old') upload_image(mpid, new_name, meta_file) update_properties(mpid, old, new) elif new_ver < old_ver: vprint("NO-OP: downgraded image") else: vprint("NO-OP: corrupted image (same version, md5 differ)")
def test_glance_rename_multi(self): # Rename multiple images with same name... self.common_start() self.assertTrue(glance.glance_exists(self._IMG_NAME)) IMG_ID = glance.glance_import_id(os.devnull, name=self._IMG_NAME, diskformat='raw') self.assertTrue(IMG_ID) self.assertTrue(glance.glance_exists(IMG_ID)) self.assertTrue(glance.glance_exists(self._IMG_NAME)) self.assertTrue(len(glance.glance_ids(self._IMG_NAME)) == 2) self.assertTrue(glance.glance_rename(self._IMG_NAME, self._IMG_NAME + '_rename_multi')) # One has been renamed, the other stayed as-is... self.assertTrue(glance.glance_exists(self._IMG_NAME + '_rename_multi')) self.assertTrue(glance.glance_exists(self._IMG_NAME)) self.assertTrue(glance.glance_exists(self._IMG_ID)) self.assertTrue(glance.glance_exists(IMG_ID)) # Get it back to its previous name, so that it is cleaned up self.assertTrue(glance.glance_rename(self._IMG_NAME + '_rename_multi', self._IMG_NAME))
def test_glance_rename_inexistent(self): old = '_rename_test' self.common_start() self.assertFalse(glance.glance_exists(self._IMG_NAME + old)) self.assertFalse(glance.glance_exists(self._IMG_NAME + 'inexistent')) self.assertFalse(glance.glance_rename(self._IMG_NAME + 'inexistent', self._IMG_NAME + old)) self.assertTrue(glance.glance_exists(self._IMG_NAME)) self.assertFalse(glance.glance_exists(self._IMG_NAME + old)) self.assertFalse(glance.glance_exists(self._IMG_NAME + 'inexistent'))
def test_glance_rename_inexistent(self): old = '_rename_test' self.common_start() self.assertFalse(glance.glance_exists(self._IMG_NAME + old)) self.assertFalse(glance.glance_exists(self._IMG_NAME + 'inexistent')) self.assertFalse( glance.glance_rename(self._IMG_NAME + 'inexistent', self._IMG_NAME + old)) self.assertTrue(glance.glance_exists(self._IMG_NAME)) self.assertFalse(glance.glance_exists(self._IMG_NAME + old)) self.assertFalse(glance.glance_exists(self._IMG_NAME + 'inexistent'))
def test_glance_rename_multi(self): # Rename multiple images with same name... self.common_start() self.assertTrue(glance.glance_exists(self._IMG_NAME)) IMG_ID = glance.glance_import_id(os.devnull, name=self._IMG_NAME, diskformat='raw') self.assertTrue(IMG_ID) self.assertTrue(glance.glance_exists(IMG_ID)) self.assertTrue(glance.glance_exists(self._IMG_NAME)) self.assertTrue(len(glance.glance_ids(self._IMG_NAME)) == 2) self.assertTrue( glance.glance_rename(self._IMG_NAME, self._IMG_NAME + '_rename_multi')) # One has been renamed, the other stayed as-is... self.assertTrue(glance.glance_exists(self._IMG_NAME + '_rename_multi')) self.assertTrue(glance.glance_exists(self._IMG_NAME)) self.assertTrue(glance.glance_exists(self._IMG_ID)) self.assertTrue(glance.glance_exists(IMG_ID)) # Get it back to its previous name, so that it is cleaned up self.assertTrue( glance.glance_rename(self._IMG_NAME + '_rename_multi', self._IMG_NAME))
def handle_vm(mpid, url): '''Handle one image given by its SL marketplace ID ''' vprint('Handle image with marketplace ID : %s' % mpid) meta_file = get_meta_file(mpid, url) if meta_file is None: return # TODO: delete meta_file to avoid filling /tmp new = metadata.MetaStratusLabXml(meta_file).get_metadata() vmmap = get_glance_images() if mpid in vmmap: vprint("Image is already in glance") needs_upgrade(mpid, vmmap[mpid], new, meta_file) # TODO: check other image properties, they should match perfectly else: vprint("No image with the same marketplace ID found in glance") new_md5 = new['checksums']['md5'] new_name = new['title'] new_ver = new['version'] if new_md5 in vmmap: vprint('An image with the same MD5 is already in glance') old = vmmap[new_md5] old_md5 = old['checksum'] old_name = old['name'] old_ver = old.get('version', None) diff = False # Check name if old_name != new_name: vprint("Names differ, old: %s, new: %s" % (old_name, new_name)) diff = True # Check Version if old_ver != new_ver: vprint("Versions differ, old: %s, new: %s" % (old_ver, new_ver)) diff = True # Which one is the good one ? Let the admin sort it out... if diff: diff_msg = "differ, but we don't know which is the good one" else: diff_msg = "look like the same images" vprint("They %s, ignoring..." % diff_msg) return elif new_name in vmmap: old = vmmap[new_name] old_md5 = old['checksum'] old_name = old['name'] old_ver = old['version'] vprint('An image with the same name is already in glance: ' + old_name) diff = False err_msg = "But %s differ, old: %s, new: %s" # Check MD5 if old_md5 != new_md5: vprint(err_msg % ("checksums", old_md5, new_md5)) diff = True # Check Version assert isinstance(old_ver, int) assert isinstance(new_ver, int) if old_ver != new_ver: vprint(err_msg % ("versions", old_ver, new_ver)) diff = True if old_ver > new_ver: vprint("Versions are going backwards, that's not good.") vprint("Ignoring, fix the image on the market place.") return # This should not happen, as it should already have been caught by # earlier MD5 checking... if not diff: vprint( "Identical images, that should not happen, please report" " as a bug.") return if 'mpid' in old: vprint("Previous image has 'mpid' property set, " "keeping it as-is...") # Backup old image by renaming if not glance.glance_rename(old_name, old_name + '_old'): vprint('Cannot rename old image, aborting update...') return vprint("Previous image renamed to: " + old_name + '_old') ret = upload_image(mpid, new_name, meta_file) if ret: ret = set_properties(mpid, new) return ret
def handle_vm(mpid, url): '''Handle one image given by its SL marketplace ID ''' vprint('Handle image with marketplace ID : %s' % mpid) meta_file = get_meta_file(mpid, url) if meta_file is None: return # TODO: delete meta_file to avoid filling /tmp new = metadata.MetaStratusLabXml(meta_file).get_metadata() vmmap = get_glance_images() if mpid in vmmap: vprint("Image is already in glance") needs_upgrade(mpid, vmmap[mpid], new, meta_file) # TODO: check other image properties, they should match perfectly else: vprint("No image with the same marketplace ID found in glance") new_md5 = new['checksums']['md5'] new_name = new['title'] new_ver = new['version'] if new_md5 in vmmap: vprint('An image with the same MD5 is already in glance') old = vmmap[new_md5] old_md5 = old['checksum'] old_name = old['name'] old_ver = old.get('version', None) diff = False # Check name if old_name != new_name: vprint("Names differ, old: %s, new: %s" % (old_name, new_name)) diff = True # Check Version if old_ver != new_ver: vprint("Versions differ, old: %s, new: %s" % (old_ver, new_ver)) diff = True # Which one is the good one ? Let the admin sort it out... if diff: diff_msg = "differ, but we don't know which is the good one" else: diff_msg = "look like the same images" vprint("They %s, ignoring..." % diff_msg) return elif new_name in vmmap: old = vmmap[new_name] old_md5 = old['checksum'] old_name = old['name'] old_ver = old['version'] vprint('An image with the same name is already in glance: ' + old_name) diff = False err_msg = "But %s differ, old: %s, new: %s" # Check MD5 if old_md5 != new_md5: vprint(err_msg % ("checksums", old_md5, new_md5)) diff = True # Check Version assert isinstance(old_ver, int) assert isinstance(new_ver, int) if old_ver != new_ver: vprint(err_msg % ("versions", old_ver, new_ver)) diff = True if old_ver > new_ver: vprint("Versions are going backwards, that's not good.") vprint("Ignoring, fix the image on the market place.") return # This should not happen, as it should already have been caught by # earlier MD5 checking... if not diff: vprint("Identical images, that should not happen, please report" " as a bug.") return if 'mpid' in old: vprint("Previous image has 'mpid' property set, " "keeping it as-is...") # Backup old image by renaming if not glance.glance_rename(old_name, old_name + '_old'): vprint('Cannot rename old image, aborting update...') return vprint("Previous image renamed to: " + old_name + '_old') ret = upload_image(mpid, new_name, meta_file) if ret: ret = set_properties(mpid, new) return ret
def test_glance_rename_to_same_name(self): self.common_start() # This should be a NO-OP... self.assertTrue(glance.glance_rename(self._IMG_NAME, self._IMG_NAME)) self.assertTrue(glance.glance_exists(self._IMG_NAME))
def test_glance_rename_to_same_name(self): self.common_start() # This should be a NO-OP... self.assertTrue(glance.glance_rename(self._IMG_NAME, self._IMG_NAME)) self.assertTrue(glance.glance_exists(self._IMG_NAME))