diff options
author | Jenkins <jenkins@review.openstack.org> | 2012-11-13 07:33:40 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2012-11-13 07:33:40 +0000 |
commit | 1ce386cb4b8365348c7e916d2c47cf7624aa7369 (patch) | |
tree | bc1cb1f975251d98512d57369aa3a126ce79511a | |
parent | 4504e48cab5fd87f1d9fa26eebb553d5aa54b8f0 (diff) | |
parent | 321780625993aa685c629995ecccc8bbb64ae4e7 (diff) | |
download | nova-1ce386cb4b8365348c7e916d2c47cf7624aa7369.tar.gz nova-1ce386cb4b8365348c7e916d2c47cf7624aa7369.tar.xz nova-1ce386cb4b8365348c7e916d2c47cf7624aa7369.zip |
Merge "powervm: failed spawn should raise exception"
-rw-r--r-- | nova/tests/test_powervm.py | 26 | ||||
-rw-r--r-- | nova/virt/powervm/operator.py | 10 |
2 files changed, 34 insertions, 2 deletions
diff --git a/nova/tests/test_powervm.py b/nova/tests/test_powervm.py index 6745903d2..50de428b8 100644 --- a/nova/tests/test_powervm.py +++ b/nova/tests/test_powervm.py @@ -18,15 +18,17 @@ Test suite for PowerVMDriver. """ -from nova.compute import power_state from nova import context from nova import db from nova import flags from nova import test +from nova.compute import power_state from nova.openstack.common import log as logging from nova.virt import images + from nova.virt.powervm import driver as powervm_driver +from nova.virt.powervm import exception from nova.virt.powervm import lpar from nova.virt.powervm import operator @@ -151,6 +153,28 @@ class PowerVMDriverTestCase(test.TestCase): state = self.powervm_connection.get_info(self.instance)['state'] self.assertEqual(state, power_state.RUNNING) + def test_spawn_cleanup_on_fail(self): + """Verify on a failed spawn, we get the original exception raised""" + # helper function + def raise_(ex): + raise ex + + self.flags(powervm_img_local_path='/images/') + self.stubs.Set(images, 'fetch_to_raw', lambda *x, **y: None) + self.stubs.Set( + self.powervm_connection._powervm._operator, + 'copy_image_file', + lambda *x, **y: raise_(exception.PowerVMImageCreationFailed())) + self.stubs.Set( + self.powervm_connection._powervm, '_cleanup', + lambda *x, **y: raise_(Exception('This should be logged.'))) + + self.assertRaises(exception.PowerVMImageCreationFailed, + self.powervm_connection.spawn, + context.get_admin_context(), + self.instance, + {'id': 'ANY_ID'}, 's3cr3t', []) + def test_destroy(self): self.powervm_connection.destroy(self.instance, None) self.stubs.Set(FakeIVMOperator, 'get_lpar', lambda x, y: None) diff --git a/nova/virt/powervm/operator.py b/nova/virt/powervm/operator.py index 09ad662b3..6ed7535a7 100644 --- a/nova/virt/powervm/operator.py +++ b/nova/virt/powervm/operator.py @@ -26,7 +26,9 @@ from nova import flags from nova import utils from nova.compute import power_state +from nova.openstack.common import excutils from nova.openstack.common import log as logging + from nova.virt import images from nova.virt.powervm import command from nova.virt.powervm import common @@ -264,7 +266,13 @@ class PowerVMOperator(object): time.sleep(1) except exception.PowerVMImageCreationFailed: - self._cleanup(instance['name']) + with excutils.save_and_reraise_exception(): + # log errors in cleanup + try: + self._cleanup(instance['name']) + except Exception: + LOG.exception(_('Error while attempting to ' + 'clean up failed instance launch.')) def destroy(self, instance_name): """Destroy (shutdown and delete) the specified instance. |