blob: d003f5dc7b7ffe9880df5498f7ee328893ce8308 [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
31
32# grab plugin config if specified via cinder_driver
33if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
34 source $CINDER_PLUGINS/$CINDER_DRIVER
35fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +000036
Dean Troyer67787e62012-05-02 11:48:15 -050037# set up default directories
38CINDER_DIR=$DEST/cinder
Dean Troyer50ac7922012-09-13 14:02:01 -050039CINDERCLIENT_DIR=$DEST/python-cinderclient
40CINDER_STATE_PATH=${CINDER_STATE_PATH:=$DATA_DIR/cinder}
Dean Troyer671c16e2012-12-13 16:22:38 -060041CINDER_AUTH_CACHE_DIR=${CINDER_AUTH_CACHE_DIR:-/var/cache/cinder}
42
Dean Troyer50ac7922012-09-13 14:02:01 -050043CINDER_CONF_DIR=/etc/cinder
44CINDER_CONF=$CINDER_CONF_DIR/cinder.conf
Dean Troyer671c16e2012-12-13 16:22:38 -060045CINDER_API_PASTE_INI=$CINDER_CONF_DIR/api-paste.ini
Dean Troyer50ac7922012-09-13 14:02:01 -050046
Dean Troyer560346b2012-12-13 17:05:24 -060047# Public facing bits
48CINDER_SERVICE_HOST=${CINDER_SERVICE_HOST:-$SERVICE_HOST}
49CINDER_SERVICE_PORT=${CINDER_SERVICE_PORT:-8776}
50CINDER_SERVICE_PORT_INT=${CINDER_SERVICE_PORT_INT:-18776}
51CINDER_SERVICE_PROTOCOL=${CINDER_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
52
Dean Troyer50ac7922012-09-13 14:02:01 -050053# Support entry points installation of console scripts
54if [[ -d $CINDER_DIR/bin ]]; then
Monty Taylor9fbeedd2012-08-17 12:52:27 -040055 CINDER_BIN_DIR=$CINDER_DIR/bin
56else
Jakub Ruzicka4196d552013-01-30 15:35:54 +010057 CINDER_BIN_DIR=$(get_python_exec_prefix)
Monty Taylor9fbeedd2012-08-17 12:52:27 -040058fi
Dean Troyer67787e62012-05-02 11:48:15 -050059
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +010060# Support for multi lvm backend configuration (default is no support)
61CINDER_MULTI_LVM_BACKEND=$(trueorfalse False $CINDER_MULTI_LVM_BACKEND)
62
Dean Troyerb7490da2013-03-18 16:07:56 -050063# Should cinder perform secure deletion of volumes?
64# Defaults to true, can be set to False to avoid this bug when testing:
65# https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1023755
66CINDER_SECURE_DELETE=`trueorfalse True $CINDER_SECURE_DELETE`
67
Sean Daguef35ff722013-05-16 16:31:12 -040068# Cinder reports allocations back to the scheduler on periodic intervals
69# it turns out we can get an "out of space" issue when we run tests too
70# quickly just because cinder didn't realize we'd freed up resources.
71# Make this configurable so that devstack-gate/tempest can set it to
72# less than the 60 second default
73# https://bugs.launchpad.net/cinder/+bug/1180976
74CINDER_PERIODIC_INTERVAL=${CINDER_PERIODIC_INTERVAL:-60}
75
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +010076# Name of the lvm volume groups to use/create for iscsi volumes
Dean Troyer67787e62012-05-02 11:48:15 -050077VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes}
JordanP51c90b82013-05-23 10:27:51 +020078VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
Mate Lakat68ac03c2013-06-06 16:22:34 +010079VOLUME_BACKING_DEVICE=${VOLUME_BACKING_DEVICE:-}
JordanP51c90b82013-05-23 10:27:51 +020080
81# VOLUME_GROUP2 is used only if CINDER_MULTI_LVM_BACKEND = True
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +010082VOLUME_GROUP2=${VOLUME_GROUP2:-stack-volumes2}
JordanP51c90b82013-05-23 10:27:51 +020083VOLUME_BACKING_FILE2=${VOLUME_BACKING_FILE2:-$DATA_DIR/${VOLUME_GROUP2}-backing-file}
Mate Lakat68ac03c2013-06-06 16:22:34 +010084VOLUME_BACKING_DEVICE2=${VOLUME_BACKING_DEVICE2:-}
JordanP51c90b82013-05-23 10:27:51 +020085
Dean Troyer67787e62012-05-02 11:48:15 -050086VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
87
Dean Troyer4237f592014-01-29 16:22:11 -060088# Tell Tempest this project is present
89TEMPEST_SERVICES+=,cinder
90
Dean Troyercc6b4432013-04-08 15:38:03 -050091
92# Functions
93# ---------
Dean Troyere4fa7212014-01-15 15:04:49 -060094
95# Test if any Cinder services are enabled
96# is_cinder_enabled
97function is_cinder_enabled {
98 [[ ,${ENABLED_SERVICES} =~ ,"c-" ]] && return 0
99 return 1
100}
101
JordanP022e9912013-07-09 14:14:48 +0200102# _clean_lvm_lv removes all cinder LVM volumes
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100103#
104# Usage: _clean_lvm_lv $VOLUME_GROUP $VOLUME_NAME_PREFIX
Ian Wienandaee18c72014-02-21 15:35:08 +1100105function _clean_lvm_lv {
Dean Troyer22853c12013-01-07 15:18:12 -0600106 local vg=$1
JordanP51c90b82013-05-23 10:27:51 +0200107 local lv_prefix=$2
108
Dean Troyer22853c12013-01-07 15:18:12 -0600109 # Clean out existing volumes
110 for lv in `sudo lvs --noheadings -o lv_name $vg`; do
JordanP51c90b82013-05-23 10:27:51 +0200111 # lv_prefix prefixes the LVs we want
112 if [[ "${lv#$lv_prefix}" != "$lv" ]]; then
Dean Troyer22853c12013-01-07 15:18:12 -0600113 sudo lvremove -f $vg/$lv
114 fi
115 done
JordanP022e9912013-07-09 14:14:48 +0200116}
117
118# _clean_lvm_backing_file() removes the backing file of the
119# volume group used by cinder
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100120#
121# Usage: _clean_lvm_backing_file() $VOLUME_GROUP
Ian Wienandaee18c72014-02-21 15:35:08 +1100122function _clean_lvm_backing_file {
JordanP022e9912013-07-09 14:14:48 +0200123 local vg=$1
JordanP51c90b82013-05-23 10:27:51 +0200124
125 # if there is no logical volume left, it's safe to attempt a cleanup
126 # of the backing file
127 if [ -z "`sudo lvs --noheadings -o lv_name $vg`" ]; then
128 # if the backing physical device is a loop device, it was probably setup by devstack
Dean Troyer53ffc712013-12-17 11:13:40 -0600129 if [[ -n "$VG_DEV" ]] && [[ -e "$VG_DEV" ]]; then
130 VG_DEV=$(sudo losetup -j $DATA_DIR/${vg}-backing-file | awk -F':' '/backing-file/ { print $1}')
JordanP51c90b82013-05-23 10:27:51 +0200131 sudo losetup -d $VG_DEV
132 rm -f $DATA_DIR/${vg}-backing-file
133 fi
134 fi
Dean Troyer22853c12013-01-07 15:18:12 -0600135}
136
Dean Troyer67787e62012-05-02 11:48:15 -0500137# cleanup_cinder() - Remove residual data files, anything left over from previous
138# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100139function cleanup_cinder {
Sean Dague252f2f52012-12-20 16:41:57 -0500140 # ensure the volume group is cleared up because fails might
141 # leave dead volumes in the group
142 TARGETS=$(sudo tgtadm --op show --mode target)
143 if [ $? -ne 0 ]; then
144 # If tgt driver isn't running this won't work obviously
145 # So check the response and restart if need be
146 echo "tgtd seems to be in a bad state, restarting..."
147 if is_ubuntu; then
148 restart_service tgt
149 else
150 restart_service tgtd
151 fi
152 TARGETS=$(sudo tgtadm --op show --mode target)
153 fi
154
155 if [[ -n "$TARGETS" ]]; then
156 iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
157 for i in "${iqn_list[@]}"; do
158 echo removing iSCSI target: $i
159 sudo tgt-admin --delete $i
160 done
161 fi
162
163 if is_service_enabled cinder; then
164 sudo rm -rf $CINDER_STATE_PATH/volumes/*
165 fi
166
167 if is_ubuntu; then
168 stop_service tgt
169 else
170 stop_service tgtd
171 fi
172
Dean Troyer22853c12013-01-07 15:18:12 -0600173 # Campsite rule: leave behind a volume group at least as clean as we found it
JordanP022e9912013-07-09 14:14:48 +0200174 _clean_lvm_lv $VOLUME_GROUP $VOLUME_NAME_PREFIX
175 _clean_lvm_backing_file $VOLUME_GROUP
JordanP51c90b82013-05-23 10:27:51 +0200176
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100177 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
JordanP022e9912013-07-09 14:14:48 +0200178 _clean_lvm_lv $VOLUME_GROUP2 $VOLUME_NAME_PREFIX
179 _clean_lvm_backing_file $VOLUME_GROUP2
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100180 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500181}
182
Thierry Carrez63e17842014-01-10 14:23:03 +0100183# configure_cinder_rootwrap() - configure Cinder's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +1100184function configure_cinder_rootwrap {
John Griffith4e823ff2012-07-20 13:18:17 -0600185 # Set the paths of certain binaries
Vincent Untz856a11e2012-11-21 16:04:12 +0100186 CINDER_ROOTWRAP=$(get_rootwrap_location cinder)
John Griffith4e823ff2012-07-20 13:18:17 -0600187
Thierry Carrezd5d49742014-02-06 16:00:08 +0100188 # Deploy new rootwrap filters files (owned by root).
189 # Wipe any existing rootwrap.d files first
190 if [[ -d $CINDER_CONF_DIR/rootwrap.d ]]; then
191 sudo rm -rf $CINDER_CONF_DIR/rootwrap.d
John Griffith4e823ff2012-07-20 13:18:17 -0600192 fi
Thierry Carrezd5d49742014-02-06 16:00:08 +0100193 # Deploy filters to /etc/cinder/rootwrap.d
194 sudo mkdir -m 755 $CINDER_CONF_DIR/rootwrap.d
195 sudo cp $CINDER_DIR/etc/cinder/rootwrap.d/*.filters $CINDER_CONF_DIR/rootwrap.d
196 sudo chown -R root:root $CINDER_CONF_DIR/rootwrap.d
197 sudo chmod 644 $CINDER_CONF_DIR/rootwrap.d/*
198 # Set up rootwrap.conf, pointing to /etc/cinder/rootwrap.d
199 sudo cp $CINDER_DIR/etc/cinder/rootwrap.conf $CINDER_CONF_DIR/
200 sudo sed -e "s:^filters_path=.*$:filters_path=$CINDER_CONF_DIR/rootwrap.d:" -i $CINDER_CONF_DIR/rootwrap.conf
201 sudo chown root:root $CINDER_CONF_DIR/rootwrap.conf
202 sudo chmod 0644 $CINDER_CONF_DIR/rootwrap.conf
203 # Specify rootwrap.conf as first parameter to rootwrap
204 ROOTWRAP_CSUDOER_CMD="$CINDER_ROOTWRAP $CINDER_CONF_DIR/rootwrap.conf *"
John Griffith4e823ff2012-07-20 13:18:17 -0600205
Thierry Carrezd5d49742014-02-06 16:00:08 +0100206 # Set up the rootwrap sudoers for cinder
John Griffith4e823ff2012-07-20 13:18:17 -0600207 TEMPFILE=`mktemp`
Thierry Carrezd5d49742014-02-06 16:00:08 +0100208 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_CSUDOER_CMD" >$TEMPFILE
John Griffith4e823ff2012-07-20 13:18:17 -0600209 chmod 0440 $TEMPFILE
210 sudo chown root:root $TEMPFILE
211 sudo mv $TEMPFILE /etc/sudoers.d/cinder-rootwrap
Thierry Carrez63e17842014-01-10 14:23:03 +0100212}
213
214# configure_cinder() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100215function configure_cinder {
Thierry Carrez63e17842014-01-10 14:23:03 +0100216 if [[ ! -d $CINDER_CONF_DIR ]]; then
217 sudo mkdir -p $CINDER_CONF_DIR
218 fi
219 sudo chown $STACK_USER $CINDER_CONF_DIR
220
221 cp -p $CINDER_DIR/etc/cinder/policy.json $CINDER_CONF_DIR
222
223 configure_cinder_rootwrap
John Griffith4e823ff2012-07-20 13:18:17 -0600224
Dean Troyer67787e62012-05-02 11:48:15 -0500225 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
Dan Prince82dea7c2013-10-16 18:57:15 -0400226
227 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_host
228 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_port
229 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_protocol
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000230 inicomment $CINDER_API_PASTE_INI filter:authtoken cafile
Dan Prince82dea7c2013-10-16 18:57:15 -0400231 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name
232 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_user
233 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_password
234 inicomment $CINDER_API_PASTE_INI filter:authtoken signing_dir
Dean Troyerbc071bc2012-10-01 14:06:44 -0500235
Dean Troyer67787e62012-05-02 11:48:15 -0500236 cp $CINDER_DIR/etc/cinder/cinder.conf.sample $CINDER_CONF
Dan Prince82dea7c2013-10-16 18:57:15 -0400237
238 iniset $CINDER_CONF keystone_authtoken auth_host $KEYSTONE_AUTH_HOST
239 iniset $CINDER_CONF keystone_authtoken auth_port $KEYSTONE_AUTH_PORT
240 iniset $CINDER_CONF keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000241 iniset $CINDER_CONF keystone_authtoken cafile $KEYSTONE_SSL_CA
Dan Prince82dea7c2013-10-16 18:57:15 -0400242 iniset $CINDER_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
243 iniset $CINDER_CONF keystone_authtoken admin_user cinder
244 iniset $CINDER_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
245 iniset $CINDER_CONF keystone_authtoken signing_dir $CINDER_AUTH_CACHE_DIR
246
Dean Troyer67787e62012-05-02 11:48:15 -0500247 iniset $CINDER_CONF DEFAULT auth_strategy keystone
Ben Nemec03997942013-08-10 09:56:16 -0500248 iniset $CINDER_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Dean Troyer67787e62012-05-02 11:48:15 -0500249 iniset $CINDER_CONF DEFAULT verbose True
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100250 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
251 iniset $CINDER_CONF DEFAULT enabled_backends lvmdriver-1,lvmdriver-2
252 iniset $CINDER_CONF lvmdriver-1 volume_group $VOLUME_GROUP
253 iniset $CINDER_CONF lvmdriver-1 volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver
254 iniset $CINDER_CONF lvmdriver-1 volume_backend_name LVM_iSCSI
255 iniset $CINDER_CONF lvmdriver-2 volume_group $VOLUME_GROUP2
256 iniset $CINDER_CONF lvmdriver-2 volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver
Giulio Fidente97e1bd02013-06-04 05:33:52 +0200257 iniset $CINDER_CONF lvmdriver-2 volume_backend_name LVM_iSCSI_2
Matt Riedemann7103a842013-12-07 13:53:33 -0800258 # NOTE(mriedem): Work around Cinder "wishlist" bug 1255593
259 if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then
260 iniset $CINDER_CONF lvmdriver-1 volume_clear none
261 iniset $CINDER_CONF lvmdriver-2 volume_clear none
262 fi
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100263 else
264 iniset $CINDER_CONF DEFAULT volume_group $VOLUME_GROUP
265 iniset $CINDER_CONF DEFAULT volume_name_template ${VOLUME_NAME_PREFIX}%s
266 fi
Nikolay Sobolevskiy08df29b2013-08-30 21:59:15 +0400267 iniset $CINDER_CONF DEFAULT my_ip "$CINDER_SERVICE_HOST"
Dean Troyer67787e62012-05-02 11:48:15 -0500268 iniset $CINDER_CONF DEFAULT iscsi_helper tgtadm
Attila Fazekas7e79d912013-03-03 12:23:04 +0100269 iniset $CINDER_CONF DEFAULT sql_connection `database_connection_url cinder`
Dean Troyer67787e62012-05-02 11:48:15 -0500270 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
Joe Gordona58382a2013-02-20 12:45:02 -0800271 iniset $CINDER_CONF DEFAULT rootwrap_config "$CINDER_CONF_DIR/rootwrap.conf"
Dan Prince9f22f072013-01-28 09:53:38 -0500272 iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.contrib.standard_extensions
Dean Troyer50ac7922012-09-13 14:02:01 -0500273 iniset $CINDER_CONF DEFAULT state_path $CINDER_STATE_PATH
Sergey Kraynev84783c72013-10-10 09:08:48 -0400274 iniset $CINDER_CONF DEFAULT lock_path $CINDER_STATE_PATH
Sean Daguef35ff722013-05-16 16:31:12 -0400275 iniset $CINDER_CONF DEFAULT periodic_interval $CINDER_PERIODIC_INTERVAL
John Griffith4e823ff2012-07-20 13:18:17 -0600276
Gordon Chung2bfbc772013-08-09 10:55:12 -0400277 if is_service_enabled ceilometer; then
278 iniset $CINDER_CONF DEFAULT notification_driver "cinder.openstack.common.notifier.rpc_notifier"
279 fi
280
Dean Troyer560346b2012-12-13 17:05:24 -0600281 if is_service_enabled tls-proxy; then
282 # Set the service port for a proxy to take the original
283 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
284 fi
285
Dean Troyer4d3049e2012-11-06 20:38:14 -0600286 if [ "$SYSLOG" != "False" ]; then
287 iniset $CINDER_CONF DEFAULT use_syslog True
288 fi
289
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900290 iniset_rpc_backend cinder $CINDER_CONF DEFAULT
Gary Kottonf71bf192012-08-06 11:15:36 -0400291
James E. Blair213c4162012-11-06 09:38:36 +0100292 if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then
293 iniset $CINDER_CONF DEFAULT secure_delete False
Pádraig Bradyeac93702013-01-02 16:02:54 +0000294 iniset $CINDER_CONF DEFAULT volume_clear none
James E. Blair213c4162012-11-06 09:38:36 +0100295 fi
296
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700297 # Format logging
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000298 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700299 setup_colorized_logging $CINDER_CONF DEFAULT "project_id" "user_id"
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000300 fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000301
john-griffithd0860cc2014-01-23 11:31:10 -0700302 if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
303 configure_cinder_driver
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000304 fi
Ian Wienand0db17132013-06-26 22:31:48 +1000305
306 if [[ is_fedora && $DISTRO =~ (rhel6) ]]; then
307 # Cinder clones are slightly larger due to some extra
308 # metadata. RHEL6 will not allow auto-extending of LV's
309 # without this, leading to clones giving hard-to-track disk
310 # I/O errors.
311 # see https://bugzilla.redhat.com/show_bug.cgi?id=975052
312 sudo sed -i~ \
313 -e 's/snapshot_autoextend_threshold =.*/snapshot_autoextend_threshold = 80/' \
314 -e 's/snapshot_autoextend_percent =.*/snapshot_autoextend_percent = 20/' \
315 /etc/lvm/lvm.conf
316 fi
Vincent Hou21fe4e72013-11-21 03:10:27 -0500317 configure_API_version $CINDER_CONF $IDENTITY_API_VERSION
stackcf2d0d32013-08-05 04:51:56 -0400318 iniset $CINDER_CONF keystone_authtoken admin_user cinder
319 iniset $CINDER_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
320 iniset $CINDER_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
Ian Wienand0db17132013-06-26 22:31:48 +1000321
Dean Troyer67787e62012-05-02 11:48:15 -0500322}
323
Dean Troyer671c16e2012-12-13 16:22:38 -0600324# create_cinder_accounts() - Set up common required cinder accounts
325
326# Tenant User Roles
327# ------------------------------------------------------------------
328# service cinder admin # if enabled
329
330# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100331function create_cinder_accounts {
Dean Troyer671c16e2012-12-13 16:22:38 -0600332
Steve Martinelli19685422014-01-24 13:02:26 -0600333 SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
334 ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
Dean Troyer671c16e2012-12-13 16:22:38 -0600335
336 # Cinder
337 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
Steve Martinelli19685422014-01-24 13:02:26 -0600338 CINDER_USER=$(openstack user create \
339 cinder \
340 --password "$SERVICE_PASSWORD" \
341 --project $SERVICE_TENANT \
342 --email cinder@example.com \
Dean Troyer671c16e2012-12-13 16:22:38 -0600343 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -0600344 openstack role add \
345 $ADMIN_ROLE \
346 --project $SERVICE_TENANT \
347 --user $CINDER_USER
Dean Troyer671c16e2012-12-13 16:22:38 -0600348 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Steve Martinelli19685422014-01-24 13:02:26 -0600349 CINDER_SERVICE=$(openstack service create \
350 cinder \
Dean Troyer671c16e2012-12-13 16:22:38 -0600351 --type=volume \
352 --description="Cinder Volume Service" \
353 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -0600354 openstack endpoint create \
355 $CINDER_SERVICE \
Dean Troyer671c16e2012-12-13 16:22:38 -0600356 --region RegionOne \
Dean Troyer560346b2012-12-13 17:05:24 -0600357 --publicurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
358 --adminurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
359 --internalurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s"
Steve Martinelli19685422014-01-24 13:02:26 -0600360 CINDER_V2_SERVICE=$(openstack service create \
361 cinderv2 \
Mike Perezb3862f92013-02-12 02:16:41 -0800362 --type=volumev2 \
363 --description="Cinder Volume Service V2" \
364 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -0600365 openstack endpoint create \
366 $CINDER_V2_SERVICE \
Mike Perezb3862f92013-02-12 02:16:41 -0800367 --region RegionOne \
Mike Perezb3862f92013-02-12 02:16:41 -0800368 --publicurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s" \
369 --adminurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s" \
370 --internalurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s"
Dean Troyer671c16e2012-12-13 16:22:38 -0600371 fi
372 fi
373}
374
Dean Troyerf03bafe2013-02-12 10:58:28 -0600375# create_cinder_cache_dir() - Part of the init_cinder() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100376function create_cinder_cache_dir {
Dean Troyerf03bafe2013-02-12 10:58:28 -0600377 # Create cache dir
378 sudo mkdir -p $CINDER_AUTH_CACHE_DIR
379 sudo chown $STACK_USER $CINDER_AUTH_CACHE_DIR
380 rm -f $CINDER_AUTH_CACHE_DIR/*
381}
382
Ian Wienandaee18c72014-02-21 15:35:08 +1100383function create_cinder_volume_group {
Attila Fazekasa6ed3dc2013-07-01 22:49:31 +0200384 # According to the ``CINDER_MULTI_LVM_BACKEND`` value, configure one or two default volumes
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100385 # group called ``stack-volumes`` (and ``stack-volumes2``) for the volume
386 # service if it (they) does (do) not yet exist. If you don't wish to use a
387 # file backed volume group, create your own volume group called ``stack-volumes``
388 # and ``stack-volumes2`` before invoking ``stack.sh``.
Dean Troyerf03bafe2013-02-12 10:58:28 -0600389 #
Attila Fazekasa6ed3dc2013-07-01 22:49:31 +0200390 # The two backing files are ``VOLUME_BACKING_FILE_SIZE`` in size, and they are stored in
391 # the ``DATA_DIR``.
Dean Troyerf03bafe2013-02-12 10:58:28 -0600392
393 if ! sudo vgs $VOLUME_GROUP; then
Mate Lakat68ac03c2013-06-06 16:22:34 +0100394 if [ -z "$VOLUME_BACKING_DEVICE" ]; then
395 # Only create if the file doesn't already exists
396 [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
397 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
Dean Troyerf03bafe2013-02-12 10:58:28 -0600398
Mate Lakat68ac03c2013-06-06 16:22:34 +0100399 # Only create if the loopback device doesn't contain $VOLUME_GROUP
400 if ! sudo vgs $VOLUME_GROUP; then
401 sudo vgcreate $VOLUME_GROUP $DEV
402 fi
403 else
404 sudo vgcreate $VOLUME_GROUP $VOLUME_BACKING_DEVICE
Dean Troyerf03bafe2013-02-12 10:58:28 -0600405 fi
406 fi
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100407 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
408 #set up the second volume if CINDER_MULTI_LVM_BACKEND is enabled
409
410 if ! sudo vgs $VOLUME_GROUP2; then
Mate Lakat68ac03c2013-06-06 16:22:34 +0100411 if [ -z "$VOLUME_BACKING_DEVICE2" ]; then
412 # Only create if the file doesn't already exists
413 [[ -f $VOLUME_BACKING_FILE2 ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE2
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100414
Mate Lakat68ac03c2013-06-06 16:22:34 +0100415 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE2`
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100416
Mate Lakat68ac03c2013-06-06 16:22:34 +0100417 # Only create if the loopback device doesn't contain $VOLUME_GROUP
418 if ! sudo vgs $VOLUME_GROUP2; then
419 sudo vgcreate $VOLUME_GROUP2 $DEV
420 fi
421 else
422 sudo vgcreate $VOLUME_GROUP2 $VOLUME_BACKING_DEVICE2
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100423 fi
424 fi
425 fi
Dean Troyerf03bafe2013-02-12 10:58:28 -0600426
427 mkdir -p $CINDER_STATE_PATH/volumes
428}
429
Dean Troyer67787e62012-05-02 11:48:15 -0500430# init_cinder() - Initialize database and volume group
Ian Wienandaee18c72014-02-21 15:35:08 +1100431function init_cinder {
Dean Troyer67787e62012-05-02 11:48:15 -0500432 # Force nova volumes off
433 NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
434
Terry Wilson428af5a2012-11-01 16:12:39 -0400435 if is_service_enabled $DATABASE_BACKENDS; then
Dean Troyerf03bafe2013-02-12 10:58:28 -0600436 # (Re)create cinder database
Terry Wilson428af5a2012-11-01 16:12:39 -0400437 recreate_database cinder utf8
Dean Troyer67787e62012-05-02 11:48:15 -0500438
Dean Troyerf03bafe2013-02-12 10:58:28 -0600439 # Migrate cinder database
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400440 $CINDER_BIN_DIR/cinder-manage db sync
Dean Troyer67787e62012-05-02 11:48:15 -0500441 fi
442
443 if is_service_enabled c-vol; then
Dean Troyer67787e62012-05-02 11:48:15 -0500444
Dean Troyerf03bafe2013-02-12 10:58:28 -0600445 create_cinder_volume_group
Chuck Short3f603d92012-07-28 13:28:33 -0500446
Dean Troyer67787e62012-05-02 11:48:15 -0500447 if sudo vgs $VOLUME_GROUP; then
Vincent Untz00011c02012-12-06 09:56:32 +0100448 if is_fedora || is_suse; then
449 # service is not started by default
Vincent Untz0230aa82012-06-14 08:51:01 +0200450 start_service tgtd
451 fi
452
Dean Troyer67787e62012-05-02 11:48:15 -0500453 # Remove iscsi targets
454 sudo tgtadm --op show --mode target | grep $VOLUME_NAME_PREFIX | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true
Dean Troyer22853c12013-01-07 15:18:12 -0600455 # Start with a clean volume group
JordanP022e9912013-07-09 14:14:48 +0200456 _clean_lvm_lv $VOLUME_GROUP $VOLUME_NAME_PREFIX
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100457 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
JordanP022e9912013-07-09 14:14:48 +0200458 _clean_lvm_lv $VOLUME_GROUP2 $VOLUME_NAME_PREFIX
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100459 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500460 fi
461 fi
Dean Troyerbc071bc2012-10-01 14:06:44 -0500462
Dean Troyerf03bafe2013-02-12 10:58:28 -0600463 create_cinder_cache_dir
Dean Troyer67787e62012-05-02 11:48:15 -0500464}
465
466# install_cinder() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100467function install_cinder {
Dean Troyer67787e62012-05-02 11:48:15 -0500468 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400469 setup_develop $CINDER_DIR
Dean Troyer253a1a32013-04-01 18:23:22 -0500470}
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400471
Dean Troyer253a1a32013-04-01 18:23:22 -0500472# install_cinderclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100473function install_cinderclient {
Dean Troyer67787e62012-05-02 11:48:15 -0500474 git_clone $CINDERCLIENT_REPO $CINDERCLIENT_DIR $CINDERCLIENT_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400475 setup_develop $CINDERCLIENT_DIR
Attila Fazekasfac533e2013-08-14 16:04:01 +0200476 sudo install -D -m 0644 -o $STACK_USER {$CINDERCLIENT_DIR/tools/,/etc/bash_completion.d/}cinder.bash_completion
Dean Troyer67787e62012-05-02 11:48:15 -0500477}
478
Steve Baker18225d92013-04-14 12:48:41 -0700479# apply config.d approach for cinder volumes directory
Ian Wienandaee18c72014-02-21 15:35:08 +1100480function _configure_tgt_for_config_d {
Steve Baker18225d92013-04-14 12:48:41 -0700481 if [[ ! -d /etc/tgt/stack.d/ ]]; then
482 sudo ln -sf $CINDER_STATE_PATH/volumes /etc/tgt/stack.d
483 echo "include /etc/tgt/stack.d/*" | sudo tee -a /etc/tgt/targets.conf
Mate Lakata39caac2012-09-03 15:45:53 +0100484 fi
485}
486
Dean Troyer67787e62012-05-02 11:48:15 -0500487# start_cinder() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100488function start_cinder {
Dean Troyer67787e62012-05-02 11:48:15 -0500489 if is_service_enabled c-vol; then
Steve Baker18225d92013-04-14 12:48:41 -0700490 # Delete any old stack.conf
491 sudo rm -f /etc/tgt/conf.d/stack.conf
Attila Fazekasb79574b2012-12-01 10:42:46 +0100492 _configure_tgt_for_config_d
Vincent Untzc18b9652012-12-04 12:36:34 +0100493 if is_ubuntu; then
Dean Troyer67787e62012-05-02 11:48:15 -0500494 # tgt in oneiric doesn't restart properly if tgtd isn't running
495 # do it in two steps
496 sudo stop tgt || true
497 sudo start tgt
Vincent Untz00011c02012-12-06 09:56:32 +0100498 elif is_fedora; then
Ian Wienand3b578292014-02-26 14:52:02 +1100499 if [[ $DISTRO =~ (rhel6) ]]; then
500 sudo /sbin/service tgtd restart
501 else
502 # bypass redirection to systemctl during restart
503 sudo /sbin/service --skip-redirect tgtd restart
504 fi
Vincent Untz00011c02012-12-06 09:56:32 +0100505 elif is_suse; then
506 restart_service tgtd
507 else
508 # note for other distros: unstack.sh also uses the tgt/tgtd service
509 # name, and would need to be adjusted too
510 exit_distro_not_supported "restarting tgt"
Dean Troyer67787e62012-05-02 11:48:15 -0500511 fi
Giulio Fidente384454d2013-09-27 13:17:34 +0200512 # NOTE(gfidente): ensure tgtd is running in debug mode
513 sudo tgtadm --mode system --op update --name debug --value on
Dean Troyer67787e62012-05-02 11:48:15 -0500514 fi
515
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400516 screen_it c-api "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400517 screen_it c-sch "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
Stephen Mulcahy67068ef2013-02-21 11:20:58 +0000518 screen_it c-bak "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF"
John Griffithe6d4fe52013-07-15 17:35:54 -0600519 screen_it c-vol "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
520
521 # NOTE(jdg): For cinder, startup order matters. To ensure that repor_capabilities is received
522 # by the scheduler start the cinder-volume service last (or restart it) after the scheduler
523 # has started. This is a quick fix for lp bug/1189595
Dean Troyer560346b2012-12-13 17:05:24 -0600524
525 # Start proxies if enabled
526 if is_service_enabled c-api && is_service_enabled tls-proxy; then
527 start_tls_proxy '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT &
528 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500529}
530
Dean Troyer699a29f2012-09-10 14:10:27 -0500531# stop_cinder() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100532function stop_cinder {
Dean Troyer699a29f2012-09-10 14:10:27 -0500533 # Kill the cinder screen windows
Stephen Mulcahy67068ef2013-02-21 11:20:58 +0000534 for serv in c-api c-bak c-sch c-vol; do
Dean Troyer9fc87922013-05-22 17:19:06 -0500535 screen_stop $serv
Dean Troyer699a29f2012-09-10 14:10:27 -0500536 done
Dean Troyer67787e62012-05-02 11:48:15 -0500537
538 if is_service_enabled c-vol; then
Vincent Untz90dd96d2012-12-13 08:59:57 +0100539 if is_ubuntu; then
540 stop_service tgt
541 else
542 stop_service tgtd
543 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500544 fi
545}
Dean Troyer7903b792012-09-13 17:16:12 -0500546
Dean Troyercc6b4432013-04-08 15:38:03 -0500547
Dean Troyer7903b792012-09-13 17:16:12 -0500548# Restore xtrace
549$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400550
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100551# Tell emacs to use shell-script-mode
552## Local variables:
553## mode: shell-script
554## End: