Replace tenant by project, part 2
Story: 2002116 Task: 20023 Change-Id: I465fe96120ed5609c2747b587963d2e5f57b55be
This commit is contained in:
@@ -18,15 +18,15 @@ from tempest.lib import exceptions
|
||||
|
||||
|
||||
class Users(object):
|
||||
def __init__(self, tenants_client, roles_client, users_client, conf):
|
||||
def __init__(self, projects_client, roles_client, users_client, conf):
|
||||
"""Init.
|
||||
|
||||
:type tenants_client: ProjectsClient object
|
||||
:type projects_client: ProjectsClient object
|
||||
:type roles_client: RolesClient object from tempest lib
|
||||
:type users_client: UsersClient object from tempest lib
|
||||
:type conf: TempestConf object
|
||||
"""
|
||||
self.tenants_client = tenants_client
|
||||
self.projects_client = projects_client
|
||||
self.roles_client = roles_client
|
||||
self.users_client = users_client
|
||||
self._conf = conf
|
||||
@@ -37,13 +37,13 @@ class Users(object):
|
||||
:type orchestration: boolean
|
||||
"""
|
||||
sec = 'identity'
|
||||
self.create_user_with_tenant(self._conf.get(sec, 'username'),
|
||||
self._conf.get(sec, 'password'),
|
||||
self._conf.get(sec, 'project_name'))
|
||||
self.create_user_with_project(self._conf.get(sec, 'username'),
|
||||
self._conf.get(sec, 'password'),
|
||||
self._conf.get(sec, 'project_name'))
|
||||
|
||||
self.create_user_with_tenant(self._conf.get(sec, 'alt_username'),
|
||||
self._conf.get(sec, 'alt_password'),
|
||||
self._conf.get(sec, 'alt_project_name'))
|
||||
self.create_user_with_project(self._conf.get(sec, 'alt_username'),
|
||||
self._conf.get(sec, 'alt_password'),
|
||||
self._conf.get(sec, 'alt_project_name'))
|
||||
|
||||
username = self._conf.get_defaulted('auth', 'admin_username')
|
||||
|
||||
@@ -59,14 +59,14 @@ class Users(object):
|
||||
|
||||
def give_role_to_user(self, username, role_name,
|
||||
role_required=True):
|
||||
"""Give the user a role in the project (tenant).
|
||||
"""Give the user a role in the project.
|
||||
|
||||
:type username: string
|
||||
:type role_name: string
|
||||
:type role_required: boolean
|
||||
"""
|
||||
tenant_name = self._conf.get('identity', 'project_name')
|
||||
tenant_id = self.tenants_client.get_project_by_name(tenant_name)['id']
|
||||
project_name = self._conf.get('identity', 'project_name')
|
||||
proj_id = self.projects_client.get_project_by_name(project_name)['id']
|
||||
users = self.users_client.list_users()
|
||||
user_ids = [u['id'] for u in users['users'] if u['name'] == username]
|
||||
user_id = user_ids[0]
|
||||
@@ -79,36 +79,36 @@ class Users(object):
|
||||
return
|
||||
role_id = role_ids[0]
|
||||
try:
|
||||
self.roles_client.create_user_role_on_project(tenant_id, user_id,
|
||||
self.roles_client.create_user_role_on_project(proj_id, user_id,
|
||||
role_id)
|
||||
LOG.debug("User '%s' was given the '%s' role in project '%s'",
|
||||
username, role_name, tenant_name)
|
||||
username, role_name, project_name)
|
||||
except exceptions.Conflict:
|
||||
LOG.debug("(no change) User '%s' already has the '%s' role in"
|
||||
" project '%s'", username, role_name, tenant_name)
|
||||
" project '%s'", username, role_name, project_name)
|
||||
|
||||
def create_user_with_tenant(self, username, password, tenant_name):
|
||||
"""Create a user and a tenant if it doesn't exist.
|
||||
def create_user_with_project(self, username, password, project_name):
|
||||
"""Create a user and a project if it doesn't exist.
|
||||
|
||||
:type username: string
|
||||
:type password: string
|
||||
:type tenant_name: string
|
||||
:type project_name: string
|
||||
"""
|
||||
LOG.info("Creating user '%s' with tenant '%s' and password '%s'",
|
||||
username, tenant_name, password)
|
||||
tenant_description = "Tenant for Tempest %s user" % username
|
||||
LOG.info("Creating user '%s' with project '%s' and password '%s'",
|
||||
username, project_name, password)
|
||||
project_description = "Project for Tempest %s user" % username
|
||||
email = "%s@test.com" % username
|
||||
# create a tenant
|
||||
# create a project
|
||||
try:
|
||||
self.tenants_client.create_project(name=tenant_name,
|
||||
description=tenant_description)
|
||||
self.projects_client.create_project(
|
||||
name=project_name, description=project_description)
|
||||
except exceptions.Conflict:
|
||||
LOG.info("(no change) Tenant '%s' already exists", tenant_name)
|
||||
LOG.info("(no change) Project '%s' already exists", project_name)
|
||||
|
||||
tenant_id = self.tenants_client.get_project_by_name(tenant_name)['id']
|
||||
proj_id = self.projects_client.get_project_by_name(project_name)['id']
|
||||
|
||||
params = {'name': username, 'password': password,
|
||||
'tenantId': tenant_id, 'email': email}
|
||||
'tenantId': proj_id, 'email': email}
|
||||
# create a user
|
||||
try:
|
||||
self.users_client.create_user(**params)
|
||||
|
||||
Reference in New Issue
Block a user