From c04b431cd63f4d934f40dd1f62a9107ae6dfde90 Mon Sep 17 00:00:00 2001 From: Aaron Lee Date: Thu, 3 Nov 2011 15:05:30 -0500 Subject: Move failed instances to error state On instance creation there is the possibility of an instance raising. This would not cause the instance to be moved to the error state. This patch fixes that. lp885323 update 1: fixing exception handling update 2: preserving the individual messages update 3: rebase on master & fix spacing Change-Id: I7584b527e408c08014f1b6a8abda343f1e2aa3b8 --- nova/tests/test_compute.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index b235bcade..4b80cc58a 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -44,6 +44,7 @@ from nova.db.sqlalchemy import models from nova.image import fake as fake_image from nova.notifier import test_notifier from nova.tests import fake_network +from nova.network.quantum import client as quantum_client LOG = logging.getLogger('nova.tests.compute') @@ -551,6 +552,50 @@ class ComputeTestCase(test.TestCase): instance_id) self.compute.terminate_instance(self.context, instance_id) + def test_instance_set_to_error_on_uncaught_exception(self): + """Test that instance is set to error state when exception is raised""" + instance_id = self._create_instance() + + self.mox.StubOutWithMock(self.compute.network_api, + "allocate_for_instance") + self.compute.network_api.allocate_for_instance(mox.IgnoreArg(), + mox.IgnoreArg(), + requested_networks=None, + vpn=False).\ + AndRaise(quantum_client.QuantumServerException()) + + FLAGS.stub_network = False + + self.mox.ReplayAll() + + self.assertRaises(quantum_client.QuantumServerException, + self.compute.run_instance, + self.context, + instance_id) + + instances = db.instance_get_all(context.get_admin_context()) + self.assertEqual(vm_states.ERROR, instances[0]['vm_state']) + + self.compute.terminate_instance(self.context, instance_id) + + def test_network_is_deallocated_on_spawn_failure(self): + """When a spawn fails the network must be deallocated""" + instance_id = self._create_instance() + + self.mox.StubOutWithMock(self.compute, "_setup_block_device_mapping") + self.compute._setup_block_device_mapping(mox.IgnoreArg(), + mox.IgnoreArg()).\ + AndRaise(rpc.common.RemoteError('', '', '')) + + self.mox.ReplayAll() + + self.assertRaises(rpc.common.RemoteError, + self.compute.run_instance, + self.context, + instance_id) + + self.compute.terminate_instance(self.context, instance_id) + def test_lock(self): """ensure locked instance cannot be changed""" instance_id = self._create_instance() -- cgit