Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mc logging and exit on first failure #159

Merged
merged 1 commit into from
Sep 29, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 36 additions & 28 deletions run/core/mc/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ function get_duration() {

function log_success() {
function=$(python -c 'import sys,json; print(json.dumps(sys.stdin.read()))' <<<"$2")
printf '{"name": "mc", "duration": "%d", "function": %s, "status": "PASS"}\n' "$1" "$function"
printf '{"name": "mc", "duration": %d, "function": %s, "status": "PASS"}\n' "$1" "$function"
}

function log_failure() {
function=$(python -c 'import sys,json; print(json.dumps(sys.stdin.read()))' <<<"$2")
printf '{"name": "mc", "duration": "%d", "function": %s, "status": "FAIL", "error": %s}\n' "$1" "$function" "$3"
printf '{"name": "mc", "duration": %d, "function": %s, "status": "FAIL", "error": "%s"}\n' "$1" "$function" "$3"
}

function log_alert() {
function=$(python -c 'import sys,json; print(json.dumps(sys.stdin.read()))' <<<"$2")
printf '{"name": "mc", "duration": "%d", "function": %s, "status": "FAIL", "alert": "%d", error": "%s"}\n' "$1" "$function" "$3" "$4"
printf '{"name": "mc", "duration": %d, "function": %s, "status": "FAIL", "alert": "%d", error": "%s"}\n' "$1" "$function" "$3" "$4"
}

function make_bucket() {
Expand Down Expand Up @@ -83,7 +83,8 @@ function test_make_bucket() {
start_time=$(get_time)

function="make_bucket"
bucket_name=$(make_bucket)
test_function=${function}
bucket_name=$(make_bucket)
rv=$?

# if make_bucket is successful remove the bucket
Expand All @@ -92,13 +93,14 @@ function test_make_bucket() {
out=$(delete_bucket "${bucket_name}")
rv=$?
else
# if make bucket failes, $bucket_name has the error output
# if make bucket fails, $bucket_name has the error output
out="${bucket_name}"
fi

if [ $rv -eq 0 ]; then
log_success "$(get_duration "$start_time")" "${function}"
log_success "$(get_duration "$start_time")" "${test_function}"
else
${MC_CMD} rm --force --recursive ${SERVER_ALIAS}/"${bucket_name}" > /dev/null 2>&1
log_failure "$(get_duration "$start_time")" "${function}" "${out}"
fi

Expand All @@ -121,7 +123,7 @@ function test_put_object() {
out=$($function 2>&1)
rv=$?
else
# if make bucket failes, $bucket_name has the error output
# if make bucket fails, $bucket_name has the error output
out="${bucket_name}"
fi

Expand Down Expand Up @@ -152,6 +154,7 @@ function test_put_object() {
if [ $rv -eq 0 ]; then
log_success "$(get_duration "$start_time")" "${test_function}"
else
${MC_CMD} rm --force --recursive ${SERVER_ALIAS}/"${bucket_name}" > /dev/null 2>&1
log_failure "$(get_duration "$start_time")" "${function}" "${out}"
fi

Expand All @@ -176,7 +179,7 @@ function test_put_object_multipart() {
out=$($function 2>&1)
rv=$?
else
# if make bucket failes, $bucket_name has the error output
# if make bucket fails, $bucket_name has the error output
out="${bucket_name}"
fi

Expand Down Expand Up @@ -207,6 +210,7 @@ function test_put_object_multipart() {
if [ $rv -eq 0 ]; then
log_success "$(get_duration "$start_time")" "${test_function}"
else
${MC_CMD} rm --force --recursive ${SERVER_ALIAS}/"${bucket_name}" > /dev/null 2>&1
log_failure "$(get_duration "$start_time")" "${function}" "${out}"
fi

Expand Down Expand Up @@ -234,7 +238,7 @@ function test_presigned_upload_object() {
out=$($function 2>&1)
rv=$?
else
# if make bucket failes, $bucket_name has the error output
# if make bucket fails, $bucket_name has the error output
out="${bucket_name}"
fi

Expand Down Expand Up @@ -269,6 +273,7 @@ function test_presigned_upload_object() {
if [ $rv -eq 0 ]; then
log_success "$(get_duration "$start_time")" "${test_function}"
else
${MC_CMD} rm --force --recursive ${SERVER_ALIAS}/"${bucket_name}" > /dev/null 2>&1
log_failure "$(get_duration "$start_time")" "${function}" "${out}"
fi

Expand All @@ -294,7 +299,7 @@ function test_presigned_download_object() {
out=$($function 2>&1)
rv=$?
else
# if make bucket failes, $bucket_name has the error output
# if make bucket fails, $bucket_name has the error output
out="${bucket_name}"
fi

Expand Down Expand Up @@ -328,6 +333,7 @@ function test_presigned_download_object() {
if [ $rv -eq 0 ]; then
log_success "$(get_duration "$start_time")" "${test_function}"
else
${MC_CMD} rm --force --recursive ${SERVER_ALIAS}/"${bucket_name}" > /dev/null 2>&1
log_failure "$(get_duration "$start_time")" "${function}" "${out}"
fi

Expand All @@ -354,12 +360,12 @@ function test_mirror_list_objects() {
out=$($function 2>&1)
rv=$?
else
# if make bucket failes, $bucket_name has the error output
# if make bucket fails, $bucket_name has the error output
out="${bucket_name}"
fi

if [ $rv -eq 0 ]; then
if diff -bB <(ls "$MINT_DATA_DIR") <(./mc ls --json "${SERVER_ALIAS}/${bucket_name}" | jq -r .key); then
if diff -bB <(find "$MINT_DATA_DIR" -type f -printf "%f\n" | sort) <(./mc ls --json "${SERVER_ALIAS}/${bucket_name}" | jq -r .key | sort) > /dev/null; then
function="delete_bucket"
out=$(delete_bucket "$bucket_name")
rv=$?
Expand All @@ -371,6 +377,7 @@ function test_mirror_list_objects() {
if [ $rv -eq 0 ]; then
log_success "$(get_duration "$start_time")" "${test_function}"
else
${MC_CMD} rm --force --recursive ${SERVER_ALIAS}/"${bucket_name}" > /dev/null 2>&1
log_failure "$(get_duration "$start_time")" "${function}" "${out}"
fi

Expand All @@ -395,7 +402,7 @@ function test_cat_objects() {
out=$($function 2>&1)
rv=$?
else
# if make bucket failes, $bucket_name has the error output
# if make bucket fails, $bucket_name has the error output
out="${bucket_name}"
fi

Expand All @@ -422,6 +429,7 @@ function test_cat_objects() {
if [ $rv -eq 0 ]; then
log_success "$(get_duration "$start_time")" "${test_function}"
else
${MC_CMD} rm --force --recursive ${SERVER_ALIAS}/"${bucket_name}" > /dev/null 2>&1
log_failure "$(get_duration "$start_time")" "${function}" "${out}"
fi

Expand Down Expand Up @@ -472,11 +480,13 @@ function test_make_bucket_error() {

# execute the test
out=$($function 2>&1)
rv=$?
rv=$?

if [ $rv -eq 1 ]; then
log_success "$(get_duration "$start_time")" "${function}"
rv=0
else
${MC_CMD} rm --force --recursive ${SERVER_ALIAS}/"${bucket_name}" > /dev/null 2>&1
log_failure "$(get_duration "$start_time")" "${function}" "${out}"
fi

Expand All @@ -503,7 +513,7 @@ function test_put_object_error() {
out=$($function 2>&1)
rv=$?
else
# if make bucket failes, $bucket_name has the error output
# if make bucket fails, $bucket_name has the error output
out="${bucket_name}"
fi

Expand All @@ -519,6 +529,7 @@ function test_put_object_error() {
if [ $rv -eq 0 ]; then
log_success "$(get_duration "$start_time")" "${test_function}"
else
${MC_CMD} rm --force --recursive ${SERVER_ALIAS}/"${bucket_name}" > /dev/null 2>&1
log_failure "$(get_duration "$start_time")" "${function}" "${out}"
fi

Expand All @@ -528,20 +539,17 @@ function test_put_object_error() {
# main handler for all the tests.
function main() {

# Success tests
test_make_bucket
test_put_object
test_put_object_multipart
test_presigned_upload_object
test_presigned_download_object
test_mirror_list_objects
test_cat_objects

# TODO Add Policy tests once supported on GCS

# Negative tests
test_make_bucket_error
test_make_bucket && \
test_put_object && \
test_put_object_multipart && \
test_presigned_upload_object && \
test_presigned_download_object && \
test_mirror_list_objects && \
test_cat_objects && \
test_make_bucket_error && \
test_put_object_error

return $?
}

main