diff --git a/nova/tests/unit/network/test_network_info.py b/nova/tests/unit/network/test_network_info.py index 0420e2d791..1c604975b0 100644 --- a/nova/tests/unit/network/test_network_info.py +++ b/nova/tests/unit/network/test_network_info.py @@ -738,6 +738,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 %}