Browse code

Merge "Add toggle to run Cinder API under Apache"

Jenkins authored on 2015/10/01 06:24:38
Showing 3 changed files
... ...
@@ -298,6 +298,12 @@ Example (Swift):
298 298
     SWIFT_USE_MOD_WSGI="True"
299 299
 
300 300
 
301
+Example (Cinder):
302
+
303
+::
304
+
305
+    CINDER_USE_MOD_WSGI="True"
306
+
301 307
 
302 308
 Libraries from Git
303 309
 ------------------
304 310
new file mode 100644
... ...
@@ -0,0 +1,26 @@
0
+Listen %PUBLICPORT%
1
+
2
+<VirtualHost *:%PUBLICPORT%>
3
+    WSGIDaemonProcess osapi_volume processes=%APIWORKERS% threads=1 user=%USER% display-name=%{GROUP} %VIRTUALENV%
4
+    WSGIProcessGroup osapi_volume
5
+    WSGIScriptAlias / %CINDER_BIN_DIR%/cinder-wsgi
6
+    WSGIApplicationGroup %{GLOBAL}
7
+    WSGIPassAuthorization On
8
+    <IfVersion >= 2.4>
9
+      ErrorLogFormat "%{cu}t %M"
10
+    </IfVersion>
11
+    ErrorLog /var/log/%APACHE_NAME%/c-api.log
12
+    %SSLENGINE%
13
+    %SSLCERTFILE%
14
+    %SSLKEYFILE%
15
+
16
+    <Directory %CINDER_BIN_DIR%>
17
+        <IfVersion >= 2.4>
18
+            Require all granted
19
+        </IfVersion>
20
+        <IfVersion < 2.4>
21
+            Order allow,deny
22
+            Allow from all
23
+        </IfVersion>
24
+    </Directory>
25
+</VirtualHost>
... ...
@@ -108,6 +108,8 @@ CINDER_PERIODIC_INTERVAL=${CINDER_PERIODIC_INTERVAL:-60}
108 108
 
109 109
 CINDER_ISCSI_HELPER=${CINDER_ISCSI_HELPER:-tgtadm}
110 110
 
111
+# Toggle for deploying Cinder under HTTPD + mod_wsgi
112
+CINDER_USE_MOD_WSGI=${CINDER_USE_MOD_WSGI:-False}
111 113
 
112 114
 # Source the enabled backends
113 115
 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
... ...
@@ -137,6 +139,11 @@ function is_cinder_enabled {
137 137
     return 1
138 138
 }
139 139
 
140
+# _cinder_cleanup_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
141
+function _cinder_cleanup_apache_wsgi {
142
+    sudo rm -f $(apache_site_config_for osapi-volume)
143
+}
144
+
140 145
 # cleanup_cinder() - Remove residual data files, anything left over from previous
141 146
 # runs that a clean run would need to clean up
