Support sort snapshots with name
Cinder now doesn't support sort snapshots with "name". This patch adds the support to keep the same with volume does. Change-Id: I79d160292bc190c643bbe11668cc49ba11a23bcb Closes-bug: #1659504
This commit is contained in:
parent
3a6c184d52
commit
8b5264f559
@ -80,6 +80,7 @@ REST_API_VERSION_HISTORY = """
|
||||
* 3.27 - Add attachment API
|
||||
* 3.28 - Add filters support to get_pools
|
||||
* 3.29 - Add filter, sorter and pagination support in group snapshot.
|
||||
* 3.30 - Support sort snapshots with "name".
|
||||
|
||||
"""
|
||||
|
||||
@ -88,7 +89,7 @@ REST_API_VERSION_HISTORY = """
|
||||
# minimum version of the API supported.
|
||||
# Explicitly using /v1 or /v2 enpoints will still work
|
||||
_MIN_API_VERSION = "3.0"
|
||||
_MAX_API_VERSION = "3.29"
|
||||
_MAX_API_VERSION = "3.30"
|
||||
_LEGACY_API_VERSION1 = "1.0"
|
||||
_LEGACY_API_VERSION2 = "2.0"
|
||||
|
||||
|
@ -292,3 +292,7 @@ user documentation.
|
||||
3.29
|
||||
----
|
||||
Add filter, sorter and pagination support in group snapshot.
|
||||
|
||||
3.30
|
||||
----
|
||||
Support sort snapshots with "name".
|
||||
|
@ -81,6 +81,10 @@ class SnapshotsController(snapshots_v2.SnapshotsController):
|
||||
# process filters
|
||||
self._process_filters(req, context, search_opts)
|
||||
|
||||
req_version = req.api_version_request
|
||||
if req_version.matches("3.30", None) and 'name' in sort_keys:
|
||||
sort_keys[sort_keys.index('name')] = 'display_name'
|
||||
|
||||
# NOTE(thingee): v3 API allows name instead of display_name
|
||||
if 'name' in search_opts:
|
||||
search_opts['display_name'] = search_opts.pop('name')
|
||||
|
@ -107,23 +107,39 @@ class SnapshotApiTest(test.TestCase):
|
||||
self.assertRaises(exception.SnapshotNotFound,
|
||||
self.controller.show, req, snapshot_id)
|
||||
|
||||
def _create_snapshot_with_metadata(self, metadata):
|
||||
def _create_snapshot(self, name=None, metadata=None):
|
||||
"""Creates test snapshopt with provided metadata"""
|
||||
req = fakes.HTTPRequest.blank('/v3/snapshots')
|
||||
snap = {"volume_size": 200,
|
||||
"volume_id": fake.VOLUME_ID,
|
||||
"display_name": "Volume Test Name",
|
||||
"display_name": name or "Volume Test Name",
|
||||
"display_description": "Volume Test Desc",
|
||||
"availability_zone": "zone1:host1",
|
||||
"host": "fake-host",
|
||||
"metadata": metadata}
|
||||
"host": "fake-host"}
|
||||
if metadata:
|
||||
snap["metadata"] = metadata
|
||||
body = {"snapshot": snap}
|
||||
self.controller.create(req, body)
|
||||
|
||||
def test_snapshot_list_with_sort_name(self):
|
||||
self._create_snapshot(name='test1')
|
||||
self._create_snapshot(name='test2')
|
||||
|
||||
req = fakes.HTTPRequest.blank('/v3/snapshots?sort_key=name',
|
||||
version='3.29')
|
||||
self.assertRaises(exception.InvalidInput, self.controller.detail, req)
|
||||
|
||||
req = fakes.HTTPRequest.blank('/v3/snapshots?sort_key=name',
|
||||
version='3.30')
|
||||
res_dict = self.controller.detail(req)
|
||||
self.assertEqual(2, len(res_dict['snapshots']))
|
||||
self.assertEqual('test2', res_dict['snapshots'][0]['name'])
|
||||
self.assertEqual('test1', res_dict['snapshots'][1]['name'])
|
||||
|
||||
def test_snapshot_list_with_one_metadata_in_filter(self):
|
||||
# Create snapshot with metadata key1: value1
|
||||
metadata = {"key1": "val1"}
|
||||
self._create_snapshot_with_metadata(metadata)
|
||||
self._create_snapshot(metadata=metadata)
|
||||
|
||||
# Create request with metadata filter key1: value1
|
||||
req = create_snapshot_query_with_metadata('{"key1":"val1"}', '3.22')
|
||||
@ -150,7 +166,7 @@ class SnapshotApiTest(test.TestCase):
|
||||
def test_snapshot_list_with_multiple_metadata_in_filter(self):
|
||||
# Create snapshot with metadata key1: value1, key11: value11
|
||||
metadata = {"key1": "val1", "key11": "val11"}
|
||||
self._create_snapshot_with_metadata(metadata)
|
||||
self._create_snapshot(metadata=metadata)
|
||||
|
||||
# Create request with metadata filter key1: value1, key11: value11
|
||||
req = create_snapshot_query_with_metadata(
|
||||
@ -182,7 +198,7 @@ class SnapshotApiTest(test.TestCase):
|
||||
def test_snapshot_list_with_metadata_unsupported_microversion(self):
|
||||
# Create snapshot with metadata key1: value1
|
||||
metadata = {"key1": "val1"}
|
||||
self._create_snapshot_with_metadata(metadata)
|
||||
self._create_snapshot(metadata=metadata)
|
||||
|
||||
# Create request with metadata filter key2: value2
|
||||
req = create_snapshot_query_with_metadata('{"key2":"val2"}', '3.21')
|
||||
|
@ -0,0 +1,3 @@
|
||||
---
|
||||
features:
|
||||
- Support to sort snapshots with "name".
|
Loading…
Reference in New Issue
Block a user