Merge "Change 422 error to 400 error"
This commit is contained in:
commit
5f65586e9d
@ -93,7 +93,7 @@ def _filters(request, attr_info):
|
|||||||
try:
|
try:
|
||||||
result_values.append(convert_to(value))
|
result_values.append(convert_to(value))
|
||||||
except exceptions.InvalidInput as e:
|
except exceptions.InvalidInput as e:
|
||||||
raise webob.exc.HTTPUnprocessableEntity(str(e))
|
raise webob.exc.HTTPBadRequest(str(e))
|
||||||
else:
|
else:
|
||||||
result_values.append(value)
|
result_values.append(value)
|
||||||
if result_values:
|
if result_values:
|
||||||
@ -464,11 +464,11 @@ class Controller(object):
|
|||||||
if is_required and attr not in res_dict:
|
if is_required and attr not in res_dict:
|
||||||
msg = _("Failed to parse request. Required "
|
msg = _("Failed to parse request. Required "
|
||||||
" attribute '%s' not specified") % attr
|
" 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:
|
if not attr_vals['allow_post'] and attr in res_dict:
|
||||||
msg = _("Attribute '%s' not allowed in POST" % attr)
|
msg = _("Attribute '%s' not allowed in POST" % attr)
|
||||||
raise webob.exc.HTTPUnprocessableEntity(msg)
|
raise webob.exc.HTTPBadRequest(msg)
|
||||||
|
|
||||||
if attr_vals['allow_post']:
|
if attr_vals['allow_post']:
|
||||||
res_dict[attr] = res_dict.get(attr,
|
res_dict[attr] = res_dict.get(attr,
|
||||||
@ -477,7 +477,7 @@ class Controller(object):
|
|||||||
for attr, attr_vals in attr_info.iteritems():
|
for attr, attr_vals in attr_info.iteritems():
|
||||||
if attr in res_dict and not attr_vals['allow_put']:
|
if attr in res_dict and not attr_vals['allow_put']:
|
||||||
msg = _("Cannot update read-only attribute %s") % attr
|
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():
|
for attr, attr_vals in attr_info.iteritems():
|
||||||
# Convert values if necessary
|
# Convert values if necessary
|
||||||
@ -498,7 +498,7 @@ class Controller(object):
|
|||||||
msg_dict = dict(attr=attr, reason=res)
|
msg_dict = dict(attr=attr, reason=res)
|
||||||
msg = _("Invalid input for %(attr)s. "
|
msg = _("Invalid input for %(attr)s. "
|
||||||
"Reason: %(reason)s.") % msg_dict
|
"Reason: %(reason)s.") % msg_dict
|
||||||
raise webob.exc.HTTPUnprocessableEntity(msg)
|
raise webob.exc.HTTPBadRequest(msg)
|
||||||
return body
|
return body
|
||||||
|
|
||||||
def _validate_network_tenant_ownership(self, request, resource_item):
|
def _validate_network_tenant_ownership(self, request, resource_item):
|
||||||
|
@ -435,14 +435,14 @@ class JSONV2TestCase(APIv2TestBase):
|
|||||||
data = {'port': {'what': 'who', 'tenant_id': _uuid()}}
|
data = {'port': {'what': 'who', 'tenant_id': _uuid()}}
|
||||||
res = self.api.post_json(_get_path('ports'), data,
|
res = self.api.post_json(_get_path('ports'), data,
|
||||||
expect_errors=True)
|
expect_errors=True)
|
||||||
self.assertEqual(res.status_int, 422)
|
self.assertEqual(res.status_int, 400)
|
||||||
|
|
||||||
def test_create_readonly_attr(self):
|
def test_create_readonly_attr(self):
|
||||||
data = {'network': {'name': 'net1', 'tenant_id': _uuid(),
|
data = {'network': {'name': 'net1', 'tenant_id': _uuid(),
|
||||||
'status': "ACTIVE"}}
|
'status': "ACTIVE"}}
|
||||||
res = self.api.post_json(_get_path('networks'), data,
|
res = self.api.post_json(_get_path('networks'), data,
|
||||||
expect_errors=True)
|
expect_errors=True)
|
||||||
self.assertEqual(res.status_int, 422)
|
self.assertEqual(res.status_int, 400)
|
||||||
|
|
||||||
def test_create_bulk(self):
|
def test_create_bulk(self):
|
||||||
data = {'networks': [{'name': 'net1',
|
data = {'networks': [{'name': 'net1',
|
||||||
@ -473,7 +473,7 @@ class JSONV2TestCase(APIv2TestBase):
|
|||||||
data = {'ports': [{'what': 'who', 'tenant_id': _uuid()}]}
|
data = {'ports': [{'what': 'who', 'tenant_id': _uuid()}]}
|
||||||
res = self.api.post_json(_get_path('ports'), data,
|
res = self.api.post_json(_get_path('ports'), data,
|
||||||
expect_errors=True)
|
expect_errors=True)
|
||||||
self.assertEqual(res.status_int, 422)
|
self.assertEqual(res.status_int, 400)
|
||||||
|
|
||||||
def test_create_bulk_partial_body(self):
|
def test_create_bulk_partial_body(self):
|
||||||
data = {'ports': [{'device_id': 'device_1',
|
data = {'ports': [{'device_id': 'device_1',
|
||||||
@ -481,7 +481,7 @@ class JSONV2TestCase(APIv2TestBase):
|
|||||||
{'tenant_id': _uuid()}]}
|
{'tenant_id': _uuid()}]}
|
||||||
res = self.api.post_json(_get_path('ports'), data,
|
res = self.api.post_json(_get_path('ports'), data,
|
||||||
expect_errors=True)
|
expect_errors=True)
|
||||||
self.assertEqual(res.status_int, 422)
|
self.assertEqual(res.status_int, 400)
|
||||||
|
|
||||||
def test_create_attr_not_specified(self):
|
def test_create_attr_not_specified(self):
|
||||||
net_id = _uuid()
|
net_id = _uuid()
|
||||||
@ -644,7 +644,7 @@ class JSONV2TestCase(APIv2TestBase):
|
|||||||
data = {'network': {'status': "NANANA"}}
|
data = {'network': {'status': "NANANA"}}
|
||||||
res = self.api.put_json(_get_path('networks', id=_uuid()), data,
|
res = self.api.put_json(_get_path('networks', id=_uuid()), data,
|
||||||
expect_errors=True)
|
expect_errors=True)
|
||||||
self.assertEqual(res.status_int, 422)
|
self.assertEqual(res.status_int, 400)
|
||||||
|
|
||||||
|
|
||||||
class V2Views(unittest.TestCase):
|
class V2Views(unittest.TestCase):
|
||||||
|
@ -1254,7 +1254,7 @@ class TestPortsV2(QuantumDbPluginV2TestCase):
|
|||||||
'fixed_ips': []}}
|
'fixed_ips': []}}
|
||||||
port_req = self.new_create_request('ports', data)
|
port_req = self.new_create_request('ports', data)
|
||||||
res = port_req.get_response(self.api)
|
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):
|
def test_default_allocation_expiration(self):
|
||||||
cfg.CONF.set_override('dhcp_lease_duration', 120)
|
cfg.CONF.set_override('dhcp_lease_duration', 120)
|
||||||
@ -1641,7 +1641,7 @@ class TestNetworksV2(QuantumDbPluginV2TestCase):
|
|||||||
req = self.new_list_request('networks',
|
req = self.new_list_request('networks',
|
||||||
params='admin_state_up=fake')
|
params='admin_state_up=fake')
|
||||||
res = req.get_response(self.api)
|
res = req.get_response(self.api)
|
||||||
self.assertEquals(422, res.status_int)
|
self.assertEquals(400, res.status_int)
|
||||||
|
|
||||||
def test_show_network(self):
|
def test_show_network(self):
|
||||||
with self.network(name='net1') as net:
|
with self.network(name='net1') as net:
|
||||||
@ -2025,12 +2025,12 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
|
|||||||
allocation_pools=allocation_pools)
|
allocation_pools=allocation_pools)
|
||||||
self.assertEquals(ctx_manager.exception.code, 400)
|
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'
|
cidr = '10.0.0.0/24'
|
||||||
with self.assertRaises(webob.exc.HTTPClientError) as ctx_manager:
|
with self.assertRaises(webob.exc.HTTPClientError) as ctx_manager:
|
||||||
self._test_create_subnet(cidr=cidr,
|
self._test_create_subnet(cidr=cidr,
|
||||||
shared=True)
|
shared=True)
|
||||||
self.assertEquals(ctx_manager.exception.code, 422)
|
self.assertEquals(ctx_manager.exception.code, 400)
|
||||||
|
|
||||||
def test_create_subnet_inconsistent_ipv6_cidrv4(self):
|
def test_create_subnet_inconsistent_ipv6_cidrv4(self):
|
||||||
with self.network() as network:
|
with self.network() as network:
|
||||||
@ -2120,14 +2120,14 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
|
|||||||
self.assertEqual(res['subnet']['gateway_ip'],
|
self.assertEqual(res['subnet']['gateway_ip'],
|
||||||
data['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.network(shared=True) as network:
|
||||||
with self.subnet(network=network) as subnet:
|
with self.subnet(network=network) as subnet:
|
||||||
data = {'subnet': {'shared': True}}
|
data = {'subnet': {'shared': True}}
|
||||||
req = self.new_update_request('subnets', data,
|
req = self.new_update_request('subnets', data,
|
||||||
subnet['subnet']['id'])
|
subnet['subnet']['id'])
|
||||||
res = req.get_response(self.api)
|
res = req.get_response(self.api)
|
||||||
self.assertEqual(res.status_int, 422)
|
self.assertEqual(res.status_int, 400)
|
||||||
|
|
||||||
def test_update_subnet_inconsistent_ipv4_gatewayv6(self):
|
def test_update_subnet_inconsistent_ipv4_gatewayv6(self):
|
||||||
with self.network() as network:
|
with self.network() as network:
|
||||||
@ -2263,7 +2263,7 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
|
|||||||
|
|
||||||
subnet_req = self.new_create_request('subnets', data)
|
subnet_req = self.new_create_request('subnets', data)
|
||||||
res = subnet_req.get_response(self.api)
|
res = subnet_req.get_response(self.api)
|
||||||
self.assertEquals(res.status_int, 422)
|
self.assertEquals(res.status_int, 400)
|
||||||
|
|
||||||
def test_invalid_subnet(self):
|
def test_invalid_subnet(self):
|
||||||
with self.network() as network:
|
with self.network() as network:
|
||||||
@ -2275,7 +2275,7 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
|
|||||||
|
|
||||||
subnet_req = self.new_create_request('subnets', data)
|
subnet_req = self.new_create_request('subnets', data)
|
||||||
res = subnet_req.get_response(self.api)
|
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):
|
def test_invalid_ip_address(self):
|
||||||
with self.network() as network:
|
with self.network() as network:
|
||||||
@ -2287,7 +2287,7 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
|
|||||||
|
|
||||||
subnet_req = self.new_create_request('subnets', data)
|
subnet_req = self.new_create_request('subnets', data)
|
||||||
res = subnet_req.get_response(self.api)
|
res = subnet_req.get_response(self.api)
|
||||||
self.assertEquals(res.status_int, 422)
|
self.assertEquals(res.status_int, 400)
|
||||||
|
|
||||||
def test_invalid_uuid(self):
|
def test_invalid_uuid(self):
|
||||||
with self.network() as network:
|
with self.network() as network:
|
||||||
@ -2299,7 +2299,7 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
|
|||||||
|
|
||||||
subnet_req = self.new_create_request('subnets', data)
|
subnet_req = self.new_create_request('subnets', data)
|
||||||
res = subnet_req.get_response(self.api)
|
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):
|
def test_create_subnet_with_one_dns(self):
|
||||||
gateway_ip = '10.0.0.1'
|
gateway_ip = '10.0.0.1'
|
||||||
|
@ -785,23 +785,23 @@ class L3NatDBTestCase(test_db_plugin.QuantumDbPluginV2TestCase):
|
|||||||
private_sub['subnet']['id'],
|
private_sub['subnet']['id'],
|
||||||
None)
|
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
|
# API-level test - no need to create all objects for l3 plugin
|
||||||
res = self._create_floatingip('json', 'iamnotanuuid',
|
res = self._create_floatingip('json', 'iamnotanuuid',
|
||||||
utils.str_uuid(), '192.168.0.1')
|
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
|
# API-level test - no need to create all objects for l3 plugin
|
||||||
res = self._create_floatingip('json', utils.str_uuid(),
|
res = self._create_floatingip('json', utils.str_uuid(),
|
||||||
'iamnotanuuid', '192.168.0.1')
|
'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
|
# API-level test - no need to create all objects for l3 plugin
|
||||||
res = self._create_floatingip('json', utils.str_uuid(),
|
res = self._create_floatingip('json', utils.str_uuid(),
|
||||||
utils.str_uuid(), 'iamnotnanip')
|
utils.str_uuid(), 'iamnotnanip')
|
||||||
self.assertEqual(res.status_int, 422)
|
self.assertEqual(res.status_int, 400)
|
||||||
|
|
||||||
def test_list_nets_external(self):
|
def test_list_nets_external(self):
|
||||||
with self.network() as n1:
|
with self.network() as n1:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user