Merge "Fix HTTP500 error of changes-since on v2.0 API"

This commit is contained in:
Zuul 2018-05-16 00:31:45 +00:00 committed by Gerrit Code Review
commit 9706d89d52
2 changed files with 17 additions and 2 deletions

View File

@ -207,8 +207,16 @@ class ServersController(wsgi.Controller):
search_opts['task_state'] = task_state
if 'changes-since' in search_opts:
try:
search_opts['changes-since'] = timeutils.parse_isotime(
search_opts['changes-since'])
except ValueError:
# NOTE: This error handling is for V2.0 API to pass the
# experimental jobs at the gate. V2.1 API covers this case
# with JSON-Schema and it is a hard burden to apply it to
# v2.0 API at this time.
msg = _("Invalid filter field: changes-since.")
raise exc.HTTPBadRequest(explanation=msg)
# By default, compute's get_all() will return deleted instances.
# If an admin hasn't specified a 'deleted' search option, we need

View File

@ -1155,6 +1155,13 @@ class ServersControllerTest(ControllerTest):
self.assertRaises(exception.ValidationError, self.controller.index,
req)
def test_get_servers_allows_changes_since_bad_value_on_compat_mode(self):
params = 'changes-since=asdf'
req = self.req('/fake/servers?%s' % params)
req.set_legacy_v2()
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.index,
req)
def test_get_servers_admin_filters_as_user(self):
"""Test getting servers by admin-only or unknown options when
context is not admin. Make sure the admin and unknown options