versions API: ignore request with a body

Update the OS API versions controller so it ignores requests
with a body. Previously an incoming (unauthenticated)
request to the versions API would log a TypeError trace
in the nova-api.log file with the following message:

TypeError: index() got an unexpected keyword argument 'body'

Change-Id: Icc3ccfc537b13627b8d5ba43ae3ba91e34e08c9e
Closes-bug: #1306727
This commit is contained in:
Dan Prince 2014-04-11 14:07:31 -04:00 committed by Mathieu Rohon
parent 6629116c33
commit c5450756b6
2 changed files with 22 additions and 2 deletions

View File

@ -241,14 +241,14 @@ class Versions(wsgi.Resource):
@wsgi.serializers(xml=VersionsTemplate,
atom=VersionsAtomSerializer)
def index(self, req):
def index(self, req, body=None):
"""Return all versions."""
builder = views_versions.get_view_builder(req)
return builder.build_versions(VERSIONS)
@wsgi.serializers(xml=ChoicesTemplate)
@wsgi.response(300)
def multi(self, req):
def multi(self, req, body=None):
"""Return multiple choices."""
builder = views_versions.get_view_builder(req)
return builder.build_choices(VERSIONS, req)

View File

@ -753,3 +753,23 @@ class VersionsSerializerTests(test.NoDBTestCase):
'type': 'application/vnd.sun.wadl+xml',
'href': EXP_LINKS['v2.0']['wadl'],
})
def test_multi_choice_image_with_body(self):
req = webob.Request.blank('/images/1')
req.accept = "application/json"
req.method = 'POST'
req.content_type = "application/json"
req.body = "{\"foo\": \"bar\"}"
res = req.get_response(fakes.wsgi_app())
self.assertEqual(300, res.status_int)
self.assertEqual("application/json", res.content_type)
def test_get_version_list_with_body(self):
req = webob.Request.blank('/')
req.accept = "application/json"
req.method = 'POST'
req.content_type = "application/json"
req.body = "{\"foo\": \"bar\"}"
res = req.get_response(fakes.wsgi_app())
self.assertEqual(200, res.status_int)
self.assertEqual("application/json", res.content_type)