blob: c50a205f20d762be823ea3bbb24c92dcf9003170 [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
Hironori Shiina01a84d22021-01-11 13:42:46 -050034CINDER_BACKUPS=$TOP_DIR/lib/cinder_backups
john-griffithd0860cc2014-01-23 11:31:10 -070035
36# grab plugin config if specified via cinder_driver
37if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
38 source $CINDER_PLUGINS/$CINDER_DRIVER
39fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +000040
Dean Troyer67787e62012-05-02 11:48:15 -050041# set up default directories
Sean Daguee08ab102014-11-13 17:09:28 -050042GITDIR["python-cinderclient"]=$DEST/python-cinderclient
Ivan Kolodyazhny8d0d3112016-05-26 23:41:49 +030043GITDIR["python-brick-cinderclient-ext"]=$DEST/python-brick-cinderclient-ext
Dean Troyer67787e62012-05-02 11:48:15 -050044CINDER_DIR=$DEST/cinder
Dean Troyer6aaad5f2015-02-18 07:09:04 -060045
Gorka Eguileor97061c92021-10-14 09:55:56 +020046if [[ $SERVICE_IP_VERSION == 6 ]]; then
47 CINDER_MY_IP="$HOST_IPV6"
48else
49 CINDER_MY_IP="$HOST_IP"
50fi
51
52
Dean Troyer6aaad5f2015-02-18 07:09:04 -060053# Cinder virtual environment
54if [[ ${USE_VENV} = True ]]; then
55 PROJECT_VENV["cinder"]=${CINDER_DIR}.venv
56 CINDER_BIN_DIR=${PROJECT_VENV["cinder"]}/bin
57else
58 CINDER_BIN_DIR=$(get_python_exec_prefix)
59fi
60
Dean Troyer50ac7922012-09-13 14:02:01 -050061CINDER_STATE_PATH=${CINDER_STATE_PATH:=$DATA_DIR/cinder}
Dean Troyer671c16e2012-12-13 16:22:38 -060062
Dean Troyer50ac7922012-09-13 14:02:01 -050063CINDER_CONF_DIR=/etc/cinder
64CINDER_CONF=$CINDER_CONF_DIR/cinder.conf
Sean McGinnisdaf12742017-03-03 18:09:35 +000065CINDER_UWSGI=$CINDER_BIN_DIR/cinder-wsgi
66CINDER_UWSGI_CONF=$CINDER_CONF_DIR/cinder-api-uwsgi.ini
Dean Troyer671c16e2012-12-13 16:22:38 -060067CINDER_API_PASTE_INI=$CINDER_CONF_DIR/api-paste.ini
Dean Troyer50ac7922012-09-13 14:02:01 -050068
Dean Troyer560346b2012-12-13 17:05:24 -060069# Public facing bits
Sean Daguef3b2f4c2017-04-13 10:11:48 -040070if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -040071 CINDER_SERVICE_PROTOCOL="https"
72fi
Dean Troyer560346b2012-12-13 17:05:24 -060073CINDER_SERVICE_HOST=${CINDER_SERVICE_HOST:-$SERVICE_HOST}
74CINDER_SERVICE_PORT=${CINDER_SERVICE_PORT:-8776}
75CINDER_SERVICE_PORT_INT=${CINDER_SERVICE_PORT_INT:-18776}
76CINDER_SERVICE_PROTOCOL=${CINDER_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
Jens Harbottdc7b4292017-09-19 10:52:32 +000077CINDER_SERVICE_LISTEN_ADDRESS=${CINDER_SERVICE_LISTEN_ADDRESS:-$(ipv6_unquote $SERVICE_LISTEN_ADDRESS)}
Dean Troyer560346b2012-12-13 17:05:24 -060078
John Griffithce8e6f62015-05-12 17:28:59 -060079# What type of LVM device should Cinder use for LVM backend
Sean McGinnis486376e2017-09-05 19:56:06 -050080# Defaults to auto, which will do thin provisioning if it's a fresh
81# volume group, otherwise it will do thick. The other valid choices are
82# default, which is thick, or thin, which as the name implies utilizes lvm
83# thin provisioning.
84CINDER_LVM_TYPE=${CINDER_LVM_TYPE:-auto}
Dean Troyer09718332014-07-03 10:46:57 -050085
Dean Troyer09718332014-07-03 10:46:57 -050086# Default backends
87# The backend format is type:name where type is one of the supported backend
88# types (lvm, nfs, etc) and name is the identifier used in the Cinder
89# configuration and for the volume type name. Multiple backends are
90# comma-separated.
Dean Troyer311f4872014-12-18 16:31:34 -060091# The old ``CINDER_MULTI_LVM_BACKEND=True`` setting had a default of:
92# CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-lvm:lvmdriver-1,lvm:lvmdriver-2}
93CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-lvm:lvmdriver-1}
Dean Troyer09718332014-07-03 10:46:57 -050094
Joe D'Andreadfcc3872015-04-29 15:39:17 -040095CINDER_VOLUME_CLEAR=${CINDER_VOLUME_CLEAR:-${CINDER_VOLUME_CLEAR_DEFAULT:-zero}}
96CINDER_VOLUME_CLEAR=$(echo ${CINDER_VOLUME_CLEAR} | tr '[:upper:]' '[:lower:]')
Dean Troyerb7490da2013-03-18 16:07:56 -050097
Rajat Dhasmana1898a682023-03-14 05:35:33 +000098VOLUME_TYPE_MULTIATTACH=${VOLUME_TYPE_MULTIATTACH:-multiattach}
Gorka Eguileor97061c92021-10-14 09:55:56 +020099
100if [[ -n "$CINDER_ISCSI_HELPER" ]]; then
101 if [[ -z "$CINDER_TARGET_HELPER" ]]; then
102 deprecated 'Using CINDER_ISCSI_HELPER is deprecated, use CINDER_TARGET_HELPER instead'
103 CINDER_TARGET_HELPER="$CINDER_ISCSI_HELPER"
104 else
105 deprecated 'Deprecated CINDER_ISCSI_HELPER is set, but is being overwritten by CINDER_TARGET_HELPER'
106 fi
107fi
108CINDER_TARGET_HELPER=${CINDER_TARGET_HELPER:-lioadm}
109
110if [[ $CINDER_TARGET_HELPER == 'nvmet' ]]; then
111 CINDER_TARGET_PROTOCOL=${CINDER_TARGET_PROTOCOL:-'nvmet_rdma'}
112 CINDER_TARGET_PREFIX=${CINDER_TARGET_PREFIX:-'nvme-subsystem-1'}
113 CINDER_TARGET_PORT=${CINDER_TARGET_PORT:-4420}
114else
115 CINDER_TARGET_PROTOCOL=${CINDER_TARGET_PROTOCOL:-'iscsi'}
116 CINDER_TARGET_PREFIX=${CINDER_TARGET_PREFIX:-'iqn.2010-10.org.openstack:'}
117 CINDER_TARGET_PORT=${CINDER_TARGET_PORT:-3260}
118fi
119
Lee Yarwoodc0627922021-03-09 22:36:57 +0000120
Lee Yarwood0386c1c2021-04-28 09:26:23 +0100121# EL and SUSE should only use lioadm
aojeagarcia61f6caf2018-09-24 12:34:15 +0200122if is_fedora || is_suse; then
Gorka Eguileor97061c92021-10-14 09:55:56 +0200123 if [[ ${CINDER_TARGET_HELPER} != "lioadm" && ${CINDER_TARGET_HELPER} != 'nvmet' ]]; then
124 die "lioadm and nvmet are the only valid Cinder target_helper config on this platform"
Ian Wienanda881b882017-04-19 15:42:34 +1000125 fi
Ian Wienanda881b882017-04-19 15:42:34 +1000126fi
Attila Fazekasc70605d2015-01-26 15:44:47 +0100127
Brian Rosmaita6e9f7c22020-10-13 14:20:38 -0400128# When Cinder is used as a backend for Glance, it can be configured to clone
129# the volume containing image data directly in the backend instead of
130# transferring data from volume to volume. Value is a comma separated list of
131# schemes (currently only 'file' and 'cinder' are supported). The default
132# configuration in Cinder is empty (that is, do not use this feature). NOTE:
133# to use this feature you must also enable GLANCE_SHOW_DIRECT_URL and/or
134# GLANCE_SHOW_MULTIPLE_LOCATIONS for glance-api.conf.
135CINDER_ALLOWED_DIRECT_URL_SCHEMES=${CINDER_ALLOWED_DIRECT_URL_SCHEMES:-}
136if [[ -n "$CINDER_ALLOWED_DIRECT_URL_SCHEMES" ]]; then
137 if [[ "${GLANCE_SHOW_DIRECT_URL:-False}" != "True" \
138 && "${GLANCE_SHOW_MULTIPLE_LOCATIONS:-False}" != "True" ]]; then
139 warn $LINENO "CINDER_ALLOWED_DIRECT_URL_SCHEMES is set, but neither \
140GLANCE_SHOW_DIRECT_URL nor GLANCE_SHOW_MULTIPLE_LOCATIONS is True"
141 fi
142fi
143
Hironori Shiina01a84d22021-01-11 13:42:46 -0500144# For backward compatibility
145# Before CINDER_BACKUP_DRIVER was introduced, ceph backup driver was configured
146# along with ceph backend driver.
147if [[ -z "${CINDER_BACKUP_DRIVER}" && "$CINDER_ENABLED_BACKENDS" =~ "ceph" ]]; then
148 CINDER_BACKUP_DRIVER=ceph
149fi
150
151# Supported backup drivers are in lib/cinder_backups
152CINDER_BACKUP_DRIVER=${CINDER_BACKUP_DRIVER:-swift}
153
Sean McGinnisdaf12742017-03-03 18:09:35 +0000154# Toggle for deploying Cinder under a wsgi server. Legacy mod_wsgi
155# reference should be cleaned up to more accurately refer to uwsgi.
156CINDER_USE_MOD_WSGI=${CINDER_USE_MOD_WSGI:-True}
Dean Troyercc6b4432013-04-08 15:38:03 -0500157
Dean Troyer09718332014-07-03 10:46:57 -0500158# Source the enabled backends
159if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
160 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500161 be_type=${be%%:*}
162 be_name=${be##*:}
163 if [[ -r $CINDER_BACKENDS/${be_type} ]]; then
164 source $CINDER_BACKENDS/${be_type}
Dean Troyer09718332014-07-03 10:46:57 -0500165 fi
166 done
167fi
168
Hironori Shiina01a84d22021-01-11 13:42:46 -0500169# Source the backup driver
170if is_service_enabled c-bak && [[ -n "$CINDER_BACKUP_DRIVER" ]]; then
171 if [[ -r $CINDER_BACKUPS/$CINDER_BACKUP_DRIVER ]]; then
172 source $CINDER_BACKUPS/$CINDER_BACKUP_DRIVER
173 else
174 die "cinder backup driver $CINDER_BACKUP_DRIVER is not supported"
175 fi
176fi
177
Patrick Eastdddb2c72016-05-03 17:34:00 -0700178# Environment variables to configure the image-volume cache
179CINDER_IMG_CACHE_ENABLED=${CINDER_IMG_CACHE_ENABLED:-True}
180
181# For limits, if left unset, it will use cinder defaults of 0 for unlimited
182CINDER_IMG_CACHE_SIZE_GB=${CINDER_IMG_CACHE_SIZE_GB:-}
183CINDER_IMG_CACHE_SIZE_COUNT=${CINDER_IMG_CACHE_SIZE_COUNT:-}
184
185# Configure which cinder backends will have the image-volume cache, this takes the same
186# form as the CINDER_ENABLED_BACKENDS config option. By default it will
187# enable the cache for all cinder backends.
188CINDER_CACHE_ENABLED_FOR_BACKENDS=${CINDER_CACHE_ENABLED_FOR_BACKENDS:-$CINDER_ENABLED_BACKENDS}
Dean Troyer09718332014-07-03 10:46:57 -0500189
Ghanshyam Mannbd0d0fd2021-03-06 17:23:39 -0600190# Flag to set the oslo_policy.enforce_scope. This is used to switch
191# the Volume API policies to start checking the scope of token. by default,
192# this flag is False.
193# For more detail: https://docs.openstack.org/oslo.policy/latest/configuration/index.html#oslo_policy.enforce_scope
194CINDER_ENFORCE_SCOPE=$(trueorfalse False CINDER_ENFORCE_SCOPE)
195
Dean Troyercc6b4432013-04-08 15:38:03 -0500196# Functions
197# ---------
Dean Troyere4fa7212014-01-15 15:04:49 -0600198
199# Test if any Cinder services are enabled
200# is_cinder_enabled
201function is_cinder_enabled {
Clark Boylan902158b2017-05-30 14:11:09 -0700202 [[ ,${DISABLED_SERVICES} =~ ,"cinder" ]] && return 1
Dean Troyere4fa7212014-01-15 15:04:49 -0600203 [[ ,${ENABLED_SERVICES} =~ ,"c-" ]] && return 0
204 return 1
205}
206
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300207# _cinder_cleanup_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
208function _cinder_cleanup_apache_wsgi {
209 sudo rm -f $(apache_site_config_for osapi-volume)
210}
211
Dean Troyer67787e62012-05-02 11:48:15 -0500212# cleanup_cinder() - Remove residual data files, anything left over from previous
213# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100214function cleanup_cinder {
Sean Dague252f2f52012-12-20 16:41:57 -0500215 # ensure the volume group is cleared up because fails might
216 # leave dead volumes in the group
Gorka Eguileor97061c92021-10-14 09:55:56 +0200217 if [ "$CINDER_TARGET_HELPER" = "tgtadm" ]; then
Ian Wienandada886d2015-10-07 14:06:26 +1100218 local targets
219 targets=$(sudo tgtadm --op show --mode target)
Attila Fazekasc70605d2015-01-26 15:44:47 +0100220 if [ $? -ne 0 ]; then
221 # If tgt driver isn't running this won't work obviously
222 # So check the response and restart if need be
223 echo "tgtd seems to be in a bad state, restarting..."
224 if is_ubuntu; then
225 restart_service tgt
226 else
227 restart_service tgtd
228 fi
229 targets=$(sudo tgtadm --op show --mode target)
Sean Dague252f2f52012-12-20 16:41:57 -0500230 fi
Sean Dague252f2f52012-12-20 16:41:57 -0500231
Attila Fazekasc70605d2015-01-26 15:44:47 +0100232 if [[ -n "$targets" ]]; then
233 local iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
234 for i in "${iqn_list[@]}"; do
235 echo removing iSCSI target: $i
236 sudo tgt-admin --delete $i
237 done
238 fi
Sean Dague252f2f52012-12-20 16:41:57 -0500239
Attila Fazekasc70605d2015-01-26 15:44:47 +0100240 if is_ubuntu; then
241 stop_service tgt
242 else
243 stop_service tgtd
244 fi
Gorka Eguileor97061c92021-10-14 09:55:56 +0200245 elif [ "$CINDER_TARGET_HELPER" = "lioadm" ]; then
Attila Fazekasc70605d2015-01-26 15:44:47 +0100246 sudo cinder-rtstool get-targets | sudo xargs -rn 1 cinder-rtstool delete
Gorka Eguileor97061c92021-10-14 09:55:56 +0200247 elif [ "$CINDER_TARGET_HELPER" = "nvmet" ]; then
248 # If we don't disconnect everything vgremove will block
249 sudo nvme disconnect-all
250 sudo nvmetcli clear
251 else
252 die $LINENO "Unknown value \"$CINDER_TARGET_HELPER\" for CINDER_TARGET_HELPER"
Sean Dague252f2f52012-12-20 16:41:57 -0500253 fi
254
Dean Troyer09718332014-07-03 10:46:57 -0500255 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500256 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500257 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500258 be_type=${be%%:*}
259 be_name=${be##*:}
260 if type cleanup_cinder_backend_${be_type} >/dev/null 2>&1; then
261 cleanup_cinder_backend_${be_type} ${be_name}
Dean Troyer09718332014-07-03 10:46:57 -0500262 fi
263 done
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100264 fi
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300265
Hironori Shiina01a84d22021-01-11 13:42:46 -0500266 if is_service_enabled c-bak && [[ -n "$CINDER_BACKUP_DRIVER" ]]; then
267 if type cleanup_cinder_backup_$CINDER_BACKUP_DRIVER >/dev/null 2>&1; then
268 cleanup_cinder_backup_$CINDER_BACKUP_DRIVER
269 fi
270 fi
271
Sean McGinnisdaf12742017-03-03 18:09:35 +0000272 stop_process "c-api"
273 remove_uwsgi_config "$CINDER_UWSGI_CONF" "$CINDER_UWSGI"
Dean Troyer67787e62012-05-02 11:48:15 -0500274}
275
Thierry Carrez63e17842014-01-10 14:23:03 +0100276# configure_cinder() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100277function configure_cinder {
Dean Troyer8421c2b2015-03-16 13:52:19 -0500278 sudo install -d -o $STACK_USER -m 755 $CINDER_CONF_DIR
Thierry Carrez63e17842014-01-10 14:23:03 +0100279
Yalei Wangcecbd1f2015-01-05 17:05:47 +0800280 rm -f $CINDER_CONF
281
Ian Wienandc6782412015-05-14 10:01:53 +1000282 configure_rootwrap cinder
John Griffith4e823ff2012-07-20 13:18:17 -0600283
TommyLike401de4d2017-05-04 17:56:22 +0800284 if [[ -f "$CINDER_DIR/etc/cinder/resource_filters.json" ]]; then
285 cp -p "$CINDER_DIR/etc/cinder/resource_filters.json" "$CINDER_CONF_DIR/resource_filters.json"
286 fi
287
Dean Troyer67787e62012-05-02 11:48:15 -0500288 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
Dan Prince82dea7c2013-10-16 18:57:15 -0400289
290 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_host
291 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_port
292 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_protocol
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000293 inicomment $CINDER_API_PASTE_INI filter:authtoken cafile
Dan Prince82dea7c2013-10-16 18:57:15 -0400294 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name
295 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_user
296 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_password
Ian Wienand1f82f432017-10-04 09:51:02 +1100297 inicomment $CINDER_API_PASTE_INI filter:authtoken signing_dir
Dean Troyerbc071bc2012-10-01 14:06:44 -0500298
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100299 configure_keystone_authtoken_middleware $CINDER_CONF cinder
Dan Prince82dea7c2013-10-16 18:57:15 -0400300
Ben Nemec03997942013-08-10 09:56:16 -0500301 iniset $CINDER_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Dean Troyer09718332014-07-03 10:46:57 -0500302
Gorka Eguileor97061c92021-10-14 09:55:56 +0200303 iniset $CINDER_CONF DEFAULT target_helper "$CINDER_TARGET_HELPER"
Joe Gordon23d6d502015-03-06 15:24:22 -0800304 iniset $CINDER_CONF database connection `database_connection_url cinder`
Dean Troyer67787e62012-05-02 11:48:15 -0500305 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
Joe Gordona58382a2013-02-20 12:45:02 -0800306 iniset $CINDER_CONF DEFAULT rootwrap_config "$CINDER_CONF_DIR/rootwrap.conf"
Dan Prince9f22f072013-01-28 09:53:38 -0500307 iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.contrib.standard_extensions
Brian Haley180f5eb2015-06-16 13:14:31 -0400308 iniset $CINDER_CONF DEFAULT osapi_volume_listen $CINDER_SERVICE_LISTEN_ADDRESS
Dean Troyer50ac7922012-09-13 14:02:01 -0500309 iniset $CINDER_CONF DEFAULT state_path $CINDER_STATE_PATH
Joe Gordon23d6d502015-03-06 15:24:22 -0800310 iniset $CINDER_CONF oslo_concurrency lock_path $CINDER_STATE_PATH
Gorka Eguileor97061c92021-10-14 09:55:56 +0200311 iniset $CINDER_CONF DEFAULT my_ip "$CINDER_MY_IP"
Sean McGinnis32712712017-09-22 07:49:15 -0500312 iniset $CINDER_CONF key_manager backend cinder.keymgr.conf_key_mgr.ConfKeyManager
lkuchlancb8256f2017-08-30 07:36:11 +0300313 iniset $CINDER_CONF key_manager fixed_key $(openssl rand -hex 16)
Brian Rosmaita6e9f7c22020-10-13 14:20:38 -0400314 if [[ -n "$CINDER_ALLOWED_DIRECT_URL_SCHEMES" ]]; then
315 iniset $CINDER_CONF DEFAULT allowed_direct_url_schemes $CINDER_ALLOWED_DIRECT_URL_SCHEMES
316 fi
Kaitlin Farra5b72b02016-01-26 22:46:13 -0500317
Brian Rosmaitaf44aa0c2021-08-04 18:27:48 -0400318 # set default quotas
319 iniset $CINDER_CONF DEFAULT quota_volumes ${CINDER_QUOTA_VOLUMES:-10}
320 iniset $CINDER_CONF DEFAULT quota_backups ${CINDER_QUOTA_BACKUPS:-10}
321 iniset $CINDER_CONF DEFAULT quota_snapshots ${CINDER_QUOTA_SNAPSHOTS:-10}
322
Lee Yarwoodfc417172020-12-23 10:52:20 +0000323 # Avoid RPC timeouts in slow CI and test environments by doubling the
324 # default response timeout set by RPC clients. See bug #1873234 for more
325 # details and example failures.
326 iniset $CINDER_CONF DEFAULT rpc_response_timeout 120
327
Dean Troyer09718332014-07-03 10:46:57 -0500328 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500329 local enabled_backends=""
330 local default_name=""
331 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500332 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500333 be_type=${be%%:*}
334 be_name=${be##*:}
335 if type configure_cinder_backend_${be_type} >/dev/null 2>&1; then
336 configure_cinder_backend_${be_type} ${be_name}
Dean Troyer09718332014-07-03 10:46:57 -0500337 fi
Dean Troyera25922b2014-08-28 09:29:47 -0500338 if [[ -z "$default_name" ]]; then
339 default_name=$be_name
Dean Troyer09718332014-07-03 10:46:57 -0500340 fi
Dean Troyere8a35ac2014-07-25 12:37:41 -0500341 enabled_backends+=$be_name,
Dean Troyer09718332014-07-03 10:46:57 -0500342 done
343 iniset $CINDER_CONF DEFAULT enabled_backends ${enabled_backends%,*}
Matt Riedemann6a4aa782014-07-25 13:35:53 -0700344 if [[ -n "$default_name" ]]; then
345 iniset $CINDER_CONF DEFAULT default_volume_type ${default_name}
Dean Troyer09718332014-07-03 10:46:57 -0500346 fi
Patrick Eastdddb2c72016-05-03 17:34:00 -0700347 configure_cinder_image_volume_cache
Dean Troyer09718332014-07-03 10:46:57 -0500348 fi
349
Hironori Shiina01a84d22021-01-11 13:42:46 -0500350 if is_service_enabled c-bak && [[ -n "$CINDER_BACKUP_DRIVER" ]]; then
351 if type configure_cinder_backup_$CINDER_BACKUP_DRIVER >/dev/null 2>&1; then
352 configure_cinder_backup_$CINDER_BACKUP_DRIVER
353 else
354 die "configure_cinder_backup_$CINDER_BACKUP_DRIVER doesn't exist in $CINDER_BACKUPS/$CINDER_BACKUP_DRIVER"
355 fi
Attila Fazekas29834742014-03-09 18:36:42 +0100356 fi
357
Gordon Chung2bfbc772013-08-09 10:55:12 -0400358 if is_service_enabled ceilometer; then
Matt Riedemann45da7772017-03-05 13:07:39 -0500359 iniset $CINDER_CONF oslo_messaging_notifications driver "messagingv2"
Gordon Chung2bfbc772013-08-09 10:55:12 -0400360 fi
361
Dean Troyer560346b2012-12-13 17:05:24 -0600362 if is_service_enabled tls-proxy; then
Sean McGinnisdaf12742017-03-03 18:09:35 +0000363 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
364 # Set the service port for a proxy to take the original
365 if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
366 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
Jens Harbott411c34d2017-08-29 14:40:26 +0000367 iniset $CINDER_CONF oslo_middleware enable_proxy_headers_parsing True
Sean McGinnisdaf12742017-03-03 18:09:35 +0000368 else
369 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
370 iniset $CINDER_CONF DEFAULT public_endpoint $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT
371 iniset $CINDER_CONF DEFAULT osapi_volume_base_URL $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT
372 fi
373 fi
Dean Troyer560346b2012-12-13 17:05:24 -0600374 fi
375
Dean Troyer4d3049e2012-11-06 20:38:14 -0600376 if [ "$SYSLOG" != "False" ]; then
377 iniset $CINDER_CONF DEFAULT use_syslog True
378 fi
379
Brant Knudson2dd110c2015-03-14 12:39:14 -0500380 iniset_rpc_backend cinder $CINDER_CONF
Gary Kottonf71bf192012-08-06 11:15:36 -0400381
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700382 # Format logging
Sean Dague9751be62016-04-05 12:08:57 -0400383 setup_logging $CINDER_CONF $CINDER_USE_MOD_WSGI
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000384
Lee Yarwoodfc8ef862021-03-09 17:32:25 +0000385 if is_service_enabled c-api; then
386 write_uwsgi_config "$CINDER_UWSGI_CONF" "$CINDER_UWSGI" "/volume"
387 fi
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300388
john-griffithd0860cc2014-01-23 11:31:10 -0700389 if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
390 configure_cinder_driver
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000391 fi
Ian Wienand0db17132013-06-26 22:31:48 +1000392
Dean Troyer05bd7b82014-09-16 17:25:33 -0500393 iniset $CINDER_CONF DEFAULT osapi_volume_workers "$API_WORKERS"
Rob Crittenden18d47782014-03-19 17:47:42 -0400394
Matthew Treinish1fa65362017-06-23 22:32:37 +0000395 iniset $CINDER_CONF DEFAULT glance_api_servers "$GLANCE_URL"
Sean Daguef3b2f4c2017-04-13 10:11:48 -0400396 if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -0400397 iniset $CINDER_CONF DEFAULT glance_protocol https
Rob Crittenden4b109292014-10-21 18:17:48 -0400398 iniset $CINDER_CONF DEFAULT glance_ca_certificates_file $SSL_BUNDLE_FILE
Rob Crittenden18d47782014-03-19 17:47:42 -0400399 fi
400
Gyorgy Szombathelyic04ac032017-05-23 16:52:35 +0200401 # Set nova credentials (used for os-assisted-snapshots)
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100402 configure_keystone_authtoken_middleware $CINDER_CONF nova nova
Gyorgy Szombathelyic04ac032017-05-23 16:52:35 +0200403 iniset $CINDER_CONF nova region_name "$REGION_NAME"
Marian Horban7159b4b2015-10-22 15:47:49 -0400404 iniset $CINDER_CONF DEFAULT graceful_shutdown_timeout "$SERVICE_GRACEFUL_SHUTDOWN_TIMEOUT"
Mehdi Abaakouk52b10742016-12-01 16:11:17 +0100405
Davanum Srinivasc0d16c22017-05-19 10:23:46 -0400406 if [[ ! -z "$CINDER_COORDINATION_URL" ]]; then
407 iniset $CINDER_CONF coordination backend_url "$CINDER_COORDINATION_URL"
408 elif is_service_enabled etcd3; then
Davanum Srinivas27367be2017-11-28 08:20:48 -0500409 iniset $CINDER_CONF coordination backend_url "etcd3+http://${SERVICE_HOST}:$ETCD_PORT"
Mehdi Abaakouk52b10742016-12-01 16:11:17 +0100410 fi
Ghanshyam Mannbd0d0fd2021-03-06 17:23:39 -0600411
Grzegorz Grasza86155632021-10-18 16:52:06 +0200412 if [[ "$CINDER_ENFORCE_SCOPE" == True || "$ENFORCE_SCOPE" == True ]] ; then
Ghanshyam Mannbd0d0fd2021-03-06 17:23:39 -0600413 iniset $CINDER_CONF oslo_policy enforce_scope true
414 iniset $CINDER_CONF oslo_policy enforce_new_defaults true
Ghanshyam Mann69d71cf2023-01-10 20:13:47 -0600415 else
416 iniset $CINDER_CONF oslo_policy enforce_scope false
417 iniset $CINDER_CONF oslo_policy enforce_new_defaults false
Ghanshyam Mannbd0d0fd2021-03-06 17:23:39 -0600418 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500419}
420
Dean Troyer671c16e2012-12-13 16:22:38 -0600421# create_cinder_accounts() - Set up common required cinder accounts
422
Alan Bishopccd116d2022-08-10 10:30:19 -0700423# Project User Roles
Dean Troyer671c16e2012-12-13 16:22:38 -0600424# ------------------------------------------------------------------
Alan Bishopccd116d2022-08-10 10:30:19 -0700425# SERVICE_PROJECT_NAME cinder service
426# SERVICE_PROJECT_NAME cinder creator (if Barbican is enabled)
Dean Troyer671c16e2012-12-13 16:22:38 -0600427
428# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100429function create_cinder_accounts {
Dean Troyer671c16e2012-12-13 16:22:38 -0600430 # Cinder
431 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100432
Alan Bishopccd116d2022-08-10 10:30:19 -0700433 local extra_role=""
434
435 # cinder needs the "creator" role in order to interact with barbican
436 if is_service_enabled barbican; then
437 extra_role=$(get_or_create_role "creator")
438 fi
439
440 create_service_user "cinder" $extra_role
Bartosz Górski0abde392014-02-28 14:15:19 +0100441
Eric Friedcda2cb52017-10-10 11:49:06 -0500442 # block-storage is the official service type
443 get_or_create_service "cinder" "block-storage" "Cinder Volume Service"
Sean McGinnisdaf12742017-03-03 18:09:35 +0000444 if [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
445 get_or_create_endpoint \
Eric Friedcda2cb52017-10-10 11:49:06 -0500446 "block-storage" \
447 "$REGION_NAME" \
Monty Taylor69057d42018-05-01 05:57:21 -0500448 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s"
Eric Friedcda2cb52017-10-10 11:49:06 -0500449
Sean McGinnisdaf12742017-03-03 18:09:35 +0000450 get_or_create_service "cinderv3" "volumev3" "Cinder Volume Service V3"
451 get_or_create_endpoint \
452 "volumev3" \
453 "$REGION_NAME" \
454 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s"
455 else
456 get_or_create_endpoint \
Eric Friedcda2cb52017-10-10 11:49:06 -0500457 "block-storage" \
458 "$REGION_NAME" \
Monty Taylor69057d42018-05-01 05:57:21 -0500459 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume/v3/\$(project_id)s"
Eric Friedcda2cb52017-10-10 11:49:06 -0500460
Sean McGinnisdaf12742017-03-03 18:09:35 +0000461 get_or_create_service "cinderv3" "volumev3" "Cinder Volume Service V3"
462 get_or_create_endpoint \
463 "volumev3" \
464 "$REGION_NAME" \
465 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume/v3/\$(project_id)s"
466 fi
Patrick Eastdddb2c72016-05-03 17:34:00 -0700467
468 configure_cinder_internal_tenant
Dean Troyer671c16e2012-12-13 16:22:38 -0600469 fi
470}
471
Dean Troyer67787e62012-05-02 11:48:15 -0500472# init_cinder() - Initialize database and volume group
Ian Wienandaee18c72014-02-21 15:35:08 +1100473function init_cinder {
Terry Wilson428af5a2012-11-01 16:12:39 -0400474 if is_service_enabled $DATABASE_BACKENDS; then
Dean Troyerf03bafe2013-02-12 10:58:28 -0600475 # (Re)create cinder database
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200476 recreate_database cinder
Dean Troyer67787e62012-05-02 11:48:15 -0500477
Clark Boylan633dbc32017-06-14 12:09:21 -0700478 time_start "dbsync"
Dean Troyerf03bafe2013-02-12 10:58:28 -0600479 # Migrate cinder database
Einst Crazy4f55c2d2016-05-04 08:14:01 +0000480 $CINDER_BIN_DIR/cinder-manage --config-file $CINDER_CONF db sync
Clark Boylan633dbc32017-06-14 12:09:21 -0700481 time_stop "dbsync"
Dean Troyer67787e62012-05-02 11:48:15 -0500482 fi
483
Dean Troyer09718332014-07-03 10:46:57 -0500484 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500485 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500486 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500487 be_type=${be%%:*}
488 be_name=${be##*:}
489 if type init_cinder_backend_${be_type} >/dev/null 2>&1; then
490 init_cinder_backend_${be_type} ${be_name}
Vincent Untz0230aa82012-06-14 08:51:01 +0200491 fi
Dean Troyer09718332014-07-03 10:46:57 -0500492 done
Dean Troyer67787e62012-05-02 11:48:15 -0500493 fi
Dean Troyerbc071bc2012-10-01 14:06:44 -0500494
Hironori Shiina01a84d22021-01-11 13:42:46 -0500495 if is_service_enabled c-bak && [[ -n "$CINDER_BACKUP_DRIVER" ]]; then
496 if type init_cinder_backup_$CINDER_BACKUP_DRIVER >/dev/null 2>&1; then
497 init_cinder_backup_$CINDER_BACKUP_DRIVER
498 fi
499 fi
500
Dean Troyer09718332014-07-03 10:46:57 -0500501 mkdir -p $CINDER_STATE_PATH/volumes
Dean Troyer67787e62012-05-02 11:48:15 -0500502}
503
504# install_cinder() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100505function install_cinder {
Dean Troyer67787e62012-05-02 11:48:15 -0500506 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400507 setup_develop $CINDER_DIR
Gorka Eguileor97061c92021-10-14 09:55:56 +0200508 if [[ "$CINDER_TARGET_HELPER" == "tgtadm" ]]; then
Ian Wienanda881b882017-04-19 15:42:34 +1000509 install_package tgt
Gorka Eguileor97061c92021-10-14 09:55:56 +0200510 elif [[ "$CINDER_TARGET_HELPER" == "lioadm" ]]; then
Xinliang Liub0667072020-06-28 08:55:28 +0000511 if is_ubuntu; then
whoami-rajatf28c75f2019-03-13 23:41:05 +0530512 # TODO(frickler): Workaround for https://launchpad.net/bugs/1819819
513 sudo mkdir -p /etc/target
514
Eric Harney363acd92019-03-04 17:50:47 -0500515 install_package targetcli-fb
516 else
517 install_package targetcli
518 fi
Gorka Eguileor97061c92021-10-14 09:55:56 +0200519 elif [[ "$CINDER_TARGET_HELPER" == "nvmet" ]]; then
520 install_package nvme-cli
521
522 # TODO: Remove manual installation of the dependency when the
523 # requirement is added to nvmetcli:
524 # http://lists.infradead.org/pipermail/linux-nvme/2022-July/033576.html
525 if is_ubuntu; then
526 install_package python3-configshell-fb
527 else
528 install_package python3-configshell
529 fi
530 # Install from source because Ubuntu doesn't have the package and some packaged versions didn't work on Python 3
531 pip_install git+git://git.infradead.org/users/hch/nvmetcli.git
532
533 sudo modprobe nvmet
534 sudo modprobe nvme-fabrics
535
536 if [[ $CINDER_TARGET_PROTOCOL == 'nvmet_rdma' ]]; then
537 install_package rdma-core
538 sudo modprobe nvme-rdma
539
540 # Create the Soft-RoCE device over the networking interface
541 local iface=${HOST_IP_IFACE:-`ip -br -$SERVICE_IP_VERSION a | grep $CINDER_MY_IP | awk '{print $1}'`}
542 if [[ -z "$iface" ]]; then
543 die $LINENO "Cannot find interface to bind Soft-RoCE"
544 fi
545
546 if ! sudo rdma link | grep $iface ; then
547 sudo rdma link add rxe_$iface type rxe netdev $iface
548 fi
549
550 elif [[ $CINDER_TARGET_PROTOCOL == 'nvmet_tcp' ]]; then
551 sudo modprobe nvme-tcp
552
553 else # 'nvmet_fc'
554 sudo modprobe nvme-fc
555 fi
Attila Fazekasc70605d2015-01-26 15:44:47 +0100556 fi
Dean Troyer253a1a32013-04-01 18:23:22 -0500557}
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400558
Dean Troyer253a1a32013-04-01 18:23:22 -0500559# install_cinderclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100560function install_cinderclient {
Ivan Kolodyazhny8d0d3112016-05-26 23:41:49 +0300561 if use_library_from_git "python-brick-cinderclient-ext"; then
562 git_clone_by_name "python-brick-cinderclient-ext"
563 setup_dev_lib "python-brick-cinderclient-ext"
564 fi
565
Sean Daguee08ab102014-11-13 17:09:28 -0500566 if use_library_from_git "python-cinderclient"; then
567 git_clone_by_name "python-cinderclient"
568 setup_dev_lib "python-cinderclient"
569 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 +0100570 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500571}
572
Steve Baker18225d92013-04-14 12:48:41 -0700573# apply config.d approach for cinder volumes directory
Ian Wienandaee18c72014-02-21 15:35:08 +1100574function _configure_tgt_for_config_d {
Steve Baker18225d92013-04-14 12:48:41 -0700575 if [[ ! -d /etc/tgt/stack.d/ ]]; then
576 sudo ln -sf $CINDER_STATE_PATH/volumes /etc/tgt/stack.d
Jordan Pittiera263e7d2016-01-07 19:40:44 +0100577 fi
578 if ! grep -q "include /etc/tgt/stack.d/*" /etc/tgt/targets.conf; then
Steve Baker18225d92013-04-14 12:48:41 -0700579 echo "include /etc/tgt/stack.d/*" | sudo tee -a /etc/tgt/targets.conf
Mate Lakata39caac2012-09-03 15:45:53 +0100580 fi
581}
582
Sean Dague0eebeb42017-08-30 14:16:58 -0400583# start_cinder() - Start running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100584function start_cinder {
Rob Crittenden18d47782014-03-19 17:47:42 -0400585 local service_port=$CINDER_SERVICE_PORT
586 local service_protocol=$CINDER_SERVICE_PROTOCOL
Sean McGinnisdaf12742017-03-03 18:09:35 +0000587 local cinder_url
Eric Harney8ea86602017-08-02 11:40:41 -0400588 if is_service_enabled tls-proxy && [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
Rob Crittenden18d47782014-03-19 17:47:42 -0400589 service_port=$CINDER_SERVICE_PORT_INT
590 service_protocol="http"
591 fi
Gorka Eguileor97061c92021-10-14 09:55:56 +0200592 if [ "$CINDER_TARGET_HELPER" = "tgtadm" ]; then
Attila Fazekasc70605d2015-01-26 15:44:47 +0100593 if is_service_enabled c-vol; then
594 # Delete any old stack.conf
595 sudo rm -f /etc/tgt/conf.d/stack.conf
596 _configure_tgt_for_config_d
597 if is_ubuntu; then
598 sudo service tgt restart
Dirk Mueller6bc089f2015-06-01 12:39:12 +0200599 elif is_suse; then
600 # NOTE(dmllr): workaround restart bug
601 # https://bugzilla.suse.com/show_bug.cgi?id=934642
602 stop_service tgtd
603 start_service tgtd
Attila Fazekasc70605d2015-01-26 15:44:47 +0100604 else
Dirk Mueller6bc089f2015-06-01 12:39:12 +0200605 restart_service tgtd
Attila Fazekasc70605d2015-01-26 15:44:47 +0100606 fi
607 # NOTE(gfidente): ensure tgtd is running in debug mode
608 sudo tgtadm --mode system --op update --name debug --value on
Dean Troyer67787e62012-05-02 11:48:15 -0500609 fi
610 fi
611
Sean McGinnisdaf12742017-03-03 18:09:35 +0000612 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
613 if [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
Clark Boylan2dfca042017-05-25 14:57:19 -0700614 run_process c-api "$CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
Sean McGinnisdaf12742017-03-03 18:09:35 +0000615 cinder_url=$service_protocol://$SERVICE_HOST:$service_port
Jens Harbott52609c62017-08-28 11:49:28 +0000616 # Start proxy if tls enabled
617 if is_service_enabled tls-proxy; then
618 start_tls_proxy cinder '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT
Sean McGinnisdaf12742017-03-03 18:09:35 +0000619 fi
620 else
Ian Wienand312517d2018-06-22 22:23:29 +1000621 run_process "c-api" "$(which uwsgi) --procname-prefix cinder-api --ini $CINDER_UWSGI_CONF"
Sean McGinnisdaf12742017-03-03 18:09:35 +0000622 cinder_url=$service_protocol://$SERVICE_HOST/volume/v3
Clark Boylan2dfca042017-05-25 14:57:19 -0700623 fi
Sean McGinnisdaf12742017-03-03 18:09:35 +0000624 fi
Eli Qiao4af6eea2017-02-28 15:13:02 +0800625
Sean McGinnisdaf12742017-03-03 18:09:35 +0000626 echo "Waiting for Cinder API to start..."
627 if ! wait_for_service $SERVICE_TIMEOUT $cinder_url; then
628 die $LINENO "c-api did not start"
Dean Troyer09718332014-07-03 10:46:57 -0500629 fi
630
Dean Troyer3159a822014-08-27 14:13:58 -0500631 run_process c-sch "$CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
Gorka Eguileord5af5142022-06-08 10:19:50 +0200632 # Tune glibc for Python Services using single malloc arena for all threads
633 # and disabling dynamic thresholds to reduce memory usage when using native
634 # threads directly or via eventlet.tpool
635 # https://www.gnu.org/software/libc/manual/html_node/Memory-Allocation-Tunables.html
636 malloc_tuning="MALLOC_ARENA_MAX=1 MALLOC_MMAP_THRESHOLD_=131072 MALLOC_TRIM_THRESHOLD_=262144"
637 run_process c-bak "$CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF" "" "" "$malloc_tuning"
638 run_process c-vol "$CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF" "" "" "$malloc_tuning"
John Griffithe6d4fe52013-07-15 17:35:54 -0600639
640 # NOTE(jdg): For cinder, startup order matters. To ensure that repor_capabilities is received
641 # by the scheduler start the cinder-volume service last (or restart it) after the scheduler
642 # has started. This is a quick fix for lp bug/1189595
Dean Troyer67787e62012-05-02 11:48:15 -0500643}
644
Dean Troyer699a29f2012-09-10 14:10:27 -0500645# stop_cinder() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100646function stop_cinder {
Sean McGinnisdaf12742017-03-03 18:09:35 +0000647 stop_process c-api
Sean Dague0eebeb42017-08-30 14:16:58 -0400648 stop_process c-bak
649 stop_process c-sch
650 stop_process c-vol
Dean Troyer67787e62012-05-02 11:48:15 -0500651}
Dean Troyer7903b792012-09-13 17:16:12 -0500652
Rajat Dhasmana1898a682023-03-14 05:35:33 +0000653function create_one_type {
654 type_name=$1
655 property_key=$2
656 property_value=$3
657 # NOTE (e0ne): openstack client doesn't work with cinder in noauth mode
658 if is_service_enabled keystone; then
659 openstack --os-region-name="$REGION_NAME" volume type create --property $property_key="$property_value" $type_name
660 else
661 # TODO (e0ne): use openstack client once it will support cinder in noauth mode:
662 # https://bugs.launchpad.net/python-cinderclient/+bug/1755279
663 local cinder_url
664 cinder_url=$CINDER_SERVICE_PROTOCOL://$SERVICE_HOST:$CINDER_SERVICE_PORT/v3
665 OS_USER_ID=$OS_USERNAME OS_PROJECT_ID=$OS_PROJECT_NAME cinder --os-auth-type noauth --os-endpoint=$cinder_url type-create $type_name
666 OS_USER_ID=$OS_USERNAME OS_PROJECT_ID=$OS_PROJECT_NAME cinder --os-auth-type noauth --os-endpoint=$cinder_url type-key $type_name set $property_key="$property_value"
667 fi
668}
669
Dean Troyer09718332014-07-03 10:46:57 -0500670# create_volume_types() - Create Cinder's configured volume types
671function create_volume_types {
672 # Create volume types
673 if is_service_enabled c-api && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Jamie Lennox494f7cd2015-05-29 08:33:03 +0000674 local be be_name
Dean Troyer09718332014-07-03 10:46:57 -0500675 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500676 be_name=${be##*:}
Rajat Dhasmana1898a682023-03-14 05:35:33 +0000677 create_one_type $be_name "volume_backend_name" $be_name
Dean Troyer09718332014-07-03 10:46:57 -0500678 done
Dan Smithb4bba2f2021-02-04 23:24:17 +0000679
Rajat Dhasmana1898a682023-03-14 05:35:33 +0000680 if [[ $ENABLE_VOLUME_MULTIATTACH == "True" ]]; then
681 create_one_type $VOLUME_TYPE_MULTIATTACH $VOLUME_TYPE_MULTIATTACH "<is> True"
682 fi
683
Dan Smithb4bba2f2021-02-04 23:24:17 +0000684 # Increase quota for the service project if glance is using cinder,
685 # since it's likely to occasionally go above the default 10 in parallel
686 # test execution.
687 if [[ "$USE_CINDER_FOR_GLANCE" == "True" ]]; then
688 openstack --os-region-name="$REGION_NAME" \
689 quota set --volumes 50 "$SERVICE_PROJECT_NAME"
690 fi
Dean Troyer09718332014-07-03 10:46:57 -0500691 fi
692}
693
694# Compatibility for Grenade
695
696function create_cinder_volume_group {
697 # During a transition period Grenade needs to have this function defined
698 # It is effectively a no-op in the Grenade 'target' use case
699 :
700}
701
Patrick Eastdddb2c72016-05-03 17:34:00 -0700702function configure_cinder_internal_tenant {
703 # Re-use the Cinder service account for simplicity.
704 iniset $CINDER_CONF DEFAULT cinder_internal_tenant_project_id $(get_or_create_project $SERVICE_PROJECT_NAME)
705 iniset $CINDER_CONF DEFAULT cinder_internal_tenant_user_id $(get_or_create_user "cinder")
706}
707
708function configure_cinder_image_volume_cache {
709 # Expect CINDER_CACHE_ENABLED_FOR_BACKENDS to be a list of backends
710 # similar to CINDER_ENABLED_BACKENDS with NAME:TYPE where NAME will
711 # be the backend specific configuration stanza in cinder.conf.
712 for be in ${CINDER_CACHE_ENABLED_FOR_BACKENDS//,/ }; do
713 local be_name=${be##*:}
714
715 iniset $CINDER_CONF $be_name image_volume_cache_enabled $CINDER_IMG_CACHE_ENABLED
716
717 if [[ -n $CINDER_IMG_CACHE_SIZE_GB ]]; then
718 iniset $CINDER_CONF $be_name image_volume_cache_max_size_gb $CINDER_IMG_CACHE_SIZE_GB
719 fi
720
721 if [[ -n $CINDER_IMG_CACHE_SIZE_COUNT ]]; then
722 iniset $CINDER_CONF $be_name image_volume_cache_max_count $CINDER_IMG_CACHE_SIZE_COUNT
723 fi
724 done
725}
726
Dean Troyercc6b4432013-04-08 15:38:03 -0500727
Dean Troyer7903b792012-09-13 17:16:12 -0500728# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +1100729$_XTRACE_CINDER
Sean Dague584d90e2013-03-29 14:34:53 -0400730
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100731# Tell emacs to use shell-script-mode
732## Local variables:
733## mode: shell-script
734## End: