Merge ~raharper/cloud-init:sysconfig-resolvconf-duplicate-header-lp1701420 into cloud-init:master

Proposed by Ryan Harper
Status: Merged
Approved by: Scott Moser
Approved revision: 491585acd21b21dc18defc90cc1e00489ea00769
Merged at revision: 56103567fbf486625cdf5bfe40eea5ddcb7e8e04
Proposed branch: ~raharper/cloud-init:sysconfig-resolvconf-duplicate-header-lp1701420
Merge into: cloud-init:master
Diff against target: 31 lines (+8/-1)
2 files modified
cloudinit/net/ (+5/-1)
tests/unittests/ (+3/-0)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Needs Fixing
cloud-init Commiters Pending
Review via email:

Description of the change

sysconfig: Dont repeat header when rendering resolv.conf

The sysconfig renderer duplicates the cloud-init header string
when rendering resolv.conf file. This leads to resolv.conf file
growing with every reboot of a system. Fix this by checking for
the header when loading content from existing file.

Update one of the sysconfig unittests with multiple render calls
to simulate the reboot to check that we don't repeat the header.

LP: #1701420

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:491585acd21b21dc18defc90cc1e00489ea00769
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    FAILED: CentOS 6 & 7: Build & Test

Click here to trigger a rebuild:

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

I think this is fine. It makes sense.
the other way to fix this is to fix
 to fix that we will stop writing resolv.conf but rather delegating that to sysconfig.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/cloudinit/net/ b/cloudinit/net/
index a550f97..f572796 100644
--- a/cloudinit/net/
+++ b/cloudinit/net/
@@ -484,7 +484,11 @@ class Renderer(renderer.Renderer):
484 content.add_nameserver(nameserver)484 content.add_nameserver(nameserver)
485 for searchdomain in network_state.dns_searchdomains:485 for searchdomain in network_state.dns_searchdomains:
486 content.add_search_domain(searchdomain)486 content.add_search_domain(searchdomain)
487 return "\n".join([_make_header(';'), str(content)])487 header = _make_header(';')
488 content_str = str(content)
489 if not content_str.startswith(header):
490 content_str = header + '\n' + content_str
491 return content_str
489 @staticmethod493 @staticmethod
490 def _render_networkmanager_conf(network_state):494 def _render_networkmanager_conf(network_state):
diff --git a/tests/unittests/ b/tests/unittests/
index e49abcc..4653be1 100644
--- a/tests/unittests/
+++ b/tests/unittests/
@@ -1683,6 +1683,9 @@ USERCTL=no
1683 ns = network_state.parse_net_config_data(network_cfg,1683 ns = network_state.parse_net_config_data(network_cfg,
1684 skip_broken=False)1684 skip_broken=False)
1685 renderer = sysconfig.Renderer()1685 renderer = sysconfig.Renderer()
1686 # render a multiple times to simulate reboots
1687 renderer.render_network_state(ns, render_dir)
1688 renderer.render_network_state(ns, render_dir)
1686 renderer.render_network_state(ns, render_dir)1689 renderer.render_network_state(ns, render_dir)
1687 for fn, expected_content in os_sample.get('out_sysconfig', []):1690 for fn, expected_content in os_sample.get('out_sysconfig', []):
1688 with open(os.path.join(render_dir, fn)) as fh:1691 with open(os.path.join(render_dir, fn)) as fh:


People subscribed via source and target branches