Browse code

Run cinder-api with uWSGI

Per the Pike goal, switching the Cinder API control plane to
use WSGI in Apache.

Co-Authored-By: Ivan Kolodyazhny <e0ne@e0ne.info>
Depends-On: Ie8a0eeab1bf31887d6f37cf155b2d161ddfb172d
Depends-On: I14b68f36e7fcc5341bbdbcf165274d9d50f7dd04
Change-Id: I8cef6c98f9242cc38d66de0ac499490e2a237887

Sean McGinnis authored on 2017/03/04 03:09:35
Showing 1 changed files
... ...
@@ -55,6 +55,8 @@ CINDER_AUTH_CACHE_DIR=${CINDER_AUTH_CACHE_DIR:-/var/cache/cinder}
55 55
 
56 56
 CINDER_CONF_DIR=/etc/cinder
57 57
 CINDER_CONF=$CINDER_CONF_DIR/cinder.conf
58
+CINDER_UWSGI=$CINDER_BIN_DIR/cinder-wsgi
59
+CINDER_UWSGI_CONF=$CINDER_CONF_DIR/cinder-api-uwsgi.ini
58 60
 CINDER_API_PASTE_INI=$CINDER_CONF_DIR/api-paste.ini
59 61
 
60 62
 # Public facing bits
... ...
@@ -106,8 +108,9 @@ else
106 106
     CINDER_ISCSI_HELPER=${CINDER_ISCSI_HELPER:-tgtadm}
107 107
 fi
108 108
 
109
-# Toggle for deploying Cinder under HTTPD + mod_wsgi
110
-CINDER_USE_MOD_WSGI=${CINDER_USE_MOD_WSGI:-False}
109
+# Toggle for deploying Cinder under a wsgi server. Legacy mod_wsgi
110
+# reference should be cleaned up to more accurately refer to uwsgi.
111
+CINDER_USE_MOD_WSGI=${CINDER_USE_MOD_WSGI:-True}
111 112
 
112 113
 # Source the enabled backends
113 114
 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
... ...
@@ -196,38 +199,8 @@ function cleanup_cinder {
196 196
         done
197 197
     fi
198 198
 
199
-    if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
200
-        _cinder_cleanup_apache_wsgi
201
-    fi
202
-}
203
-
204
-# _cinder_config_apache_wsgi() - Set WSGI config files
205
-function _cinder_config_apache_wsgi {
206
-    local cinder_apache_conf
207
-    cinder_apache_conf=$(apache_site_config_for osapi-volume)
208
-    local cinder_ssl=""
209
-    local cinder_certfile=""
210
-    local cinder_keyfile=""
211
-    local cinder_api_port=$CINDER_SERVICE_PORT
212
-    local venv_path=""
213
-
214
-    if [[ ${USE_VENV} = True ]]; then
215
-        venv_path="python-path=${PROJECT_VENV["cinder"]}/lib/python2.7/site-packages"
216
-    fi
217
-
218
-    # copy proxy vhost file
219
-    sudo cp $FILES/apache-cinder-api.template $cinder_apache_conf
220
-    sudo sed -e "
221
-        s|%PUBLICPORT%|$cinder_api_port|g;
222
-        s|%APACHE_NAME%|$APACHE_NAME|g;
223
-        s|%APIWORKERS%|$API_WORKERS|g
224
-        s|%CINDER_BIN_DIR%|$CINDER_BIN_DIR|g;
225
-        s|%SSLENGINE%|$cinder_ssl|g;
226
-        s|%SSLCERTFILE%|$cinder_certfile|g;
227
-        s|%SSLKEYFILE%|$cinder_keyfile|g;
228
-        s|%USER%|$STACK_USER|g;
229
-        s|%VIRTUALENV%|$venv_path|g
230
-    " -i $cinder_apache_conf
199
+    stop_process "c-api"
200
+    remove_uwsgi_config "$CINDER_UWSGI_CONF" "$CINDER_UWSGI"
231 201
 }
232 202
 
233 203
 # configure_cinder() - Set config files, create data dirs, etc
