From 359ca265478cf2c387bed9c44808c1f2f1ab2df5 Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Fri, 11 May 2018 10:52:06 -0700 Subject: [PATCH] Fix HTTP500 error of changes-since on v2.0 API The experimental job legacy-tempest-dsvm-nova-v20-api failed at the gate always, because test_list_servers_by_changes_since_invalid_date touched less validation part on the API. This patch fixes it. Change-Id: I0284a83a92d39d211af6108ed6cae2d8fe19da8f Close-Bug: #1770705 --- nova/api/openstack/compute/servers.py | 12 ++++++++++-- .../unit/api/openstack/compute/test_serversV21.py | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index 14dc940af376..9f13c2e58d55 100644 --- a/nova/api/openstack/compute/servers.py +++ b/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 diff --git a/nova/tests/unit/api/openstack/compute/test_serversV21.py b/nova/tests/unit/api/openstack/compute/test_serversV21.py index aadcec467b02..77a019d316fa 100644 --- a/nova/tests/unit/api/openstack/compute/test_serversV21.py +++ b/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