Merge "Fix image format error on vol-backed snapshot"

This commit is contained in:
Zuul
2024-10-08 19:07:44 +00:00
committed by Gerrit Code Review
2 changed files with 24 additions and 8 deletions
+10 -3
View File
@@ -645,10 +645,17 @@ class GlanceImageServiceV2(object):
# where we have to hardcode this parameters.
if force_activate:
data = ''
# NOTE(danms): If we are using this terrible hack to upload
# zero-length data to activate the image, we cannot claim it
# is some format other than 'raw'. If the caller asked for
# something specific, that's a bug. Otherwise, we must force
# disk_format=raw.
if 'disk_format' not in sent_service_image_meta:
sent_service_image_meta['disk_format'] = (
self._get_image_create_disk_format_default(context)
)
sent_service_image_meta['disk_format'] = 'raw'
elif sent_service_image_meta['disk_format'] != 'raw':
raise exception.ImageBadRequest(
'Unable to force activate with disk_format=%s' % (
sent_service_image_meta['disk_format']))
if 'container_format' not in sent_service_image_meta:
sent_service_image_meta['container_format'] = 'bare'
+14 -5
View File
@@ -1721,18 +1721,27 @@ class TestCreate(test.NoDBTestCase):
client.call.return_value = {'id': '123'}
ctx = mock.sentinel.ctx
service = glance.GlanceImageServiceV2(client)
with mock.patch.object(service,
'_get_image_create_disk_format_default',
return_value='vdi'):
image_meta = service.create(ctx, image_mock)
image_meta = service.create(ctx, image_mock)
trans_to_mock.assert_called_once_with(image_mock)
# Verify that the disk_format and container_format kwargs are passed.
create_call_kwargs = client.call.call_args_list[0][1]['kwargs']
self.assertEqual('vdi', create_call_kwargs['disk_format'])
self.assertEqual('raw', create_call_kwargs['disk_format'])
self.assertEqual('bare', create_call_kwargs['container_format'])
trans_from_mock.assert_called_once_with({'id': '123'})
self.assertEqual(mock.sentinel.trans_from, image_meta)
def test_create_v2_rejects_incompatible_disk_format(self):
client = mock.MagicMock()
client.call.return_value = {'id': '123'}
ctx = mock.sentinel.ctx
service = glance.GlanceImageServiceV2(client)
self.assertRaisesRegex(exception.ImageBadRequest,
'Unable to force activate',
service._create_v2,
ctx,
{'disk_format': 'qcow2'},
force_activate=True)
@mock.patch('nova.image.glance._translate_from_glance')
@mock.patch('nova.image.glance._translate_to_glance')
def test_create_success_v2_with_location(