diff --git a/novaclient/tests/functional/test_quotas.py b/novaclient/tests/functional/test_quotas.py new file mode 100644 index 000000000..3b75ed5f6 --- /dev/null +++ b/novaclient/tests/functional/test_quotas.py @@ -0,0 +1,59 @@ +# 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 novaclient.tests.functional import base + + +class TestQuotasNovaClient(base.ClientTestBase): + """Nova quotas functional tests. + """ + + _quota_resources = ['instances', 'cores', 'ram', + 'floating_ips', 'fixed_ips', 'metadata_items', + 'injected_files', 'injected_file_content_bytes', + 'injected_file_path_bytes', 'key_pairs', + 'security_groups', 'security_group_rules', + 'server_groups', 'server_group_members'] + + def test_quotas_update(self): + # `nova quota-update` requires tenant-id. EXAMPLE of keystone output: + # +-------------+----------------------------------+ + # | Property | Value | + # +-------------+----------------------------------+ + # | description | | + # | enabled | True | + # | id | 582df899eabc47018c96713c2f7196ba | + # | name | admin | + # +-------------+----------------------------------+ + tenant_info = self.cli_clients.keystone( + "tenant-get", params=self.cli_clients.tenant_name).split("\n") + tenant_id = [l.rsplit("|", 2)[-2].strip() + for l in tenant_info if "id" in l][0] + + self.addCleanup(self.client.quotas.delete, tenant_id) + + original_quotas = self.client.quotas.get(tenant_id) + + difference = 10 + params = [tenant_id] + for quota_name in self._quota_resources: + params.append("--%(name)s %(value)s" % { + "name": quota_name.replace("_", "-"), + "value": getattr(original_quotas, quota_name) + difference}) + + self.nova("quota-update", params=" ".join(params)) + + updated_quotas = self.client.quotas.get(tenant_id) + + for quota_name in self._quota_resources: + self.assertEqual(getattr(original_quotas, quota_name), + getattr(updated_quotas, quota_name) - difference) diff --git a/novaclient/tests/unit/v2/fakes.py b/novaclient/tests/unit/v2/fakes.py index 6814461d1..e50cddd0f 100644 --- a/novaclient/tests/unit/v2/fakes.py +++ b/novaclient/tests/unit/v2/fakes.py @@ -1259,8 +1259,7 @@ class FakeHTTPClient(base_client.HTTPClient): def put_os_quota_sets_97f4c221bff44578b0300df4ef119353(self, body, **kw): assert list(body) == ['quota_set'] - fakes.assert_has_keys(body['quota_set'], - required=['tenant_id']) + fakes.assert_has_keys(body['quota_set']) return (200, {}, { 'quota_set': { 'tenant_id': '97f4c221bff44578b0300df4ef119353', diff --git a/novaclient/tests/unit/v2/test_quotas.py b/novaclient/tests/unit/v2/test_quotas.py index 43f8ce1d8..76bfcfe8e 100644 --- a/novaclient/tests/unit/v2/test_quotas.py +++ b/novaclient/tests/unit/v2/test_quotas.py @@ -45,9 +45,7 @@ class QuotaSetsTest(utils.FixturedTestCase): q.update(cores=2, force=True) self.assert_called( 'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353', - {'quota_set': {'force': True, - 'cores': 2, - 'tenant_id': '97f4c221bff44578b0300df4ef119353'}}) + {'quota_set': {'force': True, 'cores': 2}}) def test_quotas_delete(self): tenant_id = 'test' diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py index 603e59ec1..9a2ae0c70 100644 --- a/novaclient/tests/unit/v2/test_shell.py +++ b/novaclient/tests/unit/v2/test_shell.py @@ -1835,8 +1835,7 @@ class ShellTest(utils.TestCase): self.assert_called( 'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353', - {'quota_set': {'instances': 5, - 'tenant_id': '97f4c221bff44578b0300df4ef119353'}}) + {'quota_set': {'instances': 5}}) def test_user_quota_update(self): self.run_command( @@ -1846,8 +1845,7 @@ class ShellTest(utils.TestCase): self.assert_called( 'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353?user_id=u1', - {'quota_set': {'instances': 5, - 'tenant_id': '97f4c221bff44578b0300df4ef119353'}}) + {'quota_set': {'instances': 5}}) def test_quota_force_update(self): self.run_command( @@ -1856,8 +1854,7 @@ class ShellTest(utils.TestCase): self.assert_called( 'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353', {'quota_set': {'force': True, - 'instances': 5, - 'tenant_id': '97f4c221bff44578b0300df4ef119353'}}) + 'instances': 5}}) def test_quota_update_fixed_ip(self): self.run_command( @@ -1865,8 +1862,7 @@ class ShellTest(utils.TestCase): ' --fixed-ips=5') self.assert_called( 'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353', - {'quota_set': {'fixed_ips': 5, - 'tenant_id': '97f4c221bff44578b0300df4ef119353'}}) + {'quota_set': {'fixed_ips': 5}}) def test_quota_delete(self): self.run_command('quota-delete --tenant ' diff --git a/novaclient/v2/quotas.py b/novaclient/v2/quotas.py index cd16042b4..a77e16e27 100644 --- a/novaclient/v2/quotas.py +++ b/novaclient/v2/quotas.py @@ -41,14 +41,10 @@ class QuotaSetManager(base.Manager): url = '/os-quota-sets/%s' % tenant_id return self._get(url, "quota_set") - def _update_body(self, tenant_id, **kwargs): - kwargs['tenant_id'] = tenant_id - return {'quota_set': kwargs} - def update(self, tenant_id, **kwargs): user_id = kwargs.pop('user_id', None) - body = self._update_body(tenant_id, **kwargs) + body = {'quota_set': kwargs} for key in list(body['quota_set']): if body['quota_set'][key] is None: