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
diff --git a/cloudinit/net/netplan.py b/cloudinit/net/netplan.py
index 6bee3d3..6344348 100644
--- a/cloudinit/net/netplan.py
+++ b/cloudinit/net/netplan.py
@@ -336,22 +336,15 @@ class Renderer(renderer.Renderer):
336 _extract_addresses(ifcfg, vlan)336 _extract_addresses(ifcfg, vlan)
337 vlans.update({ifname: vlan})337 vlans.update({ifname: vlan})
338338
339 # inject global nameserver values under each physical interface339 # inject global nameserver values under each all interface which
340 if nameservers:340 # has addresses and do not already have a DNS configuration
341 for _eth, cfg in ethernets.items():341 if nameservers or searchdomains:
342 nscfg = cfg.get('nameservers', {})342 nscfg = {'addresses': nameservers, 'search': searchdomains}
343 addresses = nscfg.get('addresses', [])343 for section in [ethernets, wifis, bonds, bridges, vlans]:
344 addresses += nameservers344 for _name, cfg in section.items():
345 nscfg.update({'addresses': addresses})345 if 'nameservers' in cfg or 'addresses' not in cfg:
346 cfg.update({'nameservers': nscfg})346 continue
347347 cfg.update({'nameservers': nscfg})
348 if searchdomains:
349 for _eth, cfg in ethernets.items():
350 nscfg = cfg.get('nameservers', {})
351 search = nscfg.get('search', [])
352 search += searchdomains
353 nscfg.update({'search': search})
354 cfg.update({'nameservers': nscfg})
355348
356 # workaround yaml dictionary key sorting when dumping349 # workaround yaml dictionary key sorting when dumping
357 def _render_section(name, section):350 def _render_section(name, section):
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index 84a0eab..c12a487 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -393,12 +393,6 @@ NETWORK_CONFIGS = {
393 eth1:393 eth1:
394 match:394 match:
395 macaddress: cf:d6:af:48:e8:80395 macaddress: cf:d6:af:48:e8:80
396 nameservers:
397 addresses:
398 - 1.2.3.4
399 - 5.6.7.8
400 search:
401 - wark.maas
402 set-name: eth1396 set-name: eth1
403 eth99:397 eth99:
404 addresses:398 addresses:
@@ -410,12 +404,9 @@ NETWORK_CONFIGS = {
410 addresses:404 addresses:
411 - 8.8.8.8405 - 8.8.8.8
412 - 8.8.4.4406 - 8.8.4.4
413 - 1.2.3.4
414 - 5.6.7.8
415 search:407 search:
416 - barley.maas408 - barley.maas
417 - sach.maas409 - sach.maas
418 - wark.maas
419 routes:410 routes:
420 - to: 0.0.0.0/0411 - to: 0.0.0.0/0
421 via: 65.61.151.37412 via: 65.61.151.37
@@ -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
654 eth0:645 eth0:
655 match:646 match:
656 macaddress: c0:d6:9f:2c:e8:80647 macaddress: c0:d6:9f:2c:e8:80
657 nameservers:
658 addresses:
659 - 8.8.8.8
660 - 4.4.4.4
661 - 8.8.4.4
662 search:
663 - barley.maas
664 - wark.maas
665 - foobar.maas
666 set-name: eth0648 set-name: eth0
667 eth1:649 eth1:
668 match:650 match:
669 macaddress: aa:d6:9f:2c:e8:80651 macaddress: aa:d6:9f:2c:e8:80
670 nameservers:
671 addresses:
672 - 8.8.8.8
673 - 4.4.4.4
674 - 8.8.4.4
675 search:
676 - barley.maas
677 - wark.maas
678 - foobar.maas
679 set-name: eth1652 set-name: eth1
680 eth2:653 eth2:
681 match:654 match:
682 macaddress: c0:bb:9f:2c:e8:80655 macaddress: c0:bb:9f:2c:e8:80
683 nameservers:
684 addresses:
685 - 8.8.8.8
686 - 4.4.4.4
687 - 8.8.4.4
688 search:
689 - barley.maas
690 - wark.maas
691 - foobar.maas
692 set-name: eth2656 set-name: eth2
693 eth3:657 eth3:
694 match:658 match:
695 macaddress: 66:bb:9f:2c:e8:80659 macaddress: 66:bb:9f:2c:e8:80
696 nameservers:
697 addresses:
698 - 8.8.8.8
699 - 4.4.4.4
700 - 8.8.4.4
701 search:
702 - barley.maas
703 - wark.maas
704 - foobar.maas
705 set-name: eth3660 set-name: eth3
706 eth4:661 eth4:
707 match:662 match:
708 macaddress: 98:bb:9f:2c:e8:80663 macaddress: 98:bb:9f:2c:e8:80
709 nameservers:
710 addresses:
711 - 8.8.8.8
712 - 4.4.4.4
713 - 8.8.4.4
714 search:
715 - barley.maas
716 - wark.maas
717 - foobar.maas
718 set-name: eth4664 set-name: eth4
719 eth5:665 eth5:
720 dhcp4: true666 dhcp4: true
721 match:667 match:
722 macaddress: 98:bb:9f:2c:e8:8a668 macaddress: 98:bb:9f:2c:e8:8a
723 nameservers:
724 addresses:
725 - 8.8.8.8
726 - 4.4.4.4
727 - 8.8.4.4
728 search:
729 - barley.maas
730 - wark.maas
731 - foobar.maas
732 set-name: eth5669 set-name: eth5
733 bonds:670 bonds:
734 bond0:671 bond0:
@@ -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
748 interfaces:685 interfaces:
749 - eth3686 - eth3
750 - eth4687 - eth4
688 nameservers:
689 addresses:
690 - 8.8.8.8
691 - 4.4.4.4
692 - 8.8.4.4
693 search:
694 - barley.maas
695 - wark.maas
696 - foobar.maas
751 parameters:697 parameters:
752 ageing-time: 250698 ageing-time: 250
753 forward-delay: 1699 forward-delay: 1
@@ -2334,6 +2280,9 @@ class TestNetplanRoundTrip(CiTestCase):
2334 def testsimple_render_all(self):2280 def testsimple_render_all(self):
2335 entry = NETWORK_CONFIGS['all']2281 entry = NETWORK_CONFIGS['all']
2336 files = self._render_and_read(network_config=yaml.load(entry['yaml']))2282 files = self._render_and_read(network_config=yaml.load(entry['yaml']))
2283 print(entry['expected_netplan'])
2284 print('-- expected ^ | v rendered --')
2285 print(files['/etc/netplan/50-cloud-init.yaml'])
2337 self.assertEqual(2286 self.assertEqual(
2338 entry['expected_netplan'].splitlines(),2287 entry['expected_netplan'].splitlines(),
2339 files['/etc/netplan/50-cloud-init.yaml'].splitlines())2288 files['/etc/netplan/50-cloud-init.yaml'].splitlines())

Subscribers

People subscribed via source and target branches