Browse code

Move keystone to lib/keystone

The next in a line of changes to break down stack.sh and make
it a bit more manageable.

Part of blueprint devstack-modular

Change-Id: I40405af07b776f045d6bf801f7e4f1ad863139ae

Dean Troyer authored on 2012/09/01 08:04:55
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,172 @@
0
+# lib/keystone
1
+# Functions to control the configuration and operation of **Keystone**
2
+
3
+# Dependencies:
4
+# ``functions`` file
5
+# ``BASE_SQL_CONN``
6
+# ``SERVICE_HOST``
7
+# ``SERVICE_TOKEN``
8
+# ``S3_SERVICE_PORT`` (template backend only)
9
+
10
+
11
+# ``stack.sh`` calls the entry points in this order:
12
+#
13
+# install_keystone
14
+# configure_keystone
15
+# init_keystone
16
+# start_keystone
17
+# stop_keystone
18
+# cleanup_keystone
19
+
20
+# Print the commands being run so that we can see the command that triggers
21
+# an error.  It is also useful for following along as the install occurs.
22
+set -o xtrace
23
+
24
+
25
+# Defaults
26
+# --------
27
+
28
+# <define global variables here that belong to this project>
29
+
30
+# Set up default directories
31
+KEYSTONE_DIR=$DEST/keystone
32
+KEYSTONE_CONF_DIR=${KEYSTONE_CONF_DIR:-/etc/keystone}
33
+KEYSTONE_CONF=$KEYSTONE_CONF_DIR/keystone.conf
34
+
35
+KEYSTONECLIENT_DIR=$DEST/python-keystoneclient
36
+
37
+# Select the backend for Keystopne's service catalog
38
+KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-template}
39
+KEYSTONE_CATALOG=$KEYSTONE_CONF_DIR/default_catalog.templates
40
+
41
+# Set Keystone interface configuration
42
+KEYSTONE_API_PORT=${KEYSTONE_API_PORT:-5000}
43
+KEYSTONE_AUTH_HOST=${KEYSTONE_AUTH_HOST:-$SERVICE_HOST}
44
+KEYSTONE_AUTH_PORT=${KEYSTONE_AUTH_PORT:-35357}
45
+KEYSTONE_AUTH_PROTOCOL=${KEYSTONE_AUTH_PROTOCOL:-http}
46
+KEYSTONE_SERVICE_HOST=${KEYSTONE_SERVICE_HOST:-$SERVICE_HOST}
47
+KEYSTONE_SERVICE_PORT=${KEYSTONE_SERVICE_PORT:-5000}
48
+KEYSTONE_SERVICE_PROTOCOL=${KEYSTONE_SERVICE_PROTOCOL:-http}
49
+
50
+
51
+# Entry Points
52
+# ------------
53
+
54
+# cleanup_keystone() - Remove residual data files, anything left over from previous
55
+# runs that a clean run would need to clean up
56
+function cleanup_keystone() {
57
+    # kill instances (nova)
58
+    # delete image files (glance)
59
+    # This function intentionally left blank
60
+    :
61
+}
62
+
63
+# configure_keystoneclient() - Set config files, create data dirs, etc
64
+function configure_keystoneclient() {
65
+    setup_develop $KEYSTONECLIENT_DIR
66
+}
67
+
68
+# configure_keystone() - Set config files, create data dirs, etc
69
+function configure_keystone() {
70
+    setup_develop $KEYSTONE_DIR
71
+
72
+    if [[ ! -d $KEYSTONE_CONF_DIR ]]; then
73
+        sudo mkdir -p $KEYSTONE_CONF_DIR
74
+        sudo chown `whoami` $KEYSTONE_CONF_DIR
75
+    fi
76
+
77
+    if [[ "$KEYSTONE_CONF_DIR" != "$KEYSTONE_DIR/etc" ]]; then
78
+        cp -p $KEYSTONE_DIR/etc/keystone.conf.sample $KEYSTONE_CONF
79
+        cp -p $KEYSTONE_DIR/etc/policy.json $KEYSTONE_CONF_DIR
80
+    fi
81
+
82
+    # Rewrite stock ``keystone.conf``
83
+    iniset $KEYSTONE_CONF DEFAULT admin_token "$SERVICE_TOKEN"
84
+    iniset $KEYSTONE_CONF sql connection "$BASE_SQL_CONN/keystone?charset=utf8"
85
+    iniset $KEYSTONE_CONF ec2 driver "keystone.contrib.ec2.backends.sql.Ec2"
86
+    sed -e "
87
+        /^pipeline.*ec2_extension crud_/s|ec2_extension crud_extension|ec2_extension s3_extension crud_extension|;
88
+    " -i $KEYSTONE_CONF
89
+
90
+    # Append the S3 bits
91
+    iniset $KEYSTONE_CONF filter:s3_extension paste.filter_factory "keystone.contrib.s3:S3Extension.factory"
92
+
93
+    if [[ "$KEYSTONE_CATALOG_BACKEND" = "sql" ]]; then
94
+        # Configure ``keystone.conf`` to use sql
95
+        iniset $KEYSTONE_CONF catalog driver keystone.catalog.backends.sql.Catalog
96
+        inicomment $KEYSTONE_CONF catalog template_file
97
+    else
98
+        cp -p $FILES/default_catalog.templates $KEYSTONE_CATALOG
99
+
100
+        # Add swift endpoints to service catalog if swift is enabled
101
+        if is_service_enabled swift; then
102
+            echo "catalog.RegionOne.object_store.publicURL = http://%SERVICE_HOST%:8080/v1/AUTH_\$(tenant_id)s" >> $KEYSTONE_CATALOG
103
+            echo "catalog.RegionOne.object_store.adminURL = http://%SERVICE_HOST%:8080/" >> $KEYSTONE_CATALOG
104
+            echo "catalog.RegionOne.object_store.internalURL = http://%SERVICE_HOST%:8080/v1/AUTH_\$(tenant_id)s" >> $KEYSTONE_CATALOG
105
+            echo "catalog.RegionOne.object_store.name = Swift Service" >> $KEYSTONE_CATALOG
106
+        fi
107
+
108
+        # Add quantum endpoints to service catalog if quantum is enabled
109
+        if is_service_enabled quantum; then
110
+            echo "catalog.RegionOne.network.publicURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
111
+            echo "catalog.RegionOne.network.adminURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
112
+            echo "catalog.RegionOne.network.internalURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
113
+            echo "catalog.RegionOne.network.name = Quantum Service" >> $KEYSTONE_CATALOG
114
+        fi
115
+
116
+        sudo sed -e "
117
+            s,%SERVICE_HOST%,$SERVICE_HOST,g;
118
+            s,%S3_SERVICE_PORT%,$S3_SERVICE_PORT,g;
119
+        " -i $KEYSTONE_CATALOG
120
+
121
+        # Configure ``keystone.conf`` to use templates
122
+        iniset $KEYSTONE_CONF catalog driver "keystone.catalog.backends.templated.TemplatedCatalog"
123
+        iniset $KEYSTONE_CONF catalog template_file "$KEYSTONE_CATALOG"
124
+    fi
125
+
126
+    # Set up logging
127
+    LOGGING_ROOT="devel"
128
+    if [ "$SYSLOG" != "False" ]; then
129
+        LOGGING_ROOT="$LOGGING_ROOT,production"
130
+    fi
131
+    KEYSTONE_LOG_CONFIG="--log-config $KEYSTONE_CONF_DIR/logging.conf"
132
+    cp $KEYSTONE_DIR/etc/logging.conf.sample $KEYSTONE_CONF_DIR/logging.conf
133
+    iniset $KEYSTONE_CONF_DIR/logging.conf logger_root level "DEBUG"
134
+    iniset $KEYSTONE_CONF_DIR/logging.conf logger_root handlers "devel,production"
135
+
136
+}
137
+
138
+# init_keystone() - Initialize databases, etc.
139
+function init_keystone() {
140
+    # (Re)create keystone database
141
+    mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS keystone;'
142
+    mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'CREATE DATABASE keystone CHARACTER SET utf8;'
143
+
144
+    # Initialize keystone database
145
+    $KEYSTONE_DIR/bin/keystone-manage db_sync
146
+
147
+    # Set up certificates
148
+    $KEYSTONE_DIR/bin/keystone-manage pki_setup
149
+}
150
+
151
+# install_keystoneclient() - Collect source and prepare
152
+function install_keystoneclient() {
153
+    git_clone $KEYSTONECLIENT_REPO $KEYSTONECLIENT_DIR $KEYSTONECLIENT_BRANCH
154
+}
155
+
156
+# install_keystone() - Collect source and prepare
157
+function install_keystone() {
158
+    git_clone $KEYSTONE_REPO $KEYSTONE_DIR $KEYSTONE_BRANCH
159
+}
160
+
161
+# start_keystone() - Start running processes, including screen
162
+function start_keystone() {
163
+    # Start Keystone in a screen window
164
+    screen_it key "cd $KEYSTONE_DIR && $KEYSTONE_DIR/bin/keystone-all --config-file $KEYSTONE_CONF $KEYSTONE_LOG_CONFIG -d --debug"
165
+}
166
+
167
+# stop_keystone() - Stop running processes
168
+function stop_keystone() {
169
+    # Kill the Keystone screen window
170
+    screen -S $SCREEN_NAME -p key -X kill
171
+}
... ...
@@ -262,10 +262,63 @@ sudo mkdir -p $DATA_DIR
262 262
 sudo chown `whoami` $DATA_DIR
