Handle images with no data

There isn't really much we can do with these images, which glance tells
us are possible [1]. Simply raise an exception.

[1] https://docs.openstack.org/python-glanceclient/latest/reference/api/glanceclient.v2.images.html

Change-Id: I5f81393a5bb41e6a674369afb899d8a41bb2c3b4
Closes-Bug: #1736759
(cherry picked from commit c10a614e92)
This commit is contained in:
Stephen Finucane 2017-12-06 17:30:49 +00:00 committed by Stephen Finucane
parent c3f238e738
commit b72cefee4a
2 changed files with 19 additions and 0 deletions

View File

@ -294,6 +294,12 @@ class GlanceImageServiceV2(object):
except Exception:
_reraise_translated_image_exception(image_id)
if image_chunks.wrapped is None:
# None is a valid return value, but there's nothing we can do with
# a image with no associated data
raise exception.ImageUnacceptable(image_id=image_id,
reason='Image has no associated data')
# Retrieve properties for verification of Glance image signature
verifier = None
if CONF.glance.verify_glance_signatures:

View File

@ -637,6 +637,19 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
self.assertRaises(FakeDiskException, service.download, ctx,
mock.sentinel.image_id, data=Exceptionator())
@mock.patch.object(six.moves.builtins, 'open')
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
def test_download_no_returned_image_data_v2(
self, show_mock, open_mock):
"""Verify images with no data are handled correctly."""
client = mock.MagicMock()
client.call.return_value = fake_glance_response(None)
ctx = mock.sentinel.ctx
service = glance.GlanceImageServiceV2(client)
with testtools.ExpectedException(exception.ImageUnacceptable):
service.download(ctx, mock.sentinel.image_id)
@mock.patch('nova.image.glance.GlanceImageServiceV2._get_transfer_module')
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
def test_download_direct_file_uri_v2(self, show_mock, get_tran_mock):