blob: aeb56c7efd84f6c12737d3e9f6c7c318b87da6f8 [file] [log] [blame]
Attila Fazekasece6a332012-11-29 14:19:41 +01001# lib/swift
Dean Troyer6d04fd72012-12-21 11:03:37 -06002# Functions to control the configuration and operation of the **Swift** service
Attila Fazekasece6a332012-11-29 14:19:41 +01003
4# Dependencies:
5# ``functions`` file
6# ``DEST``, ``SCREEN_NAME``, `SWIFT_HASH` must be defined
Attila Fazekas91b8d132013-01-06 22:40:09 +01007# ``STACK_USER`` must be defined
Attila Fazekasece6a332012-11-29 14:19:41 +01008# ``SWIFT_DATA_DIR`` or ``DATA_DIR`` must be defined
9# ``lib/keystone`` file
10# ``stack.sh`` calls the entry points in this order:
11#
12# install_swift
13# configure_swift
14# init_swift
15# start_swift
16# stop_swift
17# cleanup_swift
18
19# Save trace setting
20XTRACE=$(set +o | grep xtrace)
21set +o xtrace
22
23
24# Defaults
25# --------
26
Attila Fazekasece6a332012-11-29 14:19:41 +010027# Set up default directories
Attila Fazekasece6a332012-11-29 14:19:41 +010028SWIFT_DIR=$DEST/swift
29SWIFTCLIENT_DIR=$DEST/python-swiftclient
Dean Troyer64ab7742012-12-28 15:38:28 -060030SWIFT_AUTH_CACHE_DIR=${SWIFT_AUTH_CACHE_DIR:-/var/cache/swift}
Dean Troyerb7490da2013-03-18 16:07:56 -050031SWIFT3_DIR=$DEST/swift3
Attila Fazekasece6a332012-11-29 14:19:41 +010032
33# TODO: add logging to different location.
34
35# Set ``SWIFT_DATA_DIR`` to the location of swift drives and objects.
36# Default is the common DevStack data directory.
37SWIFT_DATA_DIR=${SWIFT_DATA_DIR:-${DATA_DIR}/swift}
38
Dean Troyer6ec72fa2013-03-13 11:44:53 -050039# Set ``SWIFT_CONF_DIR`` to the location of the configuration files.
Attila Fazekasece6a332012-11-29 14:19:41 +010040# Default is ``/etc/swift``.
Dean Troyer6ec72fa2013-03-13 11:44:53 -050041# TODO(dtroyer): remove SWIFT_CONFIG_DIR after cutting stable/grizzly
42SWIFT_CONF_DIR=${SWIFT_CONF_DIR:-${SWIFT_CONFIG_DIR:-/etc/swift}}
Attila Fazekasece6a332012-11-29 14:19:41 +010043
Dean Troyerb7490da2013-03-18 16:07:56 -050044if is_service_enabled s-proxy && is_service_enabled swift3; then
45 # If we are using swift3, we can default the s3 port to swift instead
46 # of nova-objectstore
47 S3_SERVICE_PORT=${S3_SERVICE_PORT:-8080}
48fi
49
Attila Fazekasece6a332012-11-29 14:19:41 +010050# DevStack will create a loop-back disk formatted as XFS to store the
Kevin Lydad66c9652013-01-09 13:39:57 +000051# swift data. Set ``SWIFT_LOOPBACK_DISK_SIZE`` to the disk size in
52# kilobytes.
Attila Fazekasece6a332012-11-29 14:19:41 +010053# Default is 1 gigabyte.
54SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-1000000}
55
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010056# Set ``SWIFT_EXTRAS_MIDDLEWARE`` to extras middlewares.
57# Default is ``staticweb, tempurl, bulk, formpost``
58SWIFT_EXTRAS_MIDDLEWARE=${SWIFT_EXTRAS_MIDDLEWARE:-tempurl formpost staticweb bulk}
59
Attila Fazekasece6a332012-11-29 14:19:41 +010060# The ring uses a configurable number of bits from a path’s MD5 hash as
61# a partition index that designates a device. The number of bits kept
62# from the hash is known as the partition power, and 2 to the partition
63# power indicates the partition count. Partitioning the full MD5 hash
64# ring allows other parts of the cluster to work in batches of items at
65# once which ends up either more efficient or at least less complex than
66# working with each item separately or the entire cluster all at once.
67# By default we define 9 for the partition count (which mean 512).
68SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9}
69
70# Set ``SWIFT_REPLICAS`` to configure how many replicas are to be
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +010071# configured for your Swift cluster. By default we are configuring
72# only one replica since this is way less CPU and memory intensive. If
73# you are planning to test swift replication you may want to set this
74# up to 3.
75SWIFT_REPLICAS=${SWIFT_REPLICAS:-1}
Attila Fazekasece6a332012-11-29 14:19:41 +010076SWIFT_REPLICAS_SEQ=$(seq ${SWIFT_REPLICAS})
77
78# Set ``OBJECT_PORT_BASE``, ``CONTAINER_PORT_BASE``, ``ACCOUNT_PORT_BASE``
79# Port bases used in port number calclution for the service "nodes"
80# The specified port number will be used, the additinal ports calculated by
81# base_port + node_num * 10
Dean Troyer1151d6f2013-03-29 14:06:52 -050082OBJECT_PORT_BASE=${OBJECT_PORT_BASE:-6013}
83CONTAINER_PORT_BASE=${CONTAINER_PORT_BASE:-6011}
84ACCOUNT_PORT_BASE=${ACCOUNT_PORT_BASE:-6012}
Attila Fazekasece6a332012-11-29 14:19:41 +010085
Dean Troyer6d04fd72012-12-21 11:03:37 -060086
Dean Troyercc6b4432013-04-08 15:38:03 -050087# Functions
88# ---------
Attila Fazekasece6a332012-11-29 14:19:41 +010089
90# cleanup_swift() - Remove residual data files
91function cleanup_swift() {
Dean Troyer6ec72fa2013-03-13 11:44:53 -050092 rm -f ${SWIFT_CONF_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz}
Attila Fazekasece6a332012-11-29 14:19:41 +010093 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
94 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
95 fi
96 if [[ -e ${SWIFT_DATA_DIR}/drives/images/swift.img ]]; then
97 rm ${SWIFT_DATA_DIR}/drives/images/swift.img
98 fi
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010099 rm -rf ${SWIFT_DATA_DIR}/run/
Attila Fazekasece6a332012-11-29 14:19:41 +0100100}
101
102# configure_swift() - Set config files, create data dirs and loop image
103function configure_swift() {
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100104 local swift_pipeline=" "
Attila Fazekasece6a332012-11-29 14:19:41 +0100105 local node_number
106 local swift_node_config
107 local swift_log_dir
108
Attila Fazekasece6a332012-11-29 14:19:41 +0100109 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100110 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100111
Dean Troyer1c6c1122013-03-27 17:40:53 -0500112 sudo mkdir -p ${SWIFT_CONF_DIR}/{object,container,account}-server
113 sudo chown -R $USER: ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100114
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500115 if [[ "$SWIFT_CONF_DIR" != "/etc/swift" ]]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100116 # Some swift tools are hard-coded to use ``/etc/swift`` and are apparently not going to be fixed.
117 # Create a symlink if the config dir is moved
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500118 sudo ln -sf ${SWIFT_CONF_DIR} /etc/swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100119 fi
120
121 # Swift use rsync to synchronize between all the different
122 # partitions (which make more sense when you have a multi-node
123 # setup) we configure it with our version of rsync.
124 sed -e "
125 s/%GROUP%/${USER_GROUP}/;
126 s/%USER%/$USER/;
127 s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,;
128 " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf
129 # rsyncd.conf just prepared for 4 nodes
Vincent Untzc18b9652012-12-04 12:36:34 +0100130 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100131 sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync
132 else
133 sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync
134 fi
135
136 if is_service_enabled swift3;then
137 swift_auth_server="s3token "
138 fi
139
140 # By default Swift will be installed with the tempauth middleware
141 # which has some default username and password if you have
142 # configured keystone it will checkout the directory.
143 if is_service_enabled key; then
144 swift_auth_server+="authtoken keystoneauth"
145 else
146 swift_auth_server=tempauth
147 fi
148
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500149 SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONF_DIR}/proxy-server.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100150 cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER}
151
152 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user
153 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${USER}
154
155 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500156 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100157
158 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers
159 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1
160
161 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level
162 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG
163
164 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port
165 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT:-8080}
166
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100167 # By default Swift will be installed with the tempauth middleware
168 # which has some default username and password if you have
169 # configured keystone it will configure swift with it.
170 if is_service_enabled key;then
171 if is_service_enabled swift3;then
Matthieu Huina44d5ed2013-04-08 13:31:54 +0200172 swift_pipeline=" swift3 s3token "
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100173 fi
174 swift_pipeline+=" authtoken keystoneauth "
175 else
176 if is_service_enabled swift3;then
177 swift_pipeline=" swift3 "
178 fi
179 swift_pipeline+=" tempauth "
180 fi
181 sed -i "/^pipeline/ { s/tempauth/${swift_pipeline} ${SWIFT_EXTRAS_MIDDLEWARE}/ ;}" ${SWIFT_CONFIG_PROXY_SERVER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100182
183 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true
184
185 # Configure Keystone
186 sed -i '/^# \[filter:authtoken\]/,/^# \[filter:keystoneauth\]$/ s/^#[ \t]*//' ${SWIFT_CONFIG_PROXY_SERVER}
187 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_host $KEYSTONE_AUTH_HOST
188 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_port $KEYSTONE_AUTH_PORT
189 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
190 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
191 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
192 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_user swift
193 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_password $SERVICE_PASSWORD
Dean Troyer64ab7742012-12-28 15:38:28 -0600194 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken signing_dir $SWIFT_AUTH_CACHE_DIR
Attila Fazekasece6a332012-11-29 14:19:41 +0100195
196 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use
197 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles
198 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin"
199
200 if is_service_enabled swift3; then
201 cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER}
202# NOTE(chmou): s3token middleware is not updated yet to use only
203# username and password.
204[filter:s3token]
205paste.filter_factory = keystone.middleware.s3_token:filter_factory
206auth_port = ${KEYSTONE_AUTH_PORT}
207auth_host = ${KEYSTONE_AUTH_HOST}
208auth_protocol = ${KEYSTONE_AUTH_PROTOCOL}
209auth_token = ${SERVICE_TOKEN}
210admin_token = ${SERVICE_TOKEN}
211
212[filter:swift3]
213use = egg:swift3#swift3
214EOF
215 fi
216
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500217 cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf
218 iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH}
Attila Fazekasece6a332012-11-29 14:19:41 +0100219
220 # This function generates an object/account/proxy configuration
221 # emulating 4 nodes on different ports
222 function generate_swift_config() {
223 local swift_node_config=$1
224 local node_id=$2
225 local bind_port=$3
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000226 local server_type=$4
Attila Fazekasece6a332012-11-29 14:19:41 +0100227
228 log_facility=$[ node_id - 1 ]
229 node_path=${SWIFT_DATA_DIR}/${node_number}
230
231 iniuncomment ${swift_node_config} DEFAULT user
232 iniset ${swift_node_config} DEFAULT user ${USER}
233
234 iniuncomment ${swift_node_config} DEFAULT bind_port
235 iniset ${swift_node_config} DEFAULT bind_port ${bind_port}
236
237 iniuncomment ${swift_node_config} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500238 iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100239
240 iniuncomment ${swift_node_config} DEFAULT devices
241 iniset ${swift_node_config} DEFAULT devices ${node_path}
242
243 iniuncomment ${swift_node_config} DEFAULT log_facility
244 iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility}
245
246 iniuncomment ${swift_node_config} DEFAULT mount_check
247 iniset ${swift_node_config} DEFAULT mount_check false
248
249 iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode
250 iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes
251 }
252
253 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500254 swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100255 cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000256 generate_swift_config ${swift_node_config} ${node_number} $[OBJECT_PORT_BASE + 10 * (node_number - 1)] object
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000257 iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache
258 # Using a sed and not iniset/iniuncomment because we want to a global
259 # modification and make sure it works for new sections.
260 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100261
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500262 swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100263 cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000264 generate_swift_config ${swift_node_config} ${node_number} $[CONTAINER_PORT_BASE + 10 * (node_number - 1)] container
Attila Fazekas83e10952012-11-30 23:28:07 +0100265 iniuncomment ${swift_node_config} app:container-server allow_versions
266 iniset ${swift_node_config} app:container-server allow_versions "true"
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000267 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100268
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500269 swift_node_config=${SWIFT_CONF_DIR}/account-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100270 cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000271 generate_swift_config ${swift_node_config} ${node_number} $[ACCOUNT_PORT_BASE + 10 * (node_number - 1)] account
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000272 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100273 done
274
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000275 # Set new accounts in tempauth to match keystone tenant/user (to make testing easier)
276 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest1 "testing .admin"
277 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest2_swiftusertest2 "testing2 .admin"
278 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest3 "testing3 .admin"
279
280 testfile=${SWIFT_CONF_DIR}/test.conf
281 cp ${SWIFT_DIR}/test/sample.conf ${testfile}
282
283 # Set accounts for functional tests
284 iniset ${testfile} func_test account swifttenanttest1
285 iniset ${testfile} func_test username swiftusertest1
286 iniset ${testfile} func_test username3 swiftusertest3
287 iniset ${testfile} func_test account2 swifttenanttest2
288 iniset ${testfile} func_test username2 swiftusertest2
289
290 # Set maximum file size to 10000 bytes or our vm will fill up quickly with
291 # the default 5gb size.
292 iniuncomment ${testfile} func_test max_file_size
293 iniset ${testfile} func_test max_file_size 10000
294
295
296 if is_service_enabled key;then
297 iniuncomment ${testfile} func_test auth_version
298 iniset ${testfile} func_test auth_host ${KEYSTONE_SERVICE_HOST}
299 iniset ${testfile} func_test auth_port ${KEYSTONE_AUTH_PORT}
300 iniset ${testfile} func_test auth_prefix /v2.0/
301 fi
302
Attila Fazekasece6a332012-11-29 14:19:41 +0100303 swift_log_dir=${SWIFT_DATA_DIR}/logs
304 rm -rf ${swift_log_dir}
305 mkdir -p ${swift_log_dir}/hourly
306 sudo chown -R $USER:adm ${swift_log_dir}
307 sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
308 tee /etc/rsyslog.d/10-swift.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100309}
310
Dean Troyer1c6c1122013-03-27 17:40:53 -0500311# create_swift_disk - Create Swift backing disk
312function create_swift_disk() {
313 local node_number
314
315 # First do a bit of setup by creating the directories and
316 # changing the permissions so we can run it as our user.
317
318 USER_GROUP=$(id -g)
319 sudo mkdir -p ${SWIFT_DATA_DIR}/{drives,cache,run,logs}
320 sudo chown -R $USER:${USER_GROUP} ${SWIFT_DATA_DIR}
321
322 # Create a loopback disk and format it to XFS.
323 if [[ -e ${SWIFT_DATA_DIR}/drives/images/swift.img ]]; then
324 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
325 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
326 sudo rm -f ${SWIFT_DATA_DIR}/drives/images/swift.img
327 fi
328 fi
329
330 mkdir -p ${SWIFT_DATA_DIR}/drives/images
331 sudo touch ${SWIFT_DATA_DIR}/drives/images/swift.img
332 sudo chown $USER: ${SWIFT_DATA_DIR}/drives/images/swift.img
333
334 dd if=/dev/zero of=${SWIFT_DATA_DIR}/drives/images/swift.img \
335 bs=1024 count=0 seek=${SWIFT_LOOPBACK_DISK_SIZE}
336
337 # Make a fresh XFS filesystem
338 mkfs.xfs -f -i size=1024 ${SWIFT_DATA_DIR}/drives/images/swift.img
339
340 # Mount the disk with mount options to make it as efficient as possible
341 mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1
342 if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
343 sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8 \
344 ${SWIFT_DATA_DIR}/drives/images/swift.img ${SWIFT_DATA_DIR}/drives/sdb1
345 fi
346
347 # Create a link to the above mount and
348 # create all of the directories needed to emulate a few different servers
349 for node_number in ${SWIFT_REPLICAS_SEQ}; do
350 sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number;
351 drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number}
352 node=${SWIFT_DATA_DIR}/${node_number}/node
353 node_device=${node}/sdb1
354 [[ -d $node ]] && continue
355 [[ -d $drive ]] && continue
356 sudo install -o ${USER} -g $USER_GROUP -d $drive
357 sudo install -o ${USER} -g $USER_GROUP -d $node_device
358 sudo chown -R $USER: ${node}
359 done
360}
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000361# create_swift_accounts() - Set up common required swift accounts for tests we
362# are all attach names since we want to make it compatible with tempauth which
363# use underscores for separators.
364
365# Tenant User Roles
366# ------------------------------------------------------------------
367# swifttenanttest1 swiftusertest1 admin
368# swifttenanttest1 swiftusertest3 anotherrole
369# swifttenanttest2 swiftusertest2 admin
370
371# Migrated from keystone_data.sh
372function create_swift_accounts() {
373 SWIFT_TENANT_TEST1=$(keystone tenant-create --name=swifttenanttest1 | grep " id " | get_field 2)
374 SWIFT_USER_TEST1=$(keystone user-create --name=swiftusertest1 --pass=testing --email=test@example.com | grep " id " | get_field 2)
375 keystone user-role-add --user_id $SWIFT_USER_TEST1 --role_id $ADMIN_ROLE --tenant_id $SWIFT_TENANT_TEST1
376
377 SWIFT_USER_TEST3=$(keystone user-create --name=swiftusertest3 --pass=testing3 --email=test3@example.com | grep " id " | get_field 2)
378 keystone user-role-add --user_id $SWIFT_USER_TEST3 --role_id $ANOTHER_ROLE --tenant_id $SWIFT_TENANT_TEST1
379
380 SWIFT_TENANT_TEST2=$(keystone tenant-create --name=swifttenanttest2 | grep " id " | get_field 2)
381 SWIFT_USER_TEST2=$(keystone user-create --name=swiftusertest2 --pass=testing2 --email=test2@example.com | grep " id " | get_field 2)
382 keystone user-role-add --user_id $SWIFT_USER_TEST2 --role_id $ADMIN_ROLE --tenant_id $SWIFT_TENANT_TEST2
383}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500384
Attila Fazekasece6a332012-11-29 14:19:41 +0100385# init_swift() - Initialize rings
386function init_swift() {
387 local node_number
388 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100389 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100390
Dean Troyer1c6c1122013-03-27 17:40:53 -0500391 # Forcibly re-create the backing filesystem
392 create_swift_disk
393
Attila Fazekasece6a332012-11-29 14:19:41 +0100394 # This is where we create three different rings for swift with
395 # different object servers binding on different ports.
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500396 pushd ${SWIFT_CONF_DIR} >/dev/null && {
Attila Fazekasece6a332012-11-29 14:19:41 +0100397
398 rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
399
400 swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
401 swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
402 swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
403
404 for node_number in ${SWIFT_REPLICAS_SEQ}; do
405 swift-ring-builder object.builder add z${node_number}-127.0.0.1:$[OBJECT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
406 swift-ring-builder container.builder add z${node_number}-127.0.0.1:$[CONTAINER_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
407 swift-ring-builder account.builder add z${node_number}-127.0.0.1:$[ACCOUNT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
408 done
409 swift-ring-builder object.builder rebalance
410 swift-ring-builder container.builder rebalance
411 swift-ring-builder account.builder rebalance
412 } && popd >/dev/null
413
Dean Troyer64ab7742012-12-28 15:38:28 -0600414 # Create cache dir
415 sudo mkdir -p $SWIFT_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100416 sudo chown $STACK_USER $SWIFT_AUTH_CACHE_DIR
Dean Troyer64ab7742012-12-28 15:38:28 -0600417 rm -f $SWIFT_AUTH_CACHE_DIR/*
Attila Fazekasece6a332012-11-29 14:19:41 +0100418}
419
420function install_swift() {
421 git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500422 setup_develop $SWIFT_DIR
Attila Fazekasece6a332012-11-29 14:19:41 +0100423}
424
425function install_swiftclient() {
426 git_clone $SWIFTCLIENT_REPO $SWIFTCLIENT_DIR $SWIFTCLIENT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500427 setup_develop $SWIFTCLIENT_DIR
Attila Fazekasece6a332012-11-29 14:19:41 +0100428}
429
Attila Fazekasece6a332012-11-29 14:19:41 +0100430# start_swift() - Start running processes, including screen
431function start_swift() {
432 # (re)start rsyslog
433 restart_service rsyslog
Chmouel Boudjnah8ecbb382013-03-12 12:15:17 +0100434 # (re)start memcached to make sure we have a clean memcache.
435 restart_service memcached
436
Attila Fazekasece6a332012-11-29 14:19:41 +0100437 # Start rsync
Vincent Untzc18b9652012-12-04 12:36:34 +0100438 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100439 sudo /etc/init.d/rsync restart || :
440 else
441 sudo systemctl start xinetd.service
442 fi
443
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100444 # By default with only one replica we are launching the proxy,
445 # container, account and object server in screen in foreground and
446 # other services in background. If we have SWIFT_REPLICAS set to something
447 # greater than one we first spawn all the swift services then kill the proxy
448 # service so we can run it in foreground in screen. ``swift-init ...
449 # {stop|restart}`` exits with '1' if no servers are running, ignore it just
450 # in case
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100451 swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500452 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100453 todo="object container account"
454 fi
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500455 for type in proxy ${todo}; do
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100456 swift-init --run-dir=${SWIFT_DATA_DIR}/run ${type} stop || true
457 done
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500458 screen_it s-proxy "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v"
459 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100460 for type in object container account;do
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500461 screen_it s-${type} "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-${type}-server ${SWIFT_CONF_DIR}/${type}-server/1.conf -v"
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100462 done
463 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100464}
465
466# stop_swift() - Stop running processes (non-screen)
467function stop_swift() {
468 # screen normally killed by unstack.sh
Dean Troyer995eb922013-03-07 16:11:40 -0600469 if type -p swift-init >/dev/null; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100470 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
471 fi
Dean Troyer995eb922013-03-07 16:11:40 -0600472 # Dump the proxy server
473 sudo pkill -f swift-proxy-server
Attila Fazekasece6a332012-11-29 14:19:41 +0100474}
475
476# Restore xtrace
477$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400478
479# Local variables:
480# mode: shell-script
481# End: