Raise an exception when quota config parameter is broken
Function get_remaining_quota returns None when quota config param doesn't match a pattern (i.e. it's broken). It messes up the logic of its callers and leads to unpredictible behavior of the entire system. This code raises InvalidOptionValue exception if config is broken Change-Id: Ib08d2114f460d127aacf580fc519a58d6e8eba16
This commit is contained in:
parent
392ee8076f
commit
6a9e172135
|
@ -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,
|
||||
|
|
|
@ -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.")
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue