def validate_image(self, image_id, checksum, size, delete=True):
"""Validate an image's checksum and size after upload.
Check for expected checksum and size.
Throw an IOError if they do not match.
:param image_id: str Glance Image ID
:param checksum: str Expected MD5 sum of the image
:param size: int Expected size in bytes of the image
:returns: None
"""
if not isinstance(size, util.INTEGER_TYPES):
raise TypeError("size '%s' is not an integer" % str(size))
found = self.gclient.images.get(image_id)
if found.size == size and found.checksum == checksum:
return
msg = ( ("Invalid glance image: %s. " % image_id) + ("Expected size=%s md5=%s. Found size=%s md5=%s." %
(size, checksum, found.size, found.checksum)))
if delete: LOG.warning("Deleting image %s: %s", image_id, msg) self.gclient.images.delete(image_id)
raise IOError(msg)
Glance itself is returning an MD5 hash so that would need to change before simplestreams: /docs.openstack .org/glance/ latest/ user/glanceapi. html
https:/
The code using the glance api is in the validate_image() function from simplestreams:
https:/ /git.launchpad. net/simplestrea ms/tree/ simplestreams/ mirrors/ glance. py#n515
def validate_ image(self, image_id, checksum, size, delete=True):
"""Validate an image's checksum and size after upload.
Check for expected checksum and size.
Throw an IOError if they do not match.
:param image_id: str Glance Image ID TYPES): images. get(image_ id)
(" Invalid glance image: %s. " % image_id) +
(" Expected size=%s md5=%s. Found size=%s md5=%s." %
LOG. warning( "Deleting image %s: %s", image_id, msg)
self. gclient. images. delete( image_id)
:param checksum: str Expected MD5 sum of the image
:param size: int Expected size in bytes of the image
:returns: None
"""
if not isinstance(size, util.INTEGER_
raise TypeError("size '%s' is not an integer" % str(size))
found = self.gclient.
if found.size == size and found.checksum == checksum:
return
msg = (
(size, checksum, found.size, found.checksum)))
if delete:
raise IOError(msg)