From 006113e3bfd566f3b394580262a60345eec160d6 Mon Sep 17 00:00:00 2001 From: Reedip Date: Fri, 1 Sep 2017 06:20:01 +0000 Subject: [PATCH] Skip MTU check during deletion of Networks MTU check can be skipped during deletion of Networks. The MTU check doesn't provide any additional support during deletion of the networks. Also, if a network is created with MTU 'X' and the global_mtu later on is decreased to 'Y', the created network cannot be deleted due to the MTU check. Change-Id: Ia838d2a661c5098f90b58b2cb31557f2ebf78868 Closes-Bug: #1713499 --- neutron/plugins/ml2/plugin.py | 3 +- neutron/tests/fullstack/resources/client.py | 12 +++- neutron/tests/fullstack/resources/config.py | 1 + .../tests/fullstack/resources/environment.py | 6 +- neutron/tests/fullstack/test_mtu.py | 61 +++++++++++++++++++ 5 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 neutron/tests/fullstack/test_mtu.py diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index 9f5dbeb225c..2e1bcfe414f 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -1937,7 +1937,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, # change in segments could affect resulting network mtu, so let's # recalculate it network_db = self._get_network(context, network_id) - network_db.mtu = self._get_network_mtu(network_db) + network_db.mtu = self._get_network_mtu(network_db, + validate=(event != events.PRECOMMIT_DELETE)) network_db.save(session=context.session) try: diff --git a/neutron/tests/fullstack/resources/client.py b/neutron/tests/fullstack/resources/client.py index b6a43024484..4e21fe7c464 100644 --- a/neutron/tests/fullstack/resources/client.py +++ b/neutron/tests/fullstack/resources/client.py @@ -57,6 +57,11 @@ class ClientFixture(fixtures.Fixture): resp = update(id, body=body) return resp[resource_type] + def _delete_resource(self, resource_type, id): + delete = getattr(self.client, 'delete_%s' % resource_type) + + return delete(id) + def create_router(self, tenant_id, name=None, ha=False, external_network=None): resource_type = 'router' @@ -70,7 +75,7 @@ class ClientFixture(fixtures.Fixture): def create_network(self, tenant_id, name=None, external=False, network_type=None, segmentation_id=None, - physical_network=None): + physical_network=None, mtu=None): resource_type = 'network' name = name or utils.get_rand_name(prefix=resource_type) @@ -83,12 +88,17 @@ class ClientFixture(fixtures.Fixture): spec['provider:network_type'] = network_type if physical_network is not None: spec['provider:physical_network'] = physical_network + if mtu is not None: + spec['mtu'] = mtu return self._create_resource(resource_type, spec) def update_network(self, id, **kwargs): return self._update_resource('network', id, kwargs) + def delete_network(self, id): + return self._delete_resource('network', id) + def create_subnet(self, tenant_id, network_id, cidr, gateway_ip=None, name=None, enable_dhcp=True, ipv6_address_mode='slaac', ipv6_ra_mode='slaac'): diff --git a/neutron/tests/fullstack/resources/config.py b/neutron/tests/fullstack/resources/config.py index db601ae2c81..38e7aeb5083 100644 --- a/neutron/tests/fullstack/resources/config.py +++ b/neutron/tests/fullstack/resources/config.py @@ -61,6 +61,7 @@ class NeutronConfigFixture(ConfigFixture): 'service_plugins': env_desc.service_plugins, 'auth_strategy': 'noauth', 'debug': 'True', + 'global_physnet_mtu': env_desc.global_mtu, 'agent_down_time': str(env_desc.agent_down_time), 'transport_url': 'rabbit://%(user)s:%(password)s@%(host)s:5672/%(vhost)s' % diff --git a/neutron/tests/fullstack/resources/environment.py b/neutron/tests/fullstack/resources/environment.py index 3f58dc92f66..71192c1c058 100644 --- a/neutron/tests/fullstack/resources/environment.py +++ b/neutron/tests/fullstack/resources/environment.py @@ -18,6 +18,7 @@ from neutronclient.common import exceptions as nc_exc from oslo_config import cfg from neutron.agent.linux import ip_lib +from neutron.common import constants as common_const from neutron.common import utils as common_utils from neutron.plugins.ml2.drivers.linuxbridge.agent import \ linuxbridge_neutron_agent as lb_agent @@ -36,7 +37,8 @@ class EnvironmentDescription(object): def __init__(self, network_type='vxlan', l2_pop=True, qos=False, mech_drivers='openvswitch,linuxbridge', service_plugins='router', arp_responder=False, - agent_down_time=75, router_scheduler=None): + agent_down_time=75, router_scheduler=None, + global_mtu=common_const.DEFAULT_NETWORK_MTU): self.network_type = network_type self.l2_pop = l2_pop self.qos = qos @@ -45,7 +47,7 @@ class EnvironmentDescription(object): self.arp_responder = arp_responder self.agent_down_time = agent_down_time self.router_scheduler = router_scheduler - + self.global_mtu = global_mtu self.service_plugins = service_plugins if self.qos: self.service_plugins += ',qos' diff --git a/neutron/tests/fullstack/test_mtu.py b/neutron/tests/fullstack/test_mtu.py new file mode 100644 index 00000000000..87604b3015c --- /dev/null +++ b/neutron/tests/fullstack/test_mtu.py @@ -0,0 +1,61 @@ +# Copyright 2017 NEC India +# +# 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 neutronclient.common import exceptions +from oslo_utils import uuidutils + +from neutron.tests.fullstack import base +from neutron.tests.fullstack.resources import environment +from neutron.tests.unit import testlib_api + +load_tests = testlib_api.module_load_tests + + +class MTUNetworkTestSetup(base.BaseFullStackTestCase): + host_desc = [] # No need to register agents for this test case + + def setUp(self): + env = environment.Environment( + environment.EnvironmentDescription(), + self.host_desc) + super(MTUNetworkTestSetup, self).setUp(env) + + self.tenant_id = uuidutils.generate_uuid() + + def _restart_neutron_server(self, global_mtu): + env = environment.Environment( + environment.EnvironmentDescription(global_mtu=global_mtu), + self.host_desc) + env.test_name = self.get_name() + self.useFixture(env) + env.neutron_server.restart() + + +class TestMTUScenarios(MTUNetworkTestSetup): + + def test_mtu_update_delete_network(self): + network = self.safe_client.create_network(self.tenant_id, + name='mtu-test-network', + mtu=1450) + self.safe_client.update_network(network['id'], mtu=9000) + res = self.safe_client.delete_network(network['id']) + self.assertEqual((), res) + + def test_global_physnet_mtu_update_delete_network(self): + network = self.safe_client.create_network(self.tenant_id, + name='mtu-test-network', + mtu=1450) + self._restart_neutron_server(1400) + res = self.safe_client.delete_network(network['id']) + self.assertEqual((), res)