summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloudinit/net/cmdline.py15
-rw-r--r--tests/unittests/test_net.py43
2 files changed, 53 insertions, 5 deletions
diff --git a/cloudinit/net/cmdline.py b/cloudinit/net/cmdline.py
index 822a020b..933317d5 100644
--- a/cloudinit/net/cmdline.py
+++ b/cloudinit/net/cmdline.py
@@ -66,7 +66,9 @@ def _klibc_to_config_entry(content, mac_addrs=None):
provided here. There is no good documentation on this unfortunately.
DEVICE=<name> is expected/required and PROTO should indicate if
- this is 'static' or 'dhcp'.
+ this is 'static' or 'dhcp' or 'dhcp6' (LP: #1621507).
+ note that IPV6PROTO is also written by newer code to address the
+ possibility of both ipv4 and ipv6 getting addresses.
"""
if mac_addrs is None:
@@ -86,7 +88,7 @@ def _klibc_to_config_entry(content, mac_addrs=None):
else:
proto = 'static'
- if proto not in ('static', 'dhcp'):
+ if proto not in ('static', 'dhcp', 'dhcp6'):
raise ValueError("Unexpected value for PROTO: %s" % proto)
iface = {
@@ -98,12 +100,15 @@ def _klibc_to_config_entry(content, mac_addrs=None):
if name in mac_addrs:
iface['mac_address'] = mac_addrs[name]
- # originally believed there might be IPV6* values
- for v, pre in (('ipv4', 'IPV4'),):
+ # Handle both IPv4 and IPv6 values
+ for v, pre in (('ipv4', 'IPV4'), ('ipv6', 'IPV6')):
# if no IPV4ADDR or IPV6ADDR, then go on.
if pre + "ADDR" not in data:
continue
- subnet = {'type': proto, 'control': 'manual'}
+
+ # PROTO for ipv4, IPV6PROTO for ipv6
+ cur_proto = data.get(pre + 'PROTO', proto)
+ subnet = {'type': cur_proto, 'control': 'manual'}
# these fields go right on the subnet
for key in ('NETMASK', 'BROADCAST', 'GATEWAY'):
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index 41b9a6d0..78c080ca 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -53,6 +53,45 @@ DHCP_EXPECTED_1 = {
'dns_nameservers': ['192.168.122.1']}],
}
+DHCP6_CONTENT_1 = """
+DEVICE=eno1
+HOSTNAME=
+DNSDOMAIN=
+reason='PREINIT'
+interface='eno1'
+DEVICE=eno1
+HOSTNAME=
+DNSDOMAIN=
+reason='FAIL'
+interface='eno1'
+DEVICE=eno1
+HOSTNAME=
+DNSDOMAIN=
+reason='PREINIT6'
+interface='eno1'
+DEVICE=eno1
+IPV6PROTO=dhcp6
+IPV6ADDR=2001:67c:1562:8010:0:1::
+IPV6NETMASK=64
+IPV6DNS0=2001:67c:1562:8010::2:1
+IPV6DOMAINSEARCH=
+HOSTNAME=
+DNSDOMAIN=
+reason='BOUND6'
+interface='eno1'
+new_ip6_address='2001:67c:1562:8010:0:1::'
+new_ip6_prefixlen='64'
+new_dhcp6_name_servers='2001:67c:1562:8010::2:1'
+"""
+
+DHCP6_EXPECTED_1 = {
+ 'name': 'eno1',
+ 'type': 'physical',
+ 'subnets': [{'control': 'manual',
+ 'dns_nameservers': ['2001:67c:1562:8010::2:1'],
+ 'netmask': '64',
+ 'type': 'dhcp6'}]}
+
STATIC_CONTENT_1 = """
DEVICE='eth1'
@@ -590,6 +629,10 @@ class TestCmdlineConfigParsing(TestCase):
found = cmdline._klibc_to_config_entry(DHCP_CONTENT_1)
self.assertEqual(found, ('eth0', DHCP_EXPECTED_1))
+ def test_cmdline_convert_dhcp6(self):
+ found = cmdline._klibc_to_config_entry(DHCP6_CONTENT_1)
+ self.assertEqual(found, ('eno1', DHCP6_EXPECTED_1))
+
def test_cmdline_convert_static(self):
found = cmdline._klibc_to_config_entry(STATIC_CONTENT_1)
self.assertEqual(found, ('eth1', STATIC_EXPECTED_1))