summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-05-14 07:32:44 +0000
committerGerrit Code Review <review@openstack.org>2013-05-14 07:32:44 +0000
commit9648676783c483391836185d07c358cef744cd37 (patch)
treee7f63da21e6c709840d6dfa15f839b235bd669ae
parent04c446f5751e63882894159cd594af50f338f853 (diff)
parent662a793056d4544c9c9d73fc21b99d77404537cc (diff)
Merge "Raise InstanceInvalidState for double hard reboot"
-rw-r--r--nova/compute/api.py6
-rw-r--r--nova/tests/api/openstack/compute/test_server_actions.py28
2 files changed, 32 insertions, 2 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index c56270cc3..d95e65f38 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -1721,8 +1721,10 @@ class API(base.Base):
task_states.SUSPENDING])
def reboot(self, context, instance, reboot_type):
"""Reboot the given instance."""
- if (reboot_type == 'SOFT' and
- instance['task_state'] == task_states.REBOOTING):
+ if ((reboot_type == 'SOFT' and
+ instance['task_state'] == task_states.REBOOTING) or
+ (reboot_type == 'HARD' and
+ instance['task_state'] == task_states.REBOOTING_HARD)):
raise exception.InstanceInvalidState(
attr='task_state',
instance_uuid=instance['uuid'],
diff --git a/nova/tests/api/openstack/compute/test_server_actions.py b/nova/tests/api/openstack/compute/test_server_actions.py
index fe65fe0d9..7347aa169 100644
--- a/nova/tests/api/openstack/compute/test_server_actions.py
+++ b/nova/tests/api/openstack/compute/test_server_actions.py
@@ -195,6 +195,34 @@ class ServerActionsControllerTest(test.TestCase):
self.controller._action_reboot,
req, FAKE_UUID, body)
+ def test_reboot_soft_with_soft_in_progress_raises_conflict(self):
+ body = dict(reboot=dict(type="SOFT"))
+ req = fakes.HTTPRequest.blank(self.url)
+ self.stubs.Set(db, 'instance_get_by_uuid',
+ fakes.fake_instance_get(vm_state=vm_states.ACTIVE,
+ task_state=task_states.REBOOTING))
+ self.assertRaises(webob.exc.HTTPConflict,
+ self.controller._action_reboot,
+ req, FAKE_UUID, body)
+
+ def test_reboot_hard_with_soft_in_progress_does_not_raise(self):
+ body = dict(reboot=dict(type="HARD"))
+ req = fakes.HTTPRequest.blank(self.url)
+ self.stubs.Set(db, 'instance_get_by_uuid',
+ fakes.fake_instance_get(vm_state=vm_states.ACTIVE,
+ task_state=task_states.REBOOTING))
+ self.controller._action_reboot(req, FAKE_UUID, body)
+
+ def test_reboot_hard_with_hard_in_progress_raises_conflict(self):
+ body = dict(reboot=dict(type="HARD"))
+ req = fakes.HTTPRequest.blank(self.url)
+ self.stubs.Set(db, 'instance_get_by_uuid',
+ fakes.fake_instance_get(vm_state=vm_states.ACTIVE,
+ task_state=task_states.REBOOTING_HARD))
+ self.assertRaises(webob.exc.HTTPConflict,
+ self.controller._action_reboot,
+ req, FAKE_UUID, body)
+
def test_rebuild_accepted_minimum(self):
return_server = fakes.fake_instance_get(image_ref='2',
vm_state=vm_states.ACTIVE, host='fake_host')