From 0460c7a84f2dfc81f9ff09e6e099cfd97d03a800 Mon Sep 17 00:00:00 2001 From: Igor Malinovskiy Date: Mon, 14 Sep 2015 06:14:24 -0700 Subject: [PATCH] Return share_type UUID instead of name in Share API APIImpact Change-Id: I082bdac82c981adf733c709472ce1b9e26d5650b Closes-Bug: #1483886 --- manila/api/openstack/api_version_request.py | 3 +- .../openstack/rest_api_version_history.rst | 5 ++ manila/api/views/shares.py | 18 ++++++- manila/tests/api/v1/test_shares.py | 9 ++++ manila/tests/api/views/test_shares.py | 47 +++++++++++++++++++ manila_tempest_tests/config.py | 2 +- .../tests/api/admin/test_multi_backend.py | 12 ++++- .../tests/api/admin/test_share_manage.py | 5 +- .../tests/api/admin/test_share_types.py | 6 ++- 9 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 manila/tests/api/views/test_shares.py diff --git a/manila/api/openstack/api_version_request.py b/manila/api/openstack/api_version_request.py index b5cbada621..93364dc77b 100644 --- a/manila/api/openstack/api_version_request.py +++ b/manila/api/openstack/api_version_request.py @@ -51,6 +51,7 @@ REST_API_VERSION_HISTORY = """ * 2.3 - Share instances admin API * 2.4 - Consistency Group support * 2.5 - Share Migration admin API + * 2.6 - Return share_type UUID instead of name in Share API """ @@ -58,7 +59,7 @@ REST_API_VERSION_HISTORY = """ # The default api version request is defined to be the # the minimum version of the API supported. _MIN_API_VERSION = "2.0" -_MAX_API_VERSION = "2.5" +_MAX_API_VERSION = "2.6" DEFAULT_API_VERSION = _MIN_API_VERSION diff --git a/manila/api/openstack/rest_api_version_history.rst b/manila/api/openstack/rest_api_version_history.rst index cbc73a898d..c690ec6e18 100644 --- a/manila/api/openstack/rest_api_version_history.rst +++ b/manila/api/openstack/rest_api_version_history.rst @@ -56,3 +56,8 @@ user documentation. 2.5 --- Share Migration admin API. + +2.6 +--- + Return share_type UUID instead of name in Share API and add share_type_name + field. diff --git a/manila/api/views/shares.py b/manila/api/views/shares.py index 4a6ffb83a0..4bbaf6f4c2 100644 --- a/manila/api/views/shares.py +++ b/manila/api/views/shares.py @@ -20,7 +20,10 @@ class ViewBuilder(common.ViewBuilder): """Model a server API response as a python dictionary.""" _collection_name = 'shares' - _detail_version_modifiers = ["add_consistency_group_fields"] + _detail_version_modifiers = [ + "add_consistency_group_fields", + "modify_share_type_field", + ] def summary_list(self, request, shares): """Show a list of shares without many details.""" @@ -92,6 +95,19 @@ class ViewBuilder(common.ViewBuilder): share_dict['source_cgsnapshot_member_id'] = share.get( 'source_cgsnapshot_member_id') + @common.ViewBuilder.versioned_method("2.6") + def modify_share_type_field(self, share_dict, share): + share_type = share.get('share_type_id') + + share_type_name = None + if share.get('share_type'): + share_type_name = share.get('share_type').get('name') + + share_dict.update({ + 'share_type_name': share_type_name, + 'share_type': share_type, + }) + def _list_view(self, func, request, shares): """Provide a view for a list of shares.""" shares_list = [func(request, share)['share'] for share in shares] diff --git a/manila/tests/api/v1/test_shares.py b/manila/tests/api/v1/test_shares.py index 46779d8e21..a788b0f616 100644 --- a/manila/tests/api/v1/test_shares.py +++ b/manila/tests/api/v1/test_shares.py @@ -425,6 +425,15 @@ class ShareApiTest(test.TestCase): expected['share']['source_cgsnapshot_member_id'] = None self.assertEqual(expected, res_dict) + def test_share_show_with_share_type_name(self): + req = fakes.HTTPRequest.blank('/shares/1', version='2.6') + res_dict = self.controller.show(req, '1') + expected = self._get_expected_share_detailed_response() + expected['share']['consistency_group_id'] = None + expected['share']['source_cgsnapshot_member_id'] = None + expected['share']['share_type_name'] = None + self.assertEqual(expected, res_dict) + def test_share_show_admin(self): req = fakes.HTTPRequest.blank('/shares/1', use_admin_context=True) res_dict = self.controller.show(req, '1') diff --git a/manila/tests/api/views/test_shares.py b/manila/tests/api/views/test_shares.py new file mode 100644 index 0000000000..569fc700ae --- /dev/null +++ b/manila/tests/api/views/test_shares.py @@ -0,0 +1,47 @@ +# Copyright (c) 2015 Mirantis, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from manila.api.views import shares +from manila import test +from manila.tests.api import fakes + + +class ViewBuilderTestCase(test.TestCase): + + def setUp(self): + super(ViewBuilderTestCase, self).setUp() + self.builder = shares.ViewBuilder() + self.req = fakes.HTTPRequest.blank('/shares', version="2.6") + + def test__collection_name(self): + self.assertEqual('shares', self.builder._collection_name) + + def test_detail_v_2_6(self): + fake_share = { + 'id': 'fake_id', + 'share_type_id': 'fake_share_type_id', + 'share_type': {'name': 'fake_share_type_name'} + } + + actual_result = self.builder.detail(self.req, fake_share) + + self.assertSubDictMatch( + { + 'id': fake_share['id'], + 'share_type': fake_share['share_type_id'], + 'share_type_name': fake_share['share_type']['name'], + }, + actual_result['share'] + ) diff --git a/manila_tempest_tests/config.py b/manila_tempest_tests/config.py index daed82e737..0d9ffa3937 100644 --- a/manila_tempest_tests/config.py +++ b/manila_tempest_tests/config.py @@ -36,7 +36,7 @@ ShareGroup = [ help="The minimum api microversion is configured to be the " "value of the minimum microversion supported by Manila."), cfg.StrOpt("max_api_microversion", - default="2.5", + default="2.6", help="The maximum api microversion is configured to be the " "value of the latest microversion supported by Manila."), cfg.StrOpt("region", diff --git a/manila_tempest_tests/tests/api/admin/test_multi_backend.py b/manila_tempest_tests/tests/api/admin/test_multi_backend.py index ab57d7fa1a..23fe1ae993 100644 --- a/manila_tempest_tests/tests/api/admin/test_multi_backend.py +++ b/manila_tempest_tests/tests/api/admin/test_multi_backend.py @@ -67,9 +67,19 @@ class ShareMultiBackendTest(base.BaseSharesAdminTest): def test_share_share_type(self): # Share type should be the same as provided with share creation for i in [0, 1]: - get = self.shares_client.get_share(self.shares[i]['id']) + get = self.shares_v2_client.get_share(self.shares[i]['id'], + version="2.5") self.assertEqual(get["share_type"], self.sts[i]["name"]) + @test.attr(type=["gate", "smoke", ]) + def test_share_share_type_v_2_6(self): + # Share type should be the same as provided with share creation + for i in [0, 1]: + get = self.shares_v2_client.get_share(self.shares[i]['id'], + version="2.6") + self.assertEqual(get["share_type"], self.sts[i]["id"]) + self.assertEqual(get["share_type_name"], self.sts[i]["name"]) + @test.attr(type=["gate", ]) def test_share_export_locations(self): # Different backends have different IPs on interfaces diff --git a/manila_tempest_tests/tests/api/admin/test_share_manage.py b/manila_tempest_tests/tests/api/admin/test_share_manage.py index df3896ecc9..1dd4b039ff 100644 --- a/manila_tempest_tests/tests/api/admin/test_share_manage.py +++ b/manila_tempest_tests/tests/api/admin/test_share_manage.py @@ -107,13 +107,16 @@ class ManageNFSShareTest(base.BaseSharesAdminTest): self.shares_client.wait_for_share_status(share['id'], 'available') # Verify data of managed share - get = self.shares_client.get_share(share['id']) + get = self.shares_v2_client.get_share(share['id'], version="2.5") self.assertEqual(name, get['name']) self.assertEqual(description, get['description']) self.assertEqual(self.share1['host'], get['host']) self.assertEqual(self.share1['share_proto'], get['share_proto']) self.assertEqual(self.st['share_type']['name'], get['share_type']) + get = self.shares_v2_client.get_share(share['id'], version="2.6") + self.assertEqual(self.st['share_type']['id'], get['share_type']) + # Delete share self.shares_client.delete_share(share['id']) self.shares_client.wait_for_resource_deletion(share_id=share['id']) diff --git a/manila_tempest_tests/tests/api/admin/test_share_types.py b/manila_tempest_tests/tests/api/admin/test_share_types.py index 2488317066..1f4d6a089d 100644 --- a/manila_tempest_tests/tests/api/admin/test_share_types.py +++ b/manila_tempest_tests/tests/api/admin/test_share_types.py @@ -107,11 +107,15 @@ class ShareTypesAdminTest(base.BaseSharesAdminTest): self.shares_client.wait_for_share_status(share["id"], "available") # Verify share info - get = self.shares_client.get_share(share["id"]) + get = self.shares_v2_client.get_share(share["id"], version="2.5") self.assertEqual(share_name, get["name"]) self.assertEqual(share["id"], get["id"]) self.assertEqual(shr_type_name, get["share_type"]) + get = self.shares_v2_client.get_share(share["id"], version="2.6") + self.assertEqual(st_create["share_type"]["id"], get["share_type"]) + self.assertEqual(shr_type_name, get["share_type_name"]) + def test_private_share_type_access(self): name = data_utils.rand_name("tempest-manila") extra_specs = self.add_required_extra_specs_to_dict({"key": "value", })