diff options
author | Brandon Irizarry <iz.brandon@yahoo.com> | 2016-04-13 05:18:25 +0000 |
---|---|---|
committer | ghanshyam <ghanshyam.mann@nectechnologies.in> | 2016-04-22 13:06:42 +0900 |
commit | f6f0d1bae8b67c2d8617f87dbc453a60943883c3 (patch) | |
tree | 3feb3107335a3eac5382e378505eb8279a740304 | |
parent | 6fdf1c87b1149e8b395eaa9f4cbf27263cf96ac6 (diff) | |
download | nova-f6f0d1bae8b67c2d8617f87dbc453a60943883c3.tar.gz |
Changed an HTTP exception to return proper code
POSTing to /servers with a content-type of text/plain
and a text/plain body results in a response code of 400.
It should be 415. I found this line in the code that
appears to handle this singular case and modified
the HTTP exception used to the correct one. Tests were
also updated accordingly.
Conflicts:
nova/api/openstack/wsgi.py
nova/tests/unit/api/openstack/compute/legacy_v2/test_servers.py
Change-Id: I5fa1fdba56803b2ef63b1efaaeeced6ceb7779d9
Closes-Bug: 1567977
(cherry picked from commit a7019a87ba696509d825c6c6f2220331e4ffb033)
-rw-r--r-- | nova/api/openstack/wsgi.py | 2 | ||||
-rw-r--r-- | nova/tests/unit/api/openstack/compute/legacy_v2/test_servers.py | 4 | ||||
-rw-r--r-- | nova/tests/unit/api/openstack/compute/test_api.py | 2 | ||||
-rw-r--r-- | nova/tests/unit/api/openstack/test_wsgi.py | 6 |
4 files changed, 7 insertions, 7 deletions
diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index 1c4531cb43..548b469dfb 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -802,7 +802,7 @@ class Resource(wsgi.Application): contents = self.deserialize(meth, content_type, body) except exception.InvalidContentType: msg = _("Unsupported Content-Type") - return Fault(webob.exc.HTTPBadRequest(explanation=msg)) + return Fault(webob.exc.HTTPUnsupportedMediaType(explanation=msg)) except exception.MalformedRequestBody: msg = _("Malformed request body") return Fault(webob.exc.HTTPBadRequest(explanation=msg)) diff --git a/nova/tests/unit/api/openstack/compute/legacy_v2/test_servers.py b/nova/tests/unit/api/openstack/compute/legacy_v2/test_servers.py index 4d67b8ed4c..0a42930f41 100644 --- a/nova/tests/unit/api/openstack/compute/legacy_v2/test_servers.py +++ b/nova/tests/unit/api/openstack/compute/legacy_v2/test_servers.py @@ -1380,7 +1380,7 @@ class ServersControllerUpdateTest(ControllerTest): key="Label"></meta>""" req = self._get_request(body, content_type='xml') res = req.get_response(fakes.wsgi_app()) - self.assertEqual(400, res.status_int) + self.assertEqual(415, res.status_int) def test_update_server_invalid_xml_raises_expat(self): body = """<?xml version="1.0" encoding="UTF-8"?> @@ -1389,7 +1389,7 @@ class ServersControllerUpdateTest(ControllerTest): key="Label"></meta>""" req = self._get_request(body, content_type='xml') res = req.get_response(fakes.wsgi_app()) - self.assertEqual(400, res.status_int) + self.assertEqual(415, res.status_int) def test_update_server_name(self): body = {'server': {'name': 'server_test'}} diff --git a/nova/tests/unit/api/openstack/compute/test_api.py b/nova/tests/unit/api/openstack/compute/test_api.py index 71d1e60fce..1a3b441eb6 100644 --- a/nova/tests/unit/api/openstack/compute/test_api.py +++ b/nova/tests/unit/api/openstack/compute/test_api.py @@ -52,7 +52,7 @@ class APITest(test.NoDBTestCase): req.headers["content-type"] = "application/xml" res = req.get_response(self.wsgi_app) - self.assertEqual(res.status_int, 400) + self.assertEqual(res.status_int, 415) def test_vendor_content_type_json(self): ctype = 'application/vnd.openstack.compute+json' diff --git a/nova/tests/unit/api/openstack/test_wsgi.py b/nova/tests/unit/api/openstack/test_wsgi.py index 1494176a45..66d95eb46c 100644 --- a/nova/tests/unit/api/openstack/test_wsgi.py +++ b/nova/tests/unit/api/openstack/test_wsgi.py @@ -418,9 +418,9 @@ class ResourceTest(test.NoDBTestCase): req.content_type = None req.body = '{"body": {"key": "value"}}' response = req.get_response(app) - expected_unsupported_type_body = {'badRequest': - {'message': 'Unsupported Content-Type', 'code': 400}} - self.assertEqual(response.status_int, 400) + expected_unsupported_type_body = {'badMediaType': + {'message': 'Unsupported Content-Type', 'code': 415}} + self.assertEqual(response.status_int, 415) self.assertEqual(expected_unsupported_type_body, jsonutils.loads(response.body)) |