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

Subscribers

People subscribed via source and target branches