Fix return value of get_or_add_user_project_role

get_or_add_user_project_role function was always returning an
empty user_role_id because the role assignment command does not
return any output. Added a command to get the user_role_id after
the assignment happens.

Closes-Bug: #1498599
Change-Id: If1b77eef0d4f0ebdcdf761ecb5e2011484f73871
This commit is contained in:
Roxana Gherle
2015-09-22 10:52:46 -07:00
parent c4c08686f8
commit 50821bed08

View File

@@ -830,14 +830,20 @@ function get_or_add_user_project_role {
--column "Name" \
| grep " $1 " | get_field 1)
if [[ -z "$user_role_id" ]]; then
# Adds role to user
user_role_id=$(openstack role add \
$1 \
# Adds role to user and get it
openstack role add $1 \
--user $2 \
--project $3 \
--os-url=$KEYSTONE_SERVICE_URI_V3 \
--os-identity-api-version=3
user_role_id=$(openstack role list \
--user $2 \
--os-url=$KEYSTONE_SERVICE_URI_V3 \
--os-identity-api-version=3 \
| grep " id " | get_field 2)
--column "ID" \
--project $3 \
--column "Name" \
| grep " $1 " | get_field 1)
fi
echo $user_role_id
}