From 56103567fbf486625cdf5bfe40eea5ddcb7e8e04 Mon Sep 17 00:00:00 2001 From: Ryan Harper Date: Mon, 31 Jul 2017 13:35:07 -0500 Subject: 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 --- cloudinit/net/sysconfig.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'cloudinit/net') diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py index a550f97c..f5727969 100644 --- a/cloudinit/net/sysconfig.py +++ b/cloudinit/net/sysconfig.py @@ -484,7 +484,11 @@ class Renderer(renderer.Renderer): content.add_nameserver(nameserver) for searchdomain in network_state.dns_searchdomains: content.add_search_domain(searchdomain) - 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 @staticmethod def _render_networkmanager_conf(network_state): -- cgit v1.2.3