blob: b557d4b10b6ba1ca34b17dc52713755c11e8ef3a [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
Stephen Finucane05f7d302023-12-07 10:48:10 +000065CINDER_UWSGI=cinder.wsgi.api:application
Sean McGinnisdaf12742017-03-03 18:09:35 +000066CINDER_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
Dan Smith3832ff52023-08-03 09:16:55 -070079# We do not need to report service status every 10s for devstack-like
80# deployments. In the gate this generates extra work for the services and the
81# database which are already taxed.
Artom Lifshitz220004f2023-08-16 14:08:15 -040082CINDER_SERVICE_REPORT_INTERVAL=${CINDER_SERVICE_REPORT_INTERVAL:-120}
Dan Smith3832ff52023-08-03 09:16:55 -070083
John Griffithce8e6f62015-05-12 17:28:59 -060084# What type of LVM device should Cinder use for LVM backend
Sean McGinnis486376e2017-09-05 19:56:06 -050085# Defaults to auto, which will do thin provisioning if it's a fresh
86# volume group, otherwise it will do thick. The other valid choices are
87# default, which is thick, or thin, which as the name implies utilizes lvm
88# thin provisioning.
89CINDER_LVM_TYPE=${CINDER_LVM_TYPE:-auto}
Dean Troyer09718332014-07-03 10:46:57 -050090
Rajat Dhasmana80c16052024-02-28 13:08:12 +053091# ``CINDER_USE_SERVICE_TOKEN`` is a mode where service token is passed along with
92# user token while communicating to external REST APIs like Glance.
93CINDER_USE_SERVICE_TOKEN=$(trueorfalse True CINDER_USE_SERVICE_TOKEN)
94
Dean Troyer09718332014-07-03 10:46:57 -050095# Default backends
96# The backend format is type:name where type is one of the supported backend
97# types (lvm, nfs, etc) and name is the identifier used in the Cinder
98# configuration and for the volume type name. Multiple backends are
99# comma-separated.
Dean Troyer311f4872014-12-18 16:31:34 -0600100# The old ``CINDER_MULTI_LVM_BACKEND=True`` setting had a default of:
101# CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-lvm:lvmdriver-1,lvm:lvmdriver-2}
102CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-lvm:lvmdriver-1}
Dean Troyer09718332014-07-03 10:46:57 -0500103
Joe D'Andreadfcc3872015-04-29 15:39:17 -0400104CINDER_VOLUME_CLEAR=${CINDER_VOLUME_CLEAR:-${CINDER_VOLUME_CLEAR_DEFAULT:-zero}}
105CINDER_VOLUME_CLEAR=$(echo ${CINDER_VOLUME_CLEAR} | tr '[:upper:]' '[:lower:]')
Dean Troyerb7490da2013-03-18 16:07:56 -0500106
Rajat Dhasmana1898a682023-03-14 05:35:33 +0000107VOLUME_TYPE_MULTIATTACH=${VOLUME_TYPE_MULTIATTACH:-multiattach}
Gorka Eguileor97061c92021-10-14 09:55:56 +0200108
109if [[ -n "$CINDER_ISCSI_HELPER" ]]; then
110 if [[ -z "$CINDER_TARGET_HELPER" ]]; then
111 deprecated 'Using CINDER_ISCSI_HELPER is deprecated, use CINDER_TARGET_HELPER instead'
112 CINDER_TARGET_HELPER="$CINDER_ISCSI_HELPER"
113 else
114 deprecated 'Deprecated CINDER_ISCSI_HELPER is set, but is being overwritten by CINDER_TARGET_HELPER'
115 fi
116fi
117CINDER_TARGET_HELPER=${CINDER_TARGET_HELPER:-lioadm}
118
119if [[ $CINDER_TARGET_HELPER == 'nvmet' ]]; then
120 CINDER_TARGET_PROTOCOL=${CINDER_TARGET_PROTOCOL:-'nvmet_rdma'}
121 CINDER_TARGET_PREFIX=${CINDER_TARGET_PREFIX:-'nvme-subsystem-1'}
122 CINDER_TARGET_PORT=${CINDER_TARGET_PORT:-4420}
123else
124 CINDER_TARGET_PROTOCOL=${CINDER_TARGET_PROTOCOL:-'iscsi'}
125 CINDER_TARGET_PREFIX=${CINDER_TARGET_PREFIX:-'iqn.2010-10.org.openstack:'}
126 CINDER_TARGET_PORT=${CINDER_TARGET_PORT:-3260}
127fi
128
Lee Yarwoodc0627922021-03-09 22:36:57 +0000129
Martin Kopecec07b342023-01-24 17:38:45 +0100130# EL should only use lioadm
131if is_fedora; then
Gorka Eguileor97061c92021-10-14 09:55:56 +0200132 if [[ ${CINDER_TARGET_HELPER} != "lioadm" && ${CINDER_TARGET_HELPER} != 'nvmet' ]]; then
133 die "lioadm and nvmet are the only valid Cinder target_helper config on this platform"
Ian Wienanda881b882017-04-19 15:42:34 +1000134 fi
Ian Wienanda881b882017-04-19 15:42:34 +1000135fi
Attila Fazekasc70605d2015-01-26 15:44:47 +0100136
Brian Rosmaita6e9f7c22020-10-13 14:20:38 -0400137# When Cinder is used as a backend for Glance, it can be configured to clone
138# the volume containing image data directly in the backend instead of
139# transferring data from volume to volume. Value is a comma separated list of
140# schemes (currently only 'file' and 'cinder' are supported). The default
141# configuration in Cinder is empty (that is, do not use this feature). NOTE:
142# to use this feature you must also enable GLANCE_SHOW_DIRECT_URL and/or
143# GLANCE_SHOW_MULTIPLE_LOCATIONS for glance-api.conf.
144CINDER_ALLOWED_DIRECT_URL_SCHEMES=${CINDER_ALLOWED_DIRECT_URL_SCHEMES:-}
145if [[ -n "$CINDER_ALLOWED_DIRECT_URL_SCHEMES" ]]; then
146 if [[ "${GLANCE_SHOW_DIRECT_URL:-False}" != "True" \
147 && "${GLANCE_SHOW_MULTIPLE_LOCATIONS:-False}" != "True" ]]; then
148 warn $LINENO "CINDER_ALLOWED_DIRECT_URL_SCHEMES is set, but neither \
149GLANCE_SHOW_DIRECT_URL nor GLANCE_SHOW_MULTIPLE_LOCATIONS is True"
150 fi
151fi
152
Hironori Shiina01a84d22021-01-11 13:42:46 -0500153# For backward compatibility
154# Before CINDER_BACKUP_DRIVER was introduced, ceph backup driver was configured
155# along with ceph backend driver.
156if [[ -z "${CINDER_BACKUP_DRIVER}" && "$CINDER_ENABLED_BACKENDS" =~ "ceph" ]]; then
157 CINDER_BACKUP_DRIVER=ceph
158fi
159
160# Supported backup drivers are in lib/cinder_backups
161CINDER_BACKUP_DRIVER=${CINDER_BACKUP_DRIVER:-swift}
162
Dean Troyer09718332014-07-03 10:46:57 -0500163# Source the enabled backends
164if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
165 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500166 be_type=${be%%:*}
167 be_name=${be##*:}
168 if [[ -r $CINDER_BACKENDS/${be_type} ]]; then
169 source $CINDER_BACKENDS/${be_type}
Dean Troyer09718332014-07-03 10:46:57 -0500170 fi
171 done
172fi
173
Hironori Shiina01a84d22021-01-11 13:42:46 -0500174# Source the backup driver
175if is_service_enabled c-bak && [[ -n "$CINDER_BACKUP_DRIVER" ]]; then
176 if [[ -r $CINDER_BACKUPS/$CINDER_BACKUP_DRIVER ]]; then
177 source $CINDER_BACKUPS/$CINDER_BACKUP_DRIVER
178 else
179 die "cinder backup driver $CINDER_BACKUP_DRIVER is not supported"
180 fi
181fi
182
Patrick Eastdddb2c72016-05-03 17:34:00 -0700183# Environment variables to configure the image-volume cache
184CINDER_IMG_CACHE_ENABLED=${CINDER_IMG_CACHE_ENABLED:-True}
185
Rajat Dhasmanad6e3d062024-02-22 00:11:15 +0530186# Environment variables to configure the optimized volume upload
187CINDER_UPLOAD_OPTIMIZED=${CINDER_UPLOAD_OPTIMIZED:-False}
188
189# Environment variables to configure the internal tenant during optimized volume upload
190CINDER_UPLOAD_INTERNAL_TENANT=${CINDER_UPLOAD_INTERNAL_TENANT:-False}
191
Patrick Eastdddb2c72016-05-03 17:34:00 -0700192# For limits, if left unset, it will use cinder defaults of 0 for unlimited
193CINDER_IMG_CACHE_SIZE_GB=${CINDER_IMG_CACHE_SIZE_GB:-}
194CINDER_IMG_CACHE_SIZE_COUNT=${CINDER_IMG_CACHE_SIZE_COUNT:-}
195
196# Configure which cinder backends will have the image-volume cache, this takes the same
197# form as the CINDER_ENABLED_BACKENDS config option. By default it will
198# enable the cache for all cinder backends.
199CINDER_CACHE_ENABLED_FOR_BACKENDS=${CINDER_CACHE_ENABLED_FOR_BACKENDS:-$CINDER_ENABLED_BACKENDS}
Dean Troyer09718332014-07-03 10:46:57 -0500200
Rajat Dhasmanad6e3d062024-02-22 00:11:15 +0530201# Configure which cinder backends will have optimized volume upload, this takes the same
202# form as the CINDER_ENABLED_BACKENDS config option. By default it will
203# enable the cache for all cinder backends.
204CINDER_UPLOAD_OPTIMIZED_BACKENDS=${CINDER_UPLOAD_OPTIMIZED_BACKENDS:-$CINDER_ENABLED_BACKENDS}
205
Ghanshyam Mannbd0d0fd2021-03-06 17:23:39 -0600206# Flag to set the oslo_policy.enforce_scope. This is used to switch
207# the Volume API policies to start checking the scope of token. by default,
208# this flag is False.
209# For more detail: https://docs.openstack.org/oslo.policy/latest/configuration/index.html#oslo_policy.enforce_scope
210CINDER_ENFORCE_SCOPE=$(trueorfalse False CINDER_ENFORCE_SCOPE)
211
Dean Troyercc6b4432013-04-08 15:38:03 -0500212# Functions
213# ---------
Dean Troyere4fa7212014-01-15 15:04:49 -0600214
215# Test if any Cinder services are enabled
216# is_cinder_enabled
217function is_cinder_enabled {
Clark Boylan902158b2017-05-30 14:11:09 -0700218 [[ ,${DISABLED_SERVICES} =~ ,"cinder" ]] && return 1
Dean Troyere4fa7212014-01-15 15:04:49 -0600219 [[ ,${ENABLED_SERVICES} =~ ,"c-" ]] && return 0
220 return 1
221}
222
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300223# _cinder_cleanup_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
224function _cinder_cleanup_apache_wsgi {
225 sudo rm -f $(apache_site_config_for osapi-volume)
226}
227
Dean Troyer67787e62012-05-02 11:48:15 -0500228# cleanup_cinder() - Remove residual data files, anything left over from previous
229# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100230function cleanup_cinder {
Sean Dague252f2f52012-12-20 16:41:57 -0500231 # ensure the volume group is cleared up because fails might
232 # leave dead volumes in the group
Gorka Eguileor97061c92021-10-14 09:55:56 +0200233 if [ "$CINDER_TARGET_HELPER" = "tgtadm" ]; then
Ian Wienandada886d2015-10-07 14:06:26 +1100234 local targets
235 targets=$(sudo tgtadm --op show --mode target)
Attila Fazekasc70605d2015-01-26 15:44:47 +0100236 if [ $? -ne 0 ]; then
237 # If tgt driver isn't running this won't work obviously
238 # So check the response and restart if need be
239 echo "tgtd seems to be in a bad state, restarting..."
240 if is_ubuntu; then
241 restart_service tgt
242 else
243 restart_service tgtd
244 fi
245 targets=$(sudo tgtadm --op show --mode target)
Sean Dague252f2f52012-12-20 16:41:57 -0500246 fi
Sean Dague252f2f52012-12-20 16:41:57 -0500247
Attila Fazekasc70605d2015-01-26 15:44:47 +0100248 if [[ -n "$targets" ]]; then
249 local iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
250 for i in "${iqn_list[@]}"; do
251 echo removing iSCSI target: $i
252 sudo tgt-admin --delete $i
253 done
254 fi
Sean Dague252f2f52012-12-20 16:41:57 -0500255
Attila Fazekasc70605d2015-01-26 15:44:47 +0100256 if is_ubuntu; then
257 stop_service tgt
258 else
259 stop_service tgtd
260 fi
Gorka Eguileor97061c92021-10-14 09:55:56 +0200261 elif [ "$CINDER_TARGET_HELPER" = "lioadm" ]; then
Attila Fazekasc70605d2015-01-26 15:44:47 +0100262 sudo cinder-rtstool get-targets | sudo xargs -rn 1 cinder-rtstool delete
Gorka Eguileor97061c92021-10-14 09:55:56 +0200263 elif [ "$CINDER_TARGET_HELPER" = "nvmet" ]; then
264 # If we don't disconnect everything vgremove will block
265 sudo nvme disconnect-all
266 sudo nvmetcli clear
267 else
268 die $LINENO "Unknown value \"$CINDER_TARGET_HELPER\" for CINDER_TARGET_HELPER"
Sean Dague252f2f52012-12-20 16:41:57 -0500269 fi
270
Dean Troyer09718332014-07-03 10:46:57 -0500271 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500272 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500273 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500274 be_type=${be%%:*}
275 be_name=${be##*:}
276 if type cleanup_cinder_backend_${be_type} >/dev/null 2>&1; then
277 cleanup_cinder_backend_${be_type} ${be_name}
Dean Troyer09718332014-07-03 10:46:57 -0500278 fi
279 done
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100280 fi
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300281
Hironori Shiina01a84d22021-01-11 13:42:46 -0500282 if is_service_enabled c-bak && [[ -n "$CINDER_BACKUP_DRIVER" ]]; then
283 if type cleanup_cinder_backup_$CINDER_BACKUP_DRIVER >/dev/null 2>&1; then
284 cleanup_cinder_backup_$CINDER_BACKUP_DRIVER
285 fi
286 fi
287
Sean McGinnisdaf12742017-03-03 18:09:35 +0000288 stop_process "c-api"
Stephen Finucaned5182ce2024-04-19 12:27:14 +0100289 remove_uwsgi_config "$CINDER_UWSGI_CONF" "cinder-wsgi"
Dean Troyer67787e62012-05-02 11:48:15 -0500290}
291
Thierry Carrez63e17842014-01-10 14:23:03 +0100292# configure_cinder() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100293function configure_cinder {
Dean Troyer8421c2b2015-03-16 13:52:19 -0500294 sudo install -d -o $STACK_USER -m 755 $CINDER_CONF_DIR
Thierry Carrez63e17842014-01-10 14:23:03 +0100295
Yalei Wangcecbd1f2015-01-05 17:05:47 +0800296 rm -f $CINDER_CONF
297
Ian Wienandc6782412015-05-14 10:01:53 +1000298 configure_rootwrap cinder
John Griffith4e823ff2012-07-20 13:18:17 -0600299
TommyLike401de4d2017-05-04 17:56:22 +0800300 if [[ -f "$CINDER_DIR/etc/cinder/resource_filters.json" ]]; then
301 cp -p "$CINDER_DIR/etc/cinder/resource_filters.json" "$CINDER_CONF_DIR/resource_filters.json"
302 fi
303
Dean Troyer67787e62012-05-02 11:48:15 -0500304 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
Dan Prince82dea7c2013-10-16 18:57:15 -0400305
306 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_host
307 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_port
308 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_protocol
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000309 inicomment $CINDER_API_PASTE_INI filter:authtoken cafile
Dan Prince82dea7c2013-10-16 18:57:15 -0400310 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name
311 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_user
312 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_password
Ian Wienand1f82f432017-10-04 09:51:02 +1100313 inicomment $CINDER_API_PASTE_INI filter:authtoken signing_dir
Dean Troyerbc071bc2012-10-01 14:06:44 -0500314
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100315 configure_keystone_authtoken_middleware $CINDER_CONF cinder
Dan Prince82dea7c2013-10-16 18:57:15 -0400316
Ben Nemec03997942013-08-10 09:56:16 -0500317 iniset $CINDER_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Dean Troyer09718332014-07-03 10:46:57 -0500318
Gorka Eguileor97061c92021-10-14 09:55:56 +0200319 iniset $CINDER_CONF DEFAULT target_helper "$CINDER_TARGET_HELPER"
Joe Gordon23d6d502015-03-06 15:24:22 -0800320 iniset $CINDER_CONF database connection `database_connection_url cinder`
Dean Troyer67787e62012-05-02 11:48:15 -0500321 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
Joe Gordona58382a2013-02-20 12:45:02 -0800322 iniset $CINDER_CONF DEFAULT rootwrap_config "$CINDER_CONF_DIR/rootwrap.conf"
Dan Prince9f22f072013-01-28 09:53:38 -0500323 iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.contrib.standard_extensions
Brian Haley180f5eb2015-06-16 13:14:31 -0400324 iniset $CINDER_CONF DEFAULT osapi_volume_listen $CINDER_SERVICE_LISTEN_ADDRESS
Dean Troyer50ac7922012-09-13 14:02:01 -0500325 iniset $CINDER_CONF DEFAULT state_path $CINDER_STATE_PATH
Joe Gordon23d6d502015-03-06 15:24:22 -0800326 iniset $CINDER_CONF oslo_concurrency lock_path $CINDER_STATE_PATH
Gorka Eguileor97061c92021-10-14 09:55:56 +0200327 iniset $CINDER_CONF DEFAULT my_ip "$CINDER_MY_IP"
Sean McGinnis32712712017-09-22 07:49:15 -0500328 iniset $CINDER_CONF key_manager backend cinder.keymgr.conf_key_mgr.ConfKeyManager
lkuchlancb8256f2017-08-30 07:36:11 +0300329 iniset $CINDER_CONF key_manager fixed_key $(openssl rand -hex 16)
Brian Rosmaita6e9f7c22020-10-13 14:20:38 -0400330 if [[ -n "$CINDER_ALLOWED_DIRECT_URL_SCHEMES" ]]; then
331 iniset $CINDER_CONF DEFAULT allowed_direct_url_schemes $CINDER_ALLOWED_DIRECT_URL_SCHEMES
332 fi
Kaitlin Farra5b72b02016-01-26 22:46:13 -0500333
Brian Rosmaitaf44aa0c2021-08-04 18:27:48 -0400334 # set default quotas
335 iniset $CINDER_CONF DEFAULT quota_volumes ${CINDER_QUOTA_VOLUMES:-10}
336 iniset $CINDER_CONF DEFAULT quota_backups ${CINDER_QUOTA_BACKUPS:-10}
337 iniset $CINDER_CONF DEFAULT quota_snapshots ${CINDER_QUOTA_SNAPSHOTS:-10}
338
Lee Yarwoodfc417172020-12-23 10:52:20 +0000339 # Avoid RPC timeouts in slow CI and test environments by doubling the
340 # default response timeout set by RPC clients. See bug #1873234 for more
341 # details and example failures.
342 iniset $CINDER_CONF DEFAULT rpc_response_timeout 120
343
Dan Smith3832ff52023-08-03 09:16:55 -0700344 iniset $CINDER_CONF DEFAULT report_interval $CINDER_SERVICE_REPORT_INTERVAL
345 iniset $CINDER_CONF DEFAULT service_down_time $(($CINDER_SERVICE_REPORT_INTERVAL * 6))
346
Dean Troyer09718332014-07-03 10:46:57 -0500347 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500348 local enabled_backends=""
349 local default_name=""
350 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500351 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500352 be_type=${be%%:*}
353 be_name=${be##*:}
354 if type configure_cinder_backend_${be_type} >/dev/null 2>&1; then
355 configure_cinder_backend_${be_type} ${be_name}
Dean Troyer09718332014-07-03 10:46:57 -0500356 fi
Dean Troyera25922b2014-08-28 09:29:47 -0500357 if [[ -z "$default_name" ]]; then
358 default_name=$be_name
Dean Troyer09718332014-07-03 10:46:57 -0500359 fi
Dean Troyere8a35ac2014-07-25 12:37:41 -0500360 enabled_backends+=$be_name,
Dean Troyer09718332014-07-03 10:46:57 -0500361 done
362 iniset $CINDER_CONF DEFAULT enabled_backends ${enabled_backends%,*}
Matt Riedemann6a4aa782014-07-25 13:35:53 -0700363 if [[ -n "$default_name" ]]; then
364 iniset $CINDER_CONF DEFAULT default_volume_type ${default_name}
Dean Troyer09718332014-07-03 10:46:57 -0500365 fi
Patrick Eastdddb2c72016-05-03 17:34:00 -0700366 configure_cinder_image_volume_cache
Rajat Dhasmanad6e3d062024-02-22 00:11:15 +0530367
368 # The upload optimization uses Cinder's clone volume functionality to
369 # clone the Image-Volume from source volume hence can only be
370 # performed when glance is using cinder as it's backend.
371 if [[ "$USE_CINDER_FOR_GLANCE" == "True" ]]; then
372 # Configure optimized volume upload
373 configure_cinder_volume_upload
374 fi
Dean Troyer09718332014-07-03 10:46:57 -0500375 fi
376
Hironori Shiina01a84d22021-01-11 13:42:46 -0500377 if is_service_enabled c-bak && [[ -n "$CINDER_BACKUP_DRIVER" ]]; then
378 if type configure_cinder_backup_$CINDER_BACKUP_DRIVER >/dev/null 2>&1; then
379 configure_cinder_backup_$CINDER_BACKUP_DRIVER
380 else
381 die "configure_cinder_backup_$CINDER_BACKUP_DRIVER doesn't exist in $CINDER_BACKUPS/$CINDER_BACKUP_DRIVER"
382 fi
Attila Fazekas29834742014-03-09 18:36:42 +0100383 fi
384
Gordon Chung2bfbc772013-08-09 10:55:12 -0400385 if is_service_enabled ceilometer; then
Matt Riedemann45da7772017-03-05 13:07:39 -0500386 iniset $CINDER_CONF oslo_messaging_notifications driver "messagingv2"
Gordon Chung2bfbc772013-08-09 10:55:12 -0400387 fi
388
Dean Troyer560346b2012-12-13 17:05:24 -0600389 if is_service_enabled tls-proxy; then
Sean McGinnisdaf12742017-03-03 18:09:35 +0000390 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
391 # Set the service port for a proxy to take the original
Stephen Finucane7e8d5ef2024-10-11 15:34:18 +0100392 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
393 iniset $CINDER_CONF oslo_middleware enable_proxy_headers_parsing True
Sean McGinnisdaf12742017-03-03 18:09:35 +0000394 fi
Dean Troyer560346b2012-12-13 17:05:24 -0600395 fi
396
Dean Troyer4d3049e2012-11-06 20:38:14 -0600397 if [ "$SYSLOG" != "False" ]; then
398 iniset $CINDER_CONF DEFAULT use_syslog True
399 fi
400
Brant Knudson2dd110c2015-03-14 12:39:14 -0500401 iniset_rpc_backend cinder $CINDER_CONF
Gary Kottonf71bf192012-08-06 11:15:36 -0400402
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700403 # Format logging
Stephen Finucane7e8d5ef2024-10-11 15:34:18 +0100404 setup_logging $CINDER_CONF
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000405
Lee Yarwoodfc8ef862021-03-09 17:32:25 +0000406 if is_service_enabled c-api; then
Stephen Finucane05f7d302023-12-07 10:48:10 +0000407 write_uwsgi_config "$CINDER_UWSGI_CONF" "$CINDER_UWSGI" "/volume" "" "cinder-api"
Lee Yarwoodfc8ef862021-03-09 17:32:25 +0000408 fi
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300409
john-griffithd0860cc2014-01-23 11:31:10 -0700410 if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
411 configure_cinder_driver
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000412 fi
Ian Wienand0db17132013-06-26 22:31:48 +1000413
Dean Troyer05bd7b82014-09-16 17:25:33 -0500414 iniset $CINDER_CONF DEFAULT osapi_volume_workers "$API_WORKERS"
Rob Crittenden18d47782014-03-19 17:47:42 -0400415
Matthew Treinish1fa65362017-06-23 22:32:37 +0000416 iniset $CINDER_CONF DEFAULT glance_api_servers "$GLANCE_URL"
Sean Daguef3b2f4c2017-04-13 10:11:48 -0400417 if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -0400418 iniset $CINDER_CONF DEFAULT glance_protocol https
Rob Crittenden4b109292014-10-21 18:17:48 -0400419 iniset $CINDER_CONF DEFAULT glance_ca_certificates_file $SSL_BUNDLE_FILE
Rob Crittenden18d47782014-03-19 17:47:42 -0400420 fi
421
Gyorgy Szombathelyic04ac032017-05-23 16:52:35 +0200422 # Set nova credentials (used for os-assisted-snapshots)
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100423 configure_keystone_authtoken_middleware $CINDER_CONF nova nova
Gyorgy Szombathelyic04ac032017-05-23 16:52:35 +0200424 iniset $CINDER_CONF nova region_name "$REGION_NAME"
Marian Horban7159b4b2015-10-22 15:47:49 -0400425 iniset $CINDER_CONF DEFAULT graceful_shutdown_timeout "$SERVICE_GRACEFUL_SHUTDOWN_TIMEOUT"
Mehdi Abaakouk52b10742016-12-01 16:11:17 +0100426
Davanum Srinivasc0d16c22017-05-19 10:23:46 -0400427 if [[ ! -z "$CINDER_COORDINATION_URL" ]]; then
428 iniset $CINDER_CONF coordination backend_url "$CINDER_COORDINATION_URL"
429 elif is_service_enabled etcd3; then
Jan Gutter3a7a3cd2023-08-14 21:02:04 +0100430 # NOTE(jan.gutter): api_version can revert to default once tooz is
431 # updated with the etcd v3.4 defaults
432 iniset $CINDER_CONF coordination backend_url "etcd3+http://${SERVICE_HOST}:$ETCD_PORT?api_version=v3"
Mehdi Abaakouk52b10742016-12-01 16:11:17 +0100433 fi
Ghanshyam Mannbd0d0fd2021-03-06 17:23:39 -0600434
Grzegorz Grasza86155632021-10-18 16:52:06 +0200435 if [[ "$CINDER_ENFORCE_SCOPE" == True || "$ENFORCE_SCOPE" == True ]] ; then
Ghanshyam Mannbd0d0fd2021-03-06 17:23:39 -0600436 iniset $CINDER_CONF oslo_policy enforce_scope true
437 iniset $CINDER_CONF oslo_policy enforce_new_defaults true
Ghanshyam Mann69d71cf2023-01-10 20:13:47 -0600438 else
439 iniset $CINDER_CONF oslo_policy enforce_scope false
440 iniset $CINDER_CONF oslo_policy enforce_new_defaults false
Ghanshyam Mannbd0d0fd2021-03-06 17:23:39 -0600441 fi
Rajat Dhasmana80c16052024-02-28 13:08:12 +0530442
443 if [ "$CINDER_USE_SERVICE_TOKEN" == "True" ]; then
444 init_cinder_service_user_conf
445 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500446}
447
Dean Troyer671c16e2012-12-13 16:22:38 -0600448# create_cinder_accounts() - Set up common required cinder accounts
449
Alan Bishopccd116d2022-08-10 10:30:19 -0700450# Project User Roles
Dean Troyer671c16e2012-12-13 16:22:38 -0600451# ------------------------------------------------------------------
Alan Bishopccd116d2022-08-10 10:30:19 -0700452# SERVICE_PROJECT_NAME cinder service
453# SERVICE_PROJECT_NAME cinder creator (if Barbican is enabled)
Dean Troyer671c16e2012-12-13 16:22:38 -0600454
455# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100456function create_cinder_accounts {
Dean Troyer671c16e2012-12-13 16:22:38 -0600457 # Cinder
458 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100459
Alan Bishopccd116d2022-08-10 10:30:19 -0700460 local extra_role=""
461
462 # cinder needs the "creator" role in order to interact with barbican
463 if is_service_enabled barbican; then
464 extra_role=$(get_or_create_role "creator")
465 fi
466
467 create_service_user "cinder" $extra_role
Bartosz Górski0abde392014-02-28 14:15:19 +0100468
Stephen Finucane9b443902024-09-20 11:03:15 +0100469 local cinder_api_url
Stephen Finucane7e8d5ef2024-10-11 15:34:18 +0100470 cinder_api_url="$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume"
Patrick Eastdddb2c72016-05-03 17:34:00 -0700471
Stephen Finucane9b443902024-09-20 11:03:15 +0100472 # block-storage is the official service type
473 get_or_create_service "cinder" "block-storage" "Cinder Volume Service"
474 get_or_create_endpoint \
475 "block-storage" \
476 "$REGION_NAME" \
477 "$cinder_api_url/v3"
Patrick Eastdddb2c72016-05-03 17:34:00 -0700478 configure_cinder_internal_tenant
Dean Troyer671c16e2012-12-13 16:22:38 -0600479 fi
480}
481
Dean Troyer67787e62012-05-02 11:48:15 -0500482# init_cinder() - Initialize database and volume group
Ian Wienandaee18c72014-02-21 15:35:08 +1100483function init_cinder {
Terry Wilson428af5a2012-11-01 16:12:39 -0400484 if is_service_enabled $DATABASE_BACKENDS; then
Dean Troyerf03bafe2013-02-12 10:58:28 -0600485 # (Re)create cinder database
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200486 recreate_database cinder
Dean Troyer67787e62012-05-02 11:48:15 -0500487
Clark Boylan633dbc32017-06-14 12:09:21 -0700488 time_start "dbsync"
Dean Troyerf03bafe2013-02-12 10:58:28 -0600489 # Migrate cinder database
Einst Crazy4f55c2d2016-05-04 08:14:01 +0000490 $CINDER_BIN_DIR/cinder-manage --config-file $CINDER_CONF db sync
Clark Boylan633dbc32017-06-14 12:09:21 -0700491 time_stop "dbsync"
Dean Troyer67787e62012-05-02 11:48:15 -0500492 fi
493
Dean Troyer09718332014-07-03 10:46:57 -0500494 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500495 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500496 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500497 be_type=${be%%:*}
498 be_name=${be##*:}
499 if type init_cinder_backend_${be_type} >/dev/null 2>&1; then
500 init_cinder_backend_${be_type} ${be_name}
Vincent Untz0230aa82012-06-14 08:51:01 +0200501 fi
Dean Troyer09718332014-07-03 10:46:57 -0500502 done
Dean Troyer67787e62012-05-02 11:48:15 -0500503 fi
Dean Troyerbc071bc2012-10-01 14:06:44 -0500504
Hironori Shiina01a84d22021-01-11 13:42:46 -0500505 if is_service_enabled c-bak && [[ -n "$CINDER_BACKUP_DRIVER" ]]; then
506 if type init_cinder_backup_$CINDER_BACKUP_DRIVER >/dev/null 2>&1; then
507 init_cinder_backup_$CINDER_BACKUP_DRIVER
508 fi
509 fi
510
Dean Troyer09718332014-07-03 10:46:57 -0500511 mkdir -p $CINDER_STATE_PATH/volumes
Dean Troyer67787e62012-05-02 11:48:15 -0500512}
513
514# install_cinder() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100515function install_cinder {
Dean Troyer67787e62012-05-02 11:48:15 -0500516 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400517 setup_develop $CINDER_DIR
Gorka Eguileor97061c92021-10-14 09:55:56 +0200518 if [[ "$CINDER_TARGET_HELPER" == "tgtadm" ]]; then
Ian Wienanda881b882017-04-19 15:42:34 +1000519 install_package tgt
Gorka Eguileor97061c92021-10-14 09:55:56 +0200520 elif [[ "$CINDER_TARGET_HELPER" == "lioadm" ]]; then
Xinliang Liub0667072020-06-28 08:55:28 +0000521 if is_ubuntu; then
whoami-rajatf28c75f2019-03-13 23:41:05 +0530522 # TODO(frickler): Workaround for https://launchpad.net/bugs/1819819
523 sudo mkdir -p /etc/target
524
Eric Harney363acd92019-03-04 17:50:47 -0500525 install_package targetcli-fb
526 else
527 install_package targetcli
528 fi
Gorka Eguileor97061c92021-10-14 09:55:56 +0200529 elif [[ "$CINDER_TARGET_HELPER" == "nvmet" ]]; then
530 install_package nvme-cli
531
532 # TODO: Remove manual installation of the dependency when the
533 # requirement is added to nvmetcli:
534 # http://lists.infradead.org/pipermail/linux-nvme/2022-July/033576.html
535 if is_ubuntu; then
536 install_package python3-configshell-fb
537 else
538 install_package python3-configshell
539 fi
540 # Install from source because Ubuntu doesn't have the package and some packaged versions didn't work on Python 3
541 pip_install git+git://git.infradead.org/users/hch/nvmetcli.git
542
543 sudo modprobe nvmet
544 sudo modprobe nvme-fabrics
545
546 if [[ $CINDER_TARGET_PROTOCOL == 'nvmet_rdma' ]]; then
547 install_package rdma-core
548 sudo modprobe nvme-rdma
549
550 # Create the Soft-RoCE device over the networking interface
551 local iface=${HOST_IP_IFACE:-`ip -br -$SERVICE_IP_VERSION a | grep $CINDER_MY_IP | awk '{print $1}'`}
552 if [[ -z "$iface" ]]; then
553 die $LINENO "Cannot find interface to bind Soft-RoCE"
554 fi
555
556 if ! sudo rdma link | grep $iface ; then
557 sudo rdma link add rxe_$iface type rxe netdev $iface
558 fi
559
560 elif [[ $CINDER_TARGET_PROTOCOL == 'nvmet_tcp' ]]; then
561 sudo modprobe nvme-tcp
562
563 else # 'nvmet_fc'
564 sudo modprobe nvme-fc
565 fi
Attila Fazekasc70605d2015-01-26 15:44:47 +0100566 fi
Dean Troyer253a1a32013-04-01 18:23:22 -0500567}
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400568
Dean Troyer253a1a32013-04-01 18:23:22 -0500569# install_cinderclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100570function install_cinderclient {
Ivan Kolodyazhny8d0d3112016-05-26 23:41:49 +0300571 if use_library_from_git "python-brick-cinderclient-ext"; then
572 git_clone_by_name "python-brick-cinderclient-ext"
573 setup_dev_lib "python-brick-cinderclient-ext"
574 fi
575
Sean Daguee08ab102014-11-13 17:09:28 -0500576 if use_library_from_git "python-cinderclient"; then
577 git_clone_by_name "python-cinderclient"
578 setup_dev_lib "python-cinderclient"
579 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 +0100580 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500581}
582
Steve Baker18225d92013-04-14 12:48:41 -0700583# apply config.d approach for cinder volumes directory
Ian Wienandaee18c72014-02-21 15:35:08 +1100584function _configure_tgt_for_config_d {
Steve Baker18225d92013-04-14 12:48:41 -0700585 if [[ ! -d /etc/tgt/stack.d/ ]]; then
586 sudo ln -sf $CINDER_STATE_PATH/volumes /etc/tgt/stack.d
Jordan Pittiera263e7d2016-01-07 19:40:44 +0100587 fi
588 if ! grep -q "include /etc/tgt/stack.d/*" /etc/tgt/targets.conf; then
Steve Baker18225d92013-04-14 12:48:41 -0700589 echo "include /etc/tgt/stack.d/*" | sudo tee -a /etc/tgt/targets.conf
Mate Lakata39caac2012-09-03 15:45:53 +0100590 fi
591}
592
Sean Dague0eebeb42017-08-30 14:16:58 -0400593# start_cinder() - Start running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100594function start_cinder {
Rob Crittenden18d47782014-03-19 17:47:42 -0400595 local service_port=$CINDER_SERVICE_PORT
596 local service_protocol=$CINDER_SERVICE_PROTOCOL
Sean McGinnisdaf12742017-03-03 18:09:35 +0000597 local cinder_url
Gorka Eguileor97061c92021-10-14 09:55:56 +0200598 if [ "$CINDER_TARGET_HELPER" = "tgtadm" ]; then
Attila Fazekasc70605d2015-01-26 15:44:47 +0100599 if is_service_enabled c-vol; then
600 # Delete any old stack.conf
601 sudo rm -f /etc/tgt/conf.d/stack.conf
602 _configure_tgt_for_config_d
603 if is_ubuntu; then
604 sudo service tgt restart
Attila Fazekasc70605d2015-01-26 15:44:47 +0100605 else
Dirk Mueller6bc089f2015-06-01 12:39:12 +0200606 restart_service tgtd
Attila Fazekasc70605d2015-01-26 15:44:47 +0100607 fi
608 # NOTE(gfidente): ensure tgtd is running in debug mode
609 sudo tgtadm --mode system --op update --name debug --value on
Dean Troyer67787e62012-05-02 11:48:15 -0500610 fi
611 fi
612
Sean McGinnisdaf12742017-03-03 18:09:35 +0000613 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
Stephen Finucane7e8d5ef2024-10-11 15:34:18 +0100614 run_process "c-api" "$(which uwsgi) --procname-prefix cinder-api --ini $CINDER_UWSGI_CONF"
615 cinder_url=$service_protocol://$SERVICE_HOST/volume/v3
Sean McGinnisdaf12742017-03-03 18:09:35 +0000616 fi
Eli Qiao4af6eea2017-02-28 15:13:02 +0800617
Sean McGinnisdaf12742017-03-03 18:09:35 +0000618 echo "Waiting for Cinder API to start..."
619 if ! wait_for_service $SERVICE_TIMEOUT $cinder_url; then
620 die $LINENO "c-api did not start"
Dean Troyer09718332014-07-03 10:46:57 -0500621 fi
622
Dean Troyer3159a822014-08-27 14:13:58 -0500623 run_process c-sch "$CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
Gorka Eguileord5af5142022-06-08 10:19:50 +0200624 # Tune glibc for Python Services using single malloc arena for all threads
625 # and disabling dynamic thresholds to reduce memory usage when using native
626 # threads directly or via eventlet.tpool
627 # https://www.gnu.org/software/libc/manual/html_node/Memory-Allocation-Tunables.html
628 malloc_tuning="MALLOC_ARENA_MAX=1 MALLOC_MMAP_THRESHOLD_=131072 MALLOC_TRIM_THRESHOLD_=262144"
629 run_process c-bak "$CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF" "" "" "$malloc_tuning"
630 run_process c-vol "$CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF" "" "" "$malloc_tuning"
John Griffithe6d4fe52013-07-15 17:35:54 -0600631
632 # NOTE(jdg): For cinder, startup order matters. To ensure that repor_capabilities is received
633 # by the scheduler start the cinder-volume service last (or restart it) after the scheduler
634 # has started. This is a quick fix for lp bug/1189595
Dean Troyer67787e62012-05-02 11:48:15 -0500635}
636
Dean Troyer699a29f2012-09-10 14:10:27 -0500637# stop_cinder() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100638function stop_cinder {
Sean McGinnisdaf12742017-03-03 18:09:35 +0000639 stop_process c-api
Sean Dague0eebeb42017-08-30 14:16:58 -0400640 stop_process c-bak
641 stop_process c-sch
642 stop_process c-vol
Dean Troyer67787e62012-05-02 11:48:15 -0500643}
Dean Troyer7903b792012-09-13 17:16:12 -0500644
Rajat Dhasmana1898a682023-03-14 05:35:33 +0000645function create_one_type {
646 type_name=$1
647 property_key=$2
648 property_value=$3
649 # NOTE (e0ne): openstack client doesn't work with cinder in noauth mode
650 if is_service_enabled keystone; then
651 openstack --os-region-name="$REGION_NAME" volume type create --property $property_key="$property_value" $type_name
652 else
653 # TODO (e0ne): use openstack client once it will support cinder in noauth mode:
654 # https://bugs.launchpad.net/python-cinderclient/+bug/1755279
655 local cinder_url
656 cinder_url=$CINDER_SERVICE_PROTOCOL://$SERVICE_HOST:$CINDER_SERVICE_PORT/v3
657 OS_USER_ID=$OS_USERNAME OS_PROJECT_ID=$OS_PROJECT_NAME cinder --os-auth-type noauth --os-endpoint=$cinder_url type-create $type_name
658 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"
659 fi
660}
661
Dean Troyer09718332014-07-03 10:46:57 -0500662# create_volume_types() - Create Cinder's configured volume types
663function create_volume_types {
664 # Create volume types
665 if is_service_enabled c-api && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Jamie Lennox494f7cd2015-05-29 08:33:03 +0000666 local be be_name
Dean Troyer09718332014-07-03 10:46:57 -0500667 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500668 be_name=${be##*:}
Rajat Dhasmana1898a682023-03-14 05:35:33 +0000669 create_one_type $be_name "volume_backend_name" $be_name
Dean Troyer09718332014-07-03 10:46:57 -0500670 done
Dan Smithb4bba2f2021-02-04 23:24:17 +0000671
Rajat Dhasmana1898a682023-03-14 05:35:33 +0000672 if [[ $ENABLE_VOLUME_MULTIATTACH == "True" ]]; then
673 create_one_type $VOLUME_TYPE_MULTIATTACH $VOLUME_TYPE_MULTIATTACH "<is> True"
674 fi
675
Dan Smithb4bba2f2021-02-04 23:24:17 +0000676 # Increase quota for the service project if glance is using cinder,
677 # since it's likely to occasionally go above the default 10 in parallel
678 # test execution.
679 if [[ "$USE_CINDER_FOR_GLANCE" == "True" ]]; then
680 openstack --os-region-name="$REGION_NAME" \
681 quota set --volumes 50 "$SERVICE_PROJECT_NAME"
682 fi
Dean Troyer09718332014-07-03 10:46:57 -0500683 fi
684}
685
686# Compatibility for Grenade
687
688function create_cinder_volume_group {
689 # During a transition period Grenade needs to have this function defined
690 # It is effectively a no-op in the Grenade 'target' use case
691 :
692}
693
Patrick Eastdddb2c72016-05-03 17:34:00 -0700694function configure_cinder_internal_tenant {
695 # Re-use the Cinder service account for simplicity.
696 iniset $CINDER_CONF DEFAULT cinder_internal_tenant_project_id $(get_or_create_project $SERVICE_PROJECT_NAME)
697 iniset $CINDER_CONF DEFAULT cinder_internal_tenant_user_id $(get_or_create_user "cinder")
698}
699
700function configure_cinder_image_volume_cache {
701 # Expect CINDER_CACHE_ENABLED_FOR_BACKENDS to be a list of backends
702 # similar to CINDER_ENABLED_BACKENDS with NAME:TYPE where NAME will
703 # be the backend specific configuration stanza in cinder.conf.
704 for be in ${CINDER_CACHE_ENABLED_FOR_BACKENDS//,/ }; do
705 local be_name=${be##*:}
706
707 iniset $CINDER_CONF $be_name image_volume_cache_enabled $CINDER_IMG_CACHE_ENABLED
708
709 if [[ -n $CINDER_IMG_CACHE_SIZE_GB ]]; then
710 iniset $CINDER_CONF $be_name image_volume_cache_max_size_gb $CINDER_IMG_CACHE_SIZE_GB
711 fi
712
713 if [[ -n $CINDER_IMG_CACHE_SIZE_COUNT ]]; then
714 iniset $CINDER_CONF $be_name image_volume_cache_max_count $CINDER_IMG_CACHE_SIZE_COUNT
715 fi
716 done
717}
718
Rajat Dhasmanad6e3d062024-02-22 00:11:15 +0530719function configure_cinder_volume_upload {
720 # Expect UPLOAD_VOLUME_OPTIMIZED_FOR_BACKENDS to be a list of backends
721 # similar to CINDER_ENABLED_BACKENDS with NAME:TYPE where NAME will
722 # be the backend specific configuration stanza in cinder.conf.
723 local be be_name
724 for be in ${CINDER_UPLOAD_OPTIMIZED_BACKENDS//,/ }; do
725 be_name=${be##*:}
726
727 iniset $CINDER_CONF $be_name image_upload_use_cinder_backend $CINDER_UPLOAD_OPTIMIZED
728 iniset $CINDER_CONF $be_name image_upload_use_internal_tenant $CINDER_UPLOAD_INTERNAL_TENANT
729 done
730}
Dean Troyercc6b4432013-04-08 15:38:03 -0500731
Rajat Dhasmana80c16052024-02-28 13:08:12 +0530732function init_cinder_service_user_conf {
733 configure_keystone_authtoken_middleware $CINDER_CONF cinder service_user
734 iniset $CINDER_CONF service_user send_service_user_token True
735 iniset $CINDER_CONF service_user auth_strategy keystone
736}
737
Dean Troyer7903b792012-09-13 17:16:12 -0500738# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +1100739$_XTRACE_CINDER
Sean Dague584d90e2013-03-29 14:34:53 -0400740
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100741# Tell emacs to use shell-script-mode
742## Local variables:
743## mode: shell-script
744## End: