Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 1 | # lib/swift |
Dean Troyer | 6d04fd7 | 2012-12-21 11:03:37 -0600 | [diff] [blame] | 2 | # Functions to control the configuration and operation of the **Swift** service |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 3 | |
| 4 | # Dependencies: |
| 5 | # ``functions`` file |
| 6 | # ``DEST``, ``SCREEN_NAME``, `SWIFT_HASH` must be defined |
Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 7 | # ``STACK_USER`` must be defined |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 8 | # ``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 |
| 20 | XTRACE=$(set +o | grep xtrace) |
| 21 | set +o xtrace |
| 22 | |
| 23 | |
| 24 | # Defaults |
| 25 | # -------- |
| 26 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 27 | # Set up default directories |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 28 | SWIFT_DIR=$DEST/swift |
| 29 | SWIFTCLIENT_DIR=$DEST/python-swiftclient |
Dean Troyer | 64ab774 | 2012-12-28 15:38:28 -0600 | [diff] [blame] | 30 | SWIFT_AUTH_CACHE_DIR=${SWIFT_AUTH_CACHE_DIR:-/var/cache/swift} |
Dean Troyer | b7490da | 2013-03-18 16:07:56 -0500 | [diff] [blame] | 31 | SWIFT3_DIR=$DEST/swift3 |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 32 | |
| 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. |
| 37 | SWIFT_DATA_DIR=${SWIFT_DATA_DIR:-${DATA_DIR}/swift} |
| 38 | |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 39 | # Set ``SWIFT_CONF_DIR`` to the location of the configuration files. |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 40 | # Default is ``/etc/swift``. |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 41 | # TODO(dtroyer): remove SWIFT_CONFIG_DIR after cutting stable/grizzly |
| 42 | SWIFT_CONF_DIR=${SWIFT_CONF_DIR:-${SWIFT_CONFIG_DIR:-/etc/swift}} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 43 | |
Dean Troyer | b7490da | 2013-03-18 16:07:56 -0500 | [diff] [blame] | 44 | if 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} |
| 48 | fi |
| 49 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 50 | # DevStack will create a loop-back disk formatted as XFS to store the |
Kevin Lyda | d66c965 | 2013-01-09 13:39:57 +0000 | [diff] [blame] | 51 | # swift data. Set ``SWIFT_LOOPBACK_DISK_SIZE`` to the disk size in |
| 52 | # kilobytes. |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 53 | # Default is 1 gigabyte. |
| 54 | SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-1000000} |
| 55 | |
Chmouel Boudjnah | bc3a339 | 2013-02-23 04:00:51 +0100 | [diff] [blame] | 56 | # Set ``SWIFT_EXTRAS_MIDDLEWARE`` to extras middlewares. |
| 57 | # Default is ``staticweb, tempurl, bulk, formpost`` |
| 58 | SWIFT_EXTRAS_MIDDLEWARE=${SWIFT_EXTRAS_MIDDLEWARE:-tempurl formpost staticweb bulk} |
| 59 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 60 | # 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). |
| 68 | SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9} |
| 69 | |
| 70 | # Set ``SWIFT_REPLICAS`` to configure how many replicas are to be |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 71 | # 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. |
| 75 | SWIFT_REPLICAS=${SWIFT_REPLICAS:-1} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 76 | SWIFT_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 Troyer | 1151d6f | 2013-03-29 14:06:52 -0500 | [diff] [blame] | 82 | OBJECT_PORT_BASE=${OBJECT_PORT_BASE:-6013} |
| 83 | CONTAINER_PORT_BASE=${CONTAINER_PORT_BASE:-6011} |
| 84 | ACCOUNT_PORT_BASE=${ACCOUNT_PORT_BASE:-6012} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 85 | |
Dean Troyer | 6d04fd7 | 2012-12-21 11:03:37 -0600 | [diff] [blame] | 86 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 87 | # Functions |
| 88 | # --------- |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 89 | |
| 90 | # cleanup_swift() - Remove residual data files |
| 91 | function cleanup_swift() { |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 92 | rm -f ${SWIFT_CONF_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 93 | 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 Boudjnah | bc3a339 | 2013-02-23 04:00:51 +0100 | [diff] [blame] | 99 | rm -rf ${SWIFT_DATA_DIR}/run/ |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | # configure_swift() - Set config files, create data dirs and loop image |
| 103 | function configure_swift() { |
Chmouel Boudjnah | bc3a339 | 2013-02-23 04:00:51 +0100 | [diff] [blame] | 104 | local swift_pipeline=" " |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 105 | local node_number |
| 106 | local swift_node_config |
| 107 | local swift_log_dir |
| 108 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 109 | # Make sure to kill all swift processes first |
Chmouel Boudjnah | ad8b276 | 2013-01-10 15:40:01 +0100 | [diff] [blame] | 110 | swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 111 | |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 112 | sudo mkdir -p ${SWIFT_CONF_DIR}/{object,container,account}-server |
| 113 | sudo chown -R $USER: ${SWIFT_CONF_DIR} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 114 | |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 115 | if [[ "$SWIFT_CONF_DIR" != "/etc/swift" ]]; then |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 116 | # 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 Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 118 | sudo ln -sf ${SWIFT_CONF_DIR} /etc/swift |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 119 | 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 Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 130 | if is_ubuntu; then |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 131 | 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 | |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 136 | SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONF_DIR}/proxy-server.conf |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 137 | cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER} |
| 138 | |
| 139 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user |
| 140 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${USER} |
| 141 | |
| 142 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 143 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONF_DIR} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 144 | |
| 145 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers |
| 146 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1 |
| 147 | |
| 148 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level |
| 149 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG |
| 150 | |
| 151 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port |
| 152 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT:-8080} |
| 153 | |
Chmouel Boudjnah | 5cac378 | 2013-07-17 15:13:44 +0000 | [diff] [blame^] | 154 | # By default Swift will be installed with keystone and tempauth middleware |
| 155 | # and add the swift3 middleware if its configured for it. The token for |
| 156 | # tempauth would be prefixed with the reseller_prefix setting TEMPAUTH_ the |
| 157 | # token for keystoneauth would have the standard reseller_prefix AUTH_ |
| 158 | if is_service_enabled swift3;then |
| 159 | swift_pipeline=" swift3 s3token " |
Chmouel Boudjnah | bc3a339 | 2013-02-23 04:00:51 +0100 | [diff] [blame] | 160 | fi |
Chmouel Boudjnah | 5cac378 | 2013-07-17 15:13:44 +0000 | [diff] [blame^] | 161 | swift_pipeline+=" authtoken keystoneauth tempauth " |
Chmouel Boudjnah | bc3a339 | 2013-02-23 04:00:51 +0100 | [diff] [blame] | 162 | sed -i "/^pipeline/ { s/tempauth/${swift_pipeline} ${SWIFT_EXTRAS_MIDDLEWARE}/ ;}" ${SWIFT_CONFIG_PROXY_SERVER} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 163 | |
Chmouel Boudjnah | 5cac378 | 2013-07-17 15:13:44 +0000 | [diff] [blame^] | 164 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth account_autocreate |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 165 | iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true |
| 166 | |
Chmouel Boudjnah | 5cac378 | 2013-07-17 15:13:44 +0000 | [diff] [blame^] | 167 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix |
| 168 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix "TEMPAUTH" |
| 169 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 170 | # Configure Keystone |
| 171 | sed -i '/^# \[filter:authtoken\]/,/^# \[filter:keystoneauth\]$/ s/^#[ \t]*//' ${SWIFT_CONFIG_PROXY_SERVER} |
| 172 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_host $KEYSTONE_AUTH_HOST |
| 173 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_port $KEYSTONE_AUTH_PORT |
| 174 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL |
| 175 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/ |
| 176 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME |
| 177 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_user swift |
| 178 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_password $SERVICE_PASSWORD |
Dean Troyer | 64ab774 | 2012-12-28 15:38:28 -0600 | [diff] [blame] | 179 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken signing_dir $SWIFT_AUTH_CACHE_DIR |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 180 | |
| 181 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use |
| 182 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles |
| 183 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin" |
| 184 | |
| 185 | if is_service_enabled swift3; then |
| 186 | cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER} |
| 187 | # NOTE(chmou): s3token middleware is not updated yet to use only |
| 188 | # username and password. |
| 189 | [filter:s3token] |
| 190 | paste.filter_factory = keystone.middleware.s3_token:filter_factory |
| 191 | auth_port = ${KEYSTONE_AUTH_PORT} |
| 192 | auth_host = ${KEYSTONE_AUTH_HOST} |
| 193 | auth_protocol = ${KEYSTONE_AUTH_PROTOCOL} |
| 194 | auth_token = ${SERVICE_TOKEN} |
| 195 | admin_token = ${SERVICE_TOKEN} |
| 196 | |
| 197 | [filter:swift3] |
| 198 | use = egg:swift3#swift3 |
| 199 | EOF |
| 200 | fi |
| 201 | |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 202 | cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf |
| 203 | iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 204 | |
| 205 | # This function generates an object/account/proxy configuration |
| 206 | # emulating 4 nodes on different ports |
| 207 | function generate_swift_config() { |
| 208 | local swift_node_config=$1 |
| 209 | local node_id=$2 |
| 210 | local bind_port=$3 |
Chmouel Boudjnah | 35633f0 | 2013-07-16 07:35:13 +0000 | [diff] [blame] | 211 | local server_type=$4 |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 212 | |
| 213 | log_facility=$[ node_id - 1 ] |
| 214 | node_path=${SWIFT_DATA_DIR}/${node_number} |
| 215 | |
| 216 | iniuncomment ${swift_node_config} DEFAULT user |
| 217 | iniset ${swift_node_config} DEFAULT user ${USER} |
| 218 | |
| 219 | iniuncomment ${swift_node_config} DEFAULT bind_port |
| 220 | iniset ${swift_node_config} DEFAULT bind_port ${bind_port} |
| 221 | |
| 222 | iniuncomment ${swift_node_config} DEFAULT swift_dir |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 223 | iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 224 | |
| 225 | iniuncomment ${swift_node_config} DEFAULT devices |
| 226 | iniset ${swift_node_config} DEFAULT devices ${node_path} |
| 227 | |
| 228 | iniuncomment ${swift_node_config} DEFAULT log_facility |
| 229 | iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility} |
| 230 | |
Chmouel Boudjnah | 82c0996 | 2013-07-16 07:16:07 +0000 | [diff] [blame] | 231 | iniuncomment ${swift_node_config} DEFAULT disable_fallocate |
| 232 | iniset ${swift_node_config} DEFAULT disable_fallocate true |
| 233 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 234 | iniuncomment ${swift_node_config} DEFAULT mount_check |
| 235 | iniset ${swift_node_config} DEFAULT mount_check false |
| 236 | |
| 237 | iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode |
| 238 | iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes |
| 239 | } |
| 240 | |
| 241 | for node_number in ${SWIFT_REPLICAS_SEQ}; do |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 242 | swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 243 | cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config} |
Chmouel Boudjnah | 35633f0 | 2013-07-16 07:35:13 +0000 | [diff] [blame] | 244 | generate_swift_config ${swift_node_config} ${node_number} $[OBJECT_PORT_BASE + 10 * (node_number - 1)] object |
Chmouel Boudjnah | 8e5d2f0 | 2012-12-20 13:11:43 +0000 | [diff] [blame] | 245 | iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache |
| 246 | # Using a sed and not iniset/iniuncomment because we want to a global |
| 247 | # modification and make sure it works for new sections. |
| 248 | sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 249 | |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 250 | swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 251 | cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config} |
Chmouel Boudjnah | 35633f0 | 2013-07-16 07:35:13 +0000 | [diff] [blame] | 252 | generate_swift_config ${swift_node_config} ${node_number} $[CONTAINER_PORT_BASE + 10 * (node_number - 1)] container |
Attila Fazekas | 83e1095 | 2012-11-30 23:28:07 +0100 | [diff] [blame] | 253 | iniuncomment ${swift_node_config} app:container-server allow_versions |
| 254 | iniset ${swift_node_config} app:container-server allow_versions "true" |
Chmouel Boudjnah | 8e5d2f0 | 2012-12-20 13:11:43 +0000 | [diff] [blame] | 255 | sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 256 | |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 257 | swift_node_config=${SWIFT_CONF_DIR}/account-server/${node_number}.conf |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 258 | cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config} |
Chmouel Boudjnah | 35633f0 | 2013-07-16 07:35:13 +0000 | [diff] [blame] | 259 | generate_swift_config ${swift_node_config} ${node_number} $[ACCOUNT_PORT_BASE + 10 * (node_number - 1)] account |
Chmouel Boudjnah | 8e5d2f0 | 2012-12-20 13:11:43 +0000 | [diff] [blame] | 260 | sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 261 | done |
| 262 | |
Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 263 | # Set new accounts in tempauth to match keystone tenant/user (to make testing easier) |
| 264 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest1 "testing .admin" |
| 265 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest2_swiftusertest2 "testing2 .admin" |
| 266 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest3 "testing3 .admin" |
| 267 | |
| 268 | testfile=${SWIFT_CONF_DIR}/test.conf |
| 269 | cp ${SWIFT_DIR}/test/sample.conf ${testfile} |
| 270 | |
| 271 | # Set accounts for functional tests |
| 272 | iniset ${testfile} func_test account swifttenanttest1 |
| 273 | iniset ${testfile} func_test username swiftusertest1 |
| 274 | iniset ${testfile} func_test username3 swiftusertest3 |
| 275 | iniset ${testfile} func_test account2 swifttenanttest2 |
| 276 | iniset ${testfile} func_test username2 swiftusertest2 |
| 277 | |
Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 278 | if is_service_enabled key;then |
| 279 | iniuncomment ${testfile} func_test auth_version |
| 280 | iniset ${testfile} func_test auth_host ${KEYSTONE_SERVICE_HOST} |
| 281 | iniset ${testfile} func_test auth_port ${KEYSTONE_AUTH_PORT} |
| 282 | iniset ${testfile} func_test auth_prefix /v2.0/ |
| 283 | fi |
| 284 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 285 | swift_log_dir=${SWIFT_DATA_DIR}/logs |
| 286 | rm -rf ${swift_log_dir} |
| 287 | mkdir -p ${swift_log_dir}/hourly |
| 288 | sudo chown -R $USER:adm ${swift_log_dir} |
| 289 | sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \ |
| 290 | tee /etc/rsyslog.d/10-swift.conf |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 291 | } |
| 292 | |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 293 | # create_swift_disk - Create Swift backing disk |
| 294 | function create_swift_disk() { |
| 295 | local node_number |
| 296 | |
| 297 | # First do a bit of setup by creating the directories and |
| 298 | # changing the permissions so we can run it as our user. |
| 299 | |
| 300 | USER_GROUP=$(id -g) |
| 301 | sudo mkdir -p ${SWIFT_DATA_DIR}/{drives,cache,run,logs} |
| 302 | sudo chown -R $USER:${USER_GROUP} ${SWIFT_DATA_DIR} |
| 303 | |
| 304 | # Create a loopback disk and format it to XFS. |
| 305 | if [[ -e ${SWIFT_DATA_DIR}/drives/images/swift.img ]]; then |
| 306 | if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then |
| 307 | sudo umount ${SWIFT_DATA_DIR}/drives/sdb1 |
| 308 | sudo rm -f ${SWIFT_DATA_DIR}/drives/images/swift.img |
| 309 | fi |
| 310 | fi |
| 311 | |
| 312 | mkdir -p ${SWIFT_DATA_DIR}/drives/images |
| 313 | sudo touch ${SWIFT_DATA_DIR}/drives/images/swift.img |
| 314 | sudo chown $USER: ${SWIFT_DATA_DIR}/drives/images/swift.img |
| 315 | |
| 316 | dd if=/dev/zero of=${SWIFT_DATA_DIR}/drives/images/swift.img \ |
| 317 | bs=1024 count=0 seek=${SWIFT_LOOPBACK_DISK_SIZE} |
| 318 | |
| 319 | # Make a fresh XFS filesystem |
| 320 | mkfs.xfs -f -i size=1024 ${SWIFT_DATA_DIR}/drives/images/swift.img |
| 321 | |
| 322 | # Mount the disk with mount options to make it as efficient as possible |
| 323 | mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1 |
| 324 | if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then |
| 325 | sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8 \ |
| 326 | ${SWIFT_DATA_DIR}/drives/images/swift.img ${SWIFT_DATA_DIR}/drives/sdb1 |
| 327 | fi |
| 328 | |
| 329 | # Create a link to the above mount and |
| 330 | # create all of the directories needed to emulate a few different servers |
| 331 | for node_number in ${SWIFT_REPLICAS_SEQ}; do |
| 332 | sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number; |
| 333 | drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number} |
| 334 | node=${SWIFT_DATA_DIR}/${node_number}/node |
| 335 | node_device=${node}/sdb1 |
| 336 | [[ -d $node ]] && continue |
| 337 | [[ -d $drive ]] && continue |
| 338 | sudo install -o ${USER} -g $USER_GROUP -d $drive |
| 339 | sudo install -o ${USER} -g $USER_GROUP -d $node_device |
| 340 | sudo chown -R $USER: ${node} |
| 341 | done |
| 342 | } |
Chmouel Boudjnah | ba31305 | 2013-07-10 21:03:43 +0200 | [diff] [blame] | 343 | # create_swift_accounts() - Set up standard swift accounts and extra |
| 344 | # one for tests we do this by attaching all words in the account name |
| 345 | # since we want to make it compatible with tempauth which use |
| 346 | # underscores for separators. |
Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 347 | |
| 348 | # Tenant User Roles |
| 349 | # ------------------------------------------------------------------ |
Chmouel Boudjnah | ba31305 | 2013-07-10 21:03:43 +0200 | [diff] [blame] | 350 | # service swift service |
Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 351 | # swifttenanttest1 swiftusertest1 admin |
| 352 | # swifttenanttest1 swiftusertest3 anotherrole |
| 353 | # swifttenanttest2 swiftusertest2 admin |
| 354 | |
Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 355 | function create_swift_accounts() { |
Chmouel Boudjnah | ba31305 | 2013-07-10 21:03:43 +0200 | [diff] [blame] | 356 | KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql} |
| 357 | |
| 358 | SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") |
| 359 | ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }") |
| 360 | |
| 361 | SWIFT_USER=$(keystone user-create --name=swift --pass="$SERVICE_PASSWORD" \ |
| 362 | --tenant_id $SERVICE_TENANT --email=swift@example.com | grep " id " | get_field 2) |
| 363 | keystone user-role-add --tenant_id $SERVICE_TENANT --user_id $SWIFT_USER --role_id $ADMIN_ROLE |
| 364 | |
| 365 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
| 366 | SWIFT_SERVICE=$(keystone service-create --name=swift --type="object-store" \ |
| 367 | --description="Swift Service" | grep " id " | get_field 2) |
| 368 | keystone endpoint-create \ |
| 369 | --region RegionOne \ |
| 370 | --service_id $SWIFT_SERVICE \ |
| 371 | --publicurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \ |
| 372 | --adminurl "http://$SERVICE_HOST:8080" \ |
| 373 | --internalurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" |
| 374 | fi |
| 375 | |
Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 376 | SWIFT_TENANT_TEST1=$(keystone tenant-create --name=swifttenanttest1 | grep " id " | get_field 2) |
| 377 | SWIFT_USER_TEST1=$(keystone user-create --name=swiftusertest1 --pass=testing --email=test@example.com | grep " id " | get_field 2) |
| 378 | keystone user-role-add --user_id $SWIFT_USER_TEST1 --role_id $ADMIN_ROLE --tenant_id $SWIFT_TENANT_TEST1 |
| 379 | |
| 380 | SWIFT_USER_TEST3=$(keystone user-create --name=swiftusertest3 --pass=testing3 --email=test3@example.com | grep " id " | get_field 2) |
| 381 | keystone user-role-add --user_id $SWIFT_USER_TEST3 --role_id $ANOTHER_ROLE --tenant_id $SWIFT_TENANT_TEST1 |
| 382 | |
| 383 | SWIFT_TENANT_TEST2=$(keystone tenant-create --name=swifttenanttest2 | grep " id " | get_field 2) |
| 384 | SWIFT_USER_TEST2=$(keystone user-create --name=swiftusertest2 --pass=testing2 --email=test2@example.com | grep " id " | get_field 2) |
| 385 | keystone user-role-add --user_id $SWIFT_USER_TEST2 --role_id $ADMIN_ROLE --tenant_id $SWIFT_TENANT_TEST2 |
| 386 | } |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 387 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 388 | # init_swift() - Initialize rings |
| 389 | function init_swift() { |
| 390 | local node_number |
| 391 | # Make sure to kill all swift processes first |
Chmouel Boudjnah | ad8b276 | 2013-01-10 15:40:01 +0100 | [diff] [blame] | 392 | swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 393 | |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 394 | # Forcibly re-create the backing filesystem |
| 395 | create_swift_disk |
| 396 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 397 | # This is where we create three different rings for swift with |
| 398 | # different object servers binding on different ports. |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 399 | pushd ${SWIFT_CONF_DIR} >/dev/null && { |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 400 | |
| 401 | rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz |
| 402 | |
| 403 | swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1 |
| 404 | swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1 |
| 405 | swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1 |
| 406 | |
| 407 | for node_number in ${SWIFT_REPLICAS_SEQ}; do |
| 408 | swift-ring-builder object.builder add z${node_number}-127.0.0.1:$[OBJECT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1 |
| 409 | swift-ring-builder container.builder add z${node_number}-127.0.0.1:$[CONTAINER_PORT_BASE + 10 * (node_number - 1)]/sdb1 1 |
| 410 | swift-ring-builder account.builder add z${node_number}-127.0.0.1:$[ACCOUNT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1 |
| 411 | done |
| 412 | swift-ring-builder object.builder rebalance |
| 413 | swift-ring-builder container.builder rebalance |
| 414 | swift-ring-builder account.builder rebalance |
| 415 | } && popd >/dev/null |
| 416 | |
Dean Troyer | 64ab774 | 2012-12-28 15:38:28 -0600 | [diff] [blame] | 417 | # Create cache dir |
| 418 | sudo mkdir -p $SWIFT_AUTH_CACHE_DIR |
Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 419 | sudo chown $STACK_USER $SWIFT_AUTH_CACHE_DIR |
Dean Troyer | 64ab774 | 2012-12-28 15:38:28 -0600 | [diff] [blame] | 420 | rm -f $SWIFT_AUTH_CACHE_DIR/* |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | function install_swift() { |
| 424 | git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH |
Dean Troyer | 253a1a3 | 2013-04-01 18:23:22 -0500 | [diff] [blame] | 425 | setup_develop $SWIFT_DIR |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | function install_swiftclient() { |
| 429 | git_clone $SWIFTCLIENT_REPO $SWIFTCLIENT_DIR $SWIFTCLIENT_BRANCH |
Dean Troyer | 253a1a3 | 2013-04-01 18:23:22 -0500 | [diff] [blame] | 430 | setup_develop $SWIFTCLIENT_DIR |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 431 | } |
| 432 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 433 | # start_swift() - Start running processes, including screen |
| 434 | function start_swift() { |
| 435 | # (re)start rsyslog |
| 436 | restart_service rsyslog |
Chmouel Boudjnah | 8ecbb38 | 2013-03-12 12:15:17 +0100 | [diff] [blame] | 437 | # (re)start memcached to make sure we have a clean memcache. |
| 438 | restart_service memcached |
| 439 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 440 | # Start rsync |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 441 | if is_ubuntu; then |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 442 | sudo /etc/init.d/rsync restart || : |
| 443 | else |
| 444 | sudo systemctl start xinetd.service |
| 445 | fi |
| 446 | |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 447 | # By default with only one replica we are launching the proxy, |
| 448 | # container, account and object server in screen in foreground and |
| 449 | # other services in background. If we have SWIFT_REPLICAS set to something |
| 450 | # greater than one we first spawn all the swift services then kill the proxy |
| 451 | # service so we can run it in foreground in screen. ``swift-init ... |
| 452 | # {stop|restart}`` exits with '1' if no servers are running, ignore it just |
| 453 | # in case |
Chmouel Boudjnah | ad8b276 | 2013-01-10 15:40:01 +0100 | [diff] [blame] | 454 | swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 455 | if [[ ${SWIFT_REPLICAS} == 1 ]]; then |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 456 | todo="object container account" |
| 457 | fi |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 458 | for type in proxy ${todo}; do |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 459 | swift-init --run-dir=${SWIFT_DATA_DIR}/run ${type} stop || true |
| 460 | done |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 461 | screen_it s-proxy "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v" |
| 462 | if [[ ${SWIFT_REPLICAS} == 1 ]]; then |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 463 | for type in object container account;do |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 464 | screen_it s-${type} "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-${type}-server ${SWIFT_CONF_DIR}/${type}-server/1.conf -v" |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 465 | done |
| 466 | fi |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | # stop_swift() - Stop running processes (non-screen) |
| 470 | function stop_swift() { |
| 471 | # screen normally killed by unstack.sh |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 472 | if type -p swift-init >/dev/null; then |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 473 | swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true |
| 474 | fi |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 475 | # Dump the proxy server |
| 476 | sudo pkill -f swift-proxy-server |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | # Restore xtrace |
| 480 | $XTRACE |
Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 481 | |
| 482 | # Local variables: |
| 483 | # mode: shell-script |
| 484 | # End: |