diff options
Diffstat (limited to 'os_net_config')
-rw-r--r-- | os_net_config/__init__.py | 4 | ||||
-rw-r--r-- | os_net_config/impl_ifcfg.py | 10 | ||||
-rw-r--r-- | os_net_config/tests/test_impl_ifcfg.py | 16 |
3 files changed, 29 insertions, 1 deletions
diff --git a/os_net_config/__init__.py b/os_net_config/__init__.py index e1bee26..c33e5d1 100644 --- a/os_net_config/__init__.py +++ b/os_net_config/__init__.py @@ -139,3 +139,7 @@ class NetConfig(object): 'link', 'set', 'dev', oldname, 'name', newname) self.execute(msg, '/sbin/ip', 'link', 'set', 'dev', newname, 'up') + + def ovs_appctl(self, action, *parameters): + msg = 'Running ovs-appctl %s %s' % (action, parameters) + self.execute(msg, '/bin/ovs-appctl', action, *parameters) diff --git a/os_net_config/impl_ifcfg.py b/os_net_config/impl_ifcfg.py index 40a5ff0..daadd52 100644 --- a/os_net_config/impl_ifcfg.py +++ b/os_net_config/impl_ifcfg.py @@ -52,6 +52,7 @@ class IfcfgNetConfig(os_net_config.NetConfig): self.bridge_data = {} self.member_names = {} self.renamed_interfaces = {} + self.bond_primary_ifaces = {} logger.info('Ifcfg net config provider created.') def child_members(self, name): @@ -107,6 +108,9 @@ class IfcfgNetConfig(os_net_config.NetConfig): data += "OVS_OPTIONS=\"%s\"\n" % base_opt.ovs_options ovs_extra.extend(base_opt.ovs_extra) elif isinstance(base_opt, objects.OvsBond): + if base_opt.primary_interface_name: + primary_name = base_opt.primary_interface_name + self.bond_primary_ifaces[base_opt.name] = primary_name data += "DEVICETYPE=ovs\n" data += "TYPE=OVSBond\n" if base_opt.use_dhcp: @@ -212,7 +216,7 @@ class IfcfgNetConfig(os_net_config.NetConfig): def add_bond(self, bond): """Add an OvsBond object to the net config object. - :param bridge: The OvsBond object to add. + :param bond: The OvsBond object to add. """ logger.info('adding bond: %s' % bond.name) data = self._add_common(bond) @@ -301,4 +305,8 @@ class IfcfgNetConfig(os_net_config.NetConfig): for interface in restart_interfaces: self.ifup(interface) + for bond in self.bond_primary_ifaces: + self.ovs_appctl('bond/set-active-slave', bond, + self.bond_primary_ifaces[bond]) + return update_files diff --git a/os_net_config/tests/test_impl_ifcfg.py b/os_net_config/tests/test_impl_ifcfg.py index a273b05..9480d47 100644 --- a/os_net_config/tests/test_impl_ifcfg.py +++ b/os_net_config/tests/test_impl_ifcfg.py @@ -328,6 +328,7 @@ class TestIfcfgNetConfigApply(base.TestCase): self.temp_bridge_file = tempfile.NamedTemporaryFile() self.temp_cleanup_file = tempfile.NamedTemporaryFile(delete=False) self.ifup_interface_names = [] + self.ovs_appctl_cmds = [] def test_ifcfg_path(name): return self.temp_ifcfg_file.name @@ -348,6 +349,8 @@ class TestIfcfgNetConfigApply(base.TestCase): def test_execute(*args, **kwargs): if args[0] == '/sbin/ifup': self.ifup_interface_names.append(args[1]) + elif args[0] == '/bin/ovs-appctl': + self.ovs_appctl_cmds.append(' '.join(args)) pass self.stubs.Set(processutils, 'execute', test_execute) @@ -400,6 +403,19 @@ class TestIfcfgNetConfigApply(base.TestCase): self.provider.apply(activate=False) self.assertEqual([], self.ifup_interface_names) + def test_bond_active_slave(self): + #setup and apply a bond + interface1 = objects.Interface('em1', primary=True) + interface2 = objects.Interface('em2') + bond = objects.OvsBond('bond1', use_dhcp=True, + members=[interface1, interface2]) + self.provider.add_interface(interface1) + self.provider.add_interface(interface2) + self.provider.add_bond(bond) + self.provider.apply() + ovs_appctl_cmds = '/bin/ovs-appctl bond/set-active-slave bond1 em1' + self.assertIn(ovs_appctl_cmds, self.ovs_appctl_cmds) + def test_restart_children_on_change(self): # setup and apply a bridge interface = objects.Interface('em1') |