Merge ~rmccabe/cloud-init:bug1705804-2 into cloud-init:master

Proposed by Ryan McCabe
Status: Rejected
Rejected by: Scott Moser
Proposed branch: ~rmccabe/cloud-init:bug1705804-2
Merge into: cloud-init:master
Diff against target: 45 lines (+16/-0)
2 files modified
cloudinit/net/sysconfig.py (+10/-0)
tests/unittests/test_net.py (+6/-0)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Needs Fixing
cloud-init Commiters Pending
Review via email: mp+333722@code.launchpad.net

This proposal has been superseded by a proposal from 2017-11-15.

Description of the change

Currently when dns and dns search info is provided, it is not rendered
when outputting to sysconfig format.

This patch causes the DNS and DOMAIN lines to be written out rendering
sysconfig.

LP: #1705804

To post a comment you must log in.
Revision history for this message
Ryan McCabe (rmccabe) wrote :

Updated to handle dns_search when received as either a string or a list
Updated per Ryan Harper's other comments on the previous iteration

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:cc2c67acb04881e38c6d8b5e2f7a68e7c5e99164
https://jenkins.ubuntu.com/server/job/cloud-init-ci/494/
Executed test runs:
    SUCCESS: Checkout
    FAILED: Unit & Style Tests

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/494/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Ryan Harper (raharper) :
Revision history for this message
Ryan McCabe (rmccabe) :
Revision history for this message
Ryan Harper (raharper) wrote :

On Thu, Nov 16, 2017 at 12:35 PM, Ryan McCabe <email address hidden> wrote:

>
>
> Diff comments:
>
> > diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
> > index f572796..6e11247 100644
> > --- a/cloudinit/net/sysconfig.py
> > +++ b/cloudinit/net/sysconfig.py
> > @@ -347,6 +347,16 @@ class Renderer(renderer.Renderer):
> > else:
> > iface_cfg['GATEWAY'] = subnet['gateway']
> >
> > + if 'dns_search' in subnet:
> > + if isinstance(subnet['dns_search'], (list, tuple)):
>
> Is adding the dns search and nameservers info into the network_state dict
> the right thing to do here? It looks like dns info from all interfaces, not
> just subnets of the current one, is being added, and it produces bad output
> e.g.,:
>
>
> iface lo inet loopback
> dns-nameservers 69.9.160.191 69.9.191.4 10.0.0.1
> dns-search foo.com

dns-nameservers is valid and accepts space separated list

>
>
> when it should be
>
> iface lo inet loopback
> dns-nameservers 10.0.0.1
> dns-search foo.com
>
> Doing only the listify and not adding the info to the network_state dict
> there seems to do the right thing.
>

Yes; that may be the best bet here. That keeps with the more general idea
that dns-settings should be
scoped per-interface.

>
> > + iface_cfg['DOMAIN'] = '
> '.join(subnet['dns_search'][:3])
> > + else:
> > + iface_cfg['DOMAIN'] = subnet['dns_search']
> > +
> > + if 'dns_nameservers' in subnet:
> > + for i, k in enumerate(subnet['dns_nameservers'][:3],
> 1):
> > + iface_cfg['DNS' + str(i)] = k
> > +
> > @classmethod
> > def _render_subnet_routes(cls, iface_cfg, route_cfg, subnets):
> > for i, subnet in enumerate(subnets,
> start=len(iface_cfg.children)):
>
>
> --
> https://code.launchpad.net/~rmccabe/cloud-init/+git/cloud-
> init/+merge/333722
> Your team cloud-init commiters is requested to review the proposed merge
> of ~rmccabe/cloud-init:bug1705804-2 into cloud-init:master.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~cloud-init-dev
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~cloud-init-dev
> More help : https://help.launchpad.net/ListHelp
>

Revision history for this message
Scott Moser (smoser) wrote :

one comment on ryan's patch inline

do not use .split(" "), here is why:
 > "a b c".split()
 ['a', 'b', 'c']

 > "a b c".split(" ")
 ['a', 'b', '', '', 'c']

Revision history for this message
Ryan McCabe (rmccabe) wrote :