142 147
 function cleanup_cinder {
... ...
@@ -183,6 +190,43 @@ function cleanup_cinder {
183 183
             fi
184 184
         done
185 185
     fi
186
+
187
+    if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
188
+        _cinder_cleanup_apache_wsgi
189
+    fi
190
+}
191
+
192
+# _cinder_config_apache_wsgi() - Set WSGI config files
193
+function _cinder_config_apache_wsgi {
194
+    local cinder_apache_conf=$(apache_site_config_for osapi-volume)
195
+    local cinder_ssl=""
196
+    local cinder_certfile=""
197
+    local cinder_keyfile=""
198
+    local cinder_api_port=$CINDER_SERVICE_PORT
199
+    local venv_path=""
200
+
201
+    if is_ssl_enabled_service c-api; then
202
+        cinder_ssl="SSLEngine On"
203
+        cinder_certfile="SSLCertificateFile $CINDER_SSL_CERT"
204
+        cinder_keyfile="SSLCertificateKeyFile $CINDER_SSL_KEY"
205
+    fi
206
+    if [[ ${USE_VENV} = True ]]; then
207
+        venv_path="python-path=${PROJECT_VENV["cinder"]}/lib/python2.7/site-packages"
208
+    fi
209
+
210
+    # copy proxy vhost file
211
+    sudo cp $FILES/apache-cinder-api.template $cinder_apache_conf
212
+    sudo sed -e "
213
+        s|%PUBLICPORT%|$cinder_api_port|g;
214
+        s|%APACHE_NAME%|$APACHE_NAME|g;
215
+        s|%APIWORKERS%|$API_WORKERS|g
216
+        s|%CINDER_BIN_DIR%|$CINDER_BIN_DIR|g;
217
+        s|%SSLENGINE%|$cinder_ssl|g;
218
+        s|%SSLCERTFILE%|$cinder_certfile|g;
219
+        s|%SSLKEYFILE%|$cinder_keyfile|g;
220
+        s|%USER%|$STACK_USER|g;
221
+        s|%VIRTUALENV%|$venv_path|g
222
+    " -i $cinder_apache_conf
186 223
 }
187 224
 
188 225
 # configure_cinder() - Set config files, create data dirs, etc
... ...
@@ -276,13 +320,17 @@ function configure_cinder {
276 276
     fi
277 277
 
278 278
     # Format logging
279
-    if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
279
+    if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ] && [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
280 280
         setup_colorized_logging $CINDER_CONF DEFAULT "project_id" "user_id"
281 281
     else
282 282
         # Set req-id, project-name and resource in log format
283 283
         iniset $CINDER_CONF DEFAULT logging_context_format_string "%(asctime)s.%(msecs)03d %(levelname)s %(name)s [%(request_id)s %(project_name)s] %(resource)s%(message)s"
284 284
     fi
285 285
 
286
+    if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
287
+        _cinder_config_apache_wsgi
288
+    fi
289
+
286 290
     if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
287 291
         configure_cinder_driver
288 292
     fi
... ...
@@ -399,6 +447,13 @@ function install_cinder {
399 399
             install_package tgt
400 400
         fi
401 401
     fi
402
+
403
+    if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
404
+        install_apache_wsgi
405
+        if is_ssl_enabled_service "c-api"; then
406
+            enable_mod_ssl
407
+        fi
408
+    fi
402 409
 }
403 410
 
404 411
 # install_cinderclient() - Collect source and prepare
... ...
@@ -446,10 +501,16 @@ function start_cinder {
446 446
         fi
447 447
     fi
448 448
 
449
-    run_process c-api "$CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
450
-    echo "Waiting for Cinder API to start..."
451
-    if ! wait_for_service $SERVICE_TIMEOUT $service_protocol://$CINDER_SERVICE_HOST:$service_port; then
452
-        die $LINENO "c-api did not start"
449
+    if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
450
+        enable_apache_site osapi-volume
451
+        restart_apache_server
452
+        tail_log c-api /var/log/$APACHE_NAME/c-api.log
453
+    else
454
+        run_process c-api "$CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
455
+        echo "Waiting for Cinder API to start..."
456
+        if ! wait_for_service $SERVICE_TIMEOUT $service_protocol://$CINDER_SERVICE_HOST:$service_port; then
457
+            die $LINENO "c-api did not start"
458
+        fi
453 459
     fi
454 460
 
455 461
     run_process c-sch "$CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
... ...
@@ -468,9 +529,16 @@ function start_cinder {
468 468
 
469 469
 # stop_cinder() - Stop running processes
470 470
 function stop_cinder {
471
+    if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
472
+        disable_apache_site osapi-volume
473
+        restart_apache_server
474
+    else
475
+        stop_process c-api
476
+    fi
477
+
471 478
     # Kill the cinder screen windows
472 479
     local serv
473
-    for serv in c-api c-bak c-sch c-vol; do
480
+    for serv in c-bak c-sch c-vol; do
474 481
         stop_process $serv
475 482
     done
476 483
 }