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.)
On Thu, Sep 12, 2019 at 18:01:39 -0000, Ryan Harper wrote: net/sysconfig. py net/sysconfig. py b/cloudinit/ net/sysconfig. py net/sysconfig. py net/sysconfig. py renderer. Renderer) : add_nameserver( nameserver) state.dns_ searchdomains: add_search_ domain( searchdomain) network_ state.dns_ nameservers) , state.dns_ searchdomains) ]):
> I think we need to instead skip writing resolv.conf unless we have
> content to add
>
> % git diff cloudinit/
> diff --git a/cloudinit/
> index be5dede..12c6e36 100644
> --- a/cloudinit/
> +++ b/cloudinit/
> @@ -585,7 +585,11 @@ class Renderer(
> content.
> for searchdomain in network_
> content.
> - 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(
> + len(network_
> 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