summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xnova/compute/manager.py10
-rw-r--r--nova/tests/compute/test_compute.py23
2 files changed, 31 insertions, 2 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 02f103dbc..619316e9e 100755
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -1181,8 +1181,14 @@ class ComputeManager(manager.SchedulerDependentManager):
except exception.NetworkNotFound:
network_info = network_model.NetworkInfo()
- # tear down allocated network structure
- self._deallocate_network(context, instance)
+ try:
+ # tear down allocated network structure
+ self._deallocate_network(context, instance)
+ except Exception:
+ with excutils.save_and_reraise_exception():
+ LOG.error(_('Failed to deallocate network for instance.'),
+ instance=instance)
+ self._set_instance_error_state(context, instance['uuid'])
# NOTE(vish) get bdms before destroying the instance
vol_bdms = self._get_volume_bdms(bdms)
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py
index b3d6a6b7c..446553a8e 100644
--- a/nova/tests/compute/test_compute.py
+++ b/nova/tests/compute/test_compute.py
@@ -850,6 +850,29 @@ class ComputeTestCase(BaseTestCase):
self.assert_(instance['launched_at'] < terminate)
self.assert_(instance['deleted_at'] > terminate)
+ def test_run_terminate_deallocate_net_failure_sets_error_state(self):
+ 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)
+
+ def _fake_deallocate_network(*args, **kwargs):
+ raise Exception()
+
+ self.stubs.Set(self.compute, '_deallocate_network',
+ _fake_deallocate_network)
+
+ try:
+ self.compute.terminate_instance(self.context, instance=instance)
+ except Exception:
+ pass
+
+ instance = db.instance_get_by_uuid(self.context, instance['uuid'])
+ self.assertEqual(instance['vm_state'], vm_states.ERROR)
+
def test_stop(self):
# Ensure instance can be stopped.
instance = jsonutils.to_primitive(self._create_fake_instance())