Skip to content

Commit

Permalink
Fix issues deleting instances in RESIZED state
Browse files Browse the repository at this point in the history
DB API call migration_get_by_instance_and_status requires admin
context...and it'll also raise an exception if no migration matches.

_delete() in compute/api was not using admin context, and was checking
for a false return from the DB call vs checking for an exception.

Added a test that covers both problems.

Fixes bug 1056601

Change-Id: Ib3c631dccbb2776761cf5acb8bab1d814bf3e282
(cherry picked from commit 8c9c380)
  • Loading branch information
comstud authored and Chuck Short committed Oct 24, 2012
1 parent d1e462d commit ded0473
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions nova/compute/api.py
Expand Up @@ -880,8 +880,12 @@ def _delete(self, context, instance):
if instance['vm_state'] == vm_states.RESIZED:
# 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')
get_migration = self.db.migration_get_by_instance_and_status
try:
migration_ref = get_migration(context.elevated(),
instance['uuid'], 'finished')
except exception.MigrationNotFoundByStatus:
migration_ref = None
if migration_ref:
src_host = migration_ref['source_compute']
# Call since this can race with the terminate_instance.
Expand Down
13 changes: 13 additions & 0 deletions nova/tests/compute/test_compute.py
Expand Up @@ -2986,6 +2986,19 @@ def test_delete(self):

db.instance_destroy(self.context, instance['uuid'])

def test_delete_in_resized(self):
instance, instance_uuid = self._run_instance(params={
'host': FLAGS.host})

instance['vm_state'] = vm_states.RESIZED

self.compute_api.delete(self.context, instance)

instance = db.instance_get_by_uuid(self.context, instance_uuid)
self.assertEqual(instance['task_state'], task_states.DELETING)

db.instance_destroy(self.context, instance['uuid'])

def test_repeated_delete_quota(self):
in_use = {'instances': 1}

Expand Down

0 comments on commit ded0473

Please sign in to comment.