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 "
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)
}
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'])
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)")