Merge lp:~raharper/curtin/fix-no-dns-search into lp:~curtin-dev/curtin/trunk

Proposed by Ryan Harper
Status: Merged
Merged at revision: 271
Proposed branch: lp:~raharper/curtin/fix-no-dns-search
Merge into: lp:~curtin-dev/curtin/trunk
Diff against target: 247 lines (+111/-7)
7 files modified
curtin/net/__init__.py (+7/-2)
curtin/net/network_state.py (+16/-4)
examples/network-all.yaml (+14/-0)
examples/tests/basic_network.yaml (+4/-0)
tests/unittests/test_net.py (+22/-1)
tests/vmtests/__init__.py (+7/-0)
tests/vmtests/test_network.py (+41/-0)
To merge this branch: bzr merge lp:~raharper/curtin/fix-no-dns-search
Reviewer Review Type Date Requested Status
Scott Moser (community) Approve
Blake Rouse (community) Approve
Review via email: mp+271501@code.launchpad.net

Description of the change

Implement dns-search key in network config.

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Looks good to me.

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

<smoser> i think isinstance(paths, list)
<smoser> woudl be preferable to type(paths) == list

i approve, fix type== to isinstance
then merge it.

review: Approve
274. By Ryan Harper

Prefer isinstance() over type().

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'curtin/net/__init__.py'
2--- curtin/net/__init__.py 2015-09-04 18:36:31 +0000
3+++ curtin/net/__init__.py 2015-09-18 18:13:09 +0000
4@@ -267,11 +267,15 @@
5 'pointopoint',
6 'mtu',
7 'scope',
8+ 'dns_search',
9+ 'dns_nameservers',
10 ]
11 for key, value in subnet.items():
12 if value and key in valid_map:
13 if type(value) == list:
14 value = " ".join(value)
15+ if '_' in key:
16+ key = key.replace('_', '-')
17 content += " {} {}\n".format(key, value)
18
19 return content
20@@ -362,8 +366,9 @@
21 content += iface_add_attrs(iface)
22 content += "\n"
23
24- for (addr, dns) in network_state.get('nameservers').items():
25- content += "{}\n".format(dns)
26+ for dnskey, value in network_state.get('dns', {}).items():
27+ if len(value):
28+ content += "dns-{} {}\n".format(dnskey, " ".join(value))
29
30 for route in network_state.get('routes'):
31 content += render_route(route)
32
33=== modified file 'curtin/net/network_state.py'
34--- curtin/net/network_state.py 2015-09-04 18:58:41 +0000
35+++ curtin/net/network_state.py 2015-09-18 18:13:09 +0000
36@@ -40,7 +40,10 @@
37 self.network_state = {
38 'interfaces': {},
39 'routes': [],
40- 'nameservers': {},
41+ 'dns': {
42+ 'nameservers': [],
43+ 'search': [],
44+ }
45 }
46 self.command_handlers = self.get_command_handlers()
47
48@@ -286,10 +289,19 @@
49 print(self.dump_network_state())
50 return
51
52- nameservers = self.network_state.get('nameservers')
53+ dns = self.network_state.get('dns')
54 if 'address' in command:
55- nameservers[command['address']] = \
56- "dns-nameserver {address}".format(**command)
57+ addrs = command['address']
58+ if not type(addrs) == list:
59+ addrs = [addrs]
60+ for addr in addrs:
61+ dns['nameservers'].append(addr)
62+ if 'search' in command:
63+ paths = command['search']
64+ if not isinstance(paths, list):
65+ paths = [paths]
66+ for path in paths:
67+ dns['search'].append(path)
68
69 def handle_route(self, command):
70 required_keys = [
71
72=== modified file 'examples/network-all.yaml'
73--- examples/network-all.yaml 2015-09-02 13:55:39 +0000
74+++ examples/network-all.yaml 2015-09-18 18:13:09 +0000
75@@ -34,6 +34,11 @@
76 gateway: 192.168.0.1
77 dns_nameservers:
78 - 192.168.0.10
79+ - 10.23.23.134
80+ dns_search:
81+ - barley.maas
82+ - sacchromyces.maas
83+ - brettanomyces.maas
84 - type: static
85 address: 192.168.2.10/24
86 # Bond.
87@@ -84,6 +89,15 @@
88 # A global nameserver.
89 - type: nameserver
90 address: 8.8.8.8
91+ search: barley.maas
92+ # global nameservers and search in list form
93+ - type: nameserver
94+ address:
95+ - 4.4.4.4
96+ - 8.8.4.4
97+ search:
98+ - wark.maas
99+ - foobar.maas
100 # A global route.
101 - type: route
102 destination: 10.0.0.0/8
103
104=== modified file 'examples/tests/basic_network.yaml'
105--- examples/tests/basic_network.yaml 2015-09-02 13:55:39 +0000
106+++ examples/tests/basic_network.yaml 2015-09-18 18:13:09 +0000
107@@ -17,6 +17,10 @@
108 gateway: 10.0.2.1
109 - type: static
110 address: 10.0.2.200/24
111+ dns_nameservers:
112+ - 8.8.8.8
113+ dns_search:
114+ - barley.maas
115 - type: physical
116 name: eth2
117 mac_address: "52:54:00:12:34:04"
118
119=== modified file 'tests/unittests/test_net.py'
120--- tests/unittests/test_net.py 2015-09-04 18:58:41 +0000
121+++ tests/unittests/test_net.py 2015-09-18 18:13:09 +0000
122@@ -259,10 +259,23 @@
123 mac_address: "c0:d6:9f:2c:e8:80"
124 subnets:
125 - type: dhcp4
126+ - type: static
127+ address: 192.168.21.3/24
128+ dns_nameservers:
129+ - 8.8.8.8
130+ - 8.8.4.4
131+ dns_search: barley.maas sach.maas
132 - type: physical
133 name: eth1
134 mac_address: "cf:d6:af:48:e8:80"
135+ - type: nameserver
136+ address:
137+ - 1.2.3.4
138+ - 5.6.7.8
139+ search:
140+ - wark.maas
141 '''
142+
143 with open(self.config_f, 'w') as fp:
144 fp.write(self.config)
145
146@@ -308,8 +321,16 @@
147 def test_render_interfaces(self):
148 ns = self.get_net_state()
149 ifaces = ('auto eth0\n' + 'iface eth0 inet dhcp\n\n' +
150- 'auto eth1\n' + 'iface eth1 inet manual\n\n')
151+ 'auto eth0:1\n' +
152+ 'iface eth0:1 inet static\n' +
153+ ' address 192.168.21.3/24\n' +
154+ ' dns-nameservers 8.8.8.8 8.8.4.4\n' +
155+ ' dns-search barley.maas sach.maas\n\n' +
156+ 'auto eth1\n' + 'iface eth1 inet manual\n\n' +
157+ 'dns-nameservers 1.2.3.4 5.6.7.8\n' +
158+ 'dns-search wark.maas\n')
159 net_ifaces = net.render_interfaces(ns.network_state)
160+ print(ns.network_state.get('interfaces'))
161 self.assertEqual(sorted(ifaces.split('\n')),
162 sorted(net_ifaces.split('\n')))
163
164
165=== modified file 'tests/vmtests/__init__.py'
166--- tests/vmtests/__init__.py 2015-09-10 13:02:40 +0000
167+++ tests/vmtests/__init__.py 2015-09-18 18:13:09 +0000
168@@ -283,6 +283,13 @@
169 def get_expected_etc_network_interfaces(self):
170 return curtin_net.render_interfaces(self.network_state)
171
172+ @classmethod
173+ def get_expected_etc_resolvconf(self):
174+ ifaces = {}
175+ eni = curtin_net.render_interfaces(self.network_state)
176+ curtin_net.parse_deb_config_data(ifaces, eni, None)
177+ return ifaces
178+
179 # Misc functions that are useful for many tests
180 def output_files_exist(self, files):
181 for f in files:
182
183=== modified file 'tests/vmtests/test_network.py'
184--- tests/vmtests/test_network.py 2015-09-09 19:07:27 +0000
185+++ tests/vmtests/test_network.py 2015-09-18 18:13:09 +0000
186@@ -64,6 +64,7 @@
187 runcmd:
188 - ifconfig -a > /media/output/ifconfig_a
189 - cp -av /etc/network/interfaces /media/output
190+ - cp /etc/resolv.conf /media/output
191 - cp -av /etc/udev/rules.d/70-persistent-net.rules /media/output
192 - ip -o route show > /media/output/ip_route_show
193 - route -n > /media/output/route_n
194@@ -74,6 +75,7 @@
195 def test_output_files_exist(self):
196 self.output_files_exist(["ifconfig_a",
197 "interfaces",
198+ "resolv.conf",
199 "70-persistent-net.rules",
200 "ip_route_show",
201 "route_n"])
202@@ -88,6 +90,45 @@
203 for line in expected_eni.split('\n'):
204 self.assertTrue(line in eni_lines)
205
206+ def test_etc_resolvconf(self):
207+ with open(os.path.join(self.td.mnt, "resolv.conf")) as fp:
208+ resolvconf = fp.read()
209+ logger.debug('etc/resolv.conf:\n{}'.format(resolvconf))
210+
211+ resolv_lines = resolvconf.split('\n')
212+ logger.debug('resolv.conf lines:\n{}'.format(resolv_lines))
213+ # resolv.conf
214+ '''
215+ nameserver X.Y.Z.A
216+ nameserver 1.2.3.4
217+ search foo.bar
218+ '''
219+
220+ # eni
221+ ''''
222+ auto eth1:1
223+ iface eth1:1 inet static
224+ dns-nameserver X.Y.Z.A
225+ dns-search foo.bar
226+ '''
227+
228+ # iface dict
229+ ''''
230+ eth1:1:
231+ dns:
232+ nameserver: X.Y.Z.A
233+ search: foo.bar
234+ '''
235+ expected_ifaces = self.get_expected_etc_resolvconf()
236+ logger.debug('parsed eni ifaces:\n{}'.format(expected_ifaces))
237+ for ifname in expected_ifaces.keys():
238+ iface = expected_ifaces.get(ifname)
239+ for k, v in iface.get('dns', {}).items():
240+ dns_line = '{} {}'.format(
241+ k.replace('nameservers', 'nameserver'), " ".join(v))
242+ logger.debug('dns_line:{}'.format(dns_line))
243+ self.assertTrue(dns_line in resolv_lines)
244+
245 def test_ifconfig_output(self):
246 '''check ifconfig output with test input'''
247 network_state = self.get_network_state()

Subscribers

People subscribed via source and target branches