diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index 71dc1e2ae50b..e90e30b7dfe7 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -478,7 +478,8 @@ class Controller(wsgi.Controller): raise exc.HTTPRequestEntityTooLarge(explanation=expl, headers={'Retry-After': 0}) # if the original error is okay, just reraise it - raise error + raise exc.HTTPRequestEntityTooLarge(explanation=error.msg, + headers={'Retry-After': 0}) def _validate_server_name(self, value): if not isinstance(value, basestring): diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py index 83b0e345ccd3..8d810c4a0526 100644 --- a/nova/tests/api/openstack/compute/test_servers.py +++ b/nova/tests/api/openstack/compute/test_servers.py @@ -1605,6 +1605,32 @@ class ServersControllerCreateTest(test.TestCase): self.assertEqual(FLAGS.password_length, len(server['adminPass'])) self.assertEqual(FAKE_UUID, server['id']) + def test_create_instance_too_much_metadata(self): + self.flags(quota_metadata_items=1) + image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6' + image_href = 'http://localhost/v2/images/%s' % image_uuid + flavor_ref = 'http://localhost/123/flavors/3' + body = { + 'server': { + 'name': 'server_test', + 'imageRef': image_href, + 'flavorRef': flavor_ref, + 'metadata': { + 'hello': 'world', + 'open': 'stack', + 'vote': 'fiddletown', + }, + }, + } + + req = fakes.HTTPRequest.blank('/v2/fake/servers') + req.method = 'POST' + req.body = json.dumps(body) + req.headers["content-type"] = "application/json" + + self.assertRaises(webob.exc.HTTPRequestEntityTooLarge, + self.controller.create, req, body) + def test_create_instance_invalid_key_name(self): image_href = 'http://localhost/v2/images/2' flavor_ref = 'http://localhost/flavors/3'