blob: 0d157dd78e78a7eba9f33eb861fbab2dddb40020 [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
23XTRACE=$(set +o | grep xtrace)
24set +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
Sean Dague5cb19062014-11-01 01:37:45 +010042
Dean Troyer67787e62012-05-02 11:48:15 -050043CINDER_DIR=$DEST/cinder
Dean Troyer50ac7922012-09-13 14:02:01 -050044CINDER_STATE_PATH=${CINDER_STATE_PATH:=$DATA_DIR/cinder}
Dean Troyer671c16e2012-12-13 16:22:38 -060045CINDER_AUTH_CACHE_DIR=${CINDER_AUTH_CACHE_DIR:-/var/cache/cinder}
46
Dean Troyer50ac7922012-09-13 14:02:01 -050047CINDER_CONF_DIR=/etc/cinder
48CINDER_CONF=$CINDER_CONF_DIR/cinder.conf
Dean Troyer671c16e2012-12-13 16:22:38 -060049CINDER_API_PASTE_INI=$CINDER_CONF_DIR/api-paste.ini
Dean Troyer50ac7922012-09-13 14:02:01 -050050
Dean Troyer560346b2012-12-13 17:05:24 -060051# Public facing bits
Rob Crittenden18d47782014-03-19 17:47:42 -040052if is_ssl_enabled_service "cinder" || is_service_enabled tls-proxy; then
53 CINDER_SERVICE_PROTOCOL="https"
54fi
Dean Troyer560346b2012-12-13 17:05:24 -060055CINDER_SERVICE_HOST=${CINDER_SERVICE_HOST:-$SERVICE_HOST}
56CINDER_SERVICE_PORT=${CINDER_SERVICE_PORT:-8776}
57CINDER_SERVICE_PORT_INT=${CINDER_SERVICE_PORT_INT:-18776}
58CINDER_SERVICE_PROTOCOL=${CINDER_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
59
Dean Troyer50ac7922012-09-13 14:02:01 -050060# Support entry points installation of console scripts
61if [[ -d $CINDER_DIR/bin ]]; then
Monty Taylor9fbeedd2012-08-17 12:52:27 -040062 CINDER_BIN_DIR=$CINDER_DIR/bin
63else
Jakub Ruzicka4196d552013-01-30 15:35:54 +010064 CINDER_BIN_DIR=$(get_python_exec_prefix)
Monty Taylor9fbeedd2012-08-17 12:52:27 -040065fi
Dean Troyer67787e62012-05-02 11:48:15 -050066
Dean Troyer09718332014-07-03 10:46:57 -050067
Dean Troyer09718332014-07-03 10:46:57 -050068# Default backends
69# The backend format is type:name where type is one of the supported backend
70# types (lvm, nfs, etc) and name is the identifier used in the Cinder
71# configuration and for the volume type name. Multiple backends are
72# comma-separated.
Dean Troyer311f4872014-12-18 16:31:34 -060073# The old ``CINDER_MULTI_LVM_BACKEND=True`` setting had a default of:
74# CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-lvm:lvmdriver-1,lvm:lvmdriver-2}
75CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-lvm:lvmdriver-1}
Dean Troyer09718332014-07-03 10:46:57 -050076
77
Dean Troyerb7490da2013-03-18 16:07:56 -050078# Should cinder perform secure deletion of volumes?
79# Defaults to true, can be set to False to avoid this bug when testing:
80# https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1023755
Sean Dague53753292014-12-04 19:38:15 -050081CINDER_SECURE_DELETE=$(trueorfalse True CINDER_SECURE_DELETE)
Dean Troyerb7490da2013-03-18 16:07:56 -050082
Sean Daguef35ff722013-05-16 16:31:12 -040083# Cinder reports allocations back to the scheduler on periodic intervals
84# it turns out we can get an "out of space" issue when we run tests too
85# quickly just because cinder didn't realize we'd freed up resources.
86# Make this configurable so that devstack-gate/tempest can set it to
87# less than the 60 second default
88# https://bugs.launchpad.net/cinder/+bug/1180976
89CINDER_PERIODIC_INTERVAL=${CINDER_PERIODIC_INTERVAL:-60}
90
Dean Troyer4237f592014-01-29 16:22:11 -060091# Tell Tempest this project is present
92TEMPEST_SERVICES+=,cinder
93
Dean Troyercc6b4432013-04-08 15:38:03 -050094
Dean Troyer09718332014-07-03 10:46:57 -050095# Source the enabled backends
96if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
97 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -050098 be_type=${be%%:*}
99 be_name=${be##*:}
100 if [[ -r $CINDER_BACKENDS/${be_type} ]]; then
101 source $CINDER_BACKENDS/${be_type}
Dean Troyer09718332014-07-03 10:46:57 -0500102 fi
103 done
104fi
105
git-harryafc14232015-01-08 17:37:40 +0000106# Change the default nova_catalog_info and nova_catalog_admin_info values in
107# cinder so that the service name cinder is searching for matches that set for
108# nova in keystone.
109CINDER_NOVA_CATALOG_INFO=${CINDER_NOVA_CATALOG_INFO:-compute:nova:publicURL}
110CINDER_NOVA_CATALOG_ADMIN_INFO=${CINDER_NOVA_CATALOG_ADMIN_INFO:-compute:nova:adminURL}
111
Dean Troyer09718332014-07-03 10:46:57 -0500112
Dean Troyercc6b4432013-04-08 15:38:03 -0500113# Functions
114# ---------
Dean Troyere4fa7212014-01-15 15:04:49 -0600115
116# Test if any Cinder services are enabled
117# is_cinder_enabled
118function is_cinder_enabled {
119 [[ ,${ENABLED_SERVICES} =~ ,"c-" ]] && return 0
120 return 1
121}
122
Dean Troyer67787e62012-05-02 11:48:15 -0500123# cleanup_cinder() - Remove residual data files, anything left over from previous
124# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100125function cleanup_cinder {
Sean Dague252f2f52012-12-20 16:41:57 -0500126 # ensure the volume group is cleared up because fails might
127 # leave dead volumes in the group
Dean Troyere8a35ac2014-07-25 12:37:41 -0500128 local targets=$(sudo tgtadm --op show --mode target)
Sean Dague252f2f52012-12-20 16:41:57 -0500129 if [ $? -ne 0 ]; then
130 # If tgt driver isn't running this won't work obviously
131 # So check the response and restart if need be
132 echo "tgtd seems to be in a bad state, restarting..."
133 if is_ubuntu; then
134 restart_service tgt
135 else
136 restart_service tgtd
137 fi
Dean Troyere8a35ac2014-07-25 12:37:41 -0500138 targets=$(sudo tgtadm --op show --mode target)
Sean Dague252f2f52012-12-20 16:41:57 -0500139 fi
140
Dean Troyere8a35ac2014-07-25 12:37:41 -0500141 if [[ -n "$targets" ]]; then
142 local iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
Sean Dague252f2f52012-12-20 16:41:57 -0500143 for i in "${iqn_list[@]}"; do
144 echo removing iSCSI target: $i
145 sudo tgt-admin --delete $i
146 done
147 fi
148
Sean Dague252f2f52012-12-20 16:41:57 -0500149 if is_ubuntu; then
150 stop_service tgt
151 else
152 stop_service tgtd
153 fi
154
Dean Troyer09718332014-07-03 10:46:57 -0500155 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500156 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500157 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500158 be_type=${be%%:*}
159 be_name=${be##*:}
160 if type cleanup_cinder_backend_${be_type} >/dev/null 2>&1; then
161 cleanup_cinder_backend_${be_type} ${be_name}
Dean Troyer09718332014-07-03 10:46:57 -0500162 fi
163 done
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100164 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500165}
166
Thierry Carrez63e17842014-01-10 14:23:03 +0100167# configure_cinder_rootwrap() - configure Cinder's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +1100168function configure_cinder_rootwrap {
John Griffith4e823ff2012-07-20 13:18:17 -0600169 # Set the paths of certain binaries
Dean Troyere8a35ac2014-07-25 12:37:41 -0500170 local cinder_rootwrap=$(get_rootwrap_location cinder)
John Griffith4e823ff2012-07-20 13:18:17 -0600171
Thierry Carrezd5d49742014-02-06 16:00:08 +0100172 # Deploy new rootwrap filters files (owned by root).
173 # Wipe any existing rootwrap.d files first
174 if [[ -d $CINDER_CONF_DIR/rootwrap.d ]]; then
175 sudo rm -rf $CINDER_CONF_DIR/rootwrap.d
John Griffith4e823ff2012-07-20 13:18:17 -0600176 fi
Thierry Carrezd5d49742014-02-06 16:00:08 +0100177 # Deploy filters to /etc/cinder/rootwrap.d
178 sudo mkdir -m 755 $CINDER_CONF_DIR/rootwrap.d
179 sudo cp $CINDER_DIR/etc/cinder/rootwrap.d/*.filters $CINDER_CONF_DIR/rootwrap.d
180 sudo chown -R root:root $CINDER_CONF_DIR/rootwrap.d
181 sudo chmod 644 $CINDER_CONF_DIR/rootwrap.d/*
182 # Set up rootwrap.conf, pointing to /etc/cinder/rootwrap.d
183 sudo cp $CINDER_DIR/etc/cinder/rootwrap.conf $CINDER_CONF_DIR/
184 sudo sed -e "s:^filters_path=.*$:filters_path=$CINDER_CONF_DIR/rootwrap.d:" -i $CINDER_CONF_DIR/rootwrap.conf
185 sudo chown root:root $CINDER_CONF_DIR/rootwrap.conf
186 sudo chmod 0644 $CINDER_CONF_DIR/rootwrap.conf
187 # Specify rootwrap.conf as first parameter to rootwrap
Dean Troyere8a35ac2014-07-25 12:37:41 -0500188 ROOTWRAP_CSUDOER_CMD="$cinder_rootwrap $CINDER_CONF_DIR/rootwrap.conf *"
John Griffith4e823ff2012-07-20 13:18:17 -0600189
Thierry Carrezd5d49742014-02-06 16:00:08 +0100190 # Set up the rootwrap sudoers for cinder
Dean Troyere8a35ac2014-07-25 12:37:41 -0500191 local tempfile=`mktemp`
192 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_CSUDOER_CMD" >$tempfile
193 chmod 0440 $tempfile
194 sudo chown root:root $tempfile
195 sudo mv $tempfile /etc/sudoers.d/cinder-rootwrap
Thierry Carrez63e17842014-01-10 14:23:03 +0100196}
197
198# configure_cinder() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100199function configure_cinder {
Thierry Carrez63e17842014-01-10 14:23:03 +0100200 if [[ ! -d $CINDER_CONF_DIR ]]; then
201 sudo mkdir -p $CINDER_CONF_DIR
202 fi
203 sudo chown $STACK_USER $CINDER_CONF_DIR
204
205 cp -p $CINDER_DIR/etc/cinder/policy.json $CINDER_CONF_DIR
206
Yalei Wangcecbd1f2015-01-05 17:05:47 +0800207 rm -f $CINDER_CONF
208
Thierry Carrez63e17842014-01-10 14:23:03 +0100209 configure_cinder_rootwrap
John Griffith4e823ff2012-07-20 13:18:17 -0600210
Dean Troyer67787e62012-05-02 11:48:15 -0500211 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
Dan Prince82dea7c2013-10-16 18:57:15 -0400212
213 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_host
214 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_port
215 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_protocol
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000216 inicomment $CINDER_API_PASTE_INI filter:authtoken cafile
Dan Prince82dea7c2013-10-16 18:57:15 -0400217 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name
218 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_user
219 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_password
220 inicomment $CINDER_API_PASTE_INI filter:authtoken signing_dir
Dean Troyerbc071bc2012-10-01 14:06:44 -0500221
Brant Knudson05952372014-09-19 17:22:22 -0500222 configure_auth_token_middleware $CINDER_CONF cinder $CINDER_AUTH_CACHE_DIR
Dan Prince82dea7c2013-10-16 18:57:15 -0400223
git-harryafc14232015-01-08 17:37:40 +0000224 iniset $CINDER_CONF DEFAULT nova_catalog_info $CINDER_NOVA_CATALOG_INFO
225 iniset $CINDER_CONF DEFAULT nova_catalog_admin_info $CINDER_NOVA_CATALOG_ADMIN_INFO
226
Dean Troyer67787e62012-05-02 11:48:15 -0500227 iniset $CINDER_CONF DEFAULT auth_strategy keystone
Ben Nemec03997942013-08-10 09:56:16 -0500228 iniset $CINDER_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Dean Troyer67787e62012-05-02 11:48:15 -0500229 iniset $CINDER_CONF DEFAULT verbose True
Dean Troyer09718332014-07-03 10:46:57 -0500230
Nikolay Sobolevskiy08df29b2013-08-30 21:59:15 +0400231 iniset $CINDER_CONF DEFAULT my_ip "$CINDER_SERVICE_HOST"
Dean Troyer67787e62012-05-02 11:48:15 -0500232 iniset $CINDER_CONF DEFAULT iscsi_helper tgtadm
Attila Fazekas7e79d912013-03-03 12:23:04 +0100233 iniset $CINDER_CONF DEFAULT sql_connection `database_connection_url cinder`
Dean Troyer67787e62012-05-02 11:48:15 -0500234 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
Joe Gordona58382a2013-02-20 12:45:02 -0800235 iniset $CINDER_CONF DEFAULT rootwrap_config "$CINDER_CONF_DIR/rootwrap.conf"
Dan Prince9f22f072013-01-28 09:53:38 -0500236 iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.contrib.standard_extensions
Dean Troyer50ac7922012-09-13 14:02:01 -0500237 iniset $CINDER_CONF DEFAULT state_path $CINDER_STATE_PATH
Sergey Kraynev84783c72013-10-10 09:08:48 -0400238 iniset $CINDER_CONF DEFAULT lock_path $CINDER_STATE_PATH
Sean Daguef35ff722013-05-16 16:31:12 -0400239 iniset $CINDER_CONF DEFAULT periodic_interval $CINDER_PERIODIC_INTERVAL
Mike Perezf64f43b2014-06-25 08:51:31 -0700240 # NOTE(thingee): Cinder V1 API is deprecated and defaults to off as of
241 # Juno. Keep it enabled so we can continue testing while it's still
242 # supported.
243 iniset $CINDER_CONF DEFAULT enable_v1_api true
John Griffith4e823ff2012-07-20 13:18:17 -0600244
Dean Troyer09718332014-07-03 10:46:57 -0500245 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500246 local enabled_backends=""
247 local default_name=""
248 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500249 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500250 be_type=${be%%:*}
251 be_name=${be##*:}
252 if type configure_cinder_backend_${be_type} >/dev/null 2>&1; then
253 configure_cinder_backend_${be_type} ${be_name}
Dean Troyer09718332014-07-03 10:46:57 -0500254 fi
Dean Troyera25922b2014-08-28 09:29:47 -0500255 if [[ -z "$default_name" ]]; then
256 default_name=$be_name
Dean Troyer09718332014-07-03 10:46:57 -0500257 fi
Dean Troyere8a35ac2014-07-25 12:37:41 -0500258 enabled_backends+=$be_name,
Dean Troyer09718332014-07-03 10:46:57 -0500259 done
260 iniset $CINDER_CONF DEFAULT enabled_backends ${enabled_backends%,*}
Matt Riedemann6a4aa782014-07-25 13:35:53 -0700261 if [[ -n "$default_name" ]]; then
262 iniset $CINDER_CONF DEFAULT default_volume_type ${default_name}
Dean Troyer09718332014-07-03 10:46:57 -0500263 fi
264 fi
265
Attila Fazekas29834742014-03-09 18:36:42 +0100266 if is_service_enabled swift; then
Rob Crittenden7d0a0f72014-11-17 00:03:47 -0500267 iniset $CINDER_CONF DEFAULT backup_swift_url "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:8080/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
Mark McLoughlindc0938e2014-06-17 06:37:43 +0100271 iniset $CINDER_CONF DEFAULT notification_driver "messaging"
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
275 # Set the service port for a proxy to take the original
276 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
277 fi
278
Dean Troyer4d3049e2012-11-06 20:38:14 -0600279 if [ "$SYSLOG" != "False" ]; then
280 iniset $CINDER_CONF DEFAULT use_syslog True
281 fi
282
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900283 iniset_rpc_backend cinder $CINDER_CONF DEFAULT
Gary Kottonf71bf192012-08-06 11:15:36 -0400284
James E. Blair213c4162012-11-06 09:38:36 +0100285 if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then
286 iniset $CINDER_CONF DEFAULT secure_delete False
Pádraig Bradyeac93702013-01-02 16:02:54 +0000287 iniset $CINDER_CONF DEFAULT volume_clear none
James E. Blair213c4162012-11-06 09:38:36 +0100288 fi
289
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700290 # Format logging
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000291 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700292 setup_colorized_logging $CINDER_CONF DEFAULT "project_id" "user_id"
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000293 fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000294
john-griffithd0860cc2014-01-23 11:31:10 -0700295 if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
296 configure_cinder_driver
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000297 fi
Ian Wienand0db17132013-06-26 22:31:48 +1000298
Dean Troyer05bd7b82014-09-16 17:25:33 -0500299 iniset $CINDER_CONF DEFAULT osapi_volume_workers "$API_WORKERS"
Rob Crittenden18d47782014-03-19 17:47:42 -0400300
301 iniset $CINDER_CONF DEFAULT glance_api_servers "${GLANCE_SERVICE_PROTOCOL}://${GLANCE_HOSTPORT}"
302 if is_ssl_enabled_service glance || is_service_enabled tls-proxy; then
303 iniset $CINDER_CONF DEFAULT glance_protocol https
Rob Crittenden4b109292014-10-21 18:17:48 -0400304 iniset $CINDER_CONF DEFAULT glance_ca_certificates_file $SSL_BUNDLE_FILE
Rob Crittenden18d47782014-03-19 17:47:42 -0400305 fi
306
307 # Register SSL certificates if provided
308 if is_ssl_enabled_service cinder; then
309 ensure_certificates CINDER
310
311 iniset $CINDER_CONF DEFAULT ssl_cert_file "$CINDER_SSL_CERT"
312 iniset $CINDER_CONF DEFAULT ssl_key_file "$CINDER_SSL_KEY"
313 fi
314
Dean Troyer67787e62012-05-02 11:48:15 -0500315}
316
Dean Troyer671c16e2012-12-13 16:22:38 -0600317# create_cinder_accounts() - Set up common required cinder accounts
318
319# Tenant User Roles
320# ------------------------------------------------------------------
321# service cinder admin # if enabled
322
323# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100324function create_cinder_accounts {
Dean Troyer671c16e2012-12-13 16:22:38 -0600325
Dean Troyer671c16e2012-12-13 16:22:38 -0600326 # Cinder
327 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100328
Jamie Lennoxe8bc2b82015-02-10 20:38:56 +1100329 create_service_user "cinder"
Bartosz Górski0abde392014-02-28 14:15:19 +0100330
Dean Troyer671c16e2012-12-13 16:22:38 -0600331 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100332
Dean Troyere8a35ac2014-07-25 12:37:41 -0500333 local cinder_service=$(get_or_create_service "cinder" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100334 "volume" "Cinder Volume Service")
Dean Troyere8a35ac2014-07-25 12:37:41 -0500335 get_or_create_endpoint $cinder_service "$REGION_NAME" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100336 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
337 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
338 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s"
339
Dean Troyere8a35ac2014-07-25 12:37:41 -0500340 local cinder_v2_service=$(get_or_create_service "cinderv2" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100341 "volumev2" "Cinder Volume Service V2")
Dean Troyere8a35ac2014-07-25 12:37:41 -0500342 get_or_create_endpoint $cinder_v2_service "$REGION_NAME" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100343 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s" \
344 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s" \
345 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s"
Dean Troyer671c16e2012-12-13 16:22:38 -0600346 fi
347 fi
348}
349
Dean Troyerf03bafe2013-02-12 10:58:28 -0600350# create_cinder_cache_dir() - Part of the init_cinder() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100351function create_cinder_cache_dir {
Dean Troyerf03bafe2013-02-12 10:58:28 -0600352 # Create cache dir
353 sudo mkdir -p $CINDER_AUTH_CACHE_DIR
354 sudo chown $STACK_USER $CINDER_AUTH_CACHE_DIR
355 rm -f $CINDER_AUTH_CACHE_DIR/*
356}
357
Dean Troyer67787e62012-05-02 11:48:15 -0500358# init_cinder() - Initialize database and volume group
Dean Troyere8a35ac2014-07-25 12:37:41 -0500359# Uses global ``NOVA_ENABLED_APIS``
Ian Wienandaee18c72014-02-21 15:35:08 +1100360function init_cinder {
Dean Troyer67787e62012-05-02 11:48:15 -0500361 # Force nova volumes off
362 NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
363
Terry Wilson428af5a2012-11-01 16:12:39 -0400364 if is_service_enabled $DATABASE_BACKENDS; then
Dean Troyerf03bafe2013-02-12 10:58:28 -0600365 # (Re)create cinder database
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200366 recreate_database cinder
Dean Troyer67787e62012-05-02 11:48:15 -0500367
Dean Troyerf03bafe2013-02-12 10:58:28 -0600368 # Migrate cinder database
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400369 $CINDER_BIN_DIR/cinder-manage db sync
Dean Troyer67787e62012-05-02 11:48:15 -0500370 fi
371
Dean Troyer09718332014-07-03 10:46:57 -0500372 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500373 local be be_name be_type
John Griffith0b9e76f2015-01-21 13:46:59 -0700374 local has_lvm=0
Dean Troyer09718332014-07-03 10:46:57 -0500375 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500376 be_type=${be%%:*}
377 be_name=${be##*:}
John Griffith0b9e76f2015-01-21 13:46:59 -0700378
379 if [[ $be_type == 'lvm' ]]; then
380 has_lvm=1
381 fi
382
Dean Troyere8a35ac2014-07-25 12:37:41 -0500383 if type init_cinder_backend_${be_type} >/dev/null 2>&1; then
Maru Newbyc070a3d2015-01-27 17:44:44 +0000384 # Always init the default volume group for lvm.
385 if [[ "$be_type" == "lvm" ]]; then
386 init_default_lvm_volume_group
387 fi
Dean Troyere8a35ac2014-07-25 12:37:41 -0500388 init_cinder_backend_${be_type} ${be_name}
Vincent Untz0230aa82012-06-14 08:51:01 +0200389 fi
Dean Troyer09718332014-07-03 10:46:57 -0500390 done
Dean Troyer67787e62012-05-02 11:48:15 -0500391 fi
Dean Troyerbc071bc2012-10-01 14:06:44 -0500392
John Griffith0b9e76f2015-01-21 13:46:59 -0700393 # Keep it simple, set a marker if there's an LVM backend
394 # use the created VG's to setup lvm filters
395 if [[ $has_lvm == 1 ]]; then
396 # Order matters here, not only obviously to make
397 # sure the VG's are created, but also some distros
398 # do some customizations to lvm.conf on init, we
399 # want to make sure we copy those over
400 sudo cp /etc/lvm/lvm.conf /etc/cinder/lvm.conf
401 configure_cinder_backend_conf_lvm
402 fi
403
Dean Troyer09718332014-07-03 10:46:57 -0500404 mkdir -p $CINDER_STATE_PATH/volumes
Dean Troyerf03bafe2013-02-12 10:58:28 -0600405 create_cinder_cache_dir
Dean Troyer67787e62012-05-02 11:48:15 -0500406}
407
408# install_cinder() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100409function install_cinder {
Dean Troyer67787e62012-05-02 11:48:15 -0500410 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400411 setup_develop $CINDER_DIR
Dean Troyer253a1a32013-04-01 18:23:22 -0500412}
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400413
Dean Troyer253a1a32013-04-01 18:23:22 -0500414# install_cinderclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100415function install_cinderclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500416 if use_library_from_git "python-cinderclient"; then
417 git_clone_by_name "python-cinderclient"
418 setup_dev_lib "python-cinderclient"
419 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 +0100420 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500421}
422
Steve Baker18225d92013-04-14 12:48:41 -0700423# apply config.d approach for cinder volumes directory
Ian Wienandaee18c72014-02-21 15:35:08 +1100424function _configure_tgt_for_config_d {
Steve Baker18225d92013-04-14 12:48:41 -0700425 if [[ ! -d /etc/tgt/stack.d/ ]]; then
426 sudo ln -sf $CINDER_STATE_PATH/volumes /etc/tgt/stack.d
427 echo "include /etc/tgt/stack.d/*" | sudo tee -a /etc/tgt/targets.conf
Mate Lakata39caac2012-09-03 15:45:53 +0100428 fi
429}
430
Dean Troyer67787e62012-05-02 11:48:15 -0500431# start_cinder() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100432function start_cinder {
Rob Crittenden18d47782014-03-19 17:47:42 -0400433 local service_port=$CINDER_SERVICE_PORT
434 local service_protocol=$CINDER_SERVICE_PROTOCOL
435 if is_service_enabled tls-proxy; then
436 service_port=$CINDER_SERVICE_PORT_INT
437 service_protocol="http"
438 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500439 if is_service_enabled c-vol; then
Steve Baker18225d92013-04-14 12:48:41 -0700440 # Delete any old stack.conf
441 sudo rm -f /etc/tgt/conf.d/stack.conf
Attila Fazekasb79574b2012-12-01 10:42:46 +0100442 _configure_tgt_for_config_d
Vincent Untzc18b9652012-12-04 12:36:34 +0100443 if is_ubuntu; then
Sean Dagued5b52ca2014-03-04 09:23:07 -0500444 sudo service tgt restart
Attila Fazekasec89fa02015-01-29 11:16:00 +0100445 elif is_fedora || is_suse; then
Vincent Untz00011c02012-12-06 09:56:32 +0100446 restart_service tgtd
447 else
448 # note for other distros: unstack.sh also uses the tgt/tgtd service
449 # name, and would need to be adjusted too
450 exit_distro_not_supported "restarting tgt"
Dean Troyer67787e62012-05-02 11:48:15 -0500451 fi
Giulio Fidente384454d2013-09-27 13:17:34 +0200452 # NOTE(gfidente): ensure tgtd is running in debug mode
453 sudo tgtadm --mode system --op update --name debug --value on
Dean Troyer67787e62012-05-02 11:48:15 -0500454 fi
455
Dean Troyer3159a822014-08-27 14:13:58 -0500456 run_process c-api "$CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
Dean Troyer09718332014-07-03 10:46:57 -0500457 echo "Waiting for Cinder API to start..."
Rob Crittenden18d47782014-03-19 17:47:42 -0400458 if ! wait_for_service $SERVICE_TIMEOUT $service_protocol://$CINDER_SERVICE_HOST:$service_port; then
Dean Troyer09718332014-07-03 10:46:57 -0500459 die $LINENO "c-api did not start"
460 fi
461
Dean Troyer3159a822014-08-27 14:13:58 -0500462 run_process c-sch "$CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
463 run_process c-bak "$CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF"
464 run_process c-vol "$CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
John Griffithe6d4fe52013-07-15 17:35:54 -0600465
466 # NOTE(jdg): For cinder, startup order matters. To ensure that repor_capabilities is received
467 # by the scheduler start the cinder-volume service last (or restart it) after the scheduler
468 # has started. This is a quick fix for lp bug/1189595
Dean Troyer560346b2012-12-13 17:05:24 -0600469
470 # Start proxies if enabled
471 if is_service_enabled c-api && is_service_enabled tls-proxy; then
472 start_tls_proxy '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT &
473 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500474}
475
Dean Troyer699a29f2012-09-10 14:10:27 -0500476# stop_cinder() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100477function stop_cinder {
Dean Troyer699a29f2012-09-10 14:10:27 -0500478 # Kill the cinder screen windows
Dean Troyere8a35ac2014-07-25 12:37:41 -0500479 local serv
Stephen Mulcahy67068ef2013-02-21 11:20:58 +0000480 for serv in c-api c-bak c-sch c-vol; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100481 stop_process $serv
Dean Troyer699a29f2012-09-10 14:10:27 -0500482 done
Dean Troyer67787e62012-05-02 11:48:15 -0500483
484 if is_service_enabled c-vol; then
Vincent Untz90dd96d2012-12-13 08:59:57 +0100485 if is_ubuntu; then
486 stop_service tgt
487 else
488 stop_service tgtd
489 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500490 fi
491}
Dean Troyer7903b792012-09-13 17:16:12 -0500492
Dean Troyer09718332014-07-03 10:46:57 -0500493# create_volume_types() - Create Cinder's configured volume types
494function create_volume_types {
495 # Create volume types
496 if is_service_enabled c-api && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500497 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500498 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500499 be_type=${be%%:*}
500 be_name=${be##*:}
501 # openstack volume type create --property volume_backend_name="${be_type}" ${be_name}
502 cinder type-create ${be_name} && \
503 cinder type-key ${be_name} set volume_backend_name="${be_name}"
Dean Troyer09718332014-07-03 10:46:57 -0500504 done
505 fi
506}
507
508# Compatibility for Grenade
509
510function create_cinder_volume_group {
511 # During a transition period Grenade needs to have this function defined
512 # It is effectively a no-op in the Grenade 'target' use case
513 :
514}
515
Dean Troyercc6b4432013-04-08 15:38:03 -0500516
Dean Troyer7903b792012-09-13 17:16:12 -0500517# Restore xtrace
518$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400519
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100520# Tell emacs to use shell-script-mode
521## Local variables:
522## mode: shell-script
523## End: