blob: e6e1212f23a6459e12bcfa95c5e5510c175d1ce3 [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
27XTRACE=$(set +o | grep xtrace)
28set +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
41
Attila Fazekasece6a332012-11-29 14:19:41 +010042SWIFT_DIR=$DEST/swift
Dean Troyer64ab7742012-12-28 15:38:28 -060043SWIFT_AUTH_CACHE_DIR=${SWIFT_AUTH_CACHE_DIR:-/var/cache/swift}
zhang-hared98a5d02013-06-21 18:18:02 +080044SWIFT_APACHE_WSGI_DIR=${SWIFT_APACHE_WSGI_DIR:-/var/www/swift}
Dean Troyerb7490da2013-03-18 16:07:56 -050045SWIFT3_DIR=$DEST/swift3
Attila Fazekasece6a332012-11-29 14:19:41 +010046
Rob Crittenden18d47782014-03-19 17:47:42 -040047SWIFT_SERVICE_PROTOCOL=${SWIFT_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
48SWIFT_DEFAULT_BIND_PORT_INT=${SWIFT_DEFAULT_BIND_PORT_INT:-8081}
49
Attila Fazekasece6a332012-11-29 14:19:41 +010050# TODO: add logging to different location.
51
52# Set ``SWIFT_DATA_DIR`` to the location of swift drives and objects.
53# Default is the common DevStack data directory.
54SWIFT_DATA_DIR=${SWIFT_DATA_DIR:-${DATA_DIR}/swift}
Attila Fazekase6024412013-09-15 18:38:48 +020055SWIFT_DISK_IMAGE=${SWIFT_DATA_DIR}/drives/images/swift.img
Attila Fazekasece6a332012-11-29 14:19:41 +010056
Dean Troyer6ec72fa2013-03-13 11:44:53 -050057# Set ``SWIFT_CONF_DIR`` to the location of the configuration files.
Attila Fazekasece6a332012-11-29 14:19:41 +010058# Default is ``/etc/swift``.
JordanPa6dfe812014-11-20 18:06:23 +010059SWIFT_CONF_DIR=${SWIFT_CONF_DIR:-/etc/swift}
Attila Fazekasece6a332012-11-29 14:19:41 +010060
Dean Troyerb7490da2013-03-18 16:07:56 -050061if is_service_enabled s-proxy && is_service_enabled swift3; then
62 # If we are using swift3, we can default the s3 port to swift instead
63 # of nova-objectstore
64 S3_SERVICE_PORT=${S3_SERVICE_PORT:-8080}
65fi
66
Attila Fazekasece6a332012-11-29 14:19:41 +010067# DevStack will create a loop-back disk formatted as XFS to store the
Kevin Lydad66c9652013-01-09 13:39:57 +000068# swift data. Set ``SWIFT_LOOPBACK_DISK_SIZE`` to the disk size in
69# kilobytes.
Attila Fazekasece6a332012-11-29 14:19:41 +010070# Default is 1 gigabyte.
Attila Fazekase6024412013-09-15 18:38:48 +020071SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=1G
Joe Gordon66c54242013-11-12 16:24:14 -080072# if tempest enabled the default size is 6 Gigabyte.
Attila Fazekas3418c1c2013-09-16 18:35:49 +020073if is_service_enabled tempest; then
Joe Gordon66c54242013-11-12 16:24:14 -080074 SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=${SWIFT_LOOPBACK_DISK_SIZE:-6G}
Attila Fazekas3418c1c2013-09-16 18:35:49 +020075fi
76
77SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-$SWIFT_LOOPBACK_DISK_SIZE_DEFAULT}
Attila Fazekasece6a332012-11-29 14:19:41 +010078
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010079# Set ``SWIFT_EXTRAS_MIDDLEWARE`` to extras middlewares.
Samuel Merrittf19ccb62014-03-08 07:54:05 -080080# Default is ``staticweb, formpost``
81SWIFT_EXTRAS_MIDDLEWARE=${SWIFT_EXTRAS_MIDDLEWARE:-formpost staticweb}
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010082
Cyril Roelandtd9883402013-09-27 15:16:51 +000083# Set ``SWIFT_EXTRAS_MIDDLEWARE_LAST`` to extras middlewares that need to be at
84# the end of the pipeline.
Sean Dague53753292014-12-04 19:38:15 -050085SWIFT_EXTRAS_MIDDLEWARE_LAST=${SWIFT_EXTRAS_MIDDLEWARE_LAST:-}
Cyril Roelandtd9883402013-09-27 15:16:51 +000086
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +020087# Set ``SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH`` to extras middlewares that need to be at
88# the beginning of the pipeline, before authentication middlewares.
89SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH=${SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH:-crossdomain}
90
Attila Fazekasece6a332012-11-29 14:19:41 +010091# The ring uses a configurable number of bits from a path’s MD5 hash as
92# a partition index that designates a device. The number of bits kept
93# from the hash is known as the partition power, and 2 to the partition
94# power indicates the partition count. Partitioning the full MD5 hash
95# ring allows other parts of the cluster to work in batches of items at
96# once which ends up either more efficient or at least less complex than
97# working with each item separately or the entire cluster all at once.
98# By default we define 9 for the partition count (which mean 512).
99SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9}
100
101# Set ``SWIFT_REPLICAS`` to configure how many replicas are to be
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100102# configured for your Swift cluster. By default we are configuring
103# only one replica since this is way less CPU and memory intensive. If
104# you are planning to test swift replication you may want to set this
105# up to 3.
106SWIFT_REPLICAS=${SWIFT_REPLICAS:-1}
Attila Fazekasece6a332012-11-29 14:19:41 +0100107SWIFT_REPLICAS_SEQ=$(seq ${SWIFT_REPLICAS})
108
Peter Portantecee4b3b2013-11-20 14:33:16 -0500109# Set ``SWIFT_LOG_TOKEN_LENGTH`` to configure how many characters of an auth
110# token should be placed in the logs. When keystone is used with PKI tokens,
111# the token values can be huge, seemingly larger the 2K, at the least. We
112# restrict it here to a default of 12 characters, which should be enough to
113# trace through the logs when looking for its use.
114SWIFT_LOG_TOKEN_LENGTH=${SWIFT_LOG_TOKEN_LENGTH:-12}
115
Julien Vey63024d92014-05-06 15:10:07 +0200116# Set ``SWIFT_MAX_HEADER_SIZE`` to configure the maximun length of headers in
117# Swift API
118SWIFT_MAX_HEADER_SIZE=${SWIFT_MAX_HEADER_SIZE:-16384}
119
Attila Fazekasece6a332012-11-29 14:19:41 +0100120# Set ``OBJECT_PORT_BASE``, ``CONTAINER_PORT_BASE``, ``ACCOUNT_PORT_BASE``
121# Port bases used in port number calclution for the service "nodes"
122# The specified port number will be used, the additinal ports calculated by
123# base_port + node_num * 10
Dean Troyer1151d6f2013-03-29 14:06:52 -0500124OBJECT_PORT_BASE=${OBJECT_PORT_BASE:-6013}
125CONTAINER_PORT_BASE=${CONTAINER_PORT_BASE:-6011}
126ACCOUNT_PORT_BASE=${ACCOUNT_PORT_BASE:-6012}
Attila Fazekasece6a332012-11-29 14:19:41 +0100127
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000128# Enable tempurl feature
129SWIFT_ENABLE_TEMPURLS=${SWIFT_ENABLE_TEMPURLS:-False}
Sean Dague53753292014-12-04 19:38:15 -0500130SWIFT_TEMPURL_KEY=${SWIFT_TEMPURL_KEY:-}
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000131
Dean Troyer4237f592014-01-29 16:22:11 -0600132# Tell Tempest this project is present
133TEMPEST_SERVICES+=,swift
134
JordanPfc0ff922014-12-17 12:39:36 +0100135# Toggle for deploying Swift under HTTPD + mod_wsgi
Morgan Fainberg46455a32014-06-20 10:37:18 -0700136SWIFT_USE_MOD_WSGI=${SWIFT_USE_MOD_WSGI:-False}
Dean Troyer6d04fd72012-12-21 11:03:37 -0600137
Dean Troyercc6b4432013-04-08 15:38:03 -0500138# Functions
139# ---------
Attila Fazekasece6a332012-11-29 14:19:41 +0100140
Dean Troyere4fa7212014-01-15 15:04:49 -0600141# Test if any Swift services are enabled
142# is_swift_enabled
143function is_swift_enabled {
144 [[ ,${ENABLED_SERVICES} =~ ,"s-" ]] && return 0
145 return 1
146}
147
Attila Fazekasece6a332012-11-29 14:19:41 +0100148# cleanup_swift() - Remove residual data files
Ian Wienandaee18c72014-02-21 15:35:08 +1100149function cleanup_swift {
Sean Dague101b4242013-10-22 08:47:11 -0400150 rm -f ${SWIFT_CONF_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz}
151 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
152 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
153 fi
154 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
155 rm ${SWIFT_DISK_IMAGE}
156 fi
157 rm -rf ${SWIFT_DATA_DIR}/run/
Morgan Fainberg46455a32014-06-20 10:37:18 -0700158 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
Sean Dague101b4242013-10-22 08:47:11 -0400159 _cleanup_swift_apache_wsgi
160 fi
zhang-hared98a5d02013-06-21 18:18:02 +0800161}
162
163# _cleanup_swift_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
Ian Wienandaee18c72014-02-21 15:35:08 +1100164function _cleanup_swift_apache_wsgi {
zhang-hared98a5d02013-06-21 18:18:02 +0800165 sudo rm -f $SWIFT_APACHE_WSGI_DIR/*.wsgi
Jamie Lennox54707012013-09-17 12:07:48 +1000166 disable_apache_site proxy-server
Dean Troyer084f51f2014-07-25 15:08:52 -0500167 local node_number type
zhang-hared98a5d02013-06-21 18:18:02 +0800168 for node_number in ${SWIFT_REPLICAS_SEQ}; do
169 for type in object container account; do
Dean Troyer084f51f2014-07-25 15:08:52 -0500170 local site_name=${type}-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000171 disable_apache_site ${site_name}
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000172 sudo rm -f $(apache_site_config_for ${site_name})
zhang-hared98a5d02013-06-21 18:18:02 +0800173 done
174 done
175}
176
177# _config_swift_apache_wsgi() - Set WSGI config files of Swift
Ian Wienandaee18c72014-02-21 15:35:08 +1100178function _config_swift_apache_wsgi {
zhang-hared98a5d02013-06-21 18:18:02 +0800179 sudo mkdir -p ${SWIFT_APACHE_WSGI_DIR}
zhang-hared98a5d02013-06-21 18:18:02 +0800180 local proxy_port=${SWIFT_DEFAULT_BIND_PORT:-8080}
181
182 # copy proxy vhost and wsgi file
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000183 sudo cp ${SWIFT_DIR}/examples/apache2/proxy-server.template $(apache_site_config_for proxy-server)
zhang-hared98a5d02013-06-21 18:18:02 +0800184 sudo sed -e "
185 /^#/d;/^$/d;
186 s/%PORT%/$proxy_port/g;
187 s/%SERVICENAME%/proxy-server/g;
188 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000189 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000190 " -i $(apache_site_config_for proxy-server)
Jamie Lennox54707012013-09-17 12:07:48 +1000191 enable_apache_site proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800192
193 sudo cp ${SWIFT_DIR}/examples/wsgi/proxy-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
194 sudo sed -e "
195 /^#/d;/^$/d;
196 s/%SERVICECONF%/proxy-server.conf/g;
197 " -i ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800198
199 # copy apache vhost file and set name and port
Dean Troyer084f51f2014-07-25 15:08:52 -0500200 local node_number
zhang-hared98a5d02013-06-21 18:18:02 +0800201 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Ian Wienand761c4562014-10-21 11:41:37 +1100202 local object_port=$(( OBJECT_PORT_BASE + 10 * (node_number - 1) ))
203 local container_port=$(( CONTAINER_PORT_BASE + 10 * (node_number - 1) ))
204 local account_port=$(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) ))
zhang-hared98a5d02013-06-21 18:18:02 +0800205
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000206 sudo cp ${SWIFT_DIR}/examples/apache2/object-server.template $(apache_site_config_for object-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800207 sudo sed -e "
208 s/%PORT%/$object_port/g;
209 s/%SERVICENAME%/object-server-${node_number}/g;
210 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000211 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000212 " -i $(apache_site_config_for object-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000213 enable_apache_site object-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800214
215 sudo cp ${SWIFT_DIR}/examples/wsgi/object-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
216 sudo sed -e "
217 /^#/d;/^$/d;
218 s/%SERVICECONF%/object-server\/${node_number}.conf/g;
219 " -i ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
220
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000221 sudo cp ${SWIFT_DIR}/examples/apache2/container-server.template $(apache_site_config_for container-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800222 sudo sed -e "
223 /^#/d;/^$/d;
224 s/%PORT%/$container_port/g;
225 s/%SERVICENAME%/container-server-${node_number}/g;
226 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000227 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000228 " -i $(apache_site_config_for container-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000229 enable_apache_site container-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800230
231 sudo cp ${SWIFT_DIR}/examples/wsgi/container-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
232 sudo sed -e "
233 /^#/d;/^$/d;
234 s/%SERVICECONF%/container-server\/${node_number}.conf/g;
235 " -i ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
236
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000237 sudo cp ${SWIFT_DIR}/examples/apache2/account-server.template $(apache_site_config_for account-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800238 sudo sed -e "
Sean Dague101b4242013-10-22 08:47:11 -0400239 /^#/d;/^$/d;
zhang-hared98a5d02013-06-21 18:18:02 +0800240 s/%PORT%/$account_port/g;
241 s/%SERVICENAME%/account-server-${node_number}/g;
242 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000243 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000244 " -i $(apache_site_config_for account-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000245 enable_apache_site account-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800246
247 sudo cp ${SWIFT_DIR}/examples/wsgi/account-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
248 sudo sed -e "
Sean Dague101b4242013-10-22 08:47:11 -0400249 /^#/d;/^$/d;
zhang-hared98a5d02013-06-21 18:18:02 +0800250 s/%SERVICECONF%/account-server\/${node_number}.conf/g;
251 " -i ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800252 done
Attila Fazekasece6a332012-11-29 14:19:41 +0100253}
254
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100255# This function generates an object/container/account configuration
256# emulating 4 nodes on different ports
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200257function generate_swift_config_services {
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100258 local swift_node_config=$1
259 local node_id=$2
260 local bind_port=$3
261 local server_type=$4
262
Ian Wienand761c4562014-10-21 11:41:37 +1100263 log_facility=$(( node_id - 1 ))
Dean Troyer084f51f2014-07-25 15:08:52 -0500264 local node_path=${SWIFT_DATA_DIR}/${node_number}
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100265
266 iniuncomment ${swift_node_config} DEFAULT user
267 iniset ${swift_node_config} DEFAULT user ${STACK_USER}
268
269 iniuncomment ${swift_node_config} DEFAULT bind_port
270 iniset ${swift_node_config} DEFAULT bind_port ${bind_port}
271
272 iniuncomment ${swift_node_config} DEFAULT swift_dir
273 iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR}
274
275 iniuncomment ${swift_node_config} DEFAULT devices
276 iniset ${swift_node_config} DEFAULT devices ${node_path}
277
278 iniuncomment ${swift_node_config} DEFAULT log_facility
279 iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility}
280
281 iniuncomment ${swift_node_config} DEFAULT workers
Chmouel Boudjnah55dc2c22014-09-12 09:34:20 +0200282 iniset ${swift_node_config} DEFAULT workers ${API_WORKERS:-1}
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100283
284 iniuncomment ${swift_node_config} DEFAULT disable_fallocate
285 iniset ${swift_node_config} DEFAULT disable_fallocate true
286
287 iniuncomment ${swift_node_config} DEFAULT mount_check
288 iniset ${swift_node_config} DEFAULT mount_check false
289
290 iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode
291 iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200292
293 # Using a sed and not iniset/iniuncomment because we want to a global
294 # modification and make sure it works for new sections.
295 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100296}
297
298
Attila Fazekasece6a332012-11-29 14:19:41 +0100299# configure_swift() - Set config files, create data dirs and loop image
Ian Wienandaee18c72014-02-21 15:35:08 +1100300function configure_swift {
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200301 local swift_pipeline="${SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH}"
Attila Fazekasece6a332012-11-29 14:19:41 +0100302 local node_number
303 local swift_node_config
304 local swift_log_dir
305
Attila Fazekasece6a332012-11-29 14:19:41 +0100306 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100307 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100308
Dean Troyer1c6c1122013-03-27 17:40:53 -0500309 sudo mkdir -p ${SWIFT_CONF_DIR}/{object,container,account}-server
Stephan Renatuse578eff2013-11-19 13:31:04 +0100310 sudo chown -R ${STACK_USER}: ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100311
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500312 if [[ "$SWIFT_CONF_DIR" != "/etc/swift" ]]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100313 # Some swift tools are hard-coded to use ``/etc/swift`` and are apparently not going to be fixed.
314 # Create a symlink if the config dir is moved
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500315 sudo ln -sf ${SWIFT_CONF_DIR} /etc/swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100316 fi
317
318 # Swift use rsync to synchronize between all the different
319 # partitions (which make more sense when you have a multi-node
320 # setup) we configure it with our version of rsync.
321 sed -e "
322 s/%GROUP%/${USER_GROUP}/;
Stephan Renatuse578eff2013-11-19 13:31:04 +0100323 s/%USER%/${STACK_USER}/;
Attila Fazekasece6a332012-11-29 14:19:41 +0100324 s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,;
325 " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf
326 # rsyncd.conf just prepared for 4 nodes
Vincent Untzc18b9652012-12-04 12:36:34 +0100327 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100328 sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync
Attila Fazekas0e57b962014-02-28 09:09:52 +0100329 elif [ -e /etc/xinetd.d/rsync ]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100330 sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync
331 fi
332
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500333 SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONF_DIR}/proxy-server.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100334 cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER}
335
Daisuke Moritad03915f2014-10-08 06:52:21 +0000336 # To run container sync feature introduced in Swift ver 1.12.0,
337 # container sync "realm" is added in container-sync-realms.conf
338 local csyncfile=${SWIFT_CONF_DIR}/container-sync-realms.conf
339 cp ${SWIFT_DIR}/etc/container-sync-realms.conf-sample ${csyncfile}
340 iniset ${csyncfile} realm1 key realm1key
341 iniset ${csyncfile} realm1 cluster_name1 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:8080/v1/"
Chmouel Boudjnahf2c1a712014-01-29 21:38:14 +0000342
Attila Fazekasece6a332012-11-29 14:19:41 +0100343 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user
Stephan Renatuse578eff2013-11-19 13:31:04 +0100344 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${STACK_USER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100345
346 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500347 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100348
349 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers
350 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1
351
352 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level
353 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG
354
355 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port
Rob Crittenden18d47782014-03-19 17:47:42 -0400356 if is_service_enabled tls-proxy; then
357 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT_INT}
358 else
359 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT:-8080}
360 fi
361
362 if is_ssl_enabled_service s-proxy; then
363 ensure_certificates SWIFT
364
365 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT cert_file "$SWIFT_SSL_CERT"
366 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT key_file "$SWIFT_SSL_KEY"
367 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100368
Joe Gordond254da52013-11-19 21:06:29 -0800369 # Devstack is commonly run in a small slow environment, so bump the
370 # timeouts up.
371 # node_timeout is how long between read operations a node takes to
372 # respond to the proxy server
373 # conn_timeout is all about how long it takes a connect() system call to
374 # return
375 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server node_timeout 120
376 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server conn_timeout 20
377
Dina Belovaeedfdee2014-06-24 16:52:46 +0400378 # Configure Ceilometer
379 if is_service_enabled ceilometer; then
380 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer "set log_level" "WARN"
381 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer use "egg:ceilometer#swift"
382 SWIFT_EXTRAS_MIDDLEWARE_LAST="${SWIFT_EXTRAS_MIDDLEWARE_LAST} ceilometer"
383 fi
Cyril Roelandtd9883402013-09-27 15:16:51 +0000384
Peter Portantecee4b3b2013-11-20 14:33:16 -0500385 # Restrict the length of auth tokens in the swift proxy-server logs.
386 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:proxy-logging reveal_sensitive_prefix ${SWIFT_LOG_TOKEN_LENGTH}
387
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000388 # By default Swift will be installed with keystone and tempauth middleware
389 # and add the swift3 middleware if its configured for it. The token for
Adam Spierscb961592013-10-05 12:11:07 +0100390 # tempauth would be prefixed with the reseller_prefix setting `TEMPAUTH_` the
391 # token for keystoneauth would have the standard reseller_prefix `AUTH_`
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000392 if is_service_enabled swift3;then
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200393 swift_pipeline+=" swift3 s3token "
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100394 fi
Chmouel Boudjnah254fd552014-06-30 12:22:59 +0000395
396 if is_service_enabled key;then
397 swift_pipeline+=" authtoken keystoneauth"
398 fi
399 swift_pipeline+=" tempauth "
400
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100401 sed -i "/^pipeline/ { s/tempauth/${swift_pipeline} ${SWIFT_EXTRAS_MIDDLEWARE}/ ;}" ${SWIFT_CONFIG_PROXY_SERVER}
Cyril Roelandtd9883402013-09-27 15:16:51 +0000402 sed -i "/^pipeline/ { s/proxy-server/${SWIFT_EXTRAS_MIDDLEWARE_LAST} proxy-server/ ; }" ${SWIFT_CONFIG_PROXY_SERVER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100403
Donagh McCabe7faceb62014-12-19 13:20:45 +0000404
Attila Fazekasece6a332012-11-29 14:19:41 +0100405 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true
406
Donagh McCabe7faceb62014-12-19 13:20:45 +0000407
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000408
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200409 # Configure Crossdomain
410 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:crossdomain use "egg:swift#crossdomain"
411
Jamie Lennox38c95b82015-01-30 02:15:42 +0000412
Peter Portante8afc8932013-11-20 17:34:39 -0500413 # This causes the authtoken middleware to use the same python logging
414 # adapter provided by the swift proxy-server, so that request transaction
415 # IDs will included in all of its log messages.
416 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken log_name swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100417
Jamie Lennox38c95b82015-01-30 02:15:42 +0000418 # NOTE(jamielennox): swift cannot use the regular configure_auth_token_middleware function because swift
419 # doesn't use oslo.config which is the only way to configure auth plugins with the middleare.
420 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken paste.filter_factory keystonemiddleware.auth_token:filter_factory
421 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken identity_uri $KEYSTONE_AUTH_URI
422 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_user swift
423 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_password $SERVICE_PASSWORD
424 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
425 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_uri $KEYSTONE_SERVICE_URI
426 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken cafile $SSL_BUNDLE_FILE
427 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken signing_dir $SWIFT_AUTH_CACHE_DIR
428 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken delay_auth_decision 1
429 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken cache swift.cache
430 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken include_service_catalog False
431
432 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use "egg:swift#keystoneauth"
Attila Fazekasece6a332012-11-29 14:19:41 +0100433 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin"
434
Donagh McCabe7faceb62014-12-19 13:20:45 +0000435 # Configure Tempauth. In the sample config file, Keystoneauth is commented
436 # out. Make sure we uncomment Tempauth after we uncomment Keystoneauth
437 # otherwise, this code also sets the reseller_prefix for Keystoneauth.
438 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth account_autocreate
439 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix
440 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix "TEMPAUTH"
441
Attila Fazekasece6a332012-11-29 14:19:41 +0100442 if is_service_enabled swift3; then
443 cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER}
444# NOTE(chmou): s3token middleware is not updated yet to use only
445# username and password.
446[filter:s3token]
Chmouel Boudjnah891277f2014-02-03 21:07:03 +0000447paste.filter_factory = keystoneclient.middleware.s3_token:filter_factory
Attila Fazekasece6a332012-11-29 14:19:41 +0100448auth_port = ${KEYSTONE_AUTH_PORT}
449auth_host = ${KEYSTONE_AUTH_HOST}
450auth_protocol = ${KEYSTONE_AUTH_PROTOCOL}
Rob Crittenden18d47782014-03-19 17:47:42 -0400451cafile = ${SSL_BUNDLE_FILE}
Attila Fazekasece6a332012-11-29 14:19:41 +0100452auth_token = ${SERVICE_TOKEN}
453admin_token = ${SERVICE_TOKEN}
454
455[filter:swift3]
456use = egg:swift3#swift3
457EOF
458 fi
459
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500460 cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf
461 iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH}
Julien Vey63024d92014-05-06 15:10:07 +0200462 iniset ${SWIFT_CONF_DIR}/swift.conf swift-constraints max_header_size ${SWIFT_MAX_HEADER_SIZE}
Attila Fazekasece6a332012-11-29 14:19:41 +0100463
Dean Troyer084f51f2014-07-25 15:08:52 -0500464 local node_number
Attila Fazekasece6a332012-11-29 14:19:41 +0100465 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Dean Troyer084f51f2014-07-25 15:08:52 -0500466 local swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100467 cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config}
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200468 generate_swift_config_services ${swift_node_config} ${node_number} $(( OBJECT_PORT_BASE + 10 * (node_number - 1) )) object
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000469 iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache
Attila Fazekasece6a332012-11-29 14:19:41 +0100470
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500471 swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100472 cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config}
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200473 generate_swift_config_services ${swift_node_config} ${node_number} $(( CONTAINER_PORT_BASE + 10 * (node_number - 1) )) container
Attila Fazekas83e10952012-11-30 23:28:07 +0100474 iniuncomment ${swift_node_config} app:container-server allow_versions
475 iniset ${swift_node_config} app:container-server allow_versions "true"
Attila Fazekasece6a332012-11-29 14:19:41 +0100476
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500477 swift_node_config=${SWIFT_CONF_DIR}/account-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100478 cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config}
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200479 generate_swift_config_services ${swift_node_config} ${node_number} $(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) )) account
Attila Fazekasece6a332012-11-29 14:19:41 +0100480 done
481
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000482 # Set new accounts in tempauth to match keystone tenant/user (to make testing easier)
483 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest1 "testing .admin"
484 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest2_swiftusertest2 "testing2 .admin"
485 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest3 "testing3 .admin"
486
487 testfile=${SWIFT_CONF_DIR}/test.conf
488 cp ${SWIFT_DIR}/test/sample.conf ${testfile}
489
490 # Set accounts for functional tests
491 iniset ${testfile} func_test account swifttenanttest1
492 iniset ${testfile} func_test username swiftusertest1
493 iniset ${testfile} func_test username3 swiftusertest3
494 iniset ${testfile} func_test account2 swifttenanttest2
495 iniset ${testfile} func_test username2 swiftusertest2
Alistair Coles24779f62014-10-15 18:57:59 +0100496 iniset ${testfile} func_test account4 swifttenanttest4
497 iniset ${testfile} func_test username4 swiftusertest4
498 iniset ${testfile} func_test password4 testing4
499 iniset ${testfile} func_test domain4 swift_test
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000500
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000501 if is_service_enabled key;then
502 iniuncomment ${testfile} func_test auth_version
Alistair Coles24779f62014-10-15 18:57:59 +0100503 local auth_vers=$(iniget ${testfile} func_test auth_version)
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000504 iniset ${testfile} func_test auth_host ${KEYSTONE_SERVICE_HOST}
505 iniset ${testfile} func_test auth_port ${KEYSTONE_AUTH_PORT}
Alistair Coles24779f62014-10-15 18:57:59 +0100506 if [[ $auth_vers == "3" ]]; then
507 iniset ${testfile} func_test auth_prefix /v3/
508 else
509 iniset ${testfile} func_test auth_prefix /v2.0/
510 fi
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000511 fi
512
Dean Troyer084f51f2014-07-25 15:08:52 -0500513 local swift_log_dir=${SWIFT_DATA_DIR}/logs
Attila Fazekasece6a332012-11-29 14:19:41 +0100514 rm -rf ${swift_log_dir}
515 mkdir -p ${swift_log_dir}/hourly
Stephan Renatuse578eff2013-11-19 13:31:04 +0100516 sudo chown -R ${STACK_USER}:adm ${swift_log_dir}
Yves-Gwenael Bourhisf894c2a2014-04-16 13:37:46 +0200517
518 if [[ $SYSLOG != "False" ]]; then
519 sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
520 tee /etc/rsyslog.d/10-swift.conf
521 # restart syslog to take the changes
522 sudo killall -HUP rsyslogd
523 fi
Sean Daguead7e8c62014-03-19 19:13:20 -0400524
Morgan Fainberg46455a32014-06-20 10:37:18 -0700525 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800526 _config_swift_apache_wsgi
527 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100528}
529
Dean Troyer1c6c1122013-03-27 17:40:53 -0500530# create_swift_disk - Create Swift backing disk
Ian Wienandaee18c72014-02-21 15:35:08 +1100531function create_swift_disk {
Dean Troyer1c6c1122013-03-27 17:40:53 -0500532 local node_number
533
534 # First do a bit of setup by creating the directories and
535 # changing the permissions so we can run it as our user.
536
Dean Troyer084f51f2014-07-25 15:08:52 -0500537 local user_group=$(id -g ${STACK_USER})
Dean Troyer1c6c1122013-03-27 17:40:53 -0500538 sudo mkdir -p ${SWIFT_DATA_DIR}/{drives,cache,run,logs}
Dean Troyer084f51f2014-07-25 15:08:52 -0500539 sudo chown -R ${STACK_USER}:${user_group} ${SWIFT_DATA_DIR}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500540
541 # Create a loopback disk and format it to XFS.
Attila Fazekase6024412013-09-15 18:38:48 +0200542 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
Dean Troyer1c6c1122013-03-27 17:40:53 -0500543 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
544 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
Attila Fazekase6024412013-09-15 18:38:48 +0200545 sudo rm -f ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500546 fi
547 fi
548
549 mkdir -p ${SWIFT_DATA_DIR}/drives/images
Attila Fazekase6024412013-09-15 18:38:48 +0200550 sudo touch ${SWIFT_DISK_IMAGE}
Stephan Renatuse578eff2013-11-19 13:31:04 +0100551 sudo chown ${STACK_USER}: ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500552
Attila Fazekase6024412013-09-15 18:38:48 +0200553 truncate -s ${SWIFT_LOOPBACK_DISK_SIZE} ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500554
555 # Make a fresh XFS filesystem
Longgeekfd034f02014-03-24 17:32:02 +0800556 /sbin/mkfs.xfs -f -i size=1024 ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500557
558 # Mount the disk with mount options to make it as efficient as possible
559 mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1
560 if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
561 sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8 \
Attila Fazekase6024412013-09-15 18:38:48 +0200562 ${SWIFT_DISK_IMAGE} ${SWIFT_DATA_DIR}/drives/sdb1
Dean Troyer1c6c1122013-03-27 17:40:53 -0500563 fi
564
565 # Create a link to the above mount and
566 # create all of the directories needed to emulate a few different servers
Dean Troyer084f51f2014-07-25 15:08:52 -0500567 local node_number
Dean Troyer1c6c1122013-03-27 17:40:53 -0500568 for node_number in ${SWIFT_REPLICAS_SEQ}; do
569 sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number;
Dean Troyer084f51f2014-07-25 15:08:52 -0500570 local drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number}
571 local node=${SWIFT_DATA_DIR}/${node_number}/node
572 local node_device=${node}/sdb1
Dean Troyer1c6c1122013-03-27 17:40:53 -0500573 [[ -d $node ]] && continue
574 [[ -d $drive ]] && continue
Dean Troyer084f51f2014-07-25 15:08:52 -0500575 sudo install -o ${STACK_USER} -g $user_group -d $drive
576 sudo install -o ${STACK_USER} -g $user_group -d $node_device
Stephan Renatuse578eff2013-11-19 13:31:04 +0100577 sudo chown -R ${STACK_USER}: ${node}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500578 done
579}
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200580# create_swift_accounts() - Set up standard swift accounts and extra
581# one for tests we do this by attaching all words in the account name
582# since we want to make it compatible with tempauth which use
583# underscores for separators.
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000584
Alistair Coles24779f62014-10-15 18:57:59 +0100585# Tenant User Roles Domain
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000586# ------------------------------------------------------------------
Alistair Coles24779f62014-10-15 18:57:59 +0100587# service swift service default
588# swifttenanttest1 swiftusertest1 admin default
589# swifttenanttest1 swiftusertest3 anotherrole default
590# swifttenanttest2 swiftusertest2 admin default
591# swifttenanttest4 swiftusertest4 admin swift_test
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000592
Ian Wienandaee18c72014-02-21 15:35:08 +1100593function create_swift_accounts {
Sahid Orentino Ferdjaoui1814e672014-02-11 17:56:07 +0100594 # Defines specific passwords used by tools/create_userrc.sh
JordanP7c6d0052014-10-06 23:08:50 +0200595 # As these variables are used by create_userrc.sh, they must be exported
596 # The _password suffix is expected by create_userrc.sh
597 export swiftusertest1_password=testing
598 export swiftusertest2_password=testing2
599 export swiftusertest3_password=testing3
Alistair Coles24779f62014-10-15 18:57:59 +0100600 export swiftusertest4_password=testing4
Sahid Orentino Ferdjaoui1814e672014-02-11 17:56:07 +0100601
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200602 KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql}
603
Dean Troyer084f51f2014-07-25 15:08:52 -0500604 local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
605 local admin_role=$(openstack role list | awk "/ admin / { print \$2 }")
Masayuki Igawad3654052014-09-01 17:30:05 +0900606 local another_role=$(openstack role list | awk "/ anotherrole / { print \$2 }")
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200607
Dean Troyer084f51f2014-07-25 15:08:52 -0500608 local swift_user=$(get_or_create_user "swift" \
609 "$SERVICE_PASSWORD" $service_tenant)
610 get_or_add_user_role $admin_role $swift_user $service_tenant
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200611
612 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz GĂ³rski0abde392014-02-28 14:15:19 +0100613
Dean Troyer084f51f2014-07-25 15:08:52 -0500614 local swift_service=$(get_or_create_service "swift" \
Bartosz GĂ³rski0abde392014-02-28 14:15:19 +0100615 "object-store" "Swift Service")
Dean Troyer084f51f2014-07-25 15:08:52 -0500616 get_or_create_endpoint $swift_service \
Bartosz GĂ³rski0abde392014-02-28 14:15:19 +0100617 "$REGION_NAME" \
Rob Crittenden18d47782014-03-19 17:47:42 -0400618 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \
619 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:8080" \
620 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s"
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200621 fi
622
Dean Troyer084f51f2014-07-25 15:08:52 -0500623 local swift_tenant_test1=$(get_or_create_project swifttenanttest1)
624 die_if_not_set $LINENO swift_tenant_test1 "Failure creating swift_tenant_test1"
625 SWIFT_USER_TEST1=$(get_or_create_user swiftusertest1 $swiftusertest1_password \
626 "$swift_tenant_test1" "test@example.com")
DennyZhang23178a92013-10-22 17:07:32 -0500627 die_if_not_set $LINENO SWIFT_USER_TEST1 "Failure creating SWIFT_USER_TEST1"
Dean Troyer084f51f2014-07-25 15:08:52 -0500628 get_or_add_user_role $admin_role $SWIFT_USER_TEST1 $swift_tenant_test1
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000629
Dean Troyer084f51f2014-07-25 15:08:52 -0500630 local swift_user_test3=$(get_or_create_user swiftusertest3 $swiftusertest3_password \
631 "$swift_tenant_test1" "test3@example.com")
632 die_if_not_set $LINENO swift_user_test3 "Failure creating swift_user_test3"
Masayuki Igawad3654052014-09-01 17:30:05 +0900633 get_or_add_user_role $another_role $swift_user_test3 $swift_tenant_test1
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000634
Dean Troyer084f51f2014-07-25 15:08:52 -0500635 local swift_tenant_test2=$(get_or_create_project swifttenanttest2)
636 die_if_not_set $LINENO swift_tenant_test2 "Failure creating swift_tenant_test2"
Steve Martinelli19685422014-01-24 13:02:26 -0600637
Dean Troyer084f51f2014-07-25 15:08:52 -0500638 local swift_user_test2=$(get_or_create_user swiftusertest2 $swiftusertest2_password \
639 "$swift_tenant_test2" "test2@example.com")
640 die_if_not_set $LINENO swift_user_test2 "Failure creating swift_user_test2"
641 get_or_add_user_role $admin_role $swift_user_test2 $swift_tenant_test2
Alistair Coles24779f62014-10-15 18:57:59 +0100642
643 local swift_domain=$(get_or_create_domain swift_test 'Used for swift functional testing')
644 die_if_not_set $LINENO swift_domain "Failure creating swift_test domain"
645
646 local swift_tenant_test4=$(get_or_create_project swifttenanttest4 $swift_domain)
647 die_if_not_set $LINENO swift_tenant_test4 "Failure creating swift_tenant_test4"
648 local swift_user_test4=$(get_or_create_user swiftusertest4 $swiftusertest4_password \
649 $swift_tenant_test4 "test4@example.com" $swift_domain)
650 die_if_not_set $LINENO swift_user_test4 "Failure creating swift_user_test4"
651 get_or_add_user_role $admin_role $swift_user_test4 $swift_tenant_test4
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000652}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500653
Attila Fazekasece6a332012-11-29 14:19:41 +0100654# init_swift() - Initialize rings
Ian Wienandaee18c72014-02-21 15:35:08 +1100655function init_swift {
Attila Fazekasece6a332012-11-29 14:19:41 +0100656 local node_number
657 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100658 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100659
Dean Troyer1c6c1122013-03-27 17:40:53 -0500660 # Forcibly re-create the backing filesystem
661 create_swift_disk
662
Attila Fazekasece6a332012-11-29 14:19:41 +0100663 # This is where we create three different rings for swift with
664 # different object servers binding on different ports.
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500665 pushd ${SWIFT_CONF_DIR} >/dev/null && {
Attila Fazekasece6a332012-11-29 14:19:41 +0100666
667 rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
668
669 swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
670 swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
671 swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
672
673 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Ian Wienandd968f2b2014-08-14 11:43:54 +1000674 swift-ring-builder object.builder add z${node_number}-127.0.0.1:$(( OBJECT_PORT_BASE + 10 * (node_number - 1) ))/sdb1 1
675 swift-ring-builder container.builder add z${node_number}-127.0.0.1:$(( CONTAINER_PORT_BASE + 10 * (node_number - 1) ))/sdb1 1
676 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 +0100677 done
678 swift-ring-builder object.builder rebalance
679 swift-ring-builder container.builder rebalance
680 swift-ring-builder account.builder rebalance
681 } && popd >/dev/null
682
Dean Troyer64ab7742012-12-28 15:38:28 -0600683 # Create cache dir
684 sudo mkdir -p $SWIFT_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100685 sudo chown $STACK_USER $SWIFT_AUTH_CACHE_DIR
Dean Troyer64ab7742012-12-28 15:38:28 -0600686 rm -f $SWIFT_AUTH_CACHE_DIR/*
Attila Fazekasece6a332012-11-29 14:19:41 +0100687}
688
Ian Wienandaee18c72014-02-21 15:35:08 +1100689function install_swift {
Attila Fazekasece6a332012-11-29 14:19:41 +0100690 git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500691 setup_develop $SWIFT_DIR
Morgan Fainberg46455a32014-06-20 10:37:18 -0700692 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800693 install_apache_wsgi
694 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100695}
696
Ian Wienandaee18c72014-02-21 15:35:08 +1100697function install_swiftclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500698 if use_library_from_git "python-swiftclient"; then
699 git_clone_by_name "python-swiftclient"
700 setup_dev_lib "python-swiftclient"
Sean Dague5cb19062014-11-01 01:37:45 +0100701 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100702}
703
Attila Fazekasece6a332012-11-29 14:19:41 +0100704# start_swift() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100705function start_swift {
Chmouel Boudjnah8ecbb382013-03-12 12:15:17 +0100706 # (re)start memcached to make sure we have a clean memcache.
707 restart_service memcached
708
Attila Fazekasece6a332012-11-29 14:19:41 +0100709 # Start rsync
Vincent Untzc18b9652012-12-04 12:36:34 +0100710 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100711 sudo /etc/init.d/rsync restart || :
Attila Fazekas0e57b962014-02-28 09:09:52 +0100712 elif [ -e /etc/xinetd.d/rsync ]; then
713 start_service xinetd
Attila Fazekasece6a332012-11-29 14:19:41 +0100714 else
Attila Fazekas0e57b962014-02-28 09:09:52 +0100715 start_service rsyncd
Attila Fazekasece6a332012-11-29 14:19:41 +0100716 fi
717
Morgan Fainberg46455a32014-06-20 10:37:18 -0700718 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800719 restart_apache_server
720 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest start
Chris Dent2f27a0e2014-09-09 13:46:02 +0100721 tail_log s-proxy /var/log/$APACHE_NAME/proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800722 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
723 for type in object container account; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100724 tail_log s-${type} /var/log/$APACHE_NAME/${type}-server-1
zhang-hared98a5d02013-06-21 18:18:02 +0800725 done
726 fi
727 return 0
728 fi
729
Sean Dague101b4242013-10-22 08:47:11 -0400730 # By default with only one replica we are launching the proxy,
731 # container, account and object server in screen in foreground and
732 # other services in background. If we have SWIFT_REPLICAS set to something
733 # greater than one we first spawn all the swift services then kill the proxy
734 # service so we can run it in foreground in screen. ``swift-init ...
735 # {stop|restart}`` exits with '1' if no servers are running, ignore it just
736 # in case
Dean Troyer084f51f2014-07-25 15:08:52 -0500737 local todo type
Sean Dague101b4242013-10-22 08:47:11 -0400738 swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true
739 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100740 todo="object container account"
Sean Dague101b4242013-10-22 08:47:11 -0400741 fi
742 for type in proxy ${todo}; do
743 swift-init --run-dir=${SWIFT_DATA_DIR}/run ${type} stop || true
744 done
Rob Crittenden18d47782014-03-19 17:47:42 -0400745 if is_service_enabled tls-proxy; then
746 local proxy_port=${SWIFT_DEFAULT_BIND_PORT:-8080}
747 start_tls_proxy '*' $proxy_port $SERVICE_HOST $SWIFT_DEFAULT_BIND_PORT_INT &
748 fi
Chris Dent2f27a0e2014-09-09 13:46:02 +0100749 run_process s-proxy "$SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v"
Sean Dague101b4242013-10-22 08:47:11 -0400750 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
751 for type in object container account; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100752 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 -0400753 done
754 fi
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000755
756 if [[ "$SWIFT_ENABLE_TEMPURLS" == "True" ]]; then
757 swift_configure_tempurls
758 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100759}
760
761# stop_swift() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100762function stop_swift {
Dean Troyer084f51f2014-07-25 15:08:52 -0500763 local type
zhang-hared98a5d02013-06-21 18:18:02 +0800764
Morgan Fainberg46455a32014-06-20 10:37:18 -0700765 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800766 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest stop && return 0
767 fi
768
Attila Fazekasece6a332012-11-29 14:19:41 +0100769 # screen normally killed by unstack.sh
Dean Troyer995eb922013-03-07 16:11:40 -0600770 if type -p swift-init >/dev/null; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100771 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
772 fi
Chmouel Boudjnahf36a9b22014-02-03 23:44:47 +0100773 # Dump all of the servers
Chris Dent2f27a0e2014-09-09 13:46:02 +0100774 # Maintain the iteration as stop_process() has some desirable side-effects
Dean Troyer1eae3e12014-03-06 11:49:22 -0600775 for type in proxy object container account; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100776 stop_process s-${type}
Dean Troyer1eae3e12014-03-06 11:49:22 -0600777 done
778 # Blast out any stragglers
Chmouel Boudjnahf36a9b22014-02-03 23:44:47 +0100779 pkill -f swift-
Attila Fazekasece6a332012-11-29 14:19:41 +0100780}
781
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000782function swift_configure_tempurls {
783 OS_USERNAME=swift \
784 OS_TENANT_NAME=$SERVICE_TENANT_NAME \
785 OS_PASSWORD=$SERVICE_PASSWORD \
786 swift post -m "Temp-URL-Key: $SWIFT_TEMPURL_KEY"
787}
788
Attila Fazekasece6a332012-11-29 14:19:41 +0100789# Restore xtrace
790$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400791
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100792# Tell emacs to use shell-script-mode
793## Local variables:
794## mode: shell-script
795## End: