blob: 9e61331404871c0bd7d9482bcdcee25cbd662217 [file] [log] [blame]
Attila Fazekasece6a332012-11-29 14:19:41 +01001# lib/swift
Dean Troyer6d04fd72012-12-21 11:03:37 -06002# Functions to control the configuration and operation of the **Swift** service
Attila Fazekasece6a332012-11-29 14:19:41 +01003
4# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01005#
6# - ``functions`` file
7# - ``apache`` file
8# - ``DEST``, ``SCREEN_NAME``, `SWIFT_HASH` must be defined
9# - ``STACK_USER`` must be defined
10# - ``SWIFT_DATA_DIR`` or ``DATA_DIR`` must be defined
11# - ``lib/keystone`` file
12#
Attila Fazekasece6a332012-11-29 14:19:41 +010013# ``stack.sh`` calls the entry points in this order:
14#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010015# - install_swift
16# - _config_swift_apache_wsgi
17# - configure_swift
18# - init_swift
19# - start_swift
20# - stop_swift
21# - cleanup_swift
22# - _cleanup_swift_apache_wsgi
Attila Fazekasece6a332012-11-29 14:19:41 +010023
24# Save trace setting
25XTRACE=$(set +o | grep xtrace)
26set +o xtrace
27
28
29# Defaults
30# --------
31
Rob Crittenden18d47782014-03-19 17:47:42 -040032if is_ssl_enabled_service "s-proxy" || is_service_enabled tls-proxy; then
33 SWIFT_SERVICE_PROTOCOL="https"
34fi
35
Attila Fazekasece6a332012-11-29 14:19:41 +010036# Set up default directories
Sean Daguee08ab102014-11-13 17:09:28 -050037GITDIR["python-swiftclient"]=$DEST/python-swiftclient
Sean Dague5cb19062014-11-01 01:37:45 +010038
39
Attila Fazekasece6a332012-11-29 14:19:41 +010040SWIFT_DIR=$DEST/swift
Dean Troyer64ab7742012-12-28 15:38:28 -060041SWIFT_AUTH_CACHE_DIR=${SWIFT_AUTH_CACHE_DIR:-/var/cache/swift}
zhang-hared98a5d02013-06-21 18:18:02 +080042SWIFT_APACHE_WSGI_DIR=${SWIFT_APACHE_WSGI_DIR:-/var/www/swift}
Dean Troyerb7490da2013-03-18 16:07:56 -050043SWIFT3_DIR=$DEST/swift3
Attila Fazekasece6a332012-11-29 14:19:41 +010044
Rob Crittenden18d47782014-03-19 17:47:42 -040045SWIFT_SERVICE_PROTOCOL=${SWIFT_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
46SWIFT_DEFAULT_BIND_PORT_INT=${SWIFT_DEFAULT_BIND_PORT_INT:-8081}
47
Attila Fazekasece6a332012-11-29 14:19:41 +010048# TODO: add logging to different location.
49
50# Set ``SWIFT_DATA_DIR`` to the location of swift drives and objects.
51# Default is the common DevStack data directory.
52SWIFT_DATA_DIR=${SWIFT_DATA_DIR:-${DATA_DIR}/swift}
Attila Fazekase6024412013-09-15 18:38:48 +020053SWIFT_DISK_IMAGE=${SWIFT_DATA_DIR}/drives/images/swift.img
Attila Fazekasece6a332012-11-29 14:19:41 +010054
Dean Troyer6ec72fa2013-03-13 11:44:53 -050055# Set ``SWIFT_CONF_DIR`` to the location of the configuration files.
Attila Fazekasece6a332012-11-29 14:19:41 +010056# Default is ``/etc/swift``.
JordanPa6dfe812014-11-20 18:06:23 +010057SWIFT_CONF_DIR=${SWIFT_CONF_DIR:-/etc/swift}
Attila Fazekasece6a332012-11-29 14:19:41 +010058
Dean Troyerb7490da2013-03-18 16:07:56 -050059if is_service_enabled s-proxy && is_service_enabled swift3; then
60 # If we are using swift3, we can default the s3 port to swift instead
61 # of nova-objectstore
62 S3_SERVICE_PORT=${S3_SERVICE_PORT:-8080}
63fi
64
Attila Fazekasece6a332012-11-29 14:19:41 +010065# DevStack will create a loop-back disk formatted as XFS to store the
Kevin Lydad66c9652013-01-09 13:39:57 +000066# swift data. Set ``SWIFT_LOOPBACK_DISK_SIZE`` to the disk size in
67# kilobytes.
Attila Fazekasece6a332012-11-29 14:19:41 +010068# Default is 1 gigabyte.
Attila Fazekase6024412013-09-15 18:38:48 +020069SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=1G
Joe Gordon66c54242013-11-12 16:24:14 -080070# if tempest enabled the default size is 6 Gigabyte.
Attila Fazekas3418c1c2013-09-16 18:35:49 +020071if is_service_enabled tempest; then
Joe Gordon66c54242013-11-12 16:24:14 -080072 SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=${SWIFT_LOOPBACK_DISK_SIZE:-6G}
Attila Fazekas3418c1c2013-09-16 18:35:49 +020073fi
74
75SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-$SWIFT_LOOPBACK_DISK_SIZE_DEFAULT}
Attila Fazekasece6a332012-11-29 14:19:41 +010076
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010077# Set ``SWIFT_EXTRAS_MIDDLEWARE`` to extras middlewares.
Samuel Merrittf19ccb62014-03-08 07:54:05 -080078# Default is ``staticweb, formpost``
79SWIFT_EXTRAS_MIDDLEWARE=${SWIFT_EXTRAS_MIDDLEWARE:-formpost staticweb}
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010080
Cyril Roelandtd9883402013-09-27 15:16:51 +000081# Set ``SWIFT_EXTRAS_MIDDLEWARE_LAST`` to extras middlewares that need to be at
82# the end of the pipeline.
83SWIFT_EXTRAS_MIDDLEWARE_LAST=${SWIFT_EXTRAS_MIDDLEWARE_LAST}
84
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +020085# Set ``SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH`` to extras middlewares that need to be at
86# the beginning of the pipeline, before authentication middlewares.
87SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH=${SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH:-crossdomain}
88
Attila Fazekasece6a332012-11-29 14:19:41 +010089# The ring uses a configurable number of bits from a path’s MD5 hash as
90# a partition index that designates a device. The number of bits kept
91# from the hash is known as the partition power, and 2 to the partition
92# power indicates the partition count. Partitioning the full MD5 hash
93# ring allows other parts of the cluster to work in batches of items at
94# once which ends up either more efficient or at least less complex than
95# working with each item separately or the entire cluster all at once.
96# By default we define 9 for the partition count (which mean 512).
97SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9}
98
99# Set ``SWIFT_REPLICAS`` to configure how many replicas are to be
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100100# configured for your Swift cluster. By default we are configuring
101# only one replica since this is way less CPU and memory intensive. If
102# you are planning to test swift replication you may want to set this
103# up to 3.
104SWIFT_REPLICAS=${SWIFT_REPLICAS:-1}
Attila Fazekasece6a332012-11-29 14:19:41 +0100105SWIFT_REPLICAS_SEQ=$(seq ${SWIFT_REPLICAS})
106
Peter Portantecee4b3b2013-11-20 14:33:16 -0500107# Set ``SWIFT_LOG_TOKEN_LENGTH`` to configure how many characters of an auth
108# token should be placed in the logs. When keystone is used with PKI tokens,
109# the token values can be huge, seemingly larger the 2K, at the least. We
110# restrict it here to a default of 12 characters, which should be enough to
111# trace through the logs when looking for its use.
112SWIFT_LOG_TOKEN_LENGTH=${SWIFT_LOG_TOKEN_LENGTH:-12}
113
Julien Vey63024d92014-05-06 15:10:07 +0200114# Set ``SWIFT_MAX_HEADER_SIZE`` to configure the maximun length of headers in
115# Swift API
116SWIFT_MAX_HEADER_SIZE=${SWIFT_MAX_HEADER_SIZE:-16384}
117
Attila Fazekasece6a332012-11-29 14:19:41 +0100118# Set ``OBJECT_PORT_BASE``, ``CONTAINER_PORT_BASE``, ``ACCOUNT_PORT_BASE``
119# Port bases used in port number calclution for the service "nodes"
120# The specified port number will be used, the additinal ports calculated by
121# base_port + node_num * 10
Dean Troyer1151d6f2013-03-29 14:06:52 -0500122OBJECT_PORT_BASE=${OBJECT_PORT_BASE:-6013}
123CONTAINER_PORT_BASE=${CONTAINER_PORT_BASE:-6011}
124ACCOUNT_PORT_BASE=${ACCOUNT_PORT_BASE:-6012}
Attila Fazekasece6a332012-11-29 14:19:41 +0100125
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000126# Enable tempurl feature
127SWIFT_ENABLE_TEMPURLS=${SWIFT_ENABLE_TEMPURLS:-False}
128SWIFT_TEMPURL_KEY=${SWIFT_TEMPURL_KEY}
129
Dean Troyer4237f592014-01-29 16:22:11 -0600130# Tell Tempest this project is present
131TEMPEST_SERVICES+=,swift
132
Morgan Fainberg46455a32014-06-20 10:37:18 -0700133# Toggle for deploying Keystone under HTTPD + mod_wsgi
134SWIFT_USE_MOD_WSGI=${SWIFT_USE_MOD_WSGI:-False}
Dean Troyer6d04fd72012-12-21 11:03:37 -0600135
Dean Troyercc6b4432013-04-08 15:38:03 -0500136# Functions
137# ---------
Attila Fazekasece6a332012-11-29 14:19:41 +0100138
Dean Troyere4fa7212014-01-15 15:04:49 -0600139# Test if any Swift services are enabled
140# is_swift_enabled
141function is_swift_enabled {
142 [[ ,${ENABLED_SERVICES} =~ ,"s-" ]] && return 0
143 return 1
144}
145
Attila Fazekasece6a332012-11-29 14:19:41 +0100146# cleanup_swift() - Remove residual data files
Ian Wienandaee18c72014-02-21 15:35:08 +1100147function cleanup_swift {
Sean Dague101b4242013-10-22 08:47:11 -0400148 rm -f ${SWIFT_CONF_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz}
149 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
150 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
151 fi
152 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
153 rm ${SWIFT_DISK_IMAGE}
154 fi
155 rm -rf ${SWIFT_DATA_DIR}/run/
Morgan Fainberg46455a32014-06-20 10:37:18 -0700156 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
Sean Dague101b4242013-10-22 08:47:11 -0400157 _cleanup_swift_apache_wsgi
158 fi
zhang-hared98a5d02013-06-21 18:18:02 +0800159}
160
161# _cleanup_swift_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
Ian Wienandaee18c72014-02-21 15:35:08 +1100162function _cleanup_swift_apache_wsgi {
zhang-hared98a5d02013-06-21 18:18:02 +0800163 sudo rm -f $SWIFT_APACHE_WSGI_DIR/*.wsgi
Jamie Lennox54707012013-09-17 12:07:48 +1000164 disable_apache_site proxy-server
Dean Troyer084f51f2014-07-25 15:08:52 -0500165 local node_number type
zhang-hared98a5d02013-06-21 18:18:02 +0800166 for node_number in ${SWIFT_REPLICAS_SEQ}; do
167 for type in object container account; do
Dean Troyer084f51f2014-07-25 15:08:52 -0500168 local site_name=${type}-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000169 disable_apache_site ${site_name}
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000170 sudo rm -f $(apache_site_config_for ${site_name})
zhang-hared98a5d02013-06-21 18:18:02 +0800171 done
172 done
173}
174
175# _config_swift_apache_wsgi() - Set WSGI config files of Swift
Ian Wienandaee18c72014-02-21 15:35:08 +1100176function _config_swift_apache_wsgi {
zhang-hared98a5d02013-06-21 18:18:02 +0800177 sudo mkdir -p ${SWIFT_APACHE_WSGI_DIR}
zhang-hared98a5d02013-06-21 18:18:02 +0800178 local proxy_port=${SWIFT_DEFAULT_BIND_PORT:-8080}
179
180 # copy proxy vhost and wsgi file
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000181 sudo cp ${SWIFT_DIR}/examples/apache2/proxy-server.template $(apache_site_config_for proxy-server)
zhang-hared98a5d02013-06-21 18:18:02 +0800182 sudo sed -e "
183 /^#/d;/^$/d;
184 s/%PORT%/$proxy_port/g;
185 s/%SERVICENAME%/proxy-server/g;
186 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000187 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000188 " -i $(apache_site_config_for proxy-server)
Jamie Lennox54707012013-09-17 12:07:48 +1000189 enable_apache_site proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800190
191 sudo cp ${SWIFT_DIR}/examples/wsgi/proxy-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
192 sudo sed -e "
193 /^#/d;/^$/d;
194 s/%SERVICECONF%/proxy-server.conf/g;
195 " -i ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800196
197 # copy apache vhost file and set name and port
Dean Troyer084f51f2014-07-25 15:08:52 -0500198 local node_number
zhang-hared98a5d02013-06-21 18:18:02 +0800199 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Ian Wienand761c4562014-10-21 11:41:37 +1100200 local object_port=$(( OBJECT_PORT_BASE + 10 * (node_number - 1) ))
201 local container_port=$(( CONTAINER_PORT_BASE + 10 * (node_number - 1) ))
202 local account_port=$(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) ))
zhang-hared98a5d02013-06-21 18:18:02 +0800203
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000204 sudo cp ${SWIFT_DIR}/examples/apache2/object-server.template $(apache_site_config_for object-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800205 sudo sed -e "
206 s/%PORT%/$object_port/g;
207 s/%SERVICENAME%/object-server-${node_number}/g;
208 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000209 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000210 " -i $(apache_site_config_for object-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000211 enable_apache_site object-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800212
213 sudo cp ${SWIFT_DIR}/examples/wsgi/object-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
214 sudo sed -e "
215 /^#/d;/^$/d;
216 s/%SERVICECONF%/object-server\/${node_number}.conf/g;
217 " -i ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
218
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000219 sudo cp ${SWIFT_DIR}/examples/apache2/container-server.template $(apache_site_config_for container-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800220 sudo sed -e "
221 /^#/d;/^$/d;
222 s/%PORT%/$container_port/g;
223 s/%SERVICENAME%/container-server-${node_number}/g;
224 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000225 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000226 " -i $(apache_site_config_for container-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000227 enable_apache_site container-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800228
229 sudo cp ${SWIFT_DIR}/examples/wsgi/container-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
230 sudo sed -e "
231 /^#/d;/^$/d;
232 s/%SERVICECONF%/container-server\/${node_number}.conf/g;
233 " -i ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
234
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000235 sudo cp ${SWIFT_DIR}/examples/apache2/account-server.template $(apache_site_config_for account-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800236 sudo sed -e "
Sean Dague101b4242013-10-22 08:47:11 -0400237 /^#/d;/^$/d;
zhang-hared98a5d02013-06-21 18:18:02 +0800238 s/%PORT%/$account_port/g;
239 s/%SERVICENAME%/account-server-${node_number}/g;
240 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000241 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000242 " -i $(apache_site_config_for account-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000243 enable_apache_site account-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800244
245 sudo cp ${SWIFT_DIR}/examples/wsgi/account-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
246 sudo sed -e "
Sean Dague101b4242013-10-22 08:47:11 -0400247 /^#/d;/^$/d;
zhang-hared98a5d02013-06-21 18:18:02 +0800248 s/%SERVICECONF%/account-server\/${node_number}.conf/g;
249 " -i ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800250 done
Attila Fazekasece6a332012-11-29 14:19:41 +0100251}
252
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100253# This function generates an object/container/account configuration
254# emulating 4 nodes on different ports
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200255function generate_swift_config_services {
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100256 local swift_node_config=$1
257 local node_id=$2
258 local bind_port=$3
259 local server_type=$4
260
Ian Wienand761c4562014-10-21 11:41:37 +1100261 log_facility=$(( node_id - 1 ))
Dean Troyer084f51f2014-07-25 15:08:52 -0500262 local node_path=${SWIFT_DATA_DIR}/${node_number}
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100263
264 iniuncomment ${swift_node_config} DEFAULT user
265 iniset ${swift_node_config} DEFAULT user ${STACK_USER}
266
267 iniuncomment ${swift_node_config} DEFAULT bind_port
268 iniset ${swift_node_config} DEFAULT bind_port ${bind_port}
269
270 iniuncomment ${swift_node_config} DEFAULT swift_dir
271 iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR}
272
273 iniuncomment ${swift_node_config} DEFAULT devices
274 iniset ${swift_node_config} DEFAULT devices ${node_path}
275
276 iniuncomment ${swift_node_config} DEFAULT log_facility
277 iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility}
278
279 iniuncomment ${swift_node_config} DEFAULT workers
Chmouel Boudjnah55dc2c22014-09-12 09:34:20 +0200280 iniset ${swift_node_config} DEFAULT workers ${API_WORKERS:-1}
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100281
282 iniuncomment ${swift_node_config} DEFAULT disable_fallocate
283 iniset ${swift_node_config} DEFAULT disable_fallocate true
284
285 iniuncomment ${swift_node_config} DEFAULT mount_check
286 iniset ${swift_node_config} DEFAULT mount_check false
287
288 iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode
289 iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200290
291 # Using a sed and not iniset/iniuncomment because we want to a global
292 # modification and make sure it works for new sections.
293 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100294}
295
296
Attila Fazekasece6a332012-11-29 14:19:41 +0100297# configure_swift() - Set config files, create data dirs and loop image
Ian Wienandaee18c72014-02-21 15:35:08 +1100298function configure_swift {
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200299 local swift_pipeline="${SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH}"
Attila Fazekasece6a332012-11-29 14:19:41 +0100300 local node_number
301 local swift_node_config
302 local swift_log_dir
303
Attila Fazekasece6a332012-11-29 14:19:41 +0100304 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100305 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100306
Dean Troyer1c6c1122013-03-27 17:40:53 -0500307 sudo mkdir -p ${SWIFT_CONF_DIR}/{object,container,account}-server
Stephan Renatuse578eff2013-11-19 13:31:04 +0100308 sudo chown -R ${STACK_USER}: ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100309
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500310 if [[ "$SWIFT_CONF_DIR" != "/etc/swift" ]]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100311 # Some swift tools are hard-coded to use ``/etc/swift`` and are apparently not going to be fixed.
312 # Create a symlink if the config dir is moved
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500313 sudo ln -sf ${SWIFT_CONF_DIR} /etc/swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100314 fi
315
316 # Swift use rsync to synchronize between all the different
317 # partitions (which make more sense when you have a multi-node
318 # setup) we configure it with our version of rsync.
319 sed -e "
320 s/%GROUP%/${USER_GROUP}/;
Stephan Renatuse578eff2013-11-19 13:31:04 +0100321 s/%USER%/${STACK_USER}/;
Attila Fazekasece6a332012-11-29 14:19:41 +0100322 s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,;
323 " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf
324 # rsyncd.conf just prepared for 4 nodes
Vincent Untzc18b9652012-12-04 12:36:34 +0100325 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100326 sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync
Attila Fazekas0e57b962014-02-28 09:09:52 +0100327 elif [ -e /etc/xinetd.d/rsync ]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100328 sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync
329 fi
330
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500331 SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONF_DIR}/proxy-server.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100332 cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER}
333
Daisuke Moritad03915f2014-10-08 06:52:21 +0000334 # To run container sync feature introduced in Swift ver 1.12.0,
335 # container sync "realm" is added in container-sync-realms.conf
336 local csyncfile=${SWIFT_CONF_DIR}/container-sync-realms.conf
337 cp ${SWIFT_DIR}/etc/container-sync-realms.conf-sample ${csyncfile}
338 iniset ${csyncfile} realm1 key realm1key
339 iniset ${csyncfile} realm1 cluster_name1 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:8080/v1/"
Chmouel Boudjnahf2c1a712014-01-29 21:38:14 +0000340
Attila Fazekasece6a332012-11-29 14:19:41 +0100341 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user
Stephan Renatuse578eff2013-11-19 13:31:04 +0100342 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${STACK_USER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100343
344 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500345 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100346
347 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers
348 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1
349
350 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level
351 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG
352
353 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port
Rob Crittenden18d47782014-03-19 17:47:42 -0400354 if is_service_enabled tls-proxy; then
355 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT_INT}
356 else
357 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT:-8080}
358 fi
359
360 if is_ssl_enabled_service s-proxy; then
361 ensure_certificates SWIFT
362
363 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT cert_file "$SWIFT_SSL_CERT"
364 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT key_file "$SWIFT_SSL_KEY"
365 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100366
Joe Gordond254da52013-11-19 21:06:29 -0800367 # Devstack is commonly run in a small slow environment, so bump the
368 # timeouts up.
369 # node_timeout is how long between read operations a node takes to
370 # respond to the proxy server
371 # conn_timeout is all about how long it takes a connect() system call to
372 # return
373 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server node_timeout 120
374 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server conn_timeout 20
375
Dina Belovaeedfdee2014-06-24 16:52:46 +0400376 # Configure Ceilometer
377 if is_service_enabled ceilometer; then
378 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer "set log_level" "WARN"
379 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer use "egg:ceilometer#swift"
380 SWIFT_EXTRAS_MIDDLEWARE_LAST="${SWIFT_EXTRAS_MIDDLEWARE_LAST} ceilometer"
381 fi
Cyril Roelandtd9883402013-09-27 15:16:51 +0000382
Peter Portantecee4b3b2013-11-20 14:33:16 -0500383 # Restrict the length of auth tokens in the swift proxy-server logs.
384 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:proxy-logging reveal_sensitive_prefix ${SWIFT_LOG_TOKEN_LENGTH}
385
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000386 # By default Swift will be installed with keystone and tempauth middleware
387 # and add the swift3 middleware if its configured for it. The token for
Adam Spierscb961592013-10-05 12:11:07 +0100388 # tempauth would be prefixed with the reseller_prefix setting `TEMPAUTH_` the
389 # token for keystoneauth would have the standard reseller_prefix `AUTH_`
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000390 if is_service_enabled swift3;then
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200391 swift_pipeline+=" swift3 s3token "
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100392 fi
Chmouel Boudjnah254fd552014-06-30 12:22:59 +0000393
394 if is_service_enabled key;then
395 swift_pipeline+=" authtoken keystoneauth"
396 fi
397 swift_pipeline+=" tempauth "
398
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100399 sed -i "/^pipeline/ { s/tempauth/${swift_pipeline} ${SWIFT_EXTRAS_MIDDLEWARE}/ ;}" ${SWIFT_CONFIG_PROXY_SERVER}
Cyril Roelandtd9883402013-09-27 15:16:51 +0000400 sed -i "/^pipeline/ { s/proxy-server/${SWIFT_EXTRAS_MIDDLEWARE_LAST} proxy-server/ ; }" ${SWIFT_CONFIG_PROXY_SERVER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100401
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000402 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth account_autocreate
Attila Fazekasece6a332012-11-29 14:19:41 +0100403 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true
404
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000405 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix
406 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix "TEMPAUTH"
407
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200408 # Configure Crossdomain
409 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:crossdomain use "egg:swift#crossdomain"
410
Attila Fazekasece6a332012-11-29 14:19:41 +0100411 # Configure Keystone
412 sed -i '/^# \[filter:authtoken\]/,/^# \[filter:keystoneauth\]$/ s/^#[ \t]*//' ${SWIFT_CONFIG_PROXY_SERVER}
Brant Knudson05952372014-09-19 17:22:22 -0500413 configure_auth_token_middleware ${SWIFT_CONFIG_PROXY_SERVER} swift $SWIFT_AUTH_CACHE_DIR filter:authtoken
Peter Portante8afc8932013-11-20 17:34:39 -0500414 # This causes the authtoken middleware to use the same python logging
415 # adapter provided by the swift proxy-server, so that request transaction
416 # IDs will included in all of its log messages.
417 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken log_name swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100418
419 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use
420 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles
421 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin"
422
423 if is_service_enabled swift3; then
424 cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER}
425# NOTE(chmou): s3token middleware is not updated yet to use only
426# username and password.
427[filter:s3token]
Chmouel Boudjnah891277f2014-02-03 21:07:03 +0000428paste.filter_factory = keystoneclient.middleware.s3_token:filter_factory
Attila Fazekasece6a332012-11-29 14:19:41 +0100429auth_port = ${KEYSTONE_AUTH_PORT}
430auth_host = ${KEYSTONE_AUTH_HOST}
431auth_protocol = ${KEYSTONE_AUTH_PROTOCOL}
Rob Crittenden18d47782014-03-19 17:47:42 -0400432cafile = ${SSL_BUNDLE_FILE}
Attila Fazekasece6a332012-11-29 14:19:41 +0100433auth_token = ${SERVICE_TOKEN}
434admin_token = ${SERVICE_TOKEN}
435
436[filter:swift3]
437use = egg:swift3#swift3
438EOF
439 fi
440
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500441 cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf
442 iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH}
Julien Vey63024d92014-05-06 15:10:07 +0200443 iniset ${SWIFT_CONF_DIR}/swift.conf swift-constraints max_header_size ${SWIFT_MAX_HEADER_SIZE}
Attila Fazekasece6a332012-11-29 14:19:41 +0100444
Dean Troyer084f51f2014-07-25 15:08:52 -0500445 local node_number
Attila Fazekasece6a332012-11-29 14:19:41 +0100446 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Dean Troyer084f51f2014-07-25 15:08:52 -0500447 local swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100448 cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config}
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200449 generate_swift_config_services ${swift_node_config} ${node_number} $(( OBJECT_PORT_BASE + 10 * (node_number - 1) )) object
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000450 iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache
Attila Fazekasece6a332012-11-29 14:19:41 +0100451
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500452 swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100453 cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config}
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200454 generate_swift_config_services ${swift_node_config} ${node_number} $(( CONTAINER_PORT_BASE + 10 * (node_number - 1) )) container
Attila Fazekas83e10952012-11-30 23:28:07 +0100455 iniuncomment ${swift_node_config} app:container-server allow_versions
456 iniset ${swift_node_config} app:container-server allow_versions "true"
Attila Fazekasece6a332012-11-29 14:19:41 +0100457
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500458 swift_node_config=${SWIFT_CONF_DIR}/account-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100459 cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config}
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200460 generate_swift_config_services ${swift_node_config} ${node_number} $(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) )) account
Attila Fazekasece6a332012-11-29 14:19:41 +0100461 done
462
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000463 # Set new accounts in tempauth to match keystone tenant/user (to make testing easier)
464 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest1 "testing .admin"
465 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest2_swiftusertest2 "testing2 .admin"
466 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest3 "testing3 .admin"
467
468 testfile=${SWIFT_CONF_DIR}/test.conf
469 cp ${SWIFT_DIR}/test/sample.conf ${testfile}
470
471 # Set accounts for functional tests
472 iniset ${testfile} func_test account swifttenanttest1
473 iniset ${testfile} func_test username swiftusertest1
474 iniset ${testfile} func_test username3 swiftusertest3
475 iniset ${testfile} func_test account2 swifttenanttest2
476 iniset ${testfile} func_test username2 swiftusertest2
Alistair Coles24779f62014-10-15 18:57:59 +0100477 iniset ${testfile} func_test account4 swifttenanttest4
478 iniset ${testfile} func_test username4 swiftusertest4
479 iniset ${testfile} func_test password4 testing4
480 iniset ${testfile} func_test domain4 swift_test
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000481
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000482 if is_service_enabled key;then
483 iniuncomment ${testfile} func_test auth_version
Alistair Coles24779f62014-10-15 18:57:59 +0100484 local auth_vers=$(iniget ${testfile} func_test auth_version)
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000485 iniset ${testfile} func_test auth_host ${KEYSTONE_SERVICE_HOST}
486 iniset ${testfile} func_test auth_port ${KEYSTONE_AUTH_PORT}
Alistair Coles24779f62014-10-15 18:57:59 +0100487 if [[ $auth_vers == "3" ]]; then
488 iniset ${testfile} func_test auth_prefix /v3/
489 else
490 iniset ${testfile} func_test auth_prefix /v2.0/
491 fi
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000492 fi
493
Dean Troyer084f51f2014-07-25 15:08:52 -0500494 local swift_log_dir=${SWIFT_DATA_DIR}/logs
Attila Fazekasece6a332012-11-29 14:19:41 +0100495 rm -rf ${swift_log_dir}
496 mkdir -p ${swift_log_dir}/hourly
Stephan Renatuse578eff2013-11-19 13:31:04 +0100497 sudo chown -R ${STACK_USER}:adm ${swift_log_dir}
Yves-Gwenael Bourhisf894c2a2014-04-16 13:37:46 +0200498
499 if [[ $SYSLOG != "False" ]]; then
500 sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
501 tee /etc/rsyslog.d/10-swift.conf
502 # restart syslog to take the changes
503 sudo killall -HUP rsyslogd
504 fi
Sean Daguead7e8c62014-03-19 19:13:20 -0400505
Morgan Fainberg46455a32014-06-20 10:37:18 -0700506 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800507 _config_swift_apache_wsgi
508 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100509}
510
Dean Troyer1c6c1122013-03-27 17:40:53 -0500511# create_swift_disk - Create Swift backing disk
Ian Wienandaee18c72014-02-21 15:35:08 +1100512function create_swift_disk {
Dean Troyer1c6c1122013-03-27 17:40:53 -0500513 local node_number
514
515 # First do a bit of setup by creating the directories and
516 # changing the permissions so we can run it as our user.
517
Dean Troyer084f51f2014-07-25 15:08:52 -0500518 local user_group=$(id -g ${STACK_USER})
Dean Troyer1c6c1122013-03-27 17:40:53 -0500519 sudo mkdir -p ${SWIFT_DATA_DIR}/{drives,cache,run,logs}
Dean Troyer084f51f2014-07-25 15:08:52 -0500520 sudo chown -R ${STACK_USER}:${user_group} ${SWIFT_DATA_DIR}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500521
522 # Create a loopback disk and format it to XFS.
Attila Fazekase6024412013-09-15 18:38:48 +0200523 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
Dean Troyer1c6c1122013-03-27 17:40:53 -0500524 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
525 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
Attila Fazekase6024412013-09-15 18:38:48 +0200526 sudo rm -f ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500527 fi
528 fi
529
530 mkdir -p ${SWIFT_DATA_DIR}/drives/images
Attila Fazekase6024412013-09-15 18:38:48 +0200531 sudo touch ${SWIFT_DISK_IMAGE}
Stephan Renatuse578eff2013-11-19 13:31:04 +0100532 sudo chown ${STACK_USER}: ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500533
Attila Fazekase6024412013-09-15 18:38:48 +0200534 truncate -s ${SWIFT_LOOPBACK_DISK_SIZE} ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500535
536 # Make a fresh XFS filesystem
Longgeekfd034f02014-03-24 17:32:02 +0800537 /sbin/mkfs.xfs -f -i size=1024 ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500538
539 # Mount the disk with mount options to make it as efficient as possible
540 mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1
541 if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
542 sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8 \
Attila Fazekase6024412013-09-15 18:38:48 +0200543 ${SWIFT_DISK_IMAGE} ${SWIFT_DATA_DIR}/drives/sdb1
Dean Troyer1c6c1122013-03-27 17:40:53 -0500544 fi
545
546 # Create a link to the above mount and
547 # create all of the directories needed to emulate a few different servers
Dean Troyer084f51f2014-07-25 15:08:52 -0500548 local node_number
Dean Troyer1c6c1122013-03-27 17:40:53 -0500549 for node_number in ${SWIFT_REPLICAS_SEQ}; do
550 sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number;
Dean Troyer084f51f2014-07-25 15:08:52 -0500551 local drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number}
552 local node=${SWIFT_DATA_DIR}/${node_number}/node
553 local node_device=${node}/sdb1
Dean Troyer1c6c1122013-03-27 17:40:53 -0500554 [[ -d $node ]] && continue
555 [[ -d $drive ]] && continue
Dean Troyer084f51f2014-07-25 15:08:52 -0500556 sudo install -o ${STACK_USER} -g $user_group -d $drive
557 sudo install -o ${STACK_USER} -g $user_group -d $node_device
Stephan Renatuse578eff2013-11-19 13:31:04 +0100558 sudo chown -R ${STACK_USER}: ${node}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500559 done
560}
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200561# create_swift_accounts() - Set up standard swift accounts and extra
562# one for tests we do this by attaching all words in the account name
563# since we want to make it compatible with tempauth which use
564# underscores for separators.
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000565
Alistair Coles24779f62014-10-15 18:57:59 +0100566# Tenant User Roles Domain
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000567# ------------------------------------------------------------------
Alistair Coles24779f62014-10-15 18:57:59 +0100568# service swift service default
569# swifttenanttest1 swiftusertest1 admin default
570# swifttenanttest1 swiftusertest3 anotherrole default
571# swifttenanttest2 swiftusertest2 admin default
572# swifttenanttest4 swiftusertest4 admin swift_test
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000573
Ian Wienandaee18c72014-02-21 15:35:08 +1100574function create_swift_accounts {
Sahid Orentino Ferdjaoui1814e672014-02-11 17:56:07 +0100575 # Defines specific passwords used by tools/create_userrc.sh
JordanP7c6d0052014-10-06 23:08:50 +0200576 # As these variables are used by create_userrc.sh, they must be exported
577 # The _password suffix is expected by create_userrc.sh
578 export swiftusertest1_password=testing
579 export swiftusertest2_password=testing2
580 export swiftusertest3_password=testing3
Alistair Coles24779f62014-10-15 18:57:59 +0100581 export swiftusertest4_password=testing4
Sahid Orentino Ferdjaoui1814e672014-02-11 17:56:07 +0100582
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200583 KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql}
584
Dean Troyer084f51f2014-07-25 15:08:52 -0500585 local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
586 local admin_role=$(openstack role list | awk "/ admin / { print \$2 }")
Masayuki Igawad3654052014-09-01 17:30:05 +0900587 local another_role=$(openstack role list | awk "/ anotherrole / { print \$2 }")
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200588
Dean Troyer084f51f2014-07-25 15:08:52 -0500589 local swift_user=$(get_or_create_user "swift" \
590 "$SERVICE_PASSWORD" $service_tenant)
591 get_or_add_user_role $admin_role $swift_user $service_tenant
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200592
593 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz GĂ³rski0abde392014-02-28 14:15:19 +0100594
Dean Troyer084f51f2014-07-25 15:08:52 -0500595 local swift_service=$(get_or_create_service "swift" \
Bartosz GĂ³rski0abde392014-02-28 14:15:19 +0100596 "object-store" "Swift Service")
Dean Troyer084f51f2014-07-25 15:08:52 -0500597 get_or_create_endpoint $swift_service \
Bartosz GĂ³rski0abde392014-02-28 14:15:19 +0100598 "$REGION_NAME" \
Rob Crittenden18d47782014-03-19 17:47:42 -0400599 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \
600 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:8080" \
601 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s"
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200602 fi
603
Dean Troyer084f51f2014-07-25 15:08:52 -0500604 local swift_tenant_test1=$(get_or_create_project swifttenanttest1)
605 die_if_not_set $LINENO swift_tenant_test1 "Failure creating swift_tenant_test1"
606 SWIFT_USER_TEST1=$(get_or_create_user swiftusertest1 $swiftusertest1_password \
607 "$swift_tenant_test1" "test@example.com")
DennyZhang23178a92013-10-22 17:07:32 -0500608 die_if_not_set $LINENO SWIFT_USER_TEST1 "Failure creating SWIFT_USER_TEST1"
Dean Troyer084f51f2014-07-25 15:08:52 -0500609 get_or_add_user_role $admin_role $SWIFT_USER_TEST1 $swift_tenant_test1
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000610
Dean Troyer084f51f2014-07-25 15:08:52 -0500611 local swift_user_test3=$(get_or_create_user swiftusertest3 $swiftusertest3_password \
612 "$swift_tenant_test1" "test3@example.com")
613 die_if_not_set $LINENO swift_user_test3 "Failure creating swift_user_test3"
Masayuki Igawad3654052014-09-01 17:30:05 +0900614 get_or_add_user_role $another_role $swift_user_test3 $swift_tenant_test1
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000615
Dean Troyer084f51f2014-07-25 15:08:52 -0500616 local swift_tenant_test2=$(get_or_create_project swifttenanttest2)
617 die_if_not_set $LINENO swift_tenant_test2 "Failure creating swift_tenant_test2"
Steve Martinelli19685422014-01-24 13:02:26 -0600618
Dean Troyer084f51f2014-07-25 15:08:52 -0500619 local swift_user_test2=$(get_or_create_user swiftusertest2 $swiftusertest2_password \
620 "$swift_tenant_test2" "test2@example.com")
621 die_if_not_set $LINENO swift_user_test2 "Failure creating swift_user_test2"
622 get_or_add_user_role $admin_role $swift_user_test2 $swift_tenant_test2
Alistair Coles24779f62014-10-15 18:57:59 +0100623
624 local swift_domain=$(get_or_create_domain swift_test 'Used for swift functional testing')
625 die_if_not_set $LINENO swift_domain "Failure creating swift_test domain"
626
627 local swift_tenant_test4=$(get_or_create_project swifttenanttest4 $swift_domain)
628 die_if_not_set $LINENO swift_tenant_test4 "Failure creating swift_tenant_test4"
629 local swift_user_test4=$(get_or_create_user swiftusertest4 $swiftusertest4_password \
630 $swift_tenant_test4 "test4@example.com" $swift_domain)
631 die_if_not_set $LINENO swift_user_test4 "Failure creating swift_user_test4"
632 get_or_add_user_role $admin_role $swift_user_test4 $swift_tenant_test4
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000633}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500634
Attila Fazekasece6a332012-11-29 14:19:41 +0100635# init_swift() - Initialize rings
Ian Wienandaee18c72014-02-21 15:35:08 +1100636function init_swift {
Attila Fazekasece6a332012-11-29 14:19:41 +0100637 local node_number
638 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100639 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100640
Dean Troyer1c6c1122013-03-27 17:40:53 -0500641 # Forcibly re-create the backing filesystem
642 create_swift_disk
643
Attila Fazekasece6a332012-11-29 14:19:41 +0100644 # This is where we create three different rings for swift with
645 # different object servers binding on different ports.
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500646 pushd ${SWIFT_CONF_DIR} >/dev/null && {
Attila Fazekasece6a332012-11-29 14:19:41 +0100647
648 rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
649
650 swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
651 swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
652 swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
653
654 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Ian Wienandd968f2b2014-08-14 11:43:54 +1000655 swift-ring-builder object.builder add z${node_number}-127.0.0.1:$(( OBJECT_PORT_BASE + 10 * (node_number - 1) ))/sdb1 1
656 swift-ring-builder container.builder add z${node_number}-127.0.0.1:$(( CONTAINER_PORT_BASE + 10 * (node_number - 1) ))/sdb1 1
657 swift-ring-builder account.builder add z${node_number}-127.0.0.1:$(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) ))/sdb1 1
Attila Fazekasece6a332012-11-29 14:19:41 +0100658 done
659 swift-ring-builder object.builder rebalance
660 swift-ring-builder container.builder rebalance
661 swift-ring-builder account.builder rebalance
662 } && popd >/dev/null
663
Dean Troyer64ab7742012-12-28 15:38:28 -0600664 # Create cache dir
665 sudo mkdir -p $SWIFT_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100666 sudo chown $STACK_USER $SWIFT_AUTH_CACHE_DIR
Dean Troyer64ab7742012-12-28 15:38:28 -0600667 rm -f $SWIFT_AUTH_CACHE_DIR/*
Attila Fazekasece6a332012-11-29 14:19:41 +0100668}
669
Ian Wienandaee18c72014-02-21 15:35:08 +1100670function install_swift {
Attila Fazekasece6a332012-11-29 14:19:41 +0100671 git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500672 setup_develop $SWIFT_DIR
Morgan Fainberg46455a32014-06-20 10:37:18 -0700673 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800674 install_apache_wsgi
675 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100676}
677
Ian Wienandaee18c72014-02-21 15:35:08 +1100678function install_swiftclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500679 if use_library_from_git "python-swiftclient"; then
680 git_clone_by_name "python-swiftclient"
681 setup_dev_lib "python-swiftclient"
Sean Dague5cb19062014-11-01 01:37:45 +0100682 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100683}
684
Attila Fazekasece6a332012-11-29 14:19:41 +0100685# start_swift() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100686function start_swift {
Chmouel Boudjnah8ecbb382013-03-12 12:15:17 +0100687 # (re)start memcached to make sure we have a clean memcache.
688 restart_service memcached
689
Attila Fazekasece6a332012-11-29 14:19:41 +0100690 # Start rsync
Vincent Untzc18b9652012-12-04 12:36:34 +0100691 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100692 sudo /etc/init.d/rsync restart || :
Attila Fazekas0e57b962014-02-28 09:09:52 +0100693 elif [ -e /etc/xinetd.d/rsync ]; then
694 start_service xinetd
Attila Fazekasece6a332012-11-29 14:19:41 +0100695 else
Attila Fazekas0e57b962014-02-28 09:09:52 +0100696 start_service rsyncd
Attila Fazekasece6a332012-11-29 14:19:41 +0100697 fi
698
Morgan Fainberg46455a32014-06-20 10:37:18 -0700699 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800700 restart_apache_server
701 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest start
Chris Dent2f27a0e2014-09-09 13:46:02 +0100702 tail_log s-proxy /var/log/$APACHE_NAME/proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800703 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
704 for type in object container account; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100705 tail_log s-${type} /var/log/$APACHE_NAME/${type}-server-1
zhang-hared98a5d02013-06-21 18:18:02 +0800706 done
707 fi
708 return 0
709 fi
710
Sean Dague101b4242013-10-22 08:47:11 -0400711 # By default with only one replica we are launching the proxy,
712 # container, account and object server in screen in foreground and
713 # other services in background. If we have SWIFT_REPLICAS set to something
714 # greater than one we first spawn all the swift services then kill the proxy
715 # service so we can run it in foreground in screen. ``swift-init ...
716 # {stop|restart}`` exits with '1' if no servers are running, ignore it just
717 # in case
Dean Troyer084f51f2014-07-25 15:08:52 -0500718 local todo type
Sean Dague101b4242013-10-22 08:47:11 -0400719 swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true
720 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100721 todo="object container account"
Sean Dague101b4242013-10-22 08:47:11 -0400722 fi
723 for type in proxy ${todo}; do
724 swift-init --run-dir=${SWIFT_DATA_DIR}/run ${type} stop || true
725 done
Rob Crittenden18d47782014-03-19 17:47:42 -0400726 if is_service_enabled tls-proxy; then
727 local proxy_port=${SWIFT_DEFAULT_BIND_PORT:-8080}
728 start_tls_proxy '*' $proxy_port $SERVICE_HOST $SWIFT_DEFAULT_BIND_PORT_INT &
729 fi
Chris Dent2f27a0e2014-09-09 13:46:02 +0100730 run_process s-proxy "$SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v"
Sean Dague101b4242013-10-22 08:47:11 -0400731 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
732 for type in object container account; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100733 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 -0400734 done
735 fi
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000736
737 if [[ "$SWIFT_ENABLE_TEMPURLS" == "True" ]]; then
738 swift_configure_tempurls
739 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100740}
741
742# stop_swift() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100743function stop_swift {
Dean Troyer084f51f2014-07-25 15:08:52 -0500744 local type
zhang-hared98a5d02013-06-21 18:18:02 +0800745
Morgan Fainberg46455a32014-06-20 10:37:18 -0700746 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800747 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest stop && return 0
748 fi
749
Attila Fazekasece6a332012-11-29 14:19:41 +0100750 # screen normally killed by unstack.sh
Dean Troyer995eb922013-03-07 16:11:40 -0600751 if type -p swift-init >/dev/null; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100752 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
753 fi
Chmouel Boudjnahf36a9b22014-02-03 23:44:47 +0100754 # Dump all of the servers
Chris Dent2f27a0e2014-09-09 13:46:02 +0100755 # Maintain the iteration as stop_process() has some desirable side-effects
Dean Troyer1eae3e12014-03-06 11:49:22 -0600756 for type in proxy object container account; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100757 stop_process s-${type}
Dean Troyer1eae3e12014-03-06 11:49:22 -0600758 done
759 # Blast out any stragglers
Chmouel Boudjnahf36a9b22014-02-03 23:44:47 +0100760 pkill -f swift-
Attila Fazekasece6a332012-11-29 14:19:41 +0100761}
762
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000763function swift_configure_tempurls {
764 OS_USERNAME=swift \
765 OS_TENANT_NAME=$SERVICE_TENANT_NAME \
766 OS_PASSWORD=$SERVICE_PASSWORD \
767 swift post -m "Temp-URL-Key: $SWIFT_TEMPURL_KEY"
768}
769
Attila Fazekasece6a332012-11-29 14:19:41 +0100770# Restore xtrace
771$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400772
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100773# Tell emacs to use shell-script-mode
774## Local variables:
775## mode: shell-script
776## End: