diff --git a/novaclient/tests/v1_1/test_quotas.py b/novaclient/tests/v1_1/test_quotas.py index b545e6b18..1c679389e 100644 --- a/novaclient/tests/v1_1/test_quotas.py +++ b/novaclient/tests/v1_1/test_quotas.py @@ -16,54 +16,58 @@ from novaclient.tests import utils from novaclient.tests.v1_1 import fakes -cs = fakes.FakeClient() - class QuotaSetsTest(utils.TestCase): + def setUp(self): + super(QuotaSetsTest, self).setUp() + self.cs = self._get_fake_client() + + def _get_fake_client(self): + return fakes.FakeClient() def test_tenant_quotas_get(self): tenant_id = 'test' - cs.quotas.get(tenant_id) - cs.assert_called('GET', '/os-quota-sets/%s' % tenant_id) + self.cs.quotas.get(tenant_id) + self.cs.assert_called('GET', '/os-quota-sets/%s' % tenant_id) def test_user_quotas_get(self): tenant_id = 'test' user_id = 'fake_user' - cs.quotas.get(tenant_id, user_id=user_id) + self.cs.quotas.get(tenant_id, user_id=user_id) url = '/os-quota-sets/%s?user_id=%s' % (tenant_id, user_id) - cs.assert_called('GET', url) + self.cs.assert_called('GET', url) def test_tenant_quotas_defaults(self): tenant_id = '97f4c221bff44578b0300df4ef119353' - cs.quotas.defaults(tenant_id) - cs.assert_called('GET', '/os-quota-sets/%s/defaults' % tenant_id) + self.cs.quotas.defaults(tenant_id) + self.cs.assert_called('GET', '/os-quota-sets/%s/defaults' % tenant_id) def test_update_quota(self): - q = cs.quotas.get('97f4c221bff44578b0300df4ef119353') + q = self.cs.quotas.get('97f4c221bff44578b0300df4ef119353') q.update(volumes=2) - cs.assert_called('PUT', + self.cs.assert_called('PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353') def test_update_user_quota(self): tenant_id = '97f4c221bff44578b0300df4ef119353' user_id = 'fake_user' - q = cs.quotas.get(tenant_id) + q = self.cs.quotas.get(tenant_id) q.update(volumes=2, user_id=user_id) url = '/os-quota-sets/%s?user_id=%s' % (tenant_id, user_id) - cs.assert_called('PUT', url) + self.cs.assert_called('PUT', url) def test_force_update_quota(self): - q = cs.quotas.get('97f4c221bff44578b0300df4ef119353') + q = self.cs.quotas.get('97f4c221bff44578b0300df4ef119353') q.update(cores=2, force=True) - cs.assert_called( + self.cs.assert_called( 'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353', {'quota_set': {'force': True, 'cores': 2, 'tenant_id': '97f4c221bff44578b0300df4ef119353'}}) def test_refresh_quota(self): - q = cs.quotas.get('test') - q2 = cs.quotas.get('test') + q = self.cs.quotas.get('test') + q2 = self.cs.quotas.get('test') self.assertEqual(q.volumes, q2.volumes) q2.volumes = 0 self.assertNotEqual(q.volumes, q2.volumes) @@ -72,12 +76,12 @@ class QuotaSetsTest(utils.TestCase): def test_quotas_delete(self): tenant_id = 'test' - cs.quotas.delete(tenant_id) - cs.assert_called('DELETE', '/os-quota-sets/%s' % tenant_id) + self.cs.quotas.delete(tenant_id) + self.cs.assert_called('DELETE', '/os-quota-sets/%s' % tenant_id) def test_user_quotas_delete(self): tenant_id = 'test' user_id = 'fake_user' - cs.quotas.delete(tenant_id, user_id=user_id) + self.cs.quotas.delete(tenant_id, user_id=user_id) url = '/os-quota-sets/%s?user_id=%s' % (tenant_id, user_id) - cs.assert_called('DELETE', url) + self.cs.assert_called('DELETE', url) diff --git a/novaclient/tests/v3/fakes.py b/novaclient/tests/v3/fakes.py index e1f5dbb2c..f856ce406 100644 --- a/novaclient/tests/v3/fakes.py +++ b/novaclient/tests/v3/fakes.py @@ -271,3 +271,24 @@ class FakeHTTPClient(fakes_v1_1.FakeHTTPClient): {"zone_name": "zone-2", "zone_state": {"available": False}, "hosts": None}]}) + + # + # Quotas + # + def put_os_quota_sets_97f4c221bff44578b0300df4ef119353(self, body, **kw): + assert list(body) == ['quota_set'] + return (200, {}, {'quota_set': { + 'tenant_id': '97f4c221bff44578b0300df4ef119353', + 'metadata_items': [], + 'injected_file_content_bytes': 1, + 'injected_file_path_bytes': 1, + 'volumes': 2, + 'gigabytes': 1, + 'ram': 1, + 'floating_ips': 1, + 'instances': 1, + 'injected_files': 1, + 'cores': 1, + 'keypairs': 1, + 'security_groups': 1, + 'security_group_rules': 1}}) diff --git a/novaclient/tests/v3/test_quotas.py b/novaclient/tests/v3/test_quotas.py new file mode 100644 index 000000000..0f361a49f --- /dev/null +++ b/novaclient/tests/v3/test_quotas.py @@ -0,0 +1,33 @@ +# Copyright IBM Corp. 2013 +# +# 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.v1_1 import test_quotas +from novaclient.tests.v3 import fakes + + +class QuotaSetsTest(test_quotas.QuotaSetsTest): + def setUp(self): + super(QuotaSetsTest, self).setUp() + self.cs = self._get_fake_client() + + def _get_fake_client(self): + return fakes.FakeClient() + + def test_force_update_quota(self): + q = self.cs.quotas.get('97f4c221bff44578b0300df4ef119353') + q.update(cores=2, force=True) + self.cs.assert_called( + 'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353', + {'quota_set': {'force': True, + 'cores': 2}}) diff --git a/novaclient/v1_1/quotas.py b/novaclient/v1_1/quotas.py index 601bcebe9..cd16042b4 100644 --- a/novaclient/v1_1/quotas.py +++ b/novaclient/v1_1/quotas.py @@ -41,31 +41,14 @@ class QuotaSetManager(base.Manager): url = '/os-quota-sets/%s' % tenant_id return self._get(url, "quota_set") - def update(self, tenant_id, metadata_items=None, - injected_file_content_bytes=None, injected_file_path_bytes=None, - volumes=None, gigabytes=None, - ram=None, floating_ips=None, fixed_ips=None, instances=None, - injected_files=None, cores=None, key_pairs=None, - security_groups=None, security_group_rules=None, force=None, - user_id=None): + def _update_body(self, tenant_id, **kwargs): + kwargs['tenant_id'] = tenant_id + return {'quota_set': kwargs} - body = {'quota_set': { - 'tenant_id': tenant_id, - 'metadata_items': metadata_items, - 'key_pairs': key_pairs, - 'injected_file_content_bytes': injected_file_content_bytes, - 'injected_file_path_bytes': injected_file_path_bytes, - 'volumes': volumes, - 'gigabytes': gigabytes, - 'ram': ram, - 'floating_ips': floating_ips, - 'fixed_ips': fixed_ips, - 'instances': instances, - 'injected_files': injected_files, - 'cores': cores, - 'security_groups': security_groups, - 'security_group_rules': security_group_rules, - 'force': force}} + def update(self, tenant_id, **kwargs): + + user_id = kwargs.pop('user_id', None) + body = self._update_body(tenant_id, **kwargs) for key in list(body['quota_set']): if body['quota_set'][key] is None: diff --git a/novaclient/v3/client.py b/novaclient/v3/client.py index 8bfb2bb09..f20a8a18e 100644 --- a/novaclient/v3/client.py +++ b/novaclient/v3/client.py @@ -21,6 +21,7 @@ from novaclient.v3 import flavor_access from novaclient.v3 import flavors from novaclient.v3 import hosts from novaclient.v3 import images +from novaclient.v3 import quotas from novaclient.v3 import servers @@ -63,6 +64,7 @@ class Client(object): self.flavors = flavors.FlavorManager(self) self.flavor_access = flavor_access.FlavorAccessManager(self) self.images = images.ImageManager(self) + self.quotas = quotas.QuotaSetManager(self) self.servers = servers.ServerManager(self) # Add in any extensions... diff --git a/novaclient/v3/quotas.py b/novaclient/v3/quotas.py new file mode 100644 index 000000000..19723fafa --- /dev/null +++ b/novaclient/v3/quotas.py @@ -0,0 +1,27 @@ +# Copyright 2011 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 novaclient.v1_1 import quotas + + +class QuotaSet(quotas.QuotaSet): + pass + + +class QuotaSetManager(quotas.QuotaSetManager): + resource_class = QuotaSet + + def _update_body(self, tenant_id, **kwargs): + return {'quota_set': kwargs} diff --git a/novaclient/v3/shell.py b/novaclient/v3/shell.py index 8638224dc..bca8110a0 100644 --- a/novaclient/v3/shell.py +++ b/novaclient/v3/shell.py @@ -32,7 +32,6 @@ from novaclient.openstack.common import strutils from novaclient.openstack.common import timeutils from novaclient.openstack.common import uuidutils from novaclient import utils -from novaclient.v1_1 import quotas from novaclient.v3 import availability_zones from novaclient.v3 import servers @@ -2829,10 +2828,7 @@ def do_ssh(cs, args): _quota_resources = ['instances', 'cores', 'ram', 'volumes', 'gigabytes', - 'floating_ips', 'fixed_ips', 'metadata_items', - 'injected_files', 'key_pairs', - 'injected_file_content_bytes', 'injected_file_path_bytes', - 'security_groups', 'security_group_rules'] + 'fixed_ips', 'metadata_items', 'key_pairs'] def _quota_show(quotas): @@ -2855,11 +2851,7 @@ def _quota_update(manager, identifier, args): if updates: # default value of force is None to make sure this client # will be compatibile with old nova server - force_update = getattr(args, 'force', None) - if isinstance(manager, quotas.QuotaSetManager): - manager.update(identifier, force=force_update, **updates) - else: - manager.update(identifier, **updates) + manager.update(identifier, **updates) @utils.arg('--tenant', @@ -2911,14 +2903,6 @@ def do_quota_defaults(cs, args): metavar='', type=int, default=None, help='New value for the "gigabytes" quota.') -@utils.arg('--floating-ips', - metavar='', - type=int, - default=None, - help='New value for the "floating-ips" quota.') -@utils.arg('--floating_ips', - type=int, - help=argparse.SUPPRESS) @utils.arg('--fixed-ips', metavar='', type=int, @@ -2932,42 +2916,11 @@ def do_quota_defaults(cs, args): @utils.arg('--metadata_items', type=int, help=argparse.SUPPRESS) -@utils.arg('--injected-files', - metavar='', - type=int, - default=None, - help='New value for the "injected-files" quota.') -@utils.arg('--injected_files', - type=int, - help=argparse.SUPPRESS) -@utils.arg('--injected-file-content-bytes', - metavar='', - type=int, - default=None, - help='New value for the "injected-file-content-bytes" quota.') -@utils.arg('--injected_file_content_bytes', - type=int, - help=argparse.SUPPRESS) -@utils.arg('--injected-file-path-bytes', - metavar='', - type=int, - default=None, - help='New value for the "injected-file-path-bytes" quota.') @utils.arg('--key-pairs', metavar='', type=int, default=None, help='New value for the "key-pairs" quota.') -@utils.arg('--security-groups', - metavar='', - type=int, - default=None, - help='New value for the "security-groups" quota.') -@utils.arg('--security-group-rules', - metavar='', - type=int, - default=None, - help='New value for the "security-group-rules" quota.') @utils.arg('--force', dest='force', action="store_true",