From ef0d793e9b9d99ebf4eb54766a1d5a915f54c2e8 Mon Sep 17 00:00:00 2001 From: xing-yang Date: Mon, 14 Nov 2016 07:29:19 -0500 Subject: [PATCH] Show provider_id for admin This patch adds the provider_id in the detailed view of a single volume for admin. APIImpact DocImpact Implements blueprint: show-provider-id Change-Id: Id3059cd8a8fd396333128b7b5086ccd23c008ad4 --- cinder/api/openstack/api_version_request.py | 3 ++- .../openstack/rest_api_version_history.rst | 4 +++ cinder/api/v3/views/volumes.py | 6 +++++ cinder/tests/unit/api/v3/test_volumes.py | 25 +++++++++++++++++++ ...rovider-id-for-admin-ff4fd5a2518a4bfa.yaml | 3 +++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/show-provider-id-for-admin-ff4fd5a2518a4bfa.yaml diff --git a/cinder/api/openstack/api_version_request.py b/cinder/api/openstack/api_version_request.py index cbc698cc776..b81c6aac4aa 100644 --- a/cinder/api/openstack/api_version_request.py +++ b/cinder/api/openstack/api_version_request.py @@ -70,6 +70,7 @@ REST_API_VERSION_HISTORY = """ * 3.19 - Add API reset status actions 'reset_status' to group snapshot. * 3.20 - Add API reset status actions 'reset_status' to generic volume group. + * 3.21 - Show provider_id in detailed view of a volume for admin. """ # The minimum and maximum versions of the API supported @@ -77,7 +78,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.20" +_MAX_API_VERSION = "3.21" _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 2ecc6c56a21..dfff8913b66 100644 --- a/cinder/api/openstack/rest_api_version_history.rst +++ b/cinder/api/openstack/rest_api_version_history.rst @@ -218,3 +218,7 @@ user documentation. 3.20 ---- Added reset status actions 'reset_status' to generic volume group. + +3.21 +---- + Show provider_id in detailed view of a volume for admin. diff --git a/cinder/api/v3/views/volumes.py b/cinder/api/v3/views/volumes.py index c1331bd7438..ba126a76d8f 100644 --- a/cinder/api/v3/views/volumes.py +++ b/cinder/api/v3/views/volumes.py @@ -37,4 +37,10 @@ class ViewBuilder(views_v2.ViewBuilder): if req_version.matches("3.13", None): volume_ref['volume']['group_id'] = volume.get('group_id') + # Add provider_id if min version is greater than or equal to 3.21 + # for admin. + if (request.environ['cinder.context'].is_admin and + req_version.matches("3.21", None)): + volume_ref['volume']['provider_id'] = volume.get('provider_id') + return volume_ref diff --git a/cinder/tests/unit/api/v3/test_volumes.py b/cinder/tests/unit/api/v3/test_volumes.py index 6bd03db3312..9477f534c59 100644 --- a/cinder/tests/unit/api/v3/test_volumes.py +++ b/cinder/tests/unit/api/v3/test_volumes.py @@ -372,3 +372,28 @@ class VolumeApiTest(test.TestCase): # Raise 400 when snapshot has not uuid type. self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create, req, body) + + @ddt.data({'admin': True, 'version': '3.21'}, + {'admin': False, 'version': '3.21'}, + {'admin': True, 'version': '3.20'}, + {'admin': False, 'version': '3.20'}) + @ddt.unpack + def test_volume_show_provider_id(self, admin, version): + self.mock_object(volume_api.API, 'get', v2_fakes.fake_volume_api_get) + self.mock_object(db.sqlalchemy.api, '_volume_type_get_full', + v2_fakes.fake_volume_type_get) + + req = fakes.HTTPRequest.blank('/v3/volumes/%s' % fake.VOLUME_ID, + version=version) + if admin: + admin_ctx = context.RequestContext(fake.USER_ID, fake.PROJECT_ID, + True) + req.environ['cinder.context'] = admin_ctx + res_dict = self.controller.show(req, fake.VOLUME_ID) + req_version = req.api_version_request + # provider_id is in view if min version is greater than or equal to + # 3.21 for admin. + if req_version.matches("3.21", None) and admin: + self.assertIn('provider_id', res_dict['volume']) + else: + self.assertNotIn('provider_id', res_dict['volume']) diff --git a/releasenotes/notes/show-provider-id-for-admin-ff4fd5a2518a4bfa.yaml b/releasenotes/notes/show-provider-id-for-admin-ff4fd5a2518a4bfa.yaml new file mode 100644 index 00000000000..955e27538d9 --- /dev/null +++ b/releasenotes/notes/show-provider-id-for-admin-ff4fd5a2518a4bfa.yaml @@ -0,0 +1,3 @@ +--- +features: + - Add provider_id in the detailed view of a volume for admin.