diff options
author | Jenkins <jenkins@review.openstack.org> | 2012-11-27 03:45:40 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2012-11-27 03:45:40 +0000 |
commit | 02a2cb22eba93f94d797aaa5c6247c302de89464 (patch) | |
tree | 5c602aa342165ab8fd6ce1a9cd5d26da51409bd6 | |
parent | 3fb827c512671ef93fddadcc4c21ff2477506047 (diff) | |
parent | 93efa2121afb53e663ad46e0f9d655f77005f6d2 (diff) | |
download | nova-02a2cb22eba93f94d797aaa5c6247c302de89464.tar.gz |
Merge "Deallocate network if instance is deleted in spawn" into stable/folsom
-rw-r--r-- | nova/compute/manager.py | 8 | ||||
-rw-r--r-- | nova/tests/compute/test_compute.py | 19 |
2 files changed, 26 insertions, 1 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index b93077ac0f..d87e8390ce 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -494,7 +494,13 @@ class ComputeManager(manager.SchedulerDependentManager): injected_files, admin_password) except exception.InstanceNotFound: - raise # the instance got deleted during the spawn + # the instance got deleted during the spawn + try: + self._deallocate_network(context, instance) + except Exception: + msg = _('Failed to dealloc network for deleted instance') + LOG.exception(msg, instance=instance) + raise except Exception: # try to re-schedule instance: self._reschedule_or_reraise(context, instance, diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 674f531ae3..535ba0377d 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -567,6 +567,25 @@ class ComputeTestCase(BaseTestCase): self._assert_state({'vm_state': vm_states.ERROR, 'task_state': None}) + def test_run_instance_dealloc_network_instance_not_found(self): + """ spawn network deallocate test. + + Make sure that when an instance is not found during spawn + that the network is deallocated""" + instance = self._create_instance() + + def fake(*args, **kwargs): + raise exception.InstanceNotFound() + + self.stubs.Set(self.compute.driver, 'spawn', fake) + self.mox.StubOutWithMock(self.compute, '_deallocate_network') + self.compute._deallocate_network(mox.IgnoreArg(), mox.IgnoreArg()) + self.mox.ReplayAll() + + self.assertRaises(exception.InstanceNotFound, + self.compute.run_instance, + self.context, instance=instance) + def test_can_terminate_on_error_state(self): """Make sure that the instance can be terminated in ERROR state""" elevated = context.get_admin_context() |