summaryrefslogtreecommitdiff
path: root/debian
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2018-03-01 16:05:19 -0700
committerChad Smith <chad.smith@canonical.com>2018-03-01 16:05:19 -0700
commit12926cf1af11e4a7138389b802ebdfcaeca138e7 (patch)
treea9a541c0396625150728aca11ad02acf2a17dd17 /debian
parent8730a9c4cc04f4cc7f21d22ec3474a10110c3f28 (diff)
downloadvyos-cloud-init-12926cf1af11e4a7138389b802ebdfcaeca138e7.tar.gz
vyos-cloud-init-12926cf1af11e4a7138389b802ebdfcaeca138e7.zip
cherry pick 40e7738
LP: #1752711
Diffstat (limited to 'debian')
-rw-r--r--debian/patches/cpick-40e7738-GCE-fix-reading-of-user-data-that-is-not-base64-encoded88
-rw-r--r--debian/patches/series1
2 files changed, 89 insertions, 0 deletions
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
new file mode 100644
index 00000000..530cd453
--- /dev/null
+++ b/debian/patches/cpick-40e7738-GCE-fix-reading-of-user-data-that-is-not-base64-encoded
@@ -0,0 +1,88 @@
+From 40e77380e036a24fafe91a63d0cdefada4312348 Mon Sep 17 00:00:00 2001
+From: Scott Moser <smoser@ubuntu.com>
+Date: Thu, 1 Mar 2018 15:39:16 -0700
+Subject: [PATCH] GCE: fix reading of user-data that is not base64 encoded.
+
+Last set of changes to GCE datasource broke reading of user-data
+unless the user had base64 encoded their user-data and also set
+user-data-encoding to 'base64'.
+
+This fixes the issue.
+
+LP: #1752711
+---
+ cloudinit/sources/DataSourceGCE.py | 15 +++++++--------
+ tests/unittests/test_datasource/test_gce.py | 20 +++++++++++++++++++-
+ 2 files changed, 26 insertions(+), 9 deletions(-)
+
+Index: cloud-init/cloudinit/sources/DataSourceGCE.py
+===================================================================
+--- cloud-init.orig/cloudinit/sources/DataSourceGCE.py
++++ cloud-init/cloudinit/sources/DataSourceGCE.py
+@@ -213,16 +213,15 @@ def read_md(address=None, platform_check
+ if md['availability-zone']:
+ md['availability-zone'] = md['availability-zone'].split('/')[-1]
+
+- encoding = instance_data.get('user-data-encoding')
+- if encoding:
++ if 'user-data' in instance_data:
++ # instance_data was json, so values are all utf-8 strings.
++ ud = instance_data['user-data'].encode("utf-8")
++ encoding = instance_data.get('user-data-encoding')
+ if encoding == 'base64':
+- md['user-data'] = b64decode(instance_data.get('user-data'))
+- else:
++ ud = b64decode(ud)
++ elif encoding:
+ LOG.warning('unknown user-data-encoding: %s, ignoring', encoding)
+-
+- if 'user-data' in md:
+- ret['user-data'] = md['user-data']
+- del md['user-data']
++ ret['user-data'] = ud
+
+ ret['meta-data'] = md
+ ret['success'] = True
+Index: cloud-init/tests/unittests/test_datasource/test_gce.py
+===================================================================
+--- cloud-init.orig/tests/unittests/test_datasource/test_gce.py
++++ cloud-init/tests/unittests/test_datasource/test_gce.py
+@@ -38,11 +38,20 @@ GCE_META_ENCODING = {
+ 'instance/hostname': 'server.project-baz.local',
+ 'instance/zone': 'baz/bang',
+ 'instance/attributes': {
+- 'user-data': b64encode(b'/bin/echo baz\n').decode('utf-8'),
++ 'user-data': b64encode(b'#!/bin/echo baz\n').decode('utf-8'),
+ 'user-data-encoding': 'base64',
+ }
+ }
+
++GCE_USER_DATA_TEXT = {
++ 'instance/id': '12345',
++ 'instance/hostname': 'server.project-baz.local',
++ 'instance/zone': 'baz/bang',
++ 'instance/attributes': {
++ 'user-data': '#!/bin/sh\necho hi mom\ntouch /run/up-now\n',
++ }
++}
++
+ HEADERS = {'Metadata-Flavor': 'Google'}
+ MD_URL_RE = re.compile(
+ r'http://metadata.google.internal/computeMetadata/v1/.*')
+@@ -135,7 +144,16 @@ class TestDataSourceGCE(test_helpers.Htt
+ shostname = GCE_META_PARTIAL.get('instance/hostname').split('.')[0]
+ self.assertEqual(shostname, self.ds.get_hostname())
+
++ def test_userdata_no_encoding(self):
++ """check that user-data is read."""
++ _set_mock_metadata(GCE_USER_DATA_TEXT)
++ self.ds.get_data()
++ self.assertEqual(
++ GCE_USER_DATA_TEXT['instance/attributes']['user-data'].encode(),
++ self.ds.get_userdata_raw())
++
+ def test_metadata_encoding(self):
++ """user-data is base64 encoded if user-data-encoding is 'base64'."""
+ _set_mock_metadata(GCE_META_ENCODING)
+ self.ds.get_data()
+
diff --git a/debian/patches/series b/debian/patches/series
index 7e909afc..4fa16db8 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,3 +1,4 @@
azure-use-walinux-agent.patch
ds-identify-behavior-xenial.patch
stable-release-no-jsonschema-dep.patch
+cpick-40e7738-GCE-fix-reading-of-user-data-that-is-not-base64-encoded