From 8107e5ced8f3e644e49a2fd1eff51916258c40e7 Mon Sep 17 00:00:00 2001 From: Jialiang Date: Wed, 6 Jan 2016 04:23:23 -0800 Subject: [PATCH] Update the file for IPv4-only or IPv6-only network Clean the interface template file by making both IP versions independent, including when using LXC containers. Co-Authored-By: Yongfeng Du Change-Id: If0843502fe0a85cbd5eff777d9260c90cea4812a Closes-Bug:#1355171 --- nova/tests/unit/network/test_network_info.py | 46 ++++++++++++++++++++ nova/virt/interfaces.template | 10 +++-- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/nova/tests/unit/network/test_network_info.py b/nova/tests/unit/network/test_network_info.py index 9ce228295f..93bc1b66a8 100644 --- a/nova/tests/unit/network/test_network_info.py +++ b/nova/tests/unit/network/test_network_info.py @@ -743,6 +743,52 @@ iface eth0 inet6 static template = self._setup_injected_network_scenario(use_ipv4=False) self.assertEqual(expected, template) + def test_injection_ipv6_only(self): + expected = '''\ +# Injected by Nova on instance boot +# +# This file describes the network interfaces available on your system +# and how to activate them. For more information, see interfaces(5). + +# The loopback network interface +auto lo +iface lo inet loopback + +auto eth0 +iface eth0 inet6 static + hwaddress ether aa:aa:aa:aa:aa:aa + address 1234:567::2 + netmask 48 + gateway 1234:567::1 + dns-nameservers 2001:4860:4860::8888 2001:4860:4860::8844 +''' + template = self._setup_injected_network_scenario(use_ipv4=False, + use_ipv6=True) + self.assertEqual(expected, template) + + def test_injection_ipv6_only_no_gateway(self): + expected = '''\ +# Injected by Nova on instance boot +# +# This file describes the network interfaces available on your system +# and how to activate them. For more information, see interfaces(5). + +# The loopback network interface +auto lo +iface lo inet loopback + +auto eth0 +iface eth0 inet6 static + hwaddress ether aa:aa:aa:aa:aa:aa + address 1234:567::2 + netmask 48 + dns-nameservers 2001:4860:4860::8888 2001:4860:4860::8844 +''' + template = self._setup_injected_network_scenario(use_ipv4=False, + use_ipv6=True, + gateway=False) + self.assertEqual(expected, template) + def test_injection_ipv6_two_interfaces(self): expected = """\ # Injected by Nova on instance boot diff --git a/nova/virt/interfaces.template b/nova/virt/interfaces.template index ee78a1fc60..453ac43a8f 100644 --- a/nova/virt/interfaces.template +++ b/nova/virt/interfaces.template @@ -9,6 +9,7 @@ iface lo inet loopback {% for ifc in interfaces %} auto {{ ifc.name }} +{% if ifc.address %} iface {{ ifc.name }} inet static hwaddress ether {{ ifc.hwaddress }} address {{ ifc.address }} @@ -20,11 +21,11 @@ iface {{ ifc.name }} inet static {% if ifc.dns %} dns-nameservers {{ ifc.dns }} {% endif %} -{% if use_ipv6 %} -{% if libvirt_virt_type == 'lxc' %} -{% if ifc.address_v6 %} - post-up ip -6 addr add {{ ifc.address_v6 }}/{{ifc.netmask_v6 }} dev ${IFACE} {% endif %} +{% if use_ipv6 %} +{% if ifc.address_v6 %} +{% if libvirt_virt_type == 'lxc' %} + post-up ip -6 addr add {{ ifc.address_v6 }}/{{ifc.netmask_v6 }} dev ${IFACE} {% if ifc.gateway_v6 %} post-up ip -6 route add default via {{ ifc.gateway_v6 }} dev ${IFACE} {% endif %} @@ -41,4 +42,5 @@ iface {{ ifc.name }} inet6 static {% endif %} {% endif %} {% endif %} +{% endif %} {% endfor %}