]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix the unicode encode error when create volume
authorwanghao <wanghao749@huawei.com>
Fri, 27 Feb 2015 04:09:49 +0000 (12:09 +0800)
committerwanghao <wanghao749@huawei.com>
Mon, 9 Mar 2015 08:56:16 +0000 (16:56 +0800)
Using six.text_type(value) to set image_name to
avoid UnicodeEncodeError.

Change-Id: I30542df18f31a3e07cb4b9a61521ebded62ffbc4
Closes-Bug: #1426203

cinder/db/sqlalchemy/api.py
cinder/tests/test_db_api.py

index 1a1bbe118b13b7ac48c20186ab654951da9a31f5..cda4602eca83069af3ff5a77dc533eb82e8a7474 100644 (file)
@@ -2862,8 +2862,7 @@ def volume_glance_metadata_create(context, volume_id, key, value):
         vol_glance_metadata = models.VolumeGlanceMetadata()
         vol_glance_metadata.volume_id = volume_id
         vol_glance_metadata.key = key
-        vol_glance_metadata.value = str(value)
-
+        vol_glance_metadata.value = six.text_type(value)
         session.add(vol_glance_metadata)
 
     return
index e940077268e4d320ffa994d76ab25e98985eabe7..a95e4cd292d4d28066ade0bf98fa693590078a14 100644 (file)
@@ -890,6 +890,17 @@ class DBAPIVolumeTestCase(BaseTest):
         metadata.pop('c')
         self.assertEqual(metadata, db.volume_metadata_get(self.ctxt, 1))
 
+    def test_volume_glance_metadata_create(self):
+        volume = db.volume_create(self.ctxt, {'host': 'h1'})
+        db.volume_glance_metadata_create(self.ctxt, volume['id'],
+                                         'image_name',
+                                         u'\xe4\xbd\xa0\xe5\xa5\xbd')
+        glance_meta = db.volume_glance_metadata_get(self.ctxt, volume['id'])
+        for meta_entry in glance_meta:
+            if meta_entry.key == 'image_name':
+                image_name = meta_entry.value
+        self.assertEqual(u'\xe4\xbd\xa0\xe5\xa5\xbd', image_name)
+
 
 class DBAPISnapshotTestCase(BaseTest):