Skip to content

Commit

Permalink
compute api should throw exception if soft reboot invalid state VM
Browse files Browse the repository at this point in the history
When user perform soft reboot to a VM which in suspended/paused/
stopped/error state, nova compute api should throw exception for
such state.

Change-Id: Ic365c6360f6b7407d9de0dac6ff1093484692cf4
Closes-Bug: #1236930
  • Loading branch information
Jay Lau committed Oct 12, 2013
1 parent a9a2359 commit 2392313
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions nova/compute/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1983,6 +1983,16 @@ def snapshot_volume_backed(self, context, instance, image_meta, name,
task_states.SUSPENDING])
def reboot(self, context, instance, reboot_type):
"""Reboot the given instance."""
if (reboot_type == 'SOFT' and
(instance['vm_state'] in [vm_states.STOPPED,
vm_states.PAUSED,
vm_states.SUSPENDED,
vm_states.ERROR])):
raise exception.InstanceInvalidState(
attr='vm_state',
instance_uuid=instance['uuid'],
state=instance['vm_state'],
method='reboot')
if ((reboot_type == 'SOFT' and
instance['task_state'] == task_states.REBOOTING) or
(reboot_type == 'HARD' and
Expand Down
11 changes: 10 additions & 1 deletion nova/tests/compute/test_compute_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,16 @@ def test_reboot_soft(self):
self._test_reboot_type(vm_states.ACTIVE, 'SOFT')

def test_reboot_soft_error(self):
self._test_reboot_type(vm_states.ERROR, 'SOFT')
self._test_reboot_type_fails('SOFT', vm_state=vm_states.ERROR)

def test_reboot_soft_paused(self):
self._test_reboot_type_fails('SOFT', vm_state=vm_states.PAUSED)

def test_reboot_soft_stopped(self):
self._test_reboot_type_fails('SOFT', vm_state=vm_states.STOPPED)

def test_reboot_soft_suspended(self):
self._test_reboot_type_fails('SOFT', vm_state=vm_states.SUSPENDED)

def test_reboot_soft_rebooting(self):
self._test_reboot_type_fails('SOFT', task_state=task_states.REBOOTING)
Expand Down

0 comments on commit 2392313

Please sign in to comment.