From dacb187fcd685c15fd084fdfce8c5e165130ff54 Mon Sep 17 00:00:00 2001 From: Melanie Witt Date: Thu, 23 May 2013 00:23:16 +0000 Subject: Call virt.driver.destroy before deallocating network. Call virt driver destroy before releasing the instance's ip address, so that certain failures can be handled. For instance, if destroy raises InstancePowerOffFailure, do not deallocate network resources. Fixes bug 1180178 Change-Id: I9bde984d2393bd73a73eae6065defb2ed7c01492 --- nova/tests/compute/test_compute.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 91a8c9c95..71eb28188 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -2337,6 +2337,36 @@ class ComputeTestCase(BaseTestCase): instance=jsonutils.to_primitive(instance), bdms={}) + def test_delete_instance_keeps_net_on_power_off_fail(self): + self.mox.StubOutWithMock(self.compute.driver, 'destroy') + self.mox.StubOutWithMock(self.compute, '_deallocate_network') + exp = exception.InstancePowerOffFailure(reason='') + self.compute.driver.destroy(mox.IgnoreArg(), mox.IgnoreArg(), + mox.IgnoreArg()).AndRaise(exp) + # mox will detect if _deallocate_network gets called unexpectedly + self.mox.ReplayAll() + instance = self._create_fake_instance() + self.assertRaises(exception.InstancePowerOffFailure, + self.compute._delete_instance, + self.context, + instance=jsonutils.to_primitive(instance), + bdms={}) + + def test_delete_instance_loses_net_on_other_fail(self): + self.mox.StubOutWithMock(self.compute.driver, 'destroy') + self.mox.StubOutWithMock(self.compute, '_deallocate_network') + exp = test.TestingException() + self.compute.driver.destroy(mox.IgnoreArg(), mox.IgnoreArg(), + mox.IgnoreArg()).AndRaise(exp) + self.compute._deallocate_network(mox.IgnoreArg(), mox.IgnoreArg()) + self.mox.ReplayAll() + instance = self._create_fake_instance() + self.assertRaises(test.TestingException, + self.compute._delete_instance, + self.context, + instance=jsonutils.to_primitive(instance), + bdms={}) + def test_delete_instance_deletes_console_auth_tokens(self): instance = self._create_fake_instance() self.flags(vnc_enabled=True) -- cgit