From 3eafcf5720efb3c49a374c9108f935e044f9a01e Mon Sep 17 00:00:00 2001 From: wanghao Date: Wed, 15 Jun 2016 17:14:17 +0800 Subject: [PATCH] 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 Change-Id: If3354cfaee5ca57d281b9270b4aebf4d26d42b2c Partial-Implements: blueprint improvement-to-query-consistency-group-detail --- cinder/api/common.py | 4 +-- cinder/api/openstack/api_version_request.py | 3 +- .../openstack/rest_api_version_history.rst | 5 +++ cinder/api/v3/volumes.py | 6 ++++ cinder/tests/unit/api/v3/test_volumes.py | 36 +++++++++++++++++++ ...istency-group-detail-84a906d45383e067.yaml | 5 +++ 6 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/improvement-to-query-consistency-group-detail-84a906d45383e067.yaml diff --git a/cinder/api/common.py b/cinder/api/common.py index ff5a4ae5ab3..c39770cf996 100644 --- a/cinder/api/common.py +++ b/cinder/api/common.py @@ -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 diff --git a/cinder/api/openstack/api_version_request.py b/cinder/api/openstack/api_version_request.py index 04d5805e6f7..cb273c91b33 100644 --- a/cinder/api/openstack/api_version_request.py +++ b/cinder/api/openstack/api_version_request.py @@ -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" diff --git a/cinder/api/openstack/rest_api_version_history.rst b/cinder/api/openstack/rest_api_version_history.rst index 6d9267ea5e5..3340a5dc52b 100644 --- a/cinder/api/openstack/rest_api_version_history.rst +++ b/cinder/api/openstack/rest_api_version_history.rst @@ -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. diff --git a/cinder/api/v3/volumes.py b/cinder/api/v3/volumes.py index 7be0c4c5bbe..e1cdc5283eb 100644 --- a/cinder/api/v3/volumes.py +++ b/cinder/api/v3/volumes.py @@ -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) diff --git a/cinder/tests/unit/api/v3/test_volumes.py b/cinder/tests/unit/api/v3/test_volumes.py index a0a0692965f..80d81d1e2a9 100644 --- a/cinder/tests/unit/api/v3/test_volumes.py +++ b/cinder/tests/unit/api/v3/test_volumes.py @@ -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)) diff --git a/releasenotes/notes/improvement-to-query-consistency-group-detail-84a906d45383e067.yaml b/releasenotes/notes/improvement-to-query-consistency-group-detail-84a906d45383e067.yaml new file mode 100644 index 00000000000..da53724a271 --- /dev/null +++ b/releasenotes/notes/improvement-to-query-consistency-group-detail-84a906d45383e067.yaml @@ -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}".