summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-10-07 10:27:45 +0000
committerGerrit Code Review <review@openstack.org>2014-10-07 10:27:45 +0000
commit3f4f7a34d497c342e0592ba46ea9ce8ade5f8ead (patch)
tree614cf09245304547d52188e9f4d5a14d03935105
parent7caf12e258f01bf0811302bbe0d47dd40b56e6f0 (diff)
parent5065aeca1b4acad513c07e3832ec0e12de2e6568 (diff)
downloadnova-3f4f7a34d497c342e0592ba46ea9ce8ade5f8ead.tar.gz
Merge "Destroy orig VM during resize if triggered by user" into proposed/juno
-rw-r--r--nova/tests/virt/vmwareapi/test_driver_api.py44
-rw-r--r--nova/virt/vmwareapi/vmops.py26
2 files changed, 46 insertions, 24 deletions
diff --git a/nova/tests/virt/vmwareapi/test_driver_api.py b/nova/tests/virt/vmwareapi/test_driver_api.py
index 7d99a98818..5de075c01c 100644
--- a/nova/tests/virt/vmwareapi/test_driver_api.py
+++ b/nova/tests/virt/vmwareapi/test_driver_api.py
@@ -1471,28 +1471,46 @@ class VMwareAPIVMTestCase(test.NoDBTestCase):
None, self.destroy_disks)
self.assertFalse(mock_destroy.called)
- def test_destroy_instance_without_vm_ref(self):
+ def _destroy_instance_without_vm_ref(self, resize_exists=False,
+ task_state=None):
+
+ def fake_vm_ref_from_name(session, vm_name):
+ if resize_exists:
+ return 'fake-ref'
+
self._create_instance()
with contextlib.nested(
mock.patch.object(vm_util, 'get_vm_ref_from_name',
- return_value=None),
+ fake_vm_ref_from_name),
mock.patch.object(self.conn._session,
- '_call_method')
- ) as (mock_get, mock_call):
+ '_call_method'),
+ mock.patch.object(self.conn._vmops,
+ '_destroy_instance')
+ ) as (mock_get, mock_call, mock_destroy):
+ self.instance.task_state = task_state
self.conn.destroy(self.context, self.instance,
self.network_info,
None, True)
- 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)
+ if resize_exists:
+ if task_state == task_states.RESIZE_REVERTING:
+ expected = 1
+ else:
+ expected = 2
+ else:
+ expected = 1
+ self.assertEqual(expected, mock_destroy.call_count)
self.assertFalse(mock_call.called)
+ def test_destroy_instance_without_vm_ref(self):
+ self._destroy_instance_without_vm_ref()
+
+ def test_destroy_instance_without_vm_ref_with_resize(self):
+ self._destroy_instance_without_vm_ref(resize_exists=True)
+
+ def test_destroy_instance_without_vm_ref_with_resize_revert(self):
+ self._destroy_instance_without_vm_ref(resize_exists=True,
+ task_state=task_states.RESIZE_REVERTING)
+
def _rescue(self, config_drive=False):
# validate that the power on is only called once
self._power_on = vm_util.power_on_instance
diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py
index 5c6b580b1a..f705febbae 100644
--- a/nova/virt/vmwareapi/vmops.py
+++ b/nova/virt/vmwareapi/vmops.py
@@ -838,17 +838,21 @@ 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)
+ # NOTE(arnaud): Destroy uuid-orig and uuid VMs iff it is not
+ # triggered by the revert resize api call. This prevents
+ # the uuid-orig VM to be deleted to be able to associate it later.
+ if instance.task_state != task_states.RESIZE_REVERTING:
+ # 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)