From: Forest Romain Date: Thu, 18 Jun 2015 08:58:25 +0000 (+0200) Subject: Correct overquota error message X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=76e0532db2405c59e19700241b965998f8918f8f;p=openstack-build%2Fcinder-build.git 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 --- diff --git a/cinder/exception.py b/cinder/exception.py index a8db1b040..87997dc99 100644 --- a/cinder/exception.py +++ b/cinder/exception.py @@ -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 " diff --git a/cinder/tests/unit/test_quota.py b/cinder/tests/unit/test_quota.py index 98fb1404b..d6610ae5c 100644 --- a/cinder/tests/unit/test_quota.py +++ b/cinder/tests/unit/test_quota.py @@ -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']) diff --git a/cinder/volume/flows/api/create_volume.py b/cinder/volume/flows/api/create_volume.py index 6d3b8077f..ac6bc9b19 100644 --- a/cinder/volume/flows/api/create_volume.py +++ b/cinder/volume/flows/api/create_volume.py @@ -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)")