Make identity v2 tenants_client use **kwargs
As we discussed on http://lists.openstack.org/pipermail/openstack-dev/2015-July/068864.html All http POST/PUT methods need to contain **kwargs as their arguments. This patch makes identity v2 tenant_client use **kwargs. Partially implements blueprint consistent-service-method-names Change-Id: I3fe7b6b7f81a0b20888b2c70a717065e4b43674f
This commit is contained in:
parent
e1c6c1c54e
commit
7668fad3d9
@ -43,7 +43,7 @@ class TenantsNegativeTestJSON(base.BaseIdentityV2AdminTest):
|
|||||||
def test_tenant_delete_by_unauthorized_user(self):
|
def test_tenant_delete_by_unauthorized_user(self):
|
||||||
# Non-administrator user should not be able to delete a tenant
|
# Non-administrator user should not be able to delete a tenant
|
||||||
tenant_name = data_utils.rand_name(name='tenant')
|
tenant_name = data_utils.rand_name(name='tenant')
|
||||||
tenant = self.tenants_client.create_tenant(tenant_name)['tenant']
|
tenant = self.tenants_client.create_tenant(name=tenant_name)['tenant']
|
||||||
self.data.tenants.append(tenant)
|
self.data.tenants.append(tenant)
|
||||||
self.assertRaises(lib_exc.Forbidden,
|
self.assertRaises(lib_exc.Forbidden,
|
||||||
self.non_admin_tenants_client.delete_tenant,
|
self.non_admin_tenants_client.delete_tenant,
|
||||||
@ -54,7 +54,7 @@ class TenantsNegativeTestJSON(base.BaseIdentityV2AdminTest):
|
|||||||
def test_tenant_delete_request_without_token(self):
|
def test_tenant_delete_request_without_token(self):
|
||||||
# Request to delete a tenant without a valid token should fail
|
# Request to delete a tenant without a valid token should fail
|
||||||
tenant_name = data_utils.rand_name(name='tenant')
|
tenant_name = data_utils.rand_name(name='tenant')
|
||||||
tenant = self.tenants_client.create_tenant(tenant_name)['tenant']
|
tenant = self.tenants_client.create_tenant(name=tenant_name)['tenant']
|
||||||
self.data.tenants.append(tenant)
|
self.data.tenants.append(tenant)
|
||||||
token = self.client.auth_provider.get_token()
|
token = self.client.auth_provider.get_token()
|
||||||
self.client.delete_token(token)
|
self.client.delete_token(token)
|
||||||
@ -75,7 +75,7 @@ class TenantsNegativeTestJSON(base.BaseIdentityV2AdminTest):
|
|||||||
def test_tenant_create_duplicate(self):
|
def test_tenant_create_duplicate(self):
|
||||||
# Tenant names should be unique
|
# Tenant names should be unique
|
||||||
tenant_name = data_utils.rand_name(name='tenant')
|
tenant_name = data_utils.rand_name(name='tenant')
|
||||||
body = self.tenants_client.create_tenant(tenant_name)['tenant']
|
body = self.tenants_client.create_tenant(name=tenant_name)['tenant']
|
||||||
tenant = body
|
tenant = body
|
||||||
self.data.tenants.append(tenant)
|
self.data.tenants.append(tenant)
|
||||||
tenant1_id = body.get('id')
|
tenant1_id = body.get('id')
|
||||||
@ -83,7 +83,7 @@ class TenantsNegativeTestJSON(base.BaseIdentityV2AdminTest):
|
|||||||
self.addCleanup(self.tenants_client.delete_tenant, tenant1_id)
|
self.addCleanup(self.tenants_client.delete_tenant, tenant1_id)
|
||||||
self.addCleanup(self.data.tenants.remove, tenant)
|
self.addCleanup(self.data.tenants.remove, tenant)
|
||||||
self.assertRaises(lib_exc.Conflict, self.tenants_client.create_tenant,
|
self.assertRaises(lib_exc.Conflict, self.tenants_client.create_tenant,
|
||||||
tenant_name)
|
name=tenant_name)
|
||||||
|
|
||||||
@test.attr(type=['negative'])
|
@test.attr(type=['negative'])
|
||||||
@test.idempotent_id('d26b278a-6389-4702-8d6e-5980d80137e0')
|
@test.idempotent_id('d26b278a-6389-4702-8d6e-5980d80137e0')
|
||||||
@ -92,7 +92,7 @@ class TenantsNegativeTestJSON(base.BaseIdentityV2AdminTest):
|
|||||||
tenant_name = data_utils.rand_name(name='tenant')
|
tenant_name = data_utils.rand_name(name='tenant')
|
||||||
self.assertRaises(lib_exc.Forbidden,
|
self.assertRaises(lib_exc.Forbidden,
|
||||||
self.non_admin_tenants_client.create_tenant,
|
self.non_admin_tenants_client.create_tenant,
|
||||||
tenant_name)
|
name=tenant_name)
|
||||||
|
|
||||||
@test.attr(type=['negative'])
|
@test.attr(type=['negative'])
|
||||||
@test.idempotent_id('a3ee9d7e-6920-4dd5-9321-d4b2b7f0a638')
|
@test.idempotent_id('a3ee9d7e-6920-4dd5-9321-d4b2b7f0a638')
|
||||||
@ -103,7 +103,7 @@ class TenantsNegativeTestJSON(base.BaseIdentityV2AdminTest):
|
|||||||
self.client.delete_token(token)
|
self.client.delete_token(token)
|
||||||
self.assertRaises(lib_exc.Unauthorized,
|
self.assertRaises(lib_exc.Unauthorized,
|
||||||
self.tenants_client.create_tenant,
|
self.tenants_client.create_tenant,
|
||||||
tenant_name)
|
name=tenant_name)
|
||||||
self.client.auth_provider.clear_auth()
|
self.client.auth_provider.clear_auth()
|
||||||
|
|
||||||
@test.attr(type=['negative'])
|
@test.attr(type=['negative'])
|
||||||
@ -121,7 +121,7 @@ class TenantsNegativeTestJSON(base.BaseIdentityV2AdminTest):
|
|||||||
tenant_name = 'a' * 65
|
tenant_name = 'a' * 65
|
||||||
self.assertRaises(lib_exc.BadRequest,
|
self.assertRaises(lib_exc.BadRequest,
|
||||||
self.tenants_client.create_tenant,
|
self.tenants_client.create_tenant,
|
||||||
tenant_name)
|
name=tenant_name)
|
||||||
|
|
||||||
@test.attr(type=['negative'])
|
@test.attr(type=['negative'])
|
||||||
@test.idempotent_id('bd20dc2a-9557-4db7-b755-f48d952ad706')
|
@test.idempotent_id('bd20dc2a-9557-4db7-b755-f48d952ad706')
|
||||||
@ -135,7 +135,7 @@ class TenantsNegativeTestJSON(base.BaseIdentityV2AdminTest):
|
|||||||
def test_tenant_update_by_unauthorized_user(self):
|
def test_tenant_update_by_unauthorized_user(self):
|
||||||
# Non-administrator user should not be able to update a tenant
|
# Non-administrator user should not be able to update a tenant
|
||||||
tenant_name = data_utils.rand_name(name='tenant')
|
tenant_name = data_utils.rand_name(name='tenant')
|
||||||
tenant = self.tenants_client.create_tenant(tenant_name)['tenant']
|
tenant = self.tenants_client.create_tenant(name=tenant_name)['tenant']
|
||||||
self.data.tenants.append(tenant)
|
self.data.tenants.append(tenant)
|
||||||
self.assertRaises(lib_exc.Forbidden,
|
self.assertRaises(lib_exc.Forbidden,
|
||||||
self.non_admin_tenants_client.update_tenant,
|
self.non_admin_tenants_client.update_tenant,
|
||||||
@ -146,7 +146,7 @@ class TenantsNegativeTestJSON(base.BaseIdentityV2AdminTest):
|
|||||||
def test_tenant_update_request_without_token(self):
|
def test_tenant_update_request_without_token(self):
|
||||||
# Request to update a tenant without a valid token should fail
|
# Request to update a tenant without a valid token should fail
|
||||||
tenant_name = data_utils.rand_name(name='tenant')
|
tenant_name = data_utils.rand_name(name='tenant')
|
||||||
tenant = self.tenants_client.create_tenant(tenant_name)['tenant']
|
tenant = self.tenants_client.create_tenant(name=tenant_name)['tenant']
|
||||||
self.data.tenants.append(tenant)
|
self.data.tenants.append(tenant)
|
||||||
token = self.client.auth_provider.get_token()
|
token = self.client.auth_provider.get_token()
|
||||||
self.client.delete_token(token)
|
self.client.delete_token(token)
|
||||||
|
@ -28,7 +28,8 @@ class TenantsTestJSON(base.BaseIdentityV2AdminTest):
|
|||||||
tenants = []
|
tenants = []
|
||||||
for _ in moves.xrange(3):
|
for _ in moves.xrange(3):
|
||||||
tenant_name = data_utils.rand_name(name='tenant-new')
|
tenant_name = data_utils.rand_name(name='tenant-new')
|
||||||
tenant = self.tenants_client.create_tenant(tenant_name)['tenant']
|
tenant = self.tenants_client.create_tenant(
|
||||||
|
name=tenant_name)['tenant']
|
||||||
self.data.tenants.append(tenant)
|
self.data.tenants.append(tenant)
|
||||||
tenants.append(tenant)
|
tenants.append(tenant)
|
||||||
tenant_ids = map(lambda x: x['id'], tenants)
|
tenant_ids = map(lambda x: x['id'], tenants)
|
||||||
@ -49,7 +50,7 @@ class TenantsTestJSON(base.BaseIdentityV2AdminTest):
|
|||||||
# Create tenant with a description
|
# Create tenant with a description
|
||||||
tenant_name = data_utils.rand_name(name='tenant')
|
tenant_name = data_utils.rand_name(name='tenant')
|
||||||
tenant_desc = data_utils.rand_name(name='desc')
|
tenant_desc = data_utils.rand_name(name='desc')
|
||||||
body = self.tenants_client.create_tenant(tenant_name,
|
body = self.tenants_client.create_tenant(name=tenant_name,
|
||||||
description=tenant_desc)
|
description=tenant_desc)
|
||||||
tenant = body['tenant']
|
tenant = body['tenant']
|
||||||
self.data.tenants.append(tenant)
|
self.data.tenants.append(tenant)
|
||||||
@ -68,7 +69,8 @@ class TenantsTestJSON(base.BaseIdentityV2AdminTest):
|
|||||||
def test_tenant_create_enabled(self):
|
def test_tenant_create_enabled(self):
|
||||||
# Create a tenant that is enabled
|
# Create a tenant that is enabled
|
||||||
tenant_name = data_utils.rand_name(name='tenant')
|
tenant_name = data_utils.rand_name(name='tenant')
|
||||||
body = self.tenants_client.create_tenant(tenant_name, enabled=True)
|
body = self.tenants_client.create_tenant(name=tenant_name,
|
||||||
|
enabled=True)
|
||||||
tenant = body['tenant']
|
tenant = body['tenant']
|
||||||
self.data.tenants.append(tenant)
|
self.data.tenants.append(tenant)
|
||||||
tenant_id = tenant['id']
|
tenant_id = tenant['id']
|
||||||
@ -84,7 +86,8 @@ class TenantsTestJSON(base.BaseIdentityV2AdminTest):
|
|||||||
def test_tenant_create_not_enabled(self):
|
def test_tenant_create_not_enabled(self):
|
||||||
# Create a tenant that is not enabled
|
# Create a tenant that is not enabled
|
||||||
tenant_name = data_utils.rand_name(name='tenant')
|
tenant_name = data_utils.rand_name(name='tenant')
|
||||||
body = self.tenants_client.create_tenant(tenant_name, enabled=False)
|
body = self.tenants_client.create_tenant(name=tenant_name,
|
||||||
|
enabled=False)
|
||||||
tenant = body['tenant']
|
tenant = body['tenant']
|
||||||
self.data.tenants.append(tenant)
|
self.data.tenants.append(tenant)
|
||||||
tenant_id = tenant['id']
|
tenant_id = tenant['id']
|
||||||
@ -102,7 +105,7 @@ class TenantsTestJSON(base.BaseIdentityV2AdminTest):
|
|||||||
def test_tenant_update_name(self):
|
def test_tenant_update_name(self):
|
||||||
# Update name attribute of a tenant
|
# Update name attribute of a tenant
|
||||||
t_name1 = data_utils.rand_name(name='tenant')
|
t_name1 = data_utils.rand_name(name='tenant')
|
||||||
body = self.tenants_client.create_tenant(t_name1)['tenant']
|
body = self.tenants_client.create_tenant(name=t_name1)['tenant']
|
||||||
tenant = body
|
tenant = body
|
||||||
self.data.tenants.append(tenant)
|
self.data.tenants.append(tenant)
|
||||||
|
|
||||||
@ -129,7 +132,8 @@ class TenantsTestJSON(base.BaseIdentityV2AdminTest):
|
|||||||
# Update description attribute of a tenant
|
# Update description attribute of a tenant
|
||||||
t_name = data_utils.rand_name(name='tenant')
|
t_name = data_utils.rand_name(name='tenant')
|
||||||
t_desc = data_utils.rand_name(name='desc')
|
t_desc = data_utils.rand_name(name='desc')
|
||||||
body = self.tenants_client.create_tenant(t_name, description=t_desc)
|
body = self.tenants_client.create_tenant(name=t_name,
|
||||||
|
description=t_desc)
|
||||||
tenant = body['tenant']
|
tenant = body['tenant']
|
||||||
self.data.tenants.append(tenant)
|
self.data.tenants.append(tenant)
|
||||||
|
|
||||||
@ -157,7 +161,7 @@ class TenantsTestJSON(base.BaseIdentityV2AdminTest):
|
|||||||
# Update the enabled attribute of a tenant
|
# Update the enabled attribute of a tenant
|
||||||
t_name = data_utils.rand_name(name='tenant')
|
t_name = data_utils.rand_name(name='tenant')
|
||||||
t_en = False
|
t_en = False
|
||||||
body = self.tenants_client.create_tenant(t_name, enabled=t_en)
|
body = self.tenants_client.create_tenant(name=t_name, enabled=t_en)
|
||||||
tenant = body['tenant']
|
tenant = body['tenant']
|
||||||
self.data.tenants.append(tenant)
|
self.data.tenants.append(tenant)
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class TokensTestJSON(base.BaseIdentityV2AdminTest):
|
|||||||
user_password = data_utils.rand_password()
|
user_password = data_utils.rand_password()
|
||||||
# first:create a tenant
|
# first:create a tenant
|
||||||
tenant_name = data_utils.rand_name(name='tenant')
|
tenant_name = data_utils.rand_name(name='tenant')
|
||||||
tenant = self.tenants_client.create_tenant(tenant_name)['tenant']
|
tenant = self.tenants_client.create_tenant(name=tenant_name)['tenant']
|
||||||
self.data.tenants.append(tenant)
|
self.data.tenants.append(tenant)
|
||||||
# second:create a user
|
# second:create a user
|
||||||
user = self.users_client.create_user(name=user_name,
|
user = self.users_client.create_user(name=user_name,
|
||||||
@ -72,11 +72,13 @@ class TokensTestJSON(base.BaseIdentityV2AdminTest):
|
|||||||
|
|
||||||
# Create a couple tenants.
|
# Create a couple tenants.
|
||||||
tenant1_name = data_utils.rand_name(name='tenant')
|
tenant1_name = data_utils.rand_name(name='tenant')
|
||||||
tenant1 = self.tenants_client.create_tenant(tenant1_name)['tenant']
|
tenant1 = self.tenants_client.create_tenant(
|
||||||
|
name=tenant1_name)['tenant']
|
||||||
self.data.tenants.append(tenant1)
|
self.data.tenants.append(tenant1)
|
||||||
|
|
||||||
tenant2_name = data_utils.rand_name(name='tenant')
|
tenant2_name = data_utils.rand_name(name='tenant')
|
||||||
tenant2 = self.tenants_client.create_tenant(tenant2_name)['tenant']
|
tenant2 = self.tenants_client.create_tenant(
|
||||||
|
name=tenant2_name)['tenant']
|
||||||
self.data.tenants.append(tenant2)
|
self.data.tenants.append(tenant2)
|
||||||
|
|
||||||
# Create a role
|
# Create a role
|
||||||
|
@ -319,7 +319,7 @@ def create_tenants(tenants):
|
|||||||
existing = [x['name'] for x in body]
|
existing = [x['name'] for x in body]
|
||||||
for tenant in tenants:
|
for tenant in tenants:
|
||||||
if tenant not in existing:
|
if tenant not in existing:
|
||||||
admin.tenants.create_tenant(tenant)['tenant']
|
admin.tenants.create_tenant(name=tenant)['tenant']
|
||||||
else:
|
else:
|
||||||
LOG.warning("Tenant '%s' already exists in this environment"
|
LOG.warning("Tenant '%s' already exists in this environment"
|
||||||
% tenant)
|
% tenant)
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from oslo_serialization import jsonutils as json
|
from oslo_serialization import jsonutils as json
|
||||||
|
from six.moves.urllib import parse as urllib
|
||||||
|
|
||||||
from tempest.lib.common import rest_client
|
from tempest.lib.common import rest_client
|
||||||
|
|
||||||
@ -20,40 +21,50 @@ from tempest.lib.common import rest_client
|
|||||||
class TenantsClient(rest_client.RestClient):
|
class TenantsClient(rest_client.RestClient):
|
||||||
api_version = "v2.0"
|
api_version = "v2.0"
|
||||||
|
|
||||||
def create_tenant(self, name, **kwargs):
|
def create_tenant(self, **kwargs):
|
||||||
"""Create a tenant
|
"""Create a tenant
|
||||||
|
|
||||||
name (required): New tenant name
|
Available params: see http://developer.openstack.org/
|
||||||
description: Description of new tenant (default is none)
|
api-ref-identity-v2-ext.html#createTenant
|
||||||
enabled <true|false>: Initial tenant status (default is true)
|
|
||||||
"""
|
"""
|
||||||
post_body = {
|
post_body = json.dumps({'tenant': kwargs})
|
||||||
'name': name,
|
|
||||||
'description': kwargs.get('description', ''),
|
|
||||||
'enabled': kwargs.get('enabled', True),
|
|
||||||
}
|
|
||||||
post_body = json.dumps({'tenant': post_body})
|
|
||||||
resp, body = self.post('tenants', post_body)
|
resp, body = self.post('tenants', post_body)
|
||||||
self.expected_success(200, resp.status)
|
self.expected_success(200, resp.status)
|
||||||
body = json.loads(body)
|
body = json.loads(body)
|
||||||
return rest_client.ResponseBody(resp, body)
|
return rest_client.ResponseBody(resp, body)
|
||||||
|
|
||||||
def delete_tenant(self, tenant_id):
|
def delete_tenant(self, tenant_id):
|
||||||
"""Delete a tenant."""
|
"""Delete a tenant.
|
||||||
|
|
||||||
|
Available params: see http://developer.openstack.org/
|
||||||
|
api-ref-identity-v2-ext.html#deleteTenant
|
||||||
|
"""
|
||||||
resp, body = self.delete('tenants/%s' % str(tenant_id))
|
resp, body = self.delete('tenants/%s' % str(tenant_id))
|
||||||
self.expected_success(204, resp.status)
|
self.expected_success(204, resp.status)
|
||||||
return rest_client.ResponseBody(resp, body)
|
return rest_client.ResponseBody(resp, body)
|
||||||
|
|
||||||
def show_tenant(self, tenant_id):
|
def show_tenant(self, tenant_id):
|
||||||
"""Get tenant details."""
|
"""Get tenant details.
|
||||||
|
|
||||||
|
Available params: see
|
||||||
|
http://developer.openstack.org/
|
||||||
|
api-ref-identity-v2-ext.html#admin-showTenantById
|
||||||
|
"""
|
||||||
resp, body = self.get('tenants/%s' % str(tenant_id))
|
resp, body = self.get('tenants/%s' % str(tenant_id))
|
||||||
self.expected_success(200, resp.status)
|
self.expected_success(200, resp.status)
|
||||||
body = json.loads(body)
|
body = json.loads(body)
|
||||||
return rest_client.ResponseBody(resp, body)
|
return rest_client.ResponseBody(resp, body)
|
||||||
|
|
||||||
def list_tenants(self):
|
def list_tenants(self, **params):
|
||||||
"""Returns tenants."""
|
"""Returns tenants.
|
||||||
resp, body = self.get('tenants')
|
|
||||||
|
Available params: see http://developer.openstack.org/
|
||||||
|
api-ref-identity-v2-ext.html#admin-listTenants
|
||||||
|
"""
|
||||||
|
url = 'tenants'
|
||||||
|
if params:
|
||||||
|
url += '?%s' % urllib.urlencode(params)
|
||||||
|
resp, body = self.get(url)
|
||||||
self.expected_success(200, resp.status)
|
self.expected_success(200, resp.status)
|
||||||
body = json.loads(body)
|
body = json.loads(body)
|
||||||
return rest_client.ResponseBody(resp, body)
|
return rest_client.ResponseBody(resp, body)
|
||||||
@ -64,25 +75,24 @@ class TenantsClient(rest_client.RestClient):
|
|||||||
Available params: see http://developer.openstack.org/
|
Available params: see http://developer.openstack.org/
|
||||||
api-ref-identity-v2-ext.html#updateTenant
|
api-ref-identity-v2-ext.html#updateTenant
|
||||||
"""
|
"""
|
||||||
body = self.show_tenant(tenant_id)['tenant']
|
if 'id' not in kwargs:
|
||||||
name = kwargs.get('name', body['name'])
|
kwargs['id'] = tenant_id
|
||||||
desc = kwargs.get('description', body['description'])
|
post_body = json.dumps({'tenant': kwargs})
|
||||||
en = kwargs.get('enabled', body['enabled'])
|
|
||||||
post_body = {
|
|
||||||
'id': tenant_id,
|
|
||||||
'name': name,
|
|
||||||
'description': desc,
|
|
||||||
'enabled': en,
|
|
||||||
}
|
|
||||||
post_body = json.dumps({'tenant': post_body})
|
|
||||||
resp, body = self.post('tenants/%s' % tenant_id, post_body)
|
resp, body = self.post('tenants/%s' % tenant_id, post_body)
|
||||||
self.expected_success(200, resp.status)
|
self.expected_success(200, resp.status)
|
||||||
body = json.loads(body)
|
body = json.loads(body)
|
||||||
return rest_client.ResponseBody(resp, body)
|
return rest_client.ResponseBody(resp, body)
|
||||||
|
|
||||||
def list_tenant_users(self, tenant_id):
|
def list_tenant_users(self, tenant_id, **params):
|
||||||
"""List users for a Tenant."""
|
"""List users for a Tenant.
|
||||||
resp, body = self.get('/tenants/%s/users' % tenant_id)
|
|
||||||
|
Available params: see http://developer.openstack.org/
|
||||||
|
api-ref-identity-v2-ext.html#listUsersForTenant
|
||||||
|
"""
|
||||||
|
url = '/tenants/%s/users' % tenant_id
|
||||||
|
if params:
|
||||||
|
url += '?%s' % urllib.urlencode(params)
|
||||||
|
resp, body = self.get(url)
|
||||||
self.expected_success(200, resp.status)
|
self.expected_success(200, resp.status)
|
||||||
body = json.loads(body)
|
body = json.loads(body)
|
||||||
return rest_client.ResponseBody(resp, body)
|
return rest_client.ResponseBody(resp, body)
|
||||||
|
@ -92,7 +92,7 @@ class TestCreateResources(JavelinUnitTest):
|
|||||||
javelin.create_tenants([self.fake_object['name']])
|
javelin.create_tenants([self.fake_object['name']])
|
||||||
|
|
||||||
mocked_function = self.fake_client.tenants.create_tenant
|
mocked_function = self.fake_client.tenants.create_tenant
|
||||||
mocked_function.assert_called_once_with(self.fake_object['name'])
|
mocked_function.assert_called_once_with(name=self.fake_object['name'])
|
||||||
|
|
||||||
def test_create_duplicate_tenant(self):
|
def test_create_duplicate_tenant(self):
|
||||||
self.fake_client.tenants.list_tenants.return_value = {'tenants': [
|
self.fake_client.tenants.list_tenants.return_value = {'tenants': [
|
||||||
|
Loading…
Reference in New Issue
Block a user