Merge "Add small image verifier for swift backend"

This commit is contained in:
Jenkins 2016-02-19 13:18:07 +00:00 committed by Gerrit Code Review
commit 48927adfdd
2 changed files with 50 additions and 3 deletions

View File

@ -512,9 +512,18 @@ class BaseStore(driver.Store):
if image_size > 0 and image_size < self.large_object_size:
# Image size is known, and is less than large_object_size.
# Send to Swift with regular PUT.
obj_etag = connection.put_object(location.container,
location.obj, image_file,
content_length=image_size)
if verifier:
checksum = hashlib.md5()
reader = ChunkReader(image_file, checksum,
image_size, verifier)
obj_etag = connection.put_object(location.container,
location.obj,
reader,
content_length=image_size)
else:
obj_etag = connection.put_object(location.container,
location.obj, image_file,
content_length=image_size)
else:
# Write the image into Swift in chunks.
chunk_id = 1

View File

@ -652,6 +652,44 @@ class SwiftTests(object):
mock.call(b'')]
verifier.update.assert_has_calls(calls)
@mock.patch('glance_store._drivers.swift.utils'
'.is_multiple_swift_store_accounts_enabled',
mock.Mock(return_value=True))
def test_add_with_verifier_small(self):
"""Test that the verifier is updated for smaller images."""
swift_size = FIVE_KB
base_byte = b"12345678"
swift_contents = base_byte * (swift_size // 8)
image_id = str(uuid.uuid4())
image_swift = six.BytesIO(swift_contents)
self.store = Store(self.conf)
self.store.configure()
orig_max_size = self.store.large_object_size
orig_temp_size = self.store.large_object_chunk_size
custom_size = 6 * units.Ki
verifier = mock.MagicMock(name='mock_verifier')
try:
self.store.large_object_size = custom_size
self.store.large_object_chunk_size = custom_size
self.store.add(image_id, image_swift, swift_size,
verifier=verifier)
finally:
self.store.large_object_chunk_size = orig_temp_size
self.store.large_object_size = orig_max_size
# Confirm verifier update called expected number of times
self.assertEqual(verifier.update.call_count, 2)
# define one chunk of the contents
swift_contents_piece = base_byte * (swift_size // 8)
# confirm all expected calls to update have occurred
calls = [mock.call(swift_contents_piece),
mock.call(b'')]
verifier.update.assert_has_calls(calls)
@mock.patch('glance_store._drivers.swift.utils'
'.is_multiple_swift_store_accounts_enabled',
mock.Mock(return_value=False))