summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Sherborne <msherborne@gmail.com>2013-04-18 14:37:52 +1000
committerGerrit Code Review <review@openstack.org>2013-04-19 21:30:40 +0000
commit39ffe806cdfe97721fee5e48c8591c4c3b52766b (patch)
tree9a300bfdb70059618369eae990637e75f12dc844
parent7c2b662dc6923b88ce9d3ae3a7262368cceff9b2 (diff)
Stop vm_state reset on reboot of rescued vm
When a VM is in rescue mode, giving it a reboot will reset its state in the DB back to ACTIVE. This patch stops that happening. Work towards bug: 1170237 Change-Id: Ie442bcc85ed7ad5d897b88ffd0dbcf6eeee7b990
-rwxr-xr-xnova/compute/manager.py8
-rw-r--r--nova/tests/compute/test_compute.py23
2 files changed, 27 insertions, 4 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index dc0725933..9dc6e97c5 100755
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -1751,9 +1751,15 @@ class ComputeManager(manager.SchedulerDependentManager):
self._notify_about_instance_usage(context, instance, "reboot.start")
current_power_state = self._get_power_state(context, instance)
+
+ # Don't change it out of rescue mode
+ new_vm_state = vm_states.ACTIVE
+ if instance['vm_state'] == vm_states.RESCUED:
+ new_vm_state = vm_states.RESCUED
+
instance = self._instance_update(context, instance['uuid'],
power_state=current_power_state,
- vm_state=vm_states.ACTIVE)
+ vm_state=new_vm_state)
if instance['power_state'] != power_state.RUNNING:
state = instance['power_state']
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py
index 88434078d..9dc239c8c 100644
--- a/nova/tests/compute/test_compute.py
+++ b/nova/tests/compute/test_compute.py
@@ -1341,7 +1341,8 @@ class ComputeTestCase(BaseTestCase):
self.compute.terminate_instance(self.context,
instance=jsonutils.to_primitive(instance))
- def _test_reboot(self, soft, legacy_nwinfo_driver, test_delete=False):
+ def _test_reboot(self, soft, legacy_nwinfo_driver,
+ test_delete=False, test_unrescue=False):
# This is a true unit test, so we don't need the network stubs.
fake_network.unset_stub_network_methods(self.stubs)
@@ -1353,12 +1354,16 @@ class ComputeTestCase(BaseTestCase):
self.mox.StubOutWithMock(self.compute.driver, 'reboot')
instance = dict(uuid='fake-instance',
- power_state='unknown')
+ power_state='unknown',
+ vm_state=vm_states.ACTIVE)
updated_instance1 = dict(uuid='updated-instance1',
power_state='fake')
updated_instance2 = dict(uuid='updated-instance2',
power_state='fake')
+ if test_unrescue:
+ instance['vm_state'] = vm_states.RESCUED
+
fake_nw_model = network_model.NetworkInfo()
self.mox.StubOutWithMock(fake_nw_model, 'legacy')
@@ -1388,7 +1393,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).AndReturn(updated_instance1)
+ vm_state=instance['vm_state']).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
@@ -1456,12 +1461,24 @@ class ComputeTestCase(BaseTestCase):
def test_reboot_soft_and_delete(self):
self._test_reboot(True, False, True)
+ def test_reboot_soft_and_rescued(self):
+ self._test_reboot(True, False, False, True)
+
+ def test_reboot_soft_and_delete_and_rescued(self):
+ self._test_reboot(True, False, True, True)
+
def test_reboot_hard(self):
self._test_reboot(False, False)
def test_reboot_hard_and_delete(self):
self._test_reboot(False, False, True)
+ def test_reboot_hard_and_rescued(self):
+ self._test_reboot(False, False, False, True)
+
+ def test_reboot_hard_and_delete_and_rescued(self):
+ self._test_reboot(False, False, True, True)
+
def test_reboot_soft_legacy_nwinfo_driver(self):
self._test_reboot(True, True)