From fee8409208af77f1f01c7ef3c5438cb7ef493b3d Mon Sep 17 00:00:00 2001 From: Radoslav Gerganov Date: Tue, 18 Jul 2017 11:35:47 +0300 Subject: [PATCH] VMware: Handle missing volume vmdk during detach During storage vMotion (live migration of a virtual machine and its disk files from one datastore to another), the volume's vmdk may be moved to the instance's datastore folder. We handle this case during detach volume by catching FileNotFoundException raised by shadow VM relocate operation. The shadow VM relocate will be NOP if the source and the destination datastores are the same. In this case, the subsequent detach disk device from shadow VM will fail if the volume vmdk is missing. Handling this case by catching and ignoring FileNotFoundException raised by the detach operation. Change-Id: I33ad36b147f040364514d8097a1dfc363c50b0b7 Closes-Bug: #1704196 Co-Authored-By: vbala@vmware.com Co-Authored-By: mrstarke@gmail.com --- nova/tests/unit/virt/vmwareapi/test_volumeops.py | 2 ++ nova/virt/vmwareapi/volumeops.py | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/nova/tests/unit/virt/vmwareapi/test_volumeops.py b/nova/tests/unit/virt/vmwareapi/test_volumeops.py index 2b36f72bd3..ac6d7b7b92 100644 --- a/nova/tests/unit/virt/vmwareapi/test_volumeops.py +++ b/nova/tests/unit/virt/vmwareapi/test_volumeops.py @@ -537,6 +537,8 @@ class VMwareVolumeOpsTestCase(test.NoDBTestCase): rp = mock.sentinel.rp get_res_pool_of_host.return_value = rp + detach_disk_from_vm.side_effect = [ + oslo_vmw_exceptions.FileNotFoundException] instance = self._instance volume_ref = mock.sentinel.volume_ref vm_ref = mock.sentinel.vm_ref diff --git a/nova/virt/vmwareapi/volumeops.py b/nova/virt/vmwareapi/volumeops.py index 5b211fe5b3..76a5716b81 100644 --- a/nova/virt/vmwareapi/volumeops.py +++ b/nova/virt/vmwareapi/volumeops.py @@ -490,8 +490,12 @@ class VMwareVolumeOps(object): # Volume's backing is relocated now; detach the old vmdk if not done # already. if not detached: - self.detach_disk_from_vm(volume_ref, instance, original_device, - destroy_disk=True) + try: + self.detach_disk_from_vm(volume_ref, instance, + original_device, destroy_disk=True) + except oslo_vmw_exceptions.FileNotFoundException: + LOG.debug("Original volume backing %s is missing, no need " + "to detach it", original_device.backing.fileName) # Attach the current volume to the volume_ref self.attach_disk_to_vm(volume_ref, instance,