Merge ~smoser/cloud-init:feature/digital-ocean-more-strict into cloud-init:master

Proposed by Scott Moser
Status: Rejected
Rejected by: Scott Moser
Proposed branch: ~smoser/cloud-init:feature/digital-ocean-more-strict
Merge into: cloud-init:master
Diff against target: 40 lines (+15/-0)
2 files modified
cloudinit/sources/helpers/digitalocean.py (+8/-0)
tests/unittests/test_datasource/test_digitalocean.py (+7/-0)
Reviewer Review Type Date Requested Status
Ben Howard (community) Needs Fixing
Server Team CI bot continuous-integration Approve
cloud-init Commiters Pending
Review via email: mp+321623@code.launchpad.net

Commit message

DigitalOcean: be more strict in network configuration conversion.

a.) warn on a 'nic' type in metadata that is unknown.
b.) raise exception if metadata defines a nic that is not present.

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
Ben Howard (darkmuggle-deactivatedaccount) wrote :

While I like the change in general, I've dropped the nic mapping in my MP submitted on 3/28.

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

the 2 pieces here
a.) warn on unknown type
b.) raise runtime exception

Ben's changes recently did 'b', and 'a' is not really necessary.. we still get configuration done now, we just dont pick a specific nic name.

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

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..76ae410 100644
--- a/cloudinit/sources/helpers/digitalocean.py
+++ b/cloudinit/sources/helpers/digitalocean.py
@@ -136,11 +136,19 @@ def convert_network_configuration(config, dns_servers):
136136
137 mac_address = nic.get('mac')137 mac_address = nic.get('mac')
138 sysfs_name = macs_to_nics.get(mac_address)138 sysfs_name = macs_to_nics.get(mac_address)
139 if mac_address not in macs_to_nics:
140 raise RuntimeError(
141 "Did not find network interface on system with mac '%s'."
142 "Cannot apply configuration: %s" % (mac_address, nic))
139 nic_type = nic.get('type', 'unknown')143 nic_type = nic.get('type', 'unknown')
140 # Note: the entry 'public' above contains a list, but144 # Note: the entry 'public' above contains a list, but
141 # the list will only ever have one nic inside it per digital ocean.145 # the list will only ever have one nic inside it per digital ocean.
142 # If it ever had more than one nic, then this code would146 # If it ever had more than one nic, then this code would
143 # assign all 'public' the same name.147 # assign all 'public' the same name.
148 if nic_type not in NIC_MAP:
149 LOG.warn("Unknown / unexpected nic type '%s': %s" %
150 (nic_type, nic))
151
144 if_name = NIC_MAP.get(nic_type, sysfs_name)152 if_name = NIC_MAP.get(nic_type, sysfs_name)
145153
146 LOG.debug("mapped %s interface to %s, assigning name of %s",154 LOG.debug("mapped %s interface to %s, assigning name of %s",
diff --git a/tests/unittests/test_datasource/test_digitalocean.py b/tests/unittests/test_datasource/test_digitalocean.py
index 61d6e00..e9edbf1 100644
--- a/tests/unittests/test_datasource/test_digitalocean.py
+++ b/tests/unittests/test_datasource/test_digitalocean.py
@@ -330,4 +330,11 @@ class TestNetworkConvert(TestCase):
330 sorted(['45.55.249.133', '10.17.0.5']),330 sorted(['45.55.249.133', '10.17.0.5']),
331 sorted([i['address'] for i in eth0['subnets']]))331 sorted([i['address'] for i in eth0['subnets']]))
332332
333 @mock.patch('cloudinit.net.get_interfaces_by_mac')
334 def test_missing_nic_raises_runtime(self, m_get_interfaces_by_mac):
335 m_get_interfaces_by_mac.return_value = {'04:01:57:d1:9e:02': 'eth0'}
336 self.assertRaises(
337 RuntimeError, digitalocean.convert_network_configuration,
338 *[DO_META_2['interfaces'], DO_META_2['dns']['nameservers']])
339
333# vi: ts=4 expandtab340# vi: ts=4 expandtab

Subscribers

People subscribed via source and target branches