summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKurt Garloff <kurt@garloff.de>2020-03-31 17:57:23 +0200
committerGitHub <noreply@github.com>2020-03-31 10:57:23 -0500
commitd00126c167fc06d913d99cfc184bf3402cb8cf53 (patch)
treea1f82bdf7787393092a556d4fe369d67c8be98b4
parent4fb6fd8a046a6bcce01216c386f3b691a2c466bb (diff)
downloadvyos-cloud-init-d00126c167fc06d913d99cfc184bf3402cb8cf53.tar.gz
vyos-cloud-init-d00126c167fc06d913d99cfc184bf3402cb8cf53.zip
Fix cloud-init ignoring some misdeclared mimetypes in user-data.
On some platforms (old heat on OpenTelekomCloud), the user-data mime part is mislabeled x-shellscript. cloud-init would not accept this unexpected mime-type in multipart user-data. Cloud-init will now run find_ctype() on the content of the mime-part to check if it matches known include types. This patch is from Ryan Harper (inspired by my bug report and a suggestion from Scott Moser) from the discussion on PR #234. Signed-off-by: Kurt Garloff <kurt@garloff.de>
-rw-r--r--cloudinit/user_data.py4
-rw-r--r--tests/unittests/test_data.py34
2 files changed, 37 insertions, 1 deletions
diff --git a/cloudinit/user_data.py b/cloudinit/user_data.py
index 6f41b03a..670dbee6 100644
--- a/cloudinit/user_data.py
+++ b/cloudinit/user_data.py
@@ -25,6 +25,7 @@ LOG = logging.getLogger(__name__)
NOT_MULTIPART_TYPE = handlers.NOT_MULTIPART_TYPE
PART_FN_TPL = handlers.PART_FN_TPL
OCTET_TYPE = handlers.OCTET_TYPE
+INCLUDE_MAP = handlers.INCLUSION_TYPES_MAP
# Saves typing errors
CONTENT_TYPE = 'Content-Type'
@@ -115,7 +116,8 @@ class UserDataProcessor(object):
# Attempt to figure out the payloads content-type
if not ctype_orig:
ctype_orig = UNDEF_TYPE
- if ctype_orig in TYPE_NEEDED:
+ if ctype_orig in TYPE_NEEDED or (ctype_orig in
+ INCLUDE_MAP.values()):
ctype = find_ctype(payload)
if ctype is None:
ctype = ctype_orig
diff --git a/tests/unittests/test_data.py b/tests/unittests/test_data.py
index 74cc26ec..a4261609 100644
--- a/tests/unittests/test_data.py
+++ b/tests/unittests/test_data.py
@@ -213,6 +213,40 @@ c: d
self.assertEqual(1, len(cc))
self.assertEqual('c', cc['a'])
+ def test_cloud_config_as_x_shell_script(self):
+ blob_cc = '''
+#cloud-config
+a: b
+c: d
+'''
+ message_cc = MIMEBase("text", "x-shellscript")
+ message_cc.set_payload(blob_cc)
+
+ blob_jp = '''
+#cloud-config-jsonp
+[
+ { "op": "replace", "path": "/a", "value": "c" },
+ { "op": "remove", "path": "/c" }
+]
+'''
+
+ message_jp = MIMEBase('text', "cloud-config-jsonp")
+ message_jp.set_payload(blob_jp)
+
+ message = MIMEMultipart()
+ message.attach(message_cc)
+ message.attach(message_jp)
+
+ self.reRoot()
+ ci = stages.Init()
+ ci.datasource = FakeDataSource(str(message))
+ ci.fetch()
+ ci.consume_data()
+ cc_contents = util.load_file(ci.paths.get_ipath("cloud_config"))
+ cc = util.load_yaml(cc_contents)
+ self.assertEqual(1, len(cc))
+ self.assertEqual('c', cc['a'])
+
def test_vendor_user_yaml_cloud_config(self):
vendor_blob = '''
#cloud-config