[Bug-Fix] Update requests body for quota-update
Update quotas API call doesn't accept parameter "tenant-id". Change-Id: I1cbc6088c5deeb32e4e98ef1ced5f83ce71fe3ab Closes-Bug: #1492242
This commit is contained in:
parent
eaf1e56b21
commit
6fc3a943e6
59
novaclient/tests/functional/test_quotas.py
Normal file
59
novaclient/tests/functional/test_quotas.py
Normal file
@ -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)
|
@ -1259,8 +1259,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
|||||||
|
|
||||||
def put_os_quota_sets_97f4c221bff44578b0300df4ef119353(self, body, **kw):
|
def put_os_quota_sets_97f4c221bff44578b0300df4ef119353(self, body, **kw):
|
||||||
assert list(body) == ['quota_set']
|
assert list(body) == ['quota_set']
|
||||||
fakes.assert_has_keys(body['quota_set'],
|
fakes.assert_has_keys(body['quota_set'])
|
||||||
required=['tenant_id'])
|
|
||||||
return (200, {}, {
|
return (200, {}, {
|
||||||
'quota_set': {
|
'quota_set': {
|
||||||
'tenant_id': '97f4c221bff44578b0300df4ef119353',
|
'tenant_id': '97f4c221bff44578b0300df4ef119353',
|
||||||
|
@ -45,9 +45,7 @@ class QuotaSetsTest(utils.FixturedTestCase):
|
|||||||
q.update(cores=2, force=True)
|
q.update(cores=2, force=True)
|
||||||
self.assert_called(
|
self.assert_called(
|
||||||
'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353',
|
'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353',
|
||||||
{'quota_set': {'force': True,
|
{'quota_set': {'force': True, 'cores': 2}})
|
||||||
'cores': 2,
|
|
||||||
'tenant_id': '97f4c221bff44578b0300df4ef119353'}})
|
|
||||||
|
|
||||||
def test_quotas_delete(self):
|
def test_quotas_delete(self):
|
||||||
tenant_id = 'test'
|
tenant_id = 'test'
|
||||||
|
@ -1835,8 +1835,7 @@ class ShellTest(utils.TestCase):
|
|||||||
self.assert_called(
|
self.assert_called(
|
||||||
'PUT',
|
'PUT',
|
||||||
'/os-quota-sets/97f4c221bff44578b0300df4ef119353',
|
'/os-quota-sets/97f4c221bff44578b0300df4ef119353',
|
||||||
{'quota_set': {'instances': 5,
|
{'quota_set': {'instances': 5}})
|
||||||
'tenant_id': '97f4c221bff44578b0300df4ef119353'}})
|
|
||||||
|
|
||||||
def test_user_quota_update(self):
|
def test_user_quota_update(self):
|
||||||
self.run_command(
|
self.run_command(
|
||||||
@ -1846,8 +1845,7 @@ class ShellTest(utils.TestCase):
|
|||||||
self.assert_called(
|
self.assert_called(
|
||||||
'PUT',
|
'PUT',
|
||||||
'/os-quota-sets/97f4c221bff44578b0300df4ef119353?user_id=u1',
|
'/os-quota-sets/97f4c221bff44578b0300df4ef119353?user_id=u1',
|
||||||
{'quota_set': {'instances': 5,
|
{'quota_set': {'instances': 5}})
|
||||||
'tenant_id': '97f4c221bff44578b0300df4ef119353'}})
|
|
||||||
|
|
||||||
def test_quota_force_update(self):
|
def test_quota_force_update(self):
|
||||||
self.run_command(
|
self.run_command(
|
||||||
@ -1856,8 +1854,7 @@ class ShellTest(utils.TestCase):
|
|||||||
self.assert_called(
|
self.assert_called(
|
||||||
'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353',
|
'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353',
|
||||||
{'quota_set': {'force': True,
|
{'quota_set': {'force': True,
|
||||||
'instances': 5,
|
'instances': 5}})
|
||||||
'tenant_id': '97f4c221bff44578b0300df4ef119353'}})
|
|
||||||
|
|
||||||
def test_quota_update_fixed_ip(self):
|
def test_quota_update_fixed_ip(self):
|
||||||
self.run_command(
|
self.run_command(
|
||||||
@ -1865,8 +1862,7 @@ class ShellTest(utils.TestCase):
|
|||||||
' --fixed-ips=5')
|
' --fixed-ips=5')
|
||||||
self.assert_called(
|
self.assert_called(
|
||||||
'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353',
|
'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353',
|
||||||
{'quota_set': {'fixed_ips': 5,
|
{'quota_set': {'fixed_ips': 5}})
|
||||||
'tenant_id': '97f4c221bff44578b0300df4ef119353'}})
|
|
||||||
|
|
||||||
def test_quota_delete(self):
|
def test_quota_delete(self):
|
||||||
self.run_command('quota-delete --tenant '
|
self.run_command('quota-delete --tenant '
|
||||||
|
@ -41,14 +41,10 @@ class QuotaSetManager(base.Manager):
|
|||||||
url = '/os-quota-sets/%s' % tenant_id
|
url = '/os-quota-sets/%s' % tenant_id
|
||||||
return self._get(url, "quota_set")
|
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):
|
def update(self, tenant_id, **kwargs):
|
||||||
|
|
||||||
user_id = kwargs.pop('user_id', None)
|
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']):
|
for key in list(body['quota_set']):
|
||||||
if body['quota_set'][key] is None:
|
if body['quota_set'][key] is None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user