Fixed instance deletion issue from Nova API.

When host Compute is down, Nova API deletes the resources associated with the
instance. However, since the instance is marked deleted first, the next query
to update the instance vm_state and task_state in DB fails. And instance
remains in state vm_state=ACTIVE, task_state=DELETING, deleted=True.

Fixes LP: #1074305

Change-Id: I0a4e64d180b4b2c5e398a21a62b29b7d59549a9f
This commit is contained in:
Unmesh Gurjar 2012-11-02 07:08:46 -07:00
parent d8d00ef308
commit d00f09f2eb
2 changed files with 9 additions and 6 deletions

View File

@ -954,7 +954,6 @@ class API(base.Base):
elevated = context.elevated()
self.network_api.deallocate_for_instance(elevated,
instance)
self.db.instance_destroy(context, instance_uuid)
system_meta = self.db.instance_system_metadata_get(context,
instance_uuid)
@ -979,6 +978,7 @@ class API(base.Base):
vm_state=vm_states.DELETED,
task_state=None,
terminated_at=timeutils.utcnow())
self.db.instance_destroy(context, instance_uuid)
compute_utils.notify_about_instance_usage(
context, instance, "delete.end", system_metadata=system_meta)

View File

@ -3150,7 +3150,7 @@ class ComputeAPITestCase(BaseTestCase):
def dummy(*args, **kwargs):
self.network_api_called = True
pass
self.stubs.Set(self.compute_api.network_api, 'deallocate_for_instance',
dummy)
@ -3166,10 +3166,13 @@ class ComputeAPITestCase(BaseTestCase):
self.assertEqual(instance['task_state'], None)
self.assertTrue(self.network_api_called)
#local delete, so db should be clean
self.assertRaises(exception.InstanceNotFound, db.instance_destroy,
self.context,
instance['uuid'])
# fetch the instance state from db and verify deletion.
deleted_context = context.RequestContext('fake', 'fake',
read_deleted='yes')
instance = db.instance_get_by_uuid(deleted_context, instance_uuid)
self.assertEqual(instance['vm_state'], vm_states.DELETED)
self.assertEqual(instance['task_state'], None)
self.assertTrue(instance['deleted'])
def test_repeated_delete_quota(self):
in_use = {'instances': 1}