VMWare: Fix VM leak when deletion of VM during resizing

During the VM resizing, before VM arrive RESIZED state, driver
migrate_disk_and_power_off will initially rename orginal vm
'uuid' to be 'uuid-orig' and clone a new vm with 'uuid' name.
When deletion VM is triggered at this time window, it wouldn't
be able to delete the VM uuid-orig in VCenter and so cause VM leak.
As VM task state will be set to 'deleting' and it can not be used to
determine the resize migrating/migrated state, this fix will
attempt to delete orig VM within destroy phase.

Change-Id: I7598afbf0dc3c527471af34224003d28e64daaff
Closes-Bug: #1359138
This commit is contained in:
ZHU ZHU 2014-09-03 03:59:13 -05:00
parent e7469a8c1b
commit e1f8664c9f
2 changed files with 20 additions and 2 deletions

View File

@ -1482,8 +1482,15 @@ class VMwareAPIVMTestCase(test.NoDBTestCase):
self.conn.destroy(self.context, self.instance,
self.network_info,
None, True)
mock_get.assert_called_once_with(self.conn._vmops._session,
self.instance['uuid'])
mock_get.assert_called_with(self.conn._vmops._session,
self.instance['uuid'])
expected_args = [((self.conn._vmops._session,
self.instance['uuid'] + '-orig'),),
((self.conn._vmops._session,
self.instance['uuid']),)]
# one for VM named uuid-orig, one for VM named uuid
self.assertEqual(expected_args, mock_get.call_args_list)
self.assertEqual(2, mock_get.call_count)
self.assertFalse(mock_call.called)
def _rescue(self, config_drive=False):

View File

@ -839,6 +839,17 @@ class VMwareVMOps(object):
self._destroy_instance(instance,
destroy_disks=destroy_disks,
instance_name=rescue_name)
# When VM deletion is triggered in middle of VM resize before VM
# arrive RESIZED state, uuid-orig VM need to deleted to avoid
# VM leak. Within method _destroy_instance it will check vmref
# exist or not before attempt deletion.
resize_orig_vmname = instance['uuid'] + self._migrate_suffix
vm_orig_ref = vm_util.get_vm_ref_from_name(self._session,
resize_orig_vmname)
if vm_orig_ref:
self._destroy_instance(instance,
destroy_disks=destroy_disks,
instance_name=resize_orig_vmname)
self._destroy_instance(instance, destroy_disks=destroy_disks)
LOG.debug("Instance destroyed", instance=instance)