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:
@@ -58,12 +58,14 @@ class ImageManager(base.Manager):
|
||||
|
||||
def _image_meta_from_headers(self, headers):
|
||||
meta = {'properties': {}}
|
||||
ensure_unicode = utils.ensure_unicode
|
||||
for key, value in headers.iteritems():
|
||||
value = ensure_unicode(value, incoming='utf-8')
|
||||
if key.startswith('x-image-meta-property-'):
|
||||
_key = key[22:]
|
||||
_key = ensure_unicode(key[22:], incoming='utf-8')
|
||||
meta['properties'][_key] = value
|
||||
elif key.startswith('x-image-meta-'):
|
||||
_key = key[13:]
|
||||
_key = ensure_unicode(key[13:], incoming='utf-8')
|
||||
meta[_key] = value
|
||||
|
||||
for key in ['is_public', 'protected', 'deleted']:
|
||||
|
@@ -311,6 +311,7 @@ class ImageManagerTest(testtools.TestCase):
|
||||
self.assertEqual(image.is_public, False)
|
||||
self.assertEqual(image.protected, False)
|
||||
self.assertEqual(image.deleted, False)
|
||||
self.assertEqual(image.properties, {u'arch': u'x86_64'})
|
||||
|
||||
def test_data(self):
|
||||
data = ''.join([b for b in self.mgr.data('1', do_checksum=False)])
|
||||
|
Reference in New Issue
Block a user