263 263
 
264 264
 
265
+# Common Configuration
266
+# ====================
267
+
268
+# Set fixed and floating range here so we can make sure not to use addresses
269
+# from either range when attempting to guess the IP to use for the host.
270
+# Note that setting FIXED_RANGE may be necessary when running DevStack
271
+# in an OpenStack cloud that uses either of these address ranges internally.
272
+FLOATING_RANGE=${FLOATING_RANGE:-172.24.4.224/28}
273
+FIXED_RANGE=${FIXED_RANGE:-10.0.0.0/24}
274
+FIXED_NETWORK_SIZE=${FIXED_NETWORK_SIZE:-256}
275
+NETWORK_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1}
276
+
277
+# Find the interface used for the default route
278
+HOST_IP_IFACE=${HOST_IP_IFACE:-$(ip route | sed -n '/^default/{ s/.*dev \(\w\+\)\s\+.*/\1/; p; }')}
279
+# Search for an IP unless an explicit is set by ``HOST_IP`` environment variable
280
+if [ -z "$HOST_IP" -o "$HOST_IP" == "dhcp" ]; then
281
+    HOST_IP=""
282
+    HOST_IPS=`LC_ALL=C ip -f inet addr show ${HOST_IP_IFACE} | awk '/inet/ {split($2,parts,"/");  print parts[1]}'`
283
+    for IP in $HOST_IPS; do
284
+        # Attempt to filter out IP addresses that are part of the fixed and
285
+        # floating range. Note that this method only works if the ``netaddr``
286
+        # python library is installed. If it is not installed, an error
287
+        # will be printed and the first IP from the interface will be used.
288
+        # If that is not correct set ``HOST_IP`` in ``localrc`` to the correct
289
+        # address.
290
+        if ! (address_in_net $IP $FIXED_RANGE || address_in_net $IP $FLOATING_RANGE); then
291
+            HOST_IP=$IP
292
+            break;
293
+        fi
294
+    done
295
+    if [ "$HOST_IP" == "" ]; then
296
+        echo "Could not determine host ip address."
297
+        echo "Either localrc specified dhcp on ${HOST_IP_IFACE} or defaulted"
298
+        exit 1
299
+    fi
300
+fi
301
+
302
+# Allow the use of an alternate hostname (such as localhost/127.0.0.1) for service endpoints.
303
+SERVICE_HOST=${SERVICE_HOST:-$HOST_IP}
304
+
305
+# Configure services to use syslog instead of writing to individual log files
306
+SYSLOG=`trueorfalse False $SYSLOG`
307
+SYSLOG_HOST=${SYSLOG_HOST:-$HOST_IP}
308
+SYSLOG_PORT=${SYSLOG_PORT:-516}
309
+
310
+# Use color for logging output (only available if syslog is not used)
311
+LOG_COLOR=`trueorfalse True $LOG_COLOR`
312
+
313
+# Service startup timeout
314
+SERVICE_TIMEOUT=${SERVICE_TIMEOUT:-60}
315
+
316
+
265 317
 # Configure Projects
