blob: 8c5aa5e4e878c9b2d4aa3bdc3fb762b1c64cd610 [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
Attila Fazekasece6a332012-11-29 14:19:41 +01003# lib/swift
Dean Troyer6d04fd72012-12-21 11:03:37 -06004# Functions to control the configuration and operation of the **Swift** service
Attila Fazekasece6a332012-11-29 14:19:41 +01005
6# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01007#
8# - ``functions`` file
9# - ``apache`` file
10# - ``DEST``, ``SCREEN_NAME``, `SWIFT_HASH` must be defined
11# - ``STACK_USER`` must be defined
12# - ``SWIFT_DATA_DIR`` or ``DATA_DIR`` must be defined
13# - ``lib/keystone`` file
14#
Attila Fazekasece6a332012-11-29 14:19:41 +010015# ``stack.sh`` calls the entry points in this order:
16#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010017# - install_swift
18# - _config_swift_apache_wsgi
19# - configure_swift
20# - init_swift
21# - start_swift
22# - stop_swift
23# - cleanup_swift
24# - _cleanup_swift_apache_wsgi
Attila Fazekasece6a332012-11-29 14:19:41 +010025
26# Save trace setting
Ian Wienand523f4882015-10-13 11:03:03 +110027_XTRACE_LIB_SWIFT=$(set +o | grep xtrace)
Attila Fazekasece6a332012-11-29 14:19:41 +010028set +o xtrace
29
30
31# Defaults
32# --------
33
Rob Crittenden18d47782014-03-19 17:47:42 -040034if is_ssl_enabled_service "s-proxy" || is_service_enabled tls-proxy; then
35 SWIFT_SERVICE_PROTOCOL="https"
36fi
37
Attila Fazekasece6a332012-11-29 14:19:41 +010038# Set up default directories
Sean Daguee08ab102014-11-13 17:09:28 -050039GITDIR["python-swiftclient"]=$DEST/python-swiftclient
Sean Dague5cb19062014-11-01 01:37:45 +010040
Attila Fazekasece6a332012-11-29 14:19:41 +010041SWIFT_DIR=$DEST/swift
Dean Troyer64ab7742012-12-28 15:38:28 -060042SWIFT_AUTH_CACHE_DIR=${SWIFT_AUTH_CACHE_DIR:-/var/cache/swift}
zhang-hared98a5d02013-06-21 18:18:02 +080043SWIFT_APACHE_WSGI_DIR=${SWIFT_APACHE_WSGI_DIR:-/var/www/swift}
Dean Troyerb7490da2013-03-18 16:07:56 -050044SWIFT3_DIR=$DEST/swift3
Attila Fazekasece6a332012-11-29 14:19:41 +010045
Rob Crittenden18d47782014-03-19 17:47:42 -040046SWIFT_SERVICE_PROTOCOL=${SWIFT_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
Falk Reimann22f747b2015-08-28 12:40:19 +020047SWIFT_DEFAULT_BIND_PORT=${SWIFT_DEFAULT_BIND_PORT:-8080}
Rob Crittenden18d47782014-03-19 17:47:42 -040048SWIFT_DEFAULT_BIND_PORT_INT=${SWIFT_DEFAULT_BIND_PORT_INT:-8081}
Brian Haley180f5eb2015-06-16 13:14:31 -040049SWIFT_SERVICE_LOCAL_HOST=${SWIFT_SERVICE_LOCAL_HOST:-$SERVICE_LOCAL_HOST}
Rawlin Peters92ad1522015-07-20 13:33:33 -060050SWIFT_SERVICE_LISTEN_ADDRESS=${SWIFT_SERVICE_LISTEN_ADDRESS:-$SERVICE_LISTEN_ADDRESS}
Rob Crittenden18d47782014-03-19 17:47:42 -040051
Attila Fazekasece6a332012-11-29 14:19:41 +010052# TODO: add logging to different location.
53
54# Set ``SWIFT_DATA_DIR`` to the location of swift drives and objects.
55# Default is the common DevStack data directory.
56SWIFT_DATA_DIR=${SWIFT_DATA_DIR:-${DATA_DIR}/swift}
Attila Fazekase6024412013-09-15 18:38:48 +020057SWIFT_DISK_IMAGE=${SWIFT_DATA_DIR}/drives/images/swift.img
Attila Fazekasece6a332012-11-29 14:19:41 +010058
Dean Troyer6ec72fa2013-03-13 11:44:53 -050059# Set ``SWIFT_CONF_DIR`` to the location of the configuration files.
Attila Fazekasece6a332012-11-29 14:19:41 +010060# Default is ``/etc/swift``.
JordanPa6dfe812014-11-20 18:06:23 +010061SWIFT_CONF_DIR=${SWIFT_CONF_DIR:-/etc/swift}
Attila Fazekasece6a332012-11-29 14:19:41 +010062
Dean Troyerb7490da2013-03-18 16:07:56 -050063if is_service_enabled s-proxy && is_service_enabled swift3; then
Dean Troyerdc97cb72015-03-28 08:20:50 -050064 # If we are using ``swift3``, we can default the S3 port to swift instead
Dean Troyerb7490da2013-03-18 16:07:56 -050065 # of nova-objectstore
Falk Reimann22f747b2015-08-28 12:40:19 +020066 S3_SERVICE_PORT=${S3_SERVICE_PORT:-$SWIFT_DEFAULT_BIND_PORT}
Dean Troyerb7490da2013-03-18 16:07:56 -050067fi
68
Ivan Kolodyazhny9ebd65b2015-03-08 23:51:55 +020069if is_service_enabled g-api; then
70 # Minimum Cinder volume size is 1G so if Swift backend for Glance is
71 # only 1G we can not upload volume to image.
72 # Increase Swift disk size up to 2G
73 SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=2G
Matthew Oliver7b857232016-03-07 18:21:29 +110074 SWIFT_MAX_FILE_SIZE_DEFAULT=1073741824 # 1G
Ivan Kolodyazhny9ebd65b2015-03-08 23:51:55 +020075else
76 # DevStack will create a loop-back disk formatted as XFS to store the
77 # swift data. Set ``SWIFT_LOOPBACK_DISK_SIZE`` to the disk size in
78 # kilobytes.
79 # Default is 1 gigabyte.
80 SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=1G
Matthew Oliver7b857232016-03-07 18:21:29 +110081 SWIFT_MAX_FILE_SIZE_DEFAULT=536870912 # 512M
Ivan Kolodyazhny9ebd65b2015-03-08 23:51:55 +020082fi
83
Joe Gordon66c54242013-11-12 16:24:14 -080084# if tempest enabled the default size is 6 Gigabyte.
Attila Fazekas3418c1c2013-09-16 18:35:49 +020085if is_service_enabled tempest; then
Joe Gordon66c54242013-11-12 16:24:14 -080086 SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=${SWIFT_LOOPBACK_DISK_SIZE:-6G}
Matthew Oliver7b857232016-03-07 18:21:29 +110087 SWIFT_MAX_FILE_SIZE_DEFAULT=5368709122 # Swift default 5G
Attila Fazekas3418c1c2013-09-16 18:35:49 +020088fi
89
90SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-$SWIFT_LOOPBACK_DISK_SIZE_DEFAULT}
Attila Fazekasece6a332012-11-29 14:19:41 +010091
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010092# Set ``SWIFT_EXTRAS_MIDDLEWARE`` to extras middlewares.
Samuel Merrittf19ccb62014-03-08 07:54:05 -080093# Default is ``staticweb, formpost``
94SWIFT_EXTRAS_MIDDLEWARE=${SWIFT_EXTRAS_MIDDLEWARE:-formpost staticweb}
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010095
Cyril Roelandtd9883402013-09-27 15:16:51 +000096# Set ``SWIFT_EXTRAS_MIDDLEWARE_LAST`` to extras middlewares that need to be at
97# the end of the pipeline.
Sean Dague53753292014-12-04 19:38:15 -050098SWIFT_EXTRAS_MIDDLEWARE_LAST=${SWIFT_EXTRAS_MIDDLEWARE_LAST:-}
Cyril Roelandtd9883402013-09-27 15:16:51 +000099
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200100# Set ``SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH`` to extras middlewares that need to be at
101# the beginning of the pipeline, before authentication middlewares.
102SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH=${SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH:-crossdomain}
103
Marian Horbanea21eb42015-08-18 06:57:18 -0400104# The ring uses a configurable number of bits from a path's MD5 hash as
Attila Fazekasece6a332012-11-29 14:19:41 +0100105# a partition index that designates a device. The number of bits kept
106# from the hash is known as the partition power, and 2 to the partition
107# power indicates the partition count. Partitioning the full MD5 hash
108# ring allows other parts of the cluster to work in batches of items at
109# once which ends up either more efficient or at least less complex than
110# working with each item separately or the entire cluster all at once.
111# By default we define 9 for the partition count (which mean 512).
112SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9}
113
114# Set ``SWIFT_REPLICAS`` to configure how many replicas are to be
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100115# configured for your Swift cluster. By default we are configuring
116# only one replica since this is way less CPU and memory intensive. If
117# you are planning to test swift replication you may want to set this
118# up to 3.
119SWIFT_REPLICAS=${SWIFT_REPLICAS:-1}
Attila Fazekasece6a332012-11-29 14:19:41 +0100120SWIFT_REPLICAS_SEQ=$(seq ${SWIFT_REPLICAS})
121
Peter Portantecee4b3b2013-11-20 14:33:16 -0500122# Set ``SWIFT_LOG_TOKEN_LENGTH`` to configure how many characters of an auth
123# token should be placed in the logs. When keystone is used with PKI tokens,
124# the token values can be huge, seemingly larger the 2K, at the least. We
125# restrict it here to a default of 12 characters, which should be enough to
126# trace through the logs when looking for its use.
127SWIFT_LOG_TOKEN_LENGTH=${SWIFT_LOG_TOKEN_LENGTH:-12}
128
Atsushi SAKAIfe7b56c2015-11-13 17:06:16 +0900129# Set ``SWIFT_MAX_HEADER_SIZE`` to configure the maximum length of headers in
Julien Vey63024d92014-05-06 15:10:07 +0200130# Swift API
131SWIFT_MAX_HEADER_SIZE=${SWIFT_MAX_HEADER_SIZE:-16384}
132
Matthew Oliver7b857232016-03-07 18:21:29 +1100133# Set ``SWIFT_MAX_FILE_SIZE`` to configure the maximum file size in Swift API
134# Default 500MB because the loopback file used for swift could be 1 or 2 GB
135SWIFT_MAX_FILE_SIZE=${SWIFT_MAX_FILE_SIZE:-$SWIFT_MAX_FILE_SIZE_DEFAULT}
136
Attila Fazekasece6a332012-11-29 14:19:41 +0100137# Set ``OBJECT_PORT_BASE``, ``CONTAINER_PORT_BASE``, ``ACCOUNT_PORT_BASE``
Atsushi SAKAIfe7b56c2015-11-13 17:06:16 +0900138# Port bases used in port number calculation for the service "nodes"
139# The specified port number will be used, the additional ports calculated by
Attila Fazekasece6a332012-11-29 14:19:41 +0100140# base_port + node_num * 10
Denis Afonsodbe08682015-10-02 23:51:41 -0400141OBJECT_PORT_BASE=${OBJECT_PORT_BASE:-6613}
142CONTAINER_PORT_BASE=${CONTAINER_PORT_BASE:-6611}
143ACCOUNT_PORT_BASE=${ACCOUNT_PORT_BASE:-6612}
Attila Fazekasece6a332012-11-29 14:19:41 +0100144
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000145# Enable tempurl feature
146SWIFT_ENABLE_TEMPURLS=${SWIFT_ENABLE_TEMPURLS:-False}
Sean Dague53753292014-12-04 19:38:15 -0500147SWIFT_TEMPURL_KEY=${SWIFT_TEMPURL_KEY:-}
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000148
Dean Troyerdc97cb72015-03-28 08:20:50 -0500149# Toggle for deploying Swift under HTTPD + mod_wsgi
150SWIFT_USE_MOD_WSGI=${SWIFT_USE_MOD_WSGI:-False}
151
Dean Troyercc6b4432013-04-08 15:38:03 -0500152# Functions
153# ---------
Attila Fazekasece6a332012-11-29 14:19:41 +0100154
Dean Troyere4fa7212014-01-15 15:04:49 -0600155# Test if any Swift services are enabled
156# is_swift_enabled
157function is_swift_enabled {
158 [[ ,${ENABLED_SERVICES} =~ ,"s-" ]] && return 0
159 return 1
160}
161
Attila Fazekasece6a332012-11-29 14:19:41 +0100162# cleanup_swift() - Remove residual data files
Ian Wienandaee18c72014-02-21 15:35:08 +1100163function cleanup_swift {
Sean Dague101b4242013-10-22 08:47:11 -0400164 rm -f ${SWIFT_CONF_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz}
165 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
166 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
167 fi
168 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
169 rm ${SWIFT_DISK_IMAGE}
170 fi
171 rm -rf ${SWIFT_DATA_DIR}/run/
Morgan Fainberg46455a32014-06-20 10:37:18 -0700172 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
Sean Dague101b4242013-10-22 08:47:11 -0400173 _cleanup_swift_apache_wsgi
174 fi
zhang-hared98a5d02013-06-21 18:18:02 +0800175}
176
177# _cleanup_swift_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
Ian Wienandaee18c72014-02-21 15:35:08 +1100178function _cleanup_swift_apache_wsgi {
zhang-hared98a5d02013-06-21 18:18:02 +0800179 sudo rm -f $SWIFT_APACHE_WSGI_DIR/*.wsgi
Jamie Lennox54707012013-09-17 12:07:48 +1000180 disable_apache_site proxy-server
Dean Troyer084f51f2014-07-25 15:08:52 -0500181 local node_number type
zhang-hared98a5d02013-06-21 18:18:02 +0800182 for node_number in ${SWIFT_REPLICAS_SEQ}; do
183 for type in object container account; do
Dean Troyer084f51f2014-07-25 15:08:52 -0500184 local site_name=${type}-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000185 disable_apache_site ${site_name}
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000186 sudo rm -f $(apache_site_config_for ${site_name})
zhang-hared98a5d02013-06-21 18:18:02 +0800187 done
188 done
189}
190
191# _config_swift_apache_wsgi() - Set WSGI config files of Swift
Ian Wienandaee18c72014-02-21 15:35:08 +1100192function _config_swift_apache_wsgi {
zhang-hared98a5d02013-06-21 18:18:02 +0800193 sudo mkdir -p ${SWIFT_APACHE_WSGI_DIR}
Falk Reimann22f747b2015-08-28 12:40:19 +0200194 local proxy_port=${SWIFT_DEFAULT_BIND_PORT}
zhang-hared98a5d02013-06-21 18:18:02 +0800195
196 # copy proxy vhost and wsgi file
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000197 sudo cp ${SWIFT_DIR}/examples/apache2/proxy-server.template $(apache_site_config_for proxy-server)
zhang-hared98a5d02013-06-21 18:18:02 +0800198 sudo sed -e "
199 /^#/d;/^$/d;
200 s/%PORT%/$proxy_port/g;
201 s/%SERVICENAME%/proxy-server/g;
202 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000203 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000204 " -i $(apache_site_config_for proxy-server)
Jamie Lennox54707012013-09-17 12:07:48 +1000205 enable_apache_site proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800206
207 sudo cp ${SWIFT_DIR}/examples/wsgi/proxy-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
208 sudo sed -e "
209 /^#/d;/^$/d;
210 s/%SERVICECONF%/proxy-server.conf/g;
211 " -i ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800212
213 # copy apache vhost file and set name and port
Dean Troyer084f51f2014-07-25 15:08:52 -0500214 local node_number
zhang-hared98a5d02013-06-21 18:18:02 +0800215 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Ian Wienandada886d2015-10-07 14:06:26 +1100216 local object_port
217 object_port=$(( OBJECT_PORT_BASE + 10 * (node_number - 1) ))
218 local container_port
219 container_port=$(( CONTAINER_PORT_BASE + 10 * (node_number - 1) ))
220 local account_port
221 account_port=$(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) ))
zhang-hared98a5d02013-06-21 18:18:02 +0800222
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000223 sudo cp ${SWIFT_DIR}/examples/apache2/object-server.template $(apache_site_config_for object-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800224 sudo sed -e "
225 s/%PORT%/$object_port/g;
226 s/%SERVICENAME%/object-server-${node_number}/g;
227 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000228 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000229 " -i $(apache_site_config_for object-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000230 enable_apache_site object-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800231
232 sudo cp ${SWIFT_DIR}/examples/wsgi/object-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
233 sudo sed -e "
234 /^#/d;/^$/d;
235 s/%SERVICECONF%/object-server\/${node_number}.conf/g;
236 " -i ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
237
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000238 sudo cp ${SWIFT_DIR}/examples/apache2/container-server.template $(apache_site_config_for container-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800239 sudo sed -e "
240 /^#/d;/^$/d;
241 s/%PORT%/$container_port/g;
242 s/%SERVICENAME%/container-server-${node_number}/g;
243 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000244 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000245 " -i $(apache_site_config_for container-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000246 enable_apache_site container-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800247
248 sudo cp ${SWIFT_DIR}/examples/wsgi/container-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
249 sudo sed -e "
250 /^#/d;/^$/d;
251 s/%SERVICECONF%/container-server\/${node_number}.conf/g;
252 " -i ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
253
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000254 sudo cp ${SWIFT_DIR}/examples/apache2/account-server.template $(apache_site_config_for account-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800255 sudo sed -e "
Sean Dague101b4242013-10-22 08:47:11 -0400256 /^#/d;/^$/d;
zhang-hared98a5d02013-06-21 18:18:02 +0800257 s/%PORT%/$account_port/g;
258 s/%SERVICENAME%/account-server-${node_number}/g;
259 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000260 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000261 " -i $(apache_site_config_for account-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000262 enable_apache_site account-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800263
264 sudo cp ${SWIFT_DIR}/examples/wsgi/account-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
265 sudo sed -e "
Sean Dague101b4242013-10-22 08:47:11 -0400266 /^#/d;/^$/d;
zhang-hared98a5d02013-06-21 18:18:02 +0800267 s/%SERVICECONF%/account-server\/${node_number}.conf/g;
268 " -i ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800269 done
Attila Fazekasece6a332012-11-29 14:19:41 +0100270}
271
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100272# This function generates an object/container/account configuration
273# emulating 4 nodes on different ports
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200274function generate_swift_config_services {
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100275 local swift_node_config=$1
276 local node_id=$2
277 local bind_port=$3
278 local server_type=$4
279
Ian Wienand761c4562014-10-21 11:41:37 +1100280 log_facility=$(( node_id - 1 ))
Dean Troyer084f51f2014-07-25 15:08:52 -0500281 local node_path=${SWIFT_DATA_DIR}/${node_number}
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100282
283 iniuncomment ${swift_node_config} DEFAULT user
284 iniset ${swift_node_config} DEFAULT user ${STACK_USER}
285
286 iniuncomment ${swift_node_config} DEFAULT bind_port
287 iniset ${swift_node_config} DEFAULT bind_port ${bind_port}
288
289 iniuncomment ${swift_node_config} DEFAULT swift_dir
290 iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR}
291
292 iniuncomment ${swift_node_config} DEFAULT devices
293 iniset ${swift_node_config} DEFAULT devices ${node_path}
294
295 iniuncomment ${swift_node_config} DEFAULT log_facility
296 iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility}
297
298 iniuncomment ${swift_node_config} DEFAULT workers
Chmouel Boudjnah55dc2c22014-09-12 09:34:20 +0200299 iniset ${swift_node_config} DEFAULT workers ${API_WORKERS:-1}
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100300
301 iniuncomment ${swift_node_config} DEFAULT disable_fallocate
302 iniset ${swift_node_config} DEFAULT disable_fallocate true
303
304 iniuncomment ${swift_node_config} DEFAULT mount_check
305 iniset ${swift_node_config} DEFAULT mount_check false
306
307 iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode
308 iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200309
310 # Using a sed and not iniset/iniuncomment because we want to a global
311 # modification and make sure it works for new sections.
312 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100313}
314
Attila Fazekasece6a332012-11-29 14:19:41 +0100315# configure_swift() - Set config files, create data dirs and loop image
Ian Wienandaee18c72014-02-21 15:35:08 +1100316function configure_swift {
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200317 local swift_pipeline="${SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH}"
Attila Fazekasece6a332012-11-29 14:19:41 +0100318 local node_number
319 local swift_node_config
320 local swift_log_dir
Geronimo Orozco2f6576b2015-03-19 12:08:23 -0600321 local user_group
Attila Fazekasece6a332012-11-29 14:19:41 +0100322
Attila Fazekasece6a332012-11-29 14:19:41 +0100323 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100324 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100325
Dean Troyer8421c2b2015-03-16 13:52:19 -0500326 sudo install -d -o ${STACK_USER} ${SWIFT_CONF_DIR}
327 sudo install -d -o ${STACK_USER} ${SWIFT_CONF_DIR}/{object,container,account}-server
Attila Fazekasece6a332012-11-29 14:19:41 +0100328
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500329 if [[ "$SWIFT_CONF_DIR" != "/etc/swift" ]]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100330 # Some swift tools are hard-coded to use ``/etc/swift`` and are apparently not going to be fixed.
331 # Create a symlink if the config dir is moved
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500332 sudo ln -sf ${SWIFT_CONF_DIR} /etc/swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100333 fi
334
335 # Swift use rsync to synchronize between all the different
336 # partitions (which make more sense when you have a multi-node
337 # setup) we configure it with our version of rsync.
338 sed -e "
339 s/%GROUP%/${USER_GROUP}/;
Stephan Renatuse578eff2013-11-19 13:31:04 +0100340 s/%USER%/${STACK_USER}/;
Attila Fazekasece6a332012-11-29 14:19:41 +0100341 s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,;
342 " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf
343 # rsyncd.conf just prepared for 4 nodes
Vincent Untzc18b9652012-12-04 12:36:34 +0100344 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100345 sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync
Attila Fazekas0e57b962014-02-28 09:09:52 +0100346 elif [ -e /etc/xinetd.d/rsync ]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100347 sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync
348 fi
349
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500350 SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONF_DIR}/proxy-server.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100351 cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER}
352
Daisuke Moritad03915f2014-10-08 06:52:21 +0000353 # To run container sync feature introduced in Swift ver 1.12.0,
354 # container sync "realm" is added in container-sync-realms.conf
355 local csyncfile=${SWIFT_CONF_DIR}/container-sync-realms.conf
356 cp ${SWIFT_DIR}/etc/container-sync-realms.conf-sample ${csyncfile}
357 iniset ${csyncfile} realm1 key realm1key
Falk Reimann22f747b2015-08-28 12:40:19 +0200358 iniset ${csyncfile} realm1 cluster_name1 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:$SWIFT_DEFAULT_BIND_PORT/v1/"
Chmouel Boudjnahf2c1a712014-01-29 21:38:14 +0000359
Attila Fazekasece6a332012-11-29 14:19:41 +0100360 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user
Stephan Renatuse578eff2013-11-19 13:31:04 +0100361 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${STACK_USER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100362
363 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500364 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100365
366 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers
367 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1
368
369 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level
370 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG
371
Rawlin Peters92ad1522015-07-20 13:33:33 -0600372 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_ip
373 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_ip ${SWIFT_SERVICE_LISTEN_ADDRESS}
374
Attila Fazekasece6a332012-11-29 14:19:41 +0100375 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port
Rob Crittenden18d47782014-03-19 17:47:42 -0400376 if is_service_enabled tls-proxy; then
377 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT_INT}
378 else
Falk Reimann22f747b2015-08-28 12:40:19 +0200379 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT}
Rob Crittenden18d47782014-03-19 17:47:42 -0400380 fi
381
382 if is_ssl_enabled_service s-proxy; then
383 ensure_certificates SWIFT
384
385 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT cert_file "$SWIFT_SSL_CERT"
386 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT key_file "$SWIFT_SSL_KEY"
387 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100388
Dean Troyerdc97cb72015-03-28 08:20:50 -0500389 # DevStack is commonly run in a small slow environment, so bump the timeouts up.
390 # ``node_timeout`` is the node read operation response time to the proxy server
391 # ``conn_timeout`` is how long it takes a connect() system call to return
Joe Gordond254da52013-11-19 21:06:29 -0800392 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server node_timeout 120
393 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server conn_timeout 20
394
Dina Belovaeedfdee2014-06-24 16:52:46 +0400395 # Configure Ceilometer
396 if is_service_enabled ceilometer; then
397 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer "set log_level" "WARN"
gordon chungb6197e62015-02-12 15:33:35 -0500398 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer paste.filter_factory "ceilometermiddleware.swift:filter_factory"
399 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer control_exchange "swift"
400 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer url $(get_transport_url)
401 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer driver "messaging"
402 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer topic "notifications"
Dina Belovaeedfdee2014-06-24 16:52:46 +0400403 SWIFT_EXTRAS_MIDDLEWARE_LAST="${SWIFT_EXTRAS_MIDDLEWARE_LAST} ceilometer"
404 fi
Cyril Roelandtd9883402013-09-27 15:16:51 +0000405
Dean Troyerdc97cb72015-03-28 08:20:50 -0500406 # Restrict the length of auth tokens in the Swift ``proxy-server`` logs.
Peter Portantecee4b3b2013-11-20 14:33:16 -0500407 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:proxy-logging reveal_sensitive_prefix ${SWIFT_LOG_TOKEN_LENGTH}
408
Dean Troyerdc97cb72015-03-28 08:20:50 -0500409 # By default Swift will be installed with Keystone and tempauth middleware
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000410 # and add the swift3 middleware if its configured for it. The token for
Adam Spierscb961592013-10-05 12:11:07 +0100411 # tempauth would be prefixed with the reseller_prefix setting `TEMPAUTH_` the
412 # token for keystoneauth would have the standard reseller_prefix `AUTH_`
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000413 if is_service_enabled swift3;then
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200414 swift_pipeline+=" swift3 s3token "
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100415 fi
Chmouel Boudjnah254fd552014-06-30 12:22:59 +0000416
Dean Troyer5ce44cd2015-02-12 22:18:33 -0600417 if is_service_enabled keystone; then
Chmouel Boudjnah254fd552014-06-30 12:22:59 +0000418 swift_pipeline+=" authtoken keystoneauth"
419 fi
420 swift_pipeline+=" tempauth "
421
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100422 sed -i "/^pipeline/ { s/tempauth/${swift_pipeline} ${SWIFT_EXTRAS_MIDDLEWARE}/ ;}" ${SWIFT_CONFIG_PROXY_SERVER}
Cyril Roelandtd9883402013-09-27 15:16:51 +0000423 sed -i "/^pipeline/ { s/proxy-server/${SWIFT_EXTRAS_MIDDLEWARE_LAST} proxy-server/ ; }" ${SWIFT_CONFIG_PROXY_SERVER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100424
425 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true
426
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200427 # Configure Crossdomain
428 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:crossdomain use "egg:swift#crossdomain"
429
Dean Troyerdc97cb72015-03-28 08:20:50 -0500430 # Configure authtoken middleware to use the same Python logging
431 # adapter provided by the Swift ``proxy-server``, so that request transaction
Peter Portante8afc8932013-11-20 17:34:39 -0500432 # IDs will included in all of its log messages.
433 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken log_name swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100434
Jamie Lennox38c95b82015-01-30 02:15:42 +0000435 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken paste.filter_factory keystonemiddleware.auth_token:filter_factory
Jamie Lennox6ac97de2015-03-12 09:03:28 +1100436 configure_auth_token_middleware $SWIFT_CONFIG_PROXY_SERVER swift $SWIFT_AUTH_CACHE_DIR filter:authtoken
Jamie Lennox38c95b82015-01-30 02:15:42 +0000437 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken delay_auth_decision 1
438 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken cache swift.cache
439 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken include_service_catalog False
440
441 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use "egg:swift#keystoneauth"
Attila Fazekasece6a332012-11-29 14:19:41 +0100442 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin"
443
Dean Troyerdc97cb72015-03-28 08:20:50 -0500444 # Configure Tempauth. In the sample config file Keystoneauth is commented
Donagh McCabe7faceb62014-12-19 13:20:45 +0000445 # out. Make sure we uncomment Tempauth after we uncomment Keystoneauth
446 # otherwise, this code also sets the reseller_prefix for Keystoneauth.
447 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth account_autocreate
448 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix
449 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix "TEMPAUTH"
450
Attila Fazekasece6a332012-11-29 14:19:41 +0100451 if is_service_enabled swift3; then
452 cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100453[filter:s3token]
Cyril Roelandte8a2fa42015-05-06 17:30:48 +0200454paste.filter_factory = keystonemiddleware.s3_token:filter_factory
Attila Fazekasece6a332012-11-29 14:19:41 +0100455auth_port = ${KEYSTONE_AUTH_PORT}
456auth_host = ${KEYSTONE_AUTH_HOST}
457auth_protocol = ${KEYSTONE_AUTH_PROTOCOL}
Rob Crittenden18d47782014-03-19 17:47:42 -0400458cafile = ${SSL_BUNDLE_FILE}
Attila Fazekasfbb3e772015-03-03 15:08:28 +0100459admin_user = swift
Sean Dague7580a0c2016-02-17 06:23:36 -0500460admin_tenant_name = ${SERVICE_PROJECT_NAME}
Attila Fazekasfbb3e772015-03-03 15:08:28 +0100461admin_password = ${SERVICE_PASSWORD}
Attila Fazekasece6a332012-11-29 14:19:41 +0100462
463[filter:swift3]
464use = egg:swift3#swift3
Andrey Pavlov9b21f982015-08-20 23:37:04 +0300465location = ${REGION_NAME}
Attila Fazekasece6a332012-11-29 14:19:41 +0100466EOF
467 fi
468
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500469 cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf
470 iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH}
Julien Vey63024d92014-05-06 15:10:07 +0200471 iniset ${SWIFT_CONF_DIR}/swift.conf swift-constraints max_header_size ${SWIFT_MAX_HEADER_SIZE}
Matthew Oliver7b857232016-03-07 18:21:29 +1100472 iniset ${SWIFT_CONF_DIR}/swift.conf swift-constraints max_file_size ${SWIFT_MAX_FILE_SIZE}
Attila Fazekasece6a332012-11-29 14:19:41 +0100473
Dean Troyer084f51f2014-07-25 15:08:52 -0500474 local node_number
Attila Fazekasece6a332012-11-29 14:19:41 +0100475 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Dean Troyer084f51f2014-07-25 15:08:52 -0500476 local swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100477 cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config}
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200478 generate_swift_config_services ${swift_node_config} ${node_number} $(( OBJECT_PORT_BASE + 10 * (node_number - 1) )) object
Rawlin Peters92ad1522015-07-20 13:33:33 -0600479 iniuncomment ${swift_node_config} DEFAULT bind_ip
480 iniset ${swift_node_config} DEFAULT bind_ip ${SWIFT_SERVICE_LISTEN_ADDRESS}
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000481 iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache
Attila Fazekasece6a332012-11-29 14:19:41 +0100482
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500483 swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100484 cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config}
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200485 generate_swift_config_services ${swift_node_config} ${node_number} $(( CONTAINER_PORT_BASE + 10 * (node_number - 1) )) container
Rawlin Peters92ad1522015-07-20 13:33:33 -0600486 iniuncomment ${swift_node_config} DEFAULT bind_ip
487 iniset ${swift_node_config} DEFAULT bind_ip ${SWIFT_SERVICE_LISTEN_ADDRESS}
Attila Fazekas83e10952012-11-30 23:28:07 +0100488 iniuncomment ${swift_node_config} app:container-server allow_versions
489 iniset ${swift_node_config} app:container-server allow_versions "true"
Attila Fazekasece6a332012-11-29 14:19:41 +0100490
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500491 swift_node_config=${SWIFT_CONF_DIR}/account-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100492 cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config}
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200493 generate_swift_config_services ${swift_node_config} ${node_number} $(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) )) account
Rawlin Peters92ad1522015-07-20 13:33:33 -0600494 iniuncomment ${swift_node_config} DEFAULT bind_ip
495 iniset ${swift_node_config} DEFAULT bind_ip ${SWIFT_SERVICE_LISTEN_ADDRESS}
Attila Fazekasece6a332012-11-29 14:19:41 +0100496 done
497
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000498 # Set new accounts in tempauth to match keystone tenant/user (to make testing easier)
499 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest1 "testing .admin"
500 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest2_swiftusertest2 "testing2 .admin"
501 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest3 "testing3 .admin"
502
503 testfile=${SWIFT_CONF_DIR}/test.conf
504 cp ${SWIFT_DIR}/test/sample.conf ${testfile}
505
506 # Set accounts for functional tests
507 iniset ${testfile} func_test account swifttenanttest1
508 iniset ${testfile} func_test username swiftusertest1
509 iniset ${testfile} func_test username3 swiftusertest3
510 iniset ${testfile} func_test account2 swifttenanttest2
511 iniset ${testfile} func_test username2 swiftusertest2
Alistair Coles24779f62014-10-15 18:57:59 +0100512 iniset ${testfile} func_test account4 swifttenanttest4
513 iniset ${testfile} func_test username4 swiftusertest4
514 iniset ${testfile} func_test password4 testing4
515 iniset ${testfile} func_test domain4 swift_test
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000516
Dean Troyer5ce44cd2015-02-12 22:18:33 -0600517 if is_service_enabled keystone; then
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000518 iniuncomment ${testfile} func_test auth_version
Ian Wienandada886d2015-10-07 14:06:26 +1100519 local auth_vers
520 auth_vers=$(iniget ${testfile} func_test auth_version)
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000521 iniset ${testfile} func_test auth_host ${KEYSTONE_SERVICE_HOST}
522 iniset ${testfile} func_test auth_port ${KEYSTONE_AUTH_PORT}
Alistair Coles24779f62014-10-15 18:57:59 +0100523 if [[ $auth_vers == "3" ]]; then
524 iniset ${testfile} func_test auth_prefix /v3/
525 else
526 iniset ${testfile} func_test auth_prefix /v2.0/
527 fi
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000528 fi
529
Ian Wienandada886d2015-10-07 14:06:26 +1100530 local user_group
531 user_group=$(id -g ${STACK_USER})
Geronimo Orozco2f6576b2015-03-19 12:08:23 -0600532 sudo install -d -o ${STACK_USER} -g ${user_group} ${SWIFT_DATA_DIR}
533
Dean Troyer084f51f2014-07-25 15:08:52 -0500534 local swift_log_dir=${SWIFT_DATA_DIR}/logs
Geronimo Orozco2f6576b2015-03-19 12:08:23 -0600535 sudo rm -rf ${swift_log_dir}
536 sudo install -d -o ${STACK_USER} -g adm ${swift_log_dir}/hourly
Yves-Gwenael Bourhisf894c2a2014-04-16 13:37:46 +0200537
538 if [[ $SYSLOG != "False" ]]; then
539 sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
540 tee /etc/rsyslog.d/10-swift.conf
541 # restart syslog to take the changes
542 sudo killall -HUP rsyslogd
543 fi
Sean Daguead7e8c62014-03-19 19:13:20 -0400544
Morgan Fainberg46455a32014-06-20 10:37:18 -0700545 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800546 _config_swift_apache_wsgi
547 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100548}
549
Dean Troyer1c6c1122013-03-27 17:40:53 -0500550# create_swift_disk - Create Swift backing disk
Ian Wienandaee18c72014-02-21 15:35:08 +1100551function create_swift_disk {
Dean Troyer1c6c1122013-03-27 17:40:53 -0500552 local node_number
553
554 # First do a bit of setup by creating the directories and
555 # changing the permissions so we can run it as our user.
556
Ian Wienandada886d2015-10-07 14:06:26 +1100557 local user_group
558 user_group=$(id -g ${STACK_USER})
Dean Troyer8421c2b2015-03-16 13:52:19 -0500559 sudo install -d -o ${STACK_USER} -g ${user_group} ${SWIFT_DATA_DIR}/{drives,cache,run,logs}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500560
561 # Create a loopback disk and format it to XFS.
Attila Fazekase6024412013-09-15 18:38:48 +0200562 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
Dean Troyer1c6c1122013-03-27 17:40:53 -0500563 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
564 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
Attila Fazekase6024412013-09-15 18:38:48 +0200565 sudo rm -f ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500566 fi
567 fi
568
569 mkdir -p ${SWIFT_DATA_DIR}/drives/images
Attila Fazekase6024412013-09-15 18:38:48 +0200570 sudo touch ${SWIFT_DISK_IMAGE}
Stephan Renatuse578eff2013-11-19 13:31:04 +0100571 sudo chown ${STACK_USER}: ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500572
Attila Fazekase6024412013-09-15 18:38:48 +0200573 truncate -s ${SWIFT_LOOPBACK_DISK_SIZE} ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500574
575 # Make a fresh XFS filesystem
Longgeekfd034f02014-03-24 17:32:02 +0800576 /sbin/mkfs.xfs -f -i size=1024 ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500577
578 # Mount the disk with mount options to make it as efficient as possible
579 mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1
580 if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
581 sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8 \
Attila Fazekase6024412013-09-15 18:38:48 +0200582 ${SWIFT_DISK_IMAGE} ${SWIFT_DATA_DIR}/drives/sdb1
Dean Troyer1c6c1122013-03-27 17:40:53 -0500583 fi
584
585 # Create a link to the above mount and
586 # create all of the directories needed to emulate a few different servers
Dean Troyer084f51f2014-07-25 15:08:52 -0500587 local node_number
Dean Troyer1c6c1122013-03-27 17:40:53 -0500588 for node_number in ${SWIFT_REPLICAS_SEQ}; do
589 sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number;
Dean Troyer084f51f2014-07-25 15:08:52 -0500590 local drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number}
591 local node=${SWIFT_DATA_DIR}/${node_number}/node
592 local node_device=${node}/sdb1
Dean Troyer1c6c1122013-03-27 17:40:53 -0500593 [[ -d $node ]] && continue
594 [[ -d $drive ]] && continue
Dean Troyer084f51f2014-07-25 15:08:52 -0500595 sudo install -o ${STACK_USER} -g $user_group -d $drive
596 sudo install -o ${STACK_USER} -g $user_group -d $node_device
Stephan Renatuse578eff2013-11-19 13:31:04 +0100597 sudo chown -R ${STACK_USER}: ${node}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500598 done
599}
Dean Troyerdc97cb72015-03-28 08:20:50 -0500600
601# create_swift_accounts() - Set up standard Swift accounts and extra
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200602# one for tests we do this by attaching all words in the account name
603# since we want to make it compatible with tempauth which use
604# underscores for separators.
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000605
Alistair Coles24779f62014-10-15 18:57:59 +0100606# Tenant User Roles Domain
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000607# ------------------------------------------------------------------
Alistair Coles24779f62014-10-15 18:57:59 +0100608# service swift service default
609# swifttenanttest1 swiftusertest1 admin default
610# swifttenanttest1 swiftusertest3 anotherrole default
611# swifttenanttest2 swiftusertest2 admin default
612# swifttenanttest4 swiftusertest4 admin swift_test
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000613
Ian Wienandaee18c72014-02-21 15:35:08 +1100614function create_swift_accounts {
Dean Troyerdc97cb72015-03-28 08:20:50 -0500615 # Defines specific passwords used by ``tools/create_userrc.sh``
616 # As these variables are used by ``create_userrc.sh,`` they must be exported
617 # The _password suffix is expected by ``create_userrc.sh``.
JordanP7c6d0052014-10-06 23:08:50 +0200618 export swiftusertest1_password=testing
619 export swiftusertest2_password=testing2
620 export swiftusertest3_password=testing3
Alistair Coles24779f62014-10-15 18:57:59 +0100621 export swiftusertest4_password=testing4
Sahid Orentino Ferdjaoui1814e672014-02-11 17:56:07 +0100622
Ian Wienandada886d2015-10-07 14:06:26 +1100623 local another_role
624 another_role=$(get_or_create_role "anotherrole")
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200625
Jim Rollenhagenae74ed72015-02-12 07:33:36 -0800626 # NOTE(jroll): Swift doesn't need the admin role here, however Ironic uses
627 # temp urls, which break when uploaded by a non-admin role
628 create_service_user "swift" "admin"
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200629
Sean Dague985e9582016-02-10 07:25:24 -0500630 get_or_create_service "swift" "object-store" "Swift Service"
631 get_or_create_endpoint \
632 "object-store" \
633 "$REGION_NAME" \
634 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:$SWIFT_DEFAULT_BIND_PORT/v1/AUTH_\$(tenant_id)s" \
635 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:$SWIFT_DEFAULT_BIND_PORT" \
636 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:$SWIFT_DEFAULT_BIND_PORT/v1/AUTH_\$(tenant_id)s"
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200637
Ian Wienandada886d2015-10-07 14:06:26 +1100638 local swift_tenant_test1
639 swift_tenant_test1=$(get_or_create_project swifttenanttest1 default)
Dean Troyer084f51f2014-07-25 15:08:52 -0500640 die_if_not_set $LINENO swift_tenant_test1 "Failure creating swift_tenant_test1"
Jamie Lennox9d7e7762015-05-29 01:08:53 +0000641 SWIFT_USER_TEST1=$(get_or_create_user swiftusertest1 $swiftusertest1_password \
642 "default" "test@example.com")
DennyZhang23178a92013-10-22 17:07:32 -0500643 die_if_not_set $LINENO SWIFT_USER_TEST1 "Failure creating SWIFT_USER_TEST1"
Jamie Lennox9b215db2015-02-10 18:19:57 +1100644 get_or_add_user_project_role admin $SWIFT_USER_TEST1 $swift_tenant_test1
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000645
Ian Wienandada886d2015-10-07 14:06:26 +1100646 local swift_user_test3
647 swift_user_test3=$(get_or_create_user swiftusertest3 $swiftusertest3_password \
Jamie Lennox9d7e7762015-05-29 01:08:53 +0000648 "default" "test3@example.com")
Dean Troyer084f51f2014-07-25 15:08:52 -0500649 die_if_not_set $LINENO swift_user_test3 "Failure creating swift_user_test3"
Jamie Lennox9b215db2015-02-10 18:19:57 +1100650 get_or_add_user_project_role $another_role $swift_user_test3 $swift_tenant_test1
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000651
Ian Wienandada886d2015-10-07 14:06:26 +1100652 local swift_tenant_test2
653 swift_tenant_test2=$(get_or_create_project swifttenanttest2 default)
Dean Troyer084f51f2014-07-25 15:08:52 -0500654 die_if_not_set $LINENO swift_tenant_test2 "Failure creating swift_tenant_test2"
Steve Martinelli19685422014-01-24 13:02:26 -0600655
Ian Wienandada886d2015-10-07 14:06:26 +1100656 local swift_user_test2
657 swift_user_test2=$(get_or_create_user swiftusertest2 $swiftusertest2_password \
Jamie Lennox9d7e7762015-05-29 01:08:53 +0000658 "default" "test2@example.com")
Dean Troyer084f51f2014-07-25 15:08:52 -0500659 die_if_not_set $LINENO swift_user_test2 "Failure creating swift_user_test2"
Jamie Lennox9b215db2015-02-10 18:19:57 +1100660 get_or_add_user_project_role admin $swift_user_test2 $swift_tenant_test2
Alistair Coles24779f62014-10-15 18:57:59 +0100661
Ian Wienandada886d2015-10-07 14:06:26 +1100662 local swift_domain
663 swift_domain=$(get_or_create_domain swift_test 'Used for swift functional testing')
Alistair Coles24779f62014-10-15 18:57:59 +0100664 die_if_not_set $LINENO swift_domain "Failure creating swift_test domain"
665
Ian Wienandada886d2015-10-07 14:06:26 +1100666 local swift_tenant_test4
667 swift_tenant_test4=$(get_or_create_project swifttenanttest4 $swift_domain)
Alistair Coles24779f62014-10-15 18:57:59 +0100668 die_if_not_set $LINENO swift_tenant_test4 "Failure creating swift_tenant_test4"
Jamie Lennox18f39bf2015-01-28 13:38:32 +1000669
Ian Wienandada886d2015-10-07 14:06:26 +1100670 local swift_user_test4
671 swift_user_test4=$(get_or_create_user swiftusertest4 $swiftusertest4_password \
Jamie Lennox9d7e7762015-05-29 01:08:53 +0000672 $swift_domain "test4@example.com")
Alistair Coles24779f62014-10-15 18:57:59 +0100673 die_if_not_set $LINENO swift_user_test4 "Failure creating swift_user_test4"
Jamie Lennox9b215db2015-02-10 18:19:57 +1100674 get_or_add_user_project_role admin $swift_user_test4 $swift_tenant_test4
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000675}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500676
Attila Fazekasece6a332012-11-29 14:19:41 +0100677# init_swift() - Initialize rings
Ian Wienandaee18c72014-02-21 15:35:08 +1100678function init_swift {
Attila Fazekasece6a332012-11-29 14:19:41 +0100679 local node_number
680 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100681 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100682
Dean Troyer1c6c1122013-03-27 17:40:53 -0500683 # Forcibly re-create the backing filesystem
684 create_swift_disk
685
Attila Fazekasece6a332012-11-29 14:19:41 +0100686 # This is where we create three different rings for swift with
687 # different object servers binding on different ports.
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500688 pushd ${SWIFT_CONF_DIR} >/dev/null && {
Attila Fazekasece6a332012-11-29 14:19:41 +0100689
690 rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
691
692 swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
693 swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
694 swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
695
696 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Brian Haley180f5eb2015-06-16 13:14:31 -0400697 swift-ring-builder object.builder add z${node_number}-${SWIFT_SERVICE_LOCAL_HOST}:$(( OBJECT_PORT_BASE + 10 * (node_number - 1) ))/sdb1 1
698 swift-ring-builder container.builder add z${node_number}-${SWIFT_SERVICE_LOCAL_HOST}:$(( CONTAINER_PORT_BASE + 10 * (node_number - 1) ))/sdb1 1
699 swift-ring-builder account.builder add z${node_number}-${SWIFT_SERVICE_LOCAL_HOST}:$(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) ))/sdb1 1
Attila Fazekasece6a332012-11-29 14:19:41 +0100700 done
701 swift-ring-builder object.builder rebalance
702 swift-ring-builder container.builder rebalance
703 swift-ring-builder account.builder rebalance
704 } && popd >/dev/null
705
Dean Troyer64ab7742012-12-28 15:38:28 -0600706 # Create cache dir
Dean Troyer8421c2b2015-03-16 13:52:19 -0500707 sudo install -d -o ${STACK_USER} $SWIFT_AUTH_CACHE_DIR
Dean Troyer64ab7742012-12-28 15:38:28 -0600708 rm -f $SWIFT_AUTH_CACHE_DIR/*
Attila Fazekasece6a332012-11-29 14:19:41 +0100709}
710
Ian Wienandaee18c72014-02-21 15:35:08 +1100711function install_swift {
Attila Fazekasece6a332012-11-29 14:19:41 +0100712 git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500713 setup_develop $SWIFT_DIR
Morgan Fainberg46455a32014-06-20 10:37:18 -0700714 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800715 install_apache_wsgi
716 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100717}
718
Ian Wienandaee18c72014-02-21 15:35:08 +1100719function install_swiftclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500720 if use_library_from_git "python-swiftclient"; then
721 git_clone_by_name "python-swiftclient"
722 setup_dev_lib "python-swiftclient"
Sean Dague5cb19062014-11-01 01:37:45 +0100723 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100724}
725
Chris Dent1848b832015-06-27 15:05:17 +0100726# install_ceilometermiddleware() - Collect source and prepare
727# note that this doesn't really have anything to do with ceilometer;
728# though ceilometermiddleware has ceilometer in its name as an
729# artifact of history, it is not a ceilometer specific tool. It
730# simply generates pycadf-based notifications about requests and
731# responses on the swift proxy
732function install_ceilometermiddleware {
733 if use_library_from_git "ceilometermiddleware"; then
734 git_clone_by_name "ceilometermiddleware"
735 setup_dev_lib "ceilometermiddleware"
736 else
737 pip_install_gr ceilometermiddleware
738 fi
739}
740
Attila Fazekasece6a332012-11-29 14:19:41 +0100741# start_swift() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100742function start_swift {
Chmouel Boudjnah8ecbb382013-03-12 12:15:17 +0100743 # (re)start memcached to make sure we have a clean memcache.
744 restart_service memcached
745
Attila Fazekasece6a332012-11-29 14:19:41 +0100746 # Start rsync
Vincent Untzc18b9652012-12-04 12:36:34 +0100747 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100748 sudo /etc/init.d/rsync restart || :
Attila Fazekas0e57b962014-02-28 09:09:52 +0100749 elif [ -e /etc/xinetd.d/rsync ]; then
750 start_service xinetd
Attila Fazekasece6a332012-11-29 14:19:41 +0100751 else
Attila Fazekas0e57b962014-02-28 09:09:52 +0100752 start_service rsyncd
Attila Fazekasece6a332012-11-29 14:19:41 +0100753 fi
754
Morgan Fainberg46455a32014-06-20 10:37:18 -0700755 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800756 restart_apache_server
757 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest start
Chris Dent2f27a0e2014-09-09 13:46:02 +0100758 tail_log s-proxy /var/log/$APACHE_NAME/proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800759 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
760 for type in object container account; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100761 tail_log s-${type} /var/log/$APACHE_NAME/${type}-server-1
zhang-hared98a5d02013-06-21 18:18:02 +0800762 done
763 fi
764 return 0
765 fi
766
Sean Dague101b4242013-10-22 08:47:11 -0400767 # By default with only one replica we are launching the proxy,
768 # container, account and object server in screen in foreground and
Dean Troyerdc97cb72015-03-28 08:20:50 -0500769 # other services in background. If we have ``SWIFT_REPLICAS`` set to something
770 # greater than one we first spawn all the Swift services then kill the proxy
Sean Dague101b4242013-10-22 08:47:11 -0400771 # service so we can run it in foreground in screen. ``swift-init ...
772 # {stop|restart}`` exits with '1' if no servers are running, ignore it just
773 # in case
Dean Troyer084f51f2014-07-25 15:08:52 -0500774 local todo type
Sean Dague101b4242013-10-22 08:47:11 -0400775 swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true
776 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100777 todo="object container account"
Sean Dague101b4242013-10-22 08:47:11 -0400778 fi
779 for type in proxy ${todo}; do
780 swift-init --run-dir=${SWIFT_DATA_DIR}/run ${type} stop || true
781 done
Rob Crittenden18d47782014-03-19 17:47:42 -0400782 if is_service_enabled tls-proxy; then
Falk Reimann22f747b2015-08-28 12:40:19 +0200783 local proxy_port=${SWIFT_DEFAULT_BIND_PORT}
Rob Crittenden18d47782014-03-19 17:47:42 -0400784 start_tls_proxy '*' $proxy_port $SERVICE_HOST $SWIFT_DEFAULT_BIND_PORT_INT &
785 fi
Chris Dent2f27a0e2014-09-09 13:46:02 +0100786 run_process s-proxy "$SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v"
Sean Dague101b4242013-10-22 08:47:11 -0400787 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
788 for type in object container account; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100789 run_process s-${type} "$SWIFT_DIR/bin/swift-${type}-server ${SWIFT_CONF_DIR}/${type}-server/1.conf -v"
Sean Dague101b4242013-10-22 08:47:11 -0400790 done
791 fi
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000792
793 if [[ "$SWIFT_ENABLE_TEMPURLS" == "True" ]]; then
794 swift_configure_tempurls
795 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100796}
797
798# stop_swift() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100799function stop_swift {
Dean Troyer084f51f2014-07-25 15:08:52 -0500800 local type
zhang-hared98a5d02013-06-21 18:18:02 +0800801
Morgan Fainberg46455a32014-06-20 10:37:18 -0700802 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800803 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest stop && return 0
804 fi
805
Dean Troyerdc97cb72015-03-28 08:20:50 -0500806 # screen normally killed by ``unstack.sh``
Dean Troyer995eb922013-03-07 16:11:40 -0600807 if type -p swift-init >/dev/null; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100808 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
809 fi
Chmouel Boudjnahf36a9b22014-02-03 23:44:47 +0100810 # Dump all of the servers
Chris Dent2f27a0e2014-09-09 13:46:02 +0100811 # Maintain the iteration as stop_process() has some desirable side-effects
Dean Troyer1eae3e12014-03-06 11:49:22 -0600812 for type in proxy object container account; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100813 stop_process s-${type}
Dean Troyer1eae3e12014-03-06 11:49:22 -0600814 done
815 # Blast out any stragglers
Attila Fazekasf750a6f2015-07-01 12:17:35 +0200816 pkill -f swift- || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100817}
818
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000819function swift_configure_tempurls {
Steve Martinellia91d4552015-10-20 23:15:38 -0400820 # note we are using swift credentials!
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000821 OS_USERNAME=swift \
Steve Martinellia91d4552015-10-20 23:15:38 -0400822 OS_PASSWORD=$SERVICE_PASSWORD \
Sean Dague7580a0c2016-02-17 06:23:36 -0500823 OS_PROJECT_NAME=$SERVICE_PROJECT_NAME \
Steve Martinellia91d4552015-10-20 23:15:38 -0400824 openstack object store account \
825 set --property "Temp-URL-Key=$SWIFT_TEMPURL_KEY"
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000826}
827
Attila Fazekasece6a332012-11-29 14:19:41 +0100828# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +1100829$_XTRACE_LIB_SWIFT
Sean Dague584d90e2013-03-29 14:34:53 -0400830
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100831# Tell emacs to use shell-script-mode
832## Local variables:
833## mode: shell-script
834## End: