diff --git a/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py b/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py index 7240322e4cb..3ffe487540e 100644 --- a/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py +++ b/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py @@ -251,9 +251,9 @@ class LinuxBridgeManager(amb.CommonAgentManagerBase): if self.ensure_bridge(bridge_name, interface): return interface - def ensure_vxlan_bridge(self, network_id, segmentation_id): + def ensure_vxlan_bridge(self, network_id, segmentation_id, mtu): """Create a vxlan and bridge unless they already exist.""" - interface = self.ensure_vxlan(segmentation_id) + interface = self.ensure_vxlan(segmentation_id, mtu) if not interface: LOG.error("Failed creating vxlan interface for " "%(segmentation_id)s", @@ -316,7 +316,7 @@ class LinuxBridgeManager(amb.CommonAgentManagerBase): LOG.debug("Done creating subinterface %s", interface) return interface - def ensure_vxlan(self, segmentation_id): + def ensure_vxlan(self, segmentation_id, mtu=None): """Create a vxlan unless it already exists.""" interface = self.get_vxlan_device_name(segmentation_id) if not ip_lib.device_exists(interface): @@ -348,6 +348,8 @@ class LinuxBridgeManager(amb.CommonAgentManagerBase): try: int_vxlan = self.ip.add_vxlan(interface, segmentation_id, **args) + if mtu: + int_vxlan.link.set_mtu(mtu) except RuntimeError: with excutils.save_and_reraise_exception() as ctxt: # perform this check after an attempt rather than before @@ -469,13 +471,14 @@ class LinuxBridgeManager(amb.CommonAgentManagerBase): def ensure_physical_in_bridge(self, network_id, network_type, physical_network, - segmentation_id): + segmentation_id, + mtu): if network_type == constants.TYPE_VXLAN: if self.vxlan_mode == lconst.VXLAN_NONE: LOG.error("Unable to add vxlan interface for network %s", network_id) return - return self.ensure_vxlan_bridge(network_id, segmentation_id) + return self.ensure_vxlan_bridge(network_id, segmentation_id, mtu) # NOTE(nick-ma-z): Obtain mappings of physical bridge and interfaces physical_bridge = self.bridge_mappings.get(physical_network) @@ -534,7 +537,8 @@ class LinuxBridgeManager(amb.CommonAgentManagerBase): elif not self.ensure_physical_in_bridge(network_id, network_type, physical_network, - segmentation_id): + segmentation_id, + mtu): return False if mtu: # <-None with device_details from older neutron servers. # we ensure the MTU here because libvirt does not set the diff --git a/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py b/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py index d9e048cdf17..5223edb1232 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py +++ b/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py @@ -51,6 +51,9 @@ class FakeIpLinkCommand(object): def set_up(self): pass + def set_mtu(self, mtu): + pass + class FakeIpDevice(object): def __init__(self): @@ -80,21 +83,21 @@ class TestLinuxBridge(base.BaseTestCase): def test_ensure_physical_in_bridge_invalid(self): result = self.linux_bridge.ensure_physical_in_bridge( - 'network_id', constants.TYPE_VLAN, 'physnetx', 7) + 'network_id', constants.TYPE_VLAN, 'physnetx', 7, 1450) self.assertFalse(result) def test_ensure_physical_in_bridge_flat(self): with mock.patch.object(self.linux_bridge, 'ensure_flat_bridge') as flat_bridge_func: self.linux_bridge.ensure_physical_in_bridge( - 'network_id', constants.TYPE_FLAT, 'physnet1', None) + 'network_id', constants.TYPE_FLAT, 'physnet1', None, 1450) self.assertTrue(flat_bridge_func.called) def test_ensure_physical_in_bridge_vlan(self): with mock.patch.object(self.linux_bridge, 'ensure_vlan_bridge') as vlan_bridge_func: self.linux_bridge.ensure_physical_in_bridge( - 'network_id', constants.TYPE_VLAN, 'physnet1', 7) + 'network_id', constants.TYPE_VLAN, 'physnet1', 7, 1450) self.assertTrue(vlan_bridge_func.called) def test_ensure_physical_in_bridge_vxlan(self): @@ -102,7 +105,7 @@ class TestLinuxBridge(base.BaseTestCase): with mock.patch.object(self.linux_bridge, 'ensure_vxlan_bridge') as vxlan_bridge_func: self.linux_bridge.ensure_physical_in_bridge( - 'network_id', 'vxlan', 'physnet1', 7) + 'network_id', 'vxlan', 'physnet1', 7, 1450) self.assertTrue(vxlan_bridge_func.called) @@ -383,9 +386,10 @@ class TestLinuxBridgeManager(base.BaseTestCase): de_fn.return_value = False vxlan_dev = FakeIpDevice() with mock.patch.object(vxlan_dev, 'disable_ipv6') as dv6_fn,\ + mock.patch.object(vxlan_dev.link, 'set_mtu') as set_mtu_fn,\ mock.patch.object(self.lbm.ip, 'add_vxlan', return_value=vxlan_dev) as add_vxlan_fn: - retval = self.lbm.ensure_vxlan(seg_id) + retval = self.lbm.ensure_vxlan(seg_id, mtu=1450) self.assertEqual("vxlan-" + seg_id, retval) add_vxlan_fn.assert_called_with("vxlan-" + seg_id, seg_id, group="224.0.0.1", @@ -394,6 +398,7 @@ class TestLinuxBridgeManager(base.BaseTestCase): ttl=None, dev=self.lbm.local_int) dv6_fn.assert_called_once_with() + set_mtu_fn.assert_called_once_with(1450) cfg.CONF.set_override('l2_population', 'True', 'VXLAN') self.assertEqual("vxlan-" + seg_id, self.lbm.ensure_vxlan(seg_id)) @@ -517,18 +522,18 @@ class TestLinuxBridgeManager(base.BaseTestCase): def test_ensure_physical_in_bridge(self): self.assertFalse( self.lbm.ensure_physical_in_bridge("123", constants.TYPE_VLAN, - "phys", "1") + "phys", "1", 1450) ) with mock.patch.object(self.lbm, "ensure_flat_bridge") as flbr_fn: self.assertTrue( self.lbm.ensure_physical_in_bridge("123", constants.TYPE_FLAT, - "physnet1", None) + "physnet1", None, 1450) ) self.assertTrue(flbr_fn.called) with mock.patch.object(self.lbm, "ensure_vlan_bridge") as vlbr_fn: self.assertTrue( self.lbm.ensure_physical_in_bridge("123", constants.TYPE_VLAN, - "physnet1", "1") + "physnet1", "1", 1450) ) self.assertTrue(vlbr_fn.called) @@ -536,14 +541,14 @@ class TestLinuxBridgeManager(base.BaseTestCase): self.lbm.vxlan_mode = lconst.VXLAN_MCAST self.assertTrue( self.lbm.ensure_physical_in_bridge("123", constants.TYPE_VXLAN, - "physnet1", "1") + "physnet1", "1", 1450) ) self.assertTrue(vlbr_fn.called) def test_ensure_physical_in_bridge_with_existed_brq(self): with mock.patch.object(linuxbridge_neutron_agent.LOG, 'error') as log: self.lbm.ensure_physical_in_bridge("123", constants.TYPE_FLAT, - "physnet9", "1") + "physnet9", "1", 1450) self.assertEqual(1, log.call_count) @mock.patch.object(ip_lib, "device_exists", return_value=False)