Skip to content

Commit

Permalink
Override MTU for os_vif attachments
Browse files Browse the repository at this point in the history
os-vif does not current respect the neutron provided mtu, it just uses
the configuration inside os-vif. This is a big regression from mitaka
and liberty.

Long term, this is something os-vif will be able to do by correctly
parsing and acting on the network info. For now we just set the mtu for
a second time once os-vif has done what it wants to do.

Closes-Bug: #1623876

Change-Id: Id4ca38fa1bb84f8cdb5edcd9ccb7acd8c8e9b60c
  • Loading branch information
John Garbutt authored and Matt Riedemann committed Sep 16, 2016
1 parent 6228068 commit 77f5466
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
38 changes: 38 additions & 0 deletions nova/tests/unit/virt/libvirt/test_vif.py
Expand Up @@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.

import copy
import os

import fixtures
Expand Down Expand Up @@ -1598,3 +1599,40 @@ def test_config_os_vif_ovs_hybrid(self, mock_convert_vif,
<filterref
filter="nova-instance-instance-00000001-22522562e2aa"/>
</interface>""", cfg.to_xml())

@mock.patch('nova.network.linux_net._set_device_mtu')
@mock.patch("nova.network.os_vif_util.nova_to_osvif_instance")
@mock.patch("nova.network.os_vif_util.nova_to_osvif_vif")
@mock.patch.object(os_vif, "plug")
def test_plug_ovs_vif_no_mtu(self, mock_plug,
mock_convert_vif, mock_convert_inst,
mock_set_mtu):
mock_convert_vif.return_value = self.os_vif_bridge
mock_convert_inst.return_value = self.os_vif_inst_info

d = vif.LibvirtGenericVIFDriver()
# Hack the network mtu in the vif_bridge object - make sure to copy it
# so we don't change state on a global object during a test run.
vif_bridge = copy.deepcopy(self.vif_bridge)
vif_bridge['network']._set_meta({'mtu': None})
d.plug(self.instance, vif_bridge)

self.assertFalse(mock_set_mtu.called)

@mock.patch('nova.network.linux_net._set_device_mtu')
@mock.patch("nova.network.os_vif_util.nova_to_osvif_instance")
@mock.patch("nova.network.os_vif_util.nova_to_osvif_vif")
@mock.patch.object(os_vif, "plug")
def test_plug_ovs_vif_mtu(self, mock_plug,
mock_convert_vif, mock_convert_inst,
mock_set_mtu):
mock_convert_vif.return_value = self.os_vif_ovs
mock_convert_inst.return_value = self.os_vif_inst_info

d = vif.LibvirtGenericVIFDriver()
d.plug(self.instance, self.vif_ovs)

mock_set_mtu.assert_any_call("br0", 1000)
mock_set_mtu.assert_any_call("qvbdc065497-3c", 1000)
mock_set_mtu.assert_any_call("qvodc065497-3c", 1000)
self.assertEqual(3, mock_set_mtu.call_count)
20 changes: 18 additions & 2 deletions nova/virt/libvirt/vif.py
Expand Up @@ -772,7 +772,7 @@ def plug_vrouter(self, instance, vif):
except processutils.ProcessExecutionError:
LOG.exception(_LE("Failed while plugging vif"), instance=instance)

def _plug_os_vif(self, instance, vif):
def _plug_os_vif(self, instance, vif, raw_vif):
instance_info = os_vif_util.nova_to_osvif_instance(instance)

try:
Expand All @@ -782,6 +782,22 @@ def _plug_os_vif(self, instance, vif):
% {'ex': ex})
raise exception.NovaException(msg)

# TODO(johngarbutt) remove this hack once 1623876 is fixed in os-vif
network = raw_vif.get('network')
mtu = network.get_meta('mtu') if network else None
if mtu is not None:
linux_net._set_device_mtu(network["bridge"], mtu)

if (isinstance(vif, os_vif.objects.vif.VIFBridge) and
hasattr(vif, "port_profile") and
isinstance(vif.port_profile,
os_vif.objects.vif.VIFPortProfileOpenVSwitch)):
veths = [
("qvb%s" % vif.id)[:network_model.NIC_NAME_LEN],
("qvo%s" % vif.id)[:network_model.NIC_NAME_LEN]]
for veth in veths:
linux_net._set_device_mtu(veth, mtu)

def plug(self, instance, vif):
vif_type = vif['type']

Expand All @@ -798,7 +814,7 @@ def plug(self, instance, vif):
# Try os-vif codepath first
vif_obj = os_vif_util.nova_to_osvif_vif(vif)
if vif_obj is not None:
self._plug_os_vif(instance, vif_obj)
self._plug_os_vif(instance, vif_obj, vif)
return

# Legacy non-os-vif codepath
Expand Down

0 comments on commit 77f5466

Please sign in to comment.