From ab0e0d433fb363f6a01b7c8305771f2bde47930e Mon Sep 17 00:00:00 2001 From: karthik s Date: Wed, 15 Feb 2017 18:03:14 +0530 Subject: Restart Openvswitch after adding DPDK ports OvS needs to be restarted after adding a DPDK port. This change shall be removed on migration to OvS 2.7 where DPDK Hotplug support is available. Co-Authored-By: Saravanan KR Closes-Bug: #1668375 Signed-off-by: karthik s Change-Id: I250bb8e9a8e50874a82bf7f159e5a9d5677ef5ac --- os_net_config/impl_ifcfg.py | 16 ++++++++++++++++ os_net_config/tests/test_impl_ifcfg.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/os_net_config/impl_ifcfg.py b/os_net_config/impl_ifcfg.py index 0a4f817..84a5139 100644 --- a/os_net_config/impl_ifcfg.py +++ b/os_net_config/impl_ifcfg.py @@ -694,6 +694,7 @@ class IfcfgNetConfig(os_net_config.NetConfig): nfvswitch_interfaces = [] # nfvswitch physical interfaces nfvswitch_internal_ifaces = [] # nfvswitch internal/management ports stop_dhclient_interfaces = [] + ovs_needs_restart = False for interface_name, iface_data in self.interface_data.items(): route_data = self.route_data.get(interface_name, '') @@ -719,6 +720,11 @@ class IfcfgNetConfig(os_net_config.NetConfig): update_files[route6_path] = route6_data if "BOOTPROTO=dhcp" not in iface_data: stop_dhclient_interfaces.append(interface_name) + # Openvswitch needs to be restarted when OVSDPDKPort or + # OVSDPDKBond is added + if "OVSDPDK" in iface_data: + ovs_needs_restart = True + else: logger.info('No changes required for interface: %s' % interface_name) @@ -926,6 +932,16 @@ class IfcfgNetConfig(os_net_config.NetConfig): for oldname, newname in self.renamed_interfaces.items(): self.ifrename(oldname, newname) + # DPDK initialization is done before running os-net-config, to make + # the DPDK ports available when enabled. DPDK Hotplug support is + # supported only in OvS 2.7 version. Until then, OvS needs to be + # restarted after adding a DPDK port. This change will be removed on + # migration to OvS 2.7 where DPDK Hotplug support is available. + if ovs_needs_restart: + msg = "Restart openvswitch" + self.execute(msg, '/usr/bin/systemctl', + 'restart', 'openvswitch') + for location, data in update_files.items(): self.write_config(location, data) diff --git a/os_net_config/tests/test_impl_ifcfg.py b/os_net_config/tests/test_impl_ifcfg.py index 78d19cb..6576cef 100644 --- a/os_net_config/tests/test_impl_ifcfg.py +++ b/os_net_config/tests/test_impl_ifcfg.py @@ -20,6 +20,7 @@ import tempfile from oslo_concurrency import processutils from os_net_config import impl_ifcfg +from os_net_config import NetConfig from os_net_config import objects from os_net_config.tests import base from os_net_config import utils @@ -1164,3 +1165,32 @@ class TestIfcfgNetConfigApply(base.TestCase): self.provider.apply(cleanup=True) self.assertTrue(os.path.exists(tmp_lo_file)) os.remove(tmp_lo_file) + + def test_ovs_restart_called(self): + interface = objects.Interface('em1') + dpdk_port = objects.OvsDpdkPort('dpdk0', members=[interface]) + execute_strings = [] + + def test_execute(*args, **kwargs): + execute_strings.append(args[1]) + pass + self.stubs.Set(NetConfig, 'execute', test_execute) + + self.provider.noop = True + self.provider.add_ovs_dpdk_port(dpdk_port) + self.provider.apply() + self.assertIn('Restart openvswitch', execute_strings) + + def test_ovs_restart_not_called(self): + interface = objects.Interface('em1') + execute_strings = [] + + def test_execute(*args, **kwargs): + execute_strings.append(args[1]) + pass + self.stubs.Set(NetConfig, 'execute', test_execute) + + self.provider.noop = True + self.provider.add_interface(interface) + self.provider.apply() + self.assertNotIn('Restart openvswitch', execute_strings) -- cgit 1.2.3-korg