Use mc functional tests for verifying build (#4934)

This commit is contained in:
Bala FA 2017-09-20 13:22:05 -07:00 committed by Harshavardhana
parent 3c0d3f7510
commit 6d7df1d1cb

View file

@ -15,56 +15,35 @@
# limitations under the License.
#
WORK_DIR="$PWD/verify-$RANDOM"
set -e
set -E
set -o pipefail
if [ ! -x "$PWD/minio" ]; then
echo "minio executable binary not found in current directory"
exit 1
fi
WORK_DIR="$PWD/.verify-$RANDOM"
export MINT_MODE=core
export MINT_DATA_DIR="$WORK_DIR/data"
export SERVER_ENDPOINT="127.0.0.1:9000"
export ACCESS_KEY="minio"
export SECRET_KEY="minio123"
export ENABLE_HTTPS=0
MINIO_CONFIG_DIR="$WORK_DIR/.minio"
MC_CONFIG_DIR="$WORK_DIR/.mc"
SERVER_ALIAS="myminio"
ACCESS_KEY="minio"
SECRET_KEY="minio123"
BUCKET_NAME="mc-test-bucket-$RANDOM"
MINIO="$PWD/minio"
MC_CMD="$WORK_DIR/mc"
FILE_1_MB="$WORK_DIR/datafile-1-MB"
FILE_65_MB="$WORK_DIR/datafile-65-MB"
MINIO=( "$PWD/minio" --config-dir "$MINIO_CONFIG_DIR" )
function create_minio_config()
{
## version is purposefully set to '3' for minio to migrate configuration file
echo '{"version": "3", "credential": {"accessKey": "minio", "secretKey": "minio123"}, "region": "us-east-1"}' > "$MINIO_CONFIG_DIR/config.json"
}
FILE_1_MB="$MINT_DATA_DIR/datafile-1-MB"
FILE_65_MB="$MINT_DATA_DIR/datafile-65-MB"
function assert_run_mc_command()
{
outfile="$WORK_DIR/cmd.out.$RANDOM"
rv=0
if ! "${MC_CMD}" --config-folder "$MC_CONFIG_DIR" --quiet --no-color "$@" >"$outfile" 2>&1; then
echo "failed to run command: ${MC_CMD}" "$@"
cat "$outfile"
rv=1
fi
rm -f "$outfile"
if [ "$rv" -ne 0 ]; then
exit 1
fi
}
function assert_download_mc()
{
if ! wget -q -O "${MC_CMD}" https://dl.minio.io/client/mc/release/linux-amd64/mc; then
echo "failed to download 'mc'"
exit 1
fi
chmod a+x "${MC_CMD}"
assert_run_mc_command config host add "${SERVER_ALIAS}" http://127.0.0.1:9000 minio minio123
}
FUNCTIONAL_TESTS="$WORK_DIR/functional-tests.sh"
function start_minio_fs()
{
"$MINIO" --config-dir "$MINIO_CONFIG_DIR" server "${WORK_DIR}/fs-disk" >"$WORK_DIR/fs-minio.log" 2>&1 &
"${MINIO[@]}" server "${WORK_DIR}/fs-disk" >"$WORK_DIR/fs-minio.log" 2>&1 &
minio_pid=$!
sleep 3
@ -73,7 +52,7 @@ function start_minio_fs()
function start_minio_xl()
{
"$MINIO" --config-dir "$MINIO_CONFIG_DIR" server "${WORK_DIR}/xl-disk1" "${WORK_DIR}/xl-disk2" "${WORK_DIR}/xl-disk3" "${WORK_DIR}/xl-disk4" >"$WORK_DIR/xl-minio.log" 2>&1 &
"${MINIO[@]}" server "${WORK_DIR}/xl-disk1" "${WORK_DIR}/xl-disk2" "${WORK_DIR}/xl-disk3" "${WORK_DIR}/xl-disk4" >"$WORK_DIR/xl-minio.log" 2>&1 &
minio_pid=$!
sleep 3
@ -83,85 +62,24 @@ function start_minio_xl()
function start_minio_dist()
{
declare -a minio_pids
"$MINIO" --config-dir "$MINIO_CONFIG_DIR" server --address=:9000 "http://127.0.0.1:9000${WORK_DIR}/dist-disk1" "http://127.0.0.1:9001${WORK_DIR}/dist-disk2" "http://127.0.0.1:9002${WORK_DIR}/dist-disk3" "http://127.0.0.1:9003${WORK_DIR}/dist-disk4" >"$WORK_DIR/dist-minio-9000.log" 2>&1 &
"${MINIO[@]}" server --address=:9000 "http://127.0.0.1:9000${WORK_DIR}/dist-disk1" "http://127.0.0.1:9001${WORK_DIR}/dist-disk2" "http://127.0.0.1:9002${WORK_DIR}/dist-disk3" "http://127.0.0.1:9003${WORK_DIR}/dist-disk4" >"$WORK_DIR/dist-minio-9000.log" 2>&1 &
minio_pids[0]=$!
"$MINIO" --config-dir "$MINIO_CONFIG_DIR" server --address=:9001 "http://127.0.0.1:9000${WORK_DIR}/dist-disk1" "http://127.0.0.1:9001${WORK_DIR}/dist-disk2" "http://127.0.0.1:9002${WORK_DIR}/dist-disk3" "http://127.0.0.1:9003${WORK_DIR}/dist-disk4" >"$WORK_DIR/dist-minio-9001.log" 2>&1 &
"${MINIO[@]}" server --address=:9001 "http://127.0.0.1:9000${WORK_DIR}/dist-disk1" "http://127.0.0.1:9001${WORK_DIR}/dist-disk2" "http://127.0.0.1:9002${WORK_DIR}/dist-disk3" "http://127.0.0.1:9003${WORK_DIR}/dist-disk4" >"$WORK_DIR/dist-minio-9001.log" 2>&1 &
minio_pids[1]=$!
"$MINIO" --config-dir "$MINIO_CONFIG_DIR" server --address=:9002 "http://127.0.0.1:9000${WORK_DIR}/dist-disk1" "http://127.0.0.1:9001${WORK_DIR}/dist-disk2" "http://127.0.0.1:9002${WORK_DIR}/dist-disk3" "http://127.0.0.1:9003${WORK_DIR}/dist-disk4" >"$WORK_DIR/dist-minio-9002.log" 2>&1 &
"${MINIO[@]}" server --address=:9002 "http://127.0.0.1:9000${WORK_DIR}/dist-disk1" "http://127.0.0.1:9001${WORK_DIR}/dist-disk2" "http://127.0.0.1:9002${WORK_DIR}/dist-disk3" "http://127.0.0.1:9003${WORK_DIR}/dist-disk4" >"$WORK_DIR/dist-minio-9002.log" 2>&1 &
minio_pids[2]=$!
"$MINIO" --config-dir "$MINIO_CONFIG_DIR" server --address=:9003 "http://127.0.0.1:9000${WORK_DIR}/dist-disk1" "http://127.0.0.1:9001${WORK_DIR}/dist-disk2" "http://127.0.0.1:9002${WORK_DIR}/dist-disk3" "http://127.0.0.1:9003${WORK_DIR}/dist-disk4" >"$WORK_DIR/dist-minio-9003.log" 2>&1 &
"${MINIO[@]}" server --address=:9003 "http://127.0.0.1:9000${WORK_DIR}/dist-disk1" "http://127.0.0.1:9001${WORK_DIR}/dist-disk2" "http://127.0.0.1:9002${WORK_DIR}/dist-disk3" "http://127.0.0.1:9003${WORK_DIR}/dist-disk4" >"$WORK_DIR/dist-minio-9003.log" 2>&1 &
minio_pids[3]=$!
sleep 30
echo "${minio_pids[@]}"
}
function test_make_bucket()
{
bucket_name="mc-test-bucket-$RANDOM"
assert_run_mc_command mb "${SERVER_ALIAS}/${bucket_name}"
assert_run_mc_command rm "${SERVER_ALIAS}/${bucket_name}"
}
function setup()
{
assert_run_mc_command mb "${SERVER_ALIAS}/${BUCKET_NAME}"
}
function teardown()
{
assert_run_mc_command rm --force --recursive "${SERVER_ALIAS}/${BUCKET_NAME}"
}
function test_put_object()
{
object_name="mc-test-object-$RANDOM"
assert_run_mc_command cp "${FILE_1_MB}" "${SERVER_ALIAS}/${BUCKET_NAME}/${object_name}"
assert_run_mc_command rm "${SERVER_ALIAS}/${BUCKET_NAME}/${object_name}"
}
function test_put_object_multipart()
{
object_name="mc-test-object-$RANDOM"
assert_run_mc_command cp "${FILE_65_MB}" "${SERVER_ALIAS}/${BUCKET_NAME}/${object_name}"
assert_run_mc_command rm "${SERVER_ALIAS}/${BUCKET_NAME}/${object_name}"
}
function test_get_object()
{
object_name="mc-test-object-$RANDOM"
assert_run_mc_command cp "${FILE_1_MB}" "${SERVER_ALIAS}/${BUCKET_NAME}/${object_name}"
assert_run_mc_command cp "${SERVER_ALIAS}/${BUCKET_NAME}/${object_name}" "${object_name}.downloaded"
assert_run_mc_command rm "${object_name}.downloaded" "${SERVER_ALIAS}/${BUCKET_NAME}/${object_name}"
}
function test_get_object_multipart()
{
object_name="mc-test-object-$RANDOM"
assert_run_mc_command cp "${FILE_65_MB}" "${SERVER_ALIAS}/${BUCKET_NAME}/${object_name}"
assert_run_mc_command cp "${SERVER_ALIAS}/${BUCKET_NAME}/${object_name}" "${object_name}.downloaded"
assert_run_mc_command rm "${object_name}.downloaded" "${SERVER_ALIAS}/${BUCKET_NAME}/${object_name}"
}
function run_test()
{
test_make_bucket
setup
test_put_object
test_put_object_multipart
test_get_object
test_get_object_multipart
teardown
}
function run_test_fs()
{
minio_pid="$(start_minio_fs)"
( run_test )
(cd "$WORK_DIR" && "$FUNCTIONAL_TESTS")
rv=$?
kill "$minio_pid"
@ -179,7 +97,7 @@ function run_test_xl()
{
minio_pid="$(start_minio_xl)"
( run_test )
(cd "$WORK_DIR" && "$FUNCTIONAL_TESTS")
rv=$?
kill "$minio_pid"
@ -197,7 +115,7 @@ function run_test_dist()
{
minio_pids=( $(start_minio_dist) )
( run_test )
(cd "$WORK_DIR" && "$FUNCTIONAL_TESTS")
rv=$?
for pid in "${minio_pids[@]}"; do
@ -221,44 +139,51 @@ function run_test_dist()
return "$rv"
}
function __init__()
{
echo "Initializing environment"
mkdir -p "$WORK_DIR"
mkdir -p "$MINIO_CONFIG_DIR"
mkdir -p "$MINT_DATA_DIR"
if ! wget -q -O "$WORK_DIR/mc" https://dl.minio.io/client/mc/release/linux-amd64/mc; then
echo "failed to download https://dl.minio.io/client/mc/release/linux-amd64/mc"
exit 1
fi
chmod a+x "$WORK_DIR/mc"
base64 /dev/urandom | head -c 1048576 >"$FILE_1_MB"
base64 /dev/urandom | head -c 68157440 >"$FILE_65_MB"
## version is purposefully set to '3' for minio to migrate configuration file
echo '{"version": "3", "credential": {"accessKey": "minio", "secretKey": "minio123"}, "region": "us-east-1"}' > "$MINIO_CONFIG_DIR/config.json"
if ! wget -q -O "$FUNCTIONAL_TESTS" https://raw.githubusercontent.com/minio/mc/master/functional-tests.sh; then
echo "failed to download https://raw.githubusercontent.com/minio/mc/master/functional-tests.sh"
exit 1
fi
chmod a+x "$FUNCTIONAL_TESTS"
}
function main()
{
mkdir "$WORK_DIR"
mkdir "$MINIO_CONFIG_DIR"
mkdir "$MC_CONFIG_DIR"
if ! base64 /dev/urandom | head -c 1048576 >"$FILE_1_MB"; then
echo "unable to create 1 MiB file"
exit 1
fi
if ! base64 /dev/urandom | head -c 68157440 >"$FILE_65_MB"; then
echo "unable to create 65 MiB file"
exit 1
fi
create_minio_config
echo "downloading mc"
assert_download_mc
cd "$WORK_DIR"
echo "running test in FS setup"
echo "Testing in FS setup"
if ! run_test_fs; then
echo "running test for FS setup failed"
rm -fr "$WORK_DIR"
exit 1
fi
echo "running test in XL setup"
echo "Testing in XL setup"
if ! run_test_xl; then
echo "running test for XL setup"
rm -fr "$WORK_DIR"
exit 1
fi
echo "running test in Distribute XL setup"
echo "Testing in Distribute XL setup"
if ! run_test_dist; then
echo "running test for Distribute setup"
rm -fr "$WORK_DIR"
@ -268,5 +193,7 @@ function main()
rm -fr "$WORK_DIR"
}
set -e
main "$@"
( __init__ "$@" && main "$@" )
rv=$?
rm -fr "$WORK_DIR"
exit "$rv"