Merge ~chad.smith/cloud-init:ubuntu/xenial into cloud-init:ubuntu/xenial

Proposed by Chad Smith
Status: Merged
Merged at revision: 833adcdf6f85ec2305e62bea5a20f9363bf95507
Proposed branch: ~chad.smith/cloud-init:ubuntu/xenial
Merge into: cloud-init:ubuntu/xenial
Diff against target: 292 lines (+264/-0)
4 files modified
debian/changelog (+11/-0)
debian/patches/azure-apply-network-config-false.patch (+23/-0)
debian/patches/cpick-1d5e9aef-azure-Add-apply_network_config-option-to-disable (+228/-0)
debian/patches/series (+2/-0)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Scott Moser Approve
Review via email: mp+356994@code.launchpad.net

Commit message

Cherry pick 1d5e9aef: Add azure apply_network_config config option to ignore network from IMDS
Add debian patch: to set apply_network_config default to False instead of true.

Upload to xenial as the fixes an SRU -proposed regression.

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:67629006c3d363ab59488f0730715eab7a70173d
https://jenkins.ubuntu.com/server/job/cloud-init-ci/403/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    FAILED: Ubuntu LTS: Build

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

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

I think you didn't add the azure-apply patch ? patches/series.
(need git-add)

Revision history for this message
Chad Smith (chad.smith) :
Revision history for this message
Scott Moser (smoser) wrote :

if c-i approves i do.

review: Approve
Revision history for this message
Chad Smith (chad.smith) wrote :

Just added the patch in git, built the deb and tested on azure that the fix doesn't remove ENI hotplug scripts, but still gets IMDS data in instance-data.json

ubuntu@SRU-worked-azure:~$ sudo python3 -c 'from cloudinit.stages import _pkl_load; print(_pkl_load("/var/lib/cloud/instance/obj.pkl").network_config)'
{'config': [{'params': {'driver': 'hv_netvsc', 'device_id': '0x3'}, 'name': 'eth0', 'type': 'physical', 'mac_address': '00:0d:3a:04:3c:ea', 'subnets': [{'type': 'dhcp'}]}], 'version': 1}

