cinder-volume: Stop masking IOError different than ENOSPC

When glanceclient raises an IOError with a different errno than ENOSPC,
cinder-volume silently masked it and continued its volume creation
process. The result was volumes with invalid content being successfuly
created.

With the patch, an ImageDownloadFailed exception is raised in this case,
which makes the volume creation process fail and gives enough
information to operators for troubleshooting.

Change-Id: Ic011fe30b4840e5098db1a594ea276ec98768bff
Closes-Bug: #1799221
This commit is contained in:
Francois Deppierraz 2018-10-22 15:33:25 +02:00 committed by Brian Rosmaita
parent 84d268d9a0
commit 864c074ff1
3 changed files with 32 additions and 0 deletions

View File

@ -402,6 +402,12 @@ def fetch(context, image_service, image_id, path, _user_id, _project_id):
raise exception.ImageTooBig(image_id=image_id,
reason=reason)
reason = ("IOError: %(errno)s %(strerror)s" %
{'errno': e.errno, 'strerror': e.strerror})
LOG.error(reason)
raise exception.ImageDownloadFailed(image_href=image_id,
reason=reason)
duration = timeutils.delta_seconds(start_time, timeutils.utcnow())
# NOTE(jdg): use a default of 1, mostly for unit test, but in

View File

@ -383,6 +383,26 @@ class TestFetch(test.TestCase):
context, image_service, image_id, path,
_user_id, _project_id)
def test_fetch_ioerror(self):
context = mock.sentinel.context
image_service = mock.Mock()
image_id = mock.sentinel.image_id
e = IOError()
e.errno = errno.ECONNRESET
e.strerror = 'Some descriptive message'
image_service.download.side_effect = e
path = '/test_path'
_user_id = mock.sentinel._user_id
_project_id = mock.sentinel._project_id
with mock.patch('cinder.image.image_utils.open',
new=mock.mock_open(), create=True):
self.assertRaisesRegex(exception.ImageDownloadFailed,
e.strerror,
image_utils.fetch,
context, image_service, image_id, path,
_user_id, _project_id)
class MockVerifier(object):
def update(self, data):

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Fixed a bug which could create volumes with invalid content in case of
unhandled errors from glance client
(Bug `#1799221 <https://bugs.launchpad.net/cinder/+bug/1799221>`_).