[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:
Andrey Kurilin 2015-09-04 16:02:56 +03:00
parent eaf1e56b21
commit 6fc3a943e6
5 changed files with 66 additions and 18 deletions

View 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)

View File

@ -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',

View File

@ -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'

View File

@ -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 '

View File

@ -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: