From c6ca3cf7cb749806debad1e3015e004850fdfd2a Mon Sep 17 00:00:00 2001 From: wangxiyuan Date: Mon, 17 Jul 2017 09:21:32 +0800 Subject: [PATCH] Support skip-validation for quota update Support skip-validation parameter for quota update. Change-Id: Iec4f1598987c632f45ad6eee751f78bedbf3ec26 --- cinderclient/shell_utils.py | 3 +++ cinderclient/tests/unit/v3/test_quotas.py | 29 +++++++++++++++++++++++ cinderclient/v3/quotas.py | 20 +++++++++++++++- cinderclient/v3/shell.py | 4 ++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 cinderclient/tests/unit/v3/test_quotas.py diff --git a/cinderclient/shell_utils.py b/cinderclient/shell_utils.py index 35802f85b..606bfd053 100644 --- a/cinderclient/shell_utils.py +++ b/cinderclient/shell_utils.py @@ -237,6 +237,9 @@ def quota_update(manager, identifier, args): updates[resource] = val if updates: + skip_validation = getattr(args, 'skip_validation', True) + if not skip_validation: + updates['skip_validation'] = skip_validation quota_show(manager.update(identifier, **updates)) diff --git a/cinderclient/tests/unit/v3/test_quotas.py b/cinderclient/tests/unit/v3/test_quotas.py new file mode 100644 index 000000000..fbabb47f7 --- /dev/null +++ b/cinderclient/tests/unit/v3/test_quotas.py @@ -0,0 +1,29 @@ +# Copyright (c) 2017 OpenStack Foundation +# 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 cinderclient.tests.unit import utils +from cinderclient.tests.unit.v3 import fakes + + +cs = fakes.FakeClient() + + +class QuotaSetsTest(utils.TestCase): + + def test_update_quota_with_skip_(self): + q = cs.quotas.get('test') + q.update(skip_validation=False) + cs.assert_called('PUT', '/os-quota-sets/test?skip_validation=False') + self._assert_request_id(q) diff --git a/cinderclient/v3/quotas.py b/cinderclient/v3/quotas.py index cfa0af506..63dfba835 100644 --- a/cinderclient/v3/quotas.py +++ b/cinderclient/v3/quotas.py @@ -13,4 +13,22 @@ # License for the specific language governing permissions and limitations # under the License. -from cinderclient.v2.quotas import * # flake8: noqa +from cinderclient.v2 import quotas + + +class QuotaSetManager(quotas.QuotaSetManager): + + def update(self, tenant_id, **updates): + skip_validation = updates.pop('skip_validation', True) + + body = {'quota_set': {'tenant_id': tenant_id}} + for update in updates: + body['quota_set'][update] = updates[update] + + request_url = '/os-quota-sets/%s' % tenant_id + if not skip_validation: + request_url += '?skip_validation=False' + + result = self._update(request_url, body) + return self.resource_class(self, result['quota_set'], loaded=True, + resp=result.request_ids) diff --git a/cinderclient/v3/shell.py b/cinderclient/v3/shell.py index 94aecb1a9..727fdac43 100644 --- a/cinderclient/v3/shell.py +++ b/cinderclient/v3/shell.py @@ -756,6 +756,10 @@ def do_group_type_key(cs, args): metavar='', type=int, default=None, help='Set max volume size limit. Default=None.') +@utils.arg('--skip-validation', + metavar='', + default=False, + help='Skip validate the existing resource quota. Default=False.') def do_quota_update(cs, args): """Updates quotas for a tenant."""