ubuntu@SRU-worked-azure:~$ cloud-init query --format '{{ds.meta_data.imds}}'{'compute': {'vmSize': 'Standard_DS1_v2', 'name': 'my-x1', 'offer': 'UbuntuServer', 'vmScaleSetName': '', 'sku': '16.04-DAILY-LTS', 'osType': 'Linux', 'location': 'eastus2', 'version': '16.04.201810160', 'tags': '', 'platformUpdateDomain': '0', 'platformFaultDomain': '0', 'zone': '', 'resourceGroupName': 'srugroup1', 'vmId': 'cb49a483-a6ce-491c-a977-20ab0d546f2b', 'publisher': 'Canonical', 'placementGroupId': '', 'subscriptionId': '12aad61c-6de4-4e53-a6c6-5aff52a83777'}, 'network': {'interface': [{'ipv4': {'subnet': [{'prefix': '24', 'address': '10.0.0.0'}], 'ipAddress': [{'publicIpAddress': '137.116.84.123', 'privateIpAddress': '10.0.0.4'}]}, 'ipv6': {'ipAddress': []}, 'macAddress': '000D3A043CEA'}]}}

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:833adcdf6f85ec2305e62bea5a20f9363bf95507
https://jenkins.ubuntu.com/server/job/cloud-init-ci/404/
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/404/rebuild

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index 2bdfd36..74e8dc2 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,14 @@
6+cloud-init (18.4-0ubuntu1~16.04.2) xenial; urgency=medium
7+
8+ * cherry-pick 1d5e9aef: azure: Add apply_network_config option to
9+ disable network (LP: #1798424)
10+ * debian/patches/openstack-no-network-config.patch
11+ add patch to default Azure apply_network_config to False. Only
12+ fallback network config on eth0 is generated by cloud-init. IMDS
13+ network_config is ignored.
14+
15+ -- Chad Smith <chad.smith@canonical.com> Wed, 17 Oct 2018 12:51:09 -0600
16+
17 cloud-init (18.4-0ubuntu1~16.04.1) xenial-proposed; urgency=medium
18
19 * drop the following cherry-picks now included:
20diff --git a/debian/patches/azure-apply-network-config-false.patch b/debian/patches/azure-apply-network-config-false.patch
21new file mode 100644
22index 0000000..281c19c
23--- /dev/null
24+++ b/debian/patches/azure-apply-network-config-false.patch
25@@ -0,0 +1,23 @@
26+Description: Azure apply_network_config default to False
27+ Azure cloud-images on Xenial already contain hotplug network scripts so
28+ default behavior for should remain to only generate fallback network
29+ configuration which is to dhcp on eth0 and let image hotplug scripts add
30+ network configuration for any additional nics that show up.
31+Author: Chad Smith <chad.smith@canonical.com>
32+Origin: backport
33+Bug: https://bugs.launchpad.net/cloud-init/+bug/1798424
34+Forwarded: not-needed
35+Last-Update: 2018-10-17
36+Index: cloud-init/cloudinit/sources/DataSourceAzure.py
37+===================================================================
38+--- cloud-init.orig/cloudinit/sources/DataSourceAzure.py
39++++ cloud-init/cloudinit/sources/DataSourceAzure.py
40+@@ -207,7 +207,7 @@ BUILTIN_DS_CONFIG = {
41+ },
42+ 'disk_aliases': {'ephemeral0': RESOURCE_DISK_PATH},
43+ 'dhclient_lease_file': LEASE_FILE,
44+- 'apply_network_config': True, # Use IMDS published network configuration
45++ 'apply_network_config': False, # Use fallback network config not IMDS
46+ }
47+ # RELEASE_BLOCKER: Xenial and earlier apply_network_config default is False
48+
49diff --git a/debian/patches/cpick-1d5e9aef-azure-Add-apply_network_config-option-to-disable b/debian/patches/cpick-1d5e9aef-azure-Add-apply_network_config-option-to-disable
50new file mode 100644
51index 0000000..67f9f0e
52--- /dev/null
53+++ b/debian/patches/cpick-1d5e9aef-azure-Add-apply_network_config-option-to-disable
54@@ -0,0 +1,228 @@
55+From 1d5e9aefdab06a2574d78e644deed6c6fa1da171 Mon Sep 17 00:00:00 2001
56+From: Chad Smith <chad.smith@canonical.com>
57+Date: Wed, 17 Oct 2018 18:47:35 +0000
58+Subject: [PATCH] azure: Add apply_network_config option to disable network
59+ from IMDS
60+MIME-Version: 1.0
61+Content-Type: text/plain; charset=UTF-8
62+Content-Transfer-Encoding: 8bit
63+
64+Azure generates network configuration from the IMDS service and removes
65+any preexisting hotplug network scripts which exist in Azure cloud images.
66+Add a datasource configuration option which allows for writing a default
67+network configuration which sets up dhcp on eth0 and leave the hotplug
68+handling to the cloud-image scripts.
69+
70+To disable network-config from Azure IMDS, add the following to
71+/etc/cloud/cloud.cfg.d/99-azure-no-imds-network.cfg:
72+datasource:
73+  Azure:
74+    apply_network_config: False
75+
76+LP: #1798424
77+---
78+ cloudinit/sources/DataSourceAzure.py | 11 +++-
79+ doc/rtd/topics/datasources/azure.rst | 46 +++++++++++++++
80+ tests/unittests/test_datasource/test_azure.py | 56 +++++++++++++++++--
81+ 3 files changed, 107 insertions(+), 6 deletions(-)
82+
83+--- a/cloudinit/sources/DataSourceAzure.py
84++++ b/cloudinit/sources/DataSourceAzure.py
85+@@ -207,7 +207,9 @@ BUILTIN_DS_CONFIG = {
86+ },
87+ 'disk_aliases': {'ephemeral0': RESOURCE_DISK_PATH},
88+ 'dhclient_lease_file': LEASE_FILE,
89++ 'apply_network_config': True, # Use IMDS published network configuration
90+ }
91++# RELEASE_BLOCKER: Xenial and earlier apply_network_config default is False
92+
93+ BUILTIN_CLOUD_CONFIG = {
94+ 'disk_setup': {
95+@@ -450,7 +452,8 @@ class DataSourceAzure(sources.DataSource
96+ except sources.InvalidMetaDataException as e:
97+ LOG.warning('Could not crawl Azure metadata: %s', e)
98+ return False
99+- if self.distro and self.distro.name == 'ubuntu':
100++ if (self.distro and self.distro.name == 'ubuntu' and
101++ self.ds_cfg.get('apply_network_config')):
102+ maybe_remove_ubuntu_network_config_scripts()
103+
104+ # Process crawled data and augment with various config defaults
105+@@ -611,7 +614,11 @@ class DataSourceAzure(sources.DataSource
106+ the blacklisted devices.
107+ """
108+ if not self._network_config:
109+- self._network_config = parse_network_config(self._metadata_imds)
110++ if self.ds_cfg.get('apply_network_config'):
111++ nc_src = self._metadata_imds
112++ else:
113++ nc_src = None
114++ self._network_config = parse_network_config(nc_src)
115+ return self._network_config
116+
117+
118+--- a/doc/rtd/topics/datasources/azure.rst
119++++ b/doc/rtd/topics/datasources/azure.rst
120+@@ -57,6 +57,52 @@ in order to use waagent.conf with cloud-
121+ ResourceDisk.MountPoint=/mnt
122+
123+
124++Configuration
125++-------------
126++The following configuration can be set for the datasource in system
127++configuration (in `/etc/cloud/cloud.cfg` or `/etc/cloud/cloud.cfg.d/`).
128++
129++The settings that may be configured are:
130++
131++ * **agent_command**: Either __builtin__ (default) or a command to run to getcw
132++ metadata. If __builtin__, get metadata from walinuxagent. Otherwise run the
133++ provided command to obtain metadata.
134++ * **apply_network_config**: Boolean set to True to use network configuration
135++ described by Azure's IMDS endpoint instead of fallback network config of
136++ dhcp on eth0. Default is True. For Ubuntu 16.04 or earlier, default is False.
137++ * **data_dir**: Path used to read metadata files and write crawled data.
138++ * **dhclient_lease_file**: The fallback lease file to source when looking for
139++ custom DHCP option 245 from Azure fabric.
140++ * **disk_aliases**: A dictionary defining which device paths should be
141++ interpreted as ephemeral images. See cc_disk_setup module for more info.
142++ * **hostname_bounce**: A dictionary Azure hostname bounce behavior to react to
143++ metadata changes.
144++ * **hostname_bounce**: A dictionary Azure hostname bounce behavior to react to
145++ metadata changes. Azure will throttle ifup/down in some cases after metadata
146++ has been updated to inform dhcp server about updated hostnames.
147++ * **set_hostname**: Boolean set to True when we want Azure to set the hostname
148++ based on metadata.
149++
150++An example configuration with the default values is provided below:
151++
152++.. sourcecode:: yaml
153++
154++ datasource:
155++ Azure:
156++ agent_command: __builtin__
157++ apply_network_config: true
158++ data_dir: /var/lib/waagent
159++ dhclient_lease_file: /var/lib/dhcp/dhclient.eth0.leases
160++ disk_aliases:
161++ ephemeral0: /dev/disk/cloud/azure_resource
162++ hostname_bounce:
163++ interface: eth0
164++ command: builtin
165++ policy: true
166++ hostname_command: hostname
167++ set_hostname: true
168++
169++
170+ Userdata
171+ --------
172+ Userdata is provided to cloud-init inside the ovf-env.xml file. Cloud-init
173+--- a/tests/unittests/test_datasource/test_azure.py
174++++ b/tests/unittests/test_datasource/test_azure.py
175+@@ -254,7 +254,8 @@ scbus-1 on xpt0 bus 0
176+ ])
177+ return dsaz
178+
179+- def _get_ds(self, data, agent_command=None, distro=None):
180++ def _get_ds(self, data, agent_command=None, distro=None,
181++ apply_network=None):
182+
183+ def dsdevs():
184+ return data.get('dsdevs', [])
185+@@ -310,6 +311,8 @@ scbus-1 on xpt0 bus 0
186+ data.get('sys_cfg', {}), distro=distro, paths=self.paths)
187+ if agent_command is not None:
188+ dsrc.ds_cfg['agent_command'] = agent_command
189++ if apply_network is not None:
190++ dsrc.ds_cfg['apply_network_config'] = apply_network
191+
192+ return dsrc
193+
194+@@ -414,14 +417,26 @@ fdescfs /dev/fd fdes
195+
196+ def test_get_data_on_ubuntu_will_remove_network_scripts(self):
197+ """get_data will remove ubuntu net scripts on Ubuntu distro."""
198++ sys_cfg = {'datasource': {'Azure': {'apply_network_config': True}}}
199+ odata = {'HostName': "myhost", 'UserName': "myuser"}
200+ data = {'ovfcontent': construct_valid_ovf_env(data=odata),
201+- 'sys_cfg': {}}
202++ 'sys_cfg': sys_cfg}
203+
204+ dsrc = self._get_ds(data, distro='ubuntu')
205+ dsrc.get_data()
206+ self.m_remove_ubuntu_network_scripts.assert_called_once_with()
207+
208++ def test_get_data_on_ubuntu_will_not_remove_network_scripts_disabled(self):
209++ """When apply_network_config false, do not remove scripts on Ubuntu."""
210++ sys_cfg = {'datasource': {'Azure': {'apply_network_config': False}}}
211++ odata = {'HostName': "myhost", 'UserName': "myuser"}
212++ data = {'ovfcontent': construct_valid_ovf_env(data=odata),
213++ 'sys_cfg': sys_cfg}
214++
215++ dsrc = self._get_ds(data, distro='ubuntu')
216++ dsrc.get_data()
217++ self.m_remove_ubuntu_network_scripts.assert_not_called()
218++
219+ def test_crawl_metadata_returns_structured_data_and_caches_nothing(self):
220+ """Return all structured metadata and cache no class attributes."""
221+ yaml_cfg = "{agent_command: my_command}\n"
222+@@ -503,8 +518,10 @@ fdescfs /dev/fd fdes
223+
224+ def test_network_config_set_from_imds(self):
225+ """Datasource.network_config returns IMDS network data."""
226++ sys_cfg = {'datasource': {'Azure': {'apply_network_config': True}}}
227+ odata = {}
228+- data = {'ovfcontent': construct_valid_ovf_env(data=odata)}
229++ data = {'ovfcontent': construct_valid_ovf_env(data=odata),
230++ 'sys_cfg': sys_cfg}
231+ expected_network_config = {
232+ 'ethernets': {
233+ 'eth0': {'set-name': 'eth0',
234+@@ -783,9 +800,10 @@ fdescfs /dev/fd fdes
235+ @mock.patch('cloudinit.net.generate_fallback_config')
236+ def test_imds_network_config(self, mock_fallback):
237+ """Network config is generated from IMDS network data when present."""
238++ sys_cfg = {'datasource': {'Azure': {'apply_network_config': True}}}
239+ odata = {'HostName': "myhost", 'UserName': "myuser"}
240+ data = {'ovfcontent': construct_valid_ovf_env(data=odata),
241+- 'sys_cfg': {}}
242++ 'sys_cfg': sys_cfg}
243+
244+ dsrc = self._get_ds(data)
245+ ret = dsrc.get_data()
246+@@ -803,6 +821,36 @@ fdescfs /dev/fd fdes
247+
248+ @mock.patch('cloudinit.net.get_interface_mac')
249+ @mock.patch('cloudinit.net.get_devicelist')
250++ @mock.patch('cloudinit.net.device_driver')
251++ @mock.patch('cloudinit.net.generate_fallback_config')
252++ def test_imds_network_ignored_when_apply_network_config_false(
253++ self, mock_fallback, mock_dd, mock_devlist, mock_get_mac):
254++ """When apply_network_config is False, use fallback instead of IMDS."""
255++ sys_cfg = {'datasource': {'Azure': {'apply_network_config': False}}}
256++ odata = {'HostName': "myhost", 'UserName': "myuser"}
257++ data = {'ovfcontent': construct_valid_ovf_env(data=odata),
258++ 'sys_cfg': sys_cfg}
259++ fallback_config = {
260++ 'version': 1,
261++ 'config': [{
262++ 'type': 'physical', 'name': 'eth0',
263++ 'mac_address': '00:11:22:33:44:55',
264++ 'params': {'driver': 'hv_netsvc'},
265++ 'subnets': [{'type': 'dhcp'}],
266++ }]
267++ }
268++ mock_fallback.return_value = fallback_config
269++
270++ mock_devlist.return_value = ['eth0']
271++ mock_dd.return_value = ['hv_netsvc']
272++ mock_get_mac.return_value = '00:11:22:33:44:55'
273++
274++ dsrc = self._get_ds(data)
275++ self.assertTrue(dsrc.get_data())
276++ self.assertEqual(dsrc.network_config, fallback_config)
277++
278++ @mock.patch('cloudinit.net.get_interface_mac')
279++ @mock.patch('cloudinit.net.get_devicelist')
280+ @mock.patch('cloudinit.net.device_driver')
281+ @mock.patch('cloudinit.net.generate_fallback_config')
282+ def test_fallback_network_config(self, mock_fallback, mock_dd,
283diff --git a/debian/patches/series b/debian/patches/series
284index d5a24c5..0e26411 100644
285--- a/debian/patches/series
286+++ b/debian/patches/series
287@@ -2,3 +2,5 @@ azure-use-walinux-agent.patch
288 ds-identify-behavior-xenial.patch
289 stable-release-no-jsonschema-dep.patch
290 openstack-no-network-config.patch
291+cpick-1d5e9aef-azure-Add-apply_network_config-option-to-disable
292+azure-apply-network-config-false.patch

Subscribers

People subscribed via source and target branches