From: Ollie Leahy Date: Fri, 4 Oct 2013 14:56:26 +0000 (+0000) Subject: Provide user with more information on quota fail X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=2d8b905f474a879ad6a9a441e79bf7b05d2d39a5;p=openstack-build%2Fcinder-build.git Provide user with more information on quota fail Provide the user with useful information when a snapshot or volume create fails because it would cause the user to exceed available quota. Specifically report the user's current gigabyte usage and quota allocations. Closes-Bug: #1235148 Change-Id: Ib4c5dbcbd172c69834c2824791af755380f38e01 --- diff --git a/cinder/exception.py b/cinder/exception.py index 7c2bdddc9..1a35d2c62 100644 --- a/cinder/exception.py +++ b/cinder/exception.py @@ -399,8 +399,9 @@ class QuotaError(CinderException): class VolumeSizeExceedsAvailableQuota(QuotaError): - message = _("Requested volume or snapshot exceeds " - "allowed Gigabytes quota") + message = _("Requested volume or snapshot exceeds allowed Gigabytes " + "quota. Requested %(requested)sG, quota is %(quota)sG and " + "%(consumed)sG has been consumed.") class VolumeLimitExceeded(QuotaError): diff --git a/cinder/tests/api/contrib/test_backups.py b/cinder/tests/api/contrib/test_backups.py index 9cca5e254..0ff300e75 100644 --- a/cinder/tests/api/contrib/test_backups.py +++ b/cinder/tests/api/contrib/test_backups.py @@ -852,7 +852,9 @@ class BackupsAPITestCase(test.TestCase): def fake_backup_api_restore_throwing_VolumeSizeExceedsAvailableQuota( cls, context, backup_id, volume_id): - raise exception.VolumeSizeExceedsAvailableQuota() + raise exception.VolumeSizeExceedsAvailableQuota(requested='2', + consumed='2', + quota='3') self.stubs.Set( cinder.backup.API, @@ -877,7 +879,8 @@ class BackupsAPITestCase(test.TestCase): self.assertEqual(res_dict['overLimit']['code'], 413) self.assertEqual(res_dict['overLimit']['message'], 'Requested volume or snapshot exceeds allowed ' - 'Gigabytes quota') + 'Gigabytes quota. Requested 2G, quota is 3G and ' + '2G has been consumed.') def test_restore_backup_with_VolumeLimitExceeded(self): diff --git a/cinder/tests/api/contrib/test_volume_transfer.py b/cinder/tests/api/contrib/test_volume_transfer.py index 5ca1e9ac9..30d5f22ac 100644 --- a/cinder/tests/api/contrib/test_volume_transfer.py +++ b/cinder/tests/api/contrib/test_volume_transfer.py @@ -513,7 +513,9 @@ class VolumeTransferAPITestCase(test.TestCase): def fake_transfer_api_accept_throwing_VolumeSizeExceedsAvailableQuota( cls, context, transfer, volume_id): - raise exception.VolumeSizeExceedsAvailableQuota() + raise exception.VolumeSizeExceedsAvailableQuota(requested='2', + consumed='2', + quota='3') self.stubs.Set( cinder.transfer.API, @@ -538,7 +540,8 @@ class VolumeTransferAPITestCase(test.TestCase): self.assertEqual(res_dict['overLimit']['code'], 413) self.assertEqual(res_dict['overLimit']['message'], 'Requested volume or snapshot exceeds allowed ' - 'Gigabytes quota') + 'Gigabytes quota. Requested 2G, quota is 3G and ' + '2G has been consumed.') def test_accept_transfer_with_VolumeLimitExceeded(self): diff --git a/cinder/transfer/api.py b/cinder/transfer/api.py index c52f3faa5..99ccf23a7 100644 --- a/cinder/transfer/api.py +++ b/cinder/transfer/api.py @@ -162,7 +162,10 @@ class API(base.Base): 's_size': vol_ref['size'], 'd_consumed': _consumed('gigabytes'), 'd_quota': quotas['gigabytes']}) - raise exception.VolumeSizeExceedsAvailableQuota() + raise exception.VolumeSizeExceedsAvailableQuota( + requested=vol_ref['size'], + consumed=_consumed('gigabytes'), + quota=quotas['gigabytes']) elif 'volumes' in overs: msg = _("Quota exceeded for %(s_pid)s, tried to create " "volume (%(d_consumed)d volumes " diff --git a/cinder/volume/api.py b/cinder/volume/api.py index fd43731d1..c17330d63 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -496,7 +496,10 @@ class API(base.Base): 's_size': volume['size'], 'd_consumed': _consumed(over), 'd_quota': quotas[over]}) - raise exception.VolumeSizeExceedsAvailableQuota() + raise exception.VolumeSizeExceedsAvailableQuota( + requested=volume['size'], + consumed=_consumed('gigabytes'), + quota=quotas['gigabytes']) elif 'snapshots' in over: msg = _("Quota exceeded for %(s_pid)s, tried to create " "snapshot (%(d_consumed)d snapshots " diff --git a/cinder/volume/flows/create_volume/__init__.py b/cinder/volume/flows/create_volume/__init__.py index 03a7933e1..0bda98918 100644 --- a/cinder/volume/flows/create_volume/__init__.py +++ b/cinder/volume/flows/create_volume/__init__.py @@ -634,7 +634,10 @@ class QuotaReserveTask(base.CinderTask): 's_size': size, 'd_consumed': _consumed('gigabytes'), 'd_quota': quotas['gigabytes']}) - raise exception.VolumeSizeExceedsAvailableQuota() + raise exception.VolumeSizeExceedsAvailableQuota( + requested=size, + consumed=_consumed('gigabytes'), + quota=quotas['gigabytes']) elif _is_over('volumes'): msg = _("Quota exceeded for %(s_pid)s, tried to create " "volume (%(d_consumed)d volumes "