diff options
author | Dan Prince <dprince@redhat.com> | 2014-07-02 11:21:09 -0400 |
---|---|---|
committer | Dan Prince <dprince@redhat.com> | 2014-07-02 11:21:09 -0400 |
commit | a101740ac3346ae3645dbbff4df8b8f333a59b67 (patch) | |
tree | d48417a04ed03b209f0be67d56fb8db94b08f7ef /os_net_config | |
parent | 50290b0e45429c207a5640979f3b0eee7aabfe20 (diff) |
ENI fixes for v4/v6 ips. DHCP test fixes.
Updates the ENI format so it creates multiple config sections
for a single os-net-config interface object if both v4 and v6
IP addresses are defined.
Also, fixes several of the test so that DHCP is not enabled on
OvsPorts. If an OVS port is part of a bridge that is itself using
DHCP we don't also need to run DHCP on the OvsPort interface.
Diffstat (limited to 'os_net_config')
-rw-r--r-- | os_net_config/impl_eni.py | 49 | ||||
-rw-r--r-- | os_net_config/tests/test_impl_eni.py | 64 |
2 files changed, 67 insertions, 46 deletions
diff --git a/os_net_config/impl_eni.py b/os_net_config/impl_eni.py index 20677da..56cb3bf 100644 --- a/os_net_config/impl_eni.py +++ b/os_net_config/impl_eni.py @@ -27,7 +27,7 @@ def _network_config_path(): class ENINetConfig(os_net_config.NetConfig): - """Ubuntu/Debian implementation for network config + """Debian/Ubuntu implementation for network config Configure iface/bridge/routes using debian/ubuntu /etc/network/interfaces format. @@ -38,20 +38,27 @@ class ENINetConfig(os_net_config.NetConfig): self.routes = {} self.bridges = {} - def _addCommon(self, interface): + def _addCommon(self, interface, static_addr=None): - def _static_addresses(_v4, _v6): - addr = _v4 + _v6 - address_data = "" - if addr: - address_data += "address %s\n" % addr[0].ip - address_data += "netmask %s\n" % addr[0].netmask - return address_data + data = "" + address_data = "" + if static_addr: + address_data += " address %s\n" % static_addr.ip + address_data += " netmask %s\n" % static_addr.netmask + else: + v4_addresses = interface.v4_addresses() + if v4_addresses: + data += self._addCommon(interface, v4_addresses[0]) + + v6_addresses = interface.v6_addresses() + if v6_addresses: + data += self._addCommon(interface, v6_addresses[0]) + + if data: + return data - _v6 = interface.v6_addresses() - _v4 = interface.v4_addresses() _iface = "iface %s " % interface.name - if _v6: + if static_addr and static_addr.version == 6: _iface += "inet6 " else: _iface += "inet " @@ -61,27 +68,29 @@ class ENINetConfig(os_net_config.NetConfig): _iface += "static\n" else: _iface += "manual\n" - data = "" if isinstance(interface, objects.OvsBridge): data += "allow-ovs %s\n" % interface.name data += _iface - data += _static_addresses(_v4, _v6) - data += "ovs_type OVSBridge\n" + data += address_data + data += " ovs_type OVSBridge\n" if interface.members: - data += "ovs_ports" + data += " ovs_ports" for i in interface.members: data += " %s" % i.name data += "\n" + for i in interface.members: + data += " pre-up ip addr flush dev %s\n" % i.name elif interface.ovs_port: + data += "auto %s\n" % interface.name data += "allow-%s %s\n" % (interface.bridge_name, interface.name) data += _iface - data += _static_addresses(_v4, _v6) - data += "ovs_bridge %s\n" % interface.bridge_name - data += "ovs_type OVSPort\n" + data += address_data + data += " ovs_bridge %s\n" % interface.bridge_name + data += " ovs_type OVSPort\n" else: data += "auto %s\n" % interface.name data += _iface - data += _static_addresses(_v4, _v6) + data += address_data return data def addInterface(self, interface): diff --git a/os_net_config/tests/test_impl_eni.py b/os_net_config/tests/test_impl_eni.py index 55c9c44..8bd25d7 100644 --- a/os_net_config/tests/test_impl_eni.py +++ b/os_net_config/tests/test_impl_eni.py @@ -23,31 +23,32 @@ from os_net_config import utils _AUTO = "auto eth0\n" -_BASE_IFACE = "iface eth0" +_v4_IFACE_NO_IP = _AUTO + "iface eth0 inet manual\n" -_v4_IFACE_NO_IP = _AUTO + _BASE_IFACE + " inet manual\n" - -_V4_IFACE_STATIC_IP = _AUTO + _BASE_IFACE + """ inet static -address 192.168.1.2 -netmask 255.255.255.0 +_V4_IFACE_STATIC_IP = _AUTO + """iface eth0 inet static + address 192.168.1.2 + netmask 255.255.255.0 """ -_V6_IFACE_STATIC_IP = _AUTO + _BASE_IFACE + """ inet6 static -address fe80::2677:3ff:fe7d:4c -netmask ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff +_V6_IFACE_STATIC_IP = _AUTO + """iface eth0 inet6 static + address fe80::2677:3ff:fe7d:4c + netmask ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff """ -_OVS_PORT_BASE = "allow-br0 eth0\n" +_IFACE_DHCP = _AUTO + "iface eth0 inet dhcp\n" -_OVS_IFACE_DHCP = _BASE_IFACE + " inet dhcp\n" +_OVS_PORT_BASE = _AUTO + "allow-br0 eth0\n" -_OVS_PORT_IFACE = _OVS_PORT_BASE + _OVS_IFACE_DHCP + """ovs_bridge br0 -ovs_type OVSPort\n""" +_OVS_PORT_IFACE = _OVS_PORT_BASE + """iface eth0 inet manual + ovs_bridge br0 + ovs_type OVSPort +""" _OVS_BRIDGE_DHCP = """allow-ovs br0 iface br0 inet dhcp -ovs_type OVSBridge -ovs_ports eth0 + ovs_type OVSBridge + ovs_ports eth0 + pre-up ip addr flush dev eth0 """ _RTS = """up route add -net 172.19.0.0 netmask 255.255.255.0 gw 192.168.1.1 @@ -75,19 +76,11 @@ class TestENINetConfig(base.TestCase): def _default_interface(self, addr=[], rts=[]): return objects.Interface(self.if_name, addresses=addr, routes=rts) - def test_add_base_interface(self): + def test_interface_no_ip(self): interface = self._default_interface() self.provider.addInterface(interface) self.assertEqual(_v4_IFACE_NO_IP, self.get_interface_config()) - def test_add_ovs_port_interface(self): - interface = self._default_interface() - interface.ovs_port = True - interface.bridge_name = 'br0' - interface.use_dhcp = True - self.provider.addInterface(interface) - self.assertEqual(_OVS_PORT_IFACE, self.get_interface_config()) - def test_add_interface_with_v4(self): v4_addr = objects.Address('192.168.1.2/24') interface = self._default_interface([v4_addr]) @@ -100,6 +93,27 @@ class TestENINetConfig(base.TestCase): self.provider.addInterface(interface) self.assertEqual(_V6_IFACE_STATIC_IP, self.get_interface_config()) + def test_add_interface_dhcp(self): + interface = self._default_interface() + interface.use_dhcp = True + self.provider.addInterface(interface) + self.assertEqual(_IFACE_DHCP, self.get_interface_config()) + + def test_add_interface_with_both_v4_and_v6(self): + v4_addr = objects.Address('192.168.1.2/24') + v6_addr = objects.Address('fe80::2677:3ff:fe7d:4c') + interface = self._default_interface([v4_addr, v6_addr]) + self.provider.addInterface(interface) + self.assertEqual(_V4_IFACE_STATIC_IP + _V6_IFACE_STATIC_IP, + self.get_interface_config()) + + def test_add_ovs_port_interface(self): + interface = self._default_interface() + interface.ovs_port = True + interface.bridge_name = 'br0' + self.provider.addInterface(interface) + self.assertEqual(_OVS_PORT_IFACE, self.get_interface_config()) + def test_network_with_routes(self): route1 = objects.Route('192.168.1.1', '172.19.0.0/24') v4_addr = objects.Address('192.168.1.2/24') @@ -110,7 +124,6 @@ class TestENINetConfig(base.TestCase): def test_network_ovs_bridge_with_dhcp(self): interface = self._default_interface() - interface.use_dhcp = True bridge = objects.OvsBridge('br0', use_dhcp=True, members=[interface]) self.provider.addBridge(bridge) @@ -152,7 +165,6 @@ class TestENINetConfigApply(base.TestCase): def test_dhcp_ovs_bridge_network_apply(self): interface = objects.Interface('eth0') - interface.use_dhcp = True bridge = objects.OvsBridge('br0', use_dhcp=True, members=[interface]) self.provider.addInterface(interface) |