Merge ~daniel-thewatkins/cloud-init/+git/cloud-init:macvtap into cloud-init:master

Proposed by Dan Watkins on 2019-02-20
Status: Merged
Approved by: Dan Watkins on 2019-03-04
Approved revision: 8527e3d86c150997407722aeccaaf894e9ada42b
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~daniel-thewatkins/cloud-init/+git/cloud-init:macvtap
Merge into: cloud-init:master
Diff against target: 78 lines (+29/-6)
2 files modified
cloudinit/sources/helpers/openstack.py (+6/-6)
tests/unittests/test_datasource/test_configdrive.py (+23/-0)
Reviewer Review Type Date Requested Status
Ryan Harper 2019-02-20 Approve on 2019-03-04
Server Team CI bot continuous-integration Approve on 2019-02-21
Review via email: mp+363421@code.launchpad.net

Commit message

helpers/openstack: Treat unknown link types as physical

Some deployments of OpenStack expose link types to the guest which
cloud-init doesn't recognise. These will almost always be physical, so
we can operate more robustly if we assume that they are (whilst warning
the user that we're seeing something unexpected).

LP: #1639263

To post a comment you must log in.

FAILED: Continuous integration, rev:e356bb117e48f6497d4e747c131c738c5d4a41ec
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~daniel-thewatkins/cloud-init/+git/cloud-init/+merge/363421/+edit-commit-message

https://jenkins.ubuntu.com/server/job/cloud-init-ci/566/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

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

review: Needs Fixing (continuous-integration)

PASSED: Continuous integration, rev:e356bb117e48f6497d4e747c131c738c5d4a41ec
https://jenkins.ubuntu.com/server/job/cloud-init-ci/567/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

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

review: Approve (continuous-integration)

PASSED: Continuous integration, rev:5b041496005975cbaf63c1c996814901bb0d6894
https://jenkins.ubuntu.com/server/job/cloud-init-ci/568/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

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

review: Approve (continuous-integration)
Ryan Harper (raharper) wrote :

If we're going to touch this, maybe we could get a wider list from whatever openstack has there now?

https://github.com/openstack/nova/blob/c6218428e9b29a2c52808ec7d27b4b21aadc0299/nova/network/model.py

Ryan Harper (raharper) wrote :

This looks good.

You can see the existing openstack network_data.json samples in:

tests/unittests/test_net.py line 426 of 4185 OS_SAMPLES

That shows the general structure. Another one is in

tests/unittests/test_datasource/test_configdrive.py

PASSED: Continuous integration, rev:8527e3d86c150997407722aeccaaf894e9ada42b
https://jenkins.ubuntu.com/server/job/cloud-init-ci/579/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

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

review: Approve (continuous-integration)
Ryan Harper (raharper) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/sources/helpers/openstack.py b/cloudinit/sources/helpers/openstack.py
2index 9c29cea..8f06911 100644
3--- a/cloudinit/sources/helpers/openstack.py
4+++ b/cloudinit/sources/helpers/openstack.py
5@@ -67,7 +67,7 @@ OS_VERSIONS = (
6 OS_ROCKY,
7 )
8
9-PHYSICAL_TYPES = (
10+KNOWN_PHYSICAL_TYPES = (
11 None,
12 'bgpovs', # not present in OpenStack upstream but used on OVH cloud.
13 'bridge',
14@@ -600,9 +600,7 @@ def convert_net_json(network_json=None, known_macs=None):
15 subnet['ipv6'] = True
16 subnets.append(subnet)
17 cfg.update({'subnets': subnets})
18- if link['type'] in PHYSICAL_TYPES:
19- cfg.update({'type': 'physical', 'mac_address': link_mac_addr})
20- elif link['type'] in ['bond']:
21+ if link['type'] in ['bond']:
22 params = {}
23 if link_mac_addr:
24 params['mac_address'] = link_mac_addr
25@@ -641,8 +639,10 @@ def convert_net_json(network_json=None, known_macs=None):
26 curinfo.update({'mac': link['vlan_mac_address'],
27 'name': name})
28 else:
29- raise ValueError(
30- 'Unknown network_data link type: %s' % link['type'])
31+ if link['type'] not in KNOWN_PHYSICAL_TYPES:
32+ LOG.warning('Unknown network_data link type (%s); treating as'
33+ ' physical', link['type'])
34+ cfg.update({'type': 'physical', 'mac_address': link_mac_addr})
35
36 config.append(cfg)
37 link_id_info[curinfo['id']] = curinfo
38diff --git a/tests/unittests/test_datasource/test_configdrive.py b/tests/unittests/test_datasource/test_configdrive.py
39index dcdabea..664f354 100644
40--- a/tests/unittests/test_datasource/test_configdrive.py
41+++ b/tests/unittests/test_datasource/test_configdrive.py
42@@ -604,6 +604,9 @@ class TestNetJson(CiTestCase):
43
44
45 class TestConvertNetworkData(CiTestCase):
46+
47+ with_logs = True
48+
49 def setUp(self):
50 super(TestConvertNetworkData, self).setUp()
51 self.tmp = self.tmp_dir()
52@@ -730,6 +733,26 @@ class TestConvertNetworkData(CiTestCase):
53 'enp0s2': 'fa:16:3e:d4:57:ad'}
54 self.assertEqual(expected, config_name2mac)
55
56+ def test_unknown_device_types_accepted(self):
57+ # If we don't recognise a link, we should treat it as physical for a
58+ # best-effort boot
59+ my_netdata = deepcopy(NETWORK_DATA)
60+ my_netdata['links'][0]['type'] = 'my-special-link-type'
61+
62+ ncfg = openstack.convert_net_json(my_netdata, known_macs=KNOWN_MACS)
63+ config_name2mac = {}
64+ for n in ncfg['config']:
65+ if n['type'] == 'physical':
66+ config_name2mac[n['name']] = n['mac_address']
67+
68+ expected = {'nic0': 'fa:16:3e:05:30:fe', 'enp0s1': 'fa:16:3e:69:b0:58',
69+ 'enp0s2': 'fa:16:3e:d4:57:ad'}
70+ self.assertEqual(expected, config_name2mac)
71+
72+ # We should, however, warn the user that we don't recognise the type
73+ self.assertIn('Unknown network_data link type (my-special-link-type)',
74+ self.logs.getvalue())
75+
76
77 def cfg_ds_from_dir(base_d, files=None):
78 run = os.path.join(base_d, "run")

Subscribers

People subscribed via source and target branches