summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrent Eagles <beagles@redhat.com>2016-11-14 18:52:40 -0330
committerBrent Eagles <beagles@redhat.com>2016-11-15 10:25:33 -0330
commite479535b508b4072f64300809b824dfecc3a9182 (patch)
tree026bcef6da8b71e5188e636f30eeaf62f5ac18e7
parent38a4ffbfe045b2658abaf9459b5c8ade1f3e5429 (diff)
Add ovs_fail_mode option for OVS bridges
This patch adds an option "ovs_fail_mode" with a default value of 'standalone'. This is written to the interface configuration data as part of the ovs_extra options. Closes-Bug: #1640812 Change-Id: I2f30e56ff9fbda7beac21d95d15dbde0b01ba451
-rw-r--r--os_net_config/objects.py25
-rw-r--r--os_net_config/tests/test_impl_eni.py29
-rw-r--r--os_net_config/tests/test_impl_ifcfg.py29
-rw-r--r--os_net_config/tests/test_objects.py6
4 files changed, 80 insertions, 9 deletions
diff --git a/os_net_config/objects.py b/os_net_config/objects.py
index 330b695..8d52e73 100644
--- a/os_net_config/objects.py
+++ b/os_net_config/objects.py
@@ -25,6 +25,8 @@ logger = logging.getLogger(__name__)
_MAPPED_NICS = None
+DEFAULT_OVS_BRIDGE_FAIL_MODE = 'standalone'
+
class InvalidConfigException(ValueError):
pass
@@ -397,7 +399,8 @@ class OvsBridge(_BaseOpts):
def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=None,
routes=None, mtu=None, members=None, ovs_options=None,
ovs_extra=None, nic_mapping=None, persist_mapping=False,
- defroute=True, dhclient_args=None, dns_servers=None):
+ defroute=True, dhclient_args=None, dns_servers=None,
+ fail_mode=None):
addresses = addresses or []
routes = routes or []
members = members or []
@@ -408,6 +411,9 @@ class OvsBridge(_BaseOpts):
dhclient_args, dns_servers)
self.members = members
self.ovs_options = ovs_options
+ ovs_extra = ovs_extra or []
+ if fail_mode:
+ ovs_extra.append('set bridge {name} fail_mode=%s' % fail_mode)
self.ovs_extra = format_ovs_extra(self, ovs_extra)
for member in self.members:
member.bridge_name = name
@@ -430,7 +436,8 @@ class OvsBridge(_BaseOpts):
dhclient_args, dns_servers) = _BaseOpts.base_opts_from_json(
json, include_primary=False)
ovs_options = json.get('ovs_options')
- ovs_extra = json.get('ovs_extra', [])
+ ovs_extra = json.get('ovs_extra')
+ fail_mode = json.get('ovs_fail_mode', DEFAULT_OVS_BRIDGE_FAIL_MODE)
members = []
# members
@@ -448,7 +455,8 @@ class OvsBridge(_BaseOpts):
members=members, ovs_options=ovs_options,
ovs_extra=ovs_extra, nic_mapping=nic_mapping,
persist_mapping=persist_mapping, defroute=defroute,
- dhclient_args=dhclient_args, dns_servers=dns_servers)
+ dhclient_args=dhclient_args, dns_servers=dns_servers,
+ fail_mode=fail_mode)
class OvsUserBridge(_BaseOpts):
@@ -457,7 +465,8 @@ class OvsUserBridge(_BaseOpts):
def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=None,
routes=None, mtu=None, members=None, ovs_options=None,
ovs_extra=None, nic_mapping=None, persist_mapping=False,
- defroute=True, dhclient_args=None, dns_servers=None):
+ defroute=True, dhclient_args=None, dns_servers=None,
+ fail_mode=None):
super(OvsUserBridge, self).__init__(name, use_dhcp, use_dhcpv6,
addresses, routes, mtu, False,
nic_mapping, persist_mapping,
@@ -465,6 +474,9 @@ class OvsUserBridge(_BaseOpts):
dns_servers)
self.members = members or []
self.ovs_options = ovs_options
+ ovs_extra = ovs_extra or []
+ if fail_mode:
+ ovs_extra.append('set bridge {name} fail_mode=%s' % fail_mode)
self.ovs_extra = format_ovs_extra(self, ovs_extra)
for member in self.members:
member.bridge_name = name
@@ -489,7 +501,8 @@ class OvsUserBridge(_BaseOpts):
dhclient_args, dns_servers) = _BaseOpts.base_opts_from_json(
json, include_primary=False)
ovs_options = json.get('ovs_options')
- ovs_extra = json.get('ovs_extra', [])
+ ovs_extra = json.get('ovs_extra')
+ fail_mode = json.get('ovs_fail_mode', DEFAULT_OVS_BRIDGE_FAIL_MODE)
members = []
# members
@@ -508,7 +521,7 @@ class OvsUserBridge(_BaseOpts):
ovs_extra=ovs_extra, nic_mapping=nic_mapping,
persist_mapping=persist_mapping,
defroute=defroute, dhclient_args=dhclient_args,
- dns_servers=dns_servers)
+ dns_servers=dns_servers, fail_mode=fail_mode)
class LinuxBridge(_BaseOpts):
diff --git a/os_net_config/tests/test_impl_eni.py b/os_net_config/tests/test_impl_eni.py
index 086be95..e445ed4 100644
--- a/os_net_config/tests/test_impl_eni.py
+++ b/os_net_config/tests/test_impl_eni.py
@@ -66,10 +66,15 @@ iface br0 inet dhcp
pre-up ip addr flush dev eth0
"""
+_OVS_BRIDGE_DHCP_STANDALONE = _OVS_BRIDGE_DHCP + \
+ " ovs_extra set bridge br0 fail_mode=standalone\n"
+
+_OVS_BRIDGE_DHCP_SECURE = _OVS_BRIDGE_DHCP + \
+ " ovs_extra set bridge br0 fail_mode=secure\n"
+
_OVS_BRIDGE_DHCP_PRIMARY_INTERFACE = _OVS_BRIDGE_DHCP + \
" ovs_extra set bridge br0 other-config:hwaddr=a1:b2:c3:d4:e5\n"
-
_OVS_BRIDGE_DHCP_OVS_EXTRA = _OVS_BRIDGE_DHCP + \
" ovs_extra set bridge br0 other-config:hwaddr=a1:b2:c3:d4:e5" + \
" -- br-set-external-id br0 bridge-id br0\n"
@@ -188,6 +193,28 @@ class TestENINetConfig(base.TestCase):
self.assertEqual(_OVS_PORT_IFACE, self.get_interface_config())
self.assertEqual(_OVS_BRIDGE_DHCP, self.provider.bridges['br0'])
+ def test_network_ovs_bridge_with_standalone_fail_mode(self):
+ interface = self._default_interface()
+ bridge = objects.OvsBridge('br0', use_dhcp=True,
+ members=[interface],
+ fail_mode='standalone')
+ self.provider.add_bridge(bridge)
+ self.provider.add_interface(interface)
+ self.assertEqual(_OVS_PORT_IFACE, self.get_interface_config())
+ self.assertEqual(_OVS_BRIDGE_DHCP_STANDALONE,
+ self.provider.bridges['br0'])
+
+ def test_network_ovs_bridge_with_secure_fail_mode(self):
+ interface = self._default_interface()
+ bridge = objects.OvsBridge('br0', use_dhcp=True,
+ members=[interface],
+ fail_mode='secure')
+ self.provider.add_bridge(bridge)
+ self.provider.add_interface(interface)
+ self.assertEqual(_OVS_PORT_IFACE, self.get_interface_config())
+ self.assertEqual(_OVS_BRIDGE_DHCP_SECURE,
+ self.provider.bridges['br0'])
+
def test_network_ovs_bridge_with_dhcp_and_primary_interface(self):
def test_interface_mac(name):
diff --git a/os_net_config/tests/test_impl_ifcfg.py b/os_net_config/tests/test_impl_ifcfg.py
index bfbe5b8..2f5b3af 100644
--- a/os_net_config/tests/test_impl_ifcfg.py
+++ b/os_net_config/tests/test_impl_ifcfg.py
@@ -143,6 +143,13 @@ OVSBOOTPROTO=dhcp
OVSDHCPINTERFACES="em1"
"""
+_OVS_BRIDGE_DHCP_STANDALONE = _OVS_BRIDGE_DHCP + \
+ "OVS_EXTRA=\"set bridge br-ctlplane fail_mode=standalone\"\n"
+
+_OVS_BRIDGE_DHCP_SECURE = _OVS_BRIDGE_DHCP + \
+ "OVS_EXTRA=\"set bridge br-ctlplane fail_mode=secure\"\n"
+
+
_LINUX_BRIDGE_DHCP = """# This file is autogenerated by os-net-config
DEVICE=br-ctlplane
ONBOOT=yes
@@ -499,6 +506,28 @@ class TestIfcfgNetConfig(base.TestCase):
self.assertEqual(_OVS_BRIDGE_DHCP,
self.provider.bridge_data['br-ctlplane'])
+ def test_network_ovs_bridge_with_standalone_fail_mode(self):
+ interface = objects.Interface('em1')
+ bridge = objects.OvsBridge('br-ctlplane', use_dhcp=True,
+ members=[interface],
+ fail_mode='standalone')
+ self.provider.add_interface(interface)
+ self.provider.add_bridge(bridge)
+ self.assertEqual(_OVS_INTERFACE, self.get_interface_config())
+ self.assertEqual(_OVS_BRIDGE_DHCP_STANDALONE,
+ self.provider.bridge_data['br-ctlplane'])
+
+ def test_network_ovs_bridge_with_secure_fail_mode(self):
+ interface = objects.Interface('em1')
+ bridge = objects.OvsBridge('br-ctlplane', use_dhcp=True,
+ members=[interface],
+ fail_mode='secure')
+ self.provider.add_interface(interface)
+ self.provider.add_bridge(bridge)
+ self.assertEqual(_OVS_INTERFACE, self.get_interface_config())
+ self.assertEqual(_OVS_BRIDGE_DHCP_SECURE,
+ self.provider.bridge_data['br-ctlplane'])
+
def test_network_linux_bridge_with_dhcp(self):
interface = objects.Interface('em1')
bridge = objects.LinuxBridge('br-ctlplane', use_dhcp=True,
diff --git a/os_net_config/tests/test_objects.py b/os_net_config/tests/test_objects.py
index 870a3e4..ca2dd47 100644
--- a/os_net_config/tests/test_objects.py
+++ b/os_net_config/tests/test_objects.py
@@ -651,7 +651,7 @@ class TestOvsTunnel(base.TestCase):
"type": "ovs_bridge",
"name": "br-foo",
"ovs_extra": [
- "set {name} fail_mode=standalone"
+ "set bridge {name} something"
],
"members": [{
"type": "ovs_tunnel",
@@ -669,7 +669,9 @@ class TestOvsTunnel(base.TestCase):
"""
bridge = objects.object_from_json(json.loads(data))
self.assertEqual("br-foo", bridge.name)
- self.assertEqual(["set br-foo fail_mode=standalone"], bridge.ovs_extra)
+ self.assertEqual(["set bridge br-foo something",
+ "set bridge br-foo fail_mode=standalone"],
+ bridge.ovs_extra)
tun0 = bridge.members[0]
self.assertEqual("tun0", tun0.name)
self.assertFalse(tun0.ovs_port)