summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Subiros <david.perez5@hp.com>2011-11-30 09:45:23 +0000
committerMark McLoughlin <markmc@redhat.com>2012-01-04 19:45:11 +0000
commit7e4e216e9011014d926d9a90afe46d4b64c0e369 (patch)
treea3776331bf59f7a1f45adfa0a7d08290cdc80fb2
parentb4cfd9ab1b78d8926072615d21cb7bd430b38612 (diff)
downloadnova-7e4e216e9011014d926d9a90afe46d4b64c0e369.tar.gz
Fixing snapshot failure task_state
fixes bug 898162 If a snapshot fails now the instance task_state is set back to None. Change-Id: I5ed8850a35aea901adf253f3f4adc590efd3a075
-rw-r--r--nova/compute/manager.py6
-rw-r--r--nova/tests/test_compute.py28
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()