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

Proposed by Chad Smith
Status: Merged
Merge reported by: Chad Smith
Merged at revision: ef123d2fcca883b8d1483e0e956f6d11b22e9236
Proposed branch: ~chad.smith/cloud-init:ubuntu/artful
Merge into: cloud-init:ubuntu/artful
Diff against target: 116 lines (+96/-0)
3 files modified
debian/changelog (+7/-0)
debian/patches/cpick-40e7738-GCE-fix-reading-of-user-data-that-is-not-base64-encoded (+88/-0)
debian/patches/series (+1/-0)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Scott Moser Pending
Review via email: mp+340255@code.launchpad.net

Description of the change

Cherry pick fix for GCE user-data processing into artful

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

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

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

review: Approve (continuous-integration)

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/debian/changelog b/debian/changelog
2index fe1b23d..f99edb8 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,10 @@
6+cloud-init (17.2-35-gf576b2a2-0ubuntu1~17.10.1ubuntu1) artful-proposed; urgency=medium
7+
8+ * cherry-pick 40e7738: GCE: fix reading of user-data that is not
9+ base64 encoded. (LP: #1752711)
10+
11+ -- Chad Smith <chad.smith@canonical.com> Thu, 01 Mar 2018 16:03:46 -0700
12+
13 cloud-init (17.2-35-gf576b2a2-0ubuntu1~17.10.1) artful-proposed; urgency=medium
14
15 * New upstream snapshot. (LP: #1747059)
16diff --git a/debian/patches/cpick-40e7738-GCE-fix-reading-of-user-data-that-is-not-base64-encoded b/debian/patches/cpick-40e7738-GCE-fix-reading-of-user-data-that-is-not-base64-encoded
17new file mode 100644
18index 0000000..530cd45
19--- /dev/null
20+++ b/debian/patches/cpick-40e7738-GCE-fix-reading-of-user-data-that-is-not-base64-encoded
21@@ -0,0 +1,88 @@
22+From 40e77380e036a24fafe91a63d0cdefada4312348 Mon Sep 17 00:00:00 2001
23+From: Scott Moser <smoser@ubuntu.com>
24+Date: Thu, 1 Mar 2018 15:39:16 -0700
25+Subject: [PATCH] GCE: fix reading of user-data that is not base64 encoded.
26+
27+Last set of changes to GCE datasource broke reading of user-data
28+unless the user had base64 encoded their user-data and also set
29+user-data-encoding to 'base64'.
30+
31+This fixes the issue.
32+
33+LP: #1752711
34+---
35+ cloudinit/sources/DataSourceGCE.py | 15 +++++++--------
36+ tests/unittests/test_datasource/test_gce.py | 20 +++++++++++++++++++-
37+ 2 files changed, 26 insertions(+), 9 deletions(-)
38+
39+Index: cloud-init/cloudinit/sources/DataSourceGCE.py
40+===================================================================
41+--- cloud-init.orig/cloudinit/sources/DataSourceGCE.py
42++++ cloud-init/cloudinit/sources/DataSourceGCE.py
43+@@ -213,16 +213,15 @@ def read_md(address=None, platform_check
44+ if md['availability-zone']:
45+ md['availability-zone'] = md['availability-zone'].split('/')[-1]
46+
47+- encoding = instance_data.get('user-data-encoding')
48+- if encoding:
49++ if 'user-data' in instance_data:
50++ # instance_data was json, so values are all utf-8 strings.
51++ ud = instance_data['user-data'].encode("utf-8")
52++ encoding = instance_data.get('user-data-encoding')
53+ if encoding == 'base64':
54+- md['user-data'] = b64decode(instance_data.get('user-data'))
55+- else:
56++ ud = b64decode(ud)
57++ elif encoding:
58+ LOG.warning('unknown user-data-encoding: %s, ignoring', encoding)
59+-
60+- if 'user-data' in md:
61+- ret['user-data'] = md['user-data']
62+- del md['user-data']
63++ ret['user-data'] = ud
64+
65+ ret['meta-data'] = md
66+ ret['success'] = True
67+Index: cloud-init/tests/unittests/test_datasource/test_gce.py
68+===================================================================
69+--- cloud-init.orig/tests/unittests/test_datasource/test_gce.py
70++++ cloud-init/tests/unittests/test_datasource/test_gce.py
71+@@ -38,11 +38,20 @@ GCE_META_ENCODING = {
72+ 'instance/hostname': 'server.project-baz.local',
73+ 'instance/zone': 'baz/bang',
74+ 'instance/attributes': {
75+- 'user-data': b64encode(b'/bin/echo baz\n').decode('utf-8'),
76++ 'user-data': b64encode(b'#!/bin/echo baz\n').decode('utf-8'),
77+ 'user-data-encoding': 'base64',
78+ }
79+ }
80+
81++GCE_USER_DATA_TEXT = {
82++ 'instance/id': '12345',
83++ 'instance/hostname': 'server.project-baz.local',
84++ 'instance/zone': 'baz/bang',
85++ 'instance/attributes': {
86++ 'user-data': '#!/bin/sh\necho hi mom\ntouch /run/up-now\n',
87++ }
88++}
89++
90+ HEADERS = {'Metadata-Flavor': 'Google'}
91+ MD_URL_RE = re.compile(
92+ r'http://metadata.google.internal/computeMetadata/v1/.*')
93+@@ -135,7 +144,16 @@ class TestDataSourceGCE(test_helpers.Htt
94+ shostname = GCE_META_PARTIAL.get('instance/hostname').split('.')[0]
95+ self.assertEqual(shostname, self.ds.get_hostname())
96+
97++ def test_userdata_no_encoding(self):
98++ """check that user-data is read."""
99++ _set_mock_metadata(GCE_USER_DATA_TEXT)
100++ self.ds.get_data()
101++ self.assertEqual(
102++ GCE_USER_DATA_TEXT['instance/attributes']['user-data'].encode(),
103++ self.ds.get_userdata_raw())
104++
105+ def test_metadata_encoding(self):
106++ """user-data is base64 encoded if user-data-encoding is 'base64'."""
107+ _set_mock_metadata(GCE_META_ENCODING)
108+ self.ds.get_data()
109+
110diff --git a/debian/patches/series b/debian/patches/series
111new file mode 100644
112index 0000000..7fae555
113--- /dev/null
114+++ b/debian/patches/series
115@@ -0,0 +1 @@
116+cpick-40e7738-GCE-fix-reading-of-user-data-that-is-not-base64-encoded

Subscribers

People subscribed via source and target branches