Handle None value properties in glance-replicator

bug 1208417

In glance-replicator, all image properties in the master glance are
synced to the slave. But there are circumstances(kernel_id or
ramdisk_id, etc.) when image properties in the master are None.
glance-relicator doesn't handle this issue, thus all such properties
are trasnlated to the string 'None' in the slave glance, which is
incorrect.

This patch fixes this problem by add a check before post metadata to
the slave glance. All None properties are translated to '' before
posted to slave glance.

Change-Id: I9b674db907f707ac4dce28c8a7e3d81fcce61193
This commit is contained in:
Yufang Zhang 2013-08-05 18:28:30 +08:00 committed by Yufang Zhang
parent c56fa55bb9
commit ec07f0b437
2 changed files with 8 additions and 2 deletions

View File

@ -208,7 +208,10 @@ class ImageService(object):
for key in d:
if key == 'properties':
for subkey in d[key]:
h['x-image-meta-property-%s' % subkey] = d[key][subkey]
if d[key][subkey] is None:
h['x-image-meta-property-%s' % subkey] = ''
else:
h['x-image-meta-property-%s' % subkey] = d[key][subkey]
else:
h['x-image-meta-%s' % key] = d[key]

View File

@ -195,12 +195,15 @@ class ImageServiceTestCase(test_utils.BaseTestCase):
def test_rest_dict_to_headers(self):
i = {'banana': 42,
'gerkin': 12,
'properties': {'frog': 1}
'properties': {'frog': 1,
'kernel_id': None}
}
o = glance_replicator.ImageService._dict_to_headers(i)
self.assertTrue('x-image-meta-banana' in o)
self.assertTrue('x-image-meta-gerkin' in o)
self.assertTrue('x-image-meta-property-frog' in o)
self.assertTrue('x-image-meta-property-kernel_id' in o)
self.assertEqual(o['x-image-meta-property-kernel_id'], '')
self.assertFalse('properties' in o)
def test_rest_add_image(self):