From: zhuzhubj Date: Wed, 3 Jul 2013 10:07:43 +0000 (+0800) Subject: Make volume_glance_metadata_create compat with DB2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=1350867613d8638baf8ccc85910a61df94d5a86d;p=openstack-build%2Fcinder-build.git Make volume_glance_metadata_create compat with DB2 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 --- diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index ceef71780..866bca042 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -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) diff --git a/cinder/tests/test_volume_glance_metadata.py b/cinder/tests/test_volume_glance_metadata.py index ec44d3c1c..1ee09a81f 100644 --- a/cinder/tests/test_volume_glance_metadata.py +++ b/cinder/tests/test_volume_glance_metadata.py @@ -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)