Skip to content

Commit

Permalink
fix the instance quota overlimit message
Browse files Browse the repository at this point in the history
This addresses two closely related bugs.

Bug: 998199
Fix the "used" and "total" counts
in the returned diagnostic.

Bug: 902218
Itemize instance quota items exceeded,
in the returned diagnostic.

Change-Id: Iff7781a7fb53545d44c2b4ec0ca6d65114723c8d
  • Loading branch information
Pádraig Brady committed Jun 5, 2012
1 parent 1334ce8 commit 84969af
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
17 changes: 13 additions & 4 deletions nova/compute/api.py
Expand Up @@ -172,9 +172,13 @@ def _check_num_instances_quota(self, context, instance_type, min_count,
# OK, we exceeded quota; let's figure out why...
quotas = exc.kwargs['quotas']
usages = exc.kwargs['usages']
overs = exc.kwargs['overs']

headroom = dict((res, quotas[res] -
(usages[res]['in_use'] + usages[res]['reserved']))
for res in quotas.keys())

# Reduce 'allowed' to the minimum supported
allowed = headroom['instances']
if instance_type['vcpus']:
allowed = min(allowed,
Expand All @@ -187,18 +191,23 @@ def _check_num_instances_quota(self, context, instance_type, min_count,
pid = context.project_id
if allowed <= 0:
msg = _("Cannot run any more instances of this type.")
used = max_count
allowed = 0
elif min_count <= allowed <= max_count:
# We're actually OK, but still need reservations
return self._check_num_instances_quota(context, instance_type,
min_count, allowed)
else:
msg = (_("Can only run %s more instances of this type.") %
allowed)
used = max_count - allowed
LOG.warn(_("Quota exceeded for %(pid)s,"

used = quotas['instances'] - headroom['instances']
total_allowed = used + allowed
overs = ','.join(overs)

LOG.warn(_("%(overs)s quota exceeded for %(pid)s,"
" tried to run %(min_count)s instances. %(msg)s"), locals())
raise exception.TooManyInstances(used=used, allowed=max_count)
raise exception.TooManyInstances(overs=overs, req=min_count,
used=used, allowed=total_allowed)

return max_count, reservations

Expand Down
4 changes: 2 additions & 2 deletions nova/exception.py
Expand Up @@ -993,8 +993,8 @@ class QuotaError(NovaException):


class TooManyInstances(QuotaError):
message = _("Quota exceeded: already used %(used)d of %(allowed)d"
" instances")
message = _("Quota exceeded for %(overs)s: Requested %(req)s,"
" but already used %(used)d of %(allowed)d instances")


class VolumeSizeTooLarge(QuotaError):
Expand Down
3 changes: 2 additions & 1 deletion nova/tests/api/openstack/compute/test_servers.py
Expand Up @@ -2348,7 +2348,8 @@ def test_create_instance_above_quota(self):
self.fail('expected quota to be exceeded')
except webob.exc.HTTPRequestEntityTooLarge as e:
self.assertEquals(e.explanation,
_('Quota exceeded: already used 1 of 1 instances'))
_('Quota exceeded for instances: Requested 1, but'
' already used 0 of 0 instances'))


class TestServerCreateRequestXMLDeserializer(test.TestCase):
Expand Down

0 comments on commit 84969af

Please sign in to comment.