Convert non-ascii characters within image property to unicode

Convert non-ascii characters within image property (key/value pair) to
unicode but utf-8 to prevent provisioning failure when cloud using qpid
backend.
This change also make the image property encoding consistency between
the image updating and the receiving. Before this, image property
updating use unicode, but receiving (get) result is utf-8.

Fixes: Bug #1180377

Change-Id: I010760c598a7e008c79f1240255708265352cdb5
Signed-off-by: Zhi Yan Liu <zhiyanl@cn.ibm.com>
This commit is contained in:
Zhi Yan Liu
2013-05-15 22:45:08 +08:00
parent 8451a94822
commit 8c70c5b08d
2 changed files with 5 additions and 2 deletions

View File

@@ -58,12 +58,14 @@ class ImageManager(base.Manager):
def _image_meta_from_headers(self, headers): def _image_meta_from_headers(self, headers):
meta = {'properties': {}} meta = {'properties': {}}
ensure_unicode = utils.ensure_unicode
for key, value in headers.iteritems(): for key, value in headers.iteritems():
value = ensure_unicode(value, incoming='utf-8')
if key.startswith('x-image-meta-property-'): if key.startswith('x-image-meta-property-'):
_key = key[22:] _key = ensure_unicode(key[22:], incoming='utf-8')
meta['properties'][_key] = value meta['properties'][_key] = value
elif key.startswith('x-image-meta-'): elif key.startswith('x-image-meta-'):
_key = key[13:] _key = ensure_unicode(key[13:], incoming='utf-8')
meta[_key] = value meta[_key] = value
for key in ['is_public', 'protected', 'deleted']: for key in ['is_public', 'protected', 'deleted']:

View File

@@ -311,6 +311,7 @@ class ImageManagerTest(testtools.TestCase):
self.assertEqual(image.is_public, False) self.assertEqual(image.is_public, False)
self.assertEqual(image.protected, False) self.assertEqual(image.protected, False)
self.assertEqual(image.deleted, False) self.assertEqual(image.deleted, False)
self.assertEqual(image.properties, {u'arch': u'x86_64'})
def test_data(self): def test_data(self):
data = ''.join([b for b in self.mgr.data('1', do_checksum=False)]) data = ''.join([b for b in self.mgr.data('1', do_checksum=False)])