diff --git a/lib/swift b/lib/swift index 84304d34d6..b9fa402d36 100644 --- a/lib/swift +++ b/lib/swift @@ -150,9 +150,10 @@ function cleanup_swift { function _cleanup_swift_apache_wsgi { sudo rm -f $SWIFT_APACHE_WSGI_DIR/*.wsgi disable_apache_site proxy-server + local node_number type for node_number in ${SWIFT_REPLICAS_SEQ}; do for type in object container account; do - site_name=${type}-server-${node_number} + local site_name=${type}-server-${node_number} disable_apache_site ${site_name} sudo rm -f $(apache_site_config_for ${site_name}) done @@ -182,10 +183,11 @@ function _config_swift_apache_wsgi { " -i ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi # copy apache vhost file and set name and port + local node_number for node_number in ${SWIFT_REPLICAS_SEQ}; do - object_port=$[OBJECT_PORT_BASE + 10 * ($node_number - 1)] - container_port=$[CONTAINER_PORT_BASE + 10 * ($node_number - 1)] - account_port=$[ACCOUNT_PORT_BASE + 10 * ($node_number - 1)] + local object_port=$[OBJECT_PORT_BASE + 10 * ($node_number - 1)] + local container_port=$[CONTAINER_PORT_BASE + 10 * ($node_number - 1)] + local account_port=$[ACCOUNT_PORT_BASE + 10 * ($node_number - 1)] sudo cp ${SWIFT_DIR}/examples/apache2/object-server.template $(apache_site_config_for object-server-${node_number}) sudo sed -e " @@ -245,7 +247,7 @@ function generate_swift_config { local server_type=$4 log_facility=$[ node_id - 1 ] - node_path=${SWIFT_DATA_DIR}/${node_number} + local node_path=${SWIFT_DATA_DIR}/${node_number} iniuncomment ${swift_node_config} DEFAULT user iniset ${swift_node_config} DEFAULT user ${STACK_USER} @@ -416,8 +418,9 @@ EOF iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH} iniset ${SWIFT_CONF_DIR}/swift.conf swift-constraints max_header_size ${SWIFT_MAX_HEADER_SIZE} + local node_number for node_number in ${SWIFT_REPLICAS_SEQ}; do - swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf + local swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config} generate_swift_config ${swift_node_config} ${node_number} $[OBJECT_PORT_BASE + 10 * (node_number - 1)] object iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache @@ -460,7 +463,7 @@ EOF iniset ${testfile} func_test auth_prefix /v2.0/ fi - swift_log_dir=${SWIFT_DATA_DIR}/logs + local swift_log_dir=${SWIFT_DATA_DIR}/logs rm -rf ${swift_log_dir} mkdir -p ${swift_log_dir}/hourly sudo chown -R ${STACK_USER}:adm ${swift_log_dir} @@ -484,9 +487,9 @@ function create_swift_disk { # First do a bit of setup by creating the directories and # changing the permissions so we can run it as our user. - USER_GROUP=$(id -g ${STACK_USER}) + local user_group=$(id -g ${STACK_USER}) sudo mkdir -p ${SWIFT_DATA_DIR}/{drives,cache,run,logs} - sudo chown -R ${STACK_USER}:${USER_GROUP} ${SWIFT_DATA_DIR} + sudo chown -R ${STACK_USER}:${user_group} ${SWIFT_DATA_DIR} # Create a loopback disk and format it to XFS. if [[ -e ${SWIFT_DISK_IMAGE} ]]; then @@ -514,15 +517,16 @@ function create_swift_disk { # Create a link to the above mount and # create all of the directories needed to emulate a few different servers + local node_number for node_number in ${SWIFT_REPLICAS_SEQ}; do sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number; - drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number} - node=${SWIFT_DATA_DIR}/${node_number}/node - node_device=${node}/sdb1 + local drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number} + local node=${SWIFT_DATA_DIR}/${node_number}/node + local node_device=${node}/sdb1 [[ -d $node ]] && continue [[ -d $drive ]] && continue - sudo install -o ${STACK_USER} -g $USER_GROUP -d $drive - sudo install -o ${STACK_USER} -g $USER_GROUP -d $node_device + sudo install -o ${STACK_USER} -g $user_group -d $drive + sudo install -o ${STACK_USER} -g $user_group -d $node_device sudo chown -R ${STACK_USER}: ${node} done } @@ -540,49 +544,49 @@ function create_swift_disk { function create_swift_accounts { # Defines specific passwords used by tools/create_userrc.sh - SWIFTUSERTEST1_PASSWORD=testing - SWIFTUSERTEST2_PASSWORD=testing2 - SWIFTUSERTEST3_PASSWORD=testing3 + local swiftusertest1_password=testing + local swiftusertest2_password=testing2 + local swiftusertest3_password=testing3 KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql} - SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") - ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }") + local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") + local admin_role=$(openstack role list | awk "/ admin / { print \$2 }") - SWIFT_USER=$(get_or_create_user "swift" \ - "$SERVICE_PASSWORD" $SERVICE_TENANT) - get_or_add_user_role $ADMIN_ROLE $SWIFT_USER $SERVICE_TENANT + local swift_user=$(get_or_create_user "swift" \ + "$SERVICE_PASSWORD" $service_tenant) + get_or_add_user_role $admin_role $swift_user $service_tenant if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then - SWIFT_SERVICE=$(get_or_create_service "swift" \ + local swift_service=$(get_or_create_service "swift" \ "object-store" "Swift Service") - get_or_create_endpoint $SWIFT_SERVICE \ + get_or_create_endpoint $swift_service \ "$REGION_NAME" \ "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \ "http://$SERVICE_HOST:8080" \ "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" fi - SWIFT_TENANT_TEST1=$(get_or_create_project swifttenanttest1) - die_if_not_set $LINENO SWIFT_TENANT_TEST1 "Failure creating SWIFT_TENANT_TEST1" - SWIFT_USER_TEST1=$(get_or_create_user swiftusertest1 $SWIFTUSERTEST1_PASSWORD \ - "$SWIFT_TENANT_TEST1" "test@example.com") + local swift_tenant_test1=$(get_or_create_project swifttenanttest1) + die_if_not_set $LINENO swift_tenant_test1 "Failure creating swift_tenant_test1" + SWIFT_USER_TEST1=$(get_or_create_user swiftusertest1 $swiftusertest1_password \ + "$swift_tenant_test1" "test@example.com") die_if_not_set $LINENO SWIFT_USER_TEST1 "Failure creating SWIFT_USER_TEST1" - get_or_add_user_role $ADMIN_ROLE $SWIFT_USER_TEST1 $SWIFT_TENANT_TEST1 + get_or_add_user_role $admin_role $SWIFT_USER_TEST1 $swift_tenant_test1 - SWIFT_USER_TEST3=$(get_or_create_user swiftusertest3 $SWIFTUSERTEST3_PASSWORD \ - "$SWIFT_TENANT_TEST1" "test3@example.com") - die_if_not_set $LINENO SWIFT_USER_TEST3 "Failure creating SWIFT_USER_TEST3" - get_or_add_user_role $ANOTHER_ROLE $SWIFT_USER_TEST3 $SWIFT_TENANT_TEST1 + local swift_user_test3=$(get_or_create_user swiftusertest3 $swiftusertest3_password \ + "$swift_tenant_test1" "test3@example.com") + die_if_not_set $LINENO swift_user_test3 "Failure creating swift_user_test3" + get_or_add_user_role $ANOTHER_ROLE $swift_user_test3 $swift_tenant_test1 - SWIFT_TENANT_TEST2=$(get_or_create_project swifttenanttest2) - die_if_not_set $LINENO SWIFT_TENANT_TEST2 "Failure creating SWIFT_TENANT_TEST2" + local swift_tenant_test2=$(get_or_create_project swifttenanttest2) + die_if_not_set $LINENO swift_tenant_test2 "Failure creating swift_tenant_test2" - SWIFT_USER_TEST2=$(get_or_create_user swiftusertest2 $SWIFTUSERTEST2_PASSWORD \ - "$SWIFT_TENANT_TEST2" "test2@example.com") - die_if_not_set $LINENO SWIFT_USER_TEST2 "Failure creating SWIFT_USER_TEST2" - get_or_add_user_role $ADMIN_ROLE $SWIFT_USER_TEST2 $SWIFT_TENANT_TEST2 + local swift_user_test2=$(get_or_create_user swiftusertest2 $swiftusertest2_password \ + "$swift_tenant_test2" "test2@example.com") + die_if_not_set $LINENO swift_user_test2 "Failure creating swift_user_test2" + get_or_add_user_role $admin_role $swift_user_test2 $swift_tenant_test2 } # init_swift() - Initialize rings @@ -666,6 +670,7 @@ function start_swift { # service so we can run it in foreground in screen. ``swift-init ... # {stop|restart}`` exits with '1' if no servers are running, ignore it just # in case + local todo type swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true if [[ ${SWIFT_REPLICAS} == 1 ]]; then todo="object container account" @@ -683,6 +688,7 @@ function start_swift { # stop_swift() - Stop running processes (non-screen) function stop_swift { + local type if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then swift-init --run-dir=${SWIFT_DATA_DIR}/run rest stop && return 0