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

Subscribers

People subscribed via source and target branches