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
1diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
2index f572796..6e11247 100644
3--- a/cloudinit/net/sysconfig.py
4+++ b/cloudinit/net/sysconfig.py
5@@ -347,6 +347,16 @@ class Renderer(renderer.Renderer):
6 else:
7 iface_cfg['GATEWAY'] = subnet['gateway']
8
9+ if 'dns_search' in subnet:
10+ if isinstance(subnet['dns_search'], (list, tuple)):
11+ iface_cfg['DOMAIN'] = ' '.join(subnet['dns_search'][:3])
12+ else:
13+ iface_cfg['DOMAIN'] = subnet['dns_search']
14+
15+ if 'dns_nameservers' in subnet:
16+ for i, k in enumerate(subnet['dns_nameservers'][:3], 1):
17+ iface_cfg['DNS' + str(i)] = k
18+
19 @classmethod
20 def _render_subnet_routes(cls, iface_cfg, route_cfg, subnets):
21 for i, subnet in enumerate(subnets, start=len(iface_cfg.children)):
22diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
23index bbb63cb..f3fa2a3 100644
24--- a/tests/unittests/test_net.py
25+++ b/tests/unittests/test_net.py
26@@ -436,6 +436,9 @@ NETWORK_CONFIGS = {
27 BOOTPROTO=dhcp
28 DEFROUTE=yes
29 DEVICE=eth99
30+ DNS1=8.8.8.8
31+ DNS2=8.8.4.4
32+ DOMAIN="barley.maas sach.maas"
33 GATEWAY=65.61.151.37
34 HWADDR=c0:d6:9f:2c:e8:80
35 IPADDR=192.168.21.3
36@@ -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
37 BOOTPROTO=none
38 DEFROUTE=yes
39 DEVICE=eth0.101
40+ DNS1=192.168.0.10
41+ DNS2=10.23.23.134
42+ DOMAIN="barley.maas sacchromyces.maas brettanomyces.maas"
43 GATEWAY=192.168.0.1
44 IPADDR=192.168.0.2
45 IPADDR1=192.168.2.10

Subscribers

People subscribed via source and target branches