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
1diff --git a/cloudinit/sources/helpers/digitalocean.py b/cloudinit/sources/helpers/digitalocean.py
2index 72f7bde..76ae410 100644
3--- a/cloudinit/sources/helpers/digitalocean.py
4+++ b/cloudinit/sources/helpers/digitalocean.py
5@@ -136,11 +136,19 @@ def convert_network_configuration(config, dns_servers):
6
7 mac_address = nic.get('mac')
8 sysfs_name = macs_to_nics.get(mac_address)
9+ if mac_address not in macs_to_nics:
10+ raise RuntimeError(
11+ "Did not find network interface on system with mac '%s'."
12+ "Cannot apply configuration: %s" % (mac_address, nic))
13 nic_type = nic.get('type', 'unknown')
14 # Note: the entry 'public' above contains a list, but
15 # the list will only ever have one nic inside it per digital ocean.
16 # If it ever had more than one nic, then this code would
17 # assign all 'public' the same name.
18+ if nic_type not in NIC_MAP:
19+ LOG.warn("Unknown / unexpected nic type '%s': %s" %
20+ (nic_type, nic))
21+
22 if_name = NIC_MAP.get(nic_type, sysfs_name)
23
24 LOG.debug("mapped %s interface to %s, assigning name of %s",
25diff --git a/tests/unittests/test_datasource/test_digitalocean.py b/tests/unittests/test_datasource/test_digitalocean.py
26index 61d6e00..e9edbf1 100644
27--- a/tests/unittests/test_datasource/test_digitalocean.py
28+++ b/tests/unittests/test_datasource/test_digitalocean.py
29@@ -330,4 +330,11 @@ class TestNetworkConvert(TestCase):
30 sorted(['45.55.249.133', '10.17.0.5']),
31 sorted([i['address'] for i in eth0['subnets']]))
32
33+ @mock.patch('cloudinit.net.get_interfaces_by_mac')
34+ def test_missing_nic_raises_runtime(self, m_get_interfaces_by_mac):
35+ m_get_interfaces_by_mac.return_value = {'04:01:57:d1:9e:02': 'eth0'}
36+ self.assertRaises(
37+ RuntimeError, digitalocean.convert_network_configuration,
38+ *[DO_META_2['interfaces'], DO_META_2['dns']['nameservers']])
39+
40 # vi: ts=4 expandtab

Subscribers

People subscribed via source and target branches