diff options
author | Hans Lindgren <hanlind@kth.se> | 2013-02-26 10:53:21 +0100 |
---|---|---|
committer | Hans Lindgren <hanlind@kth.se> | 2013-03-03 13:35:41 +0100 |
commit | 10f43aa0bfc6d41282fc19fb4bacddb8bc85ddc5 (patch) | |
tree | 6a9a460d5016deddc5c8ea4917f057fcb170a187 | |
parent | 7170eb3966d4a38878e46353414579804fa987e9 (diff) | |
download | nova-10f43aa0bfc6d41282fc19fb4bacddb8bc85ddc5.tar.gz nova-10f43aa0bfc6d41282fc19fb4bacddb8bc85ddc5.tar.xz nova-10f43aa0bfc6d41282fc19fb4bacddb8bc85ddc5.zip |
Fix target host variable from being overwritten
The target host parameter of the compute api evacuate method
is mistakenly overwritten before being used. The result is
that the instance rebuild operation is tried against the
original failed host and will always fail.
Rename locally used variable to a different name and modify
relevant test to prohibit this from happening again.
Resolves bug 1133204.
Change-Id: I517b2dc19d9561723391150105b4943b56dba637
-rw-r--r-- | nova/compute/api.py | 6 | ||||
-rw-r--r-- | nova/tests/compute/test_compute.py | 7 |
2 files changed, 10 insertions, 3 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py index bba6ee1eb..645f2d468 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -2438,10 +2438,10 @@ class API(base.Base): raising an exception. """ LOG.debug(_('vm evacuation scheduled')) - host = instance['host'] - service = self.db.service_get_by_compute_host(context, host) + inst_host = instance['host'] + service = self.db.service_get_by_compute_host(context, inst_host) if self.servicegroup_api.service_is_up(service): - msg = (_('Instance compute service state on %(host)s ' + msg = (_('Instance compute service state on %(inst_host)s ' 'expected to be down, but it was up.' ) % locals()) LOG.error(msg) diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 5ad333c9e..5648d4df4 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -6348,8 +6348,14 @@ class ComputeAPITestCase(BaseTestCase): def fake_service_is_up(*args, **kwargs): return False + def fake_rebuild_instance(*args, **kwargs): + db.instance_update(self.context, instance_uuid, + {'host': kwargs['host']}) + self.stubs.Set(self.compute_api.servicegroup_api, 'service_is_up', fake_service_is_up) + self.stubs.Set(self.compute_api.compute_rpcapi, 'rebuild_instance', + fake_rebuild_instance) self.compute_api.evacuate(self.context.elevated(), instance, host='fake_dest_host', @@ -6358,6 +6364,7 @@ class ComputeAPITestCase(BaseTestCase): instance = db.instance_get_by_uuid(self.context, instance_uuid) self.assertEqual(instance['task_state'], task_states.REBUILDING) + self.assertEqual(instance['host'], 'fake_dest_host') db.instance_destroy(self.context, instance['uuid']) |