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:
parent
d8d00ef308
commit
d00f09f2eb
@ -954,7 +954,6 @@ class API(base.Base):
|
|||||||
elevated = context.elevated()
|
elevated = context.elevated()
|
||||||
self.network_api.deallocate_for_instance(elevated,
|
self.network_api.deallocate_for_instance(elevated,
|
||||||
instance)
|
instance)
|
||||||
self.db.instance_destroy(context, instance_uuid)
|
|
||||||
system_meta = self.db.instance_system_metadata_get(context,
|
system_meta = self.db.instance_system_metadata_get(context,
|
||||||
instance_uuid)
|
instance_uuid)
|
||||||
|
|
||||||
@ -979,6 +978,7 @@ class API(base.Base):
|
|||||||
vm_state=vm_states.DELETED,
|
vm_state=vm_states.DELETED,
|
||||||
task_state=None,
|
task_state=None,
|
||||||
terminated_at=timeutils.utcnow())
|
terminated_at=timeutils.utcnow())
|
||||||
|
self.db.instance_destroy(context, instance_uuid)
|
||||||
compute_utils.notify_about_instance_usage(
|
compute_utils.notify_about_instance_usage(
|
||||||
context, instance, "delete.end", system_metadata=system_meta)
|
context, instance, "delete.end", system_metadata=system_meta)
|
||||||
|
|
||||||
|
@ -3150,7 +3150,7 @@ class ComputeAPITestCase(BaseTestCase):
|
|||||||
|
|
||||||
def dummy(*args, **kwargs):
|
def dummy(*args, **kwargs):
|
||||||
self.network_api_called = True
|
self.network_api_called = True
|
||||||
pass
|
|
||||||
self.stubs.Set(self.compute_api.network_api, 'deallocate_for_instance',
|
self.stubs.Set(self.compute_api.network_api, 'deallocate_for_instance',
|
||||||
dummy)
|
dummy)
|
||||||
|
|
||||||
@ -3166,10 +3166,13 @@ class ComputeAPITestCase(BaseTestCase):
|
|||||||
self.assertEqual(instance['task_state'], None)
|
self.assertEqual(instance['task_state'], None)
|
||||||
self.assertTrue(self.network_api_called)
|
self.assertTrue(self.network_api_called)
|
||||||
|
|
||||||
#local delete, so db should be clean
|
# fetch the instance state from db and verify deletion.
|
||||||
self.assertRaises(exception.InstanceNotFound, db.instance_destroy,
|
deleted_context = context.RequestContext('fake', 'fake',
|
||||||
self.context,
|
read_deleted='yes')
|
||||||
instance['uuid'])
|
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):
|
def test_repeated_delete_quota(self):
|
||||||
in_use = {'instances': 1}
|
in_use = {'instances': 1}
|
||||||
|
Loading…
Reference in New Issue
Block a user