summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorPádraig Brady <pbrady@redhat.com>2012-06-05 14:33:43 +0100
committerPádraig Brady <pbrady@redhat.com>2012-06-05 18:23:14 +0100
commit84969afb3bfd467a2f48cf030a325c1a2fcd13ca (patch)
treec95d9f57753cb37c7388e960e15a53613a0ce097 /nova
parent1334ce8755c775c963aa98a6d43e521fb641a569 (diff)
fix the instance quota overlimit message
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
Diffstat (limited to 'nova')
-rw-r--r--nova/compute/api.py17
-rw-r--r--nova/exception.py4
-rw-r--r--nova/tests/api/openstack/compute/test_servers.py3
3 files changed, 17 insertions, 7 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 0b425e726..c49604daf 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -172,9 +172,13 @@ class API(base.Base):
# 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,
@@ -187,7 +191,7 @@ class API(base.Base):
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,
@@ -195,10 +199,15 @@ class API(base.Base):
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
diff --git a/nova/exception.py b/nova/exception.py
index fd9f4c1ea..4f7f17fb5 100644
--- a/nova/exception.py
+++ b/nova/exception.py
@@ -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):
diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py
index f9e815c20..44741596b 100644
--- a/nova/tests/api/openstack/compute/test_servers.py
+++ b/nova/tests/api/openstack/compute/test_servers.py
@@ -2348,7 +2348,8 @@ class ServersControllerCreateTest(test.TestCase):
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):