Use diskimage-builder checksum files

We recently added the ability for diskimage-builder to generate
checksum files. This means nodepool can validate DIBs and then pass
the contents to shade, saving shade from caclucating the checksums.

Change-Id: I4cd44bb83beb4839c2c2346af081638e61899d4d
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
This commit is contained in:
Paul Belanger 2016-11-29 16:46:38 -05:00
parent 46d92ff720
commit baf98e052b
3 changed files with 27 additions and 2 deletions

View File

@ -235,6 +235,7 @@ diskimages:
release: trusty
env-vars:
TMPDIR: $NODEPOOL_DIB_BASE_PATH/tmp
DIB_CHECKSUM: '1'
DIB_IMAGE_CACHE: $NODEPOOL_DIB_BASE_PATH/cache
DIB_APT_LOCAL_CACHE: '0'
DIB_DISABLE_APT_CLEANUP: '1'

View File

@ -51,6 +51,8 @@ class DibImageFile(object):
def __init__(self, image_id, extension=None):
self.image_id = image_id
self.extension = extension
self.md5 = None
self.sha256 = None
@staticmethod
def from_path(path):
@ -80,8 +82,25 @@ class DibImageFile(object):
'Cannot specify image extension of None'
)
my_path += '.' + self.extension
md5 = self._checksum(my_path, 'md5')
if md5:
self.md5 = md5[0:32]
sha256 = self._checksum(my_path, 'sha256')
if sha256:
self.sha256 = sha256[0:64]
return my_path
def _checksum(self, filename, hash_name):
checksum = '%s.%s' % (filename, hash_name)
if not os.path.isfile(checksum):
return None
with open(checksum, 'r') as f:
data = f.read()
return data
class BaseWorker(threading.Thread):
def __init__(self, config_path, interval):
@ -755,7 +774,9 @@ class UploadWorker(BaseWorker):
external_id = manager.uploadImage(
ext_image_name, filename,
image_type=image.extension,
meta=meta
meta=meta,
md5=image.md5,
sha256=image.sha256,
)
except Exception:
self.log.exception("Failed to upload image %s to provider %s" %

View File

@ -284,7 +284,8 @@ class ProviderManager(TaskManager):
with shade_inner_exceptions():
return self._client.get_image(image_id)
def uploadImage(self, image_name, filename, image_type=None, meta=None):
def uploadImage(self, image_name, filename, image_type=None, meta=None,
md5=None, sha256=None):
# configure glance and upload image. Note the meta flags
# are provided as custom glance properties
# NOTE: we have wait=True set here. This is not how we normally
@ -305,6 +306,8 @@ class ProviderManager(TaskManager):
filename=filename,
is_public=False,
wait=True,
md5=md5,
sha256=sha256,
**meta)
return image.id