diff --git a/nova/api/openstack/compute/plugins/v3/servers.py b/nova/api/openstack/compute/plugins/v3/servers.py index 3ca78a2787ca..932b275e0159 100644 --- a/nova/api/openstack/compute/plugins/v3/servers.py +++ b/nova/api/openstack/compute/plugins/v3/servers.py @@ -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 = {} diff --git a/nova/tests/api/openstack/compute/plugins/v3/test_servers.py b/nova/tests/api/openstack/compute/plugins/v3/test_servers.py index 0d61bfd5195a..4eb6d5934062 100644 --- a/nova/tests/api/openstack/compute/plugins/v3/test_servers.py +++ b/nova/tests/api/openstack/compute/plugins/v3/test_servers.py @@ -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):