blob: 5005ba0e100fd0a3499adea38b0f6a2d3f7a0f48 [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
Ivan Kolodyazhny9ebd65b2015-03-08 23:51:55 +020067if is_service_enabled g-api; then
68 # Minimum Cinder volume size is 1G so if Swift backend for Glance is
69 # only 1G we can not upload volume to image.
70 # Increase Swift disk size up to 2G
71 SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=2G
72else
73 # DevStack will create a loop-back disk formatted as XFS to store the
74 # swift data. Set ``SWIFT_LOOPBACK_DISK_SIZE`` to the disk size in
75 # kilobytes.
76 # Default is 1 gigabyte.
77 SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=1G
78fi
79
Joe Gordon66c54242013-11-12 16:24:14 -080080# if tempest enabled the default size is 6 Gigabyte.
Attila Fazekas3418c1c2013-09-16 18:35:49 +020081if is_service_enabled tempest; then
Joe Gordon66c54242013-11-12 16:24:14 -080082 SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=${SWIFT_LOOPBACK_DISK_SIZE:-6G}
Attila Fazekas3418c1c2013-09-16 18:35:49 +020083fi
84
85SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-$SWIFT_LOOPBACK_DISK_SIZE_DEFAULT}
Attila Fazekasece6a332012-11-29 14:19:41 +010086
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010087# Set ``SWIFT_EXTRAS_MIDDLEWARE`` to extras middlewares.
Samuel Merrittf19ccb62014-03-08 07:54:05 -080088# Default is ``staticweb, formpost``
89SWIFT_EXTRAS_MIDDLEWARE=${SWIFT_EXTRAS_MIDDLEWARE:-formpost staticweb}
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010090
Cyril Roelandtd9883402013-09-27 15:16:51 +000091# Set ``SWIFT_EXTRAS_MIDDLEWARE_LAST`` to extras middlewares that need to be at
92# the end of the pipeline.
Sean Dague53753292014-12-04 19:38:15 -050093SWIFT_EXTRAS_MIDDLEWARE_LAST=${SWIFT_EXTRAS_MIDDLEWARE_LAST:-}
Cyril Roelandtd9883402013-09-27 15:16:51 +000094
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +020095# Set ``SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH`` to extras middlewares that need to be at
96# the beginning of the pipeline, before authentication middlewares.
97SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH=${SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH:-crossdomain}
98
Attila Fazekasece6a332012-11-29 14:19:41 +010099# The ring uses a configurable number of bits from a path’s MD5 hash as
100# a partition index that designates a device. The number of bits kept
101# from the hash is known as the partition power, and 2 to the partition
102# power indicates the partition count. Partitioning the full MD5 hash
103# ring allows other parts of the cluster to work in batches of items at
104# once which ends up either more efficient or at least less complex than
105# working with each item separately or the entire cluster all at once.
106# By default we define 9 for the partition count (which mean 512).
107SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9}
108
109# Set ``SWIFT_REPLICAS`` to configure how many replicas are to be
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100110# configured for your Swift cluster. By default we are configuring
111# only one replica since this is way less CPU and memory intensive. If
112# you are planning to test swift replication you may want to set this
113# up to 3.
114SWIFT_REPLICAS=${SWIFT_REPLICAS:-1}
Attila Fazekasece6a332012-11-29 14:19:41 +0100115SWIFT_REPLICAS_SEQ=$(seq ${SWIFT_REPLICAS})
116
Peter Portantecee4b3b2013-11-20 14:33:16 -0500117# Set ``SWIFT_LOG_TOKEN_LENGTH`` to configure how many characters of an auth
118# token should be placed in the logs. When keystone is used with PKI tokens,
119# the token values can be huge, seemingly larger the 2K, at the least. We
120# restrict it here to a default of 12 characters, which should be enough to
121# trace through the logs when looking for its use.
122SWIFT_LOG_TOKEN_LENGTH=${SWIFT_LOG_TOKEN_LENGTH:-12}
123
Julien Vey63024d92014-05-06 15:10:07 +0200124# Set ``SWIFT_MAX_HEADER_SIZE`` to configure the maximun length of headers in
125# Swift API
126SWIFT_MAX_HEADER_SIZE=${SWIFT_MAX_HEADER_SIZE:-16384}
127
Attila Fazekasece6a332012-11-29 14:19:41 +0100128# Set ``OBJECT_PORT_BASE``, ``CONTAINER_PORT_BASE``, ``ACCOUNT_PORT_BASE``
129# Port bases used in port number calclution for the service "nodes"
130# The specified port number will be used, the additinal ports calculated by
131# base_port + node_num * 10
Dean Troyer1151d6f2013-03-29 14:06:52 -0500132OBJECT_PORT_BASE=${OBJECT_PORT_BASE:-6013}
133CONTAINER_PORT_BASE=${CONTAINER_PORT_BASE:-6011}
134ACCOUNT_PORT_BASE=${ACCOUNT_PORT_BASE:-6012}
Attila Fazekasece6a332012-11-29 14:19:41 +0100135
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000136# Enable tempurl feature
137SWIFT_ENABLE_TEMPURLS=${SWIFT_ENABLE_TEMPURLS:-False}
Sean Dague53753292014-12-04 19:38:15 -0500138SWIFT_TEMPURL_KEY=${SWIFT_TEMPURL_KEY:-}
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000139
Dean Troyer4237f592014-01-29 16:22:11 -0600140# Tell Tempest this project is present
141TEMPEST_SERVICES+=,swift
142
JordanPfc0ff922014-12-17 12:39:36 +0100143# Toggle for deploying Swift under HTTPD + mod_wsgi
Morgan Fainberg46455a32014-06-20 10:37:18 -0700144SWIFT_USE_MOD_WSGI=${SWIFT_USE_MOD_WSGI:-False}
Dean Troyer6d04fd72012-12-21 11:03:37 -0600145
Dean Troyercc6b4432013-04-08 15:38:03 -0500146# Functions
147# ---------
Attila Fazekasece6a332012-11-29 14:19:41 +0100148
Dean Troyere4fa7212014-01-15 15:04:49 -0600149# Test if any Swift services are enabled
150# is_swift_enabled
151function is_swift_enabled {
152 [[ ,${ENABLED_SERVICES} =~ ,"s-" ]] && return 0
153 return 1
154}
155
Attila Fazekasece6a332012-11-29 14:19:41 +0100156# cleanup_swift() - Remove residual data files
Ian Wienandaee18c72014-02-21 15:35:08 +1100157function cleanup_swift {
Sean Dague101b4242013-10-22 08:47:11 -0400158 rm -f ${SWIFT_CONF_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz}
159 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
160 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
161 fi
162 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
163 rm ${SWIFT_DISK_IMAGE}
164 fi
165 rm -rf ${SWIFT_DATA_DIR}/run/
Morgan Fainberg46455a32014-06-20 10:37:18 -0700166 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
Sean Dague101b4242013-10-22 08:47:11 -0400167 _cleanup_swift_apache_wsgi
168 fi
zhang-hared98a5d02013-06-21 18:18:02 +0800169}
170
171# _cleanup_swift_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
Ian Wienandaee18c72014-02-21 15:35:08 +1100172function _cleanup_swift_apache_wsgi {
zhang-hared98a5d02013-06-21 18:18:02 +0800173 sudo rm -f $SWIFT_APACHE_WSGI_DIR/*.wsgi
Jamie Lennox54707012013-09-17 12:07:48 +1000174 disable_apache_site proxy-server
Dean Troyer084f51f2014-07-25 15:08:52 -0500175 local node_number type
zhang-hared98a5d02013-06-21 18:18:02 +0800176 for node_number in ${SWIFT_REPLICAS_SEQ}; do
177 for type in object container account; do
Dean Troyer084f51f2014-07-25 15:08:52 -0500178 local site_name=${type}-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000179 disable_apache_site ${site_name}
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000180 sudo rm -f $(apache_site_config_for ${site_name})
zhang-hared98a5d02013-06-21 18:18:02 +0800181 done
182 done
183}
184
185# _config_swift_apache_wsgi() - Set WSGI config files of Swift
Ian Wienandaee18c72014-02-21 15:35:08 +1100186function _config_swift_apache_wsgi {
zhang-hared98a5d02013-06-21 18:18:02 +0800187 sudo mkdir -p ${SWIFT_APACHE_WSGI_DIR}
zhang-hared98a5d02013-06-21 18:18:02 +0800188 local proxy_port=${SWIFT_DEFAULT_BIND_PORT:-8080}
189
190 # copy proxy vhost and wsgi file
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000191 sudo cp ${SWIFT_DIR}/examples/apache2/proxy-server.template $(apache_site_config_for proxy-server)
zhang-hared98a5d02013-06-21 18:18:02 +0800192 sudo sed -e "
193 /^#/d;/^$/d;
194 s/%PORT%/$proxy_port/g;
195 s/%SERVICENAME%/proxy-server/g;
196 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000197 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000198 " -i $(apache_site_config_for proxy-server)
Jamie Lennox54707012013-09-17 12:07:48 +1000199 enable_apache_site proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800200
201 sudo cp ${SWIFT_DIR}/examples/wsgi/proxy-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
202 sudo sed -e "
203 /^#/d;/^$/d;
204 s/%SERVICECONF%/proxy-server.conf/g;
205 " -i ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800206
207 # copy apache vhost file and set name and port
Dean Troyer084f51f2014-07-25 15:08:52 -0500208 local node_number
zhang-hared98a5d02013-06-21 18:18:02 +0800209 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Ian Wienand761c4562014-10-21 11:41:37 +1100210 local object_port=$(( OBJECT_PORT_BASE + 10 * (node_number - 1) ))
211 local container_port=$(( CONTAINER_PORT_BASE + 10 * (node_number - 1) ))
212 local account_port=$(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) ))
zhang-hared98a5d02013-06-21 18:18:02 +0800213
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000214 sudo cp ${SWIFT_DIR}/examples/apache2/object-server.template $(apache_site_config_for object-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800215 sudo sed -e "
216 s/%PORT%/$object_port/g;
217 s/%SERVICENAME%/object-server-${node_number}/g;
218 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000219 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000220 " -i $(apache_site_config_for object-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000221 enable_apache_site object-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800222
223 sudo cp ${SWIFT_DIR}/examples/wsgi/object-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
224 sudo sed -e "
225 /^#/d;/^$/d;
226 s/%SERVICECONF%/object-server\/${node_number}.conf/g;
227 " -i ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
228
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000229 sudo cp ${SWIFT_DIR}/examples/apache2/container-server.template $(apache_site_config_for container-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800230 sudo sed -e "
231 /^#/d;/^$/d;
232 s/%PORT%/$container_port/g;
233 s/%SERVICENAME%/container-server-${node_number}/g;
234 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000235 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000236 " -i $(apache_site_config_for container-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000237 enable_apache_site container-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800238
239 sudo cp ${SWIFT_DIR}/examples/wsgi/container-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
240 sudo sed -e "
241 /^#/d;/^$/d;
242 s/%SERVICECONF%/container-server\/${node_number}.conf/g;
243 " -i ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
244
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000245 sudo cp ${SWIFT_DIR}/examples/apache2/account-server.template $(apache_site_config_for account-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800246 sudo sed -e "
Sean Dague101b4242013-10-22 08:47:11 -0400247 /^#/d;/^$/d;
zhang-hared98a5d02013-06-21 18:18:02 +0800248 s/%PORT%/$account_port/g;
249 s/%SERVICENAME%/account-server-${node_number}/g;
250 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000251 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000252 " -i $(apache_site_config_for account-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000253 enable_apache_site account-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800254
255 sudo cp ${SWIFT_DIR}/examples/wsgi/account-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
256 sudo sed -e "
Sean Dague101b4242013-10-22 08:47:11 -0400257 /^#/d;/^$/d;
zhang-hared98a5d02013-06-21 18:18:02 +0800258 s/%SERVICECONF%/account-server\/${node_number}.conf/g;
259 " -i ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800260 done
Attila Fazekasece6a332012-11-29 14:19:41 +0100261}
262
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100263# This function generates an object/container/account configuration
264# emulating 4 nodes on different ports
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200265function generate_swift_config_services {
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100266 local swift_node_config=$1
267 local node_id=$2
268 local bind_port=$3
269 local server_type=$4
270
Ian Wienand761c4562014-10-21 11:41:37 +1100271 log_facility=$(( node_id - 1 ))
Dean Troyer084f51f2014-07-25 15:08:52 -0500272 local node_path=${SWIFT_DATA_DIR}/${node_number}
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100273
274 iniuncomment ${swift_node_config} DEFAULT user
275 iniset ${swift_node_config} DEFAULT user ${STACK_USER}
276
277 iniuncomment ${swift_node_config} DEFAULT bind_port
278 iniset ${swift_node_config} DEFAULT bind_port ${bind_port}
279
280 iniuncomment ${swift_node_config} DEFAULT swift_dir
281 iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR}
282
283 iniuncomment ${swift_node_config} DEFAULT devices
284 iniset ${swift_node_config} DEFAULT devices ${node_path}
285
286 iniuncomment ${swift_node_config} DEFAULT log_facility
287 iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility}
288
289 iniuncomment ${swift_node_config} DEFAULT workers
Chmouel Boudjnah55dc2c22014-09-12 09:34:20 +0200290 iniset ${swift_node_config} DEFAULT workers ${API_WORKERS:-1}
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100291
292 iniuncomment ${swift_node_config} DEFAULT disable_fallocate
293 iniset ${swift_node_config} DEFAULT disable_fallocate true
294
295 iniuncomment ${swift_node_config} DEFAULT mount_check
296 iniset ${swift_node_config} DEFAULT mount_check false
297
298 iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode
299 iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200300
301 # Using a sed and not iniset/iniuncomment because we want to a global
302 # modification and make sure it works for new sections.
303 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100304}
305
306
Attila Fazekasece6a332012-11-29 14:19:41 +0100307# configure_swift() - Set config files, create data dirs and loop image
Ian Wienandaee18c72014-02-21 15:35:08 +1100308function configure_swift {
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200309 local swift_pipeline="${SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH}"
Attila Fazekasece6a332012-11-29 14:19:41 +0100310 local node_number
311 local swift_node_config
312 local swift_log_dir
313
Attila Fazekasece6a332012-11-29 14:19:41 +0100314 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100315 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100316
Dean Troyer1c6c1122013-03-27 17:40:53 -0500317 sudo mkdir -p ${SWIFT_CONF_DIR}/{object,container,account}-server
Stephan Renatuse578eff2013-11-19 13:31:04 +0100318 sudo chown -R ${STACK_USER}: ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100319
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500320 if [[ "$SWIFT_CONF_DIR" != "/etc/swift" ]]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100321 # Some swift tools are hard-coded to use ``/etc/swift`` and are apparently not going to be fixed.
322 # Create a symlink if the config dir is moved
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500323 sudo ln -sf ${SWIFT_CONF_DIR} /etc/swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100324 fi
325
326 # Swift use rsync to synchronize between all the different
327 # partitions (which make more sense when you have a multi-node
328 # setup) we configure it with our version of rsync.
329 sed -e "
330 s/%GROUP%/${USER_GROUP}/;
Stephan Renatuse578eff2013-11-19 13:31:04 +0100331 s/%USER%/${STACK_USER}/;
Attila Fazekasece6a332012-11-29 14:19:41 +0100332 s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,;
333 " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf
334 # rsyncd.conf just prepared for 4 nodes
Vincent Untzc18b9652012-12-04 12:36:34 +0100335 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100336 sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync
Attila Fazekas0e57b962014-02-28 09:09:52 +0100337 elif [ -e /etc/xinetd.d/rsync ]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100338 sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync
339 fi
340
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500341 SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONF_DIR}/proxy-server.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100342 cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER}
343
Daisuke Moritad03915f2014-10-08 06:52:21 +0000344 # To run container sync feature introduced in Swift ver 1.12.0,
345 # container sync "realm" is added in container-sync-realms.conf
346 local csyncfile=${SWIFT_CONF_DIR}/container-sync-realms.conf
347 cp ${SWIFT_DIR}/etc/container-sync-realms.conf-sample ${csyncfile}
348 iniset ${csyncfile} realm1 key realm1key
349 iniset ${csyncfile} realm1 cluster_name1 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:8080/v1/"
Chmouel Boudjnahf2c1a712014-01-29 21:38:14 +0000350
Attila Fazekasece6a332012-11-29 14:19:41 +0100351 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user
Stephan Renatuse578eff2013-11-19 13:31:04 +0100352 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${STACK_USER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100353
354 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500355 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100356
357 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers
358 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1
359
360 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level
361 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG
362
363 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port
Rob Crittenden18d47782014-03-19 17:47:42 -0400364 if is_service_enabled tls-proxy; then
365 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT_INT}
366 else
367 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT:-8080}
368 fi
369
370 if is_ssl_enabled_service s-proxy; then
371 ensure_certificates SWIFT
372
373 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT cert_file "$SWIFT_SSL_CERT"
374 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT key_file "$SWIFT_SSL_KEY"
375 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100376
Joe Gordond254da52013-11-19 21:06:29 -0800377 # Devstack is commonly run in a small slow environment, so bump the
378 # timeouts up.
379 # node_timeout is how long between read operations a node takes to
380 # respond to the proxy server
381 # conn_timeout is all about how long it takes a connect() system call to
382 # return
383 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server node_timeout 120
384 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server conn_timeout 20
385
Dina Belovaeedfdee2014-06-24 16:52:46 +0400386 # Configure Ceilometer
387 if is_service_enabled ceilometer; then
388 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer "set log_level" "WARN"
389 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer use "egg:ceilometer#swift"
390 SWIFT_EXTRAS_MIDDLEWARE_LAST="${SWIFT_EXTRAS_MIDDLEWARE_LAST} ceilometer"
391 fi
Cyril Roelandtd9883402013-09-27 15:16:51 +0000392
Peter Portantecee4b3b2013-11-20 14:33:16 -0500393 # Restrict the length of auth tokens in the swift proxy-server logs.
394 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:proxy-logging reveal_sensitive_prefix ${SWIFT_LOG_TOKEN_LENGTH}
395
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000396 # By default Swift will be installed with keystone and tempauth middleware
397 # and add the swift3 middleware if its configured for it. The token for
Adam Spierscb961592013-10-05 12:11:07 +0100398 # tempauth would be prefixed with the reseller_prefix setting `TEMPAUTH_` the
399 # token for keystoneauth would have the standard reseller_prefix `AUTH_`
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000400 if is_service_enabled swift3;then
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200401 swift_pipeline+=" swift3 s3token "
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100402 fi
Chmouel Boudjnah254fd552014-06-30 12:22:59 +0000403
Dean Troyer5ce44cd2015-02-12 22:18:33 -0600404 if is_service_enabled keystone; then
Chmouel Boudjnah254fd552014-06-30 12:22:59 +0000405 swift_pipeline+=" authtoken keystoneauth"
406 fi
407 swift_pipeline+=" tempauth "
408
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100409 sed -i "/^pipeline/ { s/tempauth/${swift_pipeline} ${SWIFT_EXTRAS_MIDDLEWARE}/ ;}" ${SWIFT_CONFIG_PROXY_SERVER}
Cyril Roelandtd9883402013-09-27 15:16:51 +0000410 sed -i "/^pipeline/ { s/proxy-server/${SWIFT_EXTRAS_MIDDLEWARE_LAST} proxy-server/ ; }" ${SWIFT_CONFIG_PROXY_SERVER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100411
Donagh McCabe7faceb62014-12-19 13:20:45 +0000412
Attila Fazekasece6a332012-11-29 14:19:41 +0100413 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true
414
Donagh McCabe7faceb62014-12-19 13:20:45 +0000415
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000416
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200417 # Configure Crossdomain
418 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:crossdomain use "egg:swift#crossdomain"
419
Jamie Lennox38c95b82015-01-30 02:15:42 +0000420
Peter Portante8afc8932013-11-20 17:34:39 -0500421 # This causes the authtoken middleware to use the same python logging
422 # adapter provided by the swift proxy-server, so that request transaction
423 # IDs will included in all of its log messages.
424 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken log_name swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100425
Jamie Lennox38c95b82015-01-30 02:15:42 +0000426 # NOTE(jamielennox): swift cannot use the regular configure_auth_token_middleware function because swift
427 # doesn't use oslo.config which is the only way to configure auth plugins with the middleare.
428 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken paste.filter_factory keystonemiddleware.auth_token:filter_factory
429 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken identity_uri $KEYSTONE_AUTH_URI
430 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_user swift
431 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_password $SERVICE_PASSWORD
432 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
433 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_uri $KEYSTONE_SERVICE_URI
434 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken cafile $SSL_BUNDLE_FILE
435 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken signing_dir $SWIFT_AUTH_CACHE_DIR
436 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken delay_auth_decision 1
437 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken cache swift.cache
438 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken include_service_catalog False
439
440 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use "egg:swift#keystoneauth"
Attila Fazekasece6a332012-11-29 14:19:41 +0100441 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin"
442
Donagh McCabe7faceb62014-12-19 13:20:45 +0000443 # Configure Tempauth. In the sample config file, Keystoneauth is commented
444 # out. Make sure we uncomment Tempauth after we uncomment Keystoneauth
445 # otherwise, this code also sets the reseller_prefix for Keystoneauth.
446 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth account_autocreate
447 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix
448 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix "TEMPAUTH"
449
Attila Fazekasece6a332012-11-29 14:19:41 +0100450 if is_service_enabled swift3; then
451 cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER}
452# NOTE(chmou): s3token middleware is not updated yet to use only
453# username and password.
454[filter:s3token]
Chmouel Boudjnah891277f2014-02-03 21:07:03 +0000455paste.filter_factory = keystoneclient.middleware.s3_token:filter_factory
Attila Fazekasece6a332012-11-29 14:19:41 +0100456auth_port = ${KEYSTONE_AUTH_PORT}
457auth_host = ${KEYSTONE_AUTH_HOST}
458auth_protocol = ${KEYSTONE_AUTH_PROTOCOL}
Rob Crittenden18d47782014-03-19 17:47:42 -0400459cafile = ${SSL_BUNDLE_FILE}
Attila Fazekasece6a332012-11-29 14:19:41 +0100460auth_token = ${SERVICE_TOKEN}
461admin_token = ${SERVICE_TOKEN}
462
463[filter:swift3]
464use = egg:swift3#swift3
465EOF
466 fi
467
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500468 cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf
469 iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH}
Julien Vey63024d92014-05-06 15:10:07 +0200470 iniset ${SWIFT_CONF_DIR}/swift.conf swift-constraints max_header_size ${SWIFT_MAX_HEADER_SIZE}
Attila Fazekasece6a332012-11-29 14:19:41 +0100471
Dean Troyer084f51f2014-07-25 15:08:52 -0500472 local node_number
Attila Fazekasece6a332012-11-29 14:19:41 +0100473 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Dean Troyer084f51f2014-07-25 15:08:52 -0500474 local swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100475 cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config}
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200476 generate_swift_config_services ${swift_node_config} ${node_number} $(( OBJECT_PORT_BASE + 10 * (node_number - 1) )) object
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000477 iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache
Attila Fazekasece6a332012-11-29 14:19:41 +0100478
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500479 swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100480 cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config}
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200481 generate_swift_config_services ${swift_node_config} ${node_number} $(( CONTAINER_PORT_BASE + 10 * (node_number - 1) )) container
Attila Fazekas83e10952012-11-30 23:28:07 +0100482 iniuncomment ${swift_node_config} app:container-server allow_versions
483 iniset ${swift_node_config} app:container-server allow_versions "true"
Attila Fazekasece6a332012-11-29 14:19:41 +0100484
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500485 swift_node_config=${SWIFT_CONF_DIR}/account-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100486 cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config}
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200487 generate_swift_config_services ${swift_node_config} ${node_number} $(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) )) account
Attila Fazekasece6a332012-11-29 14:19:41 +0100488 done
489
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000490 # Set new accounts in tempauth to match keystone tenant/user (to make testing easier)
491 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest1 "testing .admin"
492 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest2_swiftusertest2 "testing2 .admin"
493 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest3 "testing3 .admin"
494
495 testfile=${SWIFT_CONF_DIR}/test.conf
496 cp ${SWIFT_DIR}/test/sample.conf ${testfile}
497
498 # Set accounts for functional tests
499 iniset ${testfile} func_test account swifttenanttest1
500 iniset ${testfile} func_test username swiftusertest1
501 iniset ${testfile} func_test username3 swiftusertest3
502 iniset ${testfile} func_test account2 swifttenanttest2
503 iniset ${testfile} func_test username2 swiftusertest2
Alistair Coles24779f62014-10-15 18:57:59 +0100504 iniset ${testfile} func_test account4 swifttenanttest4
505 iniset ${testfile} func_test username4 swiftusertest4
506 iniset ${testfile} func_test password4 testing4
507 iniset ${testfile} func_test domain4 swift_test
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000508
Dean Troyer5ce44cd2015-02-12 22:18:33 -0600509 if is_service_enabled keystone; then
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000510 iniuncomment ${testfile} func_test auth_version
Alistair Coles24779f62014-10-15 18:57:59 +0100511 local auth_vers=$(iniget ${testfile} func_test auth_version)
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000512 iniset ${testfile} func_test auth_host ${KEYSTONE_SERVICE_HOST}
513 iniset ${testfile} func_test auth_port ${KEYSTONE_AUTH_PORT}
Alistair Coles24779f62014-10-15 18:57:59 +0100514 if [[ $auth_vers == "3" ]]; then
515 iniset ${testfile} func_test auth_prefix /v3/
516 else
517 iniset ${testfile} func_test auth_prefix /v2.0/
518 fi
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000519 fi
520
Dean Troyer084f51f2014-07-25 15:08:52 -0500521 local swift_log_dir=${SWIFT_DATA_DIR}/logs
Attila Fazekasece6a332012-11-29 14:19:41 +0100522 rm -rf ${swift_log_dir}
523 mkdir -p ${swift_log_dir}/hourly
Stephan Renatuse578eff2013-11-19 13:31:04 +0100524 sudo chown -R ${STACK_USER}:adm ${swift_log_dir}
Yves-Gwenael Bourhisf894c2a2014-04-16 13:37:46 +0200525
526 if [[ $SYSLOG != "False" ]]; then
527 sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
528 tee /etc/rsyslog.d/10-swift.conf
529 # restart syslog to take the changes
530 sudo killall -HUP rsyslogd
531 fi
Sean Daguead7e8c62014-03-19 19:13:20 -0400532
Morgan Fainberg46455a32014-06-20 10:37:18 -0700533 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800534 _config_swift_apache_wsgi
535 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100536}
537
Dean Troyer1c6c1122013-03-27 17:40:53 -0500538# create_swift_disk - Create Swift backing disk
Ian Wienandaee18c72014-02-21 15:35:08 +1100539function create_swift_disk {
Dean Troyer1c6c1122013-03-27 17:40:53 -0500540 local node_number
541
542 # First do a bit of setup by creating the directories and
543 # changing the permissions so we can run it as our user.
544
Dean Troyer084f51f2014-07-25 15:08:52 -0500545 local user_group=$(id -g ${STACK_USER})
Dean Troyer1c6c1122013-03-27 17:40:53 -0500546 sudo mkdir -p ${SWIFT_DATA_DIR}/{drives,cache,run,logs}
Dean Troyer084f51f2014-07-25 15:08:52 -0500547 sudo chown -R ${STACK_USER}:${user_group} ${SWIFT_DATA_DIR}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500548
549 # Create a loopback disk and format it to XFS.
Attila Fazekase6024412013-09-15 18:38:48 +0200550 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
Dean Troyer1c6c1122013-03-27 17:40:53 -0500551 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
552 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
Attila Fazekase6024412013-09-15 18:38:48 +0200553 sudo rm -f ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500554 fi
555 fi
556
557 mkdir -p ${SWIFT_DATA_DIR}/drives/images
Attila Fazekase6024412013-09-15 18:38:48 +0200558 sudo touch ${SWIFT_DISK_IMAGE}
Stephan Renatuse578eff2013-11-19 13:31:04 +0100559 sudo chown ${STACK_USER}: ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500560
Attila Fazekase6024412013-09-15 18:38:48 +0200561 truncate -s ${SWIFT_LOOPBACK_DISK_SIZE} ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500562
563 # Make a fresh XFS filesystem
Longgeekfd034f02014-03-24 17:32:02 +0800564 /sbin/mkfs.xfs -f -i size=1024 ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500565
566 # Mount the disk with mount options to make it as efficient as possible
567 mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1
568 if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
569 sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8 \
Attila Fazekase6024412013-09-15 18:38:48 +0200570 ${SWIFT_DISK_IMAGE} ${SWIFT_DATA_DIR}/drives/sdb1
Dean Troyer1c6c1122013-03-27 17:40:53 -0500571 fi
572
573 # Create a link to the above mount and
574 # create all of the directories needed to emulate a few different servers
Dean Troyer084f51f2014-07-25 15:08:52 -0500575 local node_number
Dean Troyer1c6c1122013-03-27 17:40:53 -0500576 for node_number in ${SWIFT_REPLICAS_SEQ}; do
577 sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number;
Dean Troyer084f51f2014-07-25 15:08:52 -0500578 local drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number}
579 local node=${SWIFT_DATA_DIR}/${node_number}/node
580 local node_device=${node}/sdb1
Dean Troyer1c6c1122013-03-27 17:40:53 -0500581 [[ -d $node ]] && continue
582 [[ -d $drive ]] && continue
Dean Troyer084f51f2014-07-25 15:08:52 -0500583 sudo install -o ${STACK_USER} -g $user_group -d $drive
584 sudo install -o ${STACK_USER} -g $user_group -d $node_device
Stephan Renatuse578eff2013-11-19 13:31:04 +0100585 sudo chown -R ${STACK_USER}: ${node}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500586 done
587}
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200588# create_swift_accounts() - Set up standard swift accounts and extra
589# one for tests we do this by attaching all words in the account name
590# since we want to make it compatible with tempauth which use
591# underscores for separators.
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000592
Alistair Coles24779f62014-10-15 18:57:59 +0100593# Tenant User Roles Domain
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000594# ------------------------------------------------------------------
Alistair Coles24779f62014-10-15 18:57:59 +0100595# service swift service default
596# swifttenanttest1 swiftusertest1 admin default
597# swifttenanttest1 swiftusertest3 anotherrole default
598# swifttenanttest2 swiftusertest2 admin default
599# swifttenanttest4 swiftusertest4 admin swift_test
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000600
Ian Wienandaee18c72014-02-21 15:35:08 +1100601function create_swift_accounts {
Sahid Orentino Ferdjaoui1814e672014-02-11 17:56:07 +0100602 # Defines specific passwords used by tools/create_userrc.sh
JordanP7c6d0052014-10-06 23:08:50 +0200603 # As these variables are used by create_userrc.sh, they must be exported
604 # The _password suffix is expected by create_userrc.sh
605 export swiftusertest1_password=testing
606 export swiftusertest2_password=testing2
607 export swiftusertest3_password=testing3
Alistair Coles24779f62014-10-15 18:57:59 +0100608 export swiftusertest4_password=testing4
Sahid Orentino Ferdjaoui1814e672014-02-11 17:56:07 +0100609
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200610 KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql}
611
Masayuki Igawad3654052014-09-01 17:30:05 +0900612 local another_role=$(openstack role list | awk "/ anotherrole / { print \$2 }")
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200613
Jim Rollenhagenae74ed72015-02-12 07:33:36 -0800614 # NOTE(jroll): Swift doesn't need the admin role here, however Ironic uses
615 # temp urls, which break when uploaded by a non-admin role
616 create_service_user "swift" "admin"
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200617
618 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz GĂ³rski0abde392014-02-28 14:15:19 +0100619
Dean Troyer084f51f2014-07-25 15:08:52 -0500620 local swift_service=$(get_or_create_service "swift" \
Bartosz GĂ³rski0abde392014-02-28 14:15:19 +0100621 "object-store" "Swift Service")
Dean Troyer084f51f2014-07-25 15:08:52 -0500622 get_or_create_endpoint $swift_service \
Bartosz GĂ³rski0abde392014-02-28 14:15:19 +0100623 "$REGION_NAME" \
Rob Crittenden18d47782014-03-19 17:47:42 -0400624 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \
625 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:8080" \
626 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s"
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200627 fi
628
Dean Troyer084f51f2014-07-25 15:08:52 -0500629 local swift_tenant_test1=$(get_or_create_project swifttenanttest1)
630 die_if_not_set $LINENO swift_tenant_test1 "Failure creating swift_tenant_test1"
Jamie Lennox18f39bf2015-01-28 13:38:32 +1000631 SWIFT_USER_TEST1=$(get_or_create_user swiftusertest1 $swiftusertest1_password "test@example.com")
DennyZhang23178a92013-10-22 17:07:32 -0500632 die_if_not_set $LINENO SWIFT_USER_TEST1 "Failure creating SWIFT_USER_TEST1"
Jamie Lennox9b215db2015-02-10 18:19:57 +1100633 get_or_add_user_project_role admin $SWIFT_USER_TEST1 $swift_tenant_test1
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000634
Jamie Lennox18f39bf2015-01-28 13:38:32 +1000635 local swift_user_test3=$(get_or_create_user swiftusertest3 $swiftusertest3_password "test3@example.com")
Dean Troyer084f51f2014-07-25 15:08:52 -0500636 die_if_not_set $LINENO swift_user_test3 "Failure creating swift_user_test3"
Jamie Lennox9b215db2015-02-10 18:19:57 +1100637 get_or_add_user_project_role $another_role $swift_user_test3 $swift_tenant_test1
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000638
Dean Troyer084f51f2014-07-25 15:08:52 -0500639 local swift_tenant_test2=$(get_or_create_project swifttenanttest2)
640 die_if_not_set $LINENO swift_tenant_test2 "Failure creating swift_tenant_test2"
Steve Martinelli19685422014-01-24 13:02:26 -0600641
Jamie Lennox18f39bf2015-01-28 13:38:32 +1000642 local swift_user_test2=$(get_or_create_user swiftusertest2 $swiftusertest2_password "test2@example.com")
Dean Troyer084f51f2014-07-25 15:08:52 -0500643 die_if_not_set $LINENO swift_user_test2 "Failure creating swift_user_test2"
Jamie Lennox9b215db2015-02-10 18:19:57 +1100644 get_or_add_user_project_role admin $swift_user_test2 $swift_tenant_test2
Alistair Coles24779f62014-10-15 18:57:59 +0100645
646 local swift_domain=$(get_or_create_domain swift_test 'Used for swift functional testing')
647 die_if_not_set $LINENO swift_domain "Failure creating swift_test domain"
648
649 local swift_tenant_test4=$(get_or_create_project swifttenanttest4 $swift_domain)
650 die_if_not_set $LINENO swift_tenant_test4 "Failure creating swift_tenant_test4"
Jamie Lennox18f39bf2015-01-28 13:38:32 +1000651
652 local swift_user_test4=$(get_or_create_user swiftusertest4 $swiftusertest4_password "test4@example.com" $swift_domain)
Alistair Coles24779f62014-10-15 18:57:59 +0100653 die_if_not_set $LINENO swift_user_test4 "Failure creating swift_user_test4"
Jamie Lennox9b215db2015-02-10 18:19:57 +1100654 get_or_add_user_project_role admin $swift_user_test4 $swift_tenant_test4
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000655}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500656
Attila Fazekasece6a332012-11-29 14:19:41 +0100657# init_swift() - Initialize rings
Ian Wienandaee18c72014-02-21 15:35:08 +1100658function init_swift {
Attila Fazekasece6a332012-11-29 14:19:41 +0100659 local node_number
660 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100661 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100662
Dean Troyer1c6c1122013-03-27 17:40:53 -0500663 # Forcibly re-create the backing filesystem
664 create_swift_disk
665
Attila Fazekasece6a332012-11-29 14:19:41 +0100666 # This is where we create three different rings for swift with
667 # different object servers binding on different ports.
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500668 pushd ${SWIFT_CONF_DIR} >/dev/null && {
Attila Fazekasece6a332012-11-29 14:19:41 +0100669
670 rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
671
672 swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
673 swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
674 swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
675
676 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Ian Wienandd968f2b2014-08-14 11:43:54 +1000677 swift-ring-builder object.builder add z${node_number}-127.0.0.1:$(( OBJECT_PORT_BASE + 10 * (node_number - 1) ))/sdb1 1
678 swift-ring-builder container.builder add z${node_number}-127.0.0.1:$(( CONTAINER_PORT_BASE + 10 * (node_number - 1) ))/sdb1 1
679 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 +0100680 done
681 swift-ring-builder object.builder rebalance
682 swift-ring-builder container.builder rebalance
683 swift-ring-builder account.builder rebalance
684 } && popd >/dev/null
685
Dean Troyer64ab7742012-12-28 15:38:28 -0600686 # Create cache dir
687 sudo mkdir -p $SWIFT_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100688 sudo chown $STACK_USER $SWIFT_AUTH_CACHE_DIR
Dean Troyer64ab7742012-12-28 15:38:28 -0600689 rm -f $SWIFT_AUTH_CACHE_DIR/*
Attila Fazekasece6a332012-11-29 14:19:41 +0100690}
691
Ian Wienandaee18c72014-02-21 15:35:08 +1100692function install_swift {
Attila Fazekasece6a332012-11-29 14:19:41 +0100693 git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500694 setup_develop $SWIFT_DIR
Morgan Fainberg46455a32014-06-20 10:37:18 -0700695 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800696 install_apache_wsgi
697 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100698}
699
Ian Wienandaee18c72014-02-21 15:35:08 +1100700function install_swiftclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500701 if use_library_from_git "python-swiftclient"; then
702 git_clone_by_name "python-swiftclient"
703 setup_dev_lib "python-swiftclient"
Sean Dague5cb19062014-11-01 01:37:45 +0100704 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100705}
706
Attila Fazekasece6a332012-11-29 14:19:41 +0100707# start_swift() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100708function start_swift {
Chmouel Boudjnah8ecbb382013-03-12 12:15:17 +0100709 # (re)start memcached to make sure we have a clean memcache.
710 restart_service memcached
711
Attila Fazekasece6a332012-11-29 14:19:41 +0100712 # Start rsync
Vincent Untzc18b9652012-12-04 12:36:34 +0100713 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100714 sudo /etc/init.d/rsync restart || :
Attila Fazekas0e57b962014-02-28 09:09:52 +0100715 elif [ -e /etc/xinetd.d/rsync ]; then
716 start_service xinetd
Attila Fazekasece6a332012-11-29 14:19:41 +0100717 else
Attila Fazekas0e57b962014-02-28 09:09:52 +0100718 start_service rsyncd
Attila Fazekasece6a332012-11-29 14:19:41 +0100719 fi
720
Morgan Fainberg46455a32014-06-20 10:37:18 -0700721 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800722 restart_apache_server
723 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest start
Chris Dent2f27a0e2014-09-09 13:46:02 +0100724 tail_log s-proxy /var/log/$APACHE_NAME/proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800725 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
726 for type in object container account; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100727 tail_log s-${type} /var/log/$APACHE_NAME/${type}-server-1
zhang-hared98a5d02013-06-21 18:18:02 +0800728 done
729 fi
730 return 0
731 fi
732
Sean Dague101b4242013-10-22 08:47:11 -0400733 # By default with only one replica we are launching the proxy,
734 # container, account and object server in screen in foreground and
735 # other services in background. If we have SWIFT_REPLICAS set to something
736 # greater than one we first spawn all the swift services then kill the proxy
737 # service so we can run it in foreground in screen. ``swift-init ...
738 # {stop|restart}`` exits with '1' if no servers are running, ignore it just
739 # in case
Dean Troyer084f51f2014-07-25 15:08:52 -0500740 local todo type
Sean Dague101b4242013-10-22 08:47:11 -0400741 swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true
742 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100743 todo="object container account"
Sean Dague101b4242013-10-22 08:47:11 -0400744 fi
745 for type in proxy ${todo}; do
746 swift-init --run-dir=${SWIFT_DATA_DIR}/run ${type} stop || true
747 done
Rob Crittenden18d47782014-03-19 17:47:42 -0400748 if is_service_enabled tls-proxy; then
749 local proxy_port=${SWIFT_DEFAULT_BIND_PORT:-8080}
750 start_tls_proxy '*' $proxy_port $SERVICE_HOST $SWIFT_DEFAULT_BIND_PORT_INT &
751 fi
Chris Dent2f27a0e2014-09-09 13:46:02 +0100752 run_process s-proxy "$SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v"
Sean Dague101b4242013-10-22 08:47:11 -0400753 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
754 for type in object container account; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100755 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 -0400756 done
757 fi
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000758
759 if [[ "$SWIFT_ENABLE_TEMPURLS" == "True" ]]; then
760 swift_configure_tempurls
761 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100762}
763
764# stop_swift() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100765function stop_swift {
Dean Troyer084f51f2014-07-25 15:08:52 -0500766 local type
zhang-hared98a5d02013-06-21 18:18:02 +0800767
Morgan Fainberg46455a32014-06-20 10:37:18 -0700768 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800769 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest stop && return 0
770 fi
771
Attila Fazekasece6a332012-11-29 14:19:41 +0100772 # screen normally killed by unstack.sh
Dean Troyer995eb922013-03-07 16:11:40 -0600773 if type -p swift-init >/dev/null; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100774 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
775 fi
Chmouel Boudjnahf36a9b22014-02-03 23:44:47 +0100776 # Dump all of the servers
Chris Dent2f27a0e2014-09-09 13:46:02 +0100777 # Maintain the iteration as stop_process() has some desirable side-effects
Dean Troyer1eae3e12014-03-06 11:49:22 -0600778 for type in proxy object container account; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100779 stop_process s-${type}
Dean Troyer1eae3e12014-03-06 11:49:22 -0600780 done
781 # Blast out any stragglers
Chmouel Boudjnahf36a9b22014-02-03 23:44:47 +0100782 pkill -f swift-
Attila Fazekasece6a332012-11-29 14:19:41 +0100783}
784
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000785function swift_configure_tempurls {
786 OS_USERNAME=swift \
787 OS_TENANT_NAME=$SERVICE_TENANT_NAME \
788 OS_PASSWORD=$SERVICE_PASSWORD \
789 swift post -m "Temp-URL-Key: $SWIFT_TEMPURL_KEY"
790}
791
Attila Fazekasece6a332012-11-29 14:19:41 +0100792# Restore xtrace
793$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400794
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100795# Tell emacs to use shell-script-mode
796## Local variables:
797## mode: shell-script
798## End: