Fix calculation of the folder size

If folder contains blobs with external links
their sizes will be None, which leads to errors,
like

TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

Closes-bug: #1702113

Change-Id: I0bf431b1cded7848fe17fa69aad1e34ec11eeb87
This commit is contained in:
Mike Fedosin 2017-07-03 17:25:36 +03:00
parent 9b50f5d839
commit 4b2c4260dc
2 changed files with 14 additions and 2 deletions

View File

@ -320,8 +320,9 @@ class Engine(object):
# Check if we wanna upload to a folder (and not just to a Blob)
if blob_key is not None:
blobs_dict = getattr(af, field_name)
overall_folder_size = sum(blob["size"] for blob
in blobs_dict.values())
overall_folder_size = sum(
blob["size"] for blob in blobs_dict.values()
if blob["size"] is not None)
max_folder_size_allowed_ = af.get_max_folder_size(field_name) \
- overall_folder_size # always non-negative
max_allowed_size = min(max_allowed_size,

View File

@ -117,6 +117,17 @@ class TestArtifactUpload(base.BaseTestArtifactAPI):
self.assertEqual('active', artifact['dict_of_blobs']['blb2']['status'])
def test_upload_oversized_blob_dict(self):
# external location shouldn't affect folder size
ct = 'application/vnd+openstack.glare-custom-location+json'
body = {'url': 'https://FAKE_LOCATION.com',
'md5': "fake", 'sha1': "fake_sha", "sha256": "fake_sha256"}
artifact = self.controller.upload_blob(
self.req, 'sample_artifact', self.sample_artifact['id'],
'dict_of_blobs/external', body, ct)
self.assertIsNone(artifact['dict_of_blobs']['external']['size'])
self.assertEqual('active',
artifact['dict_of_blobs']['external']['status'])
self.controller.upload_blob(
self.req, 'sample_artifact', self.sample_artifact['id'],
'dict_of_blobs/a',