Skip to content

Commit

Permalink
Don't verify image hashes if checksumming is disabled.
Browse files Browse the repository at this point in the history
There was a bug where we were checking base image checksums, even
if checksumming was disabled, if there was already a cached checksum
for the image. This resolves bug 1075017.

DocImpact

Change-Id: I38f5914cd9d6326fdf5e5d7f0f57885ff8b5ff32
(cherry picked from commit 1442177)
  • Loading branch information
mikalstill authored and Chuck Short committed Nov 19, 2012
1 parent 803a05b commit 97542c9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
24 changes: 24 additions & 0 deletions nova/tests/test_imagecache.py
Expand Up @@ -379,6 +379,29 @@ def test_verify_checksum(self):
res = image_cache_manager._verify_checksum(img, fname)
self.assertTrue(res)

def test_verify_checksum_disabled(self):
img = {'container_format': 'ami', 'id': '42'}

self.flags(checksum_base_images=False)

with self._intercept_log_messages() as stream:
with utils.tempdir() as tmpdir:
self.flags(instances_path=tmpdir)
self.flags(image_info_filename_pattern=('$instances_path/'
'%(image)s.info'))
fname, info_fname, testdata = self._make_checksum(tmpdir)

# Checksum is valid
f = open(info_fname, 'w')
csum = hashlib.sha1()
csum.update(testdata)
f.write('{"sha1": "%s"}\n' % csum.hexdigest())
f.close()

image_cache_manager = imagecache.ImageCacheManager()
res = image_cache_manager._verify_checksum(img, fname)
self.assertTrue(res is None)

def test_verify_checksum_invalid_json(self):
img = {'container_format': 'ami', 'id': '42'}

Expand Down Expand Up @@ -653,6 +676,7 @@ def test_handle_base_image_used_missing(self):
self.assertEquals(image_cache_manager.corrupt_base_files, [])

def test_handle_base_image_checksum_fails(self):
self.flags(checksum_base_images=True)
self.stubs.Set(virtutils, 'chown', lambda x, y: None)

img = '123'
Expand Down
5 changes: 4 additions & 1 deletion nova/virt/libvirt/imagecache.py
Expand Up @@ -226,6 +226,9 @@ def _verify_checksum(self, img_id, base_file, create_if_missing=True):
handle manually when it occurs.
"""

if not FLAGS.checksum_base_images:
return None

stored_checksum = read_stored_checksum(base_file)
if stored_checksum:
f = open(base_file, 'r')
Expand All @@ -251,7 +254,7 @@ def _verify_checksum(self, img_id, base_file, create_if_missing=True):
# NOTE(mikal): If the checksum file is missing, then we should
# create one. We don't create checksums when we download images
# from glance because that would delay VM startup.
if FLAGS.checksum_base_images and create_if_missing:
if create_if_missing:
write_stored_checksum(base_file)

return None
Expand Down

0 comments on commit 97542c9

Please sign in to comment.