Merge "Change 'changes_since'/'changes-since' into v2.1 style for servers"

This commit is contained in:
Jenkins 2014-08-27 02:47:44 +00:00 committed by Gerrit Code Review
commit 3ab81c9b3e
2 changed files with 10 additions and 13 deletions
nova
api/openstack/compute/plugins/v3
tests/api/openstack/compute/plugins/v3

@ -228,28 +228,25 @@ class ServersController(wsgi.Controller):
if 'default' not in task_state:
search_opts['task_state'] = task_state
if 'changes_since' in search_opts:
if 'changes-since' in search_opts:
try:
parsed = timeutils.parse_isotime(search_opts['changes_since'])
parsed = timeutils.parse_isotime(search_opts['changes-since'])
except ValueError:
msg = _('Invalid changes_since value')
msg = _('Invalid changes-since value')
raise exc.HTTPBadRequest(explanation=msg)
search_opts['changes_since'] = parsed
search_opts['changes-since'] = parsed
# By default, compute's get_all() will return deleted instances.
# If an admin hasn't specified a 'deleted' search option, we need
# to filter out deleted instances by setting the filter ourselves.
# ... Unless 'changes_since' is specified, because 'changes_since'
# ... Unless 'changes-since' is specified, because 'changes-since'
# should return recently deleted images according to the API spec.
if 'deleted' not in search_opts:
if 'changes_since' not in search_opts:
# No 'changes_since', so we only want non-deleted servers
if 'changes-since' not in search_opts:
# No 'changes-since', so we only want non-deleted servers
search_opts['deleted'] = False
if 'changes_since' in search_opts:
search_opts['changes-since'] = search_opts.pop('changes_since')
if search_opts.get("vm_state") == ['deleted']:
if context.is_admin:
search_opts['deleted'] = True
@ -1003,7 +1000,7 @@ class ServersController(wsgi.Controller):
def _get_server_search_options(self):
"""Return server search options allowed by non-admin."""
return ('reservation_id', 'name', 'status', 'image', 'flavor',
'ip', 'changes_since', 'all_tenants')
'ip', 'changes-since', 'all_tenants')
def _get_instance(self, context, instance_uuid):
try:

@ -1084,7 +1084,7 @@ class ServersControllerTest(ControllerTest):
self.stubs.Set(compute_api.API, 'get_all', fake_get_all)
params = 'changes_since=2011-01-24T17:08:01Z'
params = 'changes-since=2011-01-24T17:08:01Z'
req = fakes.HTTPRequestV3.blank('/servers?%s' % params)
servers = self.controller.index(req)['servers']
@ -1092,7 +1092,7 @@ class ServersControllerTest(ControllerTest):
self.assertEqual(servers[0]['id'], server_uuid)
def test_get_servers_allows_changes_since_bad_value(self):
params = 'changes_since=asdf'
params = 'changes-since=asdf'
req = fakes.HTTPRequestV3.blank('/servers?%s' % params)
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.index, req)