From d3b01e4476cbee9fde01238dbdf0a41f0220e3a3 Mon Sep 17 00:00:00 2001 From: Johannes Erdfelt Date: Mon, 26 Mar 2012 14:58:27 +0000 Subject: Destroy src and dest instances when deleting in RESIZE_VERIFY Fixes bug 963630 Since deletes are allowed during RESIZE_VERIFY, we need to ensure that the original instance is also deleted so we don't leak resources. Change-Id: Ibfd5ad4e427c247f1cd5fddcf4f43b30839a6c4f --- nova/compute/api.py | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/nova/compute/api.py b/nova/compute/api.py index 79e490395..37e136a41 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -899,16 +899,30 @@ class API(base.Base): def _delete(self, context, instance): host = instance['host'] try: - if host: - self.update(context, - instance, - task_state=task_states.DELETING, - progress=0) - - self._cast_compute_message('terminate_instance', - context, instance) - else: - self.db.instance_destroy(context, instance['id']) + if not host: + # Just update database, nothing else we can do + return self.db.instance_destroy(context, instance['id']) + + self.update(context, + instance, + task_state=task_states.DELETING, + progress=0) + + if instance['task_state'] == task_states.RESIZE_VERIFY: + # If in the middle of a resize, use confirm_resize to + # ensure the original instance is cleaned up too + migration_ref = self.db.migration_get_by_instance_and_status( + context, instance['uuid'], 'finished') + if migration_ref: + src_host = migration_ref['source_compute'] + params = {'migration_id': migration_ref['id']} + # Call since this can race with the terminate_instance + self._call_compute_message('confirm_resize', context, + instance, host=src_host, + params=params) + + self._cast_compute_message('terminate_instance', + context, instance) except exception.InstanceNotFound: # NOTE(comstud): Race condition. Instance already gone. pass -- cgit