Merge ~raharper/cloud-init:fix/lp-1750884-netplan-global-dns into cloud-init:master

Proposed by Ryan Harper
Status: Merged
Approved by: Chad Smith
Approved revision: ade07170a207d456d6742e913f54334dad0078ce
Merge reported by: Chad Smith
Merged at revision: d29eeccd2c422b8eb3b053fc13ca966ed6d74c78
Proposed branch: ~raharper/cloud-init:fix/lp-1750884-netplan-global-dns
Merge into: cloud-init:master
Diff against target: 174 lines (+21/-79)
2 files modified
cloudinit/net/netplan.py (+9/-16)
tests/unittests/test_net.py (+12/-63)
Reviewer Review Type Date Requested Status
Chad Smith Abstain
Server Team CI bot continuous-integration Approve
Scott Moser Approve
Review via email: mp+341662@code.launchpad.net

Commit message

Handle global dns entries in netplan

In network config v1 format, there are dns values which are not bound to a
specific interface and do not map to the per-interface format in netplan.
To handle this case we render netplan configuration that duplicates the
DNS configuration on any interface that has a static network config. We
avoiding interfaces which have DHCP configuration which may provide
conflicting DNS values.

LP: #1750884

Description of the change

see commit message.

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:36f1a4240e804a3e785ffd82ed5ce76d2386204e
https://jenkins.ubuntu.com/server/job/cloud-init-ci/880/
Executed test runs:
    SUCCESS: Checkout
    FAILED: Unit & Style Tests

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/880/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote :

this looks fine to me.
wait on c-i approval.

review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:ade07170a207d456d6742e913f54334dad0078ce
https://jenkins.ubuntu.com/server/job/cloud-init-ci/906/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/906/rebuild

review: Approve (continuous-integration)
Revision history for this message
Chad Smith (chad.smith) wrote :

Thank you for your merge proposal.

Your branch has been set to 'Work in progress'.
Please set the branch back to 'Needs Review' after resolving the issues below.

Thanks again,
Your friendly neighborhood cloud-init robot.

Please fix the following issues:
------------------------------
Commit message lints:
 - Line #4 has 3 too many characters. Line starts with: "netplan. To handle this"...
------------------------------

For more information, see commit message guidelines at
https://cloudinit.readthedocs.io/en/latest/topics/hacking.html#do-these-things-for-each-feature-or-bug

review: Needs Fixing
Revision history for this message
Chad Smith (chad.smith) wrote :

An upstream commit landed for this bug.

To view that commit see the following URL:
https://git.launchpad.net/cloud-init/commit/?id=d29eeccd

