]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Change 422 error to 400 error
authorNachi Ueno <nachi@nttmcl.com>
Sun, 9 Sep 2012 04:58:07 +0000 (04:58 +0000)
committerNachi Ueno <nachi@nttmcl.com>
Sun, 9 Sep 2012 04:58:07 +0000 (04:58 +0000)
Fixes bug 1046956
For error code consistency, change 422 error to 400 error

Change-Id: I1d150c883e204af8a32de61f91392a46d8397ae1

quantum/api/v2/base.py
quantum/tests/unit/test_api_v2.py
quantum/tests/unit/test_db_plugin.py
quantum/tests/unit/test_l3_plugin.py

index 519f6b67eb8696a3aab185a5d196e03a03afa068..c23bcd11942b96bff55467e440cb52b8906b5ebf 100644 (file)
@@ -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):
index 6e271385b59d652d1b3da42bd5636994537542e9..5fcc0b818f4f33fb82728aeb66be59538ff9134e 100644 (file)
@@ -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):
index 1595ef7533263f76d53225710d43e01d51018b34..814570e70e339b34cf1cb39052714f7f5e00e8ff 100644 (file)
@@ -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'
index f22f90b72c31bf01ff37be3592f5ff0b3bdf2e72..b96dffe03f19c8cda00420d9c5bd271659906586 100644 (file)
@@ -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: