From 3e9b562d0b1f1815597daa5346ba32ef48f868af Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Wed, 14 Jun 2017 15:29:47 -0700 Subject: [PATCH] Actually check if roles are set In the helper functions to check if roles are set and if not add the role and return the id we weren't actually checking if the role was set. The reason for this was we grepped for name values while outputing only uuid values with OSC. Fix for this is straightforward, we just add the --role argument to OSC which will filter for us then we don't have to use a grep on the wrong value type. Change-Id: I2691b347d2a6273100deb4a1750ab353a8e49673 --- functions-common | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/functions-common b/functions-common index 30933ea4c2..35613ab7e9 100644 --- a/functions-common +++ b/functions-common @@ -864,10 +864,11 @@ function get_or_add_user_project_role { # Gets user role id user_role_id=$(openstack role assignment list \ + --role $1 \ --user $2 \ --project $3 \ $domain_args \ - | grep " $1 " | get_field 1) + | grep '^|\s[a-f0-9]\+' | get_field 1) if [[ -z "$user_role_id" ]]; then # Adds role to user and get it openstack role add $1 \ @@ -875,10 +876,11 @@ function get_or_add_user_project_role { --project $3 \ $domain_args user_role_id=$(openstack role assignment list \ + --role $1 \ --user $2 \ --project $3 \ $domain_args \ - | grep " $1 " | get_field 1) + | grep '^|\s[a-f0-9]\+' | get_field 1) fi echo $user_role_id } @@ -889,18 +891,20 @@ function get_or_add_user_domain_role { local user_role_id # Gets user role id user_role_id=$(openstack role assignment list \ + --role $1 \ --user $2 \ --domain $3 \ - | grep " $1 " | get_field 1) + | grep '^|\s[a-f0-9]\+' | get_field 1) if [[ -z "$user_role_id" ]]; then # Adds role to user and get it openstack role add $1 \ --user $2 \ --domain $3 user_role_id=$(openstack role assignment list \ + --role $1 \ --user $2 \ --domain $3 \ - | grep " $1 " | get_field 1) + | grep '^|\s[a-f0-9]\+' | get_field 1) fi echo $user_role_id } @@ -911,6 +915,7 @@ function get_or_add_group_project_role { local group_role_id # Gets group role id group_role_id=$(openstack role assignment list \ + --role $1 \ --group $2 \ --project $3 \ -f value) @@ -920,6 +925,7 @@ function get_or_add_group_project_role { --group $2 \ --project $3 group_role_id=$(openstack role assignment list \ + --role $1 \ --group $2 \ --project $3 \ -f value)