From 1abc4b0b4464d818df960dd6eec493241170601d Mon Sep 17 00:00:00 2001 From: Cao Shufeng Date: Tue, 30 Aug 2016 08:22:08 -0400 Subject: [PATCH] Wrap group type and group spec with api_version Group type and group sepc functions only support 3.11 microversion or higher. So it should be wrapped like like one[1], otherwise these fuctions may be exposed to lib users with old microversion. [1]: https://github.com/openstack/python-cinderclient/blob/master/cinderclient/v3/services.py#L82 Change-Id: I2ddac90cd483c456a5e88a3952017a77a543f995 --- cinderclient/tests/unit/v3/test_group_types.py | 10 +++++++++- cinderclient/v3/group_types.py | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cinderclient/tests/unit/v3/test_group_types.py b/cinderclient/tests/unit/v3/test_group_types.py index 8904fb38a..45147f2a8 100644 --- a/cinderclient/tests/unit/v3/test_group_types.py +++ b/cinderclient/tests/unit/v3/test_group_types.py @@ -14,11 +14,13 @@ # License for the specific language governing permissions and limitations # under the License. +from cinderclient import api_versions +from cinderclient import exceptions as exc from cinderclient.v3 import group_types from cinderclient.tests.unit import utils from cinderclient.tests.unit.v3 import fakes -cs = fakes.FakeClient() +cs = fakes.FakeClient(api_version=api_versions.APIVersion('3.11')) class GroupTypesTest(utils.TestCase): @@ -30,6 +32,12 @@ class GroupTypesTest(utils.TestCase): for t in tl: self.assertIsInstance(t, group_types.GroupType) + def test_list_group_types_pre_version(self): + pre_cs = fakes.FakeClient(api_version= + api_versions.APIVersion('3.10')) + self.assertRaises(exc.VersionNotFoundForAPIMethod, + pre_cs.group_types.list) + def test_list_group_types_not_public(self): t1 = cs.group_types.list(is_public=None) cs.assert_called('GET', '/group_types?is_public=None') diff --git a/cinderclient/v3/group_types.py b/cinderclient/v3/group_types.py index 70c5575d8..bab72ac80 100644 --- a/cinderclient/v3/group_types.py +++ b/cinderclient/v3/group_types.py @@ -16,6 +16,7 @@ """Group Type interface.""" +from cinderclient import api_versions from cinderclient import base @@ -74,6 +75,7 @@ class GroupTypeManager(base.ManagerWithFind): """Manage :class:`GroupType` resources.""" resource_class = GroupType + @api_versions.wraps("3.11") def list(self, search_opts=None, is_public=None): """Lists all group types. @@ -84,6 +86,7 @@ class GroupTypeManager(base.ManagerWithFind): query_string = '?is_public=%s' % is_public return self._list("/group_types%s" % (query_string), "group_types") + @api_versions.wraps("3.11") def get(self, group_type): """Get a specific group type. @@ -93,6 +96,7 @@ class GroupTypeManager(base.ManagerWithFind): return self._get("/group_types/%s" % base.getid(group_type), "group_type") + @api_versions.wraps("3.11") def default(self): """Get the default group type. @@ -100,6 +104,7 @@ class GroupTypeManager(base.ManagerWithFind): """ return self._get("/group_types/default", "group_type") + @api_versions.wraps("3.11") def delete(self, group_type): """Deletes a specific group_type. @@ -107,6 +112,7 @@ class GroupTypeManager(base.ManagerWithFind): """ return self._delete("/group_types/%s" % base.getid(group_type)) + @api_versions.wraps("3.11") def create(self, name, description=None, is_public=True): """Creates a group type. @@ -126,6 +132,7 @@ class GroupTypeManager(base.ManagerWithFind): return self._create("/group_types", body, "group_type") + @api_versions.wraps("3.11") def update(self, group_type, name=None, description=None, is_public=None): """Update the name and/or description for a group type.