From 7b06b00081906ee5d2ab0a2dd137a637cc7cc191 Mon Sep 17 00:00:00 2001 From: Cao Shufeng Date: Thu, 1 Sep 2016 04:45:25 -0400 Subject: [PATCH] Wrap GroupType class's function with api_version GroupType class's 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 Closes-bug: #1619105 Change-Id: I08563898cb1a1eb212973e88a87ed1248f43fa77 --- cinderclient/tests/unit/v3/test_group_types.py | 8 ++++++-- cinderclient/v3/group_types.py | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cinderclient/tests/unit/v3/test_group_types.py b/cinderclient/tests/unit/v3/test_group_types.py index 45147f2a8..7918bf11d 100644 --- a/cinderclient/tests/unit/v3/test_group_types.py +++ b/cinderclient/tests/unit/v3/test_group_types.py @@ -21,6 +21,7 @@ from cinderclient.tests.unit import utils from cinderclient.tests.unit.v3 import fakes cs = fakes.FakeClient(api_version=api_versions.APIVersion('3.11')) +pre_cs = fakes.FakeClient(api_version=api_versions.APIVersion('3.10')) class GroupTypesTest(utils.TestCase): @@ -33,8 +34,6 @@ class GroupTypesTest(utils.TestCase): 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) @@ -95,6 +94,11 @@ class GroupTypesTest(utils.TestCase): {'group_specs': {'k': 'v'}}) self._assert_request_id(res) + def test_set_key_pre_version(self): + t = group_types.GroupType(pre_cs, {'id': 1}) + self.assertRaises(exc.VersionNotFoundForAPIMethod, + t.set_keys, {'k': 'v'}) + def test_unset_keys(self): t = cs.group_types.get(1) res = t.unset_keys(['k']) diff --git a/cinderclient/v3/group_types.py b/cinderclient/v3/group_types.py index bab72ac80..1292c1f1d 100644 --- a/cinderclient/v3/group_types.py +++ b/cinderclient/v3/group_types.py @@ -33,6 +33,7 @@ class GroupType(base.Resource): return self._info.get("is_public", self._info.get("is_public", 'N/A')) + @api_versions.wraps("3.11") def get_keys(self): """Get group specs from a group type. @@ -43,6 +44,7 @@ class GroupType(base.Resource): base.getid(self)) return body["group_specs"] + @api_versions.wraps("3.11") def set_keys(self, metadata): """Set group specs on a group type. @@ -56,6 +58,7 @@ class GroupType(base.Resource): "group_specs", return_raw=True) + @api_versions.wraps("3.11") def unset_keys(self, keys): """Unset specs on a group type.