summaryrefslogtreecommitdiff
path: root/nova/image
diff options
context:
space:
mode:
authorMike Fedosin <mfedosin@mirantis.com>2016-06-15 17:35:07 +0300
committerMike Fedosin <mfedosin@mirantis.com>2016-06-15 21:06:18 +0300
commit3f8076acdc7756b8a5f0f16d4885a47cb001483e (patch)
tree221176269dfd853a1016a17f640d14fa82711037 /nova/image
parenta7de498628d3cadd38f2b7a2387c7b073c950aa8 (diff)
downloadnova-3f8076acdc7756b8a5f0f16d4885a47cb001483e.tar.gz
Fix image meta which is sent to glance v2
This commit fixes recently found issues with converting images in nova format to glance v2. 1. If property string is unicode we shouldn't convert it to str. 2. kernel_id and ramdisk_id are custom properties and for this reason they have to be processed on 'properties' layer and not with regular attributes. 3. In glance v1 it was possible to set empty string to kernel_id and ramdisk_id properties. In glance v2 it's forbidden and that's why we have to convert them to None values. Change-Id: I950777c5d0292b4a54d14913611038a18ef41d57 Closes-bug: #1592808
Diffstat (limited to 'nova/image')
-rw-r--r--nova/image/glance.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/nova/image/glance.py b/nova/image/glance.py
index 77b1ae2576..561ecf257d 100644
--- a/nova/image/glance.py
+++ b/nova/image/glance.py
@@ -841,18 +841,30 @@ 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):
- output[prop_name] = str(prop_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 prop_name in ('kernel_id', 'ramdisk_id') and \
+ prop_value is not None and \
+ prop_value.strip().lower() in ('none', ''):
+ output[prop_name] = None
+ # 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.
+ elif prop_value is None or isinstance(
+ prop_value, six.string_types):
+ output[prop_name] = prop_value
+ else:
+ output[prop_name] = str(prop_value)
+
elif name in ('min_ram', 'min_disk'):
output[name] = int(value)
elif name == 'is_public':
output['visibility'] = 'public' if value else 'private'
- elif name == 'size' or name == 'deleted':
+ elif name in ('size', 'deleted'):
continue
- elif name in ('kernel_id', 'ramdisk_id') and value == 'None':
- output[name] = None
else:
output[name] = value
-
return output