aboutsummaryrefslogtreecommitdiffstats
path: root/os_net_config/tests/test_impl_eni.py
diff options
context:
space:
mode:
Diffstat (limited to 'os_net_config/tests/test_impl_eni.py')
-rw-r--r--os_net_config/tests/test_impl_eni.py85
1 files changed, 75 insertions, 10 deletions
diff --git a/os_net_config/tests/test_impl_eni.py b/os_net_config/tests/test_impl_eni.py
index 7f909ff..4911cb9 100644
--- a/os_net_config/tests/test_impl_eni.py
+++ b/os_net_config/tests/test_impl_eni.py
@@ -32,6 +32,12 @@ _V4_IFACE_STATIC_IP = _AUTO + """iface eth0 inet static
netmask 255.255.255.0
"""
+_IFACE_HOTPLUG = """allow-hotplug eth0
+iface eth0 inet static
+ address 192.168.1.2
+ netmask 255.255.255.0
+"""
+
_V4_IFACE_STATIC_IP_MULTIPLE = (_V4_IFACE_STATIC_IP + _AUTO +
"""iface eth0 inet static
address 10.0.0.2
@@ -66,13 +72,18 @@ 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 br-ctlplane bridge-id br-ctlplane\n"
+ " -- br-set-external-id br0 bridge-id br0\n"
_VLAN_NO_IP = """auto vlan5
@@ -90,6 +101,8 @@ iface vlan5 inet manual
_RTS = """up route add -net 172.19.0.0 netmask 255.255.255.0 gw 192.168.1.1
down route del -net 172.19.0.0 netmask 255.255.255.0 gw 192.168.1.1
+up route add -net 172.20.0.0 netmask 255.255.255.0 gw 192.168.1.5 metric 100
+down route del -net 172.20.0.0 netmask 255.255.255.0 gw 192.168.1.5 metric 100
"""
@@ -110,8 +123,9 @@ class TestENINetConfig(base.TestCase):
def get_route_config(self):
return self.provider.routes[self.if_name]
- def _default_interface(self, addr=[], rts=[]):
- return objects.Interface(self.if_name, addresses=addr, routes=rts)
+ def _default_interface(self, addr=[], rts=[], hotplug=False):
+ return objects.Interface(self.if_name, addresses=addr, routes=rts,
+ hotplug=hotplug)
def test_interface_no_ip(self):
interface = self._default_interface()
@@ -124,6 +138,12 @@ class TestENINetConfig(base.TestCase):
self.provider.add_interface(interface)
self.assertEqual(_V4_IFACE_STATIC_IP, self.get_interface_config())
+ def test_add_interface_with_hotplug(self):
+ v4_addr = objects.Address('192.168.1.2/24')
+ interface = self._default_interface(addr=[v4_addr], hotplug=True)
+ self.provider.add_interface(interface)
+ self.assertEqual(_IFACE_HOTPLUG, self.get_interface_config())
+
def test_add_interface_with_v4_multiple(self):
v4_addresses = [objects.Address('192.168.1.2/24'),
objects.Address('10.0.0.2/8')]
@@ -169,8 +189,10 @@ class TestENINetConfig(base.TestCase):
def test_network_with_routes(self):
route1 = objects.Route('192.168.1.1', '172.19.0.0/24')
+ route2 = objects.Route('192.168.1.5', '172.20.0.0/24',
+ route_options="metric 100")
v4_addr = objects.Address('192.168.1.2/24')
- interface = self._default_interface([v4_addr], [route1])
+ interface = self._default_interface([v4_addr], [route1, route2])
self.provider.add_interface(interface)
self.assertEqual(_V4_IFACE_STATIC_IP, self.get_interface_config())
self.assertEqual(_RTS, self.get_route_config())
@@ -184,6 +206,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):
@@ -206,7 +250,24 @@ class TestENINetConfig(base.TestCase):
self.stubs.Set(utils, 'interface_mac', test_interface_mac)
interface = objects.Interface(self.if_name, primary=True)
- ovs_extra = "br-set-external-id br-ctlplane bridge-id br-ctlplane"
+ ovs_extra = "br-set-external-id br0 bridge-id br0"
+ bridge = objects.OvsBridge('br0', use_dhcp=True,
+ members=[interface],
+ ovs_extra=[ovs_extra])
+ self.provider.add_bridge(bridge)
+ self.provider.add_interface(interface)
+ self.assertEqual(_OVS_PORT_IFACE, self.get_interface_config())
+ self.assertEqual(_OVS_BRIDGE_DHCP_OVS_EXTRA,
+ self.provider.bridges['br0'])
+
+ def test_network_ovs_bridge_with_dhcp_and_primary_with_ovs_format(self):
+
+ def test_interface_mac(name):
+ return "a1:b2:c3:d4:e5"
+ self.stubs.Set(utils, 'interface_mac', test_interface_mac)
+
+ interface = objects.Interface(self.if_name, primary=True)
+ ovs_extra = "br-set-external-id {name} bridge-id {name}"
bridge = objects.OvsBridge('br0', use_dhcp=True,
members=[interface],
ovs_extra=[ovs_extra])
@@ -261,10 +322,12 @@ class TestENINetConfigApply(base.TestCase):
super(TestENINetConfigApply, self).tearDown()
def test_network_apply(self):
- route = objects.Route('192.168.1.1', '172.19.0.0/24')
+ route1 = objects.Route('192.168.1.1', '172.19.0.0/24')
+ route2 = objects.Route('192.168.1.5', '172.20.0.0/24',
+ route_options="metric 100")
v4_addr = objects.Address('192.168.1.2/24')
interface = objects.Interface('eth0', addresses=[v4_addr],
- routes=[route])
+ routes=[route1, route2])
self.provider.add_interface(interface)
self.provider.apply()
@@ -273,10 +336,12 @@ class TestENINetConfigApply(base.TestCase):
self.assertIn('eth0', self.ifup_interface_names)
def test_apply_noactivate(self):
- route = objects.Route('192.168.1.1', '172.19.0.0/24')
+ route1 = objects.Route('192.168.1.1', '172.19.0.0/24')
+ route2 = objects.Route('192.168.1.5', '172.20.0.0/24',
+ route_options="metric 100")
v4_addr = objects.Address('192.168.1.2/24')
interface = objects.Interface('eth0', addresses=[v4_addr],
- routes=[route])
+ routes=[route1, route2])
self.provider.add_interface(interface)
self.provider.apply(activate=False)