Skip to content

Commit

Permalink
Stop vm_state reset on reboot of rescued vm
Browse files Browse the repository at this point in the history
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
  • Loading branch information
matiu2 authored and openstack-gerrit committed Apr 19, 2013
1 parent 7c2b662 commit 39ffe80
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
8 changes: 7 additions & 1 deletion nova/compute/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1751,9 +1751,15 @@ def reboot_instance(self, context, instance,
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']
Expand Down
23 changes: 20 additions & 3 deletions nova/tests/compute/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,8 @@ def test_rebuild_launch_time(self):
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)

Expand All @@ -1353,12 +1354,16 @@ def _test_reboot(self, soft, legacy_nwinfo_driver, test_delete=False):
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')

Expand Down Expand Up @@ -1388,7 +1393,7 @@ def _test_reboot(self, soft, legacy_nwinfo_driver, test_delete=False):
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
Expand Down Expand Up @@ -1456,12 +1461,24 @@ def test_reboot_soft(self):
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)

Expand Down

0 comments on commit 39ffe80

Please sign in to comment.