Merge "Add keystone unified limits client"
This commit is contained in:
commit
fd51a46101
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
features:
|
||||
- |
|
||||
Add a new client for keystone's unified limits API to create and update limits.
|
|
@ -222,6 +222,8 @@ class Manager(clients.ServiceClients):
|
|||
self.identity_v3.ApplicationCredentialsClient(**params_v3)
|
||||
self.access_rules_client = \
|
||||
self.identity_v3.AccessRulesClient(**params_v3)
|
||||
self.identity_limits_client = \
|
||||
self.identity_v3.LimitsClient(**params_v3)
|
||||
|
||||
# Token clients do not use the catalog. They only need default_params.
|
||||
# They read auth_url, so they should only be set if the corresponding
|
||||
|
|
|
@ -32,6 +32,7 @@ from tempest.lib.services.identity.v3.groups_client import GroupsClient
|
|||
from tempest.lib.services.identity.v3.identity_client import IdentityClient
|
||||
from tempest.lib.services.identity.v3.inherited_roles_client import \
|
||||
InheritedRolesClient
|
||||
from tempest.lib.services.identity.v3.limits_client import LimitsClient
|
||||
from tempest.lib.services.identity.v3.oauth_consumers_client import \
|
||||
OAUTHConsumerClient
|
||||
from tempest.lib.services.identity.v3.oauth_token_client import \
|
||||
|
@ -55,7 +56,8 @@ __all__ = ['AccessRulesClient', 'ApplicationCredentialsClient',
|
|||
'DomainConfigurationClient', 'EndPointGroupsClient',
|
||||
'EndPointsClient', 'EndPointsFilterClient',
|
||||
'GroupsClient', 'IdentityClient', 'InheritedRolesClient',
|
||||
'OAUTHConsumerClient', 'OAUTHTokenClient', 'PoliciesClient',
|
||||
'ProjectsClient', 'ProjectTagsClient', 'RegionsClient',
|
||||
'RoleAssignmentsClient', 'RolesClient', 'ServicesClient',
|
||||
'V3TokenClient', 'TrustsClient', 'UsersClient', 'VersionsClient']
|
||||
'LimitsClient', 'OAUTHConsumerClient', 'OAUTHTokenClient',
|
||||
'PoliciesClient', 'ProjectsClient', 'ProjectTagsClient',
|
||||
'RegionsClient', 'RoleAssignmentsClient', 'RolesClient',
|
||||
'ServicesClient', 'V3TokenClient', 'TrustsClient', 'UsersClient',
|
||||
'VersionsClient']
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
# Copyright 2021 Red Hat, Inc.
|
||||
#
|
||||
# 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 oslo_serialization import jsonutils as json
|
||||
|
||||
from tempest.lib.common import rest_client
|
||||
|
||||
|
||||
class LimitsClient(rest_client.RestClient):
|
||||
api_version = "v3"
|
||||
|
||||
def get_registered_limits(self):
|
||||
"""Lists all registered limits."""
|
||||
resp, body = self.get('registered_limits')
|
||||
self.expected_success(200, resp.status)
|
||||
return rest_client.ResponseBody(resp, json.loads(body))
|
||||
|
||||
def create_limit(self, region_id, service_id, project_id, resource_name,
|
||||
default_limit, description=None, domain_id=None):
|
||||
"""Creates a limit in keystone."""
|
||||
limit = {
|
||||
'service_id': service_id,
|
||||
'project_id': project_id,
|
||||
'resource_name': resource_name,
|
||||
'resource_limit': default_limit,
|
||||
'region_id': region_id,
|
||||
'description': description or '%s limit for %s' % (
|
||||
resource_name, project_id),
|
||||
}
|
||||
if domain_id:
|
||||
limit['domain_id'] = domain_id
|
||||
post_body = json.dumps({'limits': [limit]})
|
||||
resp, body = self.post('limits', post_body)
|
||||
self.expected_success(201, resp.status)
|
||||
return rest_client.ResponseBody(resp, json.loads(body))
|
||||
|
||||
def update_limit(self, limit_id, resource_limit, description=None):
|
||||
"""Updates a limit in keystone by id."""
|
||||
|
||||
limit = {'resource_limit': resource_limit}
|
||||
if description:
|
||||
limit['description'] = description
|
||||
patch_body = json.dumps({'limit': limit})
|
||||
resp, body = self.patch('limits/%s' % limit_id, patch_body)
|
||||
self.expected_success(200, resp.status)
|
||||
return rest_client.ResponseBody(resp, json.loads(body))
|
|
@ -0,0 +1,82 @@
|
|||
# Copyright 2021 Red Hat, Inc.
|
||||
#
|
||||
# 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 tempest.lib.services.identity.v3 import limits_client
|
||||
from tempest.tests.lib import fake_auth_provider
|
||||
from tempest.tests.lib.services import base
|
||||
|
||||
|
||||
class TestLimitsClient(base.BaseServiceTest):
|
||||
def setUp(self):
|
||||
super(TestLimitsClient, self).setUp()
|
||||
self.client = limits_client.LimitsClient(
|
||||
fake_auth_provider.FakeAuthProvider(),
|
||||
'identity', 'regionOne')
|
||||
|
||||
def test_get_registered_limits(self):
|
||||
fake_result = {'foo': 'bar'}
|
||||
self.check_service_client_function(
|
||||
self.client.get_registered_limits,
|
||||
'tempest.lib.common.rest_client.RestClient.get',
|
||||
fake_result,
|
||||
False,
|
||||
status=200)
|
||||
|
||||
def test_create_limit(self):
|
||||
fake_result = {'foo': 'bar'}
|
||||
self.check_service_client_function(
|
||||
self.client.create_limit,
|
||||
'tempest.lib.common.rest_client.RestClient.post',
|
||||
fake_result,
|
||||
False,
|
||||
region_id='regionOne', service_id='image',
|
||||
project_id='project', resource_name='widgets',
|
||||
default_limit=10,
|
||||
description='Spacely Widgets',
|
||||
status=201)
|
||||
|
||||
def test_create_limit_with_domain(self):
|
||||
fake_result = {'foo': 'bar'}
|
||||
self.check_service_client_function(
|
||||
self.client.create_limit,
|
||||
'tempest.lib.common.rest_client.RestClient.post',
|
||||
fake_result,
|
||||
False,
|
||||
region_id='regionOne', service_id='image',
|
||||
project_id='project', resource_name='widgets',
|
||||
default_limit=10,
|
||||
domain_id='foo',
|
||||
description='Spacely Widgets',
|
||||
status=201)
|
||||
|
||||
def test_update_limit(self):
|
||||
fake_result = {'foo': 'bar'}
|
||||
self.check_service_client_function(
|
||||
self.client.update_limit,
|
||||
'tempest.lib.common.rest_client.RestClient.patch',
|
||||
fake_result,
|
||||
False,
|
||||
limit_id='123', resource_limit=20,
|
||||
status=200)
|
||||
|
||||
def test_update_limit_with_description(self):
|
||||
fake_result = {'foo': 'bar'}
|
||||
self.check_service_client_function(
|
||||
self.client.update_limit,
|
||||
'tempest.lib.common.rest_client.RestClient.patch',
|
||||
fake_result,
|
||||
False,
|
||||
limit_id='123', resource_limit=20,
|
||||
description='new description',
|
||||
status=200)
|
Loading…
Reference in New Issue