Improvement to query cg detail(Part 1)

This feature allows users to query volume details
filtering by consistency group id.

According the spec, this is part 1 to implement
whole bp. Next part will be implemented after
Generic Volume group done.

APIImpact
1. User can use consistency group id to filter volume detail
   in cinder API. The query url is like this:
   "volumes/detail?group_id={consistency_group_id}".

2. This change will add a new version "3.10".

Co-Authored-By: wangxiyuan<wangxiyuan@huawei.com>

Change-Id: If3354cfaee5ca57d281b9270b4aebf4d26d42b2c
Partial-Implements: blueprint improvement-to-query-consistency-group-detail
This commit is contained in:
wanghao 2016-06-15 17:14:17 +08:00 committed by wangxiyuan
parent a9246208f9
commit 3eafcf5720
6 changed files with 56 additions and 3 deletions

View File

@ -42,13 +42,13 @@ api_common_opts = [
cfg.ListOpt('query_volume_filters',
default=['name', 'status', 'metadata',
'availability_zone',
'bootable'],
'bootable', 'group_id'],
help="Volume filter options which "
"non-admin user could use to "
"query volumes. Default values "
"are: ['name', 'status', "
"'metadata', 'availability_zone' ,"
"'bootable']")
"'bootable', 'group_id']")
]
CONF = cfg.CONF

View File

@ -57,6 +57,7 @@ REST_API_VERSION_HISTORY = """
* 3.7 - Add cluster API and cluster_name field to service list API
* 3.8 - Adds resources from volume_manage and snapshot_manage extensions.
* 3.9 - Add backup update interface.
* 3.10 - Add group_id filter to list/detail volumes in _get_volumes.
"""
@ -65,7 +66,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.9"
_MAX_API_VERSION = "3.10"
_LEGACY_API_VERSION1 = "1.0"
_LEGACY_API_VERSION2 = "2.0"

View File

@ -165,3 +165,8 @@ user documentation.
"name": "backup_name",
"links": "backup_link",
}
3.10
----
Added the filter parameters ``group_id`` to
list/detail volumes requests.

View File

@ -36,6 +36,9 @@ class VolumeController(volumes_v2.VolumeController):
if req_version.matches(None, "3.3"):
filters.pop('glance_metadata', None)
if req_version.matches(None, "3.9"):
filters.pop('group_id', None)
utils.remove_invalid_filter_options(context, filters,
self._get_volume_filter_options())
# NOTE(thingee): v2 API allows name instead of display_name
@ -46,6 +49,9 @@ class VolumeController(volumes_v2.VolumeController):
filters['display_name'] = filters['name']
del filters['name']
if 'group_id' in filters:
filters['consistencygroup_id'] = filters.pop('group_id')
strict = req.api_version_request.matches("3.2", None)
self.volume_api.check_volume_filters(filters, strict)

View File

@ -87,6 +87,19 @@ class VolumeApiTest(test.TestCase):
'qcow2')
return [vol1, vol2]
def _create_volume_with_consistency_group(self):
vol1 = db.volume_create(self.ctxt, {'display_name': 'test1',
'project_id':
self.ctxt.project_id,
'consistencygroup_id':
fake.CONSISTENCY_GROUP_ID})
vol2 = db.volume_create(self.ctxt, {'display_name': 'test2',
'project_id':
self.ctxt.project_id,
'consistencygroup_id':
fake.CONSISTENCY_GROUP2_ID})
return [vol1, vol2]
def test_volume_index_filter_by_glance_metadata(self):
vols = self._create_volume_with_glance_metadata()
req = fakes.HTTPRequest.blank("/v3/volumes?glance_metadata="
@ -109,3 +122,26 @@ class VolumeApiTest(test.TestCase):
res_dict = self.controller.index(req)
volumes = res_dict['volumes']
self.assertEqual(2, len(volumes))
def test_volume_index_filter_by_group_id(self):
vols = self._create_volume_with_consistency_group()
req = fakes.HTTPRequest.blank(("/v3/volumes?group_id=%s") %
fake.CONSISTENCY_GROUP_ID)
req.headers["OpenStack-API-Version"] = "volume 3.10"
req.api_version_request = api_version.APIVersionRequest('3.10')
req.environ['cinder.context'] = self.ctxt
res_dict = self.controller.index(req)
volumes = res_dict['volumes']
self.assertEqual(1, len(volumes))
self.assertEqual(vols[0].id, volumes[0]['id'])
def test_volume_index_filter_by_group_id_in_unsupport_version(self):
self._create_volume_with_consistency_group()
req = fakes.HTTPRequest.blank(("/v3/volumes?group_id=%s") %
fake.CONSISTENCY_GROUP2_ID)
req.headers["OpenStack-API-Version"] = "volume 3.9"
req.api_version_request = api_version.APIVersionRequest('3.9')
req.environ['cinder.context'] = self.ctxt
res_dict = self.controller.index(req)
volumes = res_dict['volumes']
self.assertEqual(2, len(volumes))

View File

@ -0,0 +1,5 @@
---
features:
- Added support for querying volumes filtered by group_id
using 'group_id' optional URL parameter.
For example, "volumes/detail?group_id={consistency_group_id}".