2016-02-05 12:24:13 +00:00
|
|
|
#!/bin/bash
|
2020-08-22 12:40:53 +00:00
|
|
|
#
|
|
|
|
# s3fs - FUSE-based file system backed by Amazon S3
|
|
|
|
#
|
|
|
|
# Copyright 2007-2008 Randy Rizun <rrizun@gmail.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#
|
2016-02-05 12:24:13 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Common code for starting an s3fs-fuse mountpoint and an S3Proxy instance
|
|
|
|
# to run tests against S3Proxy locally.
|
|
|
|
#
|
|
|
|
# To run against an Amazon S3 or other S3 provider, specify the following
|
|
|
|
# environment variables:
|
|
|
|
#
|
|
|
|
# S3FS_CREDENTIALS_FILE=keyfile s3fs format key file
|
2020-05-24 02:43:12 +00:00
|
|
|
# S3FS_PROFILE=name s3fs profile to use (overrides key file)
|
2016-02-05 12:24:13 +00:00
|
|
|
# TEST_BUCKET_1=bucketname Name of bucket to use
|
|
|
|
# S3PROXY_BINARY="" Specify empty string to skip S3Proxy start
|
2020-05-24 02:43:12 +00:00
|
|
|
# S3_URL="https://s3.amazonaws.com" Specify Amazon AWS as the S3 provider
|
2020-11-15 13:10:26 +00:00
|
|
|
# S3_ENDPOINT="us-east-1" Specify region
|
2016-02-05 12:24:13 +00:00
|
|
|
#
|
2020-11-15 13:10:26 +00:00
|
|
|
# Example of running against Amazon S3 using a bucket named "bucket":
|
2016-02-05 12:24:13 +00:00
|
|
|
#
|
2019-04-05 07:24:59 +00:00
|
|
|
# S3FS_CREDENTIALS_FILE=keyfile TEST_BUCKET_1=bucket S3PROXY_BINARY="" S3_URL="https://s3.amazonaws.com" ./small-integration-test.sh
|
2016-02-05 12:24:13 +00:00
|
|
|
#
|
|
|
|
# To change the s3fs-fuse debug level:
|
|
|
|
#
|
|
|
|
# DBGLEVEL=debug ./small-integration-test.sh
|
|
|
|
#
|
|
|
|
# To stop and wait after the mount point is up for manual interaction. This allows you to
|
|
|
|
# explore the mounted file system exactly as it would have been started for the test case
|
|
|
|
#
|
|
|
|
# INTERACT=1 DBGLEVEL=debug ./small-integration-test.sh
|
|
|
|
#
|
|
|
|
# Run all of the tests from the makefile
|
|
|
|
#
|
2019-04-05 07:24:59 +00:00
|
|
|
# S3FS_CREDENTIALS_FILE=keyfile TEST_BUCKET_1=bucket S3PROXY_BINARY="" S3_URL="https://s3.amazonaws.com" make check
|
2016-02-05 12:24:13 +00:00
|
|
|
#
|
|
|
|
# Run the tests with request auth turned off in both S3Proxy and s3fs-fuse. This can be
|
|
|
|
# useful for poking around with plain old curl
|
|
|
|
#
|
|
|
|
# PUBLIC=1 INTERACT=1 ./small-integration-test.sh
|
|
|
|
#
|
|
|
|
# A valgrind tool can be specified
|
|
|
|
# eg: VALGRIND="--tool=memcheck --leak-check=full" ./small-integration-test.sh
|
|
|
|
|
|
|
|
set -o errexit
|
2019-07-03 05:31:48 +00:00
|
|
|
set -o pipefail
|
|
|
|
|
2010-11-13 23:59:23 +00:00
|
|
|
S3FS=../src/s3fs
|
|
|
|
|
2016-02-05 12:24:13 +00:00
|
|
|
# Allow these defaulted values to be overridden
|
2017-09-17 23:14:58 +00:00
|
|
|
: ${S3_URL:="https://127.0.0.1:8080"}
|
2020-11-15 13:10:26 +00:00
|
|
|
: ${S3_ENDPOINT:="us-east-1"}
|
2015-09-11 08:25:37 +00:00
|
|
|
: ${S3FS_CREDENTIALS_FILE:="passwd-s3fs"}
|
|
|
|
: ${TEST_BUCKET_1:="s3fs-integration-test"}
|
2016-02-05 12:24:13 +00:00
|
|
|
|
|
|
|
export TEST_BUCKET_1
|
|
|
|
export S3_URL
|
2020-11-15 13:10:26 +00:00
|
|
|
export S3_ENDPOINT
|
2016-02-05 12:24:13 +00:00
|
|
|
export TEST_SCRIPT_DIR=`pwd`
|
|
|
|
export TEST_BUCKET_MOUNT_POINT_1=${TEST_BUCKET_1}
|
|
|
|
|
2020-05-23 01:06:44 +00:00
|
|
|
S3PROXY_VERSION="1.7.1"
|
2016-02-05 12:24:13 +00:00
|
|
|
S3PROXY_BINARY=${S3PROXY_BINARY-"s3proxy-${S3PROXY_VERSION}"}
|
2010-11-13 23:59:23 +00:00
|
|
|
|
2021-01-04 14:32:04 +00:00
|
|
|
CHAOS_HTTP_PROXY_VERSION="1.1.0"
|
|
|
|
CHAOS_HTTP_PROXY_BINARY="chaos-http-proxy-${CHAOS_HTTP_PROXY_VERSION}"
|
|
|
|
|
2010-11-13 23:59:23 +00:00
|
|
|
if [ ! -f "$S3FS_CREDENTIALS_FILE" ]
|
|
|
|
then
|
|
|
|
echo "Missing credentials file: $S3FS_CREDENTIALS_FILE"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-03-02 22:14:40 +00:00
|
|
|
chmod 600 "$S3FS_CREDENTIALS_FILE"
|
2015-02-24 13:17:59 +00:00
|
|
|
|
2020-05-24 02:43:12 +00:00
|
|
|
if [ -z "${S3FS_PROFILE}" ]; then
|
|
|
|
export AWS_ACCESS_KEY_ID=$(cut -d: -f1 ${S3FS_CREDENTIALS_FILE})
|
|
|
|
export AWS_SECRET_ACCESS_KEY=$(cut -d: -f2 ${S3FS_CREDENTIALS_FILE})
|
|
|
|
fi
|
2020-05-22 10:25:48 +00:00
|
|
|
|
2016-02-05 12:24:13 +00:00
|
|
|
if [ ! -d $TEST_BUCKET_MOUNT_POINT_1 ]
|
|
|
|
then
|
|
|
|
mkdir -p $TEST_BUCKET_MOUNT_POINT_1
|
2015-02-24 13:17:59 +00:00
|
|
|
fi
|
2016-02-05 12:24:13 +00:00
|
|
|
|
|
|
|
# This function execute the function parameters $1 times
|
|
|
|
# before giving up, with 1 second delays.
|
|
|
|
function retry {
|
|
|
|
set +o errexit
|
|
|
|
N=$1; shift;
|
|
|
|
status=0
|
|
|
|
for i in $(seq $N); do
|
2019-04-09 12:01:42 +00:00
|
|
|
echo "Trying: $*"
|
2021-01-25 09:32:40 +00:00
|
|
|
eval $@
|
2016-02-05 12:24:13 +00:00
|
|
|
status=$?
|
|
|
|
if [ $status == 0 ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
sleep 1
|
2019-04-09 12:01:42 +00:00
|
|
|
echo "Retrying: $*"
|
2016-02-05 12:24:13 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
if [ $status != 0 ]; then
|
2019-04-09 12:01:42 +00:00
|
|
|
echo "timeout waiting for $*"
|
2016-02-05 12:24:13 +00:00
|
|
|
fi
|
|
|
|
set -o errexit
|
|
|
|
return $status
|
|
|
|
}
|
|
|
|
|
|
|
|
# Proxy is not started if S3PROXY_BINARY is an empty string
|
|
|
|
# PUBLIC unset: use s3proxy.conf
|
|
|
|
# PUBLIC=1: use s3proxy-noauth.conf (no request signing)
|
|
|
|
#
|
|
|
|
function start_s3proxy {
|
|
|
|
if [ -n "${PUBLIC}" ]; then
|
|
|
|
S3PROXY_CONFIG="s3proxy-noauth.conf"
|
|
|
|
else
|
|
|
|
S3PROXY_CONFIG="s3proxy.conf"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${S3PROXY_BINARY}" ]
|
|
|
|
then
|
|
|
|
if [ ! -e "${S3PROXY_BINARY}" ]; then
|
|
|
|
wget "https://github.com/andrewgaul/s3proxy/releases/download/s3proxy-${S3PROXY_VERSION}/s3proxy" \
|
|
|
|
--quiet -O "${S3PROXY_BINARY}"
|
|
|
|
chmod +x "${S3PROXY_BINARY}"
|
|
|
|
fi
|
|
|
|
|
2020-12-23 10:34:04 +00:00
|
|
|
${STDBUF_BIN} -oL -eL java -jar "$S3PROXY_BINARY" --properties $S3PROXY_CONFIG &
|
2017-09-17 23:23:07 +00:00
|
|
|
S3PROXY_PID=$!
|
2016-02-05 12:24:13 +00:00
|
|
|
|
|
|
|
# wait for S3Proxy to start
|
2021-01-04 14:32:04 +00:00
|
|
|
wait_for_port 8080
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${CHAOS_HTTP_PROXY}" ]; then
|
|
|
|
if [ ! -e "${CHAOS_HTTP_PROXY_BINARY}" ]; then
|
|
|
|
wget "https://github.com/bouncestorage/chaos-http-proxy/releases/download/chaos-http-proxy-${CHAOS_HTTP_PROXY_VERSION}/chaos-http-proxy" \
|
|
|
|
--quiet -O "${CHAOS_HTTP_PROXY_BINARY}"
|
|
|
|
chmod +x "${CHAOS_HTTP_PROXY_BINARY}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
${STDBUF_BIN} -oL -eL java -jar ${CHAOS_HTTP_PROXY_BINARY} --properties chaos-http-proxy.conf &
|
|
|
|
CHAOS_HTTP_PROXY_PID=$!
|
|
|
|
|
|
|
|
# wait for Chaos HTTP Proxy to start
|
|
|
|
wait_for_port 1080
|
2016-02-05 12:24:13 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function stop_s3proxy {
|
|
|
|
if [ -n "${S3PROXY_PID}" ]
|
|
|
|
then
|
|
|
|
kill $S3PROXY_PID
|
|
|
|
fi
|
2021-01-04 14:32:04 +00:00
|
|
|
|
|
|
|
if [ -n "${CHAOS_HTTP_PROXY_PID}" ]
|
|
|
|
then
|
|
|
|
kill $CHAOS_HTTP_PROXY_PID
|
|
|
|
fi
|
2016-02-05 12:24:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Mount the bucket, function arguments passed to s3fs in addition to
|
|
|
|
# a set of common arguments.
|
|
|
|
function start_s3fs {
|
|
|
|
# Public bucket if PUBLIC is set
|
|
|
|
if [ -n "${PUBLIC}" ]; then
|
|
|
|
AUTH_OPT="-o public_bucket=1"
|
2020-05-24 02:43:12 +00:00
|
|
|
elif [ -n "${S3FS_PROFILE}" ]; then
|
|
|
|
AUTH_OPT="-o profile=${S3FS_PROFILE}"
|
2016-02-05 12:24:13 +00:00
|
|
|
else
|
|
|
|
AUTH_OPT="-o passwd_file=${S3FS_CREDENTIALS_FILE}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If VALGRIND is set, pass it as options to valgrind.
|
|
|
|
# start valgrind-listener in another shell.
|
|
|
|
# eg: VALGRIND="--tool=memcheck --leak-check=full" ./small-integration-test.sh
|
2019-01-27 12:04:29 +00:00
|
|
|
# Start valgrind-listener (default port is 1500)
|
2016-02-05 12:24:13 +00:00
|
|
|
if [ -n "${VALGRIND}" ]; then
|
|
|
|
VALGRIND_EXEC="valgrind ${VALGRIND} --log-socket=127.0.1.1"
|
|
|
|
fi
|
|
|
|
|
2019-08-06 02:44:18 +00:00
|
|
|
# On OSX only, we need to specify the direct_io and auto_cache flag.
|
2019-08-03 16:49:13 +00:00
|
|
|
if [ `uname` = "Darwin" ]; then
|
2019-08-06 02:44:18 +00:00
|
|
|
DIRECT_IO_OPT="-o direct_io -o auto_cache"
|
2019-08-03 16:49:13 +00:00
|
|
|
else
|
|
|
|
DIRECT_IO_OPT=""
|
|
|
|
fi
|
|
|
|
|
2021-01-04 14:32:04 +00:00
|
|
|
if [ -n "${CHAOS_HTTP_PROXY}" ]; then
|
|
|
|
export http_proxy="127.0.0.1:1080"
|
|
|
|
fi
|
|
|
|
|
2020-12-23 10:34:04 +00:00
|
|
|
# [NOTE]
|
|
|
|
# On macos, running s3fs via stdbuf will result in no response.
|
|
|
|
# Therefore, when it is macos, it is not executed via stdbuf.
|
|
|
|
# This patch may be temporary, but no other method has been found at this time.
|
|
|
|
#
|
|
|
|
if [ `uname` = "Darwin" ]; then
|
|
|
|
VIA_STDBUF_CMDLINE=""
|
|
|
|
else
|
|
|
|
VIA_STDBUF_CMDLINE="${STDBUF_BIN} -oL -eL"
|
|
|
|
fi
|
|
|
|
|
2016-02-05 12:24:13 +00:00
|
|
|
# Common s3fs options:
|
|
|
|
#
|
2019-01-27 12:04:29 +00:00
|
|
|
# TODO: Allow all these options to be overridden with env variables
|
2016-02-05 12:24:13 +00:00
|
|
|
#
|
|
|
|
# use_path_request_style
|
|
|
|
# The test env doesn't have virtual hosts
|
|
|
|
# createbucket
|
|
|
|
# S3Proxy always starts with no buckets, this tests the s3fs-fuse
|
|
|
|
# automatic bucket creation path.
|
|
|
|
# $AUTH_OPT
|
|
|
|
# Will be either "-o public_bucket=1"
|
|
|
|
# or
|
|
|
|
# "-o passwd_file=${S3FS_CREDENTIALS_FILE}"
|
|
|
|
# dbglevel
|
|
|
|
# error by default. override with DBGLEVEL env variable
|
|
|
|
# -f
|
|
|
|
# Keep s3fs in foreground instead of daemonizing
|
|
|
|
#
|
|
|
|
|
|
|
|
# subshell with set -x to log exact invocation of s3fs-fuse
|
|
|
|
(
|
|
|
|
set -x
|
2020-12-23 10:34:04 +00:00
|
|
|
${VIA_STDBUF_CMDLINE} \
|
2016-02-05 12:24:13 +00:00
|
|
|
${VALGRIND_EXEC} ${S3FS} \
|
|
|
|
$TEST_BUCKET_1 \
|
|
|
|
$TEST_BUCKET_MOUNT_POINT_1 \
|
|
|
|
-o use_path_request_style \
|
|
|
|
-o url=${S3_URL} \
|
2020-11-15 13:10:26 +00:00
|
|
|
-o endpoint=${S3_ENDPOINT} \
|
2017-09-17 23:14:58 +00:00
|
|
|
-o no_check_certificate \
|
|
|
|
-o ssl_verify_hostname=0 \
|
2019-01-14 02:48:40 +00:00
|
|
|
-o use_xattr=1 \
|
2016-02-05 12:24:13 +00:00
|
|
|
-o createbucket \
|
|
|
|
${AUTH_OPT} \
|
2019-08-03 16:49:13 +00:00
|
|
|
${DIRECT_IO_OPT} \
|
2019-08-06 10:55:38 +00:00
|
|
|
-o stat_cache_expire=1 \
|
|
|
|
-o stat_cache_interval_expire=1 \
|
2016-02-05 12:24:13 +00:00
|
|
|
-o dbglevel=${DBGLEVEL:=info} \
|
2017-08-11 14:09:43 +00:00
|
|
|
-o retries=3 \
|
2016-02-05 12:24:13 +00:00
|
|
|
-f \
|
2020-09-17 12:03:52 +00:00
|
|
|
"${@}" &
|
|
|
|
echo $! >&3
|
2020-12-23 10:34:04 +00:00
|
|
|
) 3>pid | ${STDBUF_BIN} -oL -eL ${SED_BIN} ${SED_BUFFER_FLAG} "s/^/s3fs: /" &
|
2020-09-17 12:03:52 +00:00
|
|
|
sleep 1
|
|
|
|
export S3FS_PID=$(<pid)
|
|
|
|
rm -f pid
|
2016-02-05 12:24:13 +00:00
|
|
|
|
2017-08-11 14:09:43 +00:00
|
|
|
if [ `uname` = "Darwin" ]; then
|
|
|
|
set +o errexit
|
|
|
|
TRYCOUNT=0
|
2020-08-15 08:27:45 +00:00
|
|
|
while [ $TRYCOUNT -le ${RETRIES:=20} ]; do
|
2017-08-11 14:09:43 +00:00
|
|
|
df | grep -q $TEST_BUCKET_MOUNT_POINT_1
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
break;
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
TRYCOUNT=`expr ${TRYCOUNT} + 1`
|
|
|
|
done
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
set -o errexit
|
|
|
|
else
|
2020-08-15 08:27:45 +00:00
|
|
|
retry ${RETRIES:=20} grep -q $TEST_BUCKET_MOUNT_POINT_1 /proc/mounts || exit 1
|
2017-08-11 14:09:43 +00:00
|
|
|
fi
|
2016-02-05 12:24:13 +00:00
|
|
|
|
|
|
|
# Quick way to start system up for manual testing with options under test
|
|
|
|
if [[ -n ${INTERACT} ]]; then
|
|
|
|
echo "Mountpoint $TEST_BUCKET_MOUNT_POINT_1 is ready"
|
|
|
|
echo "control-C to quit"
|
|
|
|
sleep infinity
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function stop_s3fs {
|
|
|
|
# Retry in case file system is in use
|
2017-08-11 14:09:43 +00:00
|
|
|
if [ `uname` = "Darwin" ]; then
|
2019-06-19 17:34:58 +00:00
|
|
|
if df | grep -q $TEST_BUCKET_MOUNT_POINT_1; then
|
2021-01-25 09:32:40 +00:00
|
|
|
retry 10 df "|" grep -q $TEST_BUCKET_MOUNT_POINT_1 "&&" umount $TEST_BUCKET_MOUNT_POINT_1
|
2017-08-11 14:09:43 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
if grep -q $TEST_BUCKET_MOUNT_POINT_1 /proc/mounts; then
|
2021-01-04 13:28:40 +00:00
|
|
|
retry 10 grep -q $TEST_BUCKET_MOUNT_POINT_1 /proc/mounts "&&" fusermount -u $TEST_BUCKET_MOUNT_POINT_1
|
2017-08-11 14:09:43 +00:00
|
|
|
fi
|
2016-02-05 12:24:13 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# trap handlers do not stack. If a test sets its own, the new handler should call common_exit_handler
|
|
|
|
function common_exit_handler {
|
|
|
|
stop_s3fs
|
2017-08-11 14:09:43 +00:00
|
|
|
stop_s3proxy
|
2016-02-05 12:24:13 +00:00
|
|
|
}
|
|
|
|
trap common_exit_handler EXIT
|
2020-08-22 12:40:53 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Local variables:
|
|
|
|
# tab-width: 4
|
|
|
|
# c-basic-offset: 4
|
|
|
|
# End:
|
2020-09-15 13:11:14 +00:00
|
|
|
# vim600: expandtab sw=4 ts=4 fdm=marker
|
|
|
|
# vim<600: expandtab sw=4 ts=4
|
2020-08-22 12:40:53 +00:00
|
|
|
#
|