Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
leahyo committed Oct 4, 2013
1 parent 150e83d commit 2d8b905
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
5 changes: 3 additions & 2 deletions cinder/exception.py
Expand Up @@ -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):
Expand Down
7 changes: 5 additions & 2 deletions cinder/tests/api/contrib/test_backups.py
Expand Up @@ -852,7 +852,9 @@ def test_restore_backup_with_VolumeSizeExceedsAvailableQuota(self):

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,
Expand All @@ -877,7 +879,8 @@ def fake_backup_api_restore_throwing_VolumeSizeExceedsAvailableQuota(
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):

Expand Down
7 changes: 5 additions & 2 deletions cinder/tests/api/contrib/test_volume_transfer.py
Expand Up @@ -513,7 +513,9 @@ def test_accept_transfer_with_VolumeSizeExceedsAvailableQuota(self):

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,
Expand All @@ -538,7 +540,8 @@ def fake_transfer_api_accept_throwing_VolumeSizeExceedsAvailableQuota(
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):

Expand Down
5 changes: 4 additions & 1 deletion cinder/transfer/api.py
Expand Up @@ -162,7 +162,10 @@ def _consumed(name):
'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 "
Expand Down
5 changes: 4 additions & 1 deletion cinder/volume/api.py
Expand Up @@ -496,7 +496,10 @@ def _consumed(name):
'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 "
Expand Down
5 changes: 4 additions & 1 deletion cinder/volume/flows/create_volume/__init__.py
Expand Up @@ -634,7 +634,10 @@ def _is_over(name):
'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 "
Expand Down

0 comments on commit 2d8b905

Please sign in to comment.