From: Nachi Ueno Date: Sun, 9 Sep 2012 04:58:07 +0000 (+0000) Subject: Change 422 error to 400 error X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=255552cb7bf4dd5849791a7c88cda709f6ce829d;p=openstack-build%2Fneutron-build.git Change 422 error to 400 error Fixes bug 1046956 For error code consistency, change 422 error to 400 error Change-Id: I1d150c883e204af8a32de61f91392a46d8397ae1 --- diff --git a/quantum/api/v2/base.py b/quantum/api/v2/base.py index 519f6b67e..c23bcd119 100644 --- a/quantum/api/v2/base.py +++ b/quantum/api/v2/base.py @@ -93,7 +93,7 @@ def _filters(request, attr_info): try: result_values.append(convert_to(value)) except exceptions.InvalidInput as e: - raise webob.exc.HTTPUnprocessableEntity(str(e)) + raise webob.exc.HTTPBadRequest(str(e)) else: result_values.append(value) if result_values: @@ -464,11 +464,11 @@ class Controller(object): if is_required and attr not in res_dict: msg = _("Failed to parse request. Required " " attribute '%s' not specified") % attr - raise webob.exc.HTTPUnprocessableEntity(msg) + raise webob.exc.HTTPBadRequest(msg) if not attr_vals['allow_post'] and attr in res_dict: msg = _("Attribute '%s' not allowed in POST" % attr) - raise webob.exc.HTTPUnprocessableEntity(msg) + raise webob.exc.HTTPBadRequest(msg) if attr_vals['allow_post']: res_dict[attr] = res_dict.get(attr, @@ -477,7 +477,7 @@ class Controller(object): for attr, attr_vals in attr_info.iteritems(): if attr in res_dict and not attr_vals['allow_put']: msg = _("Cannot update read-only attribute %s") % attr - raise webob.exc.HTTPUnprocessableEntity(msg) + raise webob.exc.HTTPBadRequest(msg) for attr, attr_vals in attr_info.iteritems(): # Convert values if necessary @@ -498,7 +498,7 @@ class Controller(object): msg_dict = dict(attr=attr, reason=res) msg = _("Invalid input for %(attr)s. " "Reason: %(reason)s.") % msg_dict - raise webob.exc.HTTPUnprocessableEntity(msg) + raise webob.exc.HTTPBadRequest(msg) return body def _validate_network_tenant_ownership(self, request, resource_item): diff --git a/quantum/tests/unit/test_api_v2.py b/quantum/tests/unit/test_api_v2.py index 6e271385b..5fcc0b818 100644 --- a/quantum/tests/unit/test_api_v2.py +++ b/quantum/tests/unit/test_api_v2.py @@ -435,14 +435,14 @@ class JSONV2TestCase(APIv2TestBase): data = {'port': {'what': 'who', 'tenant_id': _uuid()}} res = self.api.post_json(_get_path('ports'), data, expect_errors=True) - self.assertEqual(res.status_int, 422) + self.assertEqual(res.status_int, 400) def test_create_readonly_attr(self): data = {'network': {'name': 'net1', 'tenant_id': _uuid(), 'status': "ACTIVE"}} res = self.api.post_json(_get_path('networks'), data, expect_errors=True) - self.assertEqual(res.status_int, 422) + self.assertEqual(res.status_int, 400) def test_create_bulk(self): data = {'networks': [{'name': 'net1', @@ -473,7 +473,7 @@ class JSONV2TestCase(APIv2TestBase): data = {'ports': [{'what': 'who', 'tenant_id': _uuid()}]} res = self.api.post_json(_get_path('ports'), data, expect_errors=True) - self.assertEqual(res.status_int, 422) + self.assertEqual(res.status_int, 400) def test_create_bulk_partial_body(self): data = {'ports': [{'device_id': 'device_1', @@ -481,7 +481,7 @@ class JSONV2TestCase(APIv2TestBase): {'tenant_id': _uuid()}]} res = self.api.post_json(_get_path('ports'), data, expect_errors=True) - self.assertEqual(res.status_int, 422) + self.assertEqual(res.status_int, 400) def test_create_attr_not_specified(self): net_id = _uuid() @@ -644,7 +644,7 @@ class JSONV2TestCase(APIv2TestBase): data = {'network': {'status': "NANANA"}} res = self.api.put_json(_get_path('networks', id=_uuid()), data, expect_errors=True) - self.assertEqual(res.status_int, 422) + self.assertEqual(res.status_int, 400) class V2Views(unittest.TestCase): diff --git a/quantum/tests/unit/test_db_plugin.py b/quantum/tests/unit/test_db_plugin.py index 1595ef753..814570e70 100644 --- a/quantum/tests/unit/test_db_plugin.py +++ b/quantum/tests/unit/test_db_plugin.py @@ -1254,7 +1254,7 @@ class TestPortsV2(QuantumDbPluginV2TestCase): 'fixed_ips': []}} port_req = self.new_create_request('ports', data) res = port_req.get_response(self.api) - self.assertEquals(res.status_int, 422) + self.assertEquals(res.status_int, 400) def test_default_allocation_expiration(self): cfg.CONF.set_override('dhcp_lease_duration', 120) @@ -1641,7 +1641,7 @@ class TestNetworksV2(QuantumDbPluginV2TestCase): req = self.new_list_request('networks', params='admin_state_up=fake') res = req.get_response(self.api) - self.assertEquals(422, res.status_int) + self.assertEquals(400, res.status_int) def test_show_network(self): with self.network(name='net1') as net: @@ -2025,12 +2025,12 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase): allocation_pools=allocation_pools) self.assertEquals(ctx_manager.exception.code, 400) - def test_create_subnet_shared_returns_422(self): + def test_create_subnet_shared_returns_400(self): cidr = '10.0.0.0/24' with self.assertRaises(webob.exc.HTTPClientError) as ctx_manager: self._test_create_subnet(cidr=cidr, shared=True) - self.assertEquals(ctx_manager.exception.code, 422) + self.assertEquals(ctx_manager.exception.code, 400) def test_update_subnet(self): with self.subnet() as subnet: @@ -2041,14 +2041,14 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase): self.assertEqual(res['subnet']['gateway_ip'], data['subnet']['gateway_ip']) - def test_update_subnet_shared_returns_422(self): + def test_update_subnet_shared_returns_400(self): with self.network(shared=True) as network: with self.subnet(network=network) as subnet: data = {'subnet': {'shared': True}} req = self.new_update_request('subnets', data, subnet['subnet']['id']) res = req.get_response(self.api) - self.assertEqual(res.status_int, 422) + self.assertEqual(res.status_int, 400) def test_show_subnet(self): with self.network() as network: @@ -2131,7 +2131,7 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase): subnet_req = self.new_create_request('subnets', data) res = subnet_req.get_response(self.api) - self.assertEquals(res.status_int, 422) + self.assertEquals(res.status_int, 400) def test_invalid_subnet(self): with self.network() as network: @@ -2143,7 +2143,7 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase): subnet_req = self.new_create_request('subnets', data) res = subnet_req.get_response(self.api) - self.assertEquals(res.status_int, 422) + self.assertEquals(res.status_int, 400) def test_invalid_ip_address(self): with self.network() as network: @@ -2155,7 +2155,7 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase): subnet_req = self.new_create_request('subnets', data) res = subnet_req.get_response(self.api) - self.assertEquals(res.status_int, 422) + self.assertEquals(res.status_int, 400) def test_invalid_uuid(self): with self.network() as network: @@ -2167,7 +2167,7 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase): subnet_req = self.new_create_request('subnets', data) res = subnet_req.get_response(self.api) - self.assertEquals(res.status_int, 422) + self.assertEquals(res.status_int, 400) def test_create_subnet_with_one_dns(self): gateway_ip = '10.0.0.1' diff --git a/quantum/tests/unit/test_l3_plugin.py b/quantum/tests/unit/test_l3_plugin.py index f22f90b72..b96dffe03 100644 --- a/quantum/tests/unit/test_l3_plugin.py +++ b/quantum/tests/unit/test_l3_plugin.py @@ -785,23 +785,23 @@ class L3NatDBTestCase(test_db_plugin.QuantumDbPluginV2TestCase): private_sub['subnet']['id'], None) - def test_create_floatingip_invalid_floating_network_id_returns_422(self): + def test_create_floatingip_invalid_floating_network_id_returns_400(self): # API-level test - no need to create all objects for l3 plugin res = self._create_floatingip('json', 'iamnotanuuid', utils.str_uuid(), '192.168.0.1') - self.assertEqual(res.status_int, 422) + self.assertEqual(res.status_int, 400) - def test_create_floatingip_invalid_floating_port_id_returns_422(self): + def test_create_floatingip_invalid_floating_port_id_returns_400(self): # API-level test - no need to create all objects for l3 plugin res = self._create_floatingip('json', utils.str_uuid(), 'iamnotanuuid', '192.168.0.1') - self.assertEqual(res.status_int, 422) + self.assertEqual(res.status_int, 400) - def test_create_floatingip_invalid_fixed_ip_address_returns_422(self): + def test_create_floatingip_invalid_fixed_ip_address_returns_400(self): # API-level test - no need to create all objects for l3 plugin res = self._create_floatingip('json', utils.str_uuid(), utils.str_uuid(), 'iamnotnanip') - self.assertEqual(res.status_int, 422) + self.assertEqual(res.status_int, 400) def test_list_nets_external(self): with self.network() as n1: