From ed1b59848fd2a6b7bed7618ab5ac0db00e8110dc Mon Sep 17 00:00:00 2001 From: Mike Fedosin Date: Thu, 4 Jan 2018 17:49:28 +0100 Subject: Check that Glance returns image data before processing it Now if Glance v2 cannot find image data it returns an empty response with 204 status code, instead of raising an error. Glance client handles this situation and wraps the response with a RequestIdProxy object, whose 'wrapped' attribute is None. But when openstack client tries to parse this object using glanceclient's save_image util function, it fails with "NoneType object is not iterable" message, for the object doesn't contain any data. This patch adds additional check to prevent such behaviour and raises SystemExit exception if no data was returned from the server. Glance v1 is not affected, because it raises an error if can't find an image data. Change-Id: I016a60462ba586f9fa7585c2cfafffd7be38de7b Closes-Bug: #1741223 --- openstackclient/image/v2/image.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'openstackclient/image') diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py index d793c459..3db9311e 100644 --- a/openstackclient/image/v2/image.py +++ b/openstackclient/image/v2/image.py @@ -17,6 +17,7 @@ import argparse import logging +import sys from glanceclient.common import utils as gc_utils from osc_lib.cli import parseractions @@ -649,6 +650,12 @@ class SaveImage(command.Command): ) data = image_client.images.data(image.id) + if data.wrapped is None: + msg = _('Image %s has no data.') % image.id + LOG.error(msg) + sys.stdout.write(msg + '\n') + raise SystemExit + gc_utils.save_image(data, parsed_args.file) -- cgit v1.2.1