Browse Source

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

changes/10/549510/3
Zuul 3 years ago
committed by Gerrit Code Review
parent
commit
9706d89d52
  1. 12
      nova/api/openstack/compute/servers.py
  2. 7
      nova/tests/unit/api/openstack/compute/test_serversV21.py

12
nova/api/openstack/compute/servers.py

@ -207,8 +207,16 @@ class ServersController(wsgi.Controller):
search_opts['task_state'] = task_state
if 'changes-since' in search_opts:
search_opts['changes-since'] = timeutils.parse_isotime(
search_opts['changes-since'])
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

7
nova/tests/unit/api/openstack/compute/test_serversV21.py

@ -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

Loading…
Cancel
Save