From 3d27a0e74bde3878af76414dc4020ac6f9f24e4e Mon Sep 17 00:00:00 2001 From: Yufang Zhang Date: Thu, 20 Jun 2013 18:17:49 +0800 Subject: Handle NoMoreFixedIps in _shutdown_instance. Bug 1192893 If no fixed ips is found, continue to perform the rest of the instance shutdown, instead of propogating the exception. Steps to reproduce: 1. Create a network 2. Reserve all fixed ips of the network 3. Try to create an instance but failed 4. Try to delete the instance Results: Cannot delete the instance due to the 'NoMoreFixedIps' exception. Change-Id: I42776c427773f1f81c16062a9aaa54850ec68bfd --- nova/compute/manager.py | 2 +- nova/tests/compute/test_compute.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 1def5b069..bd4e6f772 100755 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -1344,7 +1344,7 @@ class ComputeManager(manager.SchedulerDependentManager): # get network info before tearing down try: network_info = self._get_instance_nw_info(context, instance) - except exception.NetworkNotFound: + except (exception.NetworkNotFound, exception.NoMoreFixedIps): network_info = network_model.NetworkInfo() # NOTE(vish) get bdms before destroying the instance diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 8c6fce3a5..abb4d8e39 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -1214,6 +1214,30 @@ class ComputeTestCase(BaseTestCase): LOG.info(_("After terminating instances: %s"), instances) self.assertEqual(len(instances), 0) + def test_terminate_no_fixed_ips(self): + # This is as reported in LP bug 1192893 + instance = jsonutils.to_primitive(self._create_fake_instance()) + + self.compute.run_instance(self.context, instance=instance) + + instances = db.instance_get_all(self.context) + LOG.info(_("Running instances: %s"), instances) + self.assertEqual(len(instances), 1) + + self.mox.StubOutWithMock(self.compute, '_get_instance_nw_info') + self.compute._get_instance_nw_info( + mox.IgnoreArg(), + mox.IgnoreArg()).AndRaise( + exception.NoMoreFixedIps() + ) + self.mox.ReplayAll() + + self.compute.terminate_instance(self.context, instance=instance) + + instances = db.instance_get_all(self.context) + LOG.info(_("After terminating instances: %s"), instances) + self.assertEqual(len(instances), 0) + def test_terminate_failure_leaves_task_state(self): """Ensure that a failure in terminate_instance does not result in the task state being reverted from DELETING (see LP 1046236). -- cgit