Return HTTP 400 on list for invalid status

Raised 400 HTTPBadRequest if user passes invalid status to list
server API. Increased API microversion to v2.38 to maintain
backward compatibility.

Implements: blueprint response-for-invalid-status

Co-Authored-By: Ed Leafe <ed@leafe.com>

Change-Id: I25608280c2f30e70802e173c183de4e8da9a983b
This commit is contained in:
dineshbhor 2016-05-06 10:00:34 +00:00 committed by EdLeafe
parent 6a5e36f52c
commit 984d00919f
7 changed files with 45 additions and 3 deletions

View File

@ -19,7 +19,7 @@
}
],
"status": "CURRENT",
"version": "2.37",
"version": "2.38",
"min_version": "2.1",
"updated": "2013-07-23T11:33:21Z"
}

View File

@ -22,7 +22,7 @@
}
],
"status": "CURRENT",
"version": "2.37",
"version": "2.38",
"min_version": "2.1",
"updated": "2013-07-23T11:33:21Z"
}

View File

@ -93,6 +93,8 @@ REST_API_VERSION_HISTORY = """REST API Version History:
* 2.37 - Adds support for auto-allocating networking, otherwise known as
"Get me a Network". Also enforces server.networks.uuid to be in
UUID format.
* 2.38 - Add a condition to return HTTPBadRequest if invalid status is
provided for listing servers.
"""
# The minimum and maximum versions of the API supported
@ -101,7 +103,7 @@ REST_API_VERSION_HISTORY = """REST API Version History:
# Note(cyeoh): This only applies for the v2.1 API once microversions
# support is fully merged. It does not affect the V2 API.
_MIN_API_VERSION = "2.1"
_MAX_API_VERSION = "2.37"
_MAX_API_VERSION = "2.38"
DEFAULT_API_VERSION = _MIN_API_VERSION
# All the proxy APIs which related network, images and baremetal

View File

@ -227,6 +227,10 @@ class ServersController(wsgi.Controller):
states = common.task_and_vm_state_from_status(statuses)
vm_state, task_state = states
if not vm_state and not task_state:
if api_version_request.is_supported(req, min_version='2.38'):
msg = _('Invalid status value')
raise exc.HTTPBadRequest(explanation=msg)
return {'servers': []}
search_opts['vm_state'] = vm_state
# When we search by vm state, task state will return 'default'.

View File

@ -405,3 +405,13 @@ user documentation.
Also, the ``uuid`` field in the ``networks`` object in the server create
request is now strictly enforced to be in UUID format.
2.38
----
Before version 2.38, the command ``nova list --status invalid_status`` was
returning empty list for non admin user and 500 InternalServerError for admin
user. As there are sufficient statuses defined already, any invalid status
should not be accepted. From this version of the API admin as well as non
admin user will get 400 HTTPBadRequest if invalid status is passed to nova
list command.

View File

@ -1490,6 +1490,23 @@ class ServersControllerTestV226(ControllerTest):
self._test_get_servers_allows_tag_filters('not-tags-any')
class ServerControllerTestV238(ControllerTest):
wsgi_api_version = '2.38'
def _test_invalid_status(self, is_admin):
req = fakes.HTTPRequest.blank('/fake/servers/detail?status=invalid',
version=self.wsgi_api_version,
use_admin_context=is_admin)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.detail, req)
def test_list_servers_detail_invalid_status_for_admin(self):
self._test_invalid_status(True)
def test_list_servers_detail_invalid_status_for_non_admin(self):
self._test_invalid_status(False)
class ServersControllerDeleteTest(ControllerTest):
def setUp(self):

View File

@ -0,0 +1,9 @@
---
fixes:
- Corrected response for the case where an invalid status value is passed as
a filter to the list servers API call. As there are sufficient statuses
defined already, any invalid status should not be accepted. As of
microversion 2.38, the API will return 400 HTTPBadRequest if an invalid
status is passed to list servers API for both admin as well as non admin
user.