diff options
author | 2016-04-13 01:17:16 -0700 | |
---|---|---|
committer | 2016-07-05 10:27:45 -0700 | |
commit | 78e1b65d93a1c16d58fd72cb65f8e2adf1762854 (patch) | |
tree | 150a8e2a68c41b0bd76dc17829181e4b4842b1de /os_net_config/tests | |
parent | 6bb8412ef3d3f163d91f2884081b743f07a78f18 (diff) |
Add support for Infiniband interfaces
This patch adds support for Infiniband interfaces. The only difference
between Inifiniband and regular interfaces at this time is that an
interface with type "ib_interface" will have "TYPE=Infiniband" added
to the ifcfg file.
However, the Infiniband interface is implemented as a full new class,
so in the future we can add script functions or additional config
options to the Infiniband interface config if needed.
Unit tests for both the object and the ifcfg implementation are
included. This patch does not include an implementation for systems
that use /etc/network/interfaces (Debian-based systems).
Note that this change has not yet been tested on bare metal with
Infiniband hardware.
Fixes bug: https://bugzilla.redhat.com/show_bug.cgi?id=1326616
Change-Id: Iaeaca9cd71e2cea6147951d49aecc7458be4ca0b
Diffstat (limited to 'os_net_config/tests')
-rw-r--r-- | os_net_config/tests/test_impl_ifcfg.py | 51 | ||||
-rw-r--r-- | os_net_config/tests/test_objects.py | 89 |
2 files changed, 140 insertions, 0 deletions
diff --git a/os_net_config/tests/test_impl_ifcfg.py b/os_net_config/tests/test_impl_ifcfg.py index 71ad9ae..f30eb89 100644 --- a/os_net_config/tests/test_impl_ifcfg.py +++ b/os_net_config/tests/test_impl_ifcfg.py @@ -60,12 +60,33 @@ BOOTPROTO=none _V4_IFCFG_MAPPED = _V4_IFCFG.replace('em1', 'nic1') + "HWADDR=a1:b2:c3:d4:e5\n" + +_BASE_IB_IFCFG = """# This file is autogenerated by os-net-config +DEVICE=ib0 +ONBOOT=yes +HOTPLUG=no +NM_CONTROLLED=no +PEERDNS=no +TYPE=Infiniband +""" + +_V4_IB_IFCFG = _BASE_IB_IFCFG + """BOOTPROTO=static +IPADDR=192.168.1.2 +NETMASK=255.255.255.0 +""" + _V4_IFCFG_MULTIPLE = _V4_IFCFG + """IPADDR1=192.168.1.3 NETMASK1=255.255.255.255 IPADDR2=10.0.0.2 NETMASK2=255.0.0.0 """ +_IB_V4_IFCFG_MULTIPLE = _V4_IB_IFCFG + """IPADDR1=192.168.1.3 +NETMASK1=255.255.255.255 +IPADDR2=10.0.0.2 +NETMASK2=255.0.0.0 +""" + _V6_IFCFG = _BASE_IFCFG + """IPV6INIT=yes IPV6_AUTOCONF=no IPV6ADDR=2001:abc:a::/64 @@ -505,6 +526,16 @@ class TestIfcfgNetConfig(base.TestCase): data = self.provider.generate_ivs_config(['em1'], ['storage5']) self.assertEqual(_IVS_CONFIG, data) + def test_add_ib_interface_with_v4_multiple(self): + addresses = [objects.Address('192.168.1.2/24'), + objects.Address('192.168.1.3/32'), + objects.Address('10.0.0.2/8')] + ib_interface = objects.IbInterface('ib0', addresses=addresses) + self.provider.add_interface(ib_interface) + self.assertEqual(_IB_V4_IFCFG_MULTIPLE, + self.get_interface_config('ib0')) + self.assertEqual('', self.get_route_config()) + def test_add_vlan(self): vlan = objects.Vlan('em1', 5) self.provider.add_vlan(vlan) @@ -775,6 +806,26 @@ class TestIfcfgNetConfigApply(base.TestCase): self.provider.add_interface(interface) self.provider.add_bridge(bridge) self.provider.apply() + self.assertIn('em1', self.ifup_interface_names) + + # test infiniband interfaces act as proper bridge members + ib_interface = objects.IbInterface('ib0') + bridge = objects.OvsBridge('br-ctlplane', use_dhcp=True, + members=[ib_interface]) + self.provider.add_interface(ib_interface) + self.provider.add_bridge(bridge) + self.provider.apply() + self.assertIn('ib0', self.ifup_interface_names) + self.assertIn('br-ctlplane', self.ifup_interface_names) + + # changing the bridge should restart the interface too + self.ifup_interface_names = [] + bridge = objects.OvsBridge('br-ctlplane', use_dhcp=False, + members=[ib_interface]) + self.provider.add_interface(interface) + self.provider.add_bridge(bridge) + self.provider.apply() + self.assertIn('ib0', self.ifup_interface_names) # setup and apply a bond on a bridge self.ifup_interface_names = [] diff --git a/os_net_config/tests/test_objects.py b/os_net_config/tests/test_objects.py index 7d8d3b3..51119ec 100644 --- a/os_net_config/tests/test_objects.py +++ b/os_net_config/tests/test_objects.py @@ -564,6 +564,95 @@ class TestOvsPatchPort(base.TestCase): self.assertEqual("br-ex-patch", patch_port.peer) +class TestIbInterface(base.TestCase): + + def test_ib_interface_addresses(self): + v4_addr = objects.Address('192.168.1.1/24') + v6_addr = objects.Address('2001:abc:a::/64') + ib_interface = objects.IbInterface('foo', addresses=[v4_addr, v6_addr]) + self.assertEqual("192.168.1.1", ib_interface.v4_addresses()[0].ip) + self.assertEqual("2001:abc:a::", ib_interface.v6_addresses()[0].ip) + + def test_from_json_dhcp(self): + data = '{"type": "ib_interface", "name": "ib0", "use_dhcp": true}' + ib_interface = objects.object_from_json(json.loads(data)) + self.assertEqual("ib0", ib_interface.name) + self.assertTrue(ib_interface.use_dhcp) + + def test_from_json_defroute(self): + data = '{"type": "ib_interface", "name": "ib0", "use_dhcp": true}' + ib_interface1 = objects.object_from_json(json.loads(data)) + data = """{ +"type": "ib_interface", +"name": "ib0", +"use_dhcp": true, +"defroute": false +} +""" + ib_interface2 = objects.object_from_json(json.loads(data)) + self.assertTrue(ib_interface1.defroute) + self.assertFalse(ib_interface2.defroute) + + def test_from_json_dhclient_args(self): + data = """{ +"type": "ib_interface", +"name": "ib0", +"use_dhcp": true, +"dhclient_args": "--foobar" +} +""" + ib_interface1 = objects.object_from_json(json.loads(data)) + self.assertEqual("--foobar", ib_interface1.dhclient_args) + + def test_from_json_dns_servers(self): + data = """{ +"type": "ib_interface", +"name": "ib0", +"use_dhcp": true, +"dns_servers": ["1.2.3.4"] +} +""" + ib_interface1 = objects.object_from_json(json.loads(data)) + self.assertEqual(["1.2.3.4"], ib_interface1.dns_servers) + + def test_from_json_dhcp_nic1(self): + def dummy_numbered_nics(nic_mapping=None): + return {"nic1": "ib0"} + self.stubs.Set(objects, '_numbered_nics', dummy_numbered_nics) + + data = '{"type": "ib_interface", "name": "nic1", "use_dhcp": true}' + ib_interface = objects.object_from_json(json.loads(data)) + self.assertEqual("ib0", ib_interface.name) + self.assertTrue(ib_interface.use_dhcp) + + def test_from_json_with_addresses(self): + data = """{ +"type": "ib_interface", +"name": "ib0", +"use_dhcp": false, +"mtu": 1501, +"addresses": [{ + "ip_netmask": "192.0.2.1/24" +}], +"routes": [{ + "next_hop": "192.0.2.1", + "ip_netmask": "192.0.2.1/24" +}] +} +""" + ib_interface = objects.object_from_json(json.loads(data)) + self.assertEqual("ib0", ib_interface.name) + self.assertFalse(ib_interface.use_dhcp) + self.assertFalse(ib_interface.use_dhcpv6) + self.assertEqual(1501, ib_interface.mtu) + address1 = ib_interface.v4_addresses()[0] + self.assertEqual("192.0.2.1", address1.ip) + self.assertEqual("255.255.255.0", address1.netmask) + route1 = ib_interface.routes[0] + self.assertEqual("192.0.2.1", route1.next_hop) + self.assertEqual("192.0.2.1/24", route1.ip_netmask) + + class TestNumberedNicsMapping(base.TestCase): # We want to test the function, not the dummy.. |