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
This commit is contained in:
xing-yang 2016-11-14 07:29:19 -05:00
parent c3c560296d
commit ef0d793e9b
5 changed files with 40 additions and 1 deletions

View File

@ -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"

View File

@ -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.

View File

@ -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

View File

@ -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'])

View File

@ -0,0 +1,3 @@
---
features:
- Add provider_id in the detailed view of a volume for admin.