From 13e1a37eeb51b56bad64889447db21854f31fe83 Mon Sep 17 00:00:00 2001 From: David Subiros Date: Wed, 30 Nov 2011 09:45:23 +0000 Subject: [PATCH] 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 --- nova/tests/test_compute.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index e6167dc5..a0517934 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -471,6 +471,34 @@ class ComputeTestCase(BaseTestCase): self.compute.snapshot_instance(self.context, instance_uuid, name) self.compute.terminate_instance(self.context, instance_uuid) + 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 = self._create_fake_instance() + self.compute.run_instance(self.context, instance['uuid']) + self.assertRaises(Exception, self.compute.snapshot_instance, + self.context, instance['uuid'], "failing_snapshot") + self._assert_state({'task_state': None}) + self.compute.terminate_instance(self.context, instance['uuid']) + + 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 = self._create_fake_instance()