diff options
author | Jenkins <jenkins@review.openstack.org> | 2012-01-05 12:32:08 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2012-01-05 12:32:08 +0000 |
commit | 30c388554b38880c722e638340184961beb38972 (patch) | |
tree | d307ac5078d31a912fa780d6e83a9e27fc03743f | |
parent | c067876e587ac55cd139f054900ca5219089ae22 (diff) | |
parent | 7e4e216e9011014d926d9a90afe46d4b64c0e369 (diff) | |
download | nova-30c388554b38880c722e638340184961beb38972.tar.gz |
Merge "Fixing snapshot failure task_state" into stable/diablo
-rw-r--r-- | nova/compute/manager.py | 6 | ||||
-rw-r--r-- | nova/tests/test_compute.py | 28 |
2 files changed, 32 insertions, 2 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index b926eacc0b..98878f3cd6 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -683,8 +683,10 @@ class ComputeManager(manager.SchedulerDependentManager): 'instance: %(instance_id)s (state: %(state)s ' 'expected: %(running)s)') % locals()) - self.driver.snapshot(context, instance_ref, image_id) - self._instance_update(context, instance_id, task_state=None) + try: + self.driver.snapshot(context, instance_ref, image_id) + finally: + self._instance_update(context, instance_id, task_state=None) if image_type == 'snapshot' and rotation: raise exception.ImageRotationNotAllowed() diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index c6747d0c67..f8c5b2cbd0 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -387,6 +387,34 @@ class ComputeTestCase(test.TestCase): db.instance_destroy(self.context, instance_id) + def test_snapshot_fails(self): + """Ensure task_state is set to None if snapshot fails""" + def fake_snapshot(*args, **kwargs): + raise Exception("I don't want to create a snapshot") + + self.stubs.Set(self.compute.driver, 'snapshot', fake_snapshot) + + instance_id = self._create_instance() + self.compute.run_instance(self.context, instance_id) + self.assertRaises(Exception, self.compute.snapshot_instance, + self.context, instance_id, "failing_snapshot") + self._assert_state({'task_state': None}) + self.compute.terminate_instance(self.context, instance_id) + + def _assert_state(self, state_dict): + """Assert state of VM is equal to state passed as parameter""" + instances = db.instance_get_all(context.get_admin_context()) + self.assertEqual(len(instances), 1) + + if 'vm_state' in state_dict: + self.assertEqual(state_dict['vm_state'], instances[0]['vm_state']) + if 'task_state' in state_dict: + self.assertEqual(state_dict['task_state'], + instances[0]['task_state']) + if 'power_state' in state_dict: + self.assertEqual(state_dict['power_state'], + instances[0]['power_state']) + def test_console_output(self): """Make sure we can get console output from instance""" instance_id = self._create_instance() |