From 44670135be0640622bf6ab74552aa4a9efd21b0c Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Thu, 8 May 2014 14:48:50 -0700 Subject: [PATCH] Use mtu setting from table instead of flag Adds mtu to argument lists of key methods and configuration of vlan interface. Also adds deprecation notice to the "help" info for the file based network_device_mtu configuration property. Partially-implements blueprint better-support-for-multiple-networks Change-Id: Ia401eb95ce8c81d104e59b0348e3474655b9a992 --- nova/network/linux_net.py | 25 ++++++++++++++++--------- nova/objects/network.py | 3 ++- nova/tests/network/test_linux_net.py | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/nova/network/linux_net.py b/nova/network/linux_net.py index c75a364c352..b5451b8cafd 100644 --- a/nova/network/linux_net.py +++ b/nova/network/linux_net.py @@ -1269,12 +1269,14 @@ def _ip_bridge_cmd(action, params, device): return cmd -def _set_device_mtu(dev): +def _set_device_mtu(dev, mtu=None): """Set the device MTU.""" - if CONF.network_device_mtu: + if not mtu: + mtu = CONF.network_device_mtu + if mtu: utils.execute('ip', 'link', 'set', dev, 'mtu', - CONF.network_device_mtu, run_as_root=True, + mtu, run_as_root=True, check_exit_code=[0, 2, 254]) @@ -1418,7 +1420,8 @@ def plug(self, network, mac_address, gateway=True): network['bridge'], iface, network, - mac_address) + mac_address, + network.get('mtu')) iface = 'vlan%s' % vlan else: iface = CONF.flat_interface or network['bridge_interface'] @@ -1455,10 +1458,12 @@ def get_dev(self, network): @staticmethod def ensure_vlan_bridge(vlan_num, bridge, bridge_interface, - net_attrs=None, mac_address=None): + net_attrs=None, mac_address=None, + mtu=None): """Create a vlan and bridge unless they already exist.""" interface = LinuxBridgeInterfaceDriver.ensure_vlan(vlan_num, - bridge_interface, mac_address) + bridge_interface, mac_address, + mtu) LinuxBridgeInterfaceDriver.ensure_bridge(bridge, interface, net_attrs) return interface @@ -1470,7 +1475,7 @@ def remove_vlan_bridge(vlan_num, bridge): @staticmethod @utils.synchronized('lock_vlan', external=True) - def ensure_vlan(vlan_num, bridge_interface, mac_address=None): + def ensure_vlan(vlan_num, bridge_interface, mac_address=None, mtu=None): """Create a vlan unless it already exists.""" interface = 'vlan%s' % vlan_num if not device_exists(interface): @@ -1487,7 +1492,9 @@ def ensure_vlan(vlan_num, bridge_interface, mac_address=None): check_exit_code=[0, 2, 254]) _execute('ip', 'link', 'set', interface, 'up', run_as_root=True, check_exit_code=[0, 2, 254]) - _set_device_mtu(interface) + # NOTE(vish): set mtu every time to ensure that changes to mtu get + # propogated + _set_device_mtu(interface, mtu) return interface @staticmethod @@ -1698,7 +1705,7 @@ def plug(self, network, mac_address, gateway=True): 'external-ids:attached-mac=%s' % mac_address]) _execute('ip', 'link', 'set', dev, 'address', mac_address, run_as_root=True) - _set_device_mtu(dev) + _set_device_mtu(dev, network.get('mtu')) _execute('ip', 'link', 'set', dev, 'up', run_as_root=True) if not gateway: # If we weren't instructed to act as a gateway then add the diff --git a/nova/objects/network.py b/nova/objects/network.py index fbf0e1347c3..32baed9eb00 100644 --- a/nova/objects/network.py +++ b/nova/objects/network.py @@ -31,7 +31,8 @@ 'for DHCP will be added on each nova-network node which ' 'is only visible to the vms on the same host.'), cfg.IntOpt('network_device_mtu', - help='MTU setting for network interface'), + help='DEPRECATED: THIS VALUE SHOULD BE SET WHEN CREATING THE ' + 'NETWORK. MTU setting for network interface.'), ] CONF = cfg.CONF diff --git a/nova/tests/network/test_linux_net.py b/nova/tests/network/test_linux_net.py index 0135a4ae47e..5691b83dded 100644 --- a/nova/tests/network/test_linux_net.py +++ b/nova/tests/network/test_linux_net.py @@ -520,7 +520,7 @@ def test_vlan_override(self): info = {} @staticmethod - def test_ensure(vlan, bridge, interface, network, mac_address): + def test_ensure(vlan, bridge, interface, network, mac_address, mtu): info['passed_interface'] = interface self.stubs.Set(linux_net.LinuxBridgeInterfaceDriver,