Permalink
Browse files

Changed return code to 413 for metadata, personality and instance quo…

…ta issues
  • Loading branch information...
1 parent 6dbcc60 commit 79f3b1512166a37790c5cb2863140d696c717455 Troy Toman committed Aug 17, 2011
View
1 Authors
@@ -101,6 +101,7 @@ Stephanie Reese <reese.sm@gmail.com>
Thierry Carrez <thierry@openstack.org>
Todd Willey <todd@ansolabs.com>
Trey Morris <trey.morris@rackspace.com>
+Troy Toman <troy.toman@rackspace.com>
Tushar Patil <tushar.vitthal.patil@gmail.com>
Vasiliy Shlykov <vash@vasiliyshlykov.org>
Vishvananda Ishaya <vishvananda@gmail.com>
View
3 nova/api/openstack/common.py
@@ -241,7 +241,8 @@ def check_img_metadata_quota_limit(context, metadata):
quota_metadata = quota.allowed_metadata_items(context, num_metadata)
if quota_metadata < num_metadata:
expl = _("Image metadata limit exceeded")
- raise webob.exc.HTTPBadRequest(explanation=expl)
+ raise webob.exc.HTTPRequestEntityTooLarge(explanation=expl,
+ headers={'Retry-After': 0})
class MetadataXMLDeserializer(wsgi.XMLDeserializer):
View
13 nova/api/openstack/create_instance_helper.py
@@ -180,13 +180,20 @@ def _handle_quota_error(self, error):
"""
if error.code == "OnsetFileLimitExceeded":
expl = _("Personality file limit exceeded")
- raise exc.HTTPBadRequest(explanation=expl)
+ raise exc.HTTPRequestEntityTooLarge(explanation=error.message,
+ headers={'Retry-After': 0})
if error.code == "OnsetFilePathLimitExceeded":
expl = _("Personality file path too long")
- raise exc.HTTPBadRequest(explanation=expl)
+ raise exc.HTTPRequestEntityTooLarge(explanation=error.message,
+ headers={'Retry-After': 0})
if error.code == "OnsetFileContentLimitExceeded":
expl = _("Personality file content too long")
- raise exc.HTTPBadRequest(explanation=expl)
+ raise exc.HTTPRequestEntityTooLarge(explanation=error.message,
+ headers={'Retry-After': 0})
+ if error.code == "InstanceLimitExceeded":
+ expl = _("Instance quotas have been exceeded")
+ raise exc.HTTPRequestEntityTooLarge(explanation=error.message,
+ headers={'Retry-After': 0})
# if the original error is okay, just reraise it
raise error
View
2 nova/api/openstack/faults.py
@@ -53,7 +53,7 @@ def __call__(self, req):
fault_name: {
'code': code,
'message': self.wrapped_exc.explanation}}
- if code == 413:
+ if code == 413 and self.wrapped_exc.headers['Retry-After']:
retry = self.wrapped_exc.headers['Retry-After']
fault_data[fault_name]['retryAfter'] = retry
View
3 nova/api/openstack/server_metadata.py
@@ -151,7 +151,8 @@ def delete(self, req, server_id, id):
def _handle_quota_error(self, error):
"""Reraise quota errors as api-specific http exceptions."""
if error.code == "MetadataLimitExceeded":
- raise exc.HTTPBadRequest(explanation=error.message)
+ raise exc.HTTPRequestEntityTooLarge(explanation=error.message,
+ headers={'Retry-After': 0})
raise error
View
2 nova/quota.py
@@ -164,5 +164,5 @@ def allowed_injected_file_path_bytes(context):
class QuotaError(exception.ApiError):
- """Quota Exceeeded."""
+ """Quota Exceeded."""
pass
View
4 nova/tests/api/openstack/test_image_metadata.py
@@ -230,12 +230,12 @@ def test_too_many_metadata_items_on_create(self):
req.body = json_string
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
- self.assertEqual(400, res.status_int)
+ self.assertEqual(413, res.status_int)
def test_too_many_metadata_items_on_put(self):
req = webob.Request.blank('/v1.1/images/3/metadata/blah')
req.method = 'PUT'
req.body = '{"meta": {"blah": "blah"}}'
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
- self.assertEqual(400, res.status_int)
+ self.assertEqual(413, res.status_int)
View
4 nova/tests/api/openstack/test_server_actions.py
@@ -392,7 +392,7 @@ def test_create_backup_with_too_much_metadata(self):
req.body = json.dumps(body)
req.headers["content-type"] = "application/json"
response = req.get_response(fakes.wsgi_app())
- self.assertEqual(400, response.status_int)
+ self.assertEqual(413, response.status_int)
def test_create_backup_no_name(self):
"""Name is required for backups"""
@@ -865,7 +865,7 @@ def test_create_image_with_too_much_metadata(self):
req.body = json.dumps(body)
req.headers["content-type"] = "application/json"
response = req.get_response(fakes.wsgi_app())
- self.assertEqual(400, response.status_int)
+ self.assertEqual(413, response.status_int)
def test_create_image_no_name(self):
body = {
View
4 nova/tests/api/openstack/test_server_metadata.py
@@ -417,9 +417,9 @@ def test_too_many_metadata_items_on_create(self):
req.body = json_string
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
- self.assertEqual(400, res.status_int)
+ self.assertEqual(413, res.status_int)
- def test_to_many_metadata_items_on_update_item(self):
+ def test_too_many_metadata_items_on_update_item(self):
self.stubs.Set(nova.db.api, 'instance_metadata_update',
return_create_instance_metadata_max)
req = webob.Request.blank('/v1.1/servers/1/metadata/key1')

0 comments on commit 79f3b15

Please sign in to comment.