blob: fc736a60bcd89e3b6402c53fd88a26c65d4f63e2 [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
Attila Fazekasece6a332012-11-29 14:19:41 +010041SWIFT_DIR=$DEST/swift
Dean Troyer64ab7742012-12-28 15:38:28 -060042SWIFT_AUTH_CACHE_DIR=${SWIFT_AUTH_CACHE_DIR:-/var/cache/swift}
zhang-hared98a5d02013-06-21 18:18:02 +080043SWIFT_APACHE_WSGI_DIR=${SWIFT_APACHE_WSGI_DIR:-/var/www/swift}
Dean Troyerb7490da2013-03-18 16:07:56 -050044SWIFT3_DIR=$DEST/swift3
Attila Fazekasece6a332012-11-29 14:19:41 +010045
Rob Crittenden18d47782014-03-19 17:47:42 -040046SWIFT_SERVICE_PROTOCOL=${SWIFT_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
47SWIFT_DEFAULT_BIND_PORT_INT=${SWIFT_DEFAULT_BIND_PORT_INT:-8081}
Brian Haley180f5eb2015-06-16 13:14:31 -040048SWIFT_SERVICE_LOCAL_HOST=${SWIFT_SERVICE_LOCAL_HOST:-$SERVICE_LOCAL_HOST}
Rawlin Peters92ad1522015-07-20 13:33:33 -060049SWIFT_SERVICE_LISTEN_ADDRESS=${SWIFT_SERVICE_LISTEN_ADDRESS:-$SERVICE_LISTEN_ADDRESS}
Rob Crittenden18d47782014-03-19 17:47:42 -040050
Attila Fazekasece6a332012-11-29 14:19:41 +010051# TODO: add logging to different location.
52
53# Set ``SWIFT_DATA_DIR`` to the location of swift drives and objects.
54# Default is the common DevStack data directory.
55SWIFT_DATA_DIR=${SWIFT_DATA_DIR:-${DATA_DIR}/swift}
Attila Fazekase6024412013-09-15 18:38:48 +020056SWIFT_DISK_IMAGE=${SWIFT_DATA_DIR}/drives/images/swift.img
Attila Fazekasece6a332012-11-29 14:19:41 +010057
Dean Troyer6ec72fa2013-03-13 11:44:53 -050058# Set ``SWIFT_CONF_DIR`` to the location of the configuration files.
Attila Fazekasece6a332012-11-29 14:19:41 +010059# Default is ``/etc/swift``.
JordanPa6dfe812014-11-20 18:06:23 +010060SWIFT_CONF_DIR=${SWIFT_CONF_DIR:-/etc/swift}
Attila Fazekasece6a332012-11-29 14:19:41 +010061
Dean Troyerb7490da2013-03-18 16:07:56 -050062if is_service_enabled s-proxy && is_service_enabled swift3; then
Dean Troyerdc97cb72015-03-28 08:20:50 -050063 # If we are using ``swift3``, we can default the S3 port to swift instead
Dean Troyerb7490da2013-03-18 16:07:56 -050064 # of nova-objectstore
65 S3_SERVICE_PORT=${S3_SERVICE_PORT:-8080}
66fi
67
Ivan Kolodyazhny9ebd65b2015-03-08 23:51:55 +020068if is_service_enabled g-api; then
69 # Minimum Cinder volume size is 1G so if Swift backend for Glance is
70 # only 1G we can not upload volume to image.
71 # Increase Swift disk size up to 2G
72 SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=2G
73else
74 # DevStack will create a loop-back disk formatted as XFS to store the
75 # swift data. Set ``SWIFT_LOOPBACK_DISK_SIZE`` to the disk size in
76 # kilobytes.
77 # Default is 1 gigabyte.
78 SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=1G
79fi
80
Joe Gordon66c54242013-11-12 16:24:14 -080081# if tempest enabled the default size is 6 Gigabyte.
Attila Fazekas3418c1c2013-09-16 18:35:49 +020082if is_service_enabled tempest; then
Joe Gordon66c54242013-11-12 16:24:14 -080083 SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=${SWIFT_LOOPBACK_DISK_SIZE:-6G}
Attila Fazekas3418c1c2013-09-16 18:35:49 +020084fi
85
86SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-$SWIFT_LOOPBACK_DISK_SIZE_DEFAULT}
Attila Fazekasece6a332012-11-29 14:19:41 +010087
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010088# Set ``SWIFT_EXTRAS_MIDDLEWARE`` to extras middlewares.
Samuel Merrittf19ccb62014-03-08 07:54:05 -080089# Default is ``staticweb, formpost``
90SWIFT_EXTRAS_MIDDLEWARE=${SWIFT_EXTRAS_MIDDLEWARE:-formpost staticweb}
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010091
Cyril Roelandtd9883402013-09-27 15:16:51 +000092# Set ``SWIFT_EXTRAS_MIDDLEWARE_LAST`` to extras middlewares that need to be at
93# the end of the pipeline.
Sean Dague53753292014-12-04 19:38:15 -050094SWIFT_EXTRAS_MIDDLEWARE_LAST=${SWIFT_EXTRAS_MIDDLEWARE_LAST:-}
Cyril Roelandtd9883402013-09-27 15:16:51 +000095
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +020096# Set ``SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH`` to extras middlewares that need to be at
97# the beginning of the pipeline, before authentication middlewares.
98SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH=${SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH:-crossdomain}
99
Marian Horbanea21eb42015-08-18 06:57:18 -0400100# The ring uses a configurable number of bits from a path's MD5 hash as
Attila Fazekasece6a332012-11-29 14:19:41 +0100101# a partition index that designates a device. The number of bits kept
102# from the hash is known as the partition power, and 2 to the partition
103# power indicates the partition count. Partitioning the full MD5 hash
104# ring allows other parts of the cluster to work in batches of items at
105# once which ends up either more efficient or at least less complex than
106# working with each item separately or the entire cluster all at once.
107# By default we define 9 for the partition count (which mean 512).
108SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9}
109
110# Set ``SWIFT_REPLICAS`` to configure how many replicas are to be
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100111# configured for your Swift cluster. By default we are configuring
112# only one replica since this is way less CPU and memory intensive. If
113# you are planning to test swift replication you may want to set this
114# up to 3.
115SWIFT_REPLICAS=${SWIFT_REPLICAS:-1}
Attila Fazekasece6a332012-11-29 14:19:41 +0100116SWIFT_REPLICAS_SEQ=$(seq ${SWIFT_REPLICAS})
117
Peter Portantecee4b3b2013-11-20 14:33:16 -0500118# Set ``SWIFT_LOG_TOKEN_LENGTH`` to configure how many characters of an auth
119# token should be placed in the logs. When keystone is used with PKI tokens,
120# the token values can be huge, seemingly larger the 2K, at the least. We
121# restrict it here to a default of 12 characters, which should be enough to
122# trace through the logs when looking for its use.
123SWIFT_LOG_TOKEN_LENGTH=${SWIFT_LOG_TOKEN_LENGTH:-12}
124
Julien Vey63024d92014-05-06 15:10:07 +0200125# Set ``SWIFT_MAX_HEADER_SIZE`` to configure the maximun length of headers in
126# Swift API
127SWIFT_MAX_HEADER_SIZE=${SWIFT_MAX_HEADER_SIZE:-16384}
128
Attila Fazekasece6a332012-11-29 14:19:41 +0100129# Set ``OBJECT_PORT_BASE``, ``CONTAINER_PORT_BASE``, ``ACCOUNT_PORT_BASE``
130# Port bases used in port number calclution for the service "nodes"
131# The specified port number will be used, the additinal ports calculated by
132# base_port + node_num * 10
Dean Troyer1151d6f2013-03-29 14:06:52 -0500133OBJECT_PORT_BASE=${OBJECT_PORT_BASE:-6013}
134CONTAINER_PORT_BASE=${CONTAINER_PORT_BASE:-6011}
135ACCOUNT_PORT_BASE=${ACCOUNT_PORT_BASE:-6012}
Attila Fazekasece6a332012-11-29 14:19:41 +0100136
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000137# Enable tempurl feature
138SWIFT_ENABLE_TEMPURLS=${SWIFT_ENABLE_TEMPURLS:-False}
Sean Dague53753292014-12-04 19:38:15 -0500139SWIFT_TEMPURL_KEY=${SWIFT_TEMPURL_KEY:-}
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000140
Dean Troyerdc97cb72015-03-28 08:20:50 -0500141# Toggle for deploying Swift under HTTPD + mod_wsgi
142SWIFT_USE_MOD_WSGI=${SWIFT_USE_MOD_WSGI:-False}
143
Dean Troyer4237f592014-01-29 16:22:11 -0600144# Tell Tempest this project is present
145TEMPEST_SERVICES+=,swift
146
Dean Troyer6d04fd72012-12-21 11:03:37 -0600147
Dean Troyercc6b4432013-04-08 15:38:03 -0500148# Functions
149# ---------
Attila Fazekasece6a332012-11-29 14:19:41 +0100150
Dean Troyere4fa7212014-01-15 15:04:49 -0600151# Test if any Swift services are enabled
152# is_swift_enabled
153function is_swift_enabled {
154 [[ ,${ENABLED_SERVICES} =~ ,"s-" ]] && return 0
155 return 1
156}
157
Attila Fazekasece6a332012-11-29 14:19:41 +0100158# cleanup_swift() - Remove residual data files
Ian Wienandaee18c72014-02-21 15:35:08 +1100159function cleanup_swift {
Sean Dague101b4242013-10-22 08:47:11 -0400160 rm -f ${SWIFT_CONF_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz}
161 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
162 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
163 fi
164 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
165 rm ${SWIFT_DISK_IMAGE}
166 fi
167 rm -rf ${SWIFT_DATA_DIR}/run/
Morgan Fainberg46455a32014-06-20 10:37:18 -0700168 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
Sean Dague101b4242013-10-22 08:47:11 -0400169 _cleanup_swift_apache_wsgi
170 fi
zhang-hared98a5d02013-06-21 18:18:02 +0800171}
172
173# _cleanup_swift_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
Ian Wienandaee18c72014-02-21 15:35:08 +1100174function _cleanup_swift_apache_wsgi {
zhang-hared98a5d02013-06-21 18:18:02 +0800175 sudo rm -f $SWIFT_APACHE_WSGI_DIR/*.wsgi
Jamie Lennox54707012013-09-17 12:07:48 +1000176 disable_apache_site proxy-server
Dean Troyer084f51f2014-07-25 15:08:52 -0500177 local node_number type
zhang-hared98a5d02013-06-21 18:18:02 +0800178 for node_number in ${SWIFT_REPLICAS_SEQ}; do
179 for type in object container account; do
Dean Troyer084f51f2014-07-25 15:08:52 -0500180 local site_name=${type}-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000181 disable_apache_site ${site_name}
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000182 sudo rm -f $(apache_site_config_for ${site_name})
zhang-hared98a5d02013-06-21 18:18:02 +0800183 done
184 done
185}
186
187# _config_swift_apache_wsgi() - Set WSGI config files of Swift
Ian Wienandaee18c72014-02-21 15:35:08 +1100188function _config_swift_apache_wsgi {
zhang-hared98a5d02013-06-21 18:18:02 +0800189 sudo mkdir -p ${SWIFT_APACHE_WSGI_DIR}
zhang-hared98a5d02013-06-21 18:18:02 +0800190 local proxy_port=${SWIFT_DEFAULT_BIND_PORT:-8080}
191
192 # copy proxy vhost and wsgi file
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000193 sudo cp ${SWIFT_DIR}/examples/apache2/proxy-server.template $(apache_site_config_for proxy-server)
zhang-hared98a5d02013-06-21 18:18:02 +0800194 sudo sed -e "
195 /^#/d;/^$/d;
196 s/%PORT%/$proxy_port/g;
197 s/%SERVICENAME%/proxy-server/g;
198 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000199 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000200 " -i $(apache_site_config_for proxy-server)
Jamie Lennox54707012013-09-17 12:07:48 +1000201 enable_apache_site proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800202
203 sudo cp ${SWIFT_DIR}/examples/wsgi/proxy-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
204 sudo sed -e "
205 /^#/d;/^$/d;
206 s/%SERVICECONF%/proxy-server.conf/g;
207 " -i ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800208
209 # copy apache vhost file and set name and port
Dean Troyer084f51f2014-07-25 15:08:52 -0500210 local node_number
zhang-hared98a5d02013-06-21 18:18:02 +0800211 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Ian Wienand761c4562014-10-21 11:41:37 +1100212 local object_port=$(( OBJECT_PORT_BASE + 10 * (node_number - 1) ))
213 local container_port=$(( CONTAINER_PORT_BASE + 10 * (node_number - 1) ))
214 local account_port=$(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) ))
zhang-hared98a5d02013-06-21 18:18:02 +0800215
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000216 sudo cp ${SWIFT_DIR}/examples/apache2/object-server.template $(apache_site_config_for object-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800217 sudo sed -e "
218 s/%PORT%/$object_port/g;
219 s/%SERVICENAME%/object-server-${node_number}/g;
220 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000221 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000222 " -i $(apache_site_config_for object-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000223 enable_apache_site object-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800224
225 sudo cp ${SWIFT_DIR}/examples/wsgi/object-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
226 sudo sed -e "
227 /^#/d;/^$/d;
228 s/%SERVICECONF%/object-server\/${node_number}.conf/g;
229 " -i ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
230
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000231 sudo cp ${SWIFT_DIR}/examples/apache2/container-server.template $(apache_site_config_for container-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800232 sudo sed -e "
233 /^#/d;/^$/d;
234 s/%PORT%/$container_port/g;
235 s/%SERVICENAME%/container-server-${node_number}/g;
236 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000237 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000238 " -i $(apache_site_config_for container-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000239 enable_apache_site container-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800240
241 sudo cp ${SWIFT_DIR}/examples/wsgi/container-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
242 sudo sed -e "
243 /^#/d;/^$/d;
244 s/%SERVICECONF%/container-server\/${node_number}.conf/g;
245 " -i ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
246
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000247 sudo cp ${SWIFT_DIR}/examples/apache2/account-server.template $(apache_site_config_for account-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800248 sudo sed -e "
Sean Dague101b4242013-10-22 08:47:11 -0400249 /^#/d;/^$/d;
zhang-hared98a5d02013-06-21 18:18:02 +0800250 s/%PORT%/$account_port/g;
251 s/%SERVICENAME%/account-server-${node_number}/g;
252 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000253 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000254 " -i $(apache_site_config_for account-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000255 enable_apache_site account-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800256
257 sudo cp ${SWIFT_DIR}/examples/wsgi/account-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
258 sudo sed -e "
Sean Dague101b4242013-10-22 08:47:11 -0400259 /^#/d;/^$/d;
zhang-hared98a5d02013-06-21 18:18:02 +0800260 s/%SERVICECONF%/account-server\/${node_number}.conf/g;
261 " -i ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800262 done
Attila Fazekasece6a332012-11-29 14:19:41 +0100263}
264
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100265# This function generates an object/container/account configuration
266# emulating 4 nodes on different ports
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200267function generate_swift_config_services {
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100268 local swift_node_config=$1
269 local node_id=$2
270 local bind_port=$3
271 local server_type=$4
272
Ian Wienand761c4562014-10-21 11:41:37 +1100273 log_facility=$(( node_id - 1 ))
Dean Troyer084f51f2014-07-25 15:08:52 -0500274 local node_path=${SWIFT_DATA_DIR}/${node_number}
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100275
276 iniuncomment ${swift_node_config} DEFAULT user
277 iniset ${swift_node_config} DEFAULT user ${STACK_USER}
278
279 iniuncomment ${swift_node_config} DEFAULT bind_port
280 iniset ${swift_node_config} DEFAULT bind_port ${bind_port}
281
282 iniuncomment ${swift_node_config} DEFAULT swift_dir
283 iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR}
284
285 iniuncomment ${swift_node_config} DEFAULT devices
286 iniset ${swift_node_config} DEFAULT devices ${node_path}
287
288 iniuncomment ${swift_node_config} DEFAULT log_facility
289 iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility}
290
291 iniuncomment ${swift_node_config} DEFAULT workers
Chmouel Boudjnah55dc2c22014-09-12 09:34:20 +0200292 iniset ${swift_node_config} DEFAULT workers ${API_WORKERS:-1}
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100293
294 iniuncomment ${swift_node_config} DEFAULT disable_fallocate
295 iniset ${swift_node_config} DEFAULT disable_fallocate true
296
297 iniuncomment ${swift_node_config} DEFAULT mount_check
298 iniset ${swift_node_config} DEFAULT mount_check false
299
300 iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode
301 iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200302
303 # Using a sed and not iniset/iniuncomment because we want to a global
304 # modification and make sure it works for new sections.
305 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100306}
307
Attila Fazekasece6a332012-11-29 14:19:41 +0100308# configure_swift() - Set config files, create data dirs and loop image
Ian Wienandaee18c72014-02-21 15:35:08 +1100309function configure_swift {
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200310 local swift_pipeline="${SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH}"
Attila Fazekasece6a332012-11-29 14:19:41 +0100311 local node_number
312 local swift_node_config
313 local swift_log_dir
Geronimo Orozco2f6576b2015-03-19 12:08:23 -0600314 local user_group
Attila Fazekasece6a332012-11-29 14:19:41 +0100315
Attila Fazekasece6a332012-11-29 14:19:41 +0100316 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100317 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100318
Dean Troyer8421c2b2015-03-16 13:52:19 -0500319 sudo install -d -o ${STACK_USER} ${SWIFT_CONF_DIR}
320 sudo install -d -o ${STACK_USER} ${SWIFT_CONF_DIR}/{object,container,account}-server
Attila Fazekasece6a332012-11-29 14:19:41 +0100321
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500322 if [[ "$SWIFT_CONF_DIR" != "/etc/swift" ]]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100323 # Some swift tools are hard-coded to use ``/etc/swift`` and are apparently not going to be fixed.
324 # Create a symlink if the config dir is moved
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500325 sudo ln -sf ${SWIFT_CONF_DIR} /etc/swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100326 fi
327
328 # Swift use rsync to synchronize between all the different
329 # partitions (which make more sense when you have a multi-node
330 # setup) we configure it with our version of rsync.
331 sed -e "
332 s/%GROUP%/${USER_GROUP}/;
Stephan Renatuse578eff2013-11-19 13:31:04 +0100333 s/%USER%/${STACK_USER}/;
Attila Fazekasece6a332012-11-29 14:19:41 +0100334 s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,;
335 " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf
336 # rsyncd.conf just prepared for 4 nodes
Vincent Untzc18b9652012-12-04 12:36:34 +0100337 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100338 sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync
Attila Fazekas0e57b962014-02-28 09:09:52 +0100339 elif [ -e /etc/xinetd.d/rsync ]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100340 sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync
341 fi
342
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500343 SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONF_DIR}/proxy-server.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100344 cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER}
345
Daisuke Moritad03915f2014-10-08 06:52:21 +0000346 # To run container sync feature introduced in Swift ver 1.12.0,
347 # container sync "realm" is added in container-sync-realms.conf
348 local csyncfile=${SWIFT_CONF_DIR}/container-sync-realms.conf
349 cp ${SWIFT_DIR}/etc/container-sync-realms.conf-sample ${csyncfile}
350 iniset ${csyncfile} realm1 key realm1key
351 iniset ${csyncfile} realm1 cluster_name1 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:8080/v1/"
Chmouel Boudjnahf2c1a712014-01-29 21:38:14 +0000352
Attila Fazekasece6a332012-11-29 14:19:41 +0100353 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user
Stephan Renatuse578eff2013-11-19 13:31:04 +0100354 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${STACK_USER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100355
356 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500357 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100358
359 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers
360 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1
361
362 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level
363 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG
364
Rawlin Peters92ad1522015-07-20 13:33:33 -0600365 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_ip
366 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_ip ${SWIFT_SERVICE_LISTEN_ADDRESS}
367
Attila Fazekasece6a332012-11-29 14:19:41 +0100368 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port
Rob Crittenden18d47782014-03-19 17:47:42 -0400369 if is_service_enabled tls-proxy; then
370 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT_INT}
371 else
372 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT:-8080}
373 fi
374
375 if is_ssl_enabled_service s-proxy; then
376 ensure_certificates SWIFT
377
378 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT cert_file "$SWIFT_SSL_CERT"
379 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT key_file "$SWIFT_SSL_KEY"
380 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100381
Dean Troyerdc97cb72015-03-28 08:20:50 -0500382 # DevStack is commonly run in a small slow environment, so bump the timeouts up.
383 # ``node_timeout`` is the node read operation response time to the proxy server
384 # ``conn_timeout`` is how long it takes a connect() system call to return
Joe Gordond254da52013-11-19 21:06:29 -0800385 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server node_timeout 120
386 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server conn_timeout 20
387
Dina Belovaeedfdee2014-06-24 16:52:46 +0400388 # Configure Ceilometer
389 if is_service_enabled ceilometer; then
390 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer "set log_level" "WARN"
gordon chungb6197e62015-02-12 15:33:35 -0500391 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer paste.filter_factory "ceilometermiddleware.swift:filter_factory"
392 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer control_exchange "swift"
393 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer url $(get_transport_url)
394 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer driver "messaging"
395 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer topic "notifications"
Dina Belovaeedfdee2014-06-24 16:52:46 +0400396 SWIFT_EXTRAS_MIDDLEWARE_LAST="${SWIFT_EXTRAS_MIDDLEWARE_LAST} ceilometer"
397 fi
Cyril Roelandtd9883402013-09-27 15:16:51 +0000398
Dean Troyerdc97cb72015-03-28 08:20:50 -0500399 # Restrict the length of auth tokens in the Swift ``proxy-server`` logs.
Peter Portantecee4b3b2013-11-20 14:33:16 -0500400 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:proxy-logging reveal_sensitive_prefix ${SWIFT_LOG_TOKEN_LENGTH}
401
Dean Troyerdc97cb72015-03-28 08:20:50 -0500402 # By default Swift will be installed with Keystone and tempauth middleware
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000403 # and add the swift3 middleware if its configured for it. The token for
Adam Spierscb961592013-10-05 12:11:07 +0100404 # tempauth would be prefixed with the reseller_prefix setting `TEMPAUTH_` the
405 # token for keystoneauth would have the standard reseller_prefix `AUTH_`
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000406 if is_service_enabled swift3;then
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200407 swift_pipeline+=" swift3 s3token "
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100408 fi
Chmouel Boudjnah254fd552014-06-30 12:22:59 +0000409
Dean Troyer5ce44cd2015-02-12 22:18:33 -0600410 if is_service_enabled keystone; then
Chmouel Boudjnah254fd552014-06-30 12:22:59 +0000411 swift_pipeline+=" authtoken keystoneauth"
412 fi
413 swift_pipeline+=" tempauth "
414
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100415 sed -i "/^pipeline/ { s/tempauth/${swift_pipeline} ${SWIFT_EXTRAS_MIDDLEWARE}/ ;}" ${SWIFT_CONFIG_PROXY_SERVER}
Cyril Roelandtd9883402013-09-27 15:16:51 +0000416 sed -i "/^pipeline/ { s/proxy-server/${SWIFT_EXTRAS_MIDDLEWARE_LAST} proxy-server/ ; }" ${SWIFT_CONFIG_PROXY_SERVER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100417
418 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true
419
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200420 # Configure Crossdomain
421 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:crossdomain use "egg:swift#crossdomain"
422
Dean Troyerdc97cb72015-03-28 08:20:50 -0500423 # Configure authtoken middleware to use the same Python logging
424 # adapter provided by the Swift ``proxy-server``, so that request transaction
Peter Portante8afc8932013-11-20 17:34:39 -0500425 # IDs will included in all of its log messages.
426 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken log_name swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100427
Jamie Lennox38c95b82015-01-30 02:15:42 +0000428 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken paste.filter_factory keystonemiddleware.auth_token:filter_factory
Jamie Lennox6ac97de2015-03-12 09:03:28 +1100429 configure_auth_token_middleware $SWIFT_CONFIG_PROXY_SERVER swift $SWIFT_AUTH_CACHE_DIR filter:authtoken
Jamie Lennox38c95b82015-01-30 02:15:42 +0000430 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken delay_auth_decision 1
431 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken cache swift.cache
432 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken include_service_catalog False
433
434 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use "egg:swift#keystoneauth"
Attila Fazekasece6a332012-11-29 14:19:41 +0100435 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin"
436
Dean Troyerdc97cb72015-03-28 08:20:50 -0500437 # Configure Tempauth. In the sample config file Keystoneauth is commented
Donagh McCabe7faceb62014-12-19 13:20:45 +0000438 # out. Make sure we uncomment Tempauth after we uncomment Keystoneauth
439 # otherwise, this code also sets the reseller_prefix for Keystoneauth.
440 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth account_autocreate
441 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix
442 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix "TEMPAUTH"
443
Attila Fazekasece6a332012-11-29 14:19:41 +0100444 if is_service_enabled swift3; then
445 cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100446[filter:s3token]
Cyril Roelandte8a2fa42015-05-06 17:30:48 +0200447paste.filter_factory = keystonemiddleware.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 Fazekasfbb3e772015-03-03 15:08:28 +0100452admin_user = swift
453admin_tenant_name = ${SERVICE_TENANT_NAME}
454admin_password = ${SERVICE_PASSWORD}
Attila Fazekasece6a332012-11-29 14:19:41 +0100455
456[filter:swift3]
457use = egg:swift3#swift3
458EOF
459 fi
460
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500461 cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf
462 iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH}
Julien Vey63024d92014-05-06 15:10:07 +0200463 iniset ${SWIFT_CONF_DIR}/swift.conf swift-constraints max_header_size ${SWIFT_MAX_HEADER_SIZE}
Attila Fazekasece6a332012-11-29 14:19:41 +0100464
Dean Troyer084f51f2014-07-25 15:08:52 -0500465 local node_number
Attila Fazekasece6a332012-11-29 14:19:41 +0100466 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Dean Troyer084f51f2014-07-25 15:08:52 -0500467 local swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100468 cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config}
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200469 generate_swift_config_services ${swift_node_config} ${node_number} $(( OBJECT_PORT_BASE + 10 * (node_number - 1) )) object
Rawlin Peters92ad1522015-07-20 13:33:33 -0600470 iniuncomment ${swift_node_config} DEFAULT bind_ip
471 iniset ${swift_node_config} DEFAULT bind_ip ${SWIFT_SERVICE_LISTEN_ADDRESS}
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000472 iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache
Attila Fazekasece6a332012-11-29 14:19:41 +0100473
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500474 swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100475 cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config}
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200476 generate_swift_config_services ${swift_node_config} ${node_number} $(( CONTAINER_PORT_BASE + 10 * (node_number - 1) )) container
Rawlin Peters92ad1522015-07-20 13:33:33 -0600477 iniuncomment ${swift_node_config} DEFAULT bind_ip
478 iniset ${swift_node_config} DEFAULT bind_ip ${SWIFT_SERVICE_LISTEN_ADDRESS}
Attila Fazekas83e10952012-11-30 23:28:07 +0100479 iniuncomment ${swift_node_config} app:container-server allow_versions
480 iniset ${swift_node_config} app:container-server allow_versions "true"
Attila Fazekasece6a332012-11-29 14:19:41 +0100481
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500482 swift_node_config=${SWIFT_CONF_DIR}/account-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100483 cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config}
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200484 generate_swift_config_services ${swift_node_config} ${node_number} $(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) )) account
Rawlin Peters92ad1522015-07-20 13:33:33 -0600485 iniuncomment ${swift_node_config} DEFAULT bind_ip
486 iniset ${swift_node_config} DEFAULT bind_ip ${SWIFT_SERVICE_LISTEN_ADDRESS}
Attila Fazekasece6a332012-11-29 14:19:41 +0100487 done
488
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000489 # Set new accounts in tempauth to match keystone tenant/user (to make testing easier)
490 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest1 "testing .admin"
491 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest2_swiftusertest2 "testing2 .admin"
492 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest3 "testing3 .admin"
493
494 testfile=${SWIFT_CONF_DIR}/test.conf
495 cp ${SWIFT_DIR}/test/sample.conf ${testfile}
496
497 # Set accounts for functional tests
498 iniset ${testfile} func_test account swifttenanttest1
499 iniset ${testfile} func_test username swiftusertest1
500 iniset ${testfile} func_test username3 swiftusertest3
501 iniset ${testfile} func_test account2 swifttenanttest2
502 iniset ${testfile} func_test username2 swiftusertest2
Alistair Coles24779f62014-10-15 18:57:59 +0100503 iniset ${testfile} func_test account4 swifttenanttest4
504 iniset ${testfile} func_test username4 swiftusertest4
505 iniset ${testfile} func_test password4 testing4
506 iniset ${testfile} func_test domain4 swift_test
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000507
Dean Troyer5ce44cd2015-02-12 22:18:33 -0600508 if is_service_enabled keystone; then
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000509 iniuncomment ${testfile} func_test auth_version
Alistair Coles24779f62014-10-15 18:57:59 +0100510 local auth_vers=$(iniget ${testfile} func_test auth_version)
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000511 iniset ${testfile} func_test auth_host ${KEYSTONE_SERVICE_HOST}
512 iniset ${testfile} func_test auth_port ${KEYSTONE_AUTH_PORT}
Alistair Coles24779f62014-10-15 18:57:59 +0100513 if [[ $auth_vers == "3" ]]; then
514 iniset ${testfile} func_test auth_prefix /v3/
515 else
516 iniset ${testfile} func_test auth_prefix /v2.0/
517 fi
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000518 fi
519
Geronimo Orozco2f6576b2015-03-19 12:08:23 -0600520 local user_group=$(id -g ${STACK_USER})
521 sudo install -d -o ${STACK_USER} -g ${user_group} ${SWIFT_DATA_DIR}
522
Dean Troyer084f51f2014-07-25 15:08:52 -0500523 local swift_log_dir=${SWIFT_DATA_DIR}/logs
Geronimo Orozco2f6576b2015-03-19 12:08:23 -0600524 sudo rm -rf ${swift_log_dir}
525 sudo install -d -o ${STACK_USER} -g adm ${swift_log_dir}/hourly
Yves-Gwenael Bourhisf894c2a2014-04-16 13:37:46 +0200526
527 if [[ $SYSLOG != "False" ]]; then
528 sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
529 tee /etc/rsyslog.d/10-swift.conf
530 # restart syslog to take the changes
531 sudo killall -HUP rsyslogd
532 fi
Sean Daguead7e8c62014-03-19 19:13:20 -0400533
Morgan Fainberg46455a32014-06-20 10:37:18 -0700534 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800535 _config_swift_apache_wsgi
536 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100537}
538
Dean Troyer1c6c1122013-03-27 17:40:53 -0500539# create_swift_disk - Create Swift backing disk
Ian Wienandaee18c72014-02-21 15:35:08 +1100540function create_swift_disk {
Dean Troyer1c6c1122013-03-27 17:40:53 -0500541 local node_number
542
543 # First do a bit of setup by creating the directories and
544 # changing the permissions so we can run it as our user.
545
Dean Troyer084f51f2014-07-25 15:08:52 -0500546 local user_group=$(id -g ${STACK_USER})
Dean Troyer8421c2b2015-03-16 13:52:19 -0500547 sudo install -d -o ${STACK_USER} -g ${user_group} ${SWIFT_DATA_DIR}/{drives,cache,run,logs}
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}
Dean Troyerdc97cb72015-03-28 08:20:50 -0500588
589# create_swift_accounts() - Set up standard Swift accounts and extra
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200590# one for tests we do this by attaching all words in the account name
591# since we want to make it compatible with tempauth which use
592# underscores for separators.
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000593
Alistair Coles24779f62014-10-15 18:57:59 +0100594# Tenant User Roles Domain
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000595# ------------------------------------------------------------------
Alistair Coles24779f62014-10-15 18:57:59 +0100596# service swift service default
597# swifttenanttest1 swiftusertest1 admin default
598# swifttenanttest1 swiftusertest3 anotherrole default
599# swifttenanttest2 swiftusertest2 admin default
600# swifttenanttest4 swiftusertest4 admin swift_test
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000601
Ian Wienandaee18c72014-02-21 15:35:08 +1100602function create_swift_accounts {
Dean Troyerdc97cb72015-03-28 08:20:50 -0500603 # Defines specific passwords used by ``tools/create_userrc.sh``
604 # As these variables are used by ``create_userrc.sh,`` they must be exported
605 # The _password suffix is expected by ``create_userrc.sh``.
JordanP7c6d0052014-10-06 23:08:50 +0200606 export swiftusertest1_password=testing
607 export swiftusertest2_password=testing2
608 export swiftusertest3_password=testing3
Alistair Coles24779f62014-10-15 18:57:59 +0100609 export swiftusertest4_password=testing4
Sahid Orentino Ferdjaoui1814e672014-02-11 17:56:07 +0100610
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200611 KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql}
612
Jamie Lennoxdbdee692015-08-14 12:22:18 +1000613 local another_role=$(get_or_create_role "anotherrole")
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200614
Jim Rollenhagenae74ed72015-02-12 07:33:36 -0800615 # NOTE(jroll): Swift doesn't need the admin role here, however Ironic uses
616 # temp urls, which break when uploaded by a non-admin role
617 create_service_user "swift" "admin"
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200618
619 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100620
Jamie Lennoxb17ad752015-05-29 06:04:47 +0000621 get_or_create_service "swift" "object-store" "Swift Service"
622 get_or_create_endpoint "object-store" \
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
Jamie Lennoxb632c9e2015-05-28 23:36:15 +0000629 local swift_tenant_test1=$(get_or_create_project swifttenanttest1 default)
Dean Troyer084f51f2014-07-25 15:08:52 -0500630 die_if_not_set $LINENO swift_tenant_test1 "Failure creating swift_tenant_test1"
Jamie Lennox9d7e7762015-05-29 01:08:53 +0000631 SWIFT_USER_TEST1=$(get_or_create_user swiftusertest1 $swiftusertest1_password \
632 "default" "test@example.com")
DennyZhang23178a92013-10-22 17:07:32 -0500633 die_if_not_set $LINENO SWIFT_USER_TEST1 "Failure creating SWIFT_USER_TEST1"
Jamie Lennox9b215db2015-02-10 18:19:57 +1100634 get_or_add_user_project_role admin $SWIFT_USER_TEST1 $swift_tenant_test1
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000635
Jamie Lennox9d7e7762015-05-29 01:08:53 +0000636 local swift_user_test3=$(get_or_create_user swiftusertest3 $swiftusertest3_password \
637 "default" "test3@example.com")
Dean Troyer084f51f2014-07-25 15:08:52 -0500638 die_if_not_set $LINENO swift_user_test3 "Failure creating swift_user_test3"
Jamie Lennox9b215db2015-02-10 18:19:57 +1100639 get_or_add_user_project_role $another_role $swift_user_test3 $swift_tenant_test1
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000640
Jamie Lennoxb632c9e2015-05-28 23:36:15 +0000641 local swift_tenant_test2=$(get_or_create_project swifttenanttest2 default)
Dean Troyer084f51f2014-07-25 15:08:52 -0500642 die_if_not_set $LINENO swift_tenant_test2 "Failure creating swift_tenant_test2"
Steve Martinelli19685422014-01-24 13:02:26 -0600643
Jamie Lennox9d7e7762015-05-29 01:08:53 +0000644 local swift_user_test2=$(get_or_create_user swiftusertest2 $swiftusertest2_password \
645 "default" "test2@example.com")
Dean Troyer084f51f2014-07-25 15:08:52 -0500646 die_if_not_set $LINENO swift_user_test2 "Failure creating swift_user_test2"
Jamie Lennox9b215db2015-02-10 18:19:57 +1100647 get_or_add_user_project_role admin $swift_user_test2 $swift_tenant_test2
Alistair Coles24779f62014-10-15 18:57:59 +0100648
649 local swift_domain=$(get_or_create_domain swift_test 'Used for swift functional testing')
650 die_if_not_set $LINENO swift_domain "Failure creating swift_test domain"
651
652 local swift_tenant_test4=$(get_or_create_project swifttenanttest4 $swift_domain)
653 die_if_not_set $LINENO swift_tenant_test4 "Failure creating swift_tenant_test4"
Jamie Lennox18f39bf2015-01-28 13:38:32 +1000654
Jamie Lennox9d7e7762015-05-29 01:08:53 +0000655 local swift_user_test4=$(get_or_create_user swiftusertest4 $swiftusertest4_password \
656 $swift_domain "test4@example.com")
Alistair Coles24779f62014-10-15 18:57:59 +0100657 die_if_not_set $LINENO swift_user_test4 "Failure creating swift_user_test4"
Jamie Lennox9b215db2015-02-10 18:19:57 +1100658 get_or_add_user_project_role admin $swift_user_test4 $swift_tenant_test4
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000659}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500660
Attila Fazekasece6a332012-11-29 14:19:41 +0100661# init_swift() - Initialize rings
Ian Wienandaee18c72014-02-21 15:35:08 +1100662function init_swift {
Attila Fazekasece6a332012-11-29 14:19:41 +0100663 local node_number
664 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100665 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100666
Dean Troyer1c6c1122013-03-27 17:40:53 -0500667 # Forcibly re-create the backing filesystem
668 create_swift_disk
669
Attila Fazekasece6a332012-11-29 14:19:41 +0100670 # This is where we create three different rings for swift with
671 # different object servers binding on different ports.
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500672 pushd ${SWIFT_CONF_DIR} >/dev/null && {
Attila Fazekasece6a332012-11-29 14:19:41 +0100673
674 rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
675
676 swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
677 swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
678 swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
679
680 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Brian Haley180f5eb2015-06-16 13:14:31 -0400681 swift-ring-builder object.builder add z${node_number}-${SWIFT_SERVICE_LOCAL_HOST}:$(( OBJECT_PORT_BASE + 10 * (node_number - 1) ))/sdb1 1
682 swift-ring-builder container.builder add z${node_number}-${SWIFT_SERVICE_LOCAL_HOST}:$(( CONTAINER_PORT_BASE + 10 * (node_number - 1) ))/sdb1 1
683 swift-ring-builder account.builder add z${node_number}-${SWIFT_SERVICE_LOCAL_HOST}:$(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) ))/sdb1 1
Attila Fazekasece6a332012-11-29 14:19:41 +0100684 done
685 swift-ring-builder object.builder rebalance
686 swift-ring-builder container.builder rebalance
687 swift-ring-builder account.builder rebalance
688 } && popd >/dev/null
689
Dean Troyer64ab7742012-12-28 15:38:28 -0600690 # Create cache dir
Dean Troyer8421c2b2015-03-16 13:52:19 -0500691 sudo install -d -o ${STACK_USER} $SWIFT_AUTH_CACHE_DIR
Dean Troyer64ab7742012-12-28 15:38:28 -0600692 rm -f $SWIFT_AUTH_CACHE_DIR/*
Attila Fazekasece6a332012-11-29 14:19:41 +0100693}
694
Ian Wienandaee18c72014-02-21 15:35:08 +1100695function install_swift {
Attila Fazekasece6a332012-11-29 14:19:41 +0100696 git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500697 setup_develop $SWIFT_DIR
Morgan Fainberg46455a32014-06-20 10:37:18 -0700698 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800699 install_apache_wsgi
700 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100701}
702
Ian Wienandaee18c72014-02-21 15:35:08 +1100703function install_swiftclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500704 if use_library_from_git "python-swiftclient"; then
705 git_clone_by_name "python-swiftclient"
706 setup_dev_lib "python-swiftclient"
Sean Dague5cb19062014-11-01 01:37:45 +0100707 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100708}
709
Chris Dent1848b832015-06-27 15:05:17 +0100710# install_ceilometermiddleware() - Collect source and prepare
711# note that this doesn't really have anything to do with ceilometer;
712# though ceilometermiddleware has ceilometer in its name as an
713# artifact of history, it is not a ceilometer specific tool. It
714# simply generates pycadf-based notifications about requests and
715# responses on the swift proxy
716function install_ceilometermiddleware {
717 if use_library_from_git "ceilometermiddleware"; then
718 git_clone_by_name "ceilometermiddleware"
719 setup_dev_lib "ceilometermiddleware"
720 else
721 pip_install_gr ceilometermiddleware
722 fi
723}
724
Attila Fazekasece6a332012-11-29 14:19:41 +0100725# start_swift() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100726function start_swift {
Chmouel Boudjnah8ecbb382013-03-12 12:15:17 +0100727 # (re)start memcached to make sure we have a clean memcache.
728 restart_service memcached
729
Attila Fazekasece6a332012-11-29 14:19:41 +0100730 # Start rsync
Vincent Untzc18b9652012-12-04 12:36:34 +0100731 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100732 sudo /etc/init.d/rsync restart || :
Attila Fazekas0e57b962014-02-28 09:09:52 +0100733 elif [ -e /etc/xinetd.d/rsync ]; then
734 start_service xinetd
Attila Fazekasece6a332012-11-29 14:19:41 +0100735 else
Attila Fazekas0e57b962014-02-28 09:09:52 +0100736 start_service rsyncd
Attila Fazekasece6a332012-11-29 14:19:41 +0100737 fi
738
Morgan Fainberg46455a32014-06-20 10:37:18 -0700739 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800740 restart_apache_server
741 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest start
Chris Dent2f27a0e2014-09-09 13:46:02 +0100742 tail_log s-proxy /var/log/$APACHE_NAME/proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800743 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
744 for type in object container account; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100745 tail_log s-${type} /var/log/$APACHE_NAME/${type}-server-1
zhang-hared98a5d02013-06-21 18:18:02 +0800746 done
747 fi
748 return 0
749 fi
750
Sean Dague101b4242013-10-22 08:47:11 -0400751 # By default with only one replica we are launching the proxy,
752 # container, account and object server in screen in foreground and
Dean Troyerdc97cb72015-03-28 08:20:50 -0500753 # other services in background. If we have ``SWIFT_REPLICAS`` set to something
754 # greater than one we first spawn all the Swift services then kill the proxy
Sean Dague101b4242013-10-22 08:47:11 -0400755 # service so we can run it in foreground in screen. ``swift-init ...
756 # {stop|restart}`` exits with '1' if no servers are running, ignore it just
757 # in case
Dean Troyer084f51f2014-07-25 15:08:52 -0500758 local todo type
Sean Dague101b4242013-10-22 08:47:11 -0400759 swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true
760 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100761 todo="object container account"
Sean Dague101b4242013-10-22 08:47:11 -0400762 fi
763 for type in proxy ${todo}; do
764 swift-init --run-dir=${SWIFT_DATA_DIR}/run ${type} stop || true
765 done
Rob Crittenden18d47782014-03-19 17:47:42 -0400766 if is_service_enabled tls-proxy; then
767 local proxy_port=${SWIFT_DEFAULT_BIND_PORT:-8080}
768 start_tls_proxy '*' $proxy_port $SERVICE_HOST $SWIFT_DEFAULT_BIND_PORT_INT &
769 fi
Chris Dent2f27a0e2014-09-09 13:46:02 +0100770 run_process s-proxy "$SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v"
Sean Dague101b4242013-10-22 08:47:11 -0400771 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
772 for type in object container account; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100773 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 -0400774 done
775 fi
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000776
777 if [[ "$SWIFT_ENABLE_TEMPURLS" == "True" ]]; then
778 swift_configure_tempurls
779 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100780}
781
782# stop_swift() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100783function stop_swift {
Dean Troyer084f51f2014-07-25 15:08:52 -0500784 local type
zhang-hared98a5d02013-06-21 18:18:02 +0800785
Morgan Fainberg46455a32014-06-20 10:37:18 -0700786 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800787 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest stop && return 0
788 fi
789
Dean Troyerdc97cb72015-03-28 08:20:50 -0500790 # screen normally killed by ``unstack.sh``
Dean Troyer995eb922013-03-07 16:11:40 -0600791 if type -p swift-init >/dev/null; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100792 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
793 fi
Chmouel Boudjnahf36a9b22014-02-03 23:44:47 +0100794 # Dump all of the servers
Chris Dent2f27a0e2014-09-09 13:46:02 +0100795 # Maintain the iteration as stop_process() has some desirable side-effects
Dean Troyer1eae3e12014-03-06 11:49:22 -0600796 for type in proxy object container account; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100797 stop_process s-${type}
Dean Troyer1eae3e12014-03-06 11:49:22 -0600798 done
799 # Blast out any stragglers
Attila Fazekasf750a6f2015-07-01 12:17:35 +0200800 pkill -f swift- || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100801}
802
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000803function swift_configure_tempurls {
804 OS_USERNAME=swift \
805 OS_TENANT_NAME=$SERVICE_TENANT_NAME \
806 OS_PASSWORD=$SERVICE_PASSWORD \
807 swift post -m "Temp-URL-Key: $SWIFT_TEMPURL_KEY"
808}
809
Attila Fazekasece6a332012-11-29 14:19:41 +0100810# Restore xtrace
811$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400812
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100813# Tell emacs to use shell-script-mode
814## Local variables:
815## mode: shell-script
816## End: