Skip to content

Commit

Permalink
VMwareVCDriver Fix sparse disk copy error on spawn
Browse files Browse the repository at this point in the history
The same approach of calling VirtualDiskManager.CopyVirtualDisk
without destination disk spec in the cluster driver for fixing 1184807
turns out to work for copying a sparse disk as well because vCenter's behavior
for specless copy is to do the reasonable thing of converting a sparse disk to
thin-provisioned, and a flat disk to preallocated.

Tests done:

Verified using tempest that sparse/thin/preallocated image types deploys
properly through the cluster driver. Tempest output to be included in
the review comments.

Fixes bug 1171226

(cherry picked from commit 42e929e)

Conflicts:

	nova/tests/virt/vmwareapi/test_vmwareapi.py
	nova/virt/vmwareapi/vmops.py

Change-Id: I51627ddb4b9df8cf80f0b9c6efe68ec9eb68cd99
  • Loading branch information
vuil authored and gkotton committed Oct 9, 2013
1 parent 62f2218 commit d791181
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 14 deletions.
41 changes: 38 additions & 3 deletions nova/tests/test_vmwareapi.py
Expand Up @@ -41,6 +41,7 @@
from nova.virt.vmwareapi import vim
from nova.virt.vmwareapi import vm_util
from nova.virt.vmwareapi import vmops
from nova.virt.vmwareapi import vmware_images
from nova.virt.vmwareapi import volume_util


Expand Down Expand Up @@ -249,10 +250,10 @@ def _test_snapshot(self):
self.assertIsNone(func_call_matcher.match())

def test_snapshot(self):
# Ensure VMwareVCVMOps's _get_copy_virtual_disk_spec is getting called
# Ensure VMwareVCVMOps's get_copy_virtual_disk_spec is getting called
self.mox.StubOutWithMock(vmops.VMwareVCVMOps,
'_get_copy_virtual_disk_spec')
self.conn._vmops._get_copy_virtual_disk_spec(
'get_copy_virtual_disk_spec')
self.conn._vmops.get_copy_virtual_disk_spec(
mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(None)
Expand Down Expand Up @@ -547,3 +548,37 @@ def test_get_available_resource(self):
self.assertEquals(stats['hypervisor_version'], '5.1.0')
self.assertEquals(stats['hypervisor_hostname'], self.node_name)
self.assertEquals(stats['cpu_info'], jsonutils.dumps(cpu_info))

def test_snapshot(self):
# Ensure VMwareVCVMOps's get_copy_virtual_disk_spec is getting called
# two times
self.mox.StubOutWithMock(vmops.VMwareVCVMOps,
'get_copy_virtual_disk_spec')
self.conn._vmops.get_copy_virtual_disk_spec(
mox.IgnoreArg(), mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(None)
self.mox.ReplayAll()

self._test_snapshot()

def test_spawn_with_sparse_image(self):
# Only a sparse disk image triggers the copy
self.mox.StubOutWithMock(vmware_images, 'get_vmdk_size_and_properties')
result = [1024, {"vmware_ostype": "otherGuest",
"vmware_adaptertype": "lsiLogic",
"vmware_disktype": "sparse"}]
vmware_images.get_vmdk_size_and_properties(
mox.IgnoreArg(), mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(result)

# Ensure VMwareVCVMOps's get_copy_virtual_disk_spec is getting called
# two times
self.mox.StubOutWithMock(vmops.VMwareVCVMOps,
'get_copy_virtual_disk_spec')
self.conn._vmops.get_copy_virtual_disk_spec(
mox.IgnoreArg(), mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(None)
self.mox.ReplayAll()
self._create_vm()
info = self.conn.get_info({'uuid': 'fake-uuid'})
self._check_vm_info(info, power_state.RUNNING)
22 changes: 11 additions & 11 deletions nova/virt/vmwareapi/vmops.py
Expand Up @@ -325,9 +325,9 @@ def _copy_virtual_disk():
"data_store_name": data_store_name,
"disk_type": disk_type},
instance=instance)
vmdk_copy_spec = vm_util.get_vmdk_create_spec(client_factory,
vmdk_file_size_in_kb, adapter_type,
disk_type)
vmdk_copy_spec = self.get_copy_virtual_disk_spec(client_factory,
adapter_type,
disk_type)
vmdk_copy_task = self._session._call_method(
self._session._get_vim(),
"CopyVirtualDisk_Task",
Expand Down Expand Up @@ -425,8 +425,8 @@ def _power_on_vm():
LOG.debug(_("Powered on the VM instance"), instance=instance)
_power_on_vm()

def _get_copy_virtual_disk_spec(self, client_factory, adapter_type,
disk_type):
def get_copy_virtual_disk_spec(self, client_factory, adapter_type,
disk_type):
return vm_util.get_copy_virtual_disk_spec(client_factory,
adapter_type,
disk_type)
Expand Down Expand Up @@ -521,11 +521,11 @@ def _check_if_tmp_folder_exists():
dc_ref = self._get_datacenter_ref_and_name()[0]

def _copy_vmdk_content():
# Copy the contents of the disk ( or disks, if there were snapshots
# Copy the contents of the disk (or disks, if there were snapshots
# done earlier) to a temporary vmdk file.
copy_spec = self._get_copy_virtual_disk_spec(client_factory,
adapter_type,
disk_type)
copy_spec = self.get_copy_virtual_disk_spec(client_factory,
adapter_type,
disk_type)
LOG.debug(_('Copying disk data before snapshot of the VM'),
instance=instance)
copy_disk_task = self._session._call_method(
Expand Down Expand Up @@ -1332,8 +1332,8 @@ class VMwareVCVMOps(VMwareVMOps):
when invoked on Virtual Center instead of ESX host.
"""

def _get_copy_virtual_disk_spec(self, client_factory, adapter_type,
disk_type):
def get_copy_virtual_disk_spec(self, client_factory, adapter_type,
disk_type):
LOG.debug(_("Will copy while retaining adapter type "
"%(adapter_type)s and disk type %(disk_type)s") %
{"disk_type": disk_type,
Expand Down

0 comments on commit d791181

Please sign in to comment.