Fix run/terminate race conditions.

* synchronize run,terminate,stop,start on instance_uuid
 * don't surpress error when unfiltering instance, which
   can result in a zombified instance.
 * Fixes bug 956719
 * Remove debug raise

Change-Id: I8b2eaffdabfd5c1a9414adb1b5ed11e4c48711fc
This commit is contained in:
Anthony Young
2012-03-16 16:51:03 -07:00
parent 07cc4d056e
commit a1100cb719
2 changed files with 14 additions and 15 deletions

View File

@@ -330,6 +330,10 @@ class InstanceRebootFailure(Invalid):
message = _("Failed to reboot instance") + ": %(reason)s" message = _("Failed to reboot instance") + ": %(reason)s"
class InstanceTerminationFailure(Invalid):
message = _("Failed to terminate instance") + ": %(reason)s"
class ServiceUnavailable(Invalid): class ServiceUnavailable(Invalid):
message = _("Service is unavailable at this time.") message = _("Service is unavailable at this time.")

View File

@@ -932,26 +932,21 @@ class ComputeTestCase(BaseTestCase):
self.compute.terminate_instance(self.context, instance['uuid']) self.compute.terminate_instance(self.context, instance['uuid'])
def test_instance_set_to_error_on_deleted_instance_doesnt_raise(self): def test_instance_termination_exception_sets_error(self):
"""Test that we don't raise InstanceNotFound when trying to set """Test that we handle InstanceTerminationFailure
an instance to ERROR that has already been deleted from under us. which is propagated up from the underlying driver.
The original exception should be re-raised.
""" """
instance = self._create_fake_instance() instance = self._create_fake_instance()
instance_uuid = instance['uuid']
def fake_allocate_network(context, instance, requested_networks): def fake_delete_instance(context, instance):
# Remove the instance to simulate race condition raise exception.InstanceTerminationFailure(reason='')
self.compute.terminate_instance(self.context, instance['uuid'])
raise rpc_common.RemoteError()
self.stubs.Set(self.compute, '_allocate_network', self.stubs.Set(self.compute, '_delete_instance',
fake_allocate_network) fake_delete_instance)
self.assertRaises(rpc_common.RemoteError, self.compute.terminate_instance(self.context, instance['uuid'])
self.compute.run_instance, instance = db.instance_get_by_uuid(self.context, instance['uuid'])
self.context, self.assertEqual(instance['vm_state'], vm_states.ERROR)
instance_uuid)
def test_network_is_deallocated_on_spawn_failure(self): def test_network_is_deallocated_on_spawn_failure(self):
"""When a spawn fails the network must be deallocated""" """When a spawn fails the network must be deallocated"""