From e9c848f5fd50154bbd4bb9135159c54560382ad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Weing=C3=A4rtner?= Date: Fri, 21 Jun 2019 13:17:52 -0300 Subject: [PATCH] Introduces MV to add volume type ID in volumes details MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduces microversion (MV) 3.63 to add volume type ID in the volume details. This change comes to fix a problem we found in Gnocchi concerning volumes monitored data. When a volume event is created, Cinder uses the volume type as the volume type ID. On the other hand, Ceilometer pollsters are always updating the volume_type value in Gnocchi with the volume type from volume details API (which uses the volume type name value). That situation creates a massive number of resource revisions in Gnocchi. This MV along with the Dynamic pollster system in Ceilometer enables operators to overcome the issue. Closes-Bug: https://bugs.launchpad.net/cinder/+bug/1911660 Change-Id: Icb88faeb00040250a25a5630aeb312a8434ed3c8 Signed-off-by: Rafael Weingärtner --- api-ref/source/v3/parameters.yaml | 9 ++++++++- .../versions/version-show-response.json | 4 ++-- .../samples/versions/versions-response.json | 4 ++-- .../volumes-list-detailed-response.json | 8 +++++++- api-ref/source/v3/volumes-v3-volumes.inc | 2 ++ cinder/api/microversions.py | 2 ++ cinder/api/openstack/api_version_request.py | 9 +++++++-- .../openstack/rest_api_version_history.rst | 6 ++++++ cinder/api/v2/views/volumes.py | 6 +++--- cinder/api/v3/views/volumes.py | 19 +++++++++++++++++++ .../volumes-list-detailed-response.json.tpl | 8 +++++++- .../api_sample_tests/test_volumes.py | 12 +++++++++--- ...ume-type-name-and-id-5f4fd8480874fe9b.yaml | 7 +++++++ 13 files changed, 81 insertions(+), 15 deletions(-) create mode 100644 releasenotes/notes/mv-volume-type-name-and-id-5f4fd8480874fe9b.yaml diff --git a/api-ref/source/v3/parameters.yaml b/api-ref/source/v3/parameters.yaml index a021105a26b..c521e0b0630 100644 --- a/api-ref/source/v3/parameters.yaml +++ b/api-ref/source/v3/parameters.yaml @@ -3121,6 +3121,13 @@ volume_type_detail: in: body required: false type: string +volume_type_id_363: + description: | + The associated volume type ID for the volume. + in: body + required: true + type: object + min_version: 3.63 volume_type_id_body: description: | The UUID of the volume type. @@ -3129,7 +3136,7 @@ volume_type_id_body: type: string volume_type_vol: description: | - The associated volume type for the volume. + The associated volume type name for the volume. in: body required: true type: string diff --git a/api-ref/source/v3/samples/versions/version-show-response.json b/api-ref/source/v3/samples/versions/version-show-response.json index 505fbe2d891..1cd449cbbbe 100644 --- a/api-ref/source/v3/samples/versions/version-show-response.json +++ b/api-ref/source/v3/samples/versions/version-show-response.json @@ -21,8 +21,8 @@ ], "min_version": "3.0", "status": "CURRENT", - "updated": "2018-07-17T00:00:00Z", - "version": "3.62" + "updated": "2020-11-19T08:56:00Z", + "version": "3.63" } ] } diff --git a/api-ref/source/v3/samples/versions/versions-response.json b/api-ref/source/v3/samples/versions/versions-response.json index 7718667ffdb..795b50572e9 100644 --- a/api-ref/source/v3/samples/versions/versions-response.json +++ b/api-ref/source/v3/samples/versions/versions-response.json @@ -45,8 +45,8 @@ ], "min_version": "3.0", "status": "CURRENT", - "updated": "2018-07-17T00:00:00Z", - "version": "3.62" + "updated": "2020-11-19T08:56:00Z", + "version": "3.63" } ] } diff --git a/api-ref/source/v3/samples/volumes/volumes-list-detailed-response.json b/api-ref/source/v3/samples/volumes/volumes-list-detailed-response.json index 1a012ad81ac..82c73eea67b 100644 --- a/api-ref/source/v3/samples/volumes/volumes-list-detailed-response.json +++ b/api-ref/source/v3/samples/volumes/volumes-list-detailed-response.json @@ -34,7 +34,13 @@ "status": "creating", "updated_at": null, "user_id": "c853ca26-e8ea-4797-8a52-ee124a013d0e", - "volume_type": "__DEFAULT__" + "volume_type": "__DEFAULT__", + "volume_type_id": "5fed9d7c-401d-46e2-8e80-f30c70cb7e1d", + "provider_id": null, + "group_id": null, + "service_uuid": null, + "shared_targets": true, + "cluster_name": null } ] } \ No newline at end of file diff --git a/api-ref/source/v3/volumes-v3-volumes.inc b/api-ref/source/v3/volumes-v3-volumes.inc index 76f4b4a0efd..dadfbab9267 100644 --- a/api-ref/source/v3/volumes-v3-volumes.inc +++ b/api-ref/source/v3/volumes-v3-volumes.inc @@ -130,6 +130,7 @@ Response Parameters - created_at: created_at - volumes: volumes - volume_type: volume_type_vol + - volume_type_id: volume_type_id_363 - group_id: group_id_optional - volumes_links: links_vol_optional - count: count @@ -375,6 +376,7 @@ Response Parameters - bootable: bootable_response - created_at: created_at - volume_type: volume_type_vol + - volume_type_id: volume_type_id_363 - service_uuid: service_uuid - shared_targets: shared_targets - cluster_name: cluster_name diff --git a/cinder/api/microversions.py b/cinder/api/microversions.py index f1b9bda6edd..8c4268e36e1 100644 --- a/cinder/api/microversions.py +++ b/cinder/api/microversions.py @@ -165,6 +165,8 @@ VOLUME_CLUSTER_NAME = '3.61' DEFAULT_TYPE_OVERRIDES = '3.62' +VOLUME_TYPE_ID_IN_VOLUME_DETAIL = '3.63' + def get_mv_header(version): """Gets a formatted HTTP microversion header. diff --git a/cinder/api/openstack/api_version_request.py b/cinder/api/openstack/api_version_request.py index 966b5d22396..3513d5fe7e1 100644 --- a/cinder/api/openstack/api_version_request.py +++ b/cinder/api/openstack/api_version_request.py @@ -142,6 +142,11 @@ REST_API_VERSION_HISTORY = """ * 3.61 - Add ``cluster_name`` attribute to response body of volume details for admin. * 3.62 - Default volume type overrides + * 3.63 - Include volume type ID in the volume details JSON response. Before + this microversion (MV), Cinder returns only the volume type name + in the volume details. This MV affects the volume detail list + ("GET /v3/{project_id}/volumes/detail") and volume-show + ("GET /v3/{project_id}/volumes/{volume_id}") calls. """ # The minimum and maximum versions of the API supported @@ -149,9 +154,9 @@ REST_API_VERSION_HISTORY = """ # minimum version of the API supported. # Explicitly using /v2 endpoints will still work _MIN_API_VERSION = "3.0" -_MAX_API_VERSION = "3.62" +_MAX_API_VERSION = "3.63" _LEGACY_API_VERSION2 = "2.0" -UPDATED = "2020-10-14T00:00:00Z" +UPDATED = "2020-11-19T08:56:00Z" # NOTE(cyeoh): min and max versions declared as functions so we can diff --git a/cinder/api/openstack/rest_api_version_history.rst b/cinder/api/openstack/rest_api_version_history.rst index ca27f167804..4f6e78ac4ec 100644 --- a/cinder/api/openstack/rest_api_version_history.rst +++ b/cinder/api/openstack/rest_api_version_history.rst @@ -479,3 +479,9 @@ Active/Active HA mode. Add support for set, get, and unset a default volume type for a specific project. Setting this default overrides the configured default_volume_type value. + +3.63 +---- +Includes volume type ID in the volume-show and volume-detail-list JSON +responses. Before this microversion, Cinder returns only the volume type name +in the volume details. diff --git a/cinder/api/v2/views/volumes.py b/cinder/api/v2/views/volumes.py index e69a03a1ed0..32a9a7f05c3 100644 --- a/cinder/api/v2/views/volumes.py +++ b/cinder/api/v2/views/volumes.py @@ -75,7 +75,7 @@ class ViewBuilder(common.ViewBuilder): 'updated_at': volume.get('updated_at'), 'name': volume.get('display_name'), 'description': volume.get('display_description'), - 'volume_type': self._get_volume_type(volume), + 'volume_type': self._get_volume_type(request, volume), 'snapshot_id': volume.get('snapshot_id'), 'source_volid': volume.get('source_volid'), 'metadata': self._get_volume_metadata(volume), @@ -138,8 +138,8 @@ class ViewBuilder(common.ViewBuilder): """Retrieve the metadata of the volume object.""" return volume.metadata - def _get_volume_type(self, volume): - """Retrieve the type the volume object.""" + def _get_volume_type(self, request, volume): + """Retrieve the type of the volume object.""" if volume['volume_type_id'] and volume.get('volume_type'): return volume['volume_type']['name'] else: diff --git a/cinder/api/v3/views/volumes.py b/cinder/api/v3/views/volumes.py index e72588dd0a2..6e61146337c 100644 --- a/cinder/api/v3/views/volumes.py +++ b/cinder/api/v3/views/volumes.py @@ -66,6 +66,10 @@ class ViewBuilder(views_v2.ViewBuilder): volume_ref['volume']['cluster_name'] = volume.get( 'cluster_name', None) + if req_version.matches(mv.VOLUME_TYPE_ID_IN_VOLUME_DETAIL, None): + volume_ref[ + 'volume']["volume_type_id"] = volume['volume_type'].get('id') + return volume_ref def _list_view(self, func, request, volumes, volume_count, @@ -96,3 +100,18 @@ class ViewBuilder(views_v2.ViewBuilder): volumes_dict['count'] = volume_count return volumes_dict + + def _get_volume_type(self, request, volume): + """Returns the volume type of the volume. + + Retrieves the volume type name for microversion 3.63. + Otherwise, it uses the default implementation from super. + """ + + req_version = request.api_version_request + if req_version.matches(mv.VOLUME_TYPE_ID_IN_VOLUME_DETAIL): + if volume.get('volume_type'): + return volume['volume_type']['name'] + return None + + return super(ViewBuilder, self)._get_volume_type(request, volume) diff --git a/cinder/tests/functional/api_sample_tests/samples/volumes/volumes-list-detailed-response.json.tpl b/cinder/tests/functional/api_sample_tests/samples/volumes/volumes-list-detailed-response.json.tpl index 071d4b6086a..090084f665f 100644 --- a/cinder/tests/functional/api_sample_tests/samples/volumes/volumes-list-detailed-response.json.tpl +++ b/cinder/tests/functional/api_sample_tests/samples/volumes/volumes-list-detailed-response.json.tpl @@ -34,7 +34,13 @@ "status": "creating", "updated_at": null, "user_id": "%(uuid)s", - "volume_type": "__DEFAULT__" + "volume_type": "%(name)s", + "volume_type_id": "%(uuid)s", + "service_uuid": null, + "provider_id": null, + "group_id": null, + "shared_targets": true, + "cluster_name": null } ] } \ No newline at end of file diff --git a/cinder/tests/functional/api_sample_tests/test_volumes.py b/cinder/tests/functional/api_sample_tests/test_volumes.py index 8f26ad2145c..1ff5d8333e1 100644 --- a/cinder/tests/functional/api_sample_tests/test_volumes.py +++ b/cinder/tests/functional/api_sample_tests/test_volumes.py @@ -12,6 +12,7 @@ from oslo_serialization import jsonutils +from cinder.api.microversions import VOLUME_TYPE_ID_IN_VOLUME_DETAIL from cinder.tests.functional import api_samples_test_base @@ -40,10 +41,15 @@ class VolumesSampleJsonTest(VolumesSampleBase): self.response = self._create_volume() def test_volume_list_detail(self): + original_api_version = self.api.api_version - response = self._do_get('volumes/detail') - self._verify_response('volumes-list-detailed-response', - {}, response, 200) + try: + self.api.api_version = VOLUME_TYPE_ID_IN_VOLUME_DETAIL + response = self._do_get('volumes/detail') + self._verify_response('volumes-list-detailed-response', + {}, response, 200) + finally: + self.api.api_version = original_api_version def test_volume_create(self): diff --git a/releasenotes/notes/mv-volume-type-name-and-id-5f4fd8480874fe9b.yaml b/releasenotes/notes/mv-volume-type-name-and-id-5f4fd8480874fe9b.yaml new file mode 100644 index 00000000000..b47d88636ae --- /dev/null +++ b/releasenotes/notes/mv-volume-type-name-and-id-5f4fd8480874fe9b.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + Introduces microversion (MV) 3.63, which includes volume type ID in the + volume details JSON response. This MV affects the volume detail list + (``GET /v3/{project_id}/volumes/detail``), and volume-show + (``GET /v3/{project_id}/volumes/{volume_id}``) calls.