write_files errors out on non ascii content

Bug #1487877 reported by Tite
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Fix Released
Medium
Scott Moser

Bug Description

When trying to add content in the write_files an error is thrown:

2015-08-23 10:37:54,678 - util.py[WARNING]: Running write_files (<module 'cloudinit.config.cc_write_files' from '/usr/lib/python2.7/site-packages/cloudinit/config/cc_write_files.pyc'>) failed

The cloud-config file is attached.

When searching for the root cause, found to be an error raised in line 95 of cloudinit/config/cc_write_files.py
"""
def extract_contents(contents, extraction_types):
    result = str(contents)
    for t in extraction_types:
"""

The conversion from unicode to string throws an exception. I tested this by using a plain script:
"""
#!/bin/python

import yaml
f=open("/etc/salt-cloud/cloud.deploy.d/userdata_strbug.txt","r")
conf = yaml.load(f)

print "Testing write_files bug ... "
for c in conf['write_files']:
  print "Content to string: ",str(c['content'])
"""

With this output:
"""
Testing write_files bug ...
Content to string:
Traceback (most recent call last):
  File "utils/misc/test-yaml-bug.py", line 9, in <module>
    print "Content to string: ",str(c['content'])
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in position 1087: ordinal not in range(128)
"""

Line 40 of the configuration file, is the offending one, it's a comment.

Revision history for this message
Tite (x-ubuntu-9) wrote :
Revision history for this message
Scott Moser (smoser) wrote :

This is fixed in trunk in revno 1199 (fixed with the fix for bug 1565638)

Changed in cloud-init:
assignee: nobody → Scott Moser (smoser)
importance: Undecided → Medium
status: New → Fix Committed
Revision history for this message
Scott Moser (smoser) wrote :

This is fixed in cloud-init 0.7.7

Changed in cloud-init:
status: Fix Committed → Fix Released
Revision history for this message
James Falcon (falcojr) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.