Raise GatewayConflict as BadRequest

neutron GatewayConflictWithAllocationPools exception is raised
as a 500, but it is actually user error, so it should be a 400.
Catch the GatewayConflictWithAllocationPools exception and raise
as a BadRequest with the relevant info.

Change-Id: Id94590c2c8637a64a90f06834c7e3400ea2b6330
JIRA:NCP-1993
Closes-Bug: #1599980
This commit is contained in:
Kyle Haley 2016-07-07 12:56:26 -07:00
parent 7a906e1406
commit 203412773d
2 changed files with 7 additions and 4 deletions

View File

@ -14,6 +14,7 @@
# under the License.
import netaddr
from neutron.common import exceptions as neutron_exc
from neutron import quota
from neutron_lib import exceptions as n_exc
from oslo_config import cfg
@ -71,7 +72,11 @@ def create_route(context, route):
alloc_pools = allocation_pool.AllocationPools(subnet["cidr"],
policies=policies)
alloc_pools.validate_gateway_excluded(route["gateway"])
try:
alloc_pools.validate_gateway_excluded(route["gateway"])
except neutron_exc.GatewayConflictWithAllocationPools as e:
LOG.exception(str(e))
raise n_exc.BadRequest(resource="routes", msg=str(e))
# TODO(anyone): May want to denormalize the cidr values into columns
# to achieve single db lookup on conflict check

View File

@ -15,7 +15,6 @@
import contextlib
import mock
from neutron.common import exceptions as n_exc_ext
from neutron_lib import exceptions as n_exc
from oslo_config import cfg
from quark import exceptions as q_exc
@ -102,8 +101,7 @@ class QuarkCreateRoutes(BaseFunctionalTest):
self.assertIsNotNone(sub)
self.assertIsNotNone(ipp)
create_route["subnet_id"] = sub["id"]
with self.assertRaises(
n_exc_ext.GatewayConflictWithAllocationPools):
with self.assertRaises(n_exc.BadRequest):
routes_api.create_route(self.context,
dict(route=create_route))