Merge ~darkmuggle-deactivatedaccount/cloud-init:lp-1676908-resolver_workaround into cloud-init:master

Proposed by Ben Howard
Status: Merged
Approved by: Scott Moser
Approved revision: 9bf82bec81455037235c7064d5b63378b32ded3b
Merged at revision: 493f6c3e923902d5d4f3d87e1cc4c726ea90ada4
Proposed branch: ~darkmuggle-deactivatedaccount/cloud-init:lp-1676908-resolver_workaround
Merge into: cloud-init:master
Diff against target: 135 lines (+34/-30)
2 files modified
cloudinit/sources/helpers/digitalocean.py (+7/-11)
tests/unittests/test_datasource/test_digitalocean.py (+27/-19)
Reviewer Review Type Date Requested Status
Scott Moser Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+322379@code.launchpad.net

Description of the change

DigitalOcean update to bind the resovlers to the loopback interface. This is a workaround to the resolvconf bug. However, this change brings the DigitalOcean DS in line with OpenStack and the SmartOS DS in the configuration of resolvers.

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote :

drop the reference to 1676908 in the commit message, as it will just mean that is "fixed". You can put "this is part of bug XXXXXX" to avoid that.

Please fix the debug message as suggested.

(if a commit message has 'LP: #' at the beginning of the line, its treated like 'bzr --fixes='.
and since this is one of three that get there, thats kind of odd.

I suggest for commit message:

DigitalOcean: attach dns information to loopback interface

This change makes the DigitalOcean datasource consistent with OpenStack and
Joyent by binding the resolver addresses to the loopback interface. This _is_
a work-around to LP: #1675571.

Part of bug 1676908.

review: Needs Fixing
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote :

given the updated commit message, i've updated the log message and will just push.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/cloudinit/sources/helpers/digitalocean.py b/cloudinit/sources/helpers/digitalocean.py
index 72f7bde..ca290cf 100644
--- a/cloudinit/sources/helpers/digitalocean.py
+++ b/cloudinit/sources/helpers/digitalocean.py
@@ -107,15 +107,12 @@ def convert_network_configuration(config, dns_servers):
107 }107 }
108 """108 """
109109
110 def _get_subnet_part(pcfg, nameservers=None):110 def _get_subnet_part(pcfg):
111 subpart = {'type': 'static',111 subpart = {'type': 'static',
112 'control': 'auto',112 'control': 'auto',
113 'address': pcfg.get('ip_address'),113 'address': pcfg.get('ip_address'),
114 'gateway': pcfg.get('gateway')}114 'gateway': pcfg.get('gateway')}
115115
116 if nameservers:
117 subpart['dns_nameservers'] = nameservers
118
119 if ":" in pcfg.get('ip_address'):116 if ":" in pcfg.get('ip_address'):
120 subpart['address'] = "{0}/{1}".format(pcfg.get('ip_address'),117 subpart['address'] = "{0}/{1}".format(pcfg.get('ip_address'),
121 pcfg.get('cidr'))118 pcfg.get('cidr'))
@@ -157,13 +154,8 @@ def convert_network_configuration(config, dns_servers):
157 continue154 continue
158155
159 sub_part = _get_subnet_part(raw_subnet)156 sub_part = _get_subnet_part(raw_subnet)
160 if nic_type == 'public' and 'anchor' not in netdef:157 if netdef in ('private', 'anchor_ipv4', 'anchor_ipv6'):
161 # add DNS resolvers to the public interfaces only158 del sub_part['gateway']
162 sub_part = _get_subnet_part(raw_subnet, dns_servers)
163 else:
164 # remove the gateway any non-public interfaces
165 if 'gateway' in sub_part:
166 del sub_part['gateway']
167159
168 subnets.append(sub_part)160 subnets.append(sub_part)
169161
@@ -171,6 +163,10 @@ def convert_network_configuration(config, dns_servers):
171 nic_configs.append(ncfg)163 nic_configs.append(ncfg)
172 LOG.debug("nic '%s' configuration: %s", if_name, ncfg)164 LOG.debug("nic '%s' configuration: %s", if_name, ncfg)
173165
166 if dns_servers:
167 LOG.debug("added dns servers")
168 nic_configs.append({'type': 'nameserver', 'address': dns_servers})
169
174 return {'version': 1, 'config': nic_configs}170 return {'version': 1, 'config': nic_configs}
175171
176172
diff --git a/tests/unittests/test_datasource/test_digitalocean.py b/tests/unittests/test_datasource/test_digitalocean.py
index 61d6e00..a11166a 100644
--- a/tests/unittests/test_datasource/test_digitalocean.py
+++ b/tests/unittests/test_datasource/test_digitalocean.py
@@ -197,7 +197,8 @@ class TestNetworkConvert(TestCase):
197 @mock.patch('cloudinit.net.get_interfaces_by_mac')197 @mock.patch('cloudinit.net.get_interfaces_by_mac')
198 def _get_networking(self, m_get_by_mac):198 def _get_networking(self, m_get_by_mac):
199 m_get_by_mac.return_value = {199 m_get_by_mac.return_value = {
200 '04:01:57:d1:9e:01': 'ens1', '04:01:57:d1:9e:02': 'ens2',200 '04:01:57:d1:9e:01': 'ens1',
201 '04:01:57:d1:9e:02': 'ens2',
201 'b8:ae:ed:75:5f:9a': 'enp0s25',202 'b8:ae:ed:75:5f:9a': 'enp0s25',
202 'ae:cc:08:7c:88:00': 'meta2p1'}203 'ae:cc:08:7c:88:00': 'meta2p1'}
203 netcfg = digitalocean.convert_network_configuration(204 netcfg = digitalocean.convert_network_configuration(
@@ -208,18 +209,33 @@ class TestNetworkConvert(TestCase):
208 def test_networking_defined(self):209 def test_networking_defined(self):
209 netcfg = self._get_networking()210 netcfg = self._get_networking()
210 self.assertIsNotNone(netcfg)211 self.assertIsNotNone(netcfg)
212 dns_defined = False
211213
212 for nic_def in netcfg.get('config'):214 for part in netcfg.get('config'):
213 print(json.dumps(nic_def, indent=3))215 n_type = part.get('type')
214 n_type = nic_def.get('type')216 print("testing part ", n_type, "\n", json.dumps(part, indent=3))
215 n_subnets = nic_def.get('type')217
216 n_name = nic_def.get('name')218 if n_type == 'nameserver':
217 n_mac = nic_def.get('mac_address')219 n_address = part.get('address')
220 self.assertIsNotNone(n_address)
221 self.assertEqual(len(n_address), 3)
222
223 dns_resolvers = DO_META["dns"]["nameservers"]
224 for x in n_address:
225 self.assertIn(x, dns_resolvers)
226 dns_defined = True
218227
219 self.assertIsNotNone(n_type)228 else:
220 self.assertIsNotNone(n_subnets)229 n_subnets = part.get('type')
221 self.assertIsNotNone(n_name)230 n_name = part.get('name')
222 self.assertIsNotNone(n_mac)231 n_mac = part.get('mac_address')
232
233 self.assertIsNotNone(n_type)
234 self.assertIsNotNone(n_subnets)
235 self.assertIsNotNone(n_name)
236 self.assertIsNotNone(n_mac)
237
238 self.assertTrue(dns_defined)
223239
224 def _get_nic_definition(self, int_type, expected_name):240 def _get_nic_definition(self, int_type, expected_name):
225 """helper function to return if_type (i.e. public) and the expected241 """helper function to return if_type (i.e. public) and the expected
@@ -260,12 +276,6 @@ class TestNetworkConvert(TestCase):
260 self.assertEqual(meta_def.get('mac'), nic_def.get('mac_address'))276 self.assertEqual(meta_def.get('mac'), nic_def.get('mac_address'))
261 self.assertEqual('physical', nic_def.get('type'))277 self.assertEqual('physical', nic_def.get('type'))
262278
263 def _check_dns_nameservers(self, subn_def):
264 self.assertIn('dns_nameservers', subn_def)
265 expected_nameservers = DO_META['dns']['nameservers']
266 nic_nameservers = subn_def.get('dns_nameservers')
267 self.assertEqual(expected_nameservers, nic_nameservers)
268
269 def test_public_interface_ipv6(self):279 def test_public_interface_ipv6(self):
270 """test public ipv6 addressing"""280 """test public ipv6 addressing"""
271 (nic_def, meta_def) = self._get_nic_definition('public', 'eth0')281 (nic_def, meta_def) = self._get_nic_definition('public', 'eth0')
@@ -280,7 +290,6 @@ class TestNetworkConvert(TestCase):
280290
281 self.assertEqual(cidr_notated_address, subn_def.get('address'))291 self.assertEqual(cidr_notated_address, subn_def.get('address'))
282 self.assertEqual(ipv6_def.get('gateway'), subn_def.get('gateway'))292 self.assertEqual(ipv6_def.get('gateway'), subn_def.get('gateway'))
283 self._check_dns_nameservers(subn_def)
284293
285 def test_public_interface_ipv4(self):294 def test_public_interface_ipv4(self):
286 """test public ipv4 addressing"""295 """test public ipv4 addressing"""
@@ -293,7 +302,6 @@ class TestNetworkConvert(TestCase):
293302
294 self.assertEqual(ipv4_def.get('netmask'), subn_def.get('netmask'))303 self.assertEqual(ipv4_def.get('netmask'), subn_def.get('netmask'))
295 self.assertEqual(ipv4_def.get('gateway'), subn_def.get('gateway'))304 self.assertEqual(ipv4_def.get('gateway'), subn_def.get('gateway'))
296 self._check_dns_nameservers(subn_def)
297305
298 def test_public_interface_anchor_ipv4(self):306 def test_public_interface_anchor_ipv4(self):
299 """test public ipv4 addressing"""307 """test public ipv4 addressing"""

Subscribers

People subscribed via source and target branches