diff --git a/doc/api_samples/versions/v21-version-get-resp.json b/doc/api_samples/versions/v21-version-get-resp.json index 731af39aa821..79a37afb0ca4 100644 --- a/doc/api_samples/versions/v21-version-get-resp.json +++ b/doc/api_samples/versions/v21-version-get-resp.json @@ -19,7 +19,7 @@ } ], "status": "CURRENT", - "version": "2.37", + "version": "2.38", "min_version": "2.1", "updated": "2013-07-23T11:33:21Z" } diff --git a/doc/api_samples/versions/versions-get-resp.json b/doc/api_samples/versions/versions-get-resp.json index c2310bee180f..c672f1e6e825 100644 --- a/doc/api_samples/versions/versions-get-resp.json +++ b/doc/api_samples/versions/versions-get-resp.json @@ -22,7 +22,7 @@ } ], "status": "CURRENT", - "version": "2.37", + "version": "2.38", "min_version": "2.1", "updated": "2013-07-23T11:33:21Z" } diff --git a/nova/api/openstack/api_version_request.py b/nova/api/openstack/api_version_request.py index 3862da7cc1c6..6a3865f96796 100644 --- a/nova/api/openstack/api_version_request.py +++ b/nova/api/openstack/api_version_request.py @@ -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 diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index a387675d9cb6..b4837c0a1d45 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -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'. diff --git a/nova/api/openstack/rest_api_version_history.rst b/nova/api/openstack/rest_api_version_history.rst index c3bff4549938..89f5e22875de 100644 --- a/nova/api/openstack/rest_api_version_history.rst +++ b/nova/api/openstack/rest_api_version_history.rst @@ -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. diff --git a/nova/tests/unit/api/openstack/compute/test_serversV21.py b/nova/tests/unit/api/openstack/compute/test_serversV21.py index 8a1a7f344dca..20b9f1a6fc79 100644 --- a/nova/tests/unit/api/openstack/compute/test_serversV21.py +++ b/nova/tests/unit/api/openstack/compute/test_serversV21.py @@ -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): diff --git a/releasenotes/notes/list-invalid-status-af07af378728bc57.yaml b/releasenotes/notes/list-invalid-status-af07af378728bc57.yaml new file mode 100644 index 000000000000..2a51cbb9f991 --- /dev/null +++ b/releasenotes/notes/list-invalid-status-af07af378728bc57.yaml @@ -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. +