Merge lp:~daniel-thewatkins/cloud-init/fix-py26 into lp:~cloud-init-dev/cloud-init/trunk

Proposed by Dan Watkins on 2015-03-04
Status: Merged
Merged at revision: 1075
Proposed branch: lp:~daniel-thewatkins/cloud-init/fix-py26
Merge into: lp:~cloud-init-dev/cloud-init/trunk
Diff against target: 72 lines (+16/-4)
4 files modified
cloudinit/sources/DataSourceCloudSigma.py (+1/-1)
cloudinit/user_data.py (+1/-3)
cloudinit/util.py (+7/-0)
tests/unittests/test_util.py (+7/-0)
To merge this branch: bzr merge lp:~daniel-thewatkins/cloud-init/fix-py26
Reviewer Review Type Date Requested Status
cloud-init commiters 2015-03-04 Pending
Review via email: mp+251784@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cloudinit/sources/DataSourceCloudSigma.py'
2--- cloudinit/sources/DataSourceCloudSigma.py 2015-01-14 19:24:09 +0000
3+++ cloudinit/sources/DataSourceCloudSigma.py 2015-03-04 17:22:11 +0000
4@@ -59,7 +59,7 @@
5 LOG.warn("failed to get hypervisor product name via dmi data")
6 return False
7 else:
8- LOG.debug("detected hypervisor as {}".format(sys_product_name))
9+ LOG.debug("detected hypervisor as %s", sys_product_name)
10 return 'cloudsigma' in sys_product_name.lower()
11
12 LOG.warn("failed to query dmi data for system product name")
13
14=== modified file 'cloudinit/user_data.py'
15--- cloudinit/user_data.py 2015-02-26 18:51:35 +0000
16+++ cloudinit/user_data.py 2015-03-04 17:22:11 +0000
17@@ -22,8 +22,6 @@
18
19 import os
20
21-import email
22-
23 from email.mime.base import MIMEBase
24 from email.mime.multipart import MIMEMultipart
25 from email.mime.nonmultipart import MIMENonMultipart
26@@ -338,7 +336,7 @@
27 headers = {}
28 data = util.decode_binary(util.decomp_gzip(raw_data))
29 if "mime-version:" in data[0:4096].lower():
30- msg = email.message_from_string(data)
31+ msg = util.message_from_string(data)
32 for (key, val) in headers.items():
33 _replace_header(msg, key, val)
34 else:
35
36=== modified file 'cloudinit/util.py'
37--- cloudinit/util.py 2015-03-04 15:57:41 +0000
38+++ cloudinit/util.py 2015-03-04 17:22:11 +0000
39@@ -23,6 +23,7 @@
40 import contextlib
41 import copy as obj_copy
42 import ctypes
43+import email
44 import errno
45 import glob
46 import grp
47@@ -2187,3 +2188,9 @@
48 LOG.warn("did not find either path %s or dmidecode command",
49 DMI_SYS_PATH)
50 return None
51+
52+
53+def message_from_string(string):
54+ if sys.version_info[:2] < (2, 7):
55+ return email.message_from_file(six.StringIO(string))
56+ return email.message_from_string(string)
57
58=== modified file 'tests/unittests/test_util.py'
59--- tests/unittests/test_util.py 2015-03-04 10:46:27 +0000
60+++ tests/unittests/test_util.py 2015-03-04 17:22:11 +0000
61@@ -452,4 +452,11 @@
62 util.multi_log('message', log=log, log_level=log_level)
63 self.assertEqual((log_level, mock.ANY), log.log.call_args[0])
64
65+
66+class TestMessageFromString(helpers.TestCase):
67+
68+ def test_unicode_not_messed_up(self):
69+ roundtripped = util.message_from_string(u'\n').as_string()
70+ self.assertNotIn('\x00', roundtripped)
71+
72 # vi: ts=4 expandtab