aboutsummaryrefslogtreecommitdiffstats
path: root/os_net_config/tests/test_impl_ifcfg.py
diff options
context:
space:
mode:
Diffstat (limited to 'os_net_config/tests/test_impl_ifcfg.py')
-rw-r--r--os_net_config/tests/test_impl_ifcfg.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/os_net_config/tests/test_impl_ifcfg.py b/os_net_config/tests/test_impl_ifcfg.py
index 9621b8c..82ca116 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
@@ -33,6 +34,14 @@ NM_CONTROLLED=no
PEERDNS=no
"""
+_BASE_IFCFG_NETWORKMANAGER = """# This file is autogenerated by os-net-config
+DEVICE=em1
+ONBOOT=yes
+HOTPLUG=no
+NM_CONTROLLED=yes
+PEERDNS=no
+"""
+
_HOTPLUG = """# This file is autogenerated by os-net-config
DEVICE=em1
ONBOOT=yes
@@ -152,6 +161,19 @@ OVSBOOTPROTO=dhcp
OVSDHCPINTERFACES="em1"
"""
+_NM_CONTROLLED_INTERFACE = _BASE_IFCFG_NETWORKMANAGER + """MASTER=bond1
+SLAVE=yes
+BOOTPROTO=none
+"""
+
+_NM_CONTROLLED_BOND = """# This file is autogenerated by os-net-config
+DEVICE=bond1
+ONBOOT=yes
+HOTPLUG=no
+NM_CONTROLLED=yes
+PEERDNS=no
+"""
+
_OVS_BRIDGE_DHCP_STANDALONE = _OVS_BRIDGE_DHCP + \
"OVS_EXTRA=\"set bridge br-ctlplane fail_mode=standalone\"\n"
@@ -844,6 +866,20 @@ DNS2=5.6.7.8
"""
self.assertEqual(em1_config, self.get_interface_config('em1'))
+ def test_nm_controlled(self):
+ interface1 = objects.Interface('em1', nm_controlled=True)
+ interface2 = objects.Interface('em2', nm_controlled=True)
+ bond = objects.LinuxBond('bond1', nm_controlled=True,
+ members=[interface1, interface2])
+ self.provider.add_linux_bond(bond)
+ self.provider.add_interface(interface1)
+ self.provider.add_interface(interface2)
+
+ ifcfg_data = self.get_interface_config('em1')
+ self.assertEqual(_NM_CONTROLLED_INTERFACE, ifcfg_data)
+ bond_data = self.get_linux_bond_config('bond1')
+ self.assertEqual(_NM_CONTROLLED_BOND, bond_data)
+
def test_network_ovs_dpdk_bridge_and_port(self):
nic_mapping = {'nic1': 'eth0', 'nic2': 'eth1', 'nic3': 'eth2'}
self.stubbed_mapped_nics = nic_mapping
@@ -923,6 +959,7 @@ class TestIfcfgNetConfigApply(base.TestCase):
def setUp(self):
super(TestIfcfgNetConfigApply, self).setUp()
self.temp_ifcfg_file = tempfile.NamedTemporaryFile()
+ self.temp_bond_file = tempfile.NamedTemporaryFile()
self.temp_route_file = tempfile.NamedTemporaryFile()
self.temp_route6_file = tempfile.NamedTemporaryFile()
self.temp_bridge_file = tempfile.NamedTemporaryFile()
@@ -935,6 +972,13 @@ class TestIfcfgNetConfigApply(base.TestCase):
return self.temp_ifcfg_file.name
self.stubs.Set(impl_ifcfg, 'ifcfg_config_path', test_ifcfg_path)
+ def test_remove_ifcfg_config(name):
+ ifcfg_file = self.temp_ifcfg_file.name
+ if os.path.exists(ifcfg_file):
+ os.remove(ifcfg_file)
+ self.stubs.Set(impl_ifcfg, 'remove_ifcfg_config',
+ test_remove_ifcfg_config)
+
def test_routes_path(name):
return self.temp_route_file.name
self.stubs.Set(impl_ifcfg, 'route_config_path', test_routes_path)
@@ -1157,3 +1201,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)