Browse code

Add support for placement API to devstack

Uses lib/placement, but relies on some functionality from
lib/nova. This leads to some weirdness since the nova has
special status in stack.sh. If/when placement is extracted
it may be good to follow the devstack plugin structure
instead.

Because the placement code is currently a part of nova, there
are dependencies in lib/placement on a some $NOVA_* variable
and, if virtenv is being used, the virtualenv used by nova.

Because placement currently runs using nova's configuration
settings, not a lot actually happens in lib/placement: apache
is configured and keystone accounts and endpoints are created.

If PLACEMENT_DB_ENABLED is true then a separate placement db
will be configured.

When complete the initial version of the placement service will
provide support for managing resource providers, inventories and
allocations.

The placement api only runs under mod-wsgi.

Change-Id: I53dd3e6b41de17387a0e179fc9ac64c143b6a9eb

Chris Dent authored on 2016/07/13 04:34:09
Showing 5 changed files
... ...
@@ -46,6 +46,7 @@ source $TOP_DIR/lib/horizon
46 46
 source $TOP_DIR/lib/keystone
47 47
 source $TOP_DIR/lib/glance
48 48
 source $TOP_DIR/lib/nova
49
+source $TOP_DIR/lib/placement
49 50
 source $TOP_DIR/lib/cinder
50 51
 source $TOP_DIR/lib/swift
51 52
 source $TOP_DIR/lib/heat
