From 805368e902ada4c63e2e6e4d6692cf8cc2531a1e Mon Sep 17 00:00:00 2001 From: Marc Methot Date: Tue, 16 Oct 2018 12:37:28 -0400 Subject: [PATCH] Handling unexpected python error "NoneType object is not iterable" The glance documentation states that None (empty image) is a valid return value. We have to handle this outcome. Adding error handling helps debugging this unhandled issue Change-Id: If7c22ac4516f8c2a6ccd8bf6b6ed98409312b138 Closes-Bug: #1798147 (cherry picked from commit d3afc39467c6532344118e8e491409878da9c2dd) --- cinder/exception.py | 4 ++++ cinder/image/glance.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/cinder/exception.py b/cinder/exception.py index 0ed4e08d53d..d7bb818d9b3 100644 --- a/cinder/exception.py +++ b/cinder/exception.py @@ -727,6 +727,10 @@ class GlanceMetadataNotFound(NotFound): message = _("Glance metadata for volume/snapshot %(id)s cannot be found.") +class ImageDownloadFailed(CinderException): + _msg_fmt = _("Failed to download image %(image_href)s, reason: %(reason)s") + + class ExportFailure(Invalid): message = _("Failed to export for volume: %(reason)s") diff --git a/cinder/image/glance.py b/cinder/image/glance.py index 476ca7f8552..ff6c1bc3101 100644 --- a/cinder/image/glance.py +++ b/cinder/image/glance.py @@ -357,6 +357,10 @@ class GlanceImageService(object): except Exception: _reraise_translated_image_exception(image_id) + if image_chunks is None: + raise exception.ImageDownloadFailed( + image_href=context, reason=_('image contains no data.')) + if not data: return image_chunks else: