Add default role name to rally config

If the OpenStack env does not have a 'member' role, the
rally task will get a WARNING: Unable to set member role
to created user. And then task will stop due to the 401
Unauthorized error.

This patch adds default role to rally config. So for each,
test, rally will create the test user with the set
keystone_default_role.

Closes-Bug: #1595081

Change-Id: Ic97ce50f40d3a3e7f9e8fc6ef142c5465ab41a51
This commit is contained in:
LIU Yulong 2016-06-23 13:19:48 +08:00 committed by LIU Yulong
parent ec7995d870
commit a3244da2ee
2 changed files with 17 additions and 8 deletions

View File

@ -46,6 +46,9 @@ USER_CONTEXT_OPTS = [
cfg.StrOpt("user_domain", cfg.StrOpt("user_domain",
default="default", default="default",
help="ID of domain in which users will be created."), help="ID of domain in which users will be created."),
cfg.StrOpt("keystone_default_role",
default="member",
help="The default role name of the keystone."),
] ]
CONF = cfg.CONF CONF = cfg.CONF
@ -223,6 +226,7 @@ class UserGenerator(UserContextMixin, context.Context):
# NOTE(msdubov): This should be called after _create_tenants(). # NOTE(msdubov): This should be called after _create_tenants().
threads = self.config["resource_management_workers"] threads = self.config["resource_management_workers"]
users_per_tenant = self.config["users_per_tenant"] users_per_tenant = self.config["users_per_tenant"]
default_role = cfg.CONF.users_context.keystone_default_role
users = collections.deque() users = collections.deque()
@ -241,9 +245,11 @@ class UserGenerator(UserContextMixin, context.Context):
clients = osclients.Clients(self.credential) clients = osclients.Clients(self.credential)
cache["client"] = keystone.wrap(clients.keystone()) cache["client"] = keystone.wrap(clients.keystone())
client = cache["client"] client = cache["client"]
user = client.create_user(username, password, user = client.create_user(
username, password,
"%s@email.me" % username, "%s@email.me" % username,
tenant_id, user_dom) tenant_id, user_dom,
default_role=default_role)
user_credential = objects.Credential( user_credential = objects.Credential(
client.auth_url, user.name, password, client.auth_url, user.name, password,
self.context["tenants"][tenant_id]["name"], self.context["tenants"][tenant_id]["name"],

View File

@ -55,7 +55,7 @@ class KeystoneWrapper(object):
@abc.abstractmethod @abc.abstractmethod
def create_user(self, username, password, email=None, project_id=None, def create_user(self, username, password, email=None, project_id=None,
domain_name="Default"): domain_name="Default", default_role="member"):
"""Create user. """Create user.
:param username: name of user :param username: name of user
@ -64,6 +64,7 @@ class KeystoneWrapper(object):
:param domain_name: Name or id of domain where to create project, for :param domain_name: Name or id of domain where to create project, for
implementations that don't support domains this implementations that don't support domains this
argument must be None or 'Default'. argument must be None or 'Default'.
:param default_role: user's default role
""" """
@abc.abstractmethod @abc.abstractmethod
@ -136,7 +137,8 @@ class KeystoneV2Wrapper(KeystoneWrapper):
self.client.tenants.delete(project_id) self.client.tenants.delete(project_id)
def create_user(self, username, password, email=None, project_id=None, def create_user(self, username, password, email=None, project_id=None,
domain_name="Default"): domain_name="Default", default_role="member"):
# NOTE(liuyulong): For v2 wrapper the `default_role` here is not used.
self._check_domain(domain_name) self._check_domain(domain_name)
user = self.client.users.create(username, password, email, project_id) user = self.client.users.create(username, password, email, project_id)
return KeystoneV2Wrapper._wrap_v2_user(user) return KeystoneV2Wrapper._wrap_v2_user(user)
@ -194,18 +196,19 @@ class KeystoneV3Wrapper(KeystoneWrapper):
self.client.projects.delete(project_id) self.client.projects.delete(project_id)
def create_user(self, username, password, email=None, project_id=None, def create_user(self, username, password, email=None, project_id=None,
domain_name="Default"): domain_name="Default", default_role="member"):
domain_id = self._get_domain_id(domain_name) domain_id = self._get_domain_id(domain_name)
user = self.client.users.create(name=username, password=password, user = self.client.users.create(name=username, password=password,
default_project=project_id, default_project=project_id,
email=email, domain=domain_id) email=email, domain=domain_id)
for role in self.client.roles.list(): for role in self.client.roles.list():
if "member" in role.name.lower(): if default_role in role.name.lower():
self.client.roles.grant(role.id, user=user.id, self.client.roles.grant(role.id, user=user.id,
project=project_id) project=project_id)
break break
else: else:
LOG.warning("Unable to set member role to created user.") LOG.warning(
"Unable to set %s role to created user." % default_role)
return KeystoneV3Wrapper._wrap_v3_user(user) return KeystoneV3Wrapper._wrap_v3_user(user)
def delete_user(self, user_id): def delete_user(self, user_id):