Browse code

Make keystone_data.sh handle existing and updated keystone client

Keystone client commands and options have been normalized and
keystone_data.sh needs to support both versions for a transition
period.

The merge prop for the updated keystone client is
https://review.openstack.org/4375

Necessary for bug 396422

Also fix an intermittent problem extacting IDs from command output.

Change-Id: Ib13445a0bd3029fb02b0b7a86e8e0b8278717b57

Dean Troyer authored on 2012/02/24 02:21:10
Showing 1 changed files
... ...
@@ -4,9 +4,18 @@ export SERVICE_TOKEN=$SERVICE_TOKEN
4 4
 export SERVICE_ENDPOINT=$SERVICE_ENDPOINT
5 5
 
6 6
 function get_id () {
7
-    echo `$@ | grep id | awk '{print $4}'`
7
+    echo `$@ | grep ' id ' | awk '{print $4}'`
8 8
 }
9 9
 
10
+# Detect if the keystone cli binary has the command names changed
11
+# in https://review.openstack.org/4375
12
+# FIXME(dtroyer): Remove the keystone client command checking
13
+#                 after a suitable transition period.  add-user-role
14
+#                 and ec2-create-credentials were renamed
15
+if keystone help | grep -q user-role-add; then
16
+    KEYSTONE_COMMAND_4375=1
17
+fi
18
+
10 19
 ADMIN_TENANT=`get_id keystone tenant-create --name=admin`
11 20
 DEMO_TENANT=`get_id keystone tenant-create --name=demo`
12 21
 INVIS_TENANT=`get_id keystone tenant-create --name=invisible_to_admin`
... ...
@@ -31,17 +40,33 @@ SYSADMIN_ROLE=`get_id keystone role-create --name=sysadmin`
31 31
 NETADMIN_ROLE=`get_id keystone role-create --name=netadmin`
32 32
 
33 33
 
34
-# Add Roles to Users in Tenants
35
-keystone add-user-role $ADMIN_USER $ADMIN_ROLE $ADMIN_TENANT
36
-keystone add-user-role $DEMO_USER $MEMBER_ROLE $DEMO_TENANT
37
-keystone add-user-role $DEMO_USER $SYSADMIN_ROLE $DEMO_TENANT
38
-keystone add-user-role $DEMO_USER $NETADMIN_ROLE $DEMO_TENANT
39
-keystone add-user-role $DEMO_USER $MEMBER_ROLE $INVIS_TENANT
40
-keystone add-user-role $ADMIN_USER $ADMIN_ROLE $DEMO_TENANT
41
-
42
-# TODO(termie): these two might be dubious
43
-keystone add-user-role $ADMIN_USER $KEYSTONEADMIN_ROLE $ADMIN_TENANT
44
-keystone add-user-role $ADMIN_USER $KEYSTONESERVICE_ROLE $ADMIN_TENANT
34
+if [[ -n "$KEYSTONE_COMMAND_4375" ]]; then
35
+    # Add Roles to Users in Tenants
36
+    keystone user-role-add --user $ADMIN_USER --role $ADMIN_ROLE --tenant_id $ADMIN_TENANT
37
+    keystone user-role-add --user $DEMO_USER --role $MEMBER_ROLE --tenant_id $DEMO_TENANT
38
+    keystone user-role-add --user $DEMO_USER --role $SYSADMIN_ROLE --tenant_id $DEMO_TENANT
39
+    keystone user-role-add --user $DEMO_USER --role $NETADMIN_ROLE --tenant_id $DEMO_TENANT
40
+    keystone user-role-add --user $DEMO_USER --role $MEMBER_ROLE --tenant_id $INVIS_TENANT
41
+    keystone user-role-add --user $ADMIN_USER --role $ADMIN_ROLE --tenant_id $DEMO_TENANT
42
+
43
+    # TODO(termie): these two might be dubious
44
+    keystone user-role-add --user $ADMIN_USER --role $KEYSTONEADMIN_ROLE --tenant_id $ADMIN_TENANT
45
+    keystone user-role-add --user $ADMIN_USER --role $KEYSTONESERVICE_ROLE --tenant_id $ADMIN_TENANT
46
+else
47
+    ### compat
48
+    # Add Roles to Users in Tenants
49
+    keystone add-user-role $ADMIN_USER $ADMIN_ROLE $ADMIN_TENANT
50
+    keystone add-user-role $DEMO_USER $MEMBER_ROLE $DEMO_TENANT
51
+    keystone add-user-role $DEMO_USER $SYSADMIN_ROLE $DEMO_TENANT
52
+    keystone add-user-role $DEMO_USER $NETADMIN_ROLE $DEMO_TENANT
53
+    keystone add-user-role $DEMO_USER $MEMBER_ROLE $INVIS_TENANT
54
+    keystone add-user-role $ADMIN_USER $ADMIN_ROLE $DEMO_TENANT
55
+
56
+    # TODO(termie): these two might be dubious
57
+    keystone add-user-role $ADMIN_USER $KEYSTONEADMIN_ROLE $ADMIN_TENANT
58
+    keystone add-user-role $ADMIN_USER $KEYSTONESERVICE_ROLE $ADMIN_TENANT
59
+    ###
60
+fi
45 61
 
46 62
 # Services
47 63
 keystone service-create \
... ...
@@ -77,13 +102,21 @@ if [[ "$ENABLED_SERVICES" =~ "quantum" ]]; then
77 77
 fi
78 78
 
79 79
 # create ec2 creds and parse the secret and access key returned
80
-RESULT=`keystone ec2-create-credentials --tenant_id=$ADMIN_TENANT --user_id=$ADMIN_USER`
80
+if [[ -n "$KEYSTONE_COMMAND_4375" ]]; then
81
+    RESULT=`keystone ec2-credentials-create --tenant_id=$ADMIN_TENANT --user=$ADMIN_USER`
82
+else
83
+    RESULT=`keystone ec2-create-credentials --tenant_id=$ADMIN_TENANT --user_id=$ADMIN_USER`
84
+fi
81 85
     echo `$@ | grep id | awk '{print $4}'`
82 86
 ADMIN_ACCESS=`echo "$RESULT" | grep access | awk '{print $4}'`
83 87
 ADMIN_SECRET=`echo "$RESULT" | grep secret | awk '{print $4}'`
84 88
 
85 89
 
86
-RESULT=`keystone ec2-create-credentials --tenant_id=$DEMO_TENANT --user_id=$DEMO_USER`
90
+if [[ -n "$KEYSTONE_COMMAND_4375" ]]; then
91
+    RESULT=`keystone ec2-credentials-create --tenant_id=$DEMO_TENANT --user=$DEMO_USER`
92
+else
93
+    RESULT=`keystone ec2-create-credentials --tenant_id=$DEMO_TENANT --user_id=$DEMO_USER`
94
+fi
87 95
 DEMO_ACCESS=`echo "$RESULT" | grep access | awk '{print $4}'`
88 96
 DEMO_SECRET=`echo "$RESULT" | grep secret | awk '{print $4}'`
89 97