Skip to content

Commit 66b361b

Browse files
kevinbentonannp1987
authored andcommitted
WSGI Neutron integration
This patch provides a new mechanism to deploy Neutron using WSGI script. This also starts a Neutron RPC server process when the Neutron API is loaded via a WSGI entry point to serve the agents. Co-Authored-By: Victor Morales <victor.morales@intel.com> Co-Authored-By: Nguyen Phuong An <AnNP@vn.fujitsu.com> Change-Id: I16a199b04858bfc03ef50d9883154dba8b0d66ea Depends-On: https://review.openstack.org/#/c/580049/ Partially-implements: blueprint run-in-wsgi-server
1 parent 3b5477d commit 66b361b

4 files changed

Lines changed: 140 additions & 23 deletions

File tree

.zuul.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,23 @@
511511
# changes to devstack w/o gating on it for all devstack changes.
512512
# * nova-next: maintained by nova for unreleased/undefaulted
513513
# things like cellsv2 and placement-api
514+
# * neutron-fullstack-with-uwsgi: maintained by neutron for fullstack test
515+
# when neutron-api is served by uwsgi, it's in exprimental for testing.
516+
# the next cycle we can remove this job if things turn out to be
517+
# stable enough.
518+
# * neutron-functional-with-uwsgi: maintained by neutron for functional
519+
# test. Next cycle we can remove this one if things turn out to be
520+
# stable engouh with uwsgi.
521+
# * neutron-tempest-with-uwsgi: maintained by neutron for tempest test.
522+
# Next cycle we can remove this if everything run out stable enough.
523+
514524
experimental:
515525
jobs:
516526
- nova-cells-v1:
517527
irrelevant-files:
518528
- ^.*\.rst$
519529
- ^doc/.*$
520530
- nova-next
531+
- neutron-fullstack-with-uwsgi
532+
- neutron-functional-with-uwsgi
533+
- neutron-tempest-with-uwsgi

files/apache-neutron.template

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Listen %PUBLICPORT%
2+
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" %D(us)" neutron_combined
3+
4+
<Directory %NEUTRON_BIN%>
5+
Require all granted
6+
</Directory>
7+
8+
<VirtualHost *:%PUBLICPORT%>
9+
WSGIDaemonProcess neutron-server processes=%APIWORKERS% threads=1 user=%USER% display-name=%{GROUP} %VIRTUALENV%
10+
WSGIProcessGroup neutron-server
11+
WSGIScriptAlias / %NEUTRON_BIN%/neutron-api
12+
WSGIApplicationGroup %{GLOBAL}
13+
WSGIPassAuthorization On
14+
ErrorLogFormat "%M"
15+
ErrorLog /var/log/%APACHE_NAME%/neutron.log
16+
CustomLog /var/log/%APACHE_NAME%/neutron_access.log neutron_combined
17+
%SSLENGINE%
18+
%SSLCERTFILE%
19+
%SSLKEYFILE%
20+
</VirtualHost>
21+
22+
23+
%SSLLISTEN%<VirtualHost *:443>
24+
%SSLLISTEN% %SSLENGINE%
25+
%SSLLISTEN% %SSLCERTFILE%
26+
%SSLLISTEN% %SSLKEYFILE%
27+
%SSLLISTEN%</VirtualHost>
28+
29+
Alias /networking %NEUTRON_BIN%/neutron-api
30+
<Location /networking>
31+
SetHandler wsgi-script
32+
Options +ExecCGI
33+
WSGIProcessGroup neutron-server
34+
WSGIApplicationGroup %{GLOBAL}
35+
WSGIPassAuthorization On
36+
</Location>

lib/neutron

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ set +o xtrace
2828
# Set up default directories
2929
GITDIR["python-neutronclient"]=$DEST/python-neutronclient
3030

31+
# NEUTRON_DEPLOY_MOD_WSGI defines how neutron is deployed, allowed values:
32+
# - False (default) : Run neutron under Eventlet
33+
# - True : Run neutron under uwsgi
34+
# TODO(annp): Switching to uwsgi in next cycle if things turn out to be stable
35+
# enough
36+
NEUTRON_DEPLOY_MOD_WSGI=${NEUTRON_DEPLOY_MOD_WSGI:-False}
3137
NEUTRON_AGENT=${NEUTRON_AGENT:-openvswitch}
3238
NEUTRON_DIR=$DEST/neutron
3339
NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
@@ -58,6 +64,8 @@ NEUTRON_CREATE_INITIAL_NETWORKS=${NEUTRON_CREATE_INITIAL_NETWORKS:-True}
5864
NEUTRON_STATE_PATH=${NEUTRON_STATE_PATH:=$DATA_DIR/neutron}
5965
NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
6066

