Merge "Support sort backup with name"

This commit is contained in:
Jenkins 2017-06-05 14:04:36 +00:00 committed by Gerrit Code Review
commit 224d04e2ee
6 changed files with 39 additions and 1 deletions

View File

@ -87,6 +87,10 @@ class BackupsController(wsgi.Controller):
filters,
self._get_backup_filter_options())
def _convert_sort_name(self, req_version, sort_keys):
"""Convert sort key "name" to "display_name". """
pass
def _get_backups(self, req, is_detail):
"""Returns a list of backups, transformed through view builder."""
context = req.environ['cinder.context']
@ -95,6 +99,7 @@ class BackupsController(wsgi.Controller):
marker, limit, offset = common.get_pagination_params(filters)
sort_keys, sort_dirs = common.get_sort_params(filters)
self._convert_sort_name(req_version, sort_keys)
self._process_backup_filtering(context=context, filters=filters,
req_version=req_version)

View File

@ -90,6 +90,7 @@ REST_API_VERSION_HISTORY = """
list APIs.
* 3.35 - Add ``volume-type`` filter to Get-Pools API.
* 3.36 - Add metadata to volumes/summary response body.
* 3.37 - Support sort backup by "name".
"""
# The minimum and maximum versions of the API supported
@ -97,7 +98,7 @@ REST_API_VERSION_HISTORY = """
# minimum version of the API supported.
# Explicitly using /v1 or /v2 endpoints will still work
_MIN_API_VERSION = "3.0"
_MAX_API_VERSION = "3.36"
_MAX_API_VERSION = "3.37"
_LEGACY_API_VERSION1 = "1.0"
_LEGACY_API_VERSION2 = "2.0"

View File

@ -321,3 +321,7 @@ user documentation.
3.36
----
Add metadata to volumes/summary response body.
3.37
----
Support sort backup by "name".

View File

@ -96,6 +96,10 @@ class BackupsController(backups_v2.BackupsController):
pass
return resp_backup
def _convert_sort_name(self, req_version, sort_keys):
if req_version.matches("3.37") and 'name' in sort_keys:
sort_keys[sort_keys.index('name')] = 'display_name'
def create_resource():
return wsgi.Resource(BackupsController())

View File

@ -21,6 +21,7 @@ import webob
from cinder.api.openstack import api_version_request as api_version
from cinder.api.v3 import backups
from cinder.api.views import backups as backup_view
import cinder.backup
from cinder import context
from cinder import exception
@ -100,6 +101,26 @@ class BackupsControllerAPITestCase(test.TestCase):
mock.ANY, 'backup',
support_like)
@ddt.data('3.36', '3.37')
def test_backup_list_with_name(self, version):
backup1 = test_utils.create_backup(
self.ctxt, display_name='b_test_name',
status=fields.BackupStatus.AVAILABLE)
backup2 = test_utils.create_backup(
self.ctxt, display_name='a_test_name',
status=fields.BackupStatus.AVAILABLE)
url = '/v3/%s/backups?sort_key=name' % fake.PROJECT_ID
req = fakes.HTTPRequest.blank(url, version=version)
if version == '3.36':
self.assertRaises(exception.InvalidInput,
self.controller.index,
req)
else:
expect = backup_view.ViewBuilder().summary_list(req,
[backup1, backup2])
result = self.controller.index(req)
self.assertEqual(expect, result)
def test_backup_update(self):
backup = test_utils.create_backup(
self.ctxt,

View File

@ -0,0 +1,3 @@
---
features:
- Add support for sorting backups by "name".