Skip to content

Commit

Permalink
Check if reboot request type is None
Browse files Browse the repository at this point in the history
If the reboot request type is None, raise HTTPBadRequest like if the
argument was missing.

Change-Id: I75b1791b7a6c9304c3a78e869fe63d72302fc9d8
Closes-Bug: #1247735
  • Loading branch information
Adri2000 committed Nov 21, 2013
1 parent 84bddb0 commit 6796246
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nova/api/openstack/compute/plugins/v3/servers.py
Expand Up @@ -938,6 +938,10 @@ def _action_revert_resize(self, req, id, body):
@wsgi.action('reboot')
def _action_reboot(self, req, id, body):
if 'reboot' in body and 'type' in body['reboot']:
if not isinstance(body['reboot']['type'], six.string_types):
msg = _("Argument 'type' for reboot must be a string")
LOG.error(msg)
raise exc.HTTPBadRequest(explanation=msg)
valid_reboot_types = ['HARD', 'SOFT']
reboot_type = body['reboot']['type'].upper()
if not valid_reboot_types.count(reboot_type):
Expand Down
4 changes: 4 additions & 0 deletions nova/api/openstack/compute/servers.py
Expand Up @@ -1087,6 +1087,10 @@ def _action_revert_resize(self, req, id, body):
@wsgi.action('reboot')
def _action_reboot(self, req, id, body):
if 'reboot' in body and 'type' in body['reboot']:
if not isinstance(body['reboot']['type'], six.string_types):
msg = _("Argument 'type' for reboot must be a string")
LOG.error(msg)
raise exc.HTTPBadRequest(explanation=msg)
valid_reboot_types = ['HARD', 'SOFT']
reboot_type = body['reboot']['type'].upper()
if not valid_reboot_types.count(reboot_type):
Expand Down
Expand Up @@ -124,6 +124,13 @@ def test_reboot_missing_type(self):
self.controller._action_reboot,
req, FAKE_UUID, body)

def test_reboot_none(self):
body = dict(reboot=dict(type=None))
req = fakes.HTTPRequest.blank(self.url)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_reboot,
req, FAKE_UUID, body)

def test_reboot_not_found(self):
self.stubs.Set(db, 'instance_get_by_uuid',
return_server_not_found)
Expand Down
7 changes: 7 additions & 0 deletions nova/tests/api/openstack/compute/test_server_actions.py
Expand Up @@ -180,6 +180,13 @@ def test_reboot_missing_type(self):
self.controller._action_reboot,
req, FAKE_UUID, body)

def test_reboot_none(self):
body = dict(reboot=dict(type=None))
req = fakes.HTTPRequest.blank(self.url)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_reboot,
req, FAKE_UUID, body)

def test_reboot_not_found(self):
self.stubs.Set(db, 'instance_get_by_uuid',
return_server_not_found)
Expand Down

0 comments on commit 6796246

Please sign in to comment.