Revision history for this message
Chad Smith (chad.smith) :
review: Abstain

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/net/netplan.py b/cloudinit/net/netplan.py
2index 6bee3d3..6344348 100644
3--- a/cloudinit/net/netplan.py
4+++ b/cloudinit/net/netplan.py
5@@ -336,22 +336,15 @@ class Renderer(renderer.Renderer):
6 _extract_addresses(ifcfg, vlan)
7 vlans.update({ifname: vlan})
8
9- # inject global nameserver values under each physical interface
10- if nameservers:
11- for _eth, cfg in ethernets.items():
12- nscfg = cfg.get('nameservers', {})
13- addresses = nscfg.get('addresses', [])
14- addresses += nameservers
15- nscfg.update({'addresses': addresses})
16- cfg.update({'nameservers': nscfg})
17-
18- if searchdomains:
19- for _eth, cfg in ethernets.items():
20- nscfg = cfg.get('nameservers', {})
21- search = nscfg.get('search', [])
22- search += searchdomains
23- nscfg.update({'search': search})
24- cfg.update({'nameservers': nscfg})
25+ # inject global nameserver values under each all interface which
26+ # has addresses and do not already have a DNS configuration
27+ if nameservers or searchdomains:
28+ nscfg = {'addresses': nameservers, 'search': searchdomains}
29+ for section in [ethernets, wifis, bonds, bridges, vlans]:
30+ for _name, cfg in section.items():
31+ if 'nameservers' in cfg or 'addresses' not in cfg:
32+ continue
33+ cfg.update({'nameservers': nscfg})
34
35 # workaround yaml dictionary key sorting when dumping
36 def _render_section(name, section):
37diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
38index 84a0eab..c12a487 100644
39--- a/tests/unittests/test_net.py
40+++ b/tests/unittests/test_net.py
41@@ -393,12 +393,6 @@ NETWORK_CONFIGS = {
42 eth1:
43 match:
44 macaddress: cf:d6:af:48:e8:80
45- nameservers:
46- addresses:
47- - 1.2.3.4
48- - 5.6.7.8
49- search:
50- - wark.maas
51 set-name: eth1
52 eth99:
53 addresses:
54@@ -410,12 +404,9 @@ NETWORK_CONFIGS = {
55 addresses:
56 - 8.8.8.8
57 - 8.8.4.4
58- - 1.2.3.4
59- - 5.6.7.8
60 search:
61 - barley.maas
62 - sach.maas
63- - wark.maas
64 routes:
65 - to: 0.0.0.0/0
66 via: 65.61.151.37
67@@ -654,81 +645,27 @@ pre-down route del -net 10.0.0.0 netmask 255.0.0.0 gw 11.0.0.1 metric 3 || true
68 eth0:
69 match:
70 macaddress: c0:d6:9f:2c:e8:80
71- nameservers:
72- addresses:
73- - 8.8.8.8
74- - 4.4.4.4
75- - 8.8.4.4
76- search:
77- - barley.maas
78- - wark.maas
79- - foobar.maas
80 set-name: eth0
81 eth1:
82 match:
83 macaddress: aa:d6:9f:2c:e8:80
84- nameservers:
85- addresses:
86- - 8.8.8.8
87- - 4.4.4.4
88- - 8.8.4.4
89- search:
90- - barley.maas
91- - wark.maas
92- - foobar.maas
93 set-name: eth1
94 eth2:
95 match:
96 macaddress: c0:bb:9f:2c:e8:80
97- nameservers:
98- addresses:
99- - 8.8.8.8
100- - 4.4.4.4
101- - 8.8.4.4
102- search:
103- - barley.maas
104- - wark.maas
105- - foobar.maas
106 set-name: eth2
107 eth3:
108 match:
109 macaddress: 66:bb:9f:2c:e8:80
110- nameservers:
111- addresses:
112- - 8.8.8.8
113- - 4.4.4.4
114- - 8.8.4.4
115- search:
116- - barley.maas
117- - wark.maas
118- - foobar.maas
119 set-name: eth3
120 eth4:
121 match:
122 macaddress: 98:bb:9f:2c:e8:80
123- nameservers:
124- addresses:
125- - 8.8.8.8
126- - 4.4.4.4
127- - 8.8.4.4
128- search:
129- - barley.maas
130- - wark.maas
131- - foobar.maas
132 set-name: eth4
133 eth5:
134 dhcp4: true
135 match:
136 macaddress: 98:bb:9f:2c:e8:8a
137- nameservers:
138- addresses:
139- - 8.8.8.8
140- - 4.4.4.4
141- - 8.8.4.4
142- search:
143- - barley.maas
144- - wark.maas
145- - foobar.maas
146 set-name: eth5
147 bonds:
148 bond0:
149@@ -748,6 +685,15 @@ pre-down route del -net 10.0.0.0 netmask 255.0.0.0 gw 11.0.0.1 metric 3 || true
150 interfaces:
151 - eth3
152 - eth4
153+ nameservers:
154+ addresses:
155+ - 8.8.8.8
156+ - 4.4.4.4
157+ - 8.8.4.4
158+ search:
159+ - barley.maas
160+ - wark.maas
161+ - foobar.maas
162 parameters:
163 ageing-time: 250
164 forward-delay: 1
165@@ -2334,6 +2280,9 @@ class TestNetplanRoundTrip(CiTestCase):
166 def testsimple_render_all(self):
167 entry = NETWORK_CONFIGS['all']
168 files = self._render_and_read(network_config=yaml.load(entry['yaml']))
169+ print(entry['expected_netplan'])
170+ print('-- expected ^ | v rendered --')
171+ print(files['/etc/netplan/50-cloud-init.yaml'])
172 self.assertEqual(
173 entry['expected_netplan'].splitlines(),
174 files['/etc/netplan/50-cloud-init.yaml'].splitlines())

Subscribers

People subscribed via source and target branches