Merge lp:~troy-toman/nova/lp785812 into lp:~hudson-openstack/nova/trunk

Proposed by Troy Toman
Status: Merged
Approved by: Brian Waldon
Approved revision: 1451
Merged at revision: 1453
Proposed branch: lp:~troy-toman/nova/lp785812
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 135 lines (+22/-12)
8 files modified
Authors (+1/-0)
nova/api/openstack/common.py (+2/-1)
nova/api/openstack/create_instance_helper.py (+10/-3)
nova/api/openstack/server_metadata.py (+2/-1)
nova/quota.py (+1/-1)
nova/tests/api/openstack/test_image_metadata.py (+2/-2)
nova/tests/api/openstack/test_server_actions.py (+2/-2)
nova/tests/api/openstack/test_server_metadata.py (+2/-2)
To merge this branch: bzr merge lp:~troy-toman/nova/lp785812
Reviewer Review Type Date Requested Status
Brian Waldon (community) Approve
Dan Prince (community) Approve
Jay Pipes (community) Approve
Review via email: mp+71973@code.launchpad.net

Commit message

Fix to return 413 for over limit exceptions with instances, metadata and personality

Description of the change

This fix returns a 413 for too much instance and image metadata, to large of a personality as well as exceeding quotas for instances, ram, etc. This can be tested by trying to create more than 10 instances in a default configuration or by passing an excessive amount of metadata.

To post a comment you must log in.
Revision history for this message
Jay Pipes (jaypipes) wrote :

nice stuff, Troy :)

review: Approve
Revision history for this message
Dan Prince (dan-prince) wrote :

Looks good.

review: Approve
Revision history for this message
Brian Waldon (bcwaldon) wrote :

