Correct overquota error message

When an overquota is raised, VolumeSizeExceedsAvailableQuota returns
gigabytes quota instead of the related property quota. This change
correct values in order to match with related property quota.

Change-Id: I82fb676007a820a1890fde488ffe25320e035ff5
Closes-Bug: #1463798
This commit is contained in:
Forest Romain 2015-06-18 10:58:25 +02:00
parent 5f6cbecc5e
commit 76e0532db2
3 changed files with 29 additions and 18 deletions

View File

@ -446,10 +446,15 @@ class QuotaError(CinderException):
class VolumeSizeExceedsAvailableQuota(QuotaError):
message = _("Requested volume or snapshot exceeds allowed gigabytes "
message = _("Requested volume or snapshot exceeds allowed %(name)s "
"quota. Requested %(requested)sG, quota is %(quota)sG and "
"%(consumed)sG has been consumed.")
def __init__(self, message=None, **kwargs):
kwargs.setdefault('name', 'gigabytes')
super(VolumeSizeExceedsAvailableQuota, self).__init__(
message, **kwargs)
class VolumeSizeExceedsLimit(QuotaError):
message = _("Requested volume size %(size)d is larger than "

View File

@ -181,10 +181,12 @@ class QuotaIntegrationTestCase(test.TestCase):
volume_ids = []
vol_ref = self._create_volume(size=20)
volume_ids.append(vol_ref['id'])
self.assertRaises(exception.VolumeSizeExceedsAvailableQuota,
volume.API().create,
self.context, 1, '', '',
volume_type=self.volume_type)
raised_exc = self.assertRaises(
exception.VolumeSizeExceedsAvailableQuota, volume.API().create,
self.context, 1, '', '', volume_type=self.volume_type)
expected = exception.VolumeSizeExceedsAvailableQuota(
requested=1, quota=20, consumed=20)
self.assertEqual(str(expected), str(raised_exc))
for volume_id in volume_ids:
db.volume_destroy(self.context, volume_id)
@ -280,10 +282,12 @@ class QuotaIntegrationTestCase(test.TestCase):
}
self.flags(**flag_args)
vol_ref = self._create_volume(size=10)
self.assertRaises(exception.VolumeSizeExceedsAvailableQuota,
volume.API().create,
self.context, 1, '', '',
volume_type=self.volume_type)
raised_exc = self.assertRaises(
exception.VolumeSizeExceedsAvailableQuota, volume.API().create,
self.context, 1, '', '', volume_type=self.volume_type)
expected = exception.VolumeSizeExceedsAvailableQuota(
requested=1, quota=10, consumed=10, name=resource)
self.assertEqual(str(expected), str(raised_exc))
db.volume_destroy(self.context, vol_ref['id'])

View File

@ -540,25 +540,27 @@ class QuotaReserveTask(flow_utils.CinderTask):
def _consumed(name):
return usages[name]['reserved'] + usages[name]['in_use']
def _is_over(name):
def _get_over(name):
for over in overs:
if name in over:
return True
return False
return over
return None
if _is_over('gigabytes'):
over_name = _get_over('gigabytes')
if over_name:
msg = _LW("Quota exceeded for %(s_pid)s, tried to create "
"%(s_size)sG volume (%(d_consumed)dG "
"of %(d_quota)dG already consumed)")
LOG.warning(msg, {'s_pid': context.project_id,
's_size': size,
'd_consumed': _consumed('gigabytes'),
'd_quota': quotas['gigabytes']})
'd_consumed': _consumed(over_name),
'd_quota': quotas[over_name]})
raise exception.VolumeSizeExceedsAvailableQuota(
name=over_name,
requested=size,
consumed=_consumed('gigabytes'),
quota=quotas['gigabytes'])
elif _is_over('volumes'):
consumed=_consumed(over_name),
quota=quotas[over_name])
elif _get_over('volumes'):
msg = _LW("Quota exceeded for %(s_pid)s, tried to create "
"volume (%(d_consumed)d volumes "
"already consumed)")