aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Sneddon <dsneddon@redhat.com>2015-06-09 10:50:07 -0700
committerDan Prince <dprince@redhat.com>2015-06-09 14:17:41 -0400
commit9355a535e71407911332c228a382ee592452f5e7 (patch)
tree5a0d93bbd63b98c5c251c9e463eae2b3ec1a6967
parent7ce531d3c099e310c81f94328b9bfa20de58699b (diff)
Automate selection of active bond slave
This change selects an interface to be the active slave in a bond with active/passive characteristics. If one of the interfaces is marked as primary, it will be the active slave. If none of the interfaces are marked, the interface with the lowest alphanumeric value will be chosen. For instance em2 comes before em3. Co-Authored-By: Dan Prince <dprince@redhat.com> Change-Id: Ic9b4e8c68b788b98a19ea33a76c9210a80deabeb
-rw-r--r--os_net_config/objects.py4
-rw-r--r--os_net_config/tests/test_impl_ifcfg.py15
2 files changed, 18 insertions, 1 deletions
diff --git a/os_net_config/objects.py b/os_net_config/objects.py
index 65bdd3b..ea9c11c 100644
--- a/os_net_config/objects.py
+++ b/os_net_config/objects.py
@@ -338,6 +338,10 @@ class OvsBond(_BaseOpts):
self.primary_interface_name = member.primary_interface_name
else:
self.primary_interface_name = member.name
+ if not self.primary_interface_name:
+ bond_members = list(self.members)
+ bond_members.sort(key=lambda x: x.name)
+ self.primary_interface_name = bond_members[0].name
@staticmethod
def from_json(json):
diff --git a/os_net_config/tests/test_impl_ifcfg.py b/os_net_config/tests/test_impl_ifcfg.py
index 9480d47..92ce828 100644
--- a/os_net_config/tests/test_impl_ifcfg.py
+++ b/os_net_config/tests/test_impl_ifcfg.py
@@ -405,7 +405,20 @@ class TestIfcfgNetConfigApply(base.TestCase):
def test_bond_active_slave(self):
#setup and apply a bond
- interface1 = objects.Interface('em1', primary=True)
+ interface1 = objects.Interface('em1')
+ interface2 = objects.Interface('em2', primary=True)
+ 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 em2'
+ self.assertIn(ovs_appctl_cmds, self.ovs_appctl_cmds)
+
+ def test_bond_active_ordering(self):
+ #setup and apply a bond
+ interface1 = objects.Interface('em1')
interface2 = objects.Interface('em2')
bond = objects.OvsBond('bond1', use_dhcp=True,
members=[interface1, interface2])