Good work.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Authors'
2--- Authors 2011-08-16 17:34:38 +0000
3+++ Authors 2011-08-18 02:06:18 +0000
4@@ -101,6 +101,7 @@
5 Thierry Carrez <thierry@openstack.org>
6 Todd Willey <todd@ansolabs.com>
7 Trey Morris <trey.morris@rackspace.com>
8+Troy Toman <troy.toman@rackspace.com>
9 Tushar Patil <tushar.vitthal.patil@gmail.com>
10 Vasiliy Shlykov <vash@vasiliyshlykov.org>
11 Vishvananda Ishaya <vishvananda@gmail.com>
12
13=== modified file 'nova/api/openstack/common.py'
14--- nova/api/openstack/common.py 2011-08-14 04:25:46 +0000
15+++ nova/api/openstack/common.py 2011-08-18 02:06:18 +0000
16@@ -241,7 +241,8 @@
17 quota_metadata = quota.allowed_metadata_items(context, num_metadata)
18 if quota_metadata < num_metadata:
19 expl = _("Image metadata limit exceeded")
20- raise webob.exc.HTTPBadRequest(explanation=expl)
21+ raise webob.exc.HTTPRequestEntityTooLarge(explanation=expl,
22+ headers={'Retry-After': 0})
23
24
25 class MetadataXMLDeserializer(wsgi.XMLDeserializer):
26
27=== modified file 'nova/api/openstack/create_instance_helper.py'
28--- nova/api/openstack/create_instance_helper.py 2011-08-11 18:15:14 +0000
29+++ nova/api/openstack/create_instance_helper.py 2011-08-18 02:06:18 +0000
30@@ -180,13 +180,20 @@
31 """
32 if error.code == "OnsetFileLimitExceeded":
33 expl = _("Personality file limit exceeded")
34- raise exc.HTTPBadRequest(explanation=expl)
35+ raise exc.HTTPRequestEntityTooLarge(explanation=error.message,
36+ headers={'Retry-After': 0})
37 if error.code == "OnsetFilePathLimitExceeded":
38 expl = _("Personality file path too long")
39- raise exc.HTTPBadRequest(explanation=expl)
40+ raise exc.HTTPRequestEntityTooLarge(explanation=error.message,
41+ headers={'Retry-After': 0})
42 if error.code == "OnsetFileContentLimitExceeded":
43 expl = _("Personality file content too long")
44- raise exc.HTTPBadRequest(explanation=expl)
45+ raise exc.HTTPRequestEntityTooLarge(explanation=error.message,
46+ headers={'Retry-After': 0})
47+ if error.code == "InstanceLimitExceeded":
48+ expl = _("Instance quotas have been exceeded")
49+ raise exc.HTTPRequestEntityTooLarge(explanation=error.message,
50+ headers={'Retry-After': 0})
51 # if the original error is okay, just reraise it
52 raise error
53
54
55=== modified file 'nova/api/openstack/server_metadata.py'
56--- nova/api/openstack/server_metadata.py 2011-08-09 15:10:14 +0000
57+++ nova/api/openstack/server_metadata.py 2011-08-18 02:06:18 +0000
58@@ -151,7 +151,8 @@
59 def _handle_quota_error(self, error):
60 """Reraise quota errors as api-specific http exceptions."""
61 if error.code == "MetadataLimitExceeded":
62- raise exc.HTTPBadRequest(explanation=error.message)
63+ raise exc.HTTPRequestEntityTooLarge(explanation=error.message,
64+ headers={'Retry-After': 0})
65 raise error
66
67
68
69=== modified file 'nova/quota.py'
70--- nova/quota.py 2011-05-19 18:08:15 +0000
71+++ nova/quota.py 2011-08-18 02:06:18 +0000
72@@ -164,5 +164,5 @@
73
74
75 class QuotaError(exception.ApiError):
76- """Quota Exceeeded."""
77+ """Quota Exceeded."""
78 pass
79
80=== modified file 'nova/tests/api/openstack/test_image_metadata.py'
81--- nova/tests/api/openstack/test_image_metadata.py 2011-07-29 16:28:02 +0000
82+++ nova/tests/api/openstack/test_image_metadata.py 2011-08-18 02:06:18 +0000
83@@ -230,7 +230,7 @@
84 req.body = json_string
85 req.headers["content-type"] = "application/json"
86 res = req.get_response(fakes.wsgi_app())
87- self.assertEqual(400, res.status_int)
88+ self.assertEqual(413, res.status_int)
89
90 def test_too_many_metadata_items_on_put(self):
91 req = webob.Request.blank('/v1.1/images/3/metadata/blah')
92@@ -238,4 +238,4 @@
93 req.body = '{"meta": {"blah": "blah"}}'
94 req.headers["content-type"] = "application/json"
95 res = req.get_response(fakes.wsgi_app())
96- self.assertEqual(400, res.status_int)
97+ self.assertEqual(413, res.status_int)
98
99=== modified file 'nova/tests/api/openstack/test_server_actions.py'
100--- nova/tests/api/openstack/test_server_actions.py 2011-08-11 01:27:40 +0000
101+++ nova/tests/api/openstack/test_server_actions.py 2011-08-18 02:06:18 +0000
102@@ -392,7 +392,7 @@
103 req.body = json.dumps(body)
104 req.headers["content-type"] = "application/json"
105 response = req.get_response(fakes.wsgi_app())
106- self.assertEqual(400, response.status_int)
107+ self.assertEqual(413, response.status_int)
108
109 def test_create_backup_no_name(self):
110 """Name is required for backups"""
111@@ -865,7 +865,7 @@
112 req.body = json.dumps(body)
113 req.headers["content-type"] = "application/json"
114 response = req.get_response(fakes.wsgi_app())
115- self.assertEqual(400, response.status_int)
116+ self.assertEqual(413, response.status_int)
117
118 def test_create_image_no_name(self):
119 body = {
120
121=== modified file 'nova/tests/api/openstack/test_server_metadata.py'
122--- nova/tests/api/openstack/test_server_metadata.py 2011-08-09 15:47:46 +0000
123+++ nova/tests/api/openstack/test_server_metadata.py 2011-08-18 02:06:18 +0000
124@@ -417,9 +417,9 @@
125 req.body = json_string
126 req.headers["content-type"] = "application/json"
127 res = req.get_response(fakes.wsgi_app())
128- self.assertEqual(400, res.status_int)
129+ self.assertEqual(413, res.status_int)
130
131- def test_to_many_metadata_items_on_update_item(self):
132+ def test_too_many_metadata_items_on_update_item(self):
133 self.stubs.Set(nova.db.api, 'instance_metadata_update',
134 return_create_instance_metadata_max)
135 req = webob.Request.blank('/v1.1/servers/1/metadata/key1')