Merge "Raise an exception when quota config parameter is broken"

This commit is contained in:
Jenkins
2014-11-03 10:00:11 +00:00
committed by Gerrit Code Review
3 changed files with 16 additions and 5 deletions

View File

@@ -115,10 +115,11 @@ def get_remaining_quota(context, db_api, image_id=None):
match = pattern.match(users_quota)
if not match:
LOG.warn(_LW("Invalid value for option user_storage_quota: "
"%(users_quota)s")
% {'users_quota': users_quota})
return None
LOG.error(_LE("Invalid value for option user_storage_quota: "
"%(users_quota)s")
% {'users_quota': users_quota})
raise exception.InvalidOptionValue(option='user_storage_quota',
value=users_quota)
quota_value, quota_unit = (match.groups())[0:2]
# fall back to Bytes if user specified anything other than
@@ -128,7 +129,7 @@ def get_remaining_quota(context, db_api, image_id=None):
users_quota = int(quota_value) * factor
if users_quota <= 0:
return None
return
usage = db_api.user_get_storage_usage(context,
context.owner,

View File

@@ -163,6 +163,10 @@ class InvalidFilterRangeValue(Invalid):
message = _("Unable to filter using the specified range.")
class InvalidOptionValue(Invalid):
message = _("Invalid value for option %(option)s: %(value)s")
class ReadonlyProperty(Forbidden):
message = _("Attribute '%(property)s' is read-only.")

View File

@@ -434,6 +434,12 @@ class TestImagePropertyQuotas(test_utils.BaseTestCase):
self.assertNotIn('foo', self.base_image.extra_properties)
self.assertEqual('ham', self.base_image.extra_properties['spam'])
def test_invalid_quota_config_parameter(self):
self.config(user_storage_quota='foo')
location = {"url": "file:///fake.img.tar.gz", "metadata": {}}
self.assertRaises(exception.InvalidOptionValue,
self.image.locations.append, location)
def test_exceed_quota_during_patch_operation(self):
self._quota_exceed_setup()
self.image.extra_properties['frob'] = 'baz'