67+
NEUTRON_UWSGI_CONF=$NEUTRON_CONF_DIR/neutron-api-uwsgi.ini
68+
6169
# By default, use the ML2 plugin
6270
NEUTRON_CORE_PLUGIN=${NEUTRON_CORE_PLUGIN:-ml2}
6371
NEUTRON_CORE_PLUGIN_CONF_FILENAME=${NEUTRON_CORE_PLUGIN_CONF_FILENAME:-ml2_conf.ini}
@@ -286,7 +294,7 @@ function configure_neutron_new {
286294
# Format logging
287295
setup_logging $NEUTRON_CONF
288296

289-
if is_service_enabled tls-proxy; then
297+
if is_service_enabled tls-proxy && [ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" ]; then
290298
# Set the service port for a proxy to take the original
291299
iniset $NEUTRON_CONF DEFAULT bind_port "$NEUTRON_SERVICE_PORT_INT"
292300
iniset $NEUTRON_CONF oslo_middleware enable_proxy_headers_parsing True
@@ -357,15 +365,23 @@ function configure_neutron_nova_new {
357365

358366
# create_neutron_accounts() - Create required service accounts
359367
function create_neutron_accounts_new {
368+
local neutron_url
369+
370+
if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
371+
neutron_url=$NEUTRON_SERVICE_PROTOCOL://$NEUTRON_SERVICE_HOST/networking/
372+
else
373+
neutron_url=$NEUTRON_SERVICE_PROTOCOL://$NEUTRON_SERVICE_HOST:$NEUTRON_SERVICE_PORT/
374+
fi
375+
376+
360377
if [[ "$ENABLED_SERVICES" =~ "neutron-api" ]]; then
361378

362379
create_service_user "neutron"
363380

364381
neutron_service=$(get_or_create_service "neutron" \
365382
"network" "Neutron Service")
366383
get_or_create_endpoint $neutron_service \
367-
"$REGION_NAME" \
368-
"$NEUTRON_SERVICE_PROTOCOL://$NEUTRON_SERVICE_HOST:$NEUTRON_SERVICE_PORT/"
384+
"$REGION_NAME" "$neutron_url"
369385
fi
370386
}
371387

@@ -427,6 +443,7 @@ function install_neutronclient {
427443
function start_neutron_api {
428444
local service_port=$NEUTRON_SERVICE_PORT
429445
local service_protocol=$NEUTRON_SERVICE_PROTOCOL
446+
local neutron_url
430447
if is_service_enabled tls-proxy; then
431448
service_port=$NEUTRON_SERVICE_PORT_INT
432449
service_protocol="http"
@@ -440,17 +457,24 @@ function start_neutron_api {
440457
opts+=" --config-file $cfg_file"
441458
done
442459

443-
# Start the Neutron service
444-
# TODO(sc68cal) Stop hard coding this
445-
run_process neutron-api "$NEUTRON_BIN_DIR/neutron-server $opts"
446-
447-
if ! wait_for_service $SERVICE_TIMEOUT $service_protocol://$NEUTRON_SERVICE_HOST:$service_port; then
448-
die $LINENO "neutron-api did not start"
460+
if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
461+
run_process neutron-api "$NEUTRON_BIN_DIR/uwsgi --procname-prefix neutron-api --ini $NEUTRON_UWSGI_CONF"
462+
neutron_url=$service_protocol://$NEUTRON_SERVICE_HOST/networking/
463+
enable_service neutron-rpc-server
464+
run_process neutron-rpc-server "$NEUTRON_BIN_DIR/neutron-rpc-server $opts"
465+
else
466+
# Start the Neutron service
467+
# TODO(sc68cal) Stop hard coding this
468+
run_process neutron-api "$NEUTRON_BIN_DIR/neutron-server $opts"
469+
neutron_url=$service_protocol://$NEUTRON_SERVICE_HOST:$service_port
470+
# Start proxy if enabled
471+
if is_service_enabled tls-proxy; then
472+
start_tls_proxy neutron '*' $NEUTRON_SERVICE_PORT $NEUTRON_SERVICE_HOST $NEUTRON_SERVICE_PORT_INT
473+
fi
449474
fi
450475

451-
# Start proxy if enabled
452-
if is_service_enabled tls-proxy; then
453-
start_tls_proxy neutron '*' $NEUTRON_SERVICE_PORT $NEUTRON_SERVICE_HOST $NEUTRON_SERVICE_PORT_INT
476+
if ! wait_for_service $SERVICE_TIMEOUT $neutron_url; then
477+
die $LINENO "neutron-api did not start"
454478
fi
455479
}
456480

@@ -497,6 +521,10 @@ function stop_neutron_new {
497521
stop_process $serv
498522
done
499523

524+
if is_service_enabled neutron-rpc-server; then
525+
stop_process neutron-rpc-server
526+
fi
527+
500528
if is_service_enabled neutron-dhcp; then
501529
stop_process neutron-dhcp
502530
pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
@@ -551,6 +579,13 @@ function neutron_deploy_rootwrap_filters_new {
551579
# neutron-legacy is removed.
552580
# TODO(sc68cal) Remove when neutron-legacy is no more.
553581
function cleanup_neutron {
582+
if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
583+
stop_process neutron-api
584+
stop_process neutron-rpc-server
585+
remove_uwsgi_config "$NEUTRON_UWSGI_CONF" "$NEUTRON_BIN_DIR/neutron-api"
586+
sudo rm -f $(apache_site_config_for neutron-api)
587+
fi
588+
554589
if is_neutron_legacy_enabled; then
555590
# Call back to old function
556591
cleanup_mutnauq "$@"
@@ -566,6 +601,10 @@ function configure_neutron {
566601
else
567602
configure_neutron_new "$@"
568603
fi
604+
605+
if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
606+
write_uwsgi_config "$NEUTRON_UWSGI_CONF" "$NEUTRON_BIN_DIR/neutron-api" "/networking"
607+
fi
569608
}
570609

571610
function configure_neutron_nova {

lib/neutron-legacy

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ NEUTRON_CONF_DIR=/etc/neutron
8686
NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
8787
export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
8888

89+
# NEUTRON_DEPLOY_MOD_WSGI defines how neutron is deployed, allowed values:
90+
# - False (default) : Run neutron under Eventlet
91+
# - True : Run neutron under uwsgi
92+
# TODO(annp): Switching to uwsgi in next cycle if things turn out to be stable
93+
# enough
94+
NEUTRON_DEPLOY_MOD_WSGI=${NEUTRON_DEPLOY_MOD_WSGI:-False}
95+
96+
NEUTRON_UWSGI_CONF=$NEUTRON_CONF_DIR/neutron-api-uwsgi.ini
97+
8998
# Agent binaries. Note, binary paths for other agents are set in per-service
9099
# scripts in lib/neutron_plugins/services/
91100
AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
@@ -402,15 +411,21 @@ function create_nova_conf_neutron {
402411

403412
# Migrated from keystone_data.sh
404413
function create_mutnauq_accounts {
414+
local neutron_url
415+
if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
416+
neutron_url=$Q_PROTOCOL://$SERVICE_HOST/networking/
417+
else
418+
neutron_url=$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/
419+
fi
420+
405421
if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
406422

407423
create_service_user "neutron"
408424

409425
get_or_create_service "neutron" "network" "Neutron Service"
410426
get_or_create_endpoint \
411427
"network" \
412-
"$REGION_NAME" \
413-
"$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/"
428+
"$REGION_NAME" "$neutron_url"
414429
fi
415430
}
416431

@@ -460,6 +475,7 @@ function start_neutron_service_and_check {
460475
local service_port=$Q_PORT
461476
local service_protocol=$Q_PROTOCOL
462477
local cfg_file_options
478+
local neutron_url
463479

464480
cfg_file_options="$(determine_config_files neutron-server)"
465481

@@ -468,16 +484,24 @@ function start_neutron_service_and_check {
468484
service_protocol="http"
469485
fi
470486
# Start the Neutron service
471-
run_process q-svc "$NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
487+
if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
488+
enable_service neutron-api
489+
run_process neutron-api "$NEUTRON_BIN_DIR/uwsgi --procname-prefix neutron-api --ini $NEUTRON_UWSGI_CONF"
490+
neutron_url=$Q_PROTOCOL://$Q_HOST/networking/
491+
enable_service neutron-rpc-server
492+
run_process neutron-rpc-server "$NEUTRON_BIN_DIR/neutron-rpc-server $cfg_file_options"
493+
else
494+
run_process q-svc "$NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
495+
neutron_url=$service_protocol://$Q_HOST:$service_port
496+
# Start proxy if enabled
497+
if is_service_enabled tls-proxy; then
498+
start_tls_proxy neutron '*' $Q_PORT $Q_HOST $Q_PORT_INT
499+
fi
500+
fi
472501
echo "Waiting for Neutron to start..."
473502

474-
local testcmd="wget ${ssl_ca} --no-proxy -q -O- $service_protocol://$Q_HOST:$service_port"
503+
local testcmd="wget ${ssl_ca} --no-proxy -q -O- $neutron_url"
475504
test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT
476-
477-
# Start proxy if enabled
478-
if is_service_enabled tls-proxy; then
479-
start_tls_proxy neutron '*' $Q_PORT $Q_HOST $Q_PORT_INT
480-
fi
481505
}
482506

483507
# Control of the l2 agent is separated out to make it easier to test partial
@@ -532,7 +556,12 @@ function stop_mutnauq_other {
532556
[ ! -z "$pid" ] && sudo kill -9 $pid
533557
fi
534558

535-
stop_process q-svc
559+
if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
560+
stop_process neutron-rpc-server
561+
stop_process neutron-api
562+
else
563+
stop_process q-svc
564+
fi
536565

537566
if is_service_enabled q-l3; then
538567
sudo pkill -f "radvd -C $DATA_DIR/neutron/ra"
@@ -715,7 +744,7 @@ function _configure_neutron_common {
715744
# Format logging
716745
setup_logging $NEUTRON_CONF
717746

718-
if is_service_enabled tls-proxy; then
747+
if is_service_enabled tls-proxy && [ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" ]; then
719748
# Set the service port for a proxy to take the original
720749
iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
721750
iniset $NEUTRON_CONF oslo_middleware enable_proxy_headers_parsing True

0 commit comments

Comments
 (0)