Sorry, what I meant re: "dns-nameservers 69.9.160.191 69.9.191.4 10.0.0.1" is that the first two IPs were pulled from an ethX interface and don't belong there, given the yaml, not that there was a problem with the syntax.

ACK, re: Scott's comment

I'll resubmit a proposal that does only the listify and cleans up the split

Revision history for this message
Ryan Harper (raharper) wrote :

> one comment on ryan's patch inline
>
> do not use .split(" "), here is why:
> > "a b c".split()
> ['a', 'b', 'c']
>
> > "a b c".split(" ")
> ['a', 'b', '', '', 'c']

I had to hit reply to see how those two strings looked different

Even cut and pasting, something is removing the additional spaces you added:

"a b c".split(" ")

Crazy, but point taken,

>>> "a...b.c".split(".")
['a', '', '', 'b', 'c']

Revision history for this message
Scott Moser (smoser) wrote :

I'm going to mark this as 'rejected' as i'm 99% sure you have fixed with
https://code.launchpad.net/~rmccabe/cloud-init/+git/cloud-init/+merge/333844

re-open if that is not the case.

Unmerged commits

cc2c67a... by Ryan McCabe

Currently when dns and dns search info is provided, it is not rendered
when outputting to sysconfig format.

This patch causes the DNS and DOMAIN lines to be written out rendering
sysconfig.

LP: #1705804

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
index f572796..6e11247 100644
--- a/cloudinit/net/sysconfig.py
+++ b/cloudinit/net/sysconfig.py
@@ -347,6 +347,16 @@ class Renderer(renderer.Renderer):
347 else:347 else:
348 iface_cfg['GATEWAY'] = subnet['gateway']348 iface_cfg['GATEWAY'] = subnet['gateway']
349349
350 if 'dns_search' in subnet:
351 if isinstance(subnet['dns_search'], (list, tuple)):
352 iface_cfg['DOMAIN'] = ' '.join(subnet['dns_search'][:3])
353 else:
354 iface_cfg['DOMAIN'] = subnet['dns_search']
355
356 if 'dns_nameservers' in subnet:
357 for i, k in enumerate(subnet['dns_nameservers'][:3], 1):
358 iface_cfg['DNS' + str(i)] = k
359
350 @classmethod360 @classmethod
351 def _render_subnet_routes(cls, iface_cfg, route_cfg, subnets):361 def _render_subnet_routes(cls, iface_cfg, route_cfg, subnets):
352 for i, subnet in enumerate(subnets, start=len(iface_cfg.children)):362 for i, subnet in enumerate(subnets, start=len(iface_cfg.children)):
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index bbb63cb..f3fa2a3 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -436,6 +436,9 @@ NETWORK_CONFIGS = {
436 BOOTPROTO=dhcp436 BOOTPROTO=dhcp
437 DEFROUTE=yes437 DEFROUTE=yes
438 DEVICE=eth99438 DEVICE=eth99
439 DNS1=8.8.8.8
440 DNS2=8.8.4.4
441 DOMAIN="barley.maas sach.maas"
439 GATEWAY=65.61.151.37442 GATEWAY=65.61.151.37
440 HWADDR=c0:d6:9f:2c:e8:80443 HWADDR=c0:d6:9f:2c:e8:80
441 IPADDR=192.168.21.3444 IPADDR=192.168.21.3
@@ -836,6 +839,9 @@ pre-down route del -net 10.0.0.0 netmask 255.0.0.0 gw 11.0.0.1 metric 3 || true
836 BOOTPROTO=none839 BOOTPROTO=none
837 DEFROUTE=yes840 DEFROUTE=yes
838 DEVICE=eth0.101841 DEVICE=eth0.101
842 DNS1=192.168.0.10
843 DNS2=10.23.23.134
844 DOMAIN="barley.maas sacchromyces.maas brettanomyces.maas"
839 GATEWAY=192.168.0.1845 GATEWAY=192.168.0.1
840 IPADDR=192.168.0.2846 IPADDR=192.168.0.2
841 IPADDR1=192.168.2.10847 IPADDR1=192.168.2.10

Subscribers

People subscribed via source and target branches