Use NetworkMTUSubnetConflict from neutron-lib
It was added to neutron-lib. Depends-on: https://review.opendev.org/952978 Change-Id: I82e96063bff82815ec0a529e6139912e2f8e8c84 Signed-off-by: Takashi Kajinami <kajinamit@oss.nttdata.com>
This commit is contained in:
1 parent
0b23123a09
commit
2983babbac
4 files changed
+9
-39
No files matched your search
@@ -63,7 +63,6 @@ from neutron.db import models_v2
|
||||
from neutron.db import rbac_db_mixin as rbac_mixin
|
||||
from neutron.db import rbac_db_models
|
||||
from neutron.db import standardattrdescription_db as stattr_db
|
||||
from neutron.exceptions import mtu as mtu_exc
|
||||
from neutron.extensions import subnetpool_prefix_ops
|
||||
from neutron import ipam
|
||||
from neutron.ipam import exceptions as ipam_exc
|
||||
@@ -550,7 +549,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
|
||||
# at least one subnet present, if below IPv4 minimum we fail early
|
||||
if mtu < constants.IPV4_MIN_MTU:
|
||||
raise mtu_exc.NetworkMTUSubnetConflict(
|
||||
raise exc.NetworkMTUSubnetConflict(
|
||||
net_id=id, mtu=constants.IPV4_MIN_MTU)
|
||||
|
||||
# We do not need to check IPv4 subnets as they will have been
|
||||
@@ -558,7 +557,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
for subnet in subnets:
|
||||
if (subnet.ip_version == constants.IP_VERSION_6 and
|
||||
mtu < constants.IPV6_MIN_MTU):
|
||||
raise mtu_exc.NetworkMTUSubnetConflict(
|
||||
raise exc.NetworkMTUSubnetConflict(
|
||||
net_id=id, mtu=constants.IPV6_MIN_MTU)
|
||||
|
||||
def _ensure_network_not_in_use(self, context, net_id):
|
||||
@@ -831,7 +830,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
|
||||
# if below IPv4 minimum we fail early
|
||||
if mtu < constants.IPV4_MIN_MTU:
|
||||
raise mtu_exc.NetworkMTUSubnetConflict(
|
||||
raise exc.NetworkMTUSubnetConflict(
|
||||
net_id=network.id, mtu=constants.IPV4_MIN_MTU)
|
||||
|
||||
# We do not need to check IPv4 subnets as they will have been
|
||||
@@ -839,7 +838,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
ip_version = subnet.get('ip_version')
|
||||
if (ip_version == constants.IP_VERSION_6 and
|
||||
mtu < constants.IPV6_MIN_MTU):
|
||||
raise mtu_exc.NetworkMTUSubnetConflict(
|
||||
raise exc.NetworkMTUSubnetConflict(
|
||||
net_id=network.id, mtu=constants.IPV6_MIN_MTU)
|
||||
|
||||
def _update_router_gw_ports(self, context, network, subnet):
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
# Copyright (c) 2023 Canonical Ltd.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib import exceptions as e
|
||||
|
||||
from neutron._i18n import _
|
||||
|
||||
|
||||
# TODO(haleyb): Move to n-lib
|
||||
class NetworkMTUSubnetConflict(e.Conflict):
|
||||
"""A conflict error due to MTU being invalid on said network.
|
||||
|
||||
:param net_id: The UUID of the network
|
||||
:param mtu: The minimum MTU required by a subnet for the network
|
||||
"""
|
||||
message = _("MTU of %(net_id)s is not valid, subnet requires a "
|
||||
"minimum of %(mtu)s")
|
||||
@@ -61,7 +61,6 @@ from neutron.db.models import l3 as l3_models
|
||||
from neutron.db.models import securitygroup as sg_models
|
||||
from neutron.db import models_v2
|
||||
from neutron.db import rbac_db_models
|
||||
from neutron.exceptions import mtu as mtu_exc
|
||||
from neutron.ipam.drivers.neutrondb_ipam import driver as ipam_driver
|
||||
from neutron.ipam import exceptions as ipam_exc
|
||||
from neutron.objects import network as network_obj
|
||||
@@ -7308,7 +7307,7 @@ class NeutronDbPluginV2AsMixinTestCase(NeutronDbPluginV2TestCase,
|
||||
|
||||
# This should fail with any subnets present
|
||||
self.net_data['network']['mtu'] = constants.IPV4_MIN_MTU - 1
|
||||
with testlib_api.ExpectedException(mtu_exc.NetworkMTUSubnetConflict):
|
||||
with testlib_api.ExpectedException(lib_exc.NetworkMTUSubnetConflict):
|
||||
self.plugin.update_network(self.context, net['id'], self.net_data)
|
||||
|
||||
def test_update_network_invalid_mtu_ipv4_ipv6(self):
|
||||
@@ -7329,13 +7328,13 @@ class NeutronDbPluginV2AsMixinTestCase(NeutronDbPluginV2TestCase,
|
||||
self.plugin.update_network(self.context, net['id'], self.net_data)
|
||||
|
||||
# These should all fail with both subnets present
|
||||
with testlib_api.ExpectedException(mtu_exc.NetworkMTUSubnetConflict):
|
||||
with testlib_api.ExpectedException(lib_exc.NetworkMTUSubnetConflict):
|
||||
self.net_data['network']['mtu'] = constants.IPV6_MIN_MTU - 1
|
||||
self.plugin.update_network(self.context, net['id'], self.net_data)
|
||||
with testlib_api.ExpectedException(mtu_exc.NetworkMTUSubnetConflict):
|
||||
with testlib_api.ExpectedException(lib_exc.NetworkMTUSubnetConflict):
|
||||
self.net_data['network']['mtu'] = constants.IPV4_MIN_MTU
|
||||
self.plugin.update_network(self.context, net['id'], self.net_data)
|
||||
with testlib_api.ExpectedException(mtu_exc.NetworkMTUSubnetConflict):
|
||||
with testlib_api.ExpectedException(lib_exc.NetworkMTUSubnetConflict):
|
||||
self.net_data['network']['mtu'] = constants.IPV4_MIN_MTU - 1
|
||||
self.plugin.update_network(self.context, net['id'], self.net_data)
|
||||
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ requests>=2.32.3 # Apache-2.0
|
||||
Jinja2>=2.10 # BSD License (3 clause)
|
||||
keystonemiddleware>=5.1.0 # Apache-2.0
|
||||
netaddr>=0.7.18 # BSD
|
||||
neutron-lib>=3.17.0 # Apache-2.0
|
||||
neutron-lib>=3.20.0 # Apache-2.0
|
||||
python-neutronclient>=7.8.0 # Apache-2.0
|
||||
tenacity>=6.0.0 # Apache-2.0
|
||||
SQLAlchemy>=1.4.23 # MIT
|
||||
|
||||
Reference in new issue
Block a user