← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1487877] [NEW] write_files errors out on non ascii content

 

Public bug reported:

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.

** Affects: cloud-init
     Importance: Undecided
         Status: New

** Attachment added: "this is the configuration that fails to initialize"
   https://bugs.launchpad.net/bugs/1487877/+attachment/4451285/+files/userdata_strbug.txt

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to cloud-init.
https://bugs.launchpad.net/bugs/1487877

Title:
  write_files errors out on non ascii content

Status in cloud-init:
  New

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.

To manage notifications about this bug go to:
https://bugs.launchpad.net/cloud-init/+bug/1487877/+subscriptions


Follow ups