Don't verify image hashes if checksumming is disabled.
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 1442177d5d
)
This commit is contained in:
parent
803a05b7b3
commit
97542c9ead
|
@ -379,6 +379,29 @@ class ImageCacheManagerTestCase(test.TestCase):
|
|||
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'}
|
||||
|
||||
|
@ -653,6 +676,7 @@ class ImageCacheManagerTestCase(test.TestCase):
|
|||
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'
|
||||
|
|
|
@ -226,6 +226,9 @@ class ImageCacheManager(object):
|
|||
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')
|
||||
|
@ -251,7 +254,7 @@ class ImageCacheManager(object):
|
|||
# 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
|
||||
|
|
Loading…
Reference in New Issue