Improve readability by renaming tenant_role

The for-loop processing the kwarg roles only
iterates over tenant *names* so naming the
variable "tenant_role" is misleading.

Also explicitly iterating over the passed dict's
keys so we get a useful error message when a list
is passed instead (and makes the code easier to
read).
This commit is contained in:
Florian Ermisch 2015-04-21 15:32:15 +02:00
parent 1fb606ef6b
commit f0ae2eb84f

View file

@ -173,11 +173,11 @@ def user_present(name,
ret['comment'] = 'User "{0}" has been updated'.format(name)
ret['changes']['Password'] = 'Updated'
if roles:
for tenant_role in roles:
for tenant in roles.keys():
args = dict({'user_name': name, 'tenant_name':
tenant_role, 'profile': profile}, **connection_args)
tenant, 'profile': profile}, **connection_args)
tenant_roles = __salt__['keystone.user_role_list'](**args)
for role in roles[tenant_role]:
for role in roles[tenant]:
if role not in tenant_roles:
if __opts__['test']:
ret['result'] = None
@ -187,7 +187,7 @@ def user_present(name,
ret['changes']['roles'] = [role]
continue
addargs = dict({'user': name, 'role': role,
'tenant': tenant_role,
'tenant': tenant,
'profile': profile},
**connection_args)
newrole = __salt__['keystone.user_role_add'](**addargs)
@ -195,7 +195,7 @@ def user_present(name,
ret['changes']['roles'].append(newrole)
else:
ret['changes']['roles'] = [newrole]
roles_to_remove = list(set(tenant_roles) - set(roles[tenant_role]))
roles_to_remove = list(set(tenant_roles) - set(roles[tenant]))
for role in roles_to_remove:
if __opts__['test']:
ret['result'] = None
@ -205,7 +205,7 @@ def user_present(name,
ret['changes']['roles'] = [role]
continue
addargs = dict({'user': name, 'role': role,
'tenant': tenant_role,
'tenant': tenant,
'profile': profile},
**connection_args)
oldrole = __salt__['keystone.user_role_remove'](**addargs)
@ -228,11 +228,11 @@ def user_present(name,
profile=profile,
**connection_args)
if roles:
for tenant_role in roles:
for role in roles[tenant_role]:
for tenant in roles.keys():
for role in roles[tenant]:
__salt__['keystone.user_role_add'](user=name,
role=role,
tenant=tenant_role,
tenant=tenant,
profile=profile,
**connection_args)
ret['comment'] = 'Keystone user {0} has been added'.format(name)