From 3b4016184f83c71158d41db9a26e6043d9ae1506 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Wed, 16 Jan 2013 12:47:04 -0800 Subject: Makes sure compute doesn't crash on failed resume. If the call to the driver to resume an instance raises an exception, then nova-compute fails to start properly. This can happen during recovery, for example, where an instance has been deleted so the backing files are gone but the database is restored to a state where it exists. This patch fixes the issue by catching the exception and setting the instance to error. Fixes bug 1100430 Change-Id: Ie31f39fcd43174c29bf7a5cb1b6fa29e4c723f97 --- nova/tests/compute/test_compute.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 40bc8d148..3deb100f6 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -3249,6 +3249,35 @@ class ComputeTestCase(BaseTestCase): self.mox.VerifyAll() self.mox.UnsetStubs() + def test_init_instance_failed_resume_sets_error(self): + instance = { + 'uuid': 'fake-uuid', + 'info_cache': None, + 'power_state': power_state.RUNNING, + 'vm_state': vm_states.ACTIVE, + } + self.flags(resume_guests_state_on_host_boot=True) + self.mox.StubOutWithMock(self.compute, '_get_power_state') + self.mox.StubOutWithMock(self.compute.driver, 'plug_vifs') + self.mox.StubOutWithMock(self.compute.driver, + 'resume_state_on_host_boot') + self.mox.StubOutWithMock(self.compute, + '_get_instance_volume_block_device_info') + self.mox.StubOutWithMock(self.compute, + '_set_instance_error_state') + self.compute._get_power_state(mox.IgnoreArg(), + instance).AndReturn(power_state.SHUTDOWN) + self.compute.driver.plug_vifs(instance, mox.IgnoreArg()) + self.compute._get_instance_volume_block_device_info(mox.IgnoreArg(), + instance['uuid']).AndReturn('fake-bdm') + self.compute.driver.resume_state_on_host_boot(mox.IgnoreArg(), + instance, mox.IgnoreArg(), + 'fake-bdm').AndRaise(test.TestingException) + self.compute._set_instance_error_state(mox.IgnoreArg(), + instance['uuid']) + self.mox.ReplayAll() + self.compute._init_instance('fake-context', instance) + def test_get_instances_on_driver(self): fake_context = context.get_admin_context() -- cgit