← Back to team overview

cloud-init-dev team mailing list archive

[Merge] lp:~daniel-thewatkins/cloud-init/fix-py26 into lp:cloud-init

 

Dan Watkins has proposed merging lp:~daniel-thewatkins/cloud-init/fix-py26 into lp:cloud-init.

Requested reviews:
  cloud init development team (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~daniel-thewatkins/cloud-init/fix-py26/+merge/251784
-- 
Your team cloud init development team is requested to review the proposed merge of lp:~daniel-thewatkins/cloud-init/fix-py26 into lp:cloud-init.
=== modified file 'cloudinit/sources/DataSourceCloudSigma.py'
--- cloudinit/sources/DataSourceCloudSigma.py	2015-01-14 19:24:09 +0000
+++ cloudinit/sources/DataSourceCloudSigma.py	2015-03-04 17:22:11 +0000
@@ -59,7 +59,7 @@
             LOG.warn("failed to get hypervisor product name via dmi data")
             return False
         else:
-            LOG.debug("detected hypervisor as {}".format(sys_product_name))
+            LOG.debug("detected hypervisor as %s", sys_product_name)
             return 'cloudsigma' in sys_product_name.lower()
 
         LOG.warn("failed to query dmi data for system product name")

=== modified file 'cloudinit/user_data.py'
--- cloudinit/user_data.py	2015-02-26 18:51:35 +0000
+++ cloudinit/user_data.py	2015-03-04 17:22:11 +0000
@@ -22,8 +22,6 @@
 
 import os
 
-import email
-
 from email.mime.base import MIMEBase
 from email.mime.multipart import MIMEMultipart
 from email.mime.nonmultipart import MIMENonMultipart
@@ -338,7 +336,7 @@
         headers = {}
     data = util.decode_binary(util.decomp_gzip(raw_data))
     if "mime-version:" in data[0:4096].lower():
-        msg = email.message_from_string(data)
+        msg = util.message_from_string(data)
         for (key, val) in headers.items():
             _replace_header(msg, key, val)
     else:

=== modified file 'cloudinit/util.py'
--- cloudinit/util.py	2015-03-04 15:57:41 +0000
+++ cloudinit/util.py	2015-03-04 17:22:11 +0000
@@ -23,6 +23,7 @@
 import contextlib
 import copy as obj_copy
 import ctypes
+import email
 import errno
 import glob
 import grp
@@ -2187,3 +2188,9 @@
     LOG.warn("did not find either path %s or dmidecode command",
              DMI_SYS_PATH)
     return None
+
+
+def message_from_string(string):
+    if sys.version_info[:2] < (2, 7):
+        return email.message_from_file(six.StringIO(string))
+    return email.message_from_string(string)

=== modified file 'tests/unittests/test_util.py'
--- tests/unittests/test_util.py	2015-03-04 10:46:27 +0000
+++ tests/unittests/test_util.py	2015-03-04 17:22:11 +0000
@@ -452,4 +452,11 @@
         util.multi_log('message', log=log, log_level=log_level)
         self.assertEqual((log_level, mock.ANY), log.log.call_args[0])
 
+
+class TestMessageFromString(helpers.TestCase):
+
+    def test_unicode_not_messed_up(self):
+        roundtripped = util.message_from_string(u'\n').as_string()
+        self.assertNotIn('\x00', roundtripped)
+
 # vi: ts=4 expandtab


Follow ups