Add MTU to Network model and use it in plugging
This adds an MTU field to the network model and has the vif_plug_ovs and vif_plug_linux_bridge drivers check for it before referencing the global config variable. Closes-Bug: #1623876 Change-Id: I327c901a285bca23560f49a921a5d030f7f71cad
This commit is contained in:
parent
20fcd7aef6
commit
f3130fe8e2
|
@ -10,6 +10,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_utils import versionutils
|
||||
from oslo_versionedobjects import base
|
||||
from oslo_versionedobjects import fields
|
||||
|
||||
|
@ -21,7 +22,8 @@ from os_vif.objects import base as osv_base
|
|||
class Network(osv_base.VersionedObject):
|
||||
"""Represents a network."""
|
||||
# Version 1.0: Initial version
|
||||
VERSION = '1.0'
|
||||
# Version 1.1: Added MTU field
|
||||
VERSION = '1.1'
|
||||
|
||||
fields = {
|
||||
'id': fields.UUIDField(),
|
||||
|
@ -33,6 +35,7 @@ class Network(osv_base.VersionedObject):
|
|||
'should_provide_vlan': fields.BooleanField(),
|
||||
'bridge_interface': fields.StringField(nullable=True),
|
||||
'vlan': fields.IntegerField(nullable=True),
|
||||
'mtu': fields.IntegerField(nullable=True),
|
||||
}
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
|
@ -40,4 +43,10 @@ class Network(osv_base.VersionedObject):
|
|||
kwargs.setdefault('multi_host', False)
|
||||
kwargs.setdefault('should_provide_bridge', False)
|
||||
kwargs.setdefault('should_provide_vlan', False)
|
||||
kwargs.setdefault('mtu', None)
|
||||
super(Network, self).__init__(**kwargs)
|
||||
|
||||
def obj_make_compatible(self, primitive, target_version):
|
||||
target_version = versionutils.convert_version_to_tuple(target_version)
|
||||
if target_version < (1, 1):
|
||||
primitive.pop('mtu', None)
|
||||
|
|
|
@ -113,7 +113,7 @@ object_data = {
|
|||
'FixedIP': '1.0-d1a0ec7e7b6ce021a784c54d44cce009',
|
||||
'FixedIPList': '1.0-15ecf022a68ddbb8c2a6739cfc9f8f5e',
|
||||
'InstanceInfo': '1.0-84104d3435046b1a282ac8265ec2a976',
|
||||
'Network': '1.0-14d4787990b079f230423fcc364abf91',
|
||||
'Network': '1.1-27a8a3e236d1d239121668a590130154',
|
||||
'Route': '1.0-5ca049cb82c4d4ec5edb1b839c1429c7',
|
||||
'RouteList': '1.0-15ecf022a68ddbb8c2a6739cfc9f8f5e',
|
||||
'Subnet': '1.0-6a8c192ef7492120d1a5e0fd08e44272',
|
||||
|
|
|
@ -97,7 +97,7 @@ class LinuxBridgePlugin(plugin.PluginBase):
|
|||
if not network.multi_host and network.should_provide_bridge:
|
||||
if network.should_provide_vlan:
|
||||
iface = self.config.vlan_interface or network.bridge_interface
|
||||
mtu = self.config.network_device_mtu
|
||||
mtu = network.mtu or self.config.network_device_mtu
|
||||
linux_net.ensure_vlan_bridge(network.vlan,
|
||||
bridge_name, iface, mtu=mtu)
|
||||
else:
|
||||
|
|
|
@ -87,14 +87,21 @@ class PluginTest(testtools.TestCase):
|
|||
mock_ensure_bridge.assert_called_with("br0", "eth0")
|
||||
self.assertEqual(len(mock_ensure_vlan_bridge.calls), 0)
|
||||
|
||||
def test_plug_bridge_create_br_vlan(self):
|
||||
def test_plug_bridge_create_br_vlan_mtu_in_model(self):
|
||||
self._test_plug_bridge_create_br_vlan(mtu=1234)
|
||||
|
||||
def test_plug_bridge_create_br_vlan_mtu_from_config(self):
|
||||
self._test_plug_bridge_create_br_vlan()
|
||||
|
||||
def _test_plug_bridge_create_br_vlan(self, mtu=None):
|
||||
network = objects.network.Network(
|
||||
id='437c6db5-4e6f-4b43-b64b-ed6a11ee5ba7',
|
||||
bridge='br0',
|
||||
bridge_interface='eth0',
|
||||
vlan=99,
|
||||
should_provide_bridge=True,
|
||||
should_provide_vlan=True)
|
||||
should_provide_vlan=True,
|
||||
mtu=mtu)
|
||||
|
||||
vif = objects.vif.VIFBridge(
|
||||
id='b679325f-ca89-4ee0-a8be-6db1409b69ea',
|
||||
|
@ -112,4 +119,4 @@ class PluginTest(testtools.TestCase):
|
|||
|
||||
self.assertEqual(len(mock_ensure_bridge.calls), 0)
|
||||
mock_ensure_vlan_bridge.assert_called_with(
|
||||
99, "br0", "eth0", mtu=1500)
|
||||
99, "br0", "eth0", mtu=mtu or 1500)
|
||||
|
|
|
@ -83,12 +83,16 @@ class OvsPlugin(plugin.PluginBase):
|
|||
])
|
||||
|
||||
def _create_vif_port(self, vif, vif_name, instance_info, **kwargs):
|
||||
if vif.network and vif.network.mtu:
|
||||
mtu = vif.network.mtu
|
||||
else:
|
||||
mtu = self.config.network_device_mtu
|
||||
linux_net.create_ovs_vif_port(
|
||||
vif.network.bridge,
|
||||
vif_name,
|
||||
vif.port_profile.interface_id,
|
||||
vif.address, instance_info.uuid,
|
||||
self.config.network_device_mtu,
|
||||
mtu,
|
||||
timeout=self.config.ovs_vsctl_timeout,
|
||||
**kwargs)
|
||||
|
||||
|
@ -114,8 +118,11 @@ class OvsPlugin(plugin.PluginBase):
|
|||
linux_net.ensure_bridge(vif.bridge_name)
|
||||
|
||||
if not linux_net.device_exists(v2_name):
|
||||
linux_net.create_veth_pair(v1_name, v2_name,
|
||||
self.config.network_device_mtu)
|
||||
if vif.network and vif.network.mtu:
|
||||
mtu = vif.network.mtu
|
||||
else:
|
||||
mtu = self.config.network_device_mtu
|
||||
linux_net.create_veth_pair(v1_name, v2_name, mtu)
|
||||
linux_net.add_bridge_port(vif.bridge_name, v1_name)
|
||||
linux_net.ensure_ovs_bridge(vif.network.bridge,
|
||||
constants.OVS_DATAPATH_SYSTEM)
|
||||
|
|
|
@ -58,6 +58,13 @@ class PluginTest(testtools.TestCase):
|
|||
subnets=self.subnets,
|
||||
vlan=99)
|
||||
|
||||
self.network_ovs_mtu = objects.network.Network(
|
||||
id='437c6db5-4e6f-4b43-b64b-ed6a11ee5ba7',
|
||||
bridge='br0',
|
||||
subnets=self.subnets,
|
||||
vlan=99,
|
||||
mtu=1234)
|
||||
|
||||
self.profile_ovs = objects.vif.VIFPortProfileOpenVSwitch(
|
||||
interface_id='e65867e0-9340-4a7f-a256-09af6eb7a3aa')
|
||||
|
||||
|
@ -102,6 +109,21 @@ class PluginTest(testtools.TestCase):
|
|||
timeout=plugin.config.ovs_vsctl_timeout,
|
||||
interface_type=constants.OVS_VHOSTUSER_INTERFACE_TYPE)
|
||||
|
||||
@mock.patch.object(linux_net, 'create_ovs_vif_port')
|
||||
def test_create_vif_port_mtu_in_model(self, mock_create_ovs_vif_port):
|
||||
self.vif_ovs.network = self.network_ovs_mtu
|
||||
plugin = ovs.OvsPlugin.load('ovs')
|
||||
plugin._create_vif_port(
|
||||
self.vif_ovs, mock.sentinel.vif_name, self.instance,
|
||||
interface_type=constants.OVS_VHOSTUSER_INTERFACE_TYPE)
|
||||
mock_create_ovs_vif_port.assert_called_once_with(
|
||||
self.vif_ovs.network.bridge, mock.sentinel.vif_name,
|
||||
self.vif_ovs.port_profile.interface_id,
|
||||
self.vif_ovs.address, self.instance.uuid,
|
||||
self.network_ovs_mtu.mtu,
|
||||
timeout=plugin.config.ovs_vsctl_timeout,
|
||||
interface_type=constants.OVS_VHOSTUSER_INTERFACE_TYPE)
|
||||
|
||||
def test_plug_ovs(self):
|
||||
with nested(
|
||||
mock.patch.object(ovs, 'sys'),
|
||||
|
|
Loading…
Reference in New Issue