def test_verify_checksum_invalid_json(self): img = {'container_format': 'ami', 'id': '42'} self.flags(checksum_base_images=True) 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 invalid, and not json f = open(info_fname, 'w') f.write('banana') f.close() image_cache_manager = imagecache.ImageCacheManager() res = image_cache_manager._verify_checksum( img, fname, create_if_missing=False) self.assertFalse(res) log = stream.getvalue() # NOTE(mikal): this is a skip not a fail because the file is # present, but is not in valid json format and therefore is # skipped. self.assertNotEqual(log.find('image verification skipped'), -1)
def test_verify_checksum_invalid(self): img = {'container_format': 'ami', 'id': '42'} self.flags(checksum_base_images=True) 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 invalid, but is in valid json f = open(info_fname, 'w') f.write('{"sha1": "banana"}') f.close() image_cache_manager = imagecache.ImageCacheManager() res = image_cache_manager._verify_checksum(img, fname) self.assertFalse(res) log = stream.getvalue() self.assertNotEqual(log.find('image verification failed'), -1)