summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Behrens <cbehrens@codestud.com>2013-01-11 21:47:12 +0000
committerChris Behrens <cbehrens@codestud.com>2013-01-12 01:00:45 +0000
commitbc7dc55692fd8bd09d15779915e23bd89cbd6ba6 (patch)
treeb481c75f5542d78b0902362c92ca46e78eec7d85
parent741166904eb64aca4d82a146d3153eeade072b3e (diff)
downloadnova-bc7dc55692fd8bd09d15779915e23bd89cbd6ba6.tar.gz
nova-bc7dc55692fd8bd09d15779915e23bd89cbd6ba6.tar.xz
nova-bc7dc55692fd8bd09d15779915e23bd89cbd6ba6.zip
Make sure reboot_instance uses updated instance
compute manager's reboot_instance() was doing a check on a stale version of instance['power_state'] as well as passing stale instance data to the driver and notification calls. Fixes bug 1098727 Change-Id: I59f12f09d6e8a364e65f53912c09132a249c88c0
-rw-r--r--nova/compute/manager.py14
-rw-r--r--nova/tests/compute/test_compute.py16
2 files changed, 17 insertions, 13 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index f138a3708..819ec25ab 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -1486,9 +1486,9 @@ class ComputeManager(manager.SchedulerDependentManager):
self._notify_about_instance_usage(context, instance, "reboot.start")
current_power_state = self._get_power_state(context, instance)
- self._instance_update(context, instance['uuid'],
- power_state=current_power_state,
- vm_state=vm_states.ACTIVE)
+ instance = self._instance_update(context, instance['uuid'],
+ power_state=current_power_state,
+ vm_state=vm_states.ACTIVE)
if instance['power_state'] != power_state.RUNNING:
state = instance['power_state']
@@ -1509,10 +1509,10 @@ class ComputeManager(manager.SchedulerDependentManager):
# Fall through and reset task_state to None
current_power_state = self._get_power_state(context, instance)
- self._instance_update(context, instance['uuid'],
- power_state=current_power_state,
- vm_state=vm_states.ACTIVE,
- task_state=None)
+ instance = self._instance_update(context, instance['uuid'],
+ power_state=current_power_state,
+ vm_state=vm_states.ACTIVE,
+ task_state=None)
self._notify_about_instance_usage(context, instance, "reboot.end")
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py
index d44899350..73d58d32a 100644
--- a/nova/tests/compute/test_compute.py
+++ b/nova/tests/compute/test_compute.py
@@ -1010,6 +1010,10 @@ class ComputeTestCase(BaseTestCase):
instance = dict(uuid='fake-instance',
power_state='unknown')
+ updated_instance1 = dict(uuid='updated-instance1',
+ power_state='fake')
+ updated_instance2 = dict(uuid='updated-instance2',
+ power_state='fake')
fake_nw_info = 'fake-network-info'
fake_nw_model = network_model.NetworkInfo()
@@ -1040,7 +1044,7 @@ class ComputeTestCase(BaseTestCase):
instance).AndReturn(fake_power_state1)
self.compute._instance_update(econtext, instance['uuid'],
power_state=fake_power_state1,
- vm_state=vm_states.ACTIVE)
+ vm_state=vm_states.ACTIVE).AndReturn(updated_instance1)
# Reboot should check the driver to see if legacy nwinfo is
# needed. If it is, the model's legacy() method should be
@@ -1058,7 +1062,7 @@ class ComputeTestCase(BaseTestCase):
# this is called with the wrong args, so we have to hack
# around it.
reboot_call_info = {}
- expected_call_info = {'args': (instance, expected_nw_info,
+ expected_call_info = {'args': (updated_instance1, expected_nw_info,
reboot_type, fake_block_dev_info),
'kwargs': {}}
@@ -1070,13 +1074,13 @@ class ComputeTestCase(BaseTestCase):
# Power state should be updated again
self.compute._get_power_state(econtext,
- instance).AndReturn(fake_power_state2)
- self.compute._instance_update(econtext, instance['uuid'],
+ updated_instance1).AndReturn(fake_power_state2)
+ self.compute._instance_update(econtext, updated_instance1['uuid'],
power_state=fake_power_state2,
task_state=None,
- vm_state=vm_states.ACTIVE)
+ vm_state=vm_states.ACTIVE).AndReturn(updated_instance2)
self.compute._notify_about_instance_usage(econtext,
- instance,
+ updated_instance2,
'reboot.end')
self.mox.ReplayAll()