266 318
 # ==================
267 319
 
268 320
 # Get project function libraries
321
+source $TOP_DIR/lib/keystone
269 322
 source $TOP_DIR/lib/cinder
270 323
 source $TOP_DIR/lib/n-vol
271 324
 source $TOP_DIR/lib/ceilometer
... ...
@@ -277,9 +330,7 @@ NOVA_DIR=$DEST/nova
277 277
 HORIZON_DIR=$DEST/horizon
278 278
 GLANCE_DIR=$DEST/glance
279 279
 GLANCECLIENT_DIR=$DEST/python-glanceclient
280
-KEYSTONE_DIR=$DEST/keystone
281 280
 NOVACLIENT_DIR=$DEST/python-novaclient
282
-KEYSTONECLIENT_DIR=$DEST/python-keystoneclient
283 281
 OPENSTACKCLIENT_DIR=$DEST/python-openstackclient
284 282
 NOVNC_DIR=$DEST/noVNC
285 283
 SWIFT_DIR=$DEST/swift
... ...
@@ -313,52 +364,6 @@ INSTANCE_NAME_PREFIX=${INSTANCE_NAME_PREFIX:-instance-}
313 313
 # should work in most cases.
314 314
 SCHEDULER=${SCHEDULER:-nova.scheduler.filter_scheduler.FilterScheduler}
