Use 400 instead of 422 for invalid input in v3 servers core
We return 400 when input is invalid for v3 api. This patch fix this case for servers core. DocImpact Change-Id: If802d4dcba6ed25f7e9cb9d568a3ffd78f0f6c68 Closes-Bug: 1251538
This commit is contained in:
parent
79d0ce6171
commit
3cdc0799fd
|
@ -696,7 +696,7 @@ class ServersController(wsgi.Controller):
|
|||
def create(self, req, body):
|
||||
"""Creates a new server for a given user."""
|
||||
if not self.is_valid_body(body, 'server'):
|
||||
raise exc.HTTPUnprocessableEntity()
|
||||
raise exc.HTTPBadRequest(_("The request body is invalid"))
|
||||
|
||||
context = req.environ['nova.context']
|
||||
server_dict = body['server']
|
||||
|
@ -867,7 +867,7 @@ class ServersController(wsgi.Controller):
|
|||
def update(self, req, id, body):
|
||||
"""Update server then pass on to version-specific controller."""
|
||||
if not self.is_valid_body(body, 'server'):
|
||||
raise exc.HTTPUnprocessableEntity()
|
||||
raise exc.HTTPBadRequest(_("The request body is invalid"))
|
||||
|
||||
ctxt = req.environ['nova.context']
|
||||
update_dict = {}
|
||||
|
|
|
@ -4049,7 +4049,7 @@ class ServersAllExtensionsTestCase(test.TestCase):
|
|||
|
||||
req.body = jsonutils.dumps(body)
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(422, res.status_int)
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
def test_update_missing_server(self):
|
||||
# Test create with malformed body.
|
||||
|
@ -4066,54 +4066,54 @@ class ServersAllExtensionsTestCase(test.TestCase):
|
|||
|
||||
req.body = jsonutils.dumps(body)
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(422, res.status_int)
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
|
||||
class ServersUnprocessableEntityTestCase(test.TestCase):
|
||||
class ServersInvalidRequestTestCase(test.TestCase):
|
||||
"""
|
||||
Tests of places we throw 422 Unprocessable Entity from
|
||||
Tests of places we throw 400 Bad Request from
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(ServersUnprocessableEntityTestCase, self).setUp()
|
||||
super(ServersInvalidRequestTestCase, self).setUp()
|
||||
ext_info = plugins.LoadedExtensionInfo()
|
||||
self.controller = servers.ServersController(extension_info=ext_info)
|
||||
|
||||
def _unprocessable_server_create(self, body):
|
||||
def _invalid_server_create(self, body):
|
||||
req = fakes.HTTPRequestV3.blank('/servers')
|
||||
req.method = 'POST'
|
||||
|
||||
self.assertRaises(webob.exc.HTTPUnprocessableEntity,
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller.create, req, body)
|
||||
|
||||
def test_create_server_no_body(self):
|
||||
self._unprocessable_server_create(body=None)
|
||||
self._invalid_server_create(body=None)
|
||||
|
||||
def test_create_server_missing_server(self):
|
||||
body = {'foo': {'a': 'b'}}
|
||||
self._unprocessable_server_create(body=body)
|
||||
self._invalid_server_create(body=body)
|
||||
|
||||
def test_create_server_malformed_entity(self):
|
||||
body = {'server': 'string'}
|
||||
self._unprocessable_server_create(body=body)
|
||||
self._invalid_server_create(body=body)
|
||||
|
||||
def _unprocessable_server_update(self, body):
|
||||
req = fakes.HTTPRequestV3.blank('/servers/%s' % FAKE_UUID)
|
||||
req.method = 'PUT'
|
||||
|
||||
self.assertRaises(webob.exc.HTTPUnprocessableEntity,
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller.update, req, FAKE_UUID, body)
|
||||
|
||||
def test_update_server_no_body(self):
|
||||
self._unprocessable_server_update(body=None)
|
||||
self._invalid_server_create(body=None)
|
||||
|
||||
def test_update_server_missing_server(self):
|
||||
body = {'foo': {'a': 'b'}}
|
||||
self._unprocessable_server_update(body=body)
|
||||
self._invalid_server_create(body=body)
|
||||
|
||||
def test_create_update_malformed_entity(self):
|
||||
body = {'server': 'string'}
|
||||
self._unprocessable_server_update(body=body)
|
||||
self._invalid_server_create(body=body)
|
||||
|
||||
|
||||
class TestServerRebuildXMLDeserializer(test.NoDBTestCase):
|
||||
|
|
Loading…
Reference in New Issue