Allow updating empty created v2 images from v1
When an empty image is created through python-glanceclient using v2 APIs but updated using v1 APIs, python-glanceclient crashes with a "int() argument must be a string or a number, not 'NoneType'" message. This is because v1.images.ImageManager._format_image_meta_for_user expects the 'size' (and 'min_ram' and 'min_disk') field of an image to be convertible to 'int' but the server-side v2 APIs set it to 'None' for an empty image. Therefore the conversion to int fails with the message above. This fix modifies _format_image_meta_for_user to check whether or not a field can be converted to 'int' and, if not, returns 0 (zero) as the value instead. Tests have also been added. Change-Id: I86680bc06c8ce3ee492efeb3f32071da4f293bcd Closes-bug: #1258160
This commit is contained in:
@@ -98,7 +98,7 @@ class ImageManager(base.Manager):
|
||||
for key in ['size', 'min_ram', 'min_disk']:
|
||||
if key in meta:
|
||||
try:
|
||||
meta[key] = int(meta[key])
|
||||
meta[key] = int(meta[key]) if meta[key] else 0
|
||||
except ValueError:
|
||||
pass
|
||||
return meta
|
||||
|
||||
Reference in New Issue
Block a user