blob: 56878642e35adac6a381ac894d9ba887225ed561 [file] [log] [blame]
Dean Troyer67787e62012-05-02 11:48:15 -05001# lib/cinder
Dean Troyer6d04fd72012-12-21 11:03:37 -06002# Install and start **Cinder** volume service
Dean Troyer67787e62012-05-02 11:48:15 -05003
4# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01005#
Dean Troyer67787e62012-05-02 11:48:15 -05006# - functions
Attila Fazekas91b8d132013-01-06 22:40:09 +01007# - DEST, DATA_DIR, STACK_USER must be defined
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01008# - SERVICE_{TENANT_NAME|PASSWORD} must be defined
9# - ``KEYSTONE_TOKEN_FORMAT`` must be defined
Dean Troyer67787e62012-05-02 11:48:15 -050010
11# stack.sh
12# ---------
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010013# - install_cinder
14# - configure_cinder
15# - init_cinder
16# - start_cinder
17# - stop_cinder
18# - cleanup_cinder
Dean Troyer67787e62012-05-02 11:48:15 -050019
Dean Troyer7903b792012-09-13 17:16:12 -050020# Save trace setting
21XTRACE=$(set +o | grep xtrace)
22set +o xtrace
Dean Troyer67787e62012-05-02 11:48:15 -050023
24
25# Defaults
26# --------
27
Mate Lakatb2fdafe2012-11-20 15:52:21 +000028# set up default driver
29CINDER_DRIVER=${CINDER_DRIVER:-default}
john-griffithd0860cc2014-01-23 11:31:10 -070030CINDER_PLUGINS=$TOP_DIR/lib/cinder_plugins
Dean Troyer09718332014-07-03 10:46:57 -050031CINDER_BACKENDS=$TOP_DIR/lib/cinder_backends
john-griffithd0860cc2014-01-23 11:31:10 -070032
33# grab plugin config if specified via cinder_driver
34if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
35 source $CINDER_PLUGINS/$CINDER_DRIVER
36fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +000037
Dean Troyer67787e62012-05-02 11:48:15 -050038# set up default directories
Sean Dague5cb19062014-11-01 01:37:45 +010039GITDIR["cinderclient"]=$DEST/python-cinderclient
40
Dean Troyer67787e62012-05-02 11:48:15 -050041CINDER_DIR=$DEST/cinder
Dean Troyer50ac7922012-09-13 14:02:01 -050042CINDER_STATE_PATH=${CINDER_STATE_PATH:=$DATA_DIR/cinder}
Dean Troyer671c16e2012-12-13 16:22:38 -060043CINDER_AUTH_CACHE_DIR=${CINDER_AUTH_CACHE_DIR:-/var/cache/cinder}
44
Dean Troyer50ac7922012-09-13 14:02:01 -050045CINDER_CONF_DIR=/etc/cinder
46CINDER_CONF=$CINDER_CONF_DIR/cinder.conf
Dean Troyer671c16e2012-12-13 16:22:38 -060047CINDER_API_PASTE_INI=$CINDER_CONF_DIR/api-paste.ini
Dean Troyer50ac7922012-09-13 14:02:01 -050048
Dean Troyer560346b2012-12-13 17:05:24 -060049# Public facing bits
Rob Crittenden18d47782014-03-19 17:47:42 -040050if is_ssl_enabled_service "cinder" || is_service_enabled tls-proxy; then
51 CINDER_SERVICE_PROTOCOL="https"
52fi
Dean Troyer560346b2012-12-13 17:05:24 -060053CINDER_SERVICE_HOST=${CINDER_SERVICE_HOST:-$SERVICE_HOST}
54CINDER_SERVICE_PORT=${CINDER_SERVICE_PORT:-8776}
55CINDER_SERVICE_PORT_INT=${CINDER_SERVICE_PORT_INT:-18776}
56CINDER_SERVICE_PROTOCOL=${CINDER_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
57
Dean Troyer50ac7922012-09-13 14:02:01 -050058# Support entry points installation of console scripts
59if [[ -d $CINDER_DIR/bin ]]; then
Monty Taylor9fbeedd2012-08-17 12:52:27 -040060 CINDER_BIN_DIR=$CINDER_DIR/bin
61else
Jakub Ruzicka4196d552013-01-30 15:35:54 +010062 CINDER_BIN_DIR=$(get_python_exec_prefix)
Monty Taylor9fbeedd2012-08-17 12:52:27 -040063fi
Dean Troyer67787e62012-05-02 11:48:15 -050064
Dean Troyer09718332014-07-03 10:46:57 -050065
66# Maintain this here for backward-compatibility with the old configuration
67# DEPRECATED: Use CINDER_ENABLED_BACKENDS instead
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +010068# Support for multi lvm backend configuration (default is no support)
69CINDER_MULTI_LVM_BACKEND=$(trueorfalse False $CINDER_MULTI_LVM_BACKEND)
70
Dean Troyer09718332014-07-03 10:46:57 -050071# Default backends
72# The backend format is type:name where type is one of the supported backend
73# types (lvm, nfs, etc) and name is the identifier used in the Cinder
74# configuration and for the volume type name. Multiple backends are
75# comma-separated.
76if [[ $CINDER_MULTI_LVM_BACKEND == "False" ]]; then
77 CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-lvm:lvmdriver-1}
78else
79 CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-lvm:lvmdriver-1,lvm:lvmdriver-2}
80fi
81
82
Dean Troyerb7490da2013-03-18 16:07:56 -050083# Should cinder perform secure deletion of volumes?
84# Defaults to true, can be set to False to avoid this bug when testing:
85# https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1023755
86CINDER_SECURE_DELETE=`trueorfalse True $CINDER_SECURE_DELETE`
87
Sean Daguef35ff722013-05-16 16:31:12 -040088# Cinder reports allocations back to the scheduler on periodic intervals
89# it turns out we can get an "out of space" issue when we run tests too
90# quickly just because cinder didn't realize we'd freed up resources.
91# Make this configurable so that devstack-gate/tempest can set it to
92# less than the 60 second default
93# https://bugs.launchpad.net/cinder/+bug/1180976
94CINDER_PERIODIC_INTERVAL=${CINDER_PERIODIC_INTERVAL:-60}
95
Dean Troyer4237f592014-01-29 16:22:11 -060096# Tell Tempest this project is present
97TEMPEST_SERVICES+=,cinder
98
Dean Troyercc6b4432013-04-08 15:38:03 -050099
Dean Troyer09718332014-07-03 10:46:57 -0500100# Source the enabled backends
101if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
102 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500103 be_type=${be%%:*}
104 be_name=${be##*:}
105 if [[ -r $CINDER_BACKENDS/${be_type} ]]; then
106 source $CINDER_BACKENDS/${be_type}
Dean Troyer09718332014-07-03 10:46:57 -0500107 fi
108 done
109fi
110
111
Dean Troyercc6b4432013-04-08 15:38:03 -0500112# Functions
113# ---------
Dean Troyere4fa7212014-01-15 15:04:49 -0600114
115# Test if any Cinder services are enabled
116# is_cinder_enabled
117function is_cinder_enabled {
118 [[ ,${ENABLED_SERVICES} =~ ,"c-" ]] && return 0
119 return 1
120}
121
Dean Troyer67787e62012-05-02 11:48:15 -0500122# cleanup_cinder() - Remove residual data files, anything left over from previous
123# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100124function cleanup_cinder {
Sean Dague252f2f52012-12-20 16:41:57 -0500125 # ensure the volume group is cleared up because fails might
126 # leave dead volumes in the group
Dean Troyere8a35ac2014-07-25 12:37:41 -0500127 local targets=$(sudo tgtadm --op show --mode target)
Sean Dague252f2f52012-12-20 16:41:57 -0500128 if [ $? -ne 0 ]; then
129 # If tgt driver isn't running this won't work obviously
130 # So check the response and restart if need be
131 echo "tgtd seems to be in a bad state, restarting..."
132 if is_ubuntu; then
133 restart_service tgt
134 else
135 restart_service tgtd
136 fi
Dean Troyere8a35ac2014-07-25 12:37:41 -0500137 targets=$(sudo tgtadm --op show --mode target)
Sean Dague252f2f52012-12-20 16:41:57 -0500138 fi
139
Dean Troyere8a35ac2014-07-25 12:37:41 -0500140 if [[ -n "$targets" ]]; then
141 local iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
Sean Dague252f2f52012-12-20 16:41:57 -0500142 for i in "${iqn_list[@]}"; do
143 echo removing iSCSI target: $i
144 sudo tgt-admin --delete $i
145 done
146 fi
147
Sean Dague252f2f52012-12-20 16:41:57 -0500148 if is_ubuntu; then
149 stop_service tgt
150 else
151 stop_service tgtd
152 fi
153
Dean Troyer09718332014-07-03 10:46:57 -0500154 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500155 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500156 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500157 be_type=${be%%:*}
158 be_name=${be##*:}
159 if type cleanup_cinder_backend_${be_type} >/dev/null 2>&1; then
160 cleanup_cinder_backend_${be_type} ${be_name}
Dean Troyer09718332014-07-03 10:46:57 -0500161 fi
162 done
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100163 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500164}
165
Thierry Carrez63e17842014-01-10 14:23:03 +0100166# configure_cinder_rootwrap() - configure Cinder's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +1100167function configure_cinder_rootwrap {
John Griffith4e823ff2012-07-20 13:18:17 -0600168 # Set the paths of certain binaries
Dean Troyere8a35ac2014-07-25 12:37:41 -0500169 local cinder_rootwrap=$(get_rootwrap_location cinder)
John Griffith4e823ff2012-07-20 13:18:17 -0600170
Thierry Carrezd5d49742014-02-06 16:00:08 +0100171 # Deploy new rootwrap filters files (owned by root).
172 # Wipe any existing rootwrap.d files first
173 if [[ -d $CINDER_CONF_DIR/rootwrap.d ]]; then
174 sudo rm -rf $CINDER_CONF_DIR/rootwrap.d
John Griffith4e823ff2012-07-20 13:18:17 -0600175 fi
Thierry Carrezd5d49742014-02-06 16:00:08 +0100176 # Deploy filters to /etc/cinder/rootwrap.d
177 sudo mkdir -m 755 $CINDER_CONF_DIR/rootwrap.d
178 sudo cp $CINDER_DIR/etc/cinder/rootwrap.d/*.filters $CINDER_CONF_DIR/rootwrap.d
179 sudo chown -R root:root $CINDER_CONF_DIR/rootwrap.d
180 sudo chmod 644 $CINDER_CONF_DIR/rootwrap.d/*
181 # Set up rootwrap.conf, pointing to /etc/cinder/rootwrap.d
182 sudo cp $CINDER_DIR/etc/cinder/rootwrap.conf $CINDER_CONF_DIR/
183 sudo sed -e "s:^filters_path=.*$:filters_path=$CINDER_CONF_DIR/rootwrap.d:" -i $CINDER_CONF_DIR/rootwrap.conf
184 sudo chown root:root $CINDER_CONF_DIR/rootwrap.conf
185 sudo chmod 0644 $CINDER_CONF_DIR/rootwrap.conf
186 # Specify rootwrap.conf as first parameter to rootwrap
Dean Troyere8a35ac2014-07-25 12:37:41 -0500187 ROOTWRAP_CSUDOER_CMD="$cinder_rootwrap $CINDER_CONF_DIR/rootwrap.conf *"
John Griffith4e823ff2012-07-20 13:18:17 -0600188
Thierry Carrezd5d49742014-02-06 16:00:08 +0100189 # Set up the rootwrap sudoers for cinder
Dean Troyere8a35ac2014-07-25 12:37:41 -0500190 local tempfile=`mktemp`
191 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_CSUDOER_CMD" >$tempfile
192 chmod 0440 $tempfile
193 sudo chown root:root $tempfile
194 sudo mv $tempfile /etc/sudoers.d/cinder-rootwrap
Thierry Carrez63e17842014-01-10 14:23:03 +0100195}
196
197# configure_cinder() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100198function configure_cinder {
Thierry Carrez63e17842014-01-10 14:23:03 +0100199 if [[ ! -d $CINDER_CONF_DIR ]]; then
200 sudo mkdir -p $CINDER_CONF_DIR
201 fi
202 sudo chown $STACK_USER $CINDER_CONF_DIR
203
204 cp -p $CINDER_DIR/etc/cinder/policy.json $CINDER_CONF_DIR
205
206 configure_cinder_rootwrap
John Griffith4e823ff2012-07-20 13:18:17 -0600207
Dean Troyer67787e62012-05-02 11:48:15 -0500208 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
Dan Prince82dea7c2013-10-16 18:57:15 -0400209
210 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_host
211 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_port
212 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_protocol
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000213 inicomment $CINDER_API_PASTE_INI filter:authtoken cafile
Dan Prince82dea7c2013-10-16 18:57:15 -0400214 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name
215 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_user
216 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_password
217 inicomment $CINDER_API_PASTE_INI filter:authtoken signing_dir
Dean Troyerbc071bc2012-10-01 14:06:44 -0500218
Brant Knudson05952372014-09-19 17:22:22 -0500219 configure_auth_token_middleware $CINDER_CONF cinder $CINDER_AUTH_CACHE_DIR
Dan Prince82dea7c2013-10-16 18:57:15 -0400220
Dean Troyer67787e62012-05-02 11:48:15 -0500221 iniset $CINDER_CONF DEFAULT auth_strategy keystone
Ben Nemec03997942013-08-10 09:56:16 -0500222 iniset $CINDER_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Dean Troyer67787e62012-05-02 11:48:15 -0500223 iniset $CINDER_CONF DEFAULT verbose True
Dean Troyer09718332014-07-03 10:46:57 -0500224
Nikolay Sobolevskiy08df29b2013-08-30 21:59:15 +0400225 iniset $CINDER_CONF DEFAULT my_ip "$CINDER_SERVICE_HOST"
Dean Troyer67787e62012-05-02 11:48:15 -0500226 iniset $CINDER_CONF DEFAULT iscsi_helper tgtadm
Attila Fazekas7e79d912013-03-03 12:23:04 +0100227 iniset $CINDER_CONF DEFAULT sql_connection `database_connection_url cinder`
Dean Troyer67787e62012-05-02 11:48:15 -0500228 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
Joe Gordona58382a2013-02-20 12:45:02 -0800229 iniset $CINDER_CONF DEFAULT rootwrap_config "$CINDER_CONF_DIR/rootwrap.conf"
Dan Prince9f22f072013-01-28 09:53:38 -0500230 iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.contrib.standard_extensions
Dean Troyer50ac7922012-09-13 14:02:01 -0500231 iniset $CINDER_CONF DEFAULT state_path $CINDER_STATE_PATH
Sergey Kraynev84783c72013-10-10 09:08:48 -0400232 iniset $CINDER_CONF DEFAULT lock_path $CINDER_STATE_PATH
Sean Daguef35ff722013-05-16 16:31:12 -0400233 iniset $CINDER_CONF DEFAULT periodic_interval $CINDER_PERIODIC_INTERVAL
Mike Perezf64f43b2014-06-25 08:51:31 -0700234 # NOTE(thingee): Cinder V1 API is deprecated and defaults to off as of
235 # Juno. Keep it enabled so we can continue testing while it's still
236 # supported.
237 iniset $CINDER_CONF DEFAULT enable_v1_api true
John Griffith4e823ff2012-07-20 13:18:17 -0600238
Dean Troyer09718332014-07-03 10:46:57 -0500239 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500240 local enabled_backends=""
241 local default_name=""
242 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500243 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500244 be_type=${be%%:*}
245 be_name=${be##*:}
246 if type configure_cinder_backend_${be_type} >/dev/null 2>&1; then
247 configure_cinder_backend_${be_type} ${be_name}
Dean Troyer09718332014-07-03 10:46:57 -0500248 fi
Dean Troyera25922b2014-08-28 09:29:47 -0500249 if [[ -z "$default_name" ]]; then
250 default_name=$be_name
Dean Troyer09718332014-07-03 10:46:57 -0500251 fi
Dean Troyere8a35ac2014-07-25 12:37:41 -0500252 enabled_backends+=$be_name,
Dean Troyer09718332014-07-03 10:46:57 -0500253 done
254 iniset $CINDER_CONF DEFAULT enabled_backends ${enabled_backends%,*}
Matt Riedemann6a4aa782014-07-25 13:35:53 -0700255 if [[ -n "$default_name" ]]; then
256 iniset $CINDER_CONF DEFAULT default_volume_type ${default_name}
Dean Troyer09718332014-07-03 10:46:57 -0500257 fi
258 fi
259
Attila Fazekas29834742014-03-09 18:36:42 +0100260 if is_service_enabled swift; then
261 iniset $CINDER_CONF DEFAULT backup_swift_url "http://$SERVICE_HOST:8080/v1/AUTH_"
262 fi
263
Gordon Chung2bfbc772013-08-09 10:55:12 -0400264 if is_service_enabled ceilometer; then
Mark McLoughlindc0938e2014-06-17 06:37:43 +0100265 iniset $CINDER_CONF DEFAULT notification_driver "messaging"
Gordon Chung2bfbc772013-08-09 10:55:12 -0400266 fi
267
Dean Troyer560346b2012-12-13 17:05:24 -0600268 if is_service_enabled tls-proxy; then
269 # Set the service port for a proxy to take the original
270 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
271 fi
272
Dean Troyer4d3049e2012-11-06 20:38:14 -0600273 if [ "$SYSLOG" != "False" ]; then
274 iniset $CINDER_CONF DEFAULT use_syslog True
275 fi
276
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900277 iniset_rpc_backend cinder $CINDER_CONF DEFAULT
Gary Kottonf71bf192012-08-06 11:15:36 -0400278
James E. Blair213c4162012-11-06 09:38:36 +0100279 if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then
280 iniset $CINDER_CONF DEFAULT secure_delete False
Pádraig Bradyeac93702013-01-02 16:02:54 +0000281 iniset $CINDER_CONF DEFAULT volume_clear none
James E. Blair213c4162012-11-06 09:38:36 +0100282 fi
283
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700284 # Format logging
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000285 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700286 setup_colorized_logging $CINDER_CONF DEFAULT "project_id" "user_id"
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000287 fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000288
john-griffithd0860cc2014-01-23 11:31:10 -0700289 if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
290 configure_cinder_driver
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000291 fi
Ian Wienand0db17132013-06-26 22:31:48 +1000292
293 if [[ is_fedora && $DISTRO =~ (rhel6) ]]; then
294 # Cinder clones are slightly larger due to some extra
295 # metadata. RHEL6 will not allow auto-extending of LV's
296 # without this, leading to clones giving hard-to-track disk
297 # I/O errors.
298 # see https://bugzilla.redhat.com/show_bug.cgi?id=975052
299 sudo sed -i~ \
300 -e 's/snapshot_autoextend_threshold =.*/snapshot_autoextend_threshold = 80/' \
301 -e 's/snapshot_autoextend_percent =.*/snapshot_autoextend_percent = 20/' \
302 /etc/lvm/lvm.conf
303 fi
304
Dean Troyer05bd7b82014-09-16 17:25:33 -0500305 iniset $CINDER_CONF DEFAULT osapi_volume_workers "$API_WORKERS"
Rob Crittenden18d47782014-03-19 17:47:42 -0400306
307 iniset $CINDER_CONF DEFAULT glance_api_servers "${GLANCE_SERVICE_PROTOCOL}://${GLANCE_HOSTPORT}"
308 if is_ssl_enabled_service glance || is_service_enabled tls-proxy; then
309 iniset $CINDER_CONF DEFAULT glance_protocol https
Rob Crittenden4b109292014-10-21 18:17:48 -0400310 iniset $CINDER_CONF DEFAULT glance_ca_certificates_file $SSL_BUNDLE_FILE
Rob Crittenden18d47782014-03-19 17:47:42 -0400311 fi
312
313 # Register SSL certificates if provided
314 if is_ssl_enabled_service cinder; then
315 ensure_certificates CINDER
316
317 iniset $CINDER_CONF DEFAULT ssl_cert_file "$CINDER_SSL_CERT"
318 iniset $CINDER_CONF DEFAULT ssl_key_file "$CINDER_SSL_KEY"
319 fi
320
Dean Troyer67787e62012-05-02 11:48:15 -0500321}
322
Dean Troyer671c16e2012-12-13 16:22:38 -0600323# create_cinder_accounts() - Set up common required cinder accounts
324
325# Tenant User Roles
326# ------------------------------------------------------------------
327# service cinder admin # if enabled
328
329# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100330function create_cinder_accounts {
Dean Troyer671c16e2012-12-13 16:22:38 -0600331
Dean Troyere8a35ac2014-07-25 12:37:41 -0500332 local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
333 local admin_role=$(openstack role list | awk "/ admin / { print \$2 }")
Dean Troyer671c16e2012-12-13 16:22:38 -0600334
335 # Cinder
336 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100337
Dean Troyere8a35ac2014-07-25 12:37:41 -0500338 local cinder_user=$(get_or_create_user "cinder" \
339 "$SERVICE_PASSWORD" $service_tenant)
340 get_or_add_user_role $admin_role $cinder_user $service_tenant
Bartosz Górski0abde392014-02-28 14:15:19 +0100341
Dean Troyer671c16e2012-12-13 16:22:38 -0600342 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100343
Dean Troyere8a35ac2014-07-25 12:37:41 -0500344 local cinder_service=$(get_or_create_service "cinder" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100345 "volume" "Cinder Volume Service")
Dean Troyere8a35ac2014-07-25 12:37:41 -0500346 get_or_create_endpoint $cinder_service "$REGION_NAME" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100347 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
348 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
349 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s"
350
Dean Troyere8a35ac2014-07-25 12:37:41 -0500351 local cinder_v2_service=$(get_or_create_service "cinderv2" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100352 "volumev2" "Cinder Volume Service V2")
Dean Troyere8a35ac2014-07-25 12:37:41 -0500353 get_or_create_endpoint $cinder_v2_service "$REGION_NAME" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100354 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s" \
355 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s" \
356 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s"
Dean Troyer671c16e2012-12-13 16:22:38 -0600357 fi
358 fi
359}
360
Dean Troyerf03bafe2013-02-12 10:58:28 -0600361# create_cinder_cache_dir() - Part of the init_cinder() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100362function create_cinder_cache_dir {
Dean Troyerf03bafe2013-02-12 10:58:28 -0600363 # Create cache dir
364 sudo mkdir -p $CINDER_AUTH_CACHE_DIR
365 sudo chown $STACK_USER $CINDER_AUTH_CACHE_DIR
366 rm -f $CINDER_AUTH_CACHE_DIR/*
367}
368
Dean Troyer67787e62012-05-02 11:48:15 -0500369# init_cinder() - Initialize database and volume group
Dean Troyere8a35ac2014-07-25 12:37:41 -0500370# Uses global ``NOVA_ENABLED_APIS``
Ian Wienandaee18c72014-02-21 15:35:08 +1100371function init_cinder {
Dean Troyer67787e62012-05-02 11:48:15 -0500372 # Force nova volumes off
373 NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
374
Terry Wilson428af5a2012-11-01 16:12:39 -0400375 if is_service_enabled $DATABASE_BACKENDS; then
Dean Troyerf03bafe2013-02-12 10:58:28 -0600376 # (Re)create cinder database
Terry Wilson428af5a2012-11-01 16:12:39 -0400377 recreate_database cinder utf8
Dean Troyer67787e62012-05-02 11:48:15 -0500378
Dean Troyerf03bafe2013-02-12 10:58:28 -0600379 # Migrate cinder database
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400380 $CINDER_BIN_DIR/cinder-manage db sync
Dean Troyer67787e62012-05-02 11:48:15 -0500381 fi
382
Dean Troyer09718332014-07-03 10:46:57 -0500383 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500384 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500385 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500386 be_type=${be%%:*}
387 be_name=${be##*:}
388 if type init_cinder_backend_${be_type} >/dev/null 2>&1; then
389 init_cinder_backend_${be_type} ${be_name}
Vincent Untz0230aa82012-06-14 08:51:01 +0200390 fi
Dean Troyer09718332014-07-03 10:46:57 -0500391 done
Dean Troyer67787e62012-05-02 11:48:15 -0500392 fi
Dean Troyerbc071bc2012-10-01 14:06:44 -0500393
Dean Troyer09718332014-07-03 10:46:57 -0500394 mkdir -p $CINDER_STATE_PATH/volumes
Dean Troyerf03bafe2013-02-12 10:58:28 -0600395 create_cinder_cache_dir
Dean Troyer67787e62012-05-02 11:48:15 -0500396}
397
398# install_cinder() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100399function install_cinder {
Dean Troyer67787e62012-05-02 11:48:15 -0500400 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400401 setup_develop $CINDER_DIR
Dean Troyer253a1a32013-04-01 18:23:22 -0500402}
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400403
Dean Troyer253a1a32013-04-01 18:23:22 -0500404# install_cinderclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100405function install_cinderclient {
Sean Dague5cb19062014-11-01 01:37:45 +0100406 if use_library_from_git "cinderclient"; then
407 git_clone_by_name "cinderclient"
408 setup_develop "cinderclient"
409 sudo install -D -m 0644 -o $STACK_USER {$CINDERCLIENT_DIR/tools/,/etc/bash_completion.d/}cinder.bash_completion
410 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500411}
412
Steve Baker18225d92013-04-14 12:48:41 -0700413# apply config.d approach for cinder volumes directory
Ian Wienandaee18c72014-02-21 15:35:08 +1100414function _configure_tgt_for_config_d {
Steve Baker18225d92013-04-14 12:48:41 -0700415 if [[ ! -d /etc/tgt/stack.d/ ]]; then
416 sudo ln -sf $CINDER_STATE_PATH/volumes /etc/tgt/stack.d
417 echo "include /etc/tgt/stack.d/*" | sudo tee -a /etc/tgt/targets.conf
Mate Lakata39caac2012-09-03 15:45:53 +0100418 fi
419}
420
Dean Troyer67787e62012-05-02 11:48:15 -0500421# start_cinder() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100422function start_cinder {
Rob Crittenden18d47782014-03-19 17:47:42 -0400423 local service_port=$CINDER_SERVICE_PORT
424 local service_protocol=$CINDER_SERVICE_PROTOCOL
425 if is_service_enabled tls-proxy; then
426 service_port=$CINDER_SERVICE_PORT_INT
427 service_protocol="http"
428 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500429 if is_service_enabled c-vol; then
Steve Baker18225d92013-04-14 12:48:41 -0700430 # Delete any old stack.conf
431 sudo rm -f /etc/tgt/conf.d/stack.conf
Attila Fazekasb79574b2012-12-01 10:42:46 +0100432 _configure_tgt_for_config_d
Vincent Untzc18b9652012-12-04 12:36:34 +0100433 if is_ubuntu; then
Sean Dagued5b52ca2014-03-04 09:23:07 -0500434 sudo service tgt restart
Vincent Untz00011c02012-12-06 09:56:32 +0100435 elif is_fedora; then
Ian Wienand3b578292014-02-26 14:52:02 +1100436 if [[ $DISTRO =~ (rhel6) ]]; then
437 sudo /sbin/service tgtd restart
438 else
439 # bypass redirection to systemctl during restart
440 sudo /sbin/service --skip-redirect tgtd restart
441 fi
Vincent Untz00011c02012-12-06 09:56:32 +0100442 elif is_suse; then
443 restart_service tgtd
444 else
445 # note for other distros: unstack.sh also uses the tgt/tgtd service
446 # name, and would need to be adjusted too
447 exit_distro_not_supported "restarting tgt"
Dean Troyer67787e62012-05-02 11:48:15 -0500448 fi
Giulio Fidente384454d2013-09-27 13:17:34 +0200449 # NOTE(gfidente): ensure tgtd is running in debug mode
450 sudo tgtadm --mode system --op update --name debug --value on
Dean Troyer67787e62012-05-02 11:48:15 -0500451 fi
452
Dean Troyer3159a822014-08-27 14:13:58 -0500453 run_process c-api "$CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
Dean Troyer09718332014-07-03 10:46:57 -0500454 echo "Waiting for Cinder API to start..."
Rob Crittenden18d47782014-03-19 17:47:42 -0400455 if ! wait_for_service $SERVICE_TIMEOUT $service_protocol://$CINDER_SERVICE_HOST:$service_port; then
Dean Troyer09718332014-07-03 10:46:57 -0500456 die $LINENO "c-api did not start"
457 fi
458
Dean Troyer3159a822014-08-27 14:13:58 -0500459 run_process c-sch "$CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
460 run_process c-bak "$CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF"
461 run_process c-vol "$CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
John Griffithe6d4fe52013-07-15 17:35:54 -0600462
463 # NOTE(jdg): For cinder, startup order matters. To ensure that repor_capabilities is received
464 # by the scheduler start the cinder-volume service last (or restart it) after the scheduler
465 # has started. This is a quick fix for lp bug/1189595
Dean Troyer560346b2012-12-13 17:05:24 -0600466
467 # Start proxies if enabled
468 if is_service_enabled c-api && is_service_enabled tls-proxy; then
469 start_tls_proxy '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT &
470 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500471}
472
Dean Troyer699a29f2012-09-10 14:10:27 -0500473# stop_cinder() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100474function stop_cinder {
Dean Troyer699a29f2012-09-10 14:10:27 -0500475 # Kill the cinder screen windows
Dean Troyere8a35ac2014-07-25 12:37:41 -0500476 local serv
Stephen Mulcahy67068ef2013-02-21 11:20:58 +0000477 for serv in c-api c-bak c-sch c-vol; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100478 stop_process $serv
Dean Troyer699a29f2012-09-10 14:10:27 -0500479 done
Dean Troyer67787e62012-05-02 11:48:15 -0500480
481 if is_service_enabled c-vol; then
Vincent Untz90dd96d2012-12-13 08:59:57 +0100482 if is_ubuntu; then
483 stop_service tgt
484 else
485 stop_service tgtd
486 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500487 fi
488}
Dean Troyer7903b792012-09-13 17:16:12 -0500489
Dean Troyer09718332014-07-03 10:46:57 -0500490# create_volume_types() - Create Cinder's configured volume types
491function create_volume_types {
492 # Create volume types
493 if is_service_enabled c-api && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500494 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500495 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500496 be_type=${be%%:*}
497 be_name=${be##*:}
498 # openstack volume type create --property volume_backend_name="${be_type}" ${be_name}
499 cinder type-create ${be_name} && \
500 cinder type-key ${be_name} set volume_backend_name="${be_name}"
Dean Troyer09718332014-07-03 10:46:57 -0500501 done
502 fi
503}
504
505# Compatibility for Grenade
506
507function create_cinder_volume_group {
508 # During a transition period Grenade needs to have this function defined
509 # It is effectively a no-op in the Grenade 'target' use case
510 :
511}
512
Dean Troyercc6b4432013-04-08 15:38:03 -0500513
Dean Troyer7903b792012-09-13 17:16:12 -0500514# Restore xtrace
515$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400516
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100517# Tell emacs to use shell-script-mode
518## Local variables:
519## mode: shell-script
520## End: