diff --git a/releasenotes/notes/add_description_create_user-0ddc9a0ef4da840d.yaml b/releasenotes/notes/add_description_create_user-0ddc9a0ef4da840d.yaml new file mode 100644 index 000000000..98dd190bf --- /dev/null +++ b/releasenotes/notes/add_description_create_user-0ddc9a0ef4da840d.yaml @@ -0,0 +1,3 @@ +--- +features: + - Add description parameter to create_user, available on Keystone v3 diff --git a/shade/_utils.py b/shade/_utils.py index 9a9beb1ae..ea7a7acbd 100644 --- a/shade/_utils.py +++ b/shade/_utils.py @@ -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) diff --git a/shade/openstackcloud.py b/shade/openstackcloud.py index 95f961f34..12aa82c49 100644 --- a/shade/openstackcloud.py +++ b/shade/openstackcloud.py @@ -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] diff --git a/shade/tests/fakes.py b/shade/tests/fakes.py index 642d7505d..33ddc4ecd 100644 --- a/shade/tests/fakes.py +++ b/shade/tests/fakes.py @@ -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 diff --git a/shade/tests/unit/test_users.py b/shade/tests/unit/test_users.py index 2c8fb67e6..7d4f9121e 100644 --- a/shade/tests/unit/test_users.py +++ b/shade/tests/unit/test_users.py @@ -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]