VMware: Always upload a snapshot as a preallocated disk

Currently, a snapshot operation always produces a preallocated
disk type. When the snapshot is uploaded to glance, the source
image metadata is uploaded with the new snapshot and then some
of the metadata properties are updated. The update doesn't
include the disk_type property, this can be problematic. If
the original image has a sparse disk type and a snapshot is
taken, then the snapshot which is a preallocated disk type is
uploaded to glance with the disk_type property set to sparse,
which creates a disk type mismatch and causes errors when a vm
is spawned from that snapshot. This patch addresses the issue
by correcting the image metadata used when uploading a snapshot
to glance.

Also, the image_upload function in vmwareapi/fake.py has been
modified to address the change. Any function call to
image_upload (from the unit tests) will assert that the
metadata for the image to be uploaded must have the disk_type
value to be preallocated.

Closes-Bug: 1247296
(cherry picked from commit 11e327f888)

Conflicts:

	nova/tests/virt/vmwareapi/test_vmwareapi.py
Change-Id: I71cfa8d4d1eb7911abb489153292fb0d1e614765
This commit is contained in:
Maithem 2013-11-11 16:08:02 -08:00 committed by Tracy Jones
parent dce539bf06
commit 9520b8dfc2
3 changed files with 12 additions and 3 deletions

12
nova/tests/virt/vmwareapi/test_vmwareapi.py Normal file → Executable file
View File

@ -22,7 +22,6 @@ Test suite for VMwareAPI.
"""
import contextlib
import mock
import mox
from oslo.config import cfg
@ -477,6 +476,11 @@ class VMwareAPIVMTestCase(test.NoDBTestCase):
network_info=self.network_info,
block_device_info=block_device_info)
def mock_upload_image(self, context, image, instance, **kwargs):
self.assertEqual(image, 'Test-Snapshot')
self.assertEqual(instance, self.instance)
self.assertEqual(kwargs['disk_type'], 'preallocated')
def _test_snapshot(self):
expected_calls = [
{'args': (),
@ -490,8 +494,10 @@ class VMwareAPIVMTestCase(test.NoDBTestCase):
info = self.conn.get_info({'uuid': self.uuid,
'node': self.instance_node})
self._check_vm_info(info, power_state.RUNNING)
self.conn.snapshot(self.context, self.instance, "Test-Snapshot",
func_call_matcher.call)
with mock.patch.object(vmware_images, 'upload_image',
self.mock_upload_image):
self.conn.snapshot(self.context, self.instance, "Test-Snapshot",
func_call_matcher.call)
info = self.conn.get_info({'uuid': self.uuid,
'node': self.instance_node})
self._check_vm_info(info, power_state.RUNNING)

View File

@ -785,6 +785,7 @@ class VMwareVMOps(object):
image_id,
instance,
os_type=os_type,
disk_type="preallocated",
adapter_type=adapter_type,
image_version=1,
host=self._session._host_ip,

View File

@ -160,6 +160,8 @@ def upload_image(context, image, instance, **kwargs):
"size": file_size,
"properties": {"vmware_adaptertype":
kwargs.get("adapter_type"),
"vmware_disktype":
kwargs.get("disk_type"),
"vmware_ostype": kwargs.get("os_type"),
"vmware_image_version":
kwargs.get("image_version"),