← Back to team overview

cloud-init-dev team mailing list archive

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


Ryan Harper has proposed merging ~raharper/cloud-init:sysconfig-resolvconf-duplicate-header-lp1701420 into cloud-init:master.

Requested reviews:
  cloud-init commiters (cloud-init-dev)
Related bugs:
  Bug #1701420 in cloud-init: "Created by cloud-init comment being added on every reboot to /etc/resolv.conf"

For more details, see:

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
Your team cloud-init commiters is requested to review the proposed merge of ~raharper/cloud-init:sysconfig-resolvconf-duplicate-header-lp1701420 into cloud-init:master.
diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
index a550f97..f572796 100644
--- a/cloudinit/net/sysconfig.py
+++ b/cloudinit/net/sysconfig.py
@@ -484,7 +484,11 @@ class Renderer(renderer.Renderer):
         for searchdomain in network_state.dns_searchdomains:
-        return "\n".join([_make_header(';'), str(content)])
+        header = _make_header(';')
+        content_str = str(content)
+        if not content_str.startswith(header):
+            content_str = header + '\n' + content_str
+        return content_str
     def _render_networkmanager_conf(network_state):
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index e49abcc..4653be1 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -1683,6 +1683,9 @@ USERCTL=no
             ns = network_state.parse_net_config_data(network_cfg,
             renderer = sysconfig.Renderer()
+            # render a multiple times to simulate reboots
+            renderer.render_network_state(ns, render_dir)
+            renderer.render_network_state(ns, render_dir)
             renderer.render_network_state(ns, render_dir)
             for fn, expected_content in os_sample.get('out_sysconfig', []):
                 with open(os.path.join(render_dir, fn)) as fh:

Follow ups