diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-03-03 00:23:32 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-03-03 00:23:32 +0000 |
| commit | 39bc517de5ab32b7cd9b7f837fbde06211b99a67 (patch) | |
| tree | 85b0344459ed25da8d5a2a1a91648ad9b7ba82a1 | |
| parent | d5e728ca08e250ee537f5bbf0f7c2df4c899c76b (diff) | |
| parent | fbeb552175c9f9d6d444ac5cc0606a5dceb39ef7 (diff) | |
| download | nova-39bc517de5ab32b7cd9b7f837fbde06211b99a67.tar.gz nova-39bc517de5ab32b7cd9b7f837fbde06211b99a67.tar.xz nova-39bc517de5ab32b7cd9b7f837fbde06211b99a67.zip | |
Merge "Set vm_state to ERROR on net deallocate failure."
| -rwxr-xr-x | nova/compute/manager.py | 10 | ||||
| -rw-r--r-- | nova/tests/compute/test_compute.py | 23 |
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()) |
