From d325a1a2f8d7c815cbaa016858db053412201b9d Mon Sep 17 00:00:00 2001 From: James Slagle Date: Mon, 11 Apr 2016 12:19:51 -0400 Subject: Add support for OVS tunnels Adds support for configuring OVS Tunnels via os-net-config. Tunnels are configured as members of ovs_bridge's where the type is set to ovs_tunnel. The object also supports setting OVS extra and options so that additional tunnel data can be defined, such as remote_ip. Change-Id: I31ac1cbe8a13247a1529c0f99a0aea5807888844 --- os_net_config/tests/test_impl_ifcfg.py | 38 ++++++++++++++++++++++++++++++++++ os_net_config/tests/test_objects.py | 34 ++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) (limited to 'os_net_config/tests') diff --git a/os_net_config/tests/test_impl_ifcfg.py b/os_net_config/tests/test_impl_ifcfg.py index d68a96e..f4701a0 100644 --- a/os_net_config/tests/test_impl_ifcfg.py +++ b/os_net_config/tests/test_impl_ifcfg.py @@ -76,6 +76,19 @@ _V6_IFCFG_MULTIPLE = (_V6_IFCFG + "IPV6ADDR_SECONDARIES=\"2001:abc:b::1/64 " + _OVS_IFCFG = _BASE_IFCFG + "DEVICETYPE=ovs\nBOOTPROTO=none\n" +_OVS_IFCFG_TUNNEL = """# This file is autogenerated by os-net-config +DEVICE=tun0 +ONBOOT=yes +HOTPLUG=no +NM_CONTROLLED=no +PEERDNS=no +DEVICETYPE=ovs +TYPE=OVSTunnel +OVS_BRIDGE=br-ctlplane +OVS_TUNNEL_TYPE=gre +OVS_TUNNEL_OPTIONS="options:remote_ip=192.168.1.1" +""" + _OVS_BRIDGE_IFCFG = _BASE_IFCFG + "DEVICETYPE=ovs\n" @@ -287,6 +300,15 @@ class TestIfcfgNetConfig(base.TestCase): self.provider.add_interface(interface) self.assertEqual(_OVS_IFCFG, self.get_interface_config()) + def test_add_ovs_tunnel(self): + interface = objects.OvsTunnel('tun0') + interface.type = 'ovs_tunnel' + interface.tunnel_type = 'gre' + interface.ovs_options = ['options:remote_ip=192.168.1.1'] + interface.bridge_name = 'br-ctlplane' + self.provider.add_interface(interface) + self.assertEqual(_OVS_IFCFG_TUNNEL, self.get_interface_config('tun0')) + def test_add_interface_with_v4(self): v4_addr = objects.Address('192.168.1.2/24') interface = objects.Interface('em1', addresses=[v4_addr]) @@ -389,6 +411,22 @@ class TestIfcfgNetConfig(base.TestCase): self.assertEqual(_OVS_BRIDGE_STATIC, self.provider.bridge_data['br-ctlplane']) + def test_network_ovs_bridge_with_tunnel(self): + interface = objects.OvsTunnel('tun0') + interface.type = 'ovs_tunnel' + interface.tunnel_type = 'gre' + interface.ovs_options = ['options:remote_ip=192.168.1.1'] + interface.bridge_name = 'br-ctlplane' + self.provider.add_interface(interface) + v4_addr = objects.Address('192.168.1.2/24') + bridge = objects.OvsBridge('br-ctlplane', members=[interface], + addresses=[v4_addr]) + self.provider.add_bridge(bridge) + self.provider.add_interface(interface) + self.assertEqual(_OVS_IFCFG_TUNNEL, self.get_interface_config('tun0')) + self.assertEqual(_OVS_BRIDGE_STATIC, + self.provider.bridge_data['br-ctlplane']) + def test_network_linux_bridge_static(self): v4_addr = objects.Address('192.168.1.2/24') interface = objects.Interface('em1') diff --git a/os_net_config/tests/test_objects.py b/os_net_config/tests/test_objects.py index d3e41df..a7b4230 100644 --- a/os_net_config/tests/test_objects.py +++ b/os_net_config/tests/test_objects.py @@ -514,6 +514,40 @@ class TestLinuxBond(base.TestCase): self.assertEqual("em2", interface2.name) +class TestOvsTunnel(base.TestCase): + + def test_from_json(self): + data = """{ +"type": "ovs_bridge", +"name": "br-foo", +"members": [{ + "type": "ovs_tunnel", + "name": "tun0", + "tunnel_type": "gre", + "ovs_options": [ + "remote_ip=192.168.1.1" + ], + "ovs_extra": [ + "ovs extra" + ] +}] +} +""" + bridge = objects.object_from_json(json.loads(data)) + self.assertEqual("br-foo", bridge.name) + tun0 = bridge.members[0] + self.assertEqual("tun0", tun0.name) + self.assertFalse(tun0.ovs_port) + self.assertEqual("br-foo", tun0.bridge_name) + self.assertEqual("gre", tun0.tunnel_type) + self.assertEqual( + ["options:remote_ip=192.168.1.1"], + tun0.ovs_options) + self.assertEqual( + ["ovs extra"], + tun0.ovs_extra) + + class TestNumberedNicsMapping(base.TestCase): # We want to test the function, not the dummy.. -- cgit 1.2.3-korg