315 315
 
316
-# Set fixed and floating range here so we can make sure not to use addresses
317
-# from either range when attempting to guess the IP to use for the host.
318
-# Note that setting FIXED_RANGE may be necessary when running DevStack
319
-# in an OpenStack cloud that uses eith of these address ranges internally.
320
-FIXED_RANGE=${FIXED_RANGE:-10.0.0.0/24}
321
-FLOATING_RANGE=${FLOATING_RANGE:-172.24.4.224/28}
322
-
323
-# Find the interface used for the default route
324
-HOST_IP_IFACE=${HOST_IP_IFACE:-$(ip route | sed -n '/^default/{ s/.*dev \(\w\+\)\s\+.*/\1/; p; }')}
325
-# Search for an IP unless an explicit is set by ``HOST_IP`` environment variable
326
-if [ -z "$HOST_IP" -o "$HOST_IP" == "dhcp" ]; then
327
-    HOST_IP=""
328
-    HOST_IPS=`LC_ALL=C ip -f inet addr show ${HOST_IP_IFACE} | awk '/inet/ {split($2,parts,"/");  print parts[1]}'`
329
-    for IP in $HOST_IPS; do
330
-        # Attempt to filter out IP addresses that are part of the fixed and
331
-        # floating range. Note that this method only works if the ``netaddr``
332
-        # python library is installed. If it is not installed, an error
333
-        # will be printed and the first IP from the interface will be used.
334
-        # If that is not correct set ``HOST_IP`` in ``localrc`` to the correct
335
-        # address.
336
-        if ! (address_in_net $IP $FIXED_RANGE || address_in_net $IP $FLOATING_RANGE); then
337
-            HOST_IP=$IP
338
-            break;
339
-        fi
340
-    done
341
-    if [ "$HOST_IP" == "" ]; then
342
-        echo "Could not determine host ip address."
343
-        echo "Either localrc specified dhcp on ${HOST_IP_IFACE} or defaulted"
344
-        exit 1
345
-    fi
346
-fi
347
-
348
-# Allow the use of an alternate hostname (such as localhost/127.0.0.1) for service endpoints.
349
-SERVICE_HOST=${SERVICE_HOST:-$HOST_IP}
350
-
351
-# Configure services to use syslog instead of writing to individual log files
352
-SYSLOG=`trueorfalse False $SYSLOG`
353
-SYSLOG_HOST=${SYSLOG_HOST:-$HOST_IP}
354
-SYSLOG_PORT=${SYSLOG_PORT:-516}
355
-
356
-# Use color for logging output (only available if syslog is not used)
357
-LOG_COLOR=`trueorfalse True $LOG_COLOR`
358
-
359
-# Service startup timeout
360
-SERVICE_TIMEOUT=${SERVICE_TIMEOUT:-60}
361
-
362 316
 # Generic helper to configure passwords
