TypeError trying to write a file specified in OpenStack Configuration Drive

Bug #1260072 reported by James Slagle
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Fix Released

Bug Description

I'm using cloud-init with the OpenStack Configuration Drive. On the mounted iso serving as the Configuration Drive I have a /openstack/latest/meta_data.json file that looks like:


(there's some other contents as well, but I've snipped it here for brevity)

cloud-init fails writing the /etc/foo file with the following traceback:

2013-12-11 20:52:59,259 - util.py[ERROR]: in method 'matchpathcon', argument 1 of type 'char const *'
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/cloudinit/util.py", line 177, in __exit__
    self.selinux.matchpathcon(path, stats[stat.ST_MODE])
TypeError: in method 'matchpathcon', argument 1 of type 'char const *'
2013-12-11 20:52:59,260 - util.py[WARNING]: Failed writing files

Note I had to add my own LOG.exception line in __exit__ of the SeLinuxGuard class in utils.py in order to see the exception.

The issue seems to be that when the json from meta_data.json is passed to json.loads, you get back a dictionary with the keys and values in unicode, not strings. This is pretty easy to verify from the command line:

/home/jslagle $ python
Python 2.7.5 (default, Nov 12 2013, 16:18:42)
[GCC 4.8.2 20131017 (Red Hat 4.8.2-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> json.loads('{"foo":"bar"}')
{u'foo': u'bar'}

Later on in cloud-init write_files is called with the file paths in unicode, which apparently selinux.matchpathcon does not support (it only supports strings).

This is on Fedora 19, cloud-init version: cloud-init-0.7.2-7.fc19.noarch

I'll be happy to work on a patch for this as well.

What do you think the right fix for this would be? It'd be easy enough to cast path to str before calling matchpathcon.

Related branches

description: updated
Joshua Harlow (harlowja)
Changed in cloud-init:
status: New → Fix Committed
Revision history for this message
Scott Moser (smoser) wrote :

fixed in 0.7.5

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.