Comment 7 for bug 1843634

Revision history for this message
Nathan Stratton Treadway (nathanst) wrote : Re: [Bug 1843634] Re: cloud-init misconfigure the network on SLES

On Thu, Sep 12, 2019 at 18:01:39 -0000, Ryan Harper wrote:
> I think we need to instead skip writing resolv.conf unless we have
> content to add
>
> % git diff cloudinit/net/sysconfig.py
> diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
> index be5dede..12c6e36 100644
> --- a/cloudinit/net/sysconfig.py
> +++ b/cloudinit/net/sysconfig.py
> @@ -585,7 +585,11 @@ class Renderer(renderer.Renderer):
> content.add_nameserver(nameserver)
> for searchdomain in network_state.dns_searchdomains:
> content.add_search_domain(searchdomain)
> - if not str(content):
> + # content may be non-empty if an existing were present so also
> + # skip writing a resolv conf if we don't have any nameservers or
> + # search paths
> + if not any([len(network_state.dns_nameservers),
> + len(network_state.dns_searchdomains)]):
> return None
> header = _make_header(';')
> content_str = str(content)

The net effect would be the same in end, but perhaps the intent of the
code would be clearer if this check were at the top of the function?

(If we don't have any content to add, there's no need to even read in
the existing resolv.conf file... let alone pass over both of the no-op
"for" loops.)

       Nathan