From 654f71208b3a270df0c7c9d66e2f90d3ecc4c162 Mon Sep 17 00:00:00 2001 From: Cao Shufeng Date: Tue, 30 Aug 2016 07:38:14 -0400 Subject: [PATCH] Wrap volume_backup's update function with api_version Volume backup's update function only supports 3.9 microversion or higher. So it should be wrapped like like this 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: I2c800099e8ae707135417f9821f14d1a9e69586e --- cinderclient/tests/unit/v3/test_volume_backups.py | 12 +++++++++--- cinderclient/v3/volume_backups.py | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cinderclient/tests/unit/v3/test_volume_backups.py b/cinderclient/tests/unit/v3/test_volume_backups.py index 3cbbc72f5..52e843f89 100644 --- a/cinderclient/tests/unit/v3/test_volume_backups.py +++ b/cinderclient/tests/unit/v3/test_volume_backups.py @@ -13,19 +13,25 @@ # License for the specific language governing permissions and limitations # under the License. - from cinderclient.tests.unit import utils from cinderclient.tests.unit.v3 import fakes - -cs = fakes.FakeClient() +from cinderclient import api_versions +from cinderclient import exceptions as exc class VolumesTest(utils.TestCase): def test_update(self): + cs = fakes.FakeClient(api_version=api_versions.APIVersion('3.9')) b = cs.backups.get('1234') backup = b.update(name='new-name') cs.assert_called( 'PUT', '/backups/1234', {'backup': {'name': 'new-name'}}) self._assert_request_id(backup) + + def test_pre_version(self): + cs = fakes.FakeClient(api_version=api_versions.APIVersion('3.8')) + b = cs.backups.get('1234') + self.assertRaises(exc.VersionNotFoundForAPIMethod, + b.update, name='new-name') diff --git a/cinderclient/v3/volume_backups.py b/cinderclient/v3/volume_backups.py index 9a5aa5ca8..569878900 100644 --- a/cinderclient/v3/volume_backups.py +++ b/cinderclient/v3/volume_backups.py @@ -16,6 +16,7 @@ """ Volume Backups interface (v3 extension). """ +from cinderclient import api_versions from cinderclient import base from cinderclient.openstack.common.apiclient import base as common_base @@ -131,6 +132,7 @@ class VolumeBackupManager(base.ManagerWithFind): resp, body = self.api.client.post("/backups/import_record", body=body) return common_base.DictWithMeta(body['backup'], resp) + @api_versions.wraps("3.9") def update(self, backup, **kwargs): """Update the name or description for a backup.