Return 409 instead of 503 when cidr conflict

In create a network in nova-network, we should check
whether it's a conflict cidr ,but we reported 503
service unavailable to user, we should report 409
HTTPConflict.

Closes-Bug: 1541760

Change-Id: I80a07222f44017448d1877d6b821eebe462d9fec
This commit is contained in:
jichenjc 2016-01-26 14:53:34 +08:00
parent dcb63f0498
commit 2d038f79be
3 changed files with 10 additions and 1 deletions

View File

@ -193,6 +193,8 @@ class NetworkController(object):
QUOTAS.commit(context, reservation)
except exception.PolicyNotAuthorized as e:
raise exc.HTTPForbidden(explanation=six.text_type(e))
except exception.CidrConflict as e:
raise exc.HTTPConflict(explanation=e.format_message())
except Exception:
if CONF.enable_network_quota:
QUOTAS.rollback(context, reservation)

View File

@ -138,7 +138,7 @@ class TenantNetworkController(wsgi.Controller):
if CONF.enable_network_quota and reservation:
QUOTAS.commit(context, reservation)
@extensions.expected_errors((400, 403, 503))
@extensions.expected_errors((400, 403, 409, 503))
@validation.schema(schema.create)
def create(self, req, body):
context = req.environ["nova.context"]
@ -179,6 +179,8 @@ class TenantNetworkController(wsgi.Controller):
QUOTAS.commit(context, reservation)
except exception.PolicyNotAuthorized as e:
raise exc.HTTPForbidden(explanation=six.text_type(e))
except exception.CidrConflict as e:
raise exc.HTTPConflict(explanation=e.format_message())
except Exception:
if CONF.enable_network_quota:
QUOTAS.rollback(context, reservation)

View File

@ -223,6 +223,11 @@ class TenantNetworksTestV21(test.NoDBTestCase):
expex = webob.exc.HTTPForbidden
self._test_network_create_exception(ex, expex)
def test_network_create_exception_conflictcidr(self):
ex = exception.CidrConflict(cidr='dummy', other='dummy')
expex = webob.exc.HTTPConflict
self._test_network_create_exception(ex, expex)
def test_network_create_exception_service_unavailable(self):
ex = Exception
expex = webob.exc.HTTPServiceUnavailable