Skip to content

Commit

Permalink
Sub in InstanceLimitExceeded in overLimit message
Browse files Browse the repository at this point in the history
Fixes bug 950768

Previously the error message in the 413 overLimit response returned
by the OS compute API was missing a parameter subsitution indicating
the actual quota that was breeched:

  'Quota exceeded: code=%(code)s'

This is now properly reported as:

  'Quota exceeded: code=InstanceLimitExceeded'

Also a potentially useful log message is no longer discarded.

Change-Id: I7e1f8b078329a6530bb7d7ea3b006ff578cdcdd3
  • Loading branch information
Eoghan Glynn committed Mar 10, 2012
1 parent 7322c59 commit b5f7525
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
3 changes: 2 additions & 1 deletion nova/api/openstack/compute/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ def _handle_quota_error(self, error):
"InstanceLimitExceeded": error.message,
}

expl = code_mappings.get(error.kwargs['code'], error.message)
code = error.kwargs['code']
expl = code_mappings.get(code, error.message) % error.kwargs
raise exc.HTTPRequestEntityTooLarge(explanation=expl,
headers={'Retry-After': 0})

Expand Down
11 changes: 5 additions & 6 deletions nova/compute/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,13 @@ def _create_instance(self, context, instance_type,
instance_type)
if num_instances < min_count:
pid = context.project_id
LOG.warn(_("Quota exceeded for %(pid)s,"
" tried to run %(min_count)s instances") % locals())
if num_instances <= 0:
message = _("Instance quota exceeded. You cannot run any "
"more instances of this type.")
msg = _("Cannot run any more instances of this type.")
else:
message = _("Instance quota exceeded. You can only run %s "
"more instances of this type.") % num_instances
msg = (_("Can only run %s more instances of this type.") %
num_instances)
LOG.warn(_("Quota exceeded for %(pid)s,"
" tried to run %(min_count)s instances. " + msg) % locals())
raise exception.QuotaError(code="InstanceLimitExceeded")

self._check_metadata_properties_quota(context, metadata)
Expand Down
19 changes: 19 additions & 0 deletions nova/tests/api/openstack/compute/test_servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2068,6 +2068,25 @@ def test_create_location(self):

self.assertEqual(robj['Location'], selfhref)

def test_create_instance_above_quota(self):
fakes.stub_out_instance_quota(self.stubs, 0)
image_uuid = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77'
body = dict(server=dict(
name='server_test', imageRef=image_uuid, flavorRef=2,
metadata={'hello': 'world', 'open': 'stack'},
personality={}))
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.headers["content-type"] = "application/json"
try:
server = self.controller.create(req, body).obj['server']
fail('excepted quota to be exceeded')
except webob.exc.HTTPRequestEntityTooLarge as e:
code = {'code': 'InstanceLimitExceeded'}
self.assertEquals(e.explanation,
_('Quota exceeded: code=%(code)s') % code)


class TestServerCreateRequestXMLDeserializer(test.TestCase):

Expand Down
6 changes: 6 additions & 0 deletions nova/tests/api/openstack/fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ def fake_rate_init(self, app):
'__call__', fake_wsgi)


def stub_out_instance_quota(stubs, allowed):
def fake_allowed_instances(context, max_count, instance_type):
return allowed
stubs.Set(nova.quota, 'allowed_instances', fake_allowed_instances)


def stub_out_networking(stubs):
def get_my_ip():
return '127.0.0.1'
Expand Down

0 comments on commit b5f7525

Please sign in to comment.