363 317
 function read_password {
364 318
     set +o xtrace
... ...
@@ -419,8 +424,6 @@ else
419 419
 fi
420 420
 
421 421
 PUBLIC_INTERFACE=${PUBLIC_INTERFACE:-$PUBLIC_INTERFACE_DEFAULT}
422
-FIXED_NETWORK_SIZE=${FIXED_NETWORK_SIZE:-256}
423
-NETWORK_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1}
424 422
 NET_MAN=${NET_MAN:-FlatDHCPManager}
425 423
 EC2_DMZ_HOST=${EC2_DMZ_HOST:-$SERVICE_HOST}
426 424
 FLAT_NETWORK_BRIDGE=${FLAT_NETWORK_BRIDGE:-$FLAT_NETWORK_BRIDGE_DEFAULT}
... ...
@@ -568,14 +571,6 @@ read_password ADMIN_PASSWORD "ENTER A PASSWORD TO USE FOR HORIZON AND KEYSTONE (
568 568
 # Set the tenant for service accounts in Keystone
569 569
 SERVICE_TENANT_NAME=${SERVICE_TENANT_NAME:-service}
570 570
 
571
-# Set Keystone interface configuration
572
-KEYSTONE_API_PORT=${KEYSTONE_API_PORT:-5000}
573
-KEYSTONE_AUTH_HOST=${KEYSTONE_AUTH_HOST:-$SERVICE_HOST}
574
-KEYSTONE_AUTH_PORT=${KEYSTONE_AUTH_PORT:-35357}
575
-KEYSTONE_AUTH_PROTOCOL=${KEYSTONE_AUTH_PROTOCOL:-http}
576
-KEYSTONE_SERVICE_HOST=${KEYSTONE_SERVICE_HOST:-$SERVICE_HOST}
577
-KEYSTONE_SERVICE_PORT=${KEYSTONE_SERVICE_PORT:-5000}
578
-KEYSTONE_SERVICE_PROTOCOL=${KEYSTONE_SERVICE_PROTOCOL:-http}
579 571
 
580 572
 
581 573
 # Horizon
... ...
@@ -791,10 +786,11 @@ pip_install $(get_packages $FILES/pips | sort -u)
791 791
 # Check Out Source
792 792
 # ----------------
793 793
 
794
+install_keystoneclient
795
+
794 796
 git_clone $NOVA_REPO $NOVA_DIR $NOVA_BRANCH
795 797
 
796 798
 # Check out the client libs that are used most
797
-git_clone $KEYSTONECLIENT_REPO $KEYSTONECLIENT_DIR $KEYSTONECLIENT_BRANCH
798 799
 git_clone $NOVACLIENT_REPO $NOVACLIENT_DIR $NOVACLIENT_BRANCH
799 800
 git_clone $OPENSTACKCLIENT_REPO $OPENSTACKCLIENT_DIR $OPENSTACKCLIENT_BRANCH
800 801
 git_clone $GLANCECLIENT_REPO $GLANCECLIENT_DIR $GLANCECLIENT_BRANCH
... ...
@@ -802,7 +798,7 @@ git_clone $GLANCECLIENT_REPO $GLANCECLIENT_DIR $GLANCECLIENT_BRANCH
802 802
 # glance, swift middleware and nova api needs keystone middleware
803 803
 if is_service_enabled key g-api n-api swift; then
804 804
     # unified auth system (manages accounts/tokens)
805
-    git_clone $KEYSTONE_REPO $KEYSTONE_DIR $KEYSTONE_BRANCH
805
+    install_keystone
806 806
 fi
807 807
 if is_service_enabled swift; then
808 808
     # storage service
... ...
@@ -849,11 +845,11 @@ fi
849 849
 
850 850
 # Set up our checkouts so they are installed into python path
851 851
 # allowing ``import nova`` or ``import glance.client``
852
-setup_develop $KEYSTONECLIENT_DIR
852
+configure_keystoneclient
853 853
 setup_develop $NOVACLIENT_DIR
