summaryrefslogtreecommitdiffstats
path: root/os_net_config/tests
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-10-16 11:23:37 +0000
committerGerrit Code Review <review@openstack.org>2015-10-16 11:23:37 +0000
commitf885df39460d7d8d69e6a3375da69ceead42e6a7 (patch)
tree2ff2895e228c4274bcd87a1aa405a374e2de6e8c /os_net_config/tests
parentcf68668803886fb68b0f0a4a33edf65cf17c6b7c (diff)
parentd01acefc15cebcfc5b7d808d3ed4f41cbaf8d74d (diff)
Merge "Add Linux Bridge capability to os-net-config ifcfg"
Diffstat (limited to 'os_net_config/tests')
-rw-r--r--os_net_config/tests/test_impl_ifcfg.py44
-rw-r--r--os_net_config/tests/test_objects.py76
2 files changed, 120 insertions, 0 deletions
diff --git a/os_net_config/tests/test_impl_ifcfg.py b/os_net_config/tests/test_impl_ifcfg.py
index cb2e881..db61795 100644
--- a/os_net_config/tests/test_impl_ifcfg.py
+++ b/os_net_config/tests/test_impl_ifcfg.py
@@ -60,6 +60,7 @@ _OVS_IFCFG = _BASE_IFCFG + "DEVICETYPE=ovs\nBOOTPROTO=none\n"
_OVS_BRIDGE_IFCFG = _BASE_IFCFG + "DEVICETYPE=ovs\n"
+_LINUX_BRIDGE_IFCFG = _BASE_IFCFG + "BRIDGE=br-ctlplane\nBOOTPROTO=none\n"
_ROUTES = """default via 192.168.1.1 dev em1
172.19.0.0/24 via 192.168.1.1 dev em1
@@ -82,6 +83,16 @@ OVSBOOTPROTO=dhcp
OVSDHCPINTERFACES="em1"
"""
+_LINUX_BRIDGE_DHCP = """# This file is autogenerated by os-net-config
+DEVICE=br-ctlplane
+ONBOOT=yes
+HOTPLUG=no
+NM_CONTROLLED=no
+TYPE=Bridge
+DELAY=0
+BOOTPROTO=dhcp
+"""
+
_OVS_BRIDGE_STATIC = """# This file is autogenerated by os-net-config
DEVICE=br-ctlplane
ONBOOT=yes
@@ -94,6 +105,18 @@ IPADDR=192.168.1.2
NETMASK=255.255.255.0
"""
+_LINUX_BRIDGE_STATIC = """# This file is autogenerated by os-net-config
+DEVICE=br-ctlplane
+ONBOOT=yes
+HOTPLUG=no
+NM_CONTROLLED=no
+TYPE=Bridge
+DELAY=0
+BOOTPROTO=static
+IPADDR=192.168.1.2
+NETMASK=255.255.255.0
+"""
+
_OVS_BRIDGE_DHCP_PRIMARY_INTERFACE = _OVS_BRIDGE_DHCP + \
"OVS_EXTRA=\"set bridge br-ctlplane other-config:hwaddr=a1:b2:c3:d4:e5\"\n"
@@ -249,6 +272,16 @@ class TestIfcfgNetConfig(base.TestCase):
self.assertEqual(_OVS_BRIDGE_DHCP,
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,
+ members=[interface])
+ self.provider.add_linux_bridge(bridge)
+ self.provider.add_interface(interface)
+ self.assertEqual(_LINUX_BRIDGE_IFCFG, self.get_interface_config())
+ self.assertEqual(_LINUX_BRIDGE_DHCP,
+ self.provider.linuxbridge_data['br-ctlplane'])
+
def test_network_ovs_bridge_static(self):
v4_addr = objects.Address('192.168.1.2/24')
interface = objects.Interface('em1')
@@ -260,6 +293,17 @@ class TestIfcfgNetConfig(base.TestCase):
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')
+ bridge = objects.LinuxBridge('br-ctlplane', members=[interface],
+ addresses=[v4_addr])
+ self.provider.add_interface(interface)
+ self.provider.add_bridge(bridge)
+ self.assertEqual(_LINUX_BRIDGE_IFCFG, self.get_interface_config())
+ self.assertEqual(_LINUX_BRIDGE_STATIC,
+ self.provider.bridge_data['br-ctlplane'])
+
def test_network_ovs_bridge_with_dhcp_primary_interface(self):
def test_interface_mac(name):
return "a1:b2:c3:d4:e5"
diff --git a/os_net_config/tests/test_objects.py b/os_net_config/tests/test_objects.py
index 3d95bd6..a2e021b 100644
--- a/os_net_config/tests/test_objects.py
+++ b/os_net_config/tests/test_objects.py
@@ -267,6 +267,82 @@ class TestBridge(base.TestCase):
self.assertEqual("br-foo", interface2.bridge_name)
+class TestLinuxBridge(base.TestCase):
+
+ def test_from_json_dhcp(self):
+ data = """{
+"type": "linux_bridge",
+"name": "br-foo",
+"use_dhcp": true,
+"members": [{
+ "type": "interface",
+ "name": "em1"
+}]
+}
+"""
+ bridge = objects.object_from_json(json.loads(data))
+ self.assertEqual("br-foo", bridge.name)
+ self.assertEqual(True, bridge.use_dhcp)
+ interface1 = bridge.members[0]
+ self.assertEqual("em1", interface1.name)
+ self.assertEqual(False, interface1.ovs_port)
+ self.assertEqual("br-foo", interface1.linux_bridge_name)
+
+ def test_from_json_dhcp_with_nic1(self):
+ def dummy_numbered_nics(nic_mapping=None):
+ return {"nic1": "em5"}
+ self.stubs.Set(objects, '_numbered_nics', dummy_numbered_nics)
+
+ data = """{
+"type": "linux_bridge",
+"name": "br-foo",
+"use_dhcp": true,
+"members": [{
+ "type": "interface",
+ "name": "nic1"
+}]
+}
+"""
+ bridge = objects.object_from_json(json.loads(data))
+ self.assertEqual("br-foo", bridge.name)
+ self.assertEqual(True, bridge.use_dhcp)
+ interface1 = bridge.members[0]
+ self.assertEqual("em5", interface1.name)
+ self.assertEqual(False, interface1.ovs_port)
+ self.assertEqual("br-foo", interface1.linux_bridge_name)
+
+ def test_from_json_primary_interface(self):
+ data = """{
+"type": "linux_bridge",
+"name": "br-foo",
+"use_dhcp": true,
+"members": [
+ {
+ "type": "interface",
+ "name": "em1",
+ "primary": "true"
+ },
+ {
+ "type": "interface",
+ "name": "em2"
+ }]
+}
+"""
+ bridge = objects.object_from_json(json.loads(data))
+ self.assertEqual("br-foo", bridge.name)
+ self.assertEqual(True, bridge.use_dhcp)
+ self.assertEqual("em1", bridge.primary_interface_name)
+ interface1 = bridge.members[0]
+ self.assertEqual("em1", interface1.name)
+ self.assertEqual(False, interface1.ovs_port)
+ self.assertEqual(True, interface1.primary)
+ self.assertEqual("br-foo", interface1.linux_bridge_name)
+ interface2 = bridge.members[1]
+ self.assertEqual("em2", interface2.name)
+ self.assertEqual(False, interface2.ovs_port)
+ self.assertEqual("br-foo", interface2.linux_bridge_name)
+
+
class TestBond(base.TestCase):
def test_from_json_dhcp(self):