Fixed an HTTP 500 on artifact blob upload
If the HTTP PUT request to upload a binary file to an artifact does not contain a Content-size header, the length of the binary file should be detected during the upload. However, the unset content size variable was leading to an exception as its value (None) participates in some math operations during the upload. Setting the value to 0 (same is v2 API) fixes the issue. Closes-Bug: #1488037 FastTrack Change-Id: Iadbd97899445b58c2c5bad961bca61cd6ab60d1a
This commit is contained in:
parent
d5a8c91d2f
commit
b0bc1103ab
|
@ -136,6 +136,8 @@ class ArtifactBlobProxy(proxy.ArtifactBlob):
|
|||
LOG.error(msg)
|
||||
|
||||
def upload_to_store(self, data, size):
|
||||
if size is None: # NOTE(ativelkov): None is "unknown size"
|
||||
size = 0
|
||||
location, ret_size, checksum, loc_meta = self.store_api.add_to_backend(
|
||||
CONF,
|
||||
self.blob.item_key,
|
||||
|
|
|
@ -969,6 +969,29 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||
'/withblob/%s/blob1/download' % art['id'])
|
||||
self.assertEqual('ZZZZZ', data)
|
||||
|
||||
def test_file_w_unknown_size(self):
|
||||
# Upload and download data provided by an iterator, thus without
|
||||
# knowing the length in advance
|
||||
art = self._create_artifact('withblob')
|
||||
artifact_id = art['id']
|
||||
|
||||
def iterate_string(val):
|
||||
for char in val:
|
||||
yield char
|
||||
|
||||
headers = self._headers({'Content-Type': 'application/octet-stream'})
|
||||
self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'],
|
||||
headers=headers,
|
||||
data=iterate_string('ZZZZZ'), status=200)
|
||||
|
||||
art = self._check_artifact_get('/withblob/%s' % artifact_id)
|
||||
self.assertEqual(artifact_id, art['id'])
|
||||
self.assertIn('download_link', art['blob1'])
|
||||
|
||||
data = self._check_artifact_get(
|
||||
'/withblob/%s/blob1/download' % art['id'])
|
||||
self.assertEqual('ZZZZZ', data)
|
||||
|
||||
def test_limit(self):
|
||||
artifact_data = {'name': 'artifact-1',
|
||||
'version': '12'}
|
||||
|
|
Loading…
Reference in New Issue