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
1diff --git a/cloudinit/net/ b/cloudinit/net/
2index a550f97..f572796 100644
3--- a/cloudinit/net/
4+++ b/cloudinit/net/
5@@ -484,7 +484,11 @@ class Renderer(renderer.Renderer):
6 content.add_nameserver(nameserver)
7 for searchdomain in network_state.dns_searchdomains:
8 content.add_search_domain(searchdomain)
9- return "\n".join([_make_header(';'), str(content)])
10+ header = _make_header(';')
11+ content_str = str(content)
12+ if not content_str.startswith(header):
13+ content_str = header + '\n' + content_str
14+ return content_str
16 @staticmethod
17 def _render_networkmanager_conf(network_state):
18diff --git a/tests/unittests/ b/tests/unittests/
19index e49abcc..4653be1 100644
20--- a/tests/unittests/
21+++ b/tests/unittests/
22@@ -1683,6 +1683,9 @@ USERCTL=no
23 ns = network_state.parse_net_config_data(network_cfg,
24 skip_broken=False)
25 renderer = sysconfig.Renderer()
26+ # render a multiple times to simulate reboots
27+ renderer.render_network_state(ns, render_dir)
28+ renderer.render_network_state(ns, render_dir)
29 renderer.render_network_state(ns, render_dir)
30 for fn, expected_content in os_sample.get('out_sysconfig', []):
31 with open(os.path.join(render_dir, fn)) as fh:


People subscribed via source and target branches