854 854
 setup_develop $OPENSTACKCLIENT_DIR
855 855
 if is_service_enabled key g-api n-api swift; then
856
-    setup_develop $KEYSTONE_DIR
856
+    configure_keystone
857 857
 fi
858 858
 if is_service_enabled swift; then
859 859
     setup_develop $SWIFT_DIR
... ...
@@ -984,6 +980,36 @@ sleep 1
984 984
 screen -r $SCREEN_NAME -X hardstatus alwayslastline "$SCREEN_HARDSTATUS"
985 985
 
986 986
 
987
+# Keystone
988
+# --------
989
+
990
+if is_service_enabled key; then
991
+    configure_keystone
992
+    init_keystone
993
+    start_keystone
994
+    echo "Waiting for keystone to start..."
995
+    if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= curl -s $KEYSTONE_AUTH_PROTOCOL://$SERVICE_HOST:$KEYSTONE_API_PORT/v2.0/ >/dev/null; do sleep 1; done"; then
996
+      echo "keystone did not start"
997
+      exit 1
998
+    fi
999
+
1000
+    # ``keystone_data.sh`` creates services, admin and demo users, and roles.
1001
+    SERVICE_ENDPOINT=$KEYSTONE_AUTH_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0
1002
+
1003
+    ADMIN_PASSWORD=$ADMIN_PASSWORD SERVICE_TENANT_NAME=$SERVICE_TENANT_NAME SERVICE_PASSWORD=$SERVICE_PASSWORD \
1004
+    SERVICE_TOKEN=$SERVICE_TOKEN SERVICE_ENDPOINT=$SERVICE_ENDPOINT SERVICE_HOST=$SERVICE_HOST \
1005
+    S3_SERVICE_PORT=$S3_SERVICE_PORT KEYSTONE_CATALOG_BACKEND=$KEYSTONE_CATALOG_BACKEND \
1006
+    DEVSTACK_DIR=$TOP_DIR ENABLED_SERVICES=$ENABLED_SERVICES HEAT_API_PORT=$HEAT_API_PORT \
1007
+        bash -x $FILES/keystone_data.sh
1008
+
1009
+    # Set up auth creds now that keystone is bootstrapped
1010
+    export OS_AUTH_URL=$SERVICE_ENDPOINT
1011
+    export OS_TENANT_NAME=admin
1012
+    export OS_USERNAME=admin
1013
+    export OS_PASSWORD=$ADMIN_PASSWORD
1014
+fi
1015
+
1016
+
987 1017
 # Horizon
988 1018
 # -------
989 1019
 
... ...
@@ -2113,118 +2139,16 @@ if is_service_enabled g-api; then
2113 2113
     fi
2114 2114
 fi
2115 2115
 
