blob: 32e38c44dae86bc9a0d391176fa71b181dc1f074 [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
Dean Troyer67787e62012-05-02 11:48:15 -05003# lib/cinder
Dean Troyer6d04fd72012-12-21 11:03:37 -06004# Install and start **Cinder** volume service
Dean Troyer67787e62012-05-02 11:48:15 -05005
6# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01007#
Dean Troyer67787e62012-05-02 11:48:15 -05008# - functions
Attila Fazekas91b8d132013-01-06 22:40:09 +01009# - DEST, DATA_DIR, STACK_USER must be defined
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010010# - SERVICE_{TENANT_NAME|PASSWORD} must be defined
11# - ``KEYSTONE_TOKEN_FORMAT`` must be defined
Dean Troyer67787e62012-05-02 11:48:15 -050012
13# stack.sh
14# ---------
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010015# - install_cinder
16# - configure_cinder
17# - init_cinder
18# - start_cinder
19# - stop_cinder
20# - cleanup_cinder
Dean Troyer67787e62012-05-02 11:48:15 -050021
Dean Troyer7903b792012-09-13 17:16:12 -050022# Save trace setting
Ian Wienand523f4882015-10-13 11:03:03 +110023_XTRACE_CINDER=$(set +o | grep xtrace)
Dean Troyer7903b792012-09-13 17:16:12 -050024set +o xtrace
Dean Troyer67787e62012-05-02 11:48:15 -050025
26
27# Defaults
28# --------
29
Mate Lakatb2fdafe2012-11-20 15:52:21 +000030# set up default driver
31CINDER_DRIVER=${CINDER_DRIVER:-default}
john-griffithd0860cc2014-01-23 11:31:10 -070032CINDER_PLUGINS=$TOP_DIR/lib/cinder_plugins
Dean Troyer09718332014-07-03 10:46:57 -050033CINDER_BACKENDS=$TOP_DIR/lib/cinder_backends
john-griffithd0860cc2014-01-23 11:31:10 -070034
35# grab plugin config if specified via cinder_driver
36if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
37 source $CINDER_PLUGINS/$CINDER_DRIVER
38fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +000039
Dean Troyer67787e62012-05-02 11:48:15 -050040# set up default directories
Sean Daguee08ab102014-11-13 17:09:28 -050041GITDIR["python-cinderclient"]=$DEST/python-cinderclient
Ivan Kolodyazhny8d0d3112016-05-26 23:41:49 +030042GITDIR["python-brick-cinderclient-ext"]=$DEST/python-brick-cinderclient-ext
Dean Troyer67787e62012-05-02 11:48:15 -050043CINDER_DIR=$DEST/cinder
Dean Troyer6aaad5f2015-02-18 07:09:04 -060044
45# Cinder virtual environment
46if [[ ${USE_VENV} = True ]]; then
47 PROJECT_VENV["cinder"]=${CINDER_DIR}.venv
48 CINDER_BIN_DIR=${PROJECT_VENV["cinder"]}/bin
49else
50 CINDER_BIN_DIR=$(get_python_exec_prefix)
51fi
52
Dean Troyer50ac7922012-09-13 14:02:01 -050053CINDER_STATE_PATH=${CINDER_STATE_PATH:=$DATA_DIR/cinder}
Dean Troyer671c16e2012-12-13 16:22:38 -060054
Dean Troyer50ac7922012-09-13 14:02:01 -050055CINDER_CONF_DIR=/etc/cinder
56CINDER_CONF=$CINDER_CONF_DIR/cinder.conf
Sean McGinnisdaf12742017-03-03 18:09:35 +000057CINDER_UWSGI=$CINDER_BIN_DIR/cinder-wsgi
58CINDER_UWSGI_CONF=$CINDER_CONF_DIR/cinder-api-uwsgi.ini
Dean Troyer671c16e2012-12-13 16:22:38 -060059CINDER_API_PASTE_INI=$CINDER_CONF_DIR/api-paste.ini
Dean Troyer50ac7922012-09-13 14:02:01 -050060
Dean Troyer560346b2012-12-13 17:05:24 -060061# Public facing bits
Sean Daguef3b2f4c2017-04-13 10:11:48 -040062if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -040063 CINDER_SERVICE_PROTOCOL="https"
64fi
Dean Troyer560346b2012-12-13 17:05:24 -060065CINDER_SERVICE_HOST=${CINDER_SERVICE_HOST:-$SERVICE_HOST}
66CINDER_SERVICE_PORT=${CINDER_SERVICE_PORT:-8776}
67CINDER_SERVICE_PORT_INT=${CINDER_SERVICE_PORT_INT:-18776}
68CINDER_SERVICE_PROTOCOL=${CINDER_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
Jens Harbottdc7b4292017-09-19 10:52:32 +000069CINDER_SERVICE_LISTEN_ADDRESS=${CINDER_SERVICE_LISTEN_ADDRESS:-$(ipv6_unquote $SERVICE_LISTEN_ADDRESS)}
Dean Troyer560346b2012-12-13 17:05:24 -060070
John Griffithce8e6f62015-05-12 17:28:59 -060071# What type of LVM device should Cinder use for LVM backend
Sean McGinnis486376e2017-09-05 19:56:06 -050072# Defaults to auto, which will do thin provisioning if it's a fresh
73# volume group, otherwise it will do thick. The other valid choices are
74# default, which is thick, or thin, which as the name implies utilizes lvm
75# thin provisioning.
76CINDER_LVM_TYPE=${CINDER_LVM_TYPE:-auto}
Dean Troyer09718332014-07-03 10:46:57 -050077
Dean Troyer09718332014-07-03 10:46:57 -050078# Default backends
79# The backend format is type:name where type is one of the supported backend
80# types (lvm, nfs, etc) and name is the identifier used in the Cinder
81# configuration and for the volume type name. Multiple backends are
82# comma-separated.
Dean Troyer311f4872014-12-18 16:31:34 -060083# The old ``CINDER_MULTI_LVM_BACKEND=True`` setting had a default of:
84# CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-lvm:lvmdriver-1,lvm:lvmdriver-2}
85CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-lvm:lvmdriver-1}
Dean Troyer09718332014-07-03 10:46:57 -050086
Joe D'Andreadfcc3872015-04-29 15:39:17 -040087CINDER_VOLUME_CLEAR=${CINDER_VOLUME_CLEAR:-${CINDER_VOLUME_CLEAR_DEFAULT:-zero}}
88CINDER_VOLUME_CLEAR=$(echo ${CINDER_VOLUME_CLEAR} | tr '[:upper:]' '[:lower:]')
Dean Troyerb7490da2013-03-18 16:07:56 -050089
aojeagarcia61f6caf2018-09-24 12:34:15 +020090# Centos7 and OpenSUSE switched to using LIO and that's all that's supported,
91# although the tgt bits are in EPEL and OpenSUSE we don't want that for CI
92if is_fedora || is_suse; then
Ian Wienanda881b882017-04-19 15:42:34 +100093 CINDER_ISCSI_HELPER=${CINDER_ISCSI_HELPER:-lioadm}
94 if [[ ${CINDER_ISCSI_HELPER} != "lioadm" ]]; then
Lenny Verkhovskyf63ddd62018-02-25 14:48:05 +000095 die "lioadm is the only valid Cinder target_helper config on this platform"
Ian Wienanda881b882017-04-19 15:42:34 +100096 fi
97else
98 CINDER_ISCSI_HELPER=${CINDER_ISCSI_HELPER:-tgtadm}
99fi
Attila Fazekasc70605d2015-01-26 15:44:47 +0100100
Sean McGinnisdaf12742017-03-03 18:09:35 +0000101# Toggle for deploying Cinder under a wsgi server. Legacy mod_wsgi
102# reference should be cleaned up to more accurately refer to uwsgi.
103CINDER_USE_MOD_WSGI=${CINDER_USE_MOD_WSGI:-True}
Dean Troyercc6b4432013-04-08 15:38:03 -0500104
Dean Troyer09718332014-07-03 10:46:57 -0500105# Source the enabled backends
106if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
107 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500108 be_type=${be%%:*}
109 be_name=${be##*:}
110 if [[ -r $CINDER_BACKENDS/${be_type} ]]; then
111 source $CINDER_BACKENDS/${be_type}
Dean Troyer09718332014-07-03 10:46:57 -0500112 fi
113 done
114fi
115
Patrick Eastdddb2c72016-05-03 17:34:00 -0700116# Environment variables to configure the image-volume cache
117CINDER_IMG_CACHE_ENABLED=${CINDER_IMG_CACHE_ENABLED:-True}
118
119# For limits, if left unset, it will use cinder defaults of 0 for unlimited
120CINDER_IMG_CACHE_SIZE_GB=${CINDER_IMG_CACHE_SIZE_GB:-}
121CINDER_IMG_CACHE_SIZE_COUNT=${CINDER_IMG_CACHE_SIZE_COUNT:-}
122
123# Configure which cinder backends will have the image-volume cache, this takes the same
124# form as the CINDER_ENABLED_BACKENDS config option. By default it will
125# enable the cache for all cinder backends.
126CINDER_CACHE_ENABLED_FOR_BACKENDS=${CINDER_CACHE_ENABLED_FOR_BACKENDS:-$CINDER_ENABLED_BACKENDS}
Dean Troyer09718332014-07-03 10:46:57 -0500127
Dean Troyercc6b4432013-04-08 15:38:03 -0500128# Functions
129# ---------
Dean Troyere4fa7212014-01-15 15:04:49 -0600130
131# Test if any Cinder services are enabled
132# is_cinder_enabled
133function is_cinder_enabled {
Clark Boylan902158b2017-05-30 14:11:09 -0700134 [[ ,${DISABLED_SERVICES} =~ ,"cinder" ]] && return 1
Dean Troyere4fa7212014-01-15 15:04:49 -0600135 [[ ,${ENABLED_SERVICES} =~ ,"c-" ]] && return 0
136 return 1
137}
138
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300139# _cinder_cleanup_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
140function _cinder_cleanup_apache_wsgi {
141 sudo rm -f $(apache_site_config_for osapi-volume)
142}
143
Dean Troyer67787e62012-05-02 11:48:15 -0500144# cleanup_cinder() - Remove residual data files, anything left over from previous
145# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100146function cleanup_cinder {
Sean Dague252f2f52012-12-20 16:41:57 -0500147 # ensure the volume group is cleared up because fails might
148 # leave dead volumes in the group
Attila Fazekasc70605d2015-01-26 15:44:47 +0100149 if [ "$CINDER_ISCSI_HELPER" = "tgtadm" ]; then
Ian Wienandada886d2015-10-07 14:06:26 +1100150 local targets
151 targets=$(sudo tgtadm --op show --mode target)
Attila Fazekasc70605d2015-01-26 15:44:47 +0100152 if [ $? -ne 0 ]; then
153 # If tgt driver isn't running this won't work obviously
154 # So check the response and restart if need be
155 echo "tgtd seems to be in a bad state, restarting..."
156 if is_ubuntu; then
157 restart_service tgt
158 else
159 restart_service tgtd
160 fi
161 targets=$(sudo tgtadm --op show --mode target)
Sean Dague252f2f52012-12-20 16:41:57 -0500162 fi
Sean Dague252f2f52012-12-20 16:41:57 -0500163
Attila Fazekasc70605d2015-01-26 15:44:47 +0100164 if [[ -n "$targets" ]]; then
165 local iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
166 for i in "${iqn_list[@]}"; do
167 echo removing iSCSI target: $i
168 sudo tgt-admin --delete $i
169 done
170 fi
Sean Dague252f2f52012-12-20 16:41:57 -0500171
Attila Fazekasc70605d2015-01-26 15:44:47 +0100172 if is_ubuntu; then
173 stop_service tgt
174 else
175 stop_service tgtd
176 fi
Sean Dague252f2f52012-12-20 16:41:57 -0500177 else
Attila Fazekasc70605d2015-01-26 15:44:47 +0100178 sudo cinder-rtstool get-targets | sudo xargs -rn 1 cinder-rtstool delete
Sean Dague252f2f52012-12-20 16:41:57 -0500179 fi
180
Dean Troyer09718332014-07-03 10:46:57 -0500181 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500182 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500183 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500184 be_type=${be%%:*}
185 be_name=${be##*:}
186 if type cleanup_cinder_backend_${be_type} >/dev/null 2>&1; then
187 cleanup_cinder_backend_${be_type} ${be_name}
Dean Troyer09718332014-07-03 10:46:57 -0500188 fi
189 done
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100190 fi
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300191
Sean McGinnisdaf12742017-03-03 18:09:35 +0000192 stop_process "c-api"
193 remove_uwsgi_config "$CINDER_UWSGI_CONF" "$CINDER_UWSGI"
Dean Troyer67787e62012-05-02 11:48:15 -0500194}
195
Thierry Carrez63e17842014-01-10 14:23:03 +0100196# configure_cinder() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100197function configure_cinder {
Dean Troyer8421c2b2015-03-16 13:52:19 -0500198 sudo install -d -o $STACK_USER -m 755 $CINDER_CONF_DIR
Thierry Carrez63e17842014-01-10 14:23:03 +0100199
Yalei Wangcecbd1f2015-01-05 17:05:47 +0800200 rm -f $CINDER_CONF
201
Ian Wienandc6782412015-05-14 10:01:53 +1000202 configure_rootwrap cinder
John Griffith4e823ff2012-07-20 13:18:17 -0600203
TommyLike401de4d2017-05-04 17:56:22 +0800204 if [[ -f "$CINDER_DIR/etc/cinder/resource_filters.json" ]]; then
205 cp -p "$CINDER_DIR/etc/cinder/resource_filters.json" "$CINDER_CONF_DIR/resource_filters.json"
206 fi
207
Dean Troyer67787e62012-05-02 11:48:15 -0500208 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
Dan Prince82dea7c2013-10-16 18:57:15 -0400209
210 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_host
211 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_port
212 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_protocol
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000213 inicomment $CINDER_API_PASTE_INI filter:authtoken cafile
Dan Prince82dea7c2013-10-16 18:57:15 -0400214 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name
215 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_user
216 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_password
Ian Wienand1f82f432017-10-04 09:51:02 +1100217 inicomment $CINDER_API_PASTE_INI filter:authtoken signing_dir
Dean Troyerbc071bc2012-10-01 14:06:44 -0500218
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100219 configure_keystone_authtoken_middleware $CINDER_CONF cinder
Dan Prince82dea7c2013-10-16 18:57:15 -0400220
Ben Nemec03997942013-08-10 09:56:16 -0500221 iniset $CINDER_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Dean Troyer09718332014-07-03 10:46:57 -0500222
Lenny Verkhovskyf63ddd62018-02-25 14:48:05 +0000223 iniset $CINDER_CONF DEFAULT target_helper "$CINDER_ISCSI_HELPER"
Joe Gordon23d6d502015-03-06 15:24:22 -0800224 iniset $CINDER_CONF database connection `database_connection_url cinder`
Dean Troyer67787e62012-05-02 11:48:15 -0500225 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
Joe Gordona58382a2013-02-20 12:45:02 -0800226 iniset $CINDER_CONF DEFAULT rootwrap_config "$CINDER_CONF_DIR/rootwrap.conf"
Dan Prince9f22f072013-01-28 09:53:38 -0500227 iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.contrib.standard_extensions
Brian Haley180f5eb2015-06-16 13:14:31 -0400228 iniset $CINDER_CONF DEFAULT osapi_volume_listen $CINDER_SERVICE_LISTEN_ADDRESS
Dean Troyer50ac7922012-09-13 14:02:01 -0500229 iniset $CINDER_CONF DEFAULT state_path $CINDER_STATE_PATH
Joe Gordon23d6d502015-03-06 15:24:22 -0800230 iniset $CINDER_CONF oslo_concurrency lock_path $CINDER_STATE_PATH
Michał Dulko9ee14262016-06-03 15:34:50 +0200231 iniset $CINDER_CONF DEFAULT my_ip "$HOST_IP"
John Griffith4e823ff2012-07-20 13:18:17 -0600232
Sean McGinnis32712712017-09-22 07:49:15 -0500233 iniset $CINDER_CONF key_manager backend cinder.keymgr.conf_key_mgr.ConfKeyManager
lkuchlancb8256f2017-08-30 07:36:11 +0300234 iniset $CINDER_CONF key_manager fixed_key $(openssl rand -hex 16)
Kaitlin Farra5b72b02016-01-26 22:46:13 -0500235
Dean Troyer09718332014-07-03 10:46:57 -0500236 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500237 local enabled_backends=""
238 local default_name=""
239 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500240 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500241 be_type=${be%%:*}
242 be_name=${be##*:}
243 if type configure_cinder_backend_${be_type} >/dev/null 2>&1; then
244 configure_cinder_backend_${be_type} ${be_name}
Dean Troyer09718332014-07-03 10:46:57 -0500245 fi
Dean Troyera25922b2014-08-28 09:29:47 -0500246 if [[ -z "$default_name" ]]; then
247 default_name=$be_name
Dean Troyer09718332014-07-03 10:46:57 -0500248 fi
Dean Troyere8a35ac2014-07-25 12:37:41 -0500249 enabled_backends+=$be_name,
Sean McGinnis29ec2822017-05-30 14:21:39 -0500250
251 iniset $CINDER_CONF $be_name volume_clear $CINDER_VOLUME_CLEAR
252
Dean Troyer09718332014-07-03 10:46:57 -0500253 done
254 iniset $CINDER_CONF DEFAULT enabled_backends ${enabled_backends%,*}
Matt Riedemann6a4aa782014-07-25 13:35:53 -0700255 if [[ -n "$default_name" ]]; then
256 iniset $CINDER_CONF DEFAULT default_volume_type ${default_name}
Dean Troyer09718332014-07-03 10:46:57 -0500257 fi
Patrick Eastdddb2c72016-05-03 17:34:00 -0700258 configure_cinder_image_volume_cache
Dean Troyer09718332014-07-03 10:46:57 -0500259 fi
260
Matt Riedemann31c7d5c2018-07-23 09:25:08 -0400261 if is_service_enabled c-bak; then
262 # NOTE(mriedem): The default backup driver uses swift and if we're
263 # on a subnode we might not know if swift is enabled, but chances are
264 # good that it is on the controller so configure the backup service
265 # to use it. If we want to configure the backup service to use
266 # a non-swift driver, we'll likely need environment variables.
Falk Reimann22f747b2015-08-28 12:40:19 +0200267 iniset $CINDER_CONF DEFAULT backup_swift_url "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:$SWIFT_DEFAULT_BIND_PORT/v1/AUTH_"
Attila Fazekas29834742014-03-09 18:36:42 +0100268 fi
269
Gordon Chung2bfbc772013-08-09 10:55:12 -0400270 if is_service_enabled ceilometer; then
Matt Riedemann45da7772017-03-05 13:07:39 -0500271 iniset $CINDER_CONF oslo_messaging_notifications driver "messagingv2"
Gordon Chung2bfbc772013-08-09 10:55:12 -0400272 fi
273
Dean Troyer560346b2012-12-13 17:05:24 -0600274 if is_service_enabled tls-proxy; then
Sean McGinnisdaf12742017-03-03 18:09:35 +0000275 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
276 # Set the service port for a proxy to take the original
277 if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
278 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
Jens Harbott411c34d2017-08-29 14:40:26 +0000279 iniset $CINDER_CONF oslo_middleware enable_proxy_headers_parsing True
Sean McGinnisdaf12742017-03-03 18:09:35 +0000280 else
281 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
282 iniset $CINDER_CONF DEFAULT public_endpoint $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT
283 iniset $CINDER_CONF DEFAULT osapi_volume_base_URL $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT
284 fi
285 fi
Dean Troyer560346b2012-12-13 17:05:24 -0600286 fi
287
Dean Troyer4d3049e2012-11-06 20:38:14 -0600288 if [ "$SYSLOG" != "False" ]; then
289 iniset $CINDER_CONF DEFAULT use_syslog True
290 fi
291
Brant Knudson2dd110c2015-03-14 12:39:14 -0500292 iniset_rpc_backend cinder $CINDER_CONF
Gary Kottonf71bf192012-08-06 11:15:36 -0400293
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700294 # Format logging
Sean Dague9751be62016-04-05 12:08:57 -0400295 setup_logging $CINDER_CONF $CINDER_USE_MOD_WSGI
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000296
Sean McGinnisdaf12742017-03-03 18:09:35 +0000297 write_uwsgi_config "$CINDER_UWSGI_CONF" "$CINDER_UWSGI" "/volume"
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300298
john-griffithd0860cc2014-01-23 11:31:10 -0700299 if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
300 configure_cinder_driver
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000301 fi
Ian Wienand0db17132013-06-26 22:31:48 +1000302
Dean Troyer05bd7b82014-09-16 17:25:33 -0500303 iniset $CINDER_CONF DEFAULT osapi_volume_workers "$API_WORKERS"
Rob Crittenden18d47782014-03-19 17:47:42 -0400304
Matthew Treinish1fa65362017-06-23 22:32:37 +0000305 iniset $CINDER_CONF DEFAULT glance_api_servers "$GLANCE_URL"
Sean Daguef3b2f4c2017-04-13 10:11:48 -0400306 if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -0400307 iniset $CINDER_CONF DEFAULT glance_protocol https
Rob Crittenden4b109292014-10-21 18:17:48 -0400308 iniset $CINDER_CONF DEFAULT glance_ca_certificates_file $SSL_BUNDLE_FILE
Rob Crittenden18d47782014-03-19 17:47:42 -0400309 fi
310
Flavio Percoco22c695f2016-05-11 12:49:07 -0500311 if [ "$GLANCE_V1_ENABLED" != "True" ]; then
312 iniset $CINDER_CONF DEFAULT glance_api_version 2
313 fi
314
Gyorgy Szombathelyic04ac032017-05-23 16:52:35 +0200315 # Set nova credentials (used for os-assisted-snapshots)
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100316 configure_keystone_authtoken_middleware $CINDER_CONF nova nova
Gyorgy Szombathelyic04ac032017-05-23 16:52:35 +0200317 iniset $CINDER_CONF nova region_name "$REGION_NAME"
Marian Horban7159b4b2015-10-22 15:47:49 -0400318 iniset $CINDER_CONF DEFAULT graceful_shutdown_timeout "$SERVICE_GRACEFUL_SHUTDOWN_TIMEOUT"
Mehdi Abaakouk52b10742016-12-01 16:11:17 +0100319
Davanum Srinivasc0d16c22017-05-19 10:23:46 -0400320 if [[ ! -z "$CINDER_COORDINATION_URL" ]]; then
321 iniset $CINDER_CONF coordination backend_url "$CINDER_COORDINATION_URL"
322 elif is_service_enabled etcd3; then
Davanum Srinivas27367be2017-11-28 08:20:48 -0500323 iniset $CINDER_CONF coordination backend_url "etcd3+http://${SERVICE_HOST}:$ETCD_PORT"
Mehdi Abaakouk52b10742016-12-01 16:11:17 +0100324 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500325}
326
Dean Troyer671c16e2012-12-13 16:22:38 -0600327# create_cinder_accounts() - Set up common required cinder accounts
328
329# Tenant User Roles
330# ------------------------------------------------------------------
331# service cinder admin # if enabled
332
333# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100334function create_cinder_accounts {
Dean Troyer671c16e2012-12-13 16:22:38 -0600335 # Cinder
336 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100337
Jamie Lennoxe8bc2b82015-02-10 20:38:56 +1100338 create_service_user "cinder"
Bartosz Górski0abde392014-02-28 14:15:19 +0100339
Eric Friedcda2cb52017-10-10 11:49:06 -0500340 # block-storage is the official service type
341 get_or_create_service "cinder" "block-storage" "Cinder Volume Service"
Sean McGinnisdaf12742017-03-03 18:09:35 +0000342 if [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
343 get_or_create_endpoint \
Eric Friedcda2cb52017-10-10 11:49:06 -0500344 "block-storage" \
345 "$REGION_NAME" \
Monty Taylor69057d42018-05-01 05:57:21 -0500346 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s"
Eric Friedcda2cb52017-10-10 11:49:06 -0500347
Sean McGinnisdaf12742017-03-03 18:09:35 +0000348 get_or_create_service "cinderv2" "volumev2" "Cinder Volume Service V2"
349 get_or_create_endpoint \
350 "volumev2" \
351 "$REGION_NAME" \
352 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(project_id)s"
Alex Meade06c7a442016-04-01 13:18:32 -0400353
Sean McGinnisdaf12742017-03-03 18:09:35 +0000354 get_or_create_service "cinderv3" "volumev3" "Cinder Volume Service V3"
355 get_or_create_endpoint \
356 "volumev3" \
357 "$REGION_NAME" \
358 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s"
359 else
360 get_or_create_endpoint \
Eric Friedcda2cb52017-10-10 11:49:06 -0500361 "block-storage" \
362 "$REGION_NAME" \
Monty Taylor69057d42018-05-01 05:57:21 -0500363 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume/v3/\$(project_id)s"
Eric Friedcda2cb52017-10-10 11:49:06 -0500364
Sean McGinnisdaf12742017-03-03 18:09:35 +0000365 get_or_create_service "cinderv2" "volumev2" "Cinder Volume Service V2"
366 get_or_create_endpoint \
367 "volumev2" \
368 "$REGION_NAME" \
369 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume/v2/\$(project_id)s"
370
371 get_or_create_service "cinderv3" "volumev3" "Cinder Volume Service V3"
372 get_or_create_endpoint \
373 "volumev3" \
374 "$REGION_NAME" \
375 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume/v3/\$(project_id)s"
376 fi
Patrick Eastdddb2c72016-05-03 17:34:00 -0700377
378 configure_cinder_internal_tenant
Dean Troyer671c16e2012-12-13 16:22:38 -0600379 fi
380}
381
Dean Troyer67787e62012-05-02 11:48:15 -0500382# init_cinder() - Initialize database and volume group
Ian Wienandaee18c72014-02-21 15:35:08 +1100383function init_cinder {
Terry Wilson428af5a2012-11-01 16:12:39 -0400384 if is_service_enabled $DATABASE_BACKENDS; then
Dean Troyerf03bafe2013-02-12 10:58:28 -0600385 # (Re)create cinder database
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200386 recreate_database cinder
Dean Troyer67787e62012-05-02 11:48:15 -0500387
Clark Boylan633dbc32017-06-14 12:09:21 -0700388 time_start "dbsync"
Dean Troyerf03bafe2013-02-12 10:58:28 -0600389 # Migrate cinder database
Einst Crazy4f55c2d2016-05-04 08:14:01 +0000390 $CINDER_BIN_DIR/cinder-manage --config-file $CINDER_CONF db sync
Clark Boylan633dbc32017-06-14 12:09:21 -0700391 time_stop "dbsync"
Dean Troyer67787e62012-05-02 11:48:15 -0500392 fi
393
Dean Troyer09718332014-07-03 10:46:57 -0500394 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500395 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500396 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500397 be_type=${be%%:*}
398 be_name=${be##*:}
399 if type init_cinder_backend_${be_type} >/dev/null 2>&1; then
Maru Newbyc070a3d2015-01-27 17:44:44 +0000400 # Always init the default volume group for lvm.
401 if [[ "$be_type" == "lvm" ]]; then
402 init_default_lvm_volume_group
403 fi
Dean Troyere8a35ac2014-07-25 12:37:41 -0500404 init_cinder_backend_${be_type} ${be_name}
Vincent Untz0230aa82012-06-14 08:51:01 +0200405 fi
Dean Troyer09718332014-07-03 10:46:57 -0500406 done
Dean Troyer67787e62012-05-02 11:48:15 -0500407 fi
Dean Troyerbc071bc2012-10-01 14:06:44 -0500408
Dean Troyer09718332014-07-03 10:46:57 -0500409 mkdir -p $CINDER_STATE_PATH/volumes
Dean Troyer67787e62012-05-02 11:48:15 -0500410}
411
412# install_cinder() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100413function install_cinder {
Dean Troyer67787e62012-05-02 11:48:15 -0500414 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400415 setup_develop $CINDER_DIR
Ian Wienanda881b882017-04-19 15:42:34 +1000416 if [[ "$CINDER_ISCSI_HELPER" == "tgtadm" ]]; then
417 install_package tgt
Attila Fazekas501aaeb2017-12-11 12:01:32 +0100418 elif [[ "$CINDER_ISCSI_HELPER" == "lioadm" ]]; then
Eric Harney363acd92019-03-04 17:50:47 -0500419 if [[ ${DISTRO} == "bionic" ]]; then
whoami-rajatf28c75f2019-03-13 23:41:05 +0530420 # TODO(frickler): Workaround for https://launchpad.net/bugs/1819819
421 sudo mkdir -p /etc/target
422
Eric Harney363acd92019-03-04 17:50:47 -0500423 install_package targetcli-fb
424 else
425 install_package targetcli
426 fi
Attila Fazekasc70605d2015-01-26 15:44:47 +0100427 fi
Dean Troyer253a1a32013-04-01 18:23:22 -0500428}
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400429
Dean Troyer253a1a32013-04-01 18:23:22 -0500430# install_cinderclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100431function install_cinderclient {
Ivan Kolodyazhny8d0d3112016-05-26 23:41:49 +0300432 if use_library_from_git "python-brick-cinderclient-ext"; then
433 git_clone_by_name "python-brick-cinderclient-ext"
434 setup_dev_lib "python-brick-cinderclient-ext"
435 fi
436
Sean Daguee08ab102014-11-13 17:09:28 -0500437 if use_library_from_git "python-cinderclient"; then
438 git_clone_by_name "python-cinderclient"
439 setup_dev_lib "python-cinderclient"
440 sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-cinderclient"]}/tools/,/etc/bash_completion.d/}cinder.bash_completion
Sean Dague5cb19062014-11-01 01:37:45 +0100441 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500442}
443
Steve Baker18225d92013-04-14 12:48:41 -0700444# apply config.d approach for cinder volumes directory
Ian Wienandaee18c72014-02-21 15:35:08 +1100445function _configure_tgt_for_config_d {
Steve Baker18225d92013-04-14 12:48:41 -0700446 if [[ ! -d /etc/tgt/stack.d/ ]]; then
447 sudo ln -sf $CINDER_STATE_PATH/volumes /etc/tgt/stack.d
Jordan Pittiera263e7d2016-01-07 19:40:44 +0100448 fi
449 if ! grep -q "include /etc/tgt/stack.d/*" /etc/tgt/targets.conf; then
Steve Baker18225d92013-04-14 12:48:41 -0700450 echo "include /etc/tgt/stack.d/*" | sudo tee -a /etc/tgt/targets.conf
Mate Lakata39caac2012-09-03 15:45:53 +0100451 fi
452}
453
Sean Dague0eebeb42017-08-30 14:16:58 -0400454# start_cinder() - Start running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100455function start_cinder {
Rob Crittenden18d47782014-03-19 17:47:42 -0400456 local service_port=$CINDER_SERVICE_PORT
457 local service_protocol=$CINDER_SERVICE_PROTOCOL
Sean McGinnisdaf12742017-03-03 18:09:35 +0000458 local cinder_url
Eric Harney8ea86602017-08-02 11:40:41 -0400459 if is_service_enabled tls-proxy && [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
Rob Crittenden18d47782014-03-19 17:47:42 -0400460 service_port=$CINDER_SERVICE_PORT_INT
461 service_protocol="http"
462 fi
Attila Fazekasc70605d2015-01-26 15:44:47 +0100463 if [ "$CINDER_ISCSI_HELPER" = "tgtadm" ]; then
464 if is_service_enabled c-vol; then
465 # Delete any old stack.conf
466 sudo rm -f /etc/tgt/conf.d/stack.conf
467 _configure_tgt_for_config_d
468 if is_ubuntu; then
469 sudo service tgt restart
Dirk Mueller6bc089f2015-06-01 12:39:12 +0200470 elif is_suse; then
471 # NOTE(dmllr): workaround restart bug
472 # https://bugzilla.suse.com/show_bug.cgi?id=934642
473 stop_service tgtd
474 start_service tgtd
Attila Fazekasc70605d2015-01-26 15:44:47 +0100475 else
Dirk Mueller6bc089f2015-06-01 12:39:12 +0200476 restart_service tgtd
Attila Fazekasc70605d2015-01-26 15:44:47 +0100477 fi
478 # NOTE(gfidente): ensure tgtd is running in debug mode
479 sudo tgtadm --mode system --op update --name debug --value on
Dean Troyer67787e62012-05-02 11:48:15 -0500480 fi
481 fi
482
Sean McGinnisdaf12742017-03-03 18:09:35 +0000483 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
484 if [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
Clark Boylan2dfca042017-05-25 14:57:19 -0700485 run_process c-api "$CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
Sean McGinnisdaf12742017-03-03 18:09:35 +0000486 cinder_url=$service_protocol://$SERVICE_HOST:$service_port
Jens Harbott52609c62017-08-28 11:49:28 +0000487 # Start proxy if tls enabled
488 if is_service_enabled tls-proxy; then
489 start_tls_proxy cinder '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT
Sean McGinnisdaf12742017-03-03 18:09:35 +0000490 fi
491 else
Davanum Srinivasaceb27e2017-08-17 08:59:59 -0400492 run_process "c-api" "$CINDER_BIN_DIR/uwsgi --procname-prefix cinder-api --ini $CINDER_UWSGI_CONF"
Sean McGinnisdaf12742017-03-03 18:09:35 +0000493 cinder_url=$service_protocol://$SERVICE_HOST/volume/v3
Clark Boylan2dfca042017-05-25 14:57:19 -0700494 fi
Sean McGinnisdaf12742017-03-03 18:09:35 +0000495 fi
Eli Qiao4af6eea2017-02-28 15:13:02 +0800496
Sean McGinnisdaf12742017-03-03 18:09:35 +0000497 echo "Waiting for Cinder API to start..."
498 if ! wait_for_service $SERVICE_TIMEOUT $cinder_url; then
499 die $LINENO "c-api did not start"
Dean Troyer09718332014-07-03 10:46:57 -0500500 fi
501
Dean Troyer3159a822014-08-27 14:13:58 -0500502 run_process c-sch "$CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
503 run_process c-bak "$CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF"
504 run_process c-vol "$CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
John Griffithe6d4fe52013-07-15 17:35:54 -0600505
506 # NOTE(jdg): For cinder, startup order matters. To ensure that repor_capabilities is received
507 # by the scheduler start the cinder-volume service last (or restart it) after the scheduler
508 # has started. This is a quick fix for lp bug/1189595
Dean Troyer67787e62012-05-02 11:48:15 -0500509}
510
Dean Troyer699a29f2012-09-10 14:10:27 -0500511# stop_cinder() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100512function stop_cinder {
Sean McGinnisdaf12742017-03-03 18:09:35 +0000513 stop_process c-api
Sean Dague0eebeb42017-08-30 14:16:58 -0400514 stop_process c-bak
515 stop_process c-sch
516 stop_process c-vol
Dean Troyer67787e62012-05-02 11:48:15 -0500517}
Dean Troyer7903b792012-09-13 17:16:12 -0500518
Dean Troyer09718332014-07-03 10:46:57 -0500519# create_volume_types() - Create Cinder's configured volume types
520function create_volume_types {
521 # Create volume types
522 if is_service_enabled c-api && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Jamie Lennox494f7cd2015-05-29 08:33:03 +0000523 local be be_name
Dean Troyer09718332014-07-03 10:46:57 -0500524 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500525 be_name=${be##*:}
Ivan Kolodyazhny165199e2017-11-06 18:17:39 +0200526 # NOTE (e0ne): openstack client doesn't work with cinder in noauth mode
527 if is_service_enabled keystone; then
528 openstack --os-region-name="$REGION_NAME" volume type create --property volume_backend_name="${be_name}" ${be_name}
529 else
530 # TODO (e0ne): use openstack client once it will support cinder in noauth mode:
531 # https://bugs.launchpad.net/python-cinderclient/+bug/1755279
532 local cinder_url
533 cinder_url=$CINDER_SERVICE_PROTOCOL://$SERVICE_HOST:$CINDER_SERVICE_PORT/v3
534 OS_USER_ID=$OS_USERNAME OS_PROJECT_ID=$OS_PROJECT_NAME cinder --os-auth-type noauth --os-endpoint=$cinder_url type-create ${be_name}
535 OS_USER_ID=$OS_USERNAME OS_PROJECT_ID=$OS_PROJECT_NAME cinder --os-auth-type noauth --os-endpoint=$cinder_url type-key ${be_name} set volume_backend_name=${be_name}
536 fi
Dean Troyer09718332014-07-03 10:46:57 -0500537 done
538 fi
539}
540
541# Compatibility for Grenade
542
543function create_cinder_volume_group {
544 # During a transition period Grenade needs to have this function defined
545 # It is effectively a no-op in the Grenade 'target' use case
546 :
547}
548
Patrick Eastdddb2c72016-05-03 17:34:00 -0700549function configure_cinder_internal_tenant {
550 # Re-use the Cinder service account for simplicity.
551 iniset $CINDER_CONF DEFAULT cinder_internal_tenant_project_id $(get_or_create_project $SERVICE_PROJECT_NAME)
552 iniset $CINDER_CONF DEFAULT cinder_internal_tenant_user_id $(get_or_create_user "cinder")
553}
554
555function configure_cinder_image_volume_cache {
556 # Expect CINDER_CACHE_ENABLED_FOR_BACKENDS to be a list of backends
557 # similar to CINDER_ENABLED_BACKENDS with NAME:TYPE where NAME will
558 # be the backend specific configuration stanza in cinder.conf.
559 for be in ${CINDER_CACHE_ENABLED_FOR_BACKENDS//,/ }; do
560 local be_name=${be##*:}
561
562 iniset $CINDER_CONF $be_name image_volume_cache_enabled $CINDER_IMG_CACHE_ENABLED
563
564 if [[ -n $CINDER_IMG_CACHE_SIZE_GB ]]; then
565 iniset $CINDER_CONF $be_name image_volume_cache_max_size_gb $CINDER_IMG_CACHE_SIZE_GB
566 fi
567
568 if [[ -n $CINDER_IMG_CACHE_SIZE_COUNT ]]; then
569 iniset $CINDER_CONF $be_name image_volume_cache_max_count $CINDER_IMG_CACHE_SIZE_COUNT
570 fi
571 done
572}
573
Dean Troyercc6b4432013-04-08 15:38:03 -0500574
Dean Troyer7903b792012-09-13 17:16:12 -0500575# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +1100576$_XTRACE_CINDER
Sean Dague584d90e2013-03-29 14:34:53 -0400577
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100578# Tell emacs to use shell-script-mode
579## Local variables:
580## mode: shell-script
581## End: