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

Change-Id: I6c48866e06c2aa656c89848564f3262fb7b79039
  • Loading branch information
vuil committed Sep 20, 2013
1 parent 839baff commit 42e929e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
31 changes: 26 additions & 5 deletions nova/tests/virt/vmwareapi/test_vmwareapi.py
Expand Up @@ -45,6 +45,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
from nova.virt.vmwareapi import volumeops

Expand Down Expand Up @@ -992,12 +993,11 @@ def test_get_vnc_console(self):
fake_vm_id % cfg.CONF.vmware.vnc_port_total)

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(
mox.IgnoreArg(),
mox.IgnoreArg(),
'get_copy_virtual_disk_spec')
self.conn._vmops.get_copy_virtual_disk_spec(
mox.IgnoreArg(), mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(None)
self.mox.ReplayAll()

Expand All @@ -1010,3 +1010,24 @@ def test_spawn_invalid_node(self):
injected_files=[], admin_password=None,
network_info=self.network_info,
block_device_info=None)

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
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 @@ -350,9 +350,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 @@ -580,8 +580,8 @@ def decide_linked_clone(image_linked_clone, global_linked_clone):

return utils.get_boolean(value)

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 @@ -676,11 +676,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 @@ -1498,8 +1498,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 42e929e

Please sign in to comment.