Only generate checksums if neither is given

A single checksum is sufficient for unique checking if given by the
user. If the user gives no checksums, then we might as well do both
since we're doing it in one pass.

Change-Id: Ic589d5771b6f54e6f03d4612b8e7c5a4be6bbc36
This commit is contained in:
Monty Taylor 2016-11-10 11:08:36 -06:00
parent 37027c290d
commit f5c37ffcd4
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
2 changed files with 27 additions and 14 deletions

View File

@ -0,0 +1,5 @@
---
upgrade:
- shade will now only generate file hashes for glance
images if both hashes are empty. If only one is given,
the other will be treated as an empty string.

View File

@ -3006,19 +3006,27 @@ class OpenStackCloud(_normalize.Normalizer):
container_format = 'ovf' container_format = 'ovf'
else: else:
container_format = 'bare' container_format = 'bare'
if not md5 or not sha256: if not (md5 or sha256):
(md5, sha256) = self._get_file_hashes(filename) (md5, sha256) = self._get_file_hashes(filename)
if allow_duplicates: if allow_duplicates:
current_image = None current_image = None
else: else:
current_image = self.get_image(name) current_image = self.get_image(name)
if (current_image and current_image.get(IMAGE_MD5_KEY, '') == md5 if current_image:
and current_image.get(IMAGE_SHA256_KEY, '') == sha256): md5_key = current_image.get(IMAGE_MD5_KEY, '')
self.log.debug( sha256_key = current_image.get(IMAGE_SHA256_KEY, '')
"image %(name)s exists and is up to date", {'name': name}) up_to_date = False
return current_image if md5 and md5_key == md5:
kwargs[IMAGE_MD5_KEY] = md5 up_to_date = True
kwargs[IMAGE_SHA256_KEY] = sha256 if sha256 and sha256_key == sha256:
up_to_date = True
if up_to_date:
self.log.debug(
"image %(name)s exists and is up to date",
{'name': name})
return current_image
kwargs[IMAGE_MD5_KEY] = md5 or ''
kwargs[IMAGE_SHA256_KEY] = sha256 or ''
kwargs[IMAGE_OBJECT_KEY] = '/'.join([container, name]) kwargs[IMAGE_OBJECT_KEY] = '/'.join([container, name])
if disable_vendor_agent: if disable_vendor_agent:
@ -5391,15 +5399,15 @@ class OpenStackCloud(_normalize.Normalizer):
container=container, name=name)) container=container, name=name))
return True return True
if file_md5 is None or file_sha256 is None: if not (file_md5 or file_sha256):
(file_md5, file_sha256) = self._get_file_hashes(filename) (file_md5, file_sha256) = self._get_file_hashes(filename)
if metadata.get(OBJECT_MD5_KEY, '') != file_md5: if file_md5 and metadata.get(OBJECT_MD5_KEY, '') != file_md5:
self.log.debug( self.log.debug(
"swift md5 mismatch: %(filename)s!=%(container)s/%(name)s", "swift md5 mismatch: %(filename)s!=%(container)s/%(name)s",
{'filename': filename, 'container': container, 'name': name}) {'filename': filename, 'container': container, 'name': name})
return True return True
if metadata.get(OBJECT_SHA256_KEY, '') != file_sha256: if file_sha256 and metadata.get(OBJECT_SHA256_KEY, '') != file_sha256:
self.log.debug( self.log.debug(
"swift sha256 mismatch: %(filename)s!=%(container)s/%(name)s", "swift sha256 mismatch: %(filename)s!=%(container)s/%(name)s",
{'filename': filename, 'container': container, 'name': name}) {'filename': filename, 'container': container, 'name': name})
@ -5449,10 +5457,10 @@ class OpenStackCloud(_normalize.Normalizer):
segment_size = self.get_object_segment_size(segment_size) segment_size = self.get_object_segment_size(segment_size)
if not md5 or not sha256: if not (md5 or sha256):
(md5, sha256) = self._get_file_hashes(filename) (md5, sha256) = self._get_file_hashes(filename)
headers[OBJECT_MD5_KEY] = md5 headers[OBJECT_MD5_KEY] = md5 or ''
headers[OBJECT_SHA256_KEY] = sha256 headers[OBJECT_SHA256_KEY] = sha256 or ''
header_list = sorted([':'.join([k, v]) for (k, v) in headers.items()]) header_list = sorted([':'.join([k, v]) for (k, v) in headers.items()])
for (k, v) in metadata.items(): for (k, v) in metadata.items():
header_list.append(':'.join(['x-object-meta-' + k, v])) header_list.append(':'.join(['x-object-meta-' + k, v]))