summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-03-12 02:46:11 +0000
committerGerrit Code Review <review@openstack.org>2012-03-12 02:46:11 +0000
commitfa4751edef2c12c4e28372659d39c8902f2e9990 (patch)
tree5510a811162c2b6359c6c211cb58455893e860ef
parent2cc409c6f0ae61b1c1833ce679b603d0369b42e8 (diff)
parentb5f75253048438891a8740a1ea4719e5f3208ccb (diff)
downloadnova-fa4751edef2c12c4e28372659d39c8902f2e9990.tar.gz
nova-fa4751edef2c12c4e28372659d39c8902f2e9990.tar.xz
nova-fa4751edef2c12c4e28372659d39c8902f2e9990.zip
Merge "Sub in InstanceLimitExceeded in overLimit message"
-rw-r--r--nova/api/openstack/compute/servers.py3
-rw-r--r--nova/compute/api.py11
-rw-r--r--nova/tests/api/openstack/compute/test_servers.py19
-rw-r--r--nova/tests/api/openstack/fakes.py6
4 files changed, 32 insertions, 7 deletions
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py
index 2bfbfb745..0be57793c 100644
--- a/nova/api/openstack/compute/servers.py
+++ b/nova/api/openstack/compute/servers.py
@@ -491,7 +491,8 @@ class Controller(wsgi.Controller):
"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})
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 3279ca546..73a4ef1b6 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -210,14 +210,13 @@ class API(base.Base):
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)
diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py
index 9d40d7eaa..2d3384dce 100644
--- a/nova/tests/api/openstack/compute/test_servers.py
+++ b/nova/tests/api/openstack/compute/test_servers.py
@@ -2068,6 +2068,25 @@ class ServersControllerCreateTest(test.TestCase):
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):
diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py
index 172a549ba..80f72aaea 100644
--- a/nova/tests/api/openstack/fakes.py
+++ b/nova/tests/api/openstack/fakes.py
@@ -153,6 +153,12 @@ def stub_out_rate_limiting(stubs):
'__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'