... ...
@@ -319,9 +292,18 @@ function configure_cinder {
319 319
     fi
320 320
 
321 321
     if is_service_enabled tls-proxy; then
322
-        # Set the service port for a proxy to take the original
323
-        iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
324
-        iniset $CINDER_CONF DEFAULT public_endpoint $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT
322
+        if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
323
+            # Set the service port for a proxy to take the original
324
+            if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
325
+                iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
326
+                iniset $CINDER_CONF DEFAULT public_endpoint $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST
327
+                iniset $CINDER_CONF DEFAULT osapi_volume_base_URL $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST
328
+            else
329
+                iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
330
+                iniset $CINDER_CONF DEFAULT public_endpoint $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT
331
+                iniset $CINDER_CONF DEFAULT osapi_volume_base_URL $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT
332
+            fi
333
+        fi
325 334
     fi
326 335
 
327 336
     if [ "$SYSLOG" != "False" ]; then
... ...
@@ -333,9 +315,7 @@ function configure_cinder {
333 333
     # Format logging
334 334
     setup_logging $CINDER_CONF $CINDER_USE_MOD_WSGI
335 335
 
336
-    if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
337
-        _cinder_config_apache_wsgi
338
-    fi
336
+    write_uwsgi_config "$CINDER_UWSGI_CONF" "$CINDER_UWSGI" "/volume"
339 337
 
340 338
     if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
341 339
         configure_cinder_driver
... ...
@@ -374,29 +354,47 @@ function configure_cinder {
374 374
 
375 375
 # Migrated from keystone_data.sh
376 376
 function create_cinder_accounts {
377
-
378 377
     # Cinder
379 378
     if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
380 379
 
381 380
         create_service_user "cinder"
382 381
 
383 382
         get_or_create_service "cinder" "volume" "Cinder Volume Service"
384
-        get_or_create_endpoint \
385
-            "volume" \
386
-            "$REGION_NAME" \
387
-            "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(project_id)s"
388
-
389
-        get_or_create_service "cinderv2" "volumev2" "Cinder Volume Service V2"
390
-        get_or_create_endpoint \
391
-            "volumev2" \
392
-            "$REGION_NAME" \
393
-            "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(project_id)s"
394
-
395
-        get_or_create_service "cinderv3" "volumev3" "Cinder Volume Service V3"
396
-        get_or_create_endpoint \
397
-            "volumev3" \
398
-            "$REGION_NAME" \
399
-            "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s"
383
+        if [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
384
+            get_or_create_endpoint \
385
+                "volume" \
386
+                "$REGION_NAME" \
387
+                "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(project_id)s"
388
+
389
+            get_or_create_service "cinderv2" "volumev2" "Cinder Volume Service V2"
390
+            get_or_create_endpoint \
391
+                "volumev2" \
392
+                "$REGION_NAME" \
393
+                "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(project_id)s"
394
+
395
+            get_or_create_service "cinderv3" "volumev3" "Cinder Volume Service V3"
396
+            get_or_create_endpoint \
397
+                "volumev3" \
398
+                "$REGION_NAME" \
399
+                "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s"
400
+        else
401
+            get_or_create_endpoint \
402
+                "volume" \
403
+                "$REGION_NAME" \
404
+                "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume/v1/\$(project_id)s"
405
+
406
+            get_or_create_service "cinderv2" "volumev2" "Cinder Volume Service V2"
407
+            get_or_create_endpoint \
408
+                "volumev2" \
409
+                "$REGION_NAME" \
410
+                "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume/v2/\$(project_id)s"
411
+
412
+            get_or_create_service "cinderv3" "volumev3" "Cinder Volume Service V3"
413
+            get_or_create_endpoint \
414
+                "volumev3" \
415
+                "$REGION_NAME" \
416
+                "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume/v3/\$(project_id)s"
417
+        fi
400 418
 
401 419
         configure_cinder_internal_tenant
402 420
     fi
... ...
@@ -449,10 +447,6 @@ function install_cinder {
449 449
     elif [[ "$CINDER_ISCI_HELPER" == "lioadm" ]]; then
450 450
         install_package targetcli
451 451
     fi
452
-
453
-    if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
454
-        install_apache_wsgi
455
-    fi
456 452
 }
457 453
 
458 454
 # install_cinderclient() - Collect source and prepare
... ...
@@ -483,7 +477,8 @@ function _configure_tgt_for_config_d {
483 483
 function start_cinder {
484 484
     local service_port=$CINDER_SERVICE_PORT
485 485
     local service_protocol=$CINDER_SERVICE_PROTOCOL
486
-    if is_service_enabled tls-proxy; then
486
+    local cinder_url
487
+    if is_service_enabled tls-proxy && ["$CINDER_USE_MOD_WSGI" == "False"]; then
487 488
         service_port=$CINDER_SERVICE_PORT_INT
488 489
         service_protocol="http"
489 490
     fi
... ...
@@ -507,24 +502,23 @@ function start_cinder {
507 507
         fi
508 508
     fi
509 509
 
510
-    if is_service_enabled c-api ; then
511
-        if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
512
-            enable_apache_site osapi-volume
513
-            restart_apache_server
514
-            tail_log c-api /var/log/$APACHE_NAME/c-api.log
515
-        else
510
+    if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
511
+        if [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
516 512
             run_process c-api "$CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
513
+            cinder_url=$service_protocol://$SERVICE_HOST:$service_port
514
+            # Start proxy if tsl enabled
515
+            if is_service_enabled tls_proxy; then
516
+                start_tls_proxy cinder '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_POR_INT
517
+            fi
518
+        else
519
+            run_process "c-api" "$CINDER_BIN_DIR/uwsgi --ini $CINDER_UWSGI_CONF"
520
+            cinder_url=$service_protocol://$SERVICE_HOST/volume/v3
517 521
         fi
522
+    fi
518 523
 
519
-        echo "Waiting for Cinder API to start..."
520
-        if ! wait_for_service $SERVICE_TIMEOUT $service_protocol://$CINDER_SERVICE_HOST:$service_port; then
521
-            die $LINENO "c-api did not start"
522
-        fi
523
-
524
-        # Start proxies if enabled
525
-        if is_service_enabled tls-proxy; then
526
-            start_tls_proxy cinder '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT
527
-        fi
524
+    echo "Waiting for Cinder API to start..."
525
+    if ! wait_for_service $SERVICE_TIMEOUT $cinder_url; then
526
+        die $LINENO "c-api did not start"
528 527
     fi
529 528
 
530 529
     run_process c-sch "$CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
... ...
@@ -538,12 +532,7 @@ function start_cinder {
538 538
 
539 539
 # stop_cinder() - Stop running processes
540 540
 function stop_cinder {
541
-    if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
542
-        disable_apache_site osapi-volume
543
-        restart_apache_server
544
-    else
545
-        stop_process c-api
546
-    fi
541
+    stop_process c-api
547 542
 
548 543
     # Kill the cinder screen windows
549 544
     local serv