Fix creating user in keystone v3 wrapper

A "member" role should be granted to newly created user if
version 3 of keystone is used. Name of this role is different
in different clouds. In devstack clouds it is "Member" and in
MOS clouds it is "_member_".
Assing first role with "member" string in role's name.

Change-Id: I197df429b19bd625f75223207ddb3cee5caff828
Closes-Bug: #1443367
This commit is contained in:
Sergey Skripnick 2015-04-16 10:53:05 +02:00
parent e933ebdc59
commit d1da39a0fc
2 changed files with 16 additions and 2 deletions

View File

@ -19,6 +19,10 @@ import collections
from keystoneclient import exceptions
import six
from rally.common import log as logging
LOG = logging.getLogger(__name__)
Project = collections.namedtuple("Project", ["id", "name", "domain_id"])
User = collections.namedtuple("User",
@ -179,8 +183,15 @@ class KeystoneV3Wrapper(KeystoneWrapper):
domain_name="Default"):
domain_id = self._get_domain_id(domain_name)
user = self.client.users.create(name=username, password=password,
email=email, domain=domain_id,
default_project=project_id)
default_project=project_id,
email=email, domain=domain_id)
for role in self.client.roles.list():
if "member" in role.name.lower():
self.client.roles.grant(role.id, user=user.id,
project=project_id)
break
else:
LOG.warning("Unable to set member role to created user.")
return KeystoneV3Wrapper._wrap_v3_user(user)
def delete_user(self, user_id):

View File

@ -165,6 +165,9 @@ class KeystoneV3WrapperTestCase(test.TestCase, KeystoneWrapperTestBase):
self.assertFalse(hasattr(result[0], "extra_field"))
def test_create_user(self):
fake_role = mock.MagicMock(id="fake_role_id")
fake_role.name = "__member__"
self.client.roles.list.return_value = [fake_role]
self.client.users.create.return_value = mock.MagicMock(
id="fake_user_id")