]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Make volume_glance_metadata_create compat with DB2
authorzhuzhubj <zhuzhubj@cn.ibm.com>
Wed, 3 Jul 2013 10:07:43 +0000 (18:07 +0800)
committerJay S. Bryant <jsbryant@us.ibm.com>
Tue, 26 Nov 2013 00:18:11 +0000 (18:18 -0600)
As DB2 does not support SQL insert via raw number type if
table column data type is "CLOB" ("TEXT" in sqlalchemy), we need
to convert numerical values to string before insert operations.

This problem was discovered through the
test_volume_create_get_update_delete_from_image test case in
tempest.api.volume.test_volumes_get.  The test case fails with
a DBError without this change in place.

Partial-blueprint db2-database

Change-Id: I5b378cce5b639df23d7003548f49bdab1eecf6a0

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

index ceef717805fae3398a1c71e4c68d8beb3d8c0876..866bca042d679eea6c0b976716adc801fbe687c7 100644 (file)
@@ -2375,7 +2375,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 = value
+        vol_glance_metadata.value = str(value)
 
         vol_glance_metadata.save(session=session)
 
index ec44d3c1c8b3c193ef72e4047543b0b27245a1fb..1ee09a81f4ef8a635aec7803512e7e47edba1b7e 100644 (file)
@@ -50,6 +50,9 @@ class VolumeGlanceMetadataTestCase(test.TestCase):
         vol_metadata = db.volume_glance_metadata_create(ctxt, 2,
                                                         'key2',
                                                         'value2')
+        vol_metadata = db.volume_glance_metadata_create(ctxt, 2,
+                                                        'key3',
+                                                        123)
 
         expected_metadata_1 = {'volume_id': '1',
                                'key': 'key1',
@@ -65,10 +68,13 @@ class VolumeGlanceMetadataTestCase(test.TestCase):
                                 'value': 'value1'},
                                {'volume_id': '2',
                                 'key': 'key2',
-                                'value': 'value2'})
+                                'value': 'value2'},
+                               {'volume_id': '2',
+                                'key': 'key3',
+                                'value': '123'})
 
         metadata = db.volume_glance_metadata_get(ctxt, 2)
-        self.assertEqual(len(metadata), 2)
+        self.assertEqual(len(metadata), 3)
         for expected, meta in zip(expected_metadata_2, metadata):
             for key, value in expected.iteritems():
                 self.assertEqual(meta[key], value)