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 a7019a87ba)
This commit is contained in:
Brandon Irizarry 2016-04-13 05:18:25 +00:00 committed by ghanshyam
parent 6fdf1c87b1
commit f6f0d1bae8
4 changed files with 7 additions and 7 deletions

View File

@ -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))

View File

@ -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'}}

View File

@ -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'

View File

@ -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))