Merge "[Linuxbridge] Check if vxlan network MTU can be set"

This commit is contained in:
Zuul 2018-02-22 13:51:04 +00:00 committed by Gerrit Code Review
commit 4c2f666035
3 changed files with 44 additions and 0 deletions

View File

@ -945,6 +945,11 @@ def get_device_mac(device_name, namespace=None):
return IPDevice(device_name, namespace=namespace).link.address
def get_device_mtu(device_name, namespace=None):
"""Return the MTU value of the device."""
return IPDevice(device_name, namespace=namespace).link.mtu
NetworkNamespaceNotFound = privileged.NetworkNamespaceNotFound
NetworkInterfaceNotFound = privileged.NetworkInterfaceNotFound

View File

@ -346,6 +346,21 @@ class LinuxBridgeManager(amb.CommonAgentManagerBase):
args['proxy'] = cfg.CONF.VXLAN.arp_responder
try:
if mtu:
phys_dev_mtu = ip_lib.get_device_mtu(self.local_int)
max_mtu = phys_dev_mtu - constants.VXLAN_ENCAP_OVERHEAD
if mtu > max_mtu:
LOG.error("Provided MTU value %(mtu)s for VNI "
"%(segmentation_id)s is too high. "
"According to physical device %(dev)s "
"MTU=%(phys_mtu)s maximum available "
"MTU is %(max_mtu)s",
{'mtu': mtu,
'segmentation_id': segmentation_id,
'dev': self.local_int,
'phys_mtu': phys_dev_mtu,
'max_mtu': max_mtu})
return None
int_vxlan = self.ip.add_vxlan(interface, segmentation_id,
**args)
if mtu:

View File

@ -377,6 +377,7 @@ class TestLinuxBridgeManager(base.BaseTestCase):
dv6_fn.assert_called_once_with()
def test_ensure_vxlan(self, expected_proxy=False):
physical_mtu = 1500
seg_id = "12345678"
self.lbm.local_int = 'eth0'
self.lbm.vxlan_mode = lconst.VXLAN_MCAST
@ -387,6 +388,8 @@ class TestLinuxBridgeManager(base.BaseTestCase):
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(ip_lib, 'get_device_mtu',
return_value=physical_mtu),\
mock.patch.object(self.lbm.ip, 'add_vxlan',
return_value=vxlan_dev) as add_vxlan_fn:
retval = self.lbm.ensure_vxlan(seg_id, mtu=1450)
@ -435,6 +438,27 @@ class TestLinuxBridgeManager(base.BaseTestCase):
dev=self.lbm.local_int)
dv6_fn.assert_called_once_with()
def test_ensure_vxlan_mtu_too_big(self):
seg_id = "12345678"
physical_mtu = 1500
# Any mtu value which will be higher than physical_mtu - 50 should
# be too big
mtu = 1490
self.lbm.local_int = 'eth0'
self.lbm.vxlan_mode = lconst.VXLAN_MCAST
with mock.patch.object(ip_lib, 'device_exists', return_value=False):
vxlan_dev = FakeIpDevice()
with mock.patch.object(vxlan_dev, 'disable_ipv6') as dv6_fn,\
mock.patch.object(self.lbm.ip, 'add_vxlan',
return_value=vxlan_dev) as add_vxlan_fn,\
mock.patch.object(ip_lib, 'get_device_mtu',
return_value=physical_mtu):
self.assertFalse(
self.lbm.ensure_vxlan(seg_id, mtu=mtu))
add_vxlan_fn.assert_not_called()
dv6_fn.assert_not_called()
def test__update_interface_ip_details(self):
gwdict = dict(gateway='1.1.1.1',
metric=50)