Compute API: omit disk/container formats when creating images of snapshots

If making a snapshot, omit the disk and container formats from the
image API request, since the image may have been converted to another
format than what the base image uses.  The driver will correctly
populate these values later when uploading the image data.

Closes-Bug: 1497484
Change-Id: I69522977631be2ae42ac504740c04247c75022eb
(cherry picked from commit 8cfc8a8375)
This commit is contained in:
Nicolas Simonds 2015-09-21 11:17:43 -07:00 committed by Lee Yarwood
parent a2058ea8de
commit 0c21aff7e1
2 changed files with 13 additions and 0 deletions

View File

@ -2270,6 +2270,13 @@ class API(base.Base):
image_meta = self._initialize_instance_snapshot_metadata(
instance, name, properties)
# if we're making a snapshot, omit the disk and container formats,
# since the image may have been converted to another format, and the
# original values won't be accurate. The driver will populate these
# with the correct values later, on image upload.
if image_type == 'snapshot':
image_meta.pop('disk_format', None)
image_meta.pop('container_format', None)
return self.image_api.create(context, image_meta)
def _initialize_instance_snapshot_metadata(self, instance, name,

View File

@ -2034,6 +2034,8 @@ class _ComputeAPIUnitTestMixIn(object):
fake_image_meta = {
'is_public': True,
'name': 'base-name',
'disk_format': 'fake',
'container_format': 'fake',
'properties': {
'user_id': 'meow',
'foo': 'bar',
@ -2045,6 +2047,8 @@ class _ComputeAPIUnitTestMixIn(object):
sent_meta = {
'is_public': False,
'name': 'fake-name',
'disk_format': 'fake',
'container_format': 'fake',
'properties': {
'user_id': self.context.user_id,
'instance_uuid': instance.uuid,
@ -2063,6 +2067,8 @@ class _ComputeAPIUnitTestMixIn(object):
if min_disk is not None:
fake_image_meta['min_disk'] = min_disk
sent_meta['min_disk'] = min_disk
sent_meta.pop('disk_format', None)
sent_meta.pop('container_format', None)
else:
sent_meta['properties']['backup_type'] = 'fake-backup-type'