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

Proposed by Ryan McCabe
Status: Superseded
Proposed branch: ~rmccabe/cloud-init:bug1705804-4
Merge into: cloud-init:master
Diff against target: 73 lines (+26/-2)
3 files modified
cloudinit/net/network_state.py (+13/-2)
cloudinit/net/sysconfig.py (+7/-0)
tests/unittests/test_net.py (+6/-0)
Reviewer Review Type Date Requested Status
Scott Moser Needs Fixing
Server Team CI bot continuous-integration Needs Fixing
Review via email: mp+333844@code.launchpad.net

This proposal supersedes a proposal from 2017-11-15.

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

Commit message

sysconfig: Correctly render dns and dns search info.

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 : Posted in a previous version of this proposal

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 : Posted in a previous version of this proposal

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) : Posted in a previous version of this proposal
Revision history for this message
Ryan McCabe (rmccabe) wrote : Posted in a previous version of this proposal

Updated per your last comments for merge after your fixes.

Revision history for this message
Server Team CI bot (server-team-bot) wrote : Posted in a previous version of this proposal

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

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

review: Needs Fixing (continuous-integration)
Revision history for this message
Ryan McCabe (rmccabe) wrote : Posted in a previous version of this proposal

The unit tests will fail on this one until the patch you suggested is applied, btw, because of the dns search info being passed as a list.

Revision history for this message
Ryan Harper (raharper) wrote : Posted in a previous version of this proposal

I was suggesting you pick up that patch and include it with this fix. If you'd prefer, I can MP that separately.

Revision history for this message
Ryan McCabe (rmccabe) wrote : Posted in a previous version of this proposal

Sure, no problem. I can stick it in there and resubmit.

Revision history for this message
Ryan McCabe (rmccabe) : Posted in a previous version of this proposal
Revision history for this message
Ryan Harper (raharper) wrote : Posted in a previous version of this proposal

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 : Posted in a previous version of this proposal

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 : Posted in a previous version of this proposal

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
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:f85901e5bab02d47c824a945f4ee969a5c6afda3
https://jenkins.ubuntu.com/server/job/cloud-init-ci/504/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    FAILED: MAAS Compatability Testing

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

review: Needs Fixing (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote : Posted in a previous version of this proposal

> 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 : Posted in a previous version of this proposal

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.

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

Yeah, some combination of misclicks landed this in "needs review" from superseded, and I didn't see a way to put it back to there.

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

Ryan,
One question inline.

Also, rebase on master and push and the bot will re-test which will hopefully be happy (trunk was busted, causing the failure that it reported).

Last, i think the "listify" that you're doing better fits in 'normalize_subnets'

  http://paste.ubuntu.com/26007995/

Try that diff on top of yours and see what you think.

take it and re-push and we should be good.

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

Responses inline. Your diff looks good. re-pushed with that and one change per the inline comments.

Revision history for this message
Ryan McCabe (rmccabe) :

Unmerged commits

f85901e... by Ryan McCabe

Render DNS and DOMAIN lines for sysconfig

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/network_state.py b/cloudinit/net/network_state.py
2index 0e830ee..0af0f54 100644
3--- a/cloudinit/net/network_state.py
4+++ b/cloudinit/net/network_state.py
5@@ -325,13 +325,24 @@ class NetworkStateInterpreter(object):
6 # convert subnet ipv6 netmask to cidr as needed
7 subnets = _normalize_subnets(command.get('subnets'))
8
9+ # listify per-subnet dns and
10 # automatically set 'use_ipv6' if any addresses are ipv6
11- if not self.use_ipv6:
12- for subnet in subnets:
13+ for subnet in subnets:
14+ if not self.use_ipv6:
15 if (subnet.get('type').endswith('6') or
16 is_ipv6_addr(subnet.get('address'))):
17 self.use_ipv6 = True
18 break
19+ if 'dns_search' in subnet:
20+ paths = subnet['dns_search']
21+ if not isinstance(paths, list):
22+ paths = paths.split()
23+ subnet['dns_search'] = paths
24+ if 'dns_nameservers' in subnet:
25+ addrs = subnet['dns_nameservers']
26+ if not type(addrs) == list:
27+ addrs = addrs.split()
28+ subnet['dns_nameservers'] = addrs
29
30 iface.update({
31 'name': command.get('name'),
32diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
33index f572796..6b0b007 100644
34--- a/cloudinit/net/sysconfig.py
35+++ b/cloudinit/net/sysconfig.py
36@@ -347,6 +347,13 @@ class Renderer(renderer.Renderer):
37 else:
38 iface_cfg['GATEWAY'] = subnet['gateway']
39
40+ if 'dns_search' in subnet:
41+ iface_cfg['DOMAIN'] = ' '.join(subnet['dns_search'])
42+
43+ if 'dns_nameservers' in subnet:
44+ for i, k in enumerate(subnet['dns_nameservers'][:3], 1):
45+ iface_cfg['DNS' + str(i)] = k
46+
47 @classmethod
48 def _render_subnet_routes(cls, iface_cfg, route_cfg, subnets):
49 for i, subnet in enumerate(subnets, start=len(iface_cfg.children)):
50diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
51index bbb63cb..f3fa2a3 100644
52--- a/tests/unittests/test_net.py
53+++ b/tests/unittests/test_net.py
54@@ -436,6 +436,9 @@ NETWORK_CONFIGS = {
55 BOOTPROTO=dhcp
56 DEFROUTE=yes
57 DEVICE=eth99
58+ DNS1=8.8.8.8
59+ DNS2=8.8.4.4
60+ DOMAIN="barley.maas sach.maas"
61 GATEWAY=65.61.151.37
62 HWADDR=c0:d6:9f:2c:e8:80
63 IPADDR=192.168.21.3
64@@ -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
65 BOOTPROTO=none
66 DEFROUTE=yes
67 DEVICE=eth0.101
68+ DNS1=192.168.0.10
69+ DNS2=10.23.23.134
70+ DOMAIN="barley.maas sacchromyces.maas brettanomyces.maas"
71 GATEWAY=192.168.0.1
72 IPADDR=192.168.0.2
73 IPADDR1=192.168.2.10

Subscribers

People subscribed via source and target branches