2116
-if is_service_enabled key; then
2117
-    # (Re)create keystone database
2118
-    mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS keystone;'
2119
-    mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'CREATE DATABASE keystone CHARACTER SET utf8;'
2120
-
2121
-    KEYSTONE_CONF_DIR=${KEYSTONE_CONF_DIR:-/etc/keystone}
2122
-    KEYSTONE_CONF=$KEYSTONE_CONF_DIR/keystone.conf
2123
-    KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-template}
2124
-
2125
-    if [[ ! -d $KEYSTONE_CONF_DIR ]]; then
2126
-        sudo mkdir -p $KEYSTONE_CONF_DIR
2127
-        sudo chown `whoami` $KEYSTONE_CONF_DIR
2128
-    fi
2129
-
2130
-    if [[ "$KEYSTONE_CONF_DIR" != "$KEYSTONE_DIR/etc" ]]; then
2131
-        cp -p $KEYSTONE_DIR/etc/keystone.conf.sample $KEYSTONE_CONF
2132
-        cp -p $KEYSTONE_DIR/etc/policy.json $KEYSTONE_CONF_DIR
2133
-    fi
2134
-
2135
-    # Rewrite stock ``keystone.conf``
2136
-    iniset $KEYSTONE_CONF DEFAULT admin_token "$SERVICE_TOKEN"
2137
-    iniset $KEYSTONE_CONF sql connection "$BASE_SQL_CONN/keystone?charset=utf8"
2138
-    iniset $KEYSTONE_CONF ec2 driver "keystone.contrib.ec2.backends.sql.Ec2"
2139
-    sed -e "
2140
-        /^pipeline.*ec2_extension crud_/s|ec2_extension crud_extension|ec2_extension s3_extension crud_extension|;
2141
-    " -i $KEYSTONE_CONF
2142
-    # Append the S3 bits
2143
-    iniset $KEYSTONE_CONF filter:s3_extension paste.filter_factory "keystone.contrib.s3:S3Extension.factory"
2144
-
2145
-    if [[ "$KEYSTONE_CATALOG_BACKEND" = "sql" ]]; then
2146
-        # Configure ``keystone.conf`` to use sql
2147
-        iniset $KEYSTONE_CONF catalog driver keystone.catalog.backends.sql.Catalog
2148
-        inicomment $KEYSTONE_CONF catalog template_file
2149
-    else
2150
-        KEYSTONE_CATALOG=$KEYSTONE_CONF_DIR/default_catalog.templates
2151
-        cp -p $FILES/default_catalog.templates $KEYSTONE_CATALOG
2152
-
2153
-        # Add swift endpoints to service catalog if swift is enabled
2154
-        if is_service_enabled swift; then
2155
-            echo "catalog.RegionOne.object_store.publicURL = http://%SERVICE_HOST%:8080/v1/AUTH_\$(tenant_id)s" >> $KEYSTONE_CATALOG
2156
-            echo "catalog.RegionOne.object_store.adminURL = http://%SERVICE_HOST%:8080/" >> $KEYSTONE_CATALOG
2157
-            echo "catalog.RegionOne.object_store.internalURL = http://%SERVICE_HOST%:8080/v1/AUTH_\$(tenant_id)s" >> $KEYSTONE_CATALOG
2158
-            echo "catalog.RegionOne.object_store.name = Swift Service" >> $KEYSTONE_CATALOG
2159
-        fi
2160
-
2161
-        # Add quantum endpoints to service catalog if quantum is enabled
2162
-        if is_service_enabled quantum; then
2163
-            echo "catalog.RegionOne.network.publicURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
2164
-            echo "catalog.RegionOne.network.adminURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
2165
-            echo "catalog.RegionOne.network.internalURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
2166
-            echo "catalog.RegionOne.network.name = Quantum Service" >> $KEYSTONE_CATALOG
2167
-        fi
2168
-
2169
-        sudo sed -e "
2170
-            s,%SERVICE_HOST%,$SERVICE_HOST,g;
2171
-            s,%S3_SERVICE_PORT%,$S3_SERVICE_PORT,g;
2172
-        " -i $KEYSTONE_CATALOG
2173
-
2174
-        # Configure ``keystone.conf`` to use templates
2175
-        iniset $KEYSTONE_CONF catalog driver "keystone.catalog.backends.templated.TemplatedCatalog"
2176
-        iniset $KEYSTONE_CONF catalog template_file "$KEYSTONE_CATALOG"
2177
-    fi
2178
-
2179
-    # Set up logging
2180
-    LOGGING_ROOT="devel"
2181
-    if [ "$SYSLOG" != "False" ]; then
2182
-        LOGGING_ROOT="$LOGGING_ROOT,production"
2183
-    fi
2184
-    KEYSTONE_LOG_CONFIG="--log-config $KEYSTONE_CONF_DIR/logging.conf"
2185
-    cp $KEYSTONE_DIR/etc/logging.conf.sample $KEYSTONE_CONF_DIR/logging.conf
2186
-    iniset $KEYSTONE_CONF_DIR/logging.conf logger_root level "DEBUG"
2187
-    iniset $KEYSTONE_CONF_DIR/logging.conf logger_root handlers "devel,production"
2188
-
2189
-    # Initialize keystone database
2190
-    $KEYSTONE_DIR/bin/keystone-manage db_sync
2191
-
2192
-    # Set up certificates
2193
-    $KEYSTONE_DIR/bin/keystone-manage pki_setup
2194
-
2195
-    # Launch keystone and wait for it to answer before continuing
2196
-    screen_it key "cd $KEYSTONE_DIR && $KEYSTONE_DIR/bin/keystone-all --config-file $KEYSTONE_CONF $KEYSTONE_LOG_CONFIG -d --debug"
2197
-    echo "Waiting for keystone to start..."
2198
-    if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= curl -s $KEYSTONE_AUTH_PROTOCOL://$SERVICE_HOST:$KEYSTONE_API_PORT/v2.0/ >/dev/null; do sleep 1; done"; then
2199
-      echo "keystone did not start"
2200
-      exit 1
2201
-    fi
2202
-    # ``keystone_data.sh`` creates services, admin and demo users, and roles.
2203
-    SERVICE_ENDPOINT=$KEYSTONE_AUTH_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0
2204
-
2205
-    ADMIN_PASSWORD=$ADMIN_PASSWORD SERVICE_TENANT_NAME=$SERVICE_TENANT_NAME SERVICE_PASSWORD=$SERVICE_PASSWORD \
2206
-    SERVICE_TOKEN=$SERVICE_TOKEN SERVICE_ENDPOINT=$SERVICE_ENDPOINT SERVICE_HOST=$SERVICE_HOST \
2207
-    S3_SERVICE_PORT=$S3_SERVICE_PORT KEYSTONE_CATALOG_BACKEND=$KEYSTONE_CATALOG_BACKEND \
2208
-    DEVSTACK_DIR=$TOP_DIR ENABLED_SERVICES=$ENABLED_SERVICES HEAT_API_PORT=$HEAT_API_PORT \
2209
-        bash -x $FILES/keystone_data.sh
2210
-
2211
-    # Set up auth creds now that keystone is bootstrapped
2212
-    export OS_AUTH_URL=$SERVICE_ENDPOINT
2213
-    export OS_TENANT_NAME=admin
2214
-    export OS_USERNAME=admin
2215
-    export OS_PASSWORD=$ADMIN_PASSWORD
2216
-
2217
-    # Create an access key and secret key for nova ec2 register image
2218
-    if is_service_enabled swift3 && is_service_enabled nova; then
2219
-        NOVA_USER_ID=$(keystone user-list | grep ' nova ' | get_field 1)
2220
-        NOVA_TENANT_ID=$(keystone tenant-list | grep " $SERVICE_TENANT_NAME " | get_field 1)
2221
-        CREDS=$(keystone ec2-credentials-create --user_id $NOVA_USER_ID --tenant_id $NOVA_TENANT_ID)
2222
-        ACCESS_KEY=$(echo "$CREDS" | awk '/ access / { print $4 }')
2223
-        SECRET_KEY=$(echo "$CREDS" | awk '/ secret / { print $4 }')
2224
-        add_nova_opt "s3_access_key=$ACCESS_KEY"
2225
-        add_nova_opt "s3_secret_key=$SECRET_KEY"
2226
-        add_nova_opt "s3_affix_tenant=True"
2227
-    fi
2116
+# Create an access key and secret key for nova ec2 register image
2117
+if is_service_enabled key && is_service_enabled swift3 && is_service_enabled nova; then
2118
+    NOVA_USER_ID=$(keystone user-list | grep ' nova ' | get_field 1)
2119
+    NOVA_TENANT_ID=$(keystone tenant-list | grep " $SERVICE_TENANT_NAME " | get_field 1)
2120
+    CREDS=$(keystone ec2-credentials-create --user_id $NOVA_USER_ID --tenant_id $NOVA_TENANT_ID)
2121
+    ACCESS_KEY=$(echo "$CREDS" | awk '/ access / { print $4 }')
2122
+    SECRET_KEY=$(echo "$CREDS" | awk '/ secret / { print $4 }')
2123
+    add_nova_opt "s3_access_key=$ACCESS_KEY"
2124
+    add_nova_opt "s3_secret_key=$SECRET_KEY"
2125
+    add_nova_opt "s3_affix_tenant=True"
2228 2126
 fi
2229 2127
 
2230 2128
 screen_it zeromq "cd $NOVA_DIR && $NOVA_DIR/bin/nova-rpc-zmq-receiver"