52 53
new file mode 100644
... ...
@@ -0,0 +1,25 @@
0
+Listen %PUBLICPORT%
1
+
2
+<VirtualHost *:%PUBLICPORT%>
3
+    WSGIDaemonProcess placement-api processes=%APIWORKERS% threads=1 user=%USER% display-name=%{GROUP} %VIRTUALENV%
4
+    WSGIProcessGroup placement-api
5
+    WSGIScriptAlias / %PUBLICWSGI%
6
+    WSGIApplicationGroup %{GLOBAL}
7
+    WSGIPassAuthorization On
8
+    <IfVersion >= 2.4>
9
+      ErrorLogFormat "%M"
10
+    </IfVersion>
11
+    ErrorLog /var/log/%APACHE_NAME%/placement-api.log
12
+    %SSLENGINE%
13
+    %SSLCERTFILE%
14
+    %SSLKEYFILE%
15
+</VirtualHost>
16
+
17
+Alias /placement %PUBLICWSGI%
18
+<Location /placement>
19
+    SetHandler wsgi-script
20
+    Options +ExecCGI
21
+    WSGIProcessGroup placement-api
22
+    WSGIApplicationGroup %{GLOBAL}
23
+    WSGIPassAuthorization On
24
+</Location>
0 25
new file mode 100644
... ...
@@ -0,0 +1,201 @@
0
+#!/bin/bash
1
+#
2
+# lib/placement
3
+# Functions to control the configuration and operation of the **Placement** service
4
+#
5
+# Currently the placement service is embedded in nova. Eventually we
6
+# expect this to change so this file is started as a separate entity
7
+# despite making use of some *NOVA* variables and files.
8
+
9
+# Dependencies:
10
+#
11
+# - ``functions`` file
12
+# - ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined
13
+# - ``FILES``
14
+
15
+# ``stack.sh`` calls the entry points in this order:
16
+#
17
+# - install_placement
18
+# - cleanup_placement
19
+# - configure_placement
20
+# - init_placement
21
+# - start_placement
22
+# - stop_placement
23
+
24
+# Save trace setting
25
+_XTRACE_LIB_PLACEMENT=$(set +o | grep xtrace)
26
+set +o xtrace
27
+
28
+# Defaults
29
+# --------
30
+
31
+PLACEMENT_CONF_DIR=/etc/nova
32
+PLACEMENT_CONF=$PLACEMENT_CONF_DIR/nova.conf
33
+PLACEMENT_AUTH_STRATEGY=${PLACEMENT_AUTH_STRATEGY:-placement}
34
+
35
+
36
+# The placement service can optionally use a separate database
37
+# connection. Set PLACEMENT_DB_ENABLED to True to use it.
38
+# NOTE(cdent): This functionality depends on some code that is not
39
+# yet merged in nova but is coming soon.
40
+PLACEMENT_DB_ENABLED=$(trueorfalse False PLACEMENT_DB_ENABLED)
41
+
42
+if is_suse; then
43
+    PLACEMENT_WSGI_DIR=${PLACEMENT_WSGI_DIR:-/srv/www/htdocs/placement}
44
+else
45
+    PLACEMENT_WSGI_DIR=${PLACEMENT_WSGI_DIR:-/var/www/placement}
46
+fi
47
+
48
+if is_ssl_enabled_service "placement-api" || is_service_enabled tls-proxy; then
49
+    PLACEMENT_SERVICE_PROTOCOL="https"
50
+fi
51
+
52
+# Public facing bits
53
+PLACEMENT_SERVICE_PROTOCOL=${PLACEMENT_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
54
+PLACEMENT_SERVICE_HOST=${PLACEMENT_SERVICE_HOST:-$SERVICE_HOST}
55
+PLACEMENT_SERVICE_PORT=${PLACEMENT_SERVICE_PORT:-8778}
56
+
57
+# Functions
58
+# ---------
59
+
60
+# Test if any placement services are enabled
61
+# is_placement_enabled
62
+function is_placement_enabled {
63
+    [[ ,${ENABLED_SERVICES} =~ ,"placement-" ]] && return 0
64
+    return 1
65
+}
66
+
67
+# cleanup_placement() - Remove residual data files, anything left over from previous
68
+# runs that a clean run would need to clean up
69
+function cleanup_placement {
70
+    sudo rm -f $(apache_site_config_for placement-api)
71
+}
72
+
73
+# _config_placement_apache_wsgi() - Set WSGI config files
74
+function _config_placement_apache_wsgi {
75
+    sudo mkdir -p $PLACEMENT_WSGI_DIR
76
+
77
+    local placement_api_apache_conf
78
+    local placement_api_port=$PLACEMENT_SERVICE_PORT
79
+    local venv_path=""
80
+    placement_api_apache_conf=$(apache_site_config_for placement-api)
81
+
82
+    # reuse nova's cert if a cert is being used
83
+    if is_ssl_enabled_service "placement-api"; then
84
+        placement_ssl="SSLEngine On"
85
+        placement_certfile="SSLCertificateFile $NOVA_SSL_CERT"
86
+        placement_keyfile="SSLCertificateKeyFile $NOVA_SSL_KEY"
87
+    fi
88
+    # reuse nova's venv if there is one as placement code lives
89
+    # there
90
+    if [[ ${USE_VENV} = True ]]; then
91
+        venv_path="python-path=${PROJECT_VENV["nova"]}/lib/$(python_version)/site-packages"
92
+    fi
93
+
94
+    # copy wsgi application file
95
+    sudo cp $NOVA_DIR/nova/api/openstack/placement/placement-api.py $PLACEMENT_WSGI_DIR/placement-api
96
+
97
+    sudo cp $FILES/apache-placement-api.template $placement_api_apache_conf
98
+    sudo sed -e "
99
+        s|%PUBLICPORT%|$placement_api_port|g;
100
+        s|%APACHE_NAME%|$APACHE_NAME|g;
101
+        s|%PUBLICWSGI%|$PLACEMENT_WSGI_DIR/placement-api|g;
102
+        s|%SSLENGINE%|$placement_ssl|g;
103
+        s|%SSLCERTFILE%|$placement_certfile|g;
104
+        s|%SSLKEYFILE%|$placement_keyfile|g;
105
+        s|%USER%|$STACK_USER|g;
106
+        s|%VIRTUALENV%|$venv_path|g
107
+        s|%APIWORKERS%|$API_WORKERS|g
108
+    " -i $placement_api_apache_conf
109
+}
110
+
111
+# configure_placement() - Set config files, create data dirs, etc
112
+function configure_placement {
113
+    if [ "$PLACEMENT_DB_ENABLED" != False ]; then
114
+        iniset $PLACEMENT_CONF placement_database connection `database_connection_url placement`
115
+    fi
116
+
117
+    iniset $NOVA_CONF placement auth_type "password"
118
+    iniset $NOVA_CONF placement auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v3"
119
+    iniset $NOVA_CONF placement username placement
120
+    iniset $NOVA_CONF placement password "$SERVICE_PASSWORD"
121
+    iniset $NOVA_CONF placement user_domain_name "Default"
122
+    iniset $NOVA_CONF placement project_name "$SERVICE_TENANT_NAME"
123
+    iniset $NOVA_CONF placement project_domain_name "Default"
124
+    iniset $NOVA_CONF placement region_name "$REGION_NAME"
125
+    # TODO(cdent): auth_strategy, which is common to see in these
126
+    # blocks is not currently used here. For the time being the
127
+    # placement api uses the auth_strategy configuration setting
128
+    # established by the nova api. This avoids, for the time, being,
129
+    # creating redundant configuration items that are just used for
130
+    # testing.
131
+
132
+    _config_placement_apache_wsgi
133
+}
134
+
135
+# create_placement_accounts() - Set up required placement accounts
136
+# and service and endpoints.
137
+function create_placement_accounts {
138
+    create_service_user "placement" "admin"
139
+    local placement_api_url="$PLACEMENT_SERVICE_PROTOCOL://$PLACEMENT_SERVICE_HOST/placement"
140
+    get_or_create_service "placement" "placement" "Placement Service"
141
+    get_or_create_endpoint \
142
+        "placement" \
143
+        "$REGION_NAME" \
144
+        "$placement_api_url" \
145
+        "$placement_api_url" \
146
+        "$placement_api_url"
147
+}
148
+
149
+# init_placement() - Create service user and endpoints
150
+# If PLACEMENT_DB_ENABLED is true, create the separate placement db
151
+# using, for now, the api_db migrations.
152
+function init_placement {
153
+    if [ "$PLACEMENT_DB_ENABLED" != False ]; then
154
+        recreate_database placement
155
+        $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CONF api_db sync
156
+    fi
157
+    create_placement_accounts
158
+}
159
+
160
+# install_placement() - Collect source and prepare
161
+function install_placement {
162
+    install_apache_wsgi
163
+    if is_ssl_enabled_service "placement-api"; then
164
+        enable_mod_ssl
165
+    fi
166
+}
167
+
168
+# start_placement_api() - Start the API processes ahead of other things
169
+function start_placement_api {
170
+    # Get right service port for testing
171
+    local service_port=$PLACEMENT_SERVICE_PORT
172
+    local placement_api_port=$PLACEMENT_SERVICE_PORT
173
+
174
+    enable_apache_site placement-api
175
+    restart_apache_server
176
+    tail_log placement-api /var/log/$APACHE_NAME/placement-api.log
177
+
178
+    echo "Waiting for placement-api to start..."
179
+    if ! wait_for_service $SERVICE_TIMEOUT $PLACEMENT_SERVICE_PROTOCOL://$PLACEMENT_SERVICE_HOST/placement; then
180
+        die $LINENO "placement-api did not start"
181
+    fi
182
+}
183
+
184
+function start_placement {
185
+    start_placement_api
186
+}
187
+
188
+# stop_placement() - Disable the api service and stop it.
189
+function stop_placement {
190
+    disable_apache_site placement-api
191
+    restart_apache_server
192
+}
193
+
194
+# Restore xtrace
195
+$_XTRACE_LIB_PLACEMENT
196
+
197
+# Tell emacs to use shell-script-mode
198
+## Local variables:
199
+## mode: shell-script
200
+## End:
... ...
@@ -569,6 +569,7 @@ source $TOP_DIR/lib/horizon
569 569
 source $TOP_DIR/lib/keystone
570 570
 source $TOP_DIR/lib/glance
571 571
 source $TOP_DIR/lib/nova
572
+source $TOP_DIR/lib/placement
572 573
 source $TOP_DIR/lib/cinder
573 574
 source $TOP_DIR/lib/swift
574 575
 source $TOP_DIR/lib/heat
... ...
@@ -859,6 +860,13 @@ if is_service_enabled nova; then
859 859
     configure_nova
860 860
 fi
861 861
 
862
+if is_service_enabled placement; then
863
+    # placement api
864
+    stack_install_service placement
865
+    cleanup_placement
866
+    configure_placement
867
+fi
868
+
862 869
 if is_service_enabled horizon; then
863 870
     # django openstack_auth
864 871
     install_django_openstack_auth
... ...
@@ -1160,6 +1168,11 @@ if is_service_enabled nova; then
1160 1160
     init_nova_cells
1161 1161
 fi
1162 1162
 
1163
+if is_service_enabled placement; then
1164
+    echo_summary "Configuring placement"
1165
+    init_placement
1166
+fi
1167
+
1163 1168
 
1164 1169
 # Extras Configuration
1165 1170
 # ====================
... ...
@@ -1265,6 +1278,10 @@ if is_service_enabled nova; then
1265 1265
     start_nova
1266 1266
     create_flavors
1267 1267
 fi
1268
+if is_service_enabled placement; then
1269
+    echo_summary "Starting Placement"
1270
+    start_placement
1271
+fi
1268 1272
 if is_service_enabled cinder; then
1269 1273
     echo_summary "Starting Cinder"
1270 1274
     start_cinder
... ...
@@ -63,6 +63,7 @@ source $TOP_DIR/lib/horizon
63 63
 source $TOP_DIR/lib/keystone
64 64
 source $TOP_DIR/lib/glance
65 65
 source $TOP_DIR/lib/nova
66
+source $TOP_DIR/lib/placement
66 67
 source $TOP_DIR/lib/cinder
67 68
 source $TOP_DIR/lib/swift
68 69
 source $TOP_DIR/lib/heat
... ...
@@ -111,6 +112,10 @@ if is_service_enabled nova; then
111 111
     stop_nova
112 112
 fi
113 113
 
114
+if is_service_enabled placement; then
115
+    stop_placement
116
+fi
117
+
114 118
 if is_service_enabled glance; then
115 119
     stop_glance
116 120
 fi