Don't set empty kernel_id and ramdisk_id to glance image
In some cases, if 'allow_additional_properties' option is disabled in Glance, 'kernel_id' and 'ramdisk_id' are considered the usual properties and cannot have None values. So it's better always omit these props and never send them to Glance if they are empty. Change-Id: I3dd2a3f39d31a79c86bdbe7b656d42c20c560af3 Closes-bug: #1596602
This commit is contained in:
@@ -843,13 +843,13 @@ def _convert_to_v2(image_meta):
|
||||
for name, value in six.iteritems(image_meta):
|
||||
if name == 'properties':
|
||||
for prop_name, prop_value in six.iteritems(value):
|
||||
# in v2 kernel_id and ramdisk_id must be uuid4 or None,
|
||||
# therefore we convert every value with empty string and
|
||||
# 'None' to just None.
|
||||
# if allow_additional_image_properties is disabled we can't
|
||||
# define kernel_id and ramdisk_id as None, so we have to omit
|
||||
# these properties if they are not set.
|
||||
if prop_name in ('kernel_id', 'ramdisk_id') and \
|
||||
prop_value is not None and \
|
||||
prop_value.strip().lower() in ('none', ''):
|
||||
output[prop_name] = None
|
||||
continue
|
||||
# in glance only string and None property values are allowed,
|
||||
# v1 client accepts any values and converts them to string,
|
||||
# v2 doesn't - so we have to take care of it.
|
||||
|
||||
@@ -2560,14 +2560,12 @@ class TestTranslateToGlance(test.NoDBTestCase):
|
||||
'id': 'f8116538-309f-449c-8d49-df252a97a48d',
|
||||
'image_type': 'test',
|
||||
'instance_uuid': 'ec1ea9c7-8c5e-498d-a753-6ccc2464123c',
|
||||
'kernel_id': None,
|
||||
'min_disk': 0,
|
||||
'min_ram': 0,
|
||||
'name': 'tempest-image-1294122904',
|
||||
'os_distro': 'value2',
|
||||
'os_version': 'value1',
|
||||
'owner': 'd76b51cf8a44427ea404046f4c1d82ab',
|
||||
'ramdisk_id': None,
|
||||
'user_id': 'ca2ff78fd33042ceb45fbbe19012ef3f',
|
||||
'visibility': 'public'}
|
||||
nova_image_dict = self.fixture
|
||||
|
||||
Reference in New Issue
Block a user