From fcdfa93b210a092894284f60309e660a3a058fde Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Wed, 8 Aug 2012 20:49:27 +0000 Subject: Send updated instance model to schedule_prep_resize A stale instance model was being passed to schedule_prep_resize. Fixes bug 1034595 Change-Id: Ic92a22a2c315d25c70d32685fdf9f38451077b9a --- nova/compute/api.py | 7 ++----- nova/tests/compute/test_compute.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) (limited to 'nova') diff --git a/nova/compute/api.py b/nova/compute/api.py index 0122e175a..7164930f0 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -1427,11 +1427,8 @@ class API(base.Base): if (current_memory_mb == new_memory_mb) and flavor_id: raise exception.CannotResizeToSameSize() - self.update(context, - instance, - task_state=task_states.RESIZE_PREP, - progress=0, - **kwargs) + instance = self.update(context, instance, + task_state=task_states.RESIZE_PREP, progress=0, **kwargs) request_spec = { 'instance_type': new_instance_type, diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 9a647953a..c88152b3e 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -3075,6 +3075,11 @@ class ComputeAPITestCase(BaseTestCase): filter_properties = msg['args']['filter_properties'] instance_properties = request_spec['instance_properties'] self.assertEqual(instance_properties['host'], 'host2') + # Ensure the instance passed to us has been updated with + # progress set to 0 and task_state set to RESIZE_PREP. + self.assertEqual(instance_properties['task_state'], + task_states.RESIZE_PREP) + self.assertEqual(instance_properties['progress'], 0) self.assertIn('host2', filter_properties['ignore_hosts']) self.stubs.Set(rpc, 'cast', _fake_cast) @@ -3084,6 +3089,16 @@ class ComputeAPITestCase(BaseTestCase): instance = db.instance_get_by_uuid(context, instance['uuid']) instance = jsonutils.to_primitive(instance) self.compute.run_instance(self.context, instance=instance) + # We need to set the host to something 'known'. Unfortunately, + # the compute manager is using a cached copy of FLAGS.host, + # so we can't just self.flags(host='host2') before calling + # run_instance above. Also, set progress to 10 so we ensure + # it is reset to 0 in compute_api.resize(). (verified in + # _fake_cast above). + instance = db.instance_update(self.context, instance['uuid'], + dict(host='host2', progress=10)) + # different host + self.flags(host='host3') try: self.compute_api.resize(context, instance, None) finally: @@ -3095,6 +3110,11 @@ class ComputeAPITestCase(BaseTestCase): filter_properties = msg['args']['filter_properties'] instance_properties = request_spec['instance_properties'] self.assertEqual(instance_properties['host'], 'host2') + # Ensure the instance passed to us has been updated with + # progress set to 0 and task_state set to RESIZE_PREP. + self.assertEqual(instance_properties['task_state'], + task_states.RESIZE_PREP) + self.assertEqual(instance_properties['progress'], 0) self.assertNotIn('host2', filter_properties['ignore_hosts']) self.stubs.Set(rpc, 'cast', _fake_cast) @@ -3105,6 +3125,15 @@ class ComputeAPITestCase(BaseTestCase): instance = db.instance_get_by_uuid(context, instance['uuid']) instance = jsonutils.to_primitive(instance) self.compute.run_instance(self.context, instance=instance) + # We need to set the host to something 'known'. Unfortunately, + # the compute manager is using a cached copy of FLAGS.host, + # so we can't just self.flags(host='host2') before calling + # run_instance above. Also, set progress to 10 so we ensure + # it is reset to 0 in compute_api.resize(). (verified in + # _fake_cast above). + instance = db.instance_update(self.context, instance['uuid'], + dict(host='host2', progress=10)) + # different host try: self.compute_api.resize(context, instance, None) finally: -- cgit