Merge ~smoser/cloud-init:bug/1621615 into cloud-init:master

Proposed by Scott Moser
Status: Merged
Merged at revision: 868cdaaa5d4d9426df5764a2fe916f2c38923699
Proposed branch: ~smoser/cloud-init:bug/1621615
Merge into: cloud-init:master
Diff against target: 104 lines (+53/-5)
2 files modified
cloudinit/net/cmdline.py (+10/-5)
tests/unittests/test_net.py (+43/-0)
Reviewer Review Type Date Requested Status
cloud-init Commiters Pending
Review via email: mp+306345@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

I'm getting a test case written for this.

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/net/cmdline.py b/cloudinit/net/cmdline.py
2index 822a020..933317d 100644
3--- a/cloudinit/net/cmdline.py
4+++ b/cloudinit/net/cmdline.py
5@@ -66,7 +66,9 @@ def _klibc_to_config_entry(content, mac_addrs=None):
6 provided here. There is no good documentation on this unfortunately.
7
8 DEVICE=<name> is expected/required and PROTO should indicate if
9- this is 'static' or 'dhcp'.
10+ this is 'static' or 'dhcp' or 'dhcp6' (LP: #1621507).
11+ note that IPV6PROTO is also written by newer code to address the
12+ possibility of both ipv4 and ipv6 getting addresses.
13 """
14
15 if mac_addrs is None:
16@@ -86,7 +88,7 @@ def _klibc_to_config_entry(content, mac_addrs=None):
17 else:
18 proto = 'static'
19
20- if proto not in ('static', 'dhcp'):
21+ if proto not in ('static', 'dhcp', 'dhcp6'):
22 raise ValueError("Unexpected value for PROTO: %s" % proto)
23
24 iface = {
25@@ -98,12 +100,15 @@ def _klibc_to_config_entry(content, mac_addrs=None):
26 if name in mac_addrs:
27 iface['mac_address'] = mac_addrs[name]
28
29- # originally believed there might be IPV6* values
30- for v, pre in (('ipv4', 'IPV4'),):
31+ # Handle both IPv4 and IPv6 values
32+ for v, pre in (('ipv4', 'IPV4'), ('ipv6', 'IPV6')):
33 # if no IPV4ADDR or IPV6ADDR, then go on.
34 if pre + "ADDR" not in data:
35 continue
36- subnet = {'type': proto, 'control': 'manual'}
37+
38+ # PROTO for ipv4, IPV6PROTO for ipv6
39+ cur_proto = data.get(pre + 'PROTO', proto)
40+ subnet = {'type': cur_proto, 'control': 'manual'}
41
42 # these fields go right on the subnet
43 for key in ('NETMASK', 'BROADCAST', 'GATEWAY'):
44diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
45index 41b9a6d..78c080c 100644
46--- a/tests/unittests/test_net.py
47+++ b/tests/unittests/test_net.py
48@@ -53,6 +53,45 @@ DHCP_EXPECTED_1 = {
49 'dns_nameservers': ['192.168.122.1']}],
50 }
51
52+DHCP6_CONTENT_1 = """
53+DEVICE=eno1
54+HOSTNAME=
55+DNSDOMAIN=
56+reason='PREINIT'
57+interface='eno1'
58+DEVICE=eno1
59+HOSTNAME=
60+DNSDOMAIN=
61+reason='FAIL'
62+interface='eno1'
63+DEVICE=eno1
64+HOSTNAME=
65+DNSDOMAIN=
66+reason='PREINIT6'
67+interface='eno1'
68+DEVICE=eno1
69+IPV6PROTO=dhcp6
70+IPV6ADDR=2001:67c:1562:8010:0:1::
71+IPV6NETMASK=64
72+IPV6DNS0=2001:67c:1562:8010::2:1
73+IPV6DOMAINSEARCH=
74+HOSTNAME=
75+DNSDOMAIN=
76+reason='BOUND6'
77+interface='eno1'
78+new_ip6_address='2001:67c:1562:8010:0:1::'
79+new_ip6_prefixlen='64'
80+new_dhcp6_name_servers='2001:67c:1562:8010::2:1'
81+"""
82+
83+DHCP6_EXPECTED_1 = {
84+ 'name': 'eno1',
85+ 'type': 'physical',
86+ 'subnets': [{'control': 'manual',
87+ 'dns_nameservers': ['2001:67c:1562:8010::2:1'],
88+ 'netmask': '64',
89+ 'type': 'dhcp6'}]}
90+
91
92 STATIC_CONTENT_1 = """
93 DEVICE='eth1'
94@@ -590,6 +629,10 @@ class TestCmdlineConfigParsing(TestCase):
95 found = cmdline._klibc_to_config_entry(DHCP_CONTENT_1)
96 self.assertEqual(found, ('eth0', DHCP_EXPECTED_1))
97
98+ def test_cmdline_convert_dhcp6(self):
99+ found = cmdline._klibc_to_config_entry(DHCP6_CONTENT_1)
100+ self.assertEqual(found, ('eno1', DHCP6_EXPECTED_1))
101+
102 def test_cmdline_convert_static(self):
103 found = cmdline._klibc_to_config_entry(STATIC_CONTENT_1)
104 self.assertEqual(found, ('eth1', STATIC_EXPECTED_1))

Subscribers

People subscribed via source and target branches