From 2f2b0e954d7738c2bf49a48a708cc0ce2b19e726 Mon Sep 17 00:00:00 2001 From: Mike Fedosin Date: Wed, 27 Jul 2016 20:34:41 +0300 Subject: [PATCH] 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 --- nova/image/glance.py | 8 ++++---- nova/tests/unit/image/test_glance.py | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/nova/image/glance.py b/nova/image/glance.py index 5ff403e4d99c..f12c0ca546b0 100644 --- a/nova/image/glance.py +++ b/nova/image/glance.py @@ -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. diff --git a/nova/tests/unit/image/test_glance.py b/nova/tests/unit/image/test_glance.py index 7406a7620bb7..e0c8391f562a 100644 --- a/nova/tests/unit/image/test_glance.py +++ b/nova/tests/unit/image/test_glance.py @@ -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