Browse code

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

Clark Boylan authored on 2017/06/15 07:29:47
Showing 1 changed files
... ...
@@ -864,10 +864,11 @@ function get_or_add_user_project_role {
864 864
 
865 865
     # Gets user role id
866 866
     user_role_id=$(openstack role assignment list \
867
+        --role $1 \
867 868
         --user $2 \
868 869
         --project $3 \
869 870
         $domain_args \
870
-        | grep " $1 " | get_field 1)
871
+        | grep '^|\s[a-f0-9]\+' | get_field 1)
871 872
     if [[ -z "$user_role_id" ]]; then
872 873
         # Adds role to user and get it
873 874
         openstack role add $1 \
... ...
@@ -875,10 +876,11 @@ function get_or_add_user_project_role {
875 875
             --project $3 \
876 876
             $domain_args
877 877
         user_role_id=$(openstack role assignment list \
878
+            --role $1 \
878 879
             --user $2 \
879 880
             --project $3 \
880 881
             $domain_args \
881
-            | grep " $1 " | get_field 1)
882
+            | grep '^|\s[a-f0-9]\+' | get_field 1)
882 883
     fi
883 884
     echo $user_role_id
884 885
 }
... ...
@@ -889,18 +891,20 @@ function get_or_add_user_domain_role {
889 889
     local user_role_id
890 890
     # Gets user role id
891 891
     user_role_id=$(openstack role assignment list \
892
+        --role $1 \
892 893
         --user $2 \
893 894
         --domain $3 \
894
-        | grep " $1 " | get_field 1)
895
+        | grep '^|\s[a-f0-9]\+' | get_field 1)
895 896
     if [[ -z "$user_role_id" ]]; then
896 897
         # Adds role to user and get it
897 898
         openstack role add $1 \
898 899
             --user $2 \
899 900
             --domain $3
900 901
         user_role_id=$(openstack role assignment list \
902
+            --role $1 \
901 903
             --user $2 \
902 904
             --domain $3 \
903
-            | grep " $1 " | get_field 1)
905
+            | grep '^|\s[a-f0-9]\+' | get_field 1)
904 906
     fi
905 907
     echo $user_role_id
906 908
 }
... ...
@@ -911,6 +915,7 @@ function get_or_add_group_project_role {
911 911
     local group_role_id
912 912
     # Gets group role id
913 913
     group_role_id=$(openstack role assignment list \
914
+        --role $1 \
914 915
         --group $2 \
915 916
         --project $3 \
916 917
         -f value)
... ...
@@ -920,6 +925,7 @@ function get_or_add_group_project_role {
920 920
             --group $2 \
921 921
             --project $3
922 922
         group_role_id=$(openstack role assignment list \
923
+            --role $1 \
923 924
             --group $2 \
924 925
             --project $3 \
925 926
             -f value)