From c5450756b6f8a1cae307171c28e99bf15c93b265 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Fri, 11 Apr 2014 14:07:31 -0400 Subject: [PATCH] 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 --- nova/api/openstack/compute/versions.py | 4 ++-- .../api/openstack/compute/test_versions.py | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/nova/api/openstack/compute/versions.py b/nova/api/openstack/compute/versions.py index 61c607ad7b11..7d42697a89fd 100644 --- a/nova/api/openstack/compute/versions.py +++ b/nova/api/openstack/compute/versions.py @@ -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) diff --git a/nova/tests/api/openstack/compute/test_versions.py b/nova/tests/api/openstack/compute/test_versions.py index 51cd9a1f0b82..badb577c1c9b 100644 --- a/nova/tests/api/openstack/compute/test_versions.py +++ b/nova/tests/api/openstack/compute/test_versions.py @@ -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)