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:
@@ -14,6 +14,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
|
from neutron.common import exceptions as neutron_exc
|
||||||
from neutron import quota
|
from neutron import quota
|
||||||
from neutron_lib import exceptions as n_exc
|
from neutron_lib import exceptions as n_exc
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
@@ -71,7 +72,11 @@ def create_route(context, route):
|
|||||||
|
|
||||||
alloc_pools = allocation_pool.AllocationPools(subnet["cidr"],
|
alloc_pools = allocation_pool.AllocationPools(subnet["cidr"],
|
||||||
policies=policies)
|
policies=policies)
|
||||||
|
try:
|
||||||
alloc_pools.validate_gateway_excluded(route["gateway"])
|
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
|
# TODO(anyone): May want to denormalize the cidr values into columns
|
||||||
# to achieve single db lookup on conflict check
|
# to achieve single db lookup on conflict check
|
||||||
|
@@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
import contextlib
|
import contextlib
|
||||||
import mock
|
import mock
|
||||||
from neutron.common import exceptions as n_exc_ext
|
|
||||||
from neutron_lib import exceptions as n_exc
|
from neutron_lib import exceptions as n_exc
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from quark import exceptions as q_exc
|
from quark import exceptions as q_exc
|
||||||
@@ -102,8 +101,7 @@ class QuarkCreateRoutes(BaseFunctionalTest):
|
|||||||
self.assertIsNotNone(sub)
|
self.assertIsNotNone(sub)
|
||||||
self.assertIsNotNone(ipp)
|
self.assertIsNotNone(ipp)
|
||||||
create_route["subnet_id"] = sub["id"]
|
create_route["subnet_id"] = sub["id"]
|
||||||
with self.assertRaises(
|
with self.assertRaises(n_exc.BadRequest):
|
||||||
n_exc_ext.GatewayConflictWithAllocationPools):
|
|
||||||
routes_api.create_route(self.context,
|
routes_api.create_route(self.context,
|
||||||
dict(route=create_route))
|
dict(route=create_route))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user