Add description field to create_user method
Change-Id: I3444502c61de3931b0bd2623373be927682ceacb
This commit is contained in:
parent
cf877de8bb
commit
bbc8816e70
@ -0,0 +1,3 @@
|
||||
---
|
||||
features:
|
||||
- Add description parameter to create_user, available on Keystone v3
|
@ -365,6 +365,7 @@ def normalize_users(users):
|
||||
user.get('tenantId')),
|
||||
domain_id=user.get('domain_id'),
|
||||
enabled=user.get('enabled'),
|
||||
description=user.get('description')
|
||||
) for user in users
|
||||
]
|
||||
return meta.obj_list_to_dict(ret)
|
||||
|
@ -714,15 +714,25 @@ class OpenStackCloud(object):
|
||||
|
||||
def create_user(
|
||||
self, name, password=None, email=None, default_project=None,
|
||||
enabled=True, domain_id=None):
|
||||
enabled=True, domain_id=None, description=None):
|
||||
"""Create a user."""
|
||||
with _utils.shade_exceptions("Error in creating user {user}".format(
|
||||
user=name)):
|
||||
identity_params = self._get_identity_params(
|
||||
domain_id, default_project)
|
||||
user = self.manager.submit_task(_tasks.UserCreate(
|
||||
name=name, password=password, email=email,
|
||||
enabled=enabled, **identity_params))
|
||||
if self.cloud_config.get_api_version('identity') != '3':
|
||||
if description is not None:
|
||||
self.log.info(
|
||||
"description parameter is not supported on Keystone v2"
|
||||
)
|
||||
user = self.manager.submit_task(_tasks.UserCreate(
|
||||
name=name, password=password, email=email,
|
||||
enabled=enabled, **identity_params))
|
||||
else:
|
||||
user = self.manager.submit_task(_tasks.UserCreate(
|
||||
name=name, password=password, email=email,
|
||||
enabled=enabled, description=description,
|
||||
**identity_params))
|
||||
self.list_users.invalidate(self)
|
||||
return _utils.normalize_users([user])[0]
|
||||
|
||||
|
@ -133,10 +133,11 @@ class FakeService(object):
|
||||
|
||||
|
||||
class FakeUser(object):
|
||||
def __init__(self, id, email, name, domain_id=None):
|
||||
def __init__(self, id, email, name, domain_id=None, description=None):
|
||||
self.id = id
|
||||
self.email = email
|
||||
self.name = name
|
||||
self.description = description
|
||||
if domain_id is not None:
|
||||
self.domain_id = domain_id
|
||||
|
||||
|
@ -36,9 +36,11 @@ class TestUsers(base.TestCase):
|
||||
fake_user = fakes.FakeUser('1', email, name)
|
||||
mock_keystone.users.create.return_value = fake_user
|
||||
user = self.op_cloud.create_user(
|
||||
name=name, email=email, password=password)
|
||||
name=name, email=email, password=password,
|
||||
)
|
||||
mock_keystone.users.create.assert_called_once_with(
|
||||
name=name, password=password, email=email, enabled=True,
|
||||
name=name, password=password, email=email,
|
||||
enabled=True,
|
||||
)
|
||||
self.assertEqual(name, user.name)
|
||||
self.assertEqual(email, user.email)
|
||||
@ -51,18 +53,22 @@ class TestUsers(base.TestCase):
|
||||
email = 'mickey@disney.com'
|
||||
password = 'mice-rule'
|
||||
domain_id = '456'
|
||||
fake_user = fakes.FakeUser('1', email, name)
|
||||
description = 'fake-description'
|
||||
fake_user = fakes.FakeUser('1', email, name, description=description)
|
||||
mock_keystone.users.create.return_value = fake_user
|
||||
user = self.op_cloud.create_user(
|
||||
name=name, email=email,
|
||||
password=password,
|
||||
description=description,
|
||||
domain_id=domain_id)
|
||||
mock_keystone.users.create.assert_called_once_with(
|
||||
name=name, password=password, email=email, enabled=True,
|
||||
name=name, password=password, email=email,
|
||||
description=description, enabled=True,
|
||||
domain=domain_id
|
||||
)
|
||||
self.assertEqual(name, user.name)
|
||||
self.assertEqual(email, user.email)
|
||||
self.assertEqual(description, user.description)
|
||||
|
||||
@mock.patch.object(occ.cloud_config.CloudConfig, 'get_api_version')
|
||||
@mock.patch.object(shade.OpenStackCloud, 'keystone_client')
|
||||
@ -72,7 +78,7 @@ class TestUsers(base.TestCase):
|
||||
email = 'mickey@disney.com'
|
||||
password = 'mice-rule'
|
||||
domain_id = '1'
|
||||
user = {'id': '1', 'name': name, 'email': email}
|
||||
user = {'id': '1', 'name': name, 'email': email, 'description': None}
|
||||
fake_user = fakes.FakeUser(**user)
|
||||
munch_fake_user = munch.Munch(user)
|
||||
mock_keystone.users.list.return_value = [fake_user]
|
||||
|
Loading…
Reference in New Issue
Block a user