summaryrefslogtreecommitdiffstats
path: root/snaps/openstack/create_user.py
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-07-07 15:26:24 -0600
committerspisarski <s.pisarski@cablelabs.com>2017-07-11 08:10:28 -0600
commit9881e7e312b1927d9be52ae02dccc5f9df3982df (patch)
tree167feaba570b4e29368260d82284bd398564c71d /snaps/openstack/create_user.py
parent5f3fe6856f07bd1289bac532264eccf6cba68d77 (diff)
Added ability to add a user to a role.
This functionality was requested as the SNAPS-OO integration tests currently have the ability to run these tests in custom projects with custom users and certain OpenStack installations are not allowing some of the integration tests functions unless the new user has been added to the 'admin' role. Change-Id: I255cfa089a14bbcb434a6cd33b2a1dfae66206b5 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/openstack/create_user.py')
-rw-r--r--snaps/openstack/create_user.py33
1 files changed, 16 insertions, 17 deletions
diff --git a/snaps/openstack/create_user.py b/snaps/openstack/create_user.py
index 4c96121..18de215 100644
--- a/snaps/openstack/create_user.py
+++ b/snaps/openstack/create_user.py
@@ -49,13 +49,9 @@ class OpenStackUser:
self.__keystone = keystone_utils.keystone_client(self.__os_creds)
self.__user = keystone_utils.get_user(self.__keystone,
self.user_settings.name)
- if self.__user:
- logger.info('Found user with name - ' + self.user_settings.name)
- elif not cleanup:
+ if not self.__user and not cleanup:
self.__user = keystone_utils.create_user(self.__keystone,
self.user_settings)
- else:
- logger.info('Did not create user due to cleanup mode')
return self.__user
@@ -111,27 +107,30 @@ class UserSettings:
:param email: the user's email address (optional)
:param enabled: denotes whether or not the user is enabled
(default True)
+ :param roles: dict where key is the role name and value is a list of
+ project names
"""
self.name = kwargs.get('name')
self.password = kwargs.get('password')
self.project_name = kwargs.get('project_name')
self.email = kwargs.get('email')
-
- if kwargs.get('domain_name'):
- self.domain_name = kwargs['domain_name']
- else:
- self.domain_name = 'default'
-
- if kwargs.get('enabled') is not None:
- self.enabled = kwargs['enabled']
- else:
- self.enabled = True
+ self.domain_name = kwargs.get('domain_name', 'default')
+ self.enabled = kwargs.get('enabled', True)
+ self.roles = kwargs.get('roles', dict())
if not self.name or not self.password:
- raise Exception(
+ raise UserSettingsException(
'The attributes name and password are required for '
'UserSettings')
if not isinstance(self.enabled, bool):
- raise Exception('The attribute enabled must be of type boolean')
+ raise UserSettingsException('The attribute enabled must be of type'
+ ' boolean')
+
+
+class UserSettingsException(Exception):
+ """
+ Raised when there is a problem with the values set in the UserSettings
+ class
+ """