From 8c40808b94a536b48be023b706ec3b76eadb5ccd Mon Sep 17 00:00:00 2001 From: Shizun Ge Date: Tue, 20 Feb 2024 19:12:33 -0800 Subject: [PATCH] Improve logging and notification. * Notify when there is an error before updating. * Improve docker log when there is an error from daemon. * Improve error messages on registry config files. * Test quote input arguments. --- README.md | 2 +- src/docker_hub_rate.sh | 28 +++-- src/entrypoint.sh | 6 +- src/lib-common.sh | 111 ++++++++++++------ src/lib-gantry.sh | 39 +++--- tests/gantry_cleanup_images_spec.sh | 30 ++--- tests/gantry_common_options_spec.sh | 16 +-- tests/gantry_filters_spec.sh | 14 +-- tests/gantry_login_spec.sh | 50 ++++---- tests/gantry_manifest_spec.sh | 26 ++-- tests/gantry_notify_spec.sh | 8 +- tests/gantry_parallel_spec.sh | 26 ++-- tests/gantry_rollback_spec.sh | 18 +-- tests/gantry_service_multiple_spec.sh | 16 +-- tests/gantry_service_no_running_tasks_spec.sh | 14 +-- tests/gantry_service_single_spec.sh | 18 +-- tests/gantry_update_options_spec.sh | 20 ++-- tests/spec_gantry_test_helper.sh | 2 +- 18 files changed, 244 insertions(+), 200 deletions(-) diff --git a/README.md b/README.md index 2fb2d96..dd53de1 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ You can configure the most behaviors of *Gantry* via environment variables. | Environment Variable | Default |Description | |-----------------------|---------|------------| -| GANTRY_LOG_LEVEL | INFO | Control how many logs generated by *Gantry*. Valid values are `NONE`, `ERROR`, `WARN`, `INFO`, `DEBUG` (case sensitive). | +| GANTRY_LOG_LEVEL | INFO | Control how many logs generated by *Gantry*. Valid values are `NONE`, `ERROR`, `WARN`, `INFO`, `DEBUG`. | | GANTRY_NODE_NAME | | Add node name to logs. If not set, *Gantry* will use the host name of the Docker Swarm's manager, which is read from either the Docker daemon socket of current node or `DOCKER_HOST`. | | GANTRY_POST_RUN_CMD | | Command(s) to `eval` after each updating iteration. | | GANTRY_PRE_RUN_CMD | | Command(s) to `eval` before each updating iteration. | diff --git a/src/docker_hub_rate.sh b/src/docker_hub_rate.sh index d23efc9..0159b3c 100755 --- a/src/docker_hub_rate.sh +++ b/src/docker_hub_rate.sh @@ -46,6 +46,18 @@ _docker_hub_rate_read_rate() { wget -qS --spider --header="${HEADER}" -O /dev/null "${URL}" 2>&1 } +_docker_hub_echo_error() { + local TITLE="${1}" + local RESPONSE="${2}" + local OLD_LOG_SCOPE="${LOG_SCOPE}" + LOG_SCOPE=$(attach_tag_to_log_scope "docker-hub") + export LOG_SCOPE + log DEBUG "${TITLE}: RESPONSE=" + echo "${RESPONSE}" | log_lines DEBUG + echo "[${TITLE}]" + export LOG_SCOPE="${OLD_LOG_SCOPE}" +} + docker_hub_rate() { local IMAGE="${1:-ratelimitpreview/test}" local USER_AND_PASS="${2}" @@ -58,17 +70,13 @@ docker_hub_rate() { fi local RESPONSE= if ! RESPONSE=$(_docker_hub_rate_token "${IMAGE}" "${USER_AND_PASS}" 2>&1); then - log DEBUG "Read docker hub token error: RESPONSE=" - echo "${RESPONSE}" | log_lines DEBUG - echo "[GET TOKEN RESPONSE ERROR]" + _docker_hub_echo_error "GET TOKEN RESPONSE ERROR" "${RESPONSE}" return 1 fi local TOKEN= TOKEN=$(echo "${RESPONSE}" | sed 's/.*"token":"\([^"]*\).*/\1/') if [ -z "${TOKEN}" ]; then - log DEBUG "Parse docker hub token error: RESPONSE=" - echo "${RESPONSE}" | log_lines DEBUG - echo "[PARSE TOKEN ERROR]" + _docker_hub_echo_error "PARSE TOKEN ERROR" "${RESPONSE}" return 1 fi if ! RESPONSE=$(_docker_hub_rate_read_rate "${IMAGE}" "${TOKEN}" 2>&1); then @@ -76,17 +84,13 @@ docker_hub_rate() { echo "0" return 0 fi - log DEBUG "Read docker hub rate error: RESPONSE=" - echo "${RESPONSE}" | log_lines DEBUG - echo "[GET RATE RESPONSE ERROR]" + _docker_hub_echo_error "GET RATE RESPONSE ERROR" "${RESPONSE}" return 1 fi local RATE= RATE=$(echo "${RESPONSE}" | sed -n 's/.*ratelimit-remaining: \([0-9]*\).*/\1/p' ) if [ -z "${RATE}" ]; then - log DEBUG "Parse docker hub rate error: RESPONSE=" - echo "${RESPONSE}" | log_lines DEBUG - echo "[PARSE RATE ERROR]" + _docker_hub_echo_error "PARSE RATE ERROR" "${RESPONSE}" return 1 fi echo "${RATE}" diff --git a/src/entrypoint.sh b/src/entrypoint.sh index 3593d87..fab2ea5 100755 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -126,7 +126,7 @@ gantry() { DOCKER_HUB_RATE_USED=$(difference_between "${DOCKER_HUB_RATE_BEFORE}" "${DOCKER_HUB_RATE_AFTER}") log INFO "After updating, Docker Hub rate remains ${DOCKER_HUB_RATE_AFTER}. Used rate ${DOCKER_HUB_RATE_USED}." - gantry_finalize "${STACK}"; + gantry_finalize "${STACK}" "${ACCUMULATED_ERRORS}"; ACCUMULATED_ERRORS=$((ACCUMULATED_ERRORS + $?)) eval_cmd "post-run" "${POST_RUN_CMD}" @@ -142,7 +142,7 @@ gantry() { log INFO "${MESSAGE}" RETURN_VALUE=0 fi - return ${RETURN_VALUE} + return "${RETURN_VALUE}" } main() { @@ -172,7 +172,7 @@ main() { sleep "${SLEEP_SECONDS}" fi done - return ${RETURN_VALUE} + return "${RETURN_VALUE}" } load_libraries diff --git a/src/lib-common.sh b/src/lib-common.sh index 92c84f0..191bcb1 100755 --- a/src/lib-common.sh +++ b/src/lib-common.sh @@ -21,11 +21,11 @@ _log_level() { local LEVEL="${1}"; [ -z "${LEVEL}" ] && _log_level "INFO" && return 1; - [ "${LEVEL}" = "DEBUG" ] && echo 0 && return 0; - [ "${LEVEL}" = "INFO" ] && echo 1 && return 0; - [ "${LEVEL}" = "WARN" ] && echo 2 && return 0; - [ "${LEVEL}" = "ERROR" ] && echo 3 && return 0; - [ "${LEVEL}" = "NONE" ] && echo 4 && return 0; + echo "${LEVEL}" | grep -q -i "^DEBUG$" && echo 0 && return 0; + echo "${LEVEL}" | grep -q -i "^INFO$" && echo 1 && return 0; + echo "${LEVEL}" | grep -q -i "^WARN$" && echo 2 && return 0; + echo "${LEVEL}" | grep -q -i "^ERROR$" && echo 3 && return 0; + echo "${LEVEL}" | grep -q -i "^NONE$" && echo 4 && return 0; _log_level "NONE"; return 1; } @@ -56,6 +56,7 @@ _log_formatter() { local LOG_LEVEL="${LOG_LEVEL}" local LEVEL="${1}"; shift; [ "$(_log_level "${LEVEL}")" -lt "$(_log_level "${LOG_LEVEL}")" ] && return 0; + LEVEL=$(echo "${LEVEL}" | tr '[:lower:]' '[:upper:]') local TIME="${1}"; shift; local LOCATION="${1}"; shift; local SCOPE="${1}"; shift; @@ -94,32 +95,55 @@ _log_docker_time() { local TIME_INPUT="${1}" local EPOCH= if ! EPOCH="$(busybox date -d "${TIME_INPUT}" -D "%Y-%m-%dT%H:%M:%S" -u +%s 2>/dev/null)"; then - local TIME= - TIME=$(echo "${TIME_INPUT}" | cut -d '.' -f 1) - echo "${TIME}+00:00" - return 0 + date -Iseconds + return 1 fi busybox date -d "@${EPOCH}" -Iseconds 2>&1 } +_log_docker_scope() { + local LOG_SCOPE="${LOG_SCOPE}" + local TASK_NODE="${1}" + local SCOPE= + SCOPE=$(echo "${TASK_NODE}" | sed -n "s/\(.*\)@.*/\1/p"); + if [ -z "${SCOPE}" ]; then + echo "${LOG_SCOPE}" + return 1 + fi + echo "${SCOPE}" +} + +_log_docker_node() { + local NODE_NAME="${NODE_NAME}" + local TASK_NODE="${1}" + local NODE= + NODE=$(echo "${TASK_NODE}" | sed -n "s/.*@\(.*\)/\1/p"); + if [ -z "${NODE}" ]; then + echo "${NODE_NAME}" + return 1 + fi + echo "${NODE}" +} + # Convert logs from `docker service logs` to `log` format. # docker service logs --timestamps --no-task-ids # 2023-06-22T01:20:54.535860111Z @ | _log_docker_line() { local LEVEL="INFO"; - local TIME_DOCKER TIME SCOPE NODE MESSAGE SPACE FIRST_WORD - TIME_DOCKER=$(echo "${@}" | cut -d ' ' -f 1); + local TIME_DOCKER TIME TASK_NODE SCOPE NODE MESSAGE SPACE FIRST_WORD + TIME_DOCKER=$(echo "${*} " | cut -d ' ' -f 1); TIME=$(_log_docker_time "${TIME_DOCKER}") - SCOPE=$(echo "${@}" | cut -d ' ' -f 2 | cut -d '@' -f 1); - NODE=$(echo "${@}" | cut -d ' ' -f 2 | cut -d '@' -f 2); - MESSAGE=$(echo "${@}" | cut -d '|' -f 2-); + TASK_NODE=$(echo "${*} " | cut -d ' ' -f 2) + SCOPE=$(_log_docker_scope "${TASK_NODE}"); + NODE=$(_log_docker_node "${TASK_NODE}"); + MESSAGE=$(echo "${*}" | cut -d '|' -f 2-); # Remove the leading space. - SPACE=$(echo "${MESSAGE}" | cut -d ' ' -f 1) - [ -z "${SPACE}" ] && MESSAGE=$(echo "${MESSAGE}" | cut -d ' ' -f 2-) - FIRST_WORD=$(echo "${MESSAGE}" | cut -d ' ' -f 1); + SPACE=$(echo "${MESSAGE} " | cut -d ' ' -f 1) + [ -z "${SPACE}" ] && MESSAGE=$(echo "${MESSAGE} " | cut -d ' ' -f 2-) + FIRST_WORD=$(echo "${MESSAGE} " | cut -d ' ' -f 1); if _log_level "${FIRST_WORD}" >/dev/null; then LEVEL=${FIRST_WORD}; - MESSAGE=$(echo "${MESSAGE}" | cut -d ' ' -f 2-); + MESSAGE=$(echo "${MESSAGE} " | cut -d ' ' -f 2-); fi _log_formatter "${LEVEL}" "${TIME}" "${NODE}" "${SCOPE}" "${MESSAGE}"; } @@ -139,7 +163,7 @@ is_number() { is_true() { local CONFIG="${1}" - CONFIG=$(echo "${CONFIG}" | cut -d ' ' -f 1) + CONFIG=$(echo "${CONFIG} " | cut -d ' ' -f 1) echo "${CONFIG}" | grep -q -i "true" } @@ -228,18 +252,18 @@ eval_cmd() { LOG_SCOPE=$(attach_tag_to_log_scope "${TAG}") export LOG_SCOPE local LOG= - local RT=0 + local RETURN_VALUE=0 log INFO "Run ${TAG} command: ${CMD}" if LOG=$(eval "${CMD}"); then echo "${LOG}" | log_lines INFO else - RT=$? + RETURN_VALUE=$? echo "${LOG}" | log_lines WARN - log WARN "${TAG} command returned a non-zero value ${RT}." + log WARN "${TAG} command returned a non-zero value ${RETURN_VALUE}." fi log INFO "Finish ${TAG} command." export LOG_SCOPE="${OLD_LOG_SCOPE}" - return "${RT}" + return "${RETURN_VALUE}" } swarm_network_arguments() { @@ -279,15 +303,17 @@ _get_docker_command_detach() { docker_service_logs () { local SERVICE_NAME="${1}" + local RETURN_VALUE=0 local LOGS= if ! LOGS=$(docker service logs --timestamps --no-task-ids "${SERVICE_NAME}" 2>&1); then - log ERROR "Failed to obtain logs of service ${SERVICE_NAME}. ${LOGS}" - return 1 + log ERROR "Failed to obtain logs of service ${SERVICE_NAME}." + RETURN_VALUE=1 fi echo "${LOGS}" | while read -r LINE; do _log_docker_line "${LINE}" done + return "${RETURN_VALUE}" } docker_service_logs_follow() { @@ -329,16 +355,22 @@ wait_service_state() { local WAIT_RUNNING WAIT_COMPLETE; WAIT_RUNNING=$(echo "${@}" | grep -q -- "--running" && echo "true" || echo "false") WAIT_COMPLETE=$(echo "${@}" | grep -q -- "--complete" && echo "true" || echo "false") + local RETURN_VALUE=0 + local DOCKER_CMD_ERROR=1 local SLEEP_SECONDS=1 local STATES= while STATES=$(_docker_service_task_states "${SERVICE_NAME}" 2>&1); do + if ! ("${WAIT_RUNNING}" || "${WAIT_COMPLETE}"); then + RETURN_VALUE=0 + DOCKER_CMD_ERROR=0 + break + fi local NUM_LINES=0 local NUM_RUNS=0 local NUM_DONES=0 local NUM_FAILS=0 while read -r LINE; do [ -z "${LINE}" ] && continue; - log INFO "Service ${SERVICE_NAME}: ${LINE}." NUM_LINES=$((NUM_LINES+1)); echo "${LINE}" | grep -q "Running" && NUM_RUNS=$((NUM_RUNS+1)); echo "${LINE}" | grep -q "Complete" && NUM_DONES=$((NUM_DONES+1)); @@ -346,28 +378,35 @@ wait_service_state() { done < <(echo "${STATES}") if [ "${NUM_LINES}" -gt 0 ]; then if "${WAIT_RUNNING}" && [ "${NUM_RUNS}" -eq "${NUM_LINES}" ]; then - return 0; + RETURN_VALUE=0 + DOCKER_CMD_ERROR=0 + break fi if "${WAIT_COMPLETE}" && [ "${NUM_DONES}" -eq "${NUM_LINES}" ]; then - return 0; + RETURN_VALUE=0 + DOCKER_CMD_ERROR=0 + break fi if "${WAIT_COMPLETE}" && [ "${NUM_FAILS}" -gt 0 ]; then # Get return value of the task from the string "task: non-zero exit (1)". local TASK_RETURN_VALUE= TASK_RETURN_VALUE=$(echo "${STATES}" | grep "Failed" | sed -n 's/.*task: non-zero exit (\([0-9]\+\)).*/\1/p') # Get the first error code. - local RETURN_VALUE=0 - RETURN_VALUE=$(echo "${TASK_RETURN_VALUE:-1}" | cut -d ' ' -f 1) - return "${RETURN_VALUE}" + RETURN_VALUE=$(echo "${TASK_RETURN_VALUE:-1} " | cut -d ' ' -f 1) + DOCKER_CMD_ERROR=0 + break fi fi - if ! ("${WAIT_RUNNING}" || "${WAIT_COMPLETE}"); then - return 0; - fi sleep "${SLEEP_SECONDS}" done - log ERROR "Failed to obtain task states of service ${SERVICE_NAME}: ${STATES}" - return 1 + if [ "${DOCKER_CMD_ERROR}" != "0" ]; then + log ERROR "Failed to obtain task states of service ${SERVICE_NAME}: ${STATES}" + return 1 + fi + while read -r LINE; do + log INFO "Service ${SERVICE_NAME}: ${LINE}." + done < <(echo "${STATES}") + return "${RETURN_VALUE}" } docker_service_remove() { diff --git a/src/lib-gantry.sh b/src/lib-gantry.sh index 8bd8473..01fbe6b 100755 --- a/src/lib-gantry.sh +++ b/src/lib-gantry.sh @@ -15,7 +15,7 @@ # along with this program. If not, see . # -# Read a number from an environment variable. Log an error is it is not a number. +# Read a number from an environment variable. Log an error when it is not a number. gantry_read_number() { local VNAME="${1}" local DEFAULT_VALUE="${2}" @@ -115,18 +115,20 @@ _authenticate_to_registries() { log ERROR "Failed to read CONFIGS_FILE ${CONFIGS_FILE}." return 1 fi + local LINE_NUM=0 local LINE= while read -r LINE; do + LINE_NUM=$((LINE_NUM+1)) # skip comments [ -z "${LINE}" ] && continue [ "${LINE:0:1}" = "#" ] && continue LINE=$(echo "${LINE}" | tr '\t' ' ') local OTHERS= - CONFIG=$(echo "${LINE}" | cut -d ' ' -f 1) - HOST=$(echo "${LINE}" | cut -d ' ' -f 2) - USER=$(echo "${LINE}" | cut -d ' ' -f 3) - PASSWORD=$(echo "${LINE}" | cut -d ' ' -f 4) - OTHERS=$(echo "${LINE}" | cut -d ' ' -f 5-) + CONFIG=$(echo "${LINE} " | cut -d ' ' -f 1) + HOST=$(echo "${LINE} " | cut -d ' ' -f 2) + USER=$(echo "${LINE} " | cut -d ' ' -f 3) + PASSWORD=$(echo "${LINE} " | cut -d ' ' -f 4) + OTHERS=$(echo "${LINE} " | cut -d ' ' -f 5-) local ERROR_MSG= if [ -n "${OTHERS}" ]; then ERROR_MSG="Found extra item(s)." @@ -135,8 +137,7 @@ _authenticate_to_registries() { ERROR_MSG="Missing item(s)." fi if [ -n "${ERROR_MSG}" ]; then - log ERROR "CONFIGS_FILE ${CONFIGS_FILE} format error. ${ERROR_MSG} A line should contains exactly \" \"." - log DEBUG "CONFIGS_FILE ${CONFIGS_FILE} format error. Got \"${LINE}\"." + log ERROR "CONFIGS_FILE ${CONFIGS_FILE} line ${LINE_NUM} format error. ${ERROR_MSG} A line should contains exactly \" \"." ACCUMULATED_ERRORS=$((ACCUMULATED_ERRORS + 1)) continue fi @@ -393,9 +394,9 @@ _report_services() { fi local NUM_TOTAL_ERRORS=$((NUM_FAILED+NUM_ERRORS)) local TYPE="success" - [ "${NUM_TOTAL_ERRORS}" -ne "0" ] && TYPE="failure" + [ "${NUM_TOTAL_ERRORS}" != "0" ] && TYPE="failure" local ERROR_STRING= - [ "${NUM_ERRORS}" -ne "0" ] && ERROR_STRING=" ${NUM_TOTAL_ERRORS} error(s)" + [ "${NUM_ERRORS}" != "0" ] && ERROR_STRING=" ${NUM_TOTAL_ERRORS} error(s)" local TITLE BODY TITLE="[${STACK}] ${NUM_UPDATED} services updated ${NUM_FAILED} failed${ERROR_STRING}" BODY=$(echo -e "${UPDATED_MSG}\n${FAILED_MSG}\n${ERROR_MSG}") @@ -447,8 +448,8 @@ _current_container_name() { # '//' # '/' (when network mode is host) local CNAME CIP - CNAME=$(echo "${NAME_AND_IP}" | cut -d/ -f1); - CIP=$(echo "${NAME_AND_IP}" | cut -d/ -f2); + CNAME=$(echo "${NAME_AND_IP}/" | cut -d/ -f1); + CIP=$(echo "${NAME_AND_IP}/" | cut -d/ -f2); # Unable to find the container IP when network mode is host. [ -z "${CIP}" ] && continue; for IP in ${IPS}; do @@ -721,7 +722,7 @@ _get_number_of_running_tasks() { # The REPLICAS is like "5/5" or "1/1 (3/5 completed)" # Get the number before the first "/". local NUM_RUNS= - NUM_RUNS=$(echo "${REPLICAS}" | cut -d '/' -f 1) + NUM_RUNS=$(echo "${REPLICAS}/" | cut -d '/' -f 1) echo "${NUM_RUNS}" } @@ -787,7 +788,7 @@ _update_single_service() { local INPUT_ERROR=0 [ -z "${SERVICE_NAME}" ] && log ERROR "Updating service: SERVICE_NAME must not be empty." && INPUT_ERROR=1 && SERVICE_NAME="unknown-service-name" [ -z "${IMAGE}" ] && log ERROR "Updating ${SERVICE_NAME}: IMAGE must not be empty." && INPUT_ERROR=1 - if [ "${INPUT_ERROR}" -ne "0" ]; then + if [ "${INPUT_ERROR}" != "0" ]; then _static_variable_add_unique_to_list STATIC_VAR_SERVICES_UPDATE_INPUT_ERROR "${SERVICE_NAME}" return 1; fi @@ -835,8 +836,8 @@ _update_worker() { while true; do SERVICE_AND_IMAGE=$(_static_variable_pop_list "${STATIC_VAR_LIST_NAME}") [ -z "${SERVICE_AND_IMAGE}" ] && break; - SERVICE=$(echo "${SERVICE_AND_IMAGE}" | cut -d ' ' -f 1) - IMAGE=$(echo "${SERVICE_AND_IMAGE}" | cut -d ' ' -f 2) + SERVICE=$(echo "${SERVICE_AND_IMAGE} " | cut -d ' ' -f 1) + IMAGE=$(echo "${SERVICE_AND_IMAGE} " | cut -d ' ' -f 2) _update_single_service "${SERVICE}" "${IMAGE}" done export LOG_SCOPE="${OLD_LOG_SCOPE}" @@ -947,16 +948,16 @@ gantry_update_services_list() { local RETURN_VALUE=0 local FAILED_NUM= FAILED_NUM=$(_get_number_of_elements_in_static_variable STATIC_VAR_SERVICES_UPDATE_FAILED) - [ "${FAILED_NUM}" -ne 0 ] && RETURN_VALUE=1 + [ "${FAILED_NUM}" != "0" ] && RETURN_VALUE=1 local ERROR_NUM= ERROR_NUM=$(_get_number_of_elements_in_static_variable STATIC_VAR_SERVICES_UPDATE_INPUT_ERROR) - [ "${ERROR_NUM}" -ne 0 ] && RETURN_VALUE=1 + [ "${ERROR_NUM}" != "0" ] && RETURN_VALUE=1 return "${RETURN_VALUE}" } gantry_finalize() { local STACK="${1:-gantry}" - local NUM_ERRORS="${2}" + local NUM_ERRORS="${2:-0}" local RETURN_VALUE=0 if ! _remove_images "${STACK}_image-remover"; then RETURN_VALUE=1 diff --git a/tests/gantry_cleanup_images_spec.sh b/tests/gantry_cleanup_images_spec.sh index a7a1a32..516aba0 100644 --- a/tests/gantry_cleanup_images_spec.sh +++ b/tests/gantry_cleanup_images_spec.sh @@ -25,8 +25,8 @@ Describe 'cleanup-images' IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_CLEANUP_IMAGES_false() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" export GANTRY_CLEANUP_IMAGES="false" run_gantry "${TEST_NAME}" @@ -65,8 +65,8 @@ Describe 'cleanup-images' IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_CLEANUP_IMAGES_OPTIONS_bad() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" export GANTRY_CLEANUP_IMAGES="true" # Image remover would fail due to the incorrect option. @@ -109,8 +109,8 @@ Describe 'cleanup-images' IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_CLEANUP_IMAGES_OPTIONS_good() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" export GANTRY_CLEANUP_IMAGES="true" export GANTRY_CLEANUP_IMAGES_OPTIONS="--container-label=test" @@ -158,9 +158,9 @@ Describe 'cleanup-images' SERVICE_NAME0="${SERVICE_NAME}-0" SERVICE_NAME1="${SERVICE_NAME}-1" test_start() { - local TEST_NAME=${1} - local IMAGE_WITH_TAG=${2} - local SERVICE_NAME=${3} + local TEST_NAME="${1}" + local IMAGE_WITH_TAG="${2}" + local SERVICE_NAME="${3}" local IMAGE_WITH_TAG0="${IMAGE_WITH_TAG}-0" local IMAGE_WITH_TAG1="${IMAGE_WITH_TAG}-1" local IMAGE_WITH_TAG2="${IMAGE_WITH_TAG}-2" @@ -178,9 +178,9 @@ Describe 'cleanup-images' # Do not creat the Image IMAGE_WITH_TAG2, to run the test on a non-exist image. } test_IMAGES_TO_REMOVE_none_empty() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} - local IMAGE_WITH_TAG=${3} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" + local IMAGE_WITH_TAG="${3}" local IMAGE_WITH_TAG0="${IMAGE_WITH_TAG}-0" local IMAGE_WITH_TAG1="${IMAGE_WITH_TAG}-1" local IMAGE_WITH_TAG2="${IMAGE_WITH_TAG}-2" @@ -189,9 +189,9 @@ Describe 'cleanup-images' run_gantry "${TEST_NAME}" } test_end() { - local TEST_NAME=${1} - local IMAGE_WITH_TAG=${2} - local SERVICE_NAME=${3} + local TEST_NAME="${1}" + local IMAGE_WITH_TAG="${2}" + local SERVICE_NAME="${3}" local IMAGE_WITH_TAG0="${IMAGE_WITH_TAG}-0" local IMAGE_WITH_TAG1="${IMAGE_WITH_TAG}-1" local SERVICE_NAME0="${SERVICE_NAME}-0" diff --git a/tests/gantry_common_options_spec.sh b/tests/gantry_common_options_spec.sh index c07f6e4..a031cb9 100644 --- a/tests/gantry_common_options_spec.sh +++ b/tests/gantry_common_options_spec.sh @@ -24,8 +24,8 @@ Describe 'common-options' IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_common_DOCKER_HOST_not_swarm_manager() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" export DOCKER_HOST="8.8.8.8:53" local RETURN_VALUE=0 @@ -70,8 +70,8 @@ Describe 'common-options' IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_common_LOG_LEVEL_none() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" # Same as test_new_image_yes, except set LOG_LEVEL to NONE export GANTRY_LOG_LEVEL=NONE @@ -93,8 +93,8 @@ Describe 'common-options' IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_common_PRE_POST_RUN_CMD() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" export GANTRY_PRE_RUN_CMD="echo \"Pre update\"" export GANTRY_POST_RUN_CMD="echo \"Post update\"" @@ -136,8 +136,8 @@ Describe 'common-options' IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_common_SLEEP_SECONDS_not_a_number() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" export GANTRY_SLEEP_SECONDS="NotANumber" run_gantry "${TEST_NAME}" diff --git a/tests/gantry_filters_spec.sh b/tests/gantry_filters_spec.sh index 18bd98e..ad426b5 100644 --- a/tests/gantry_filters_spec.sh +++ b/tests/gantry_filters_spec.sh @@ -24,8 +24,8 @@ Describe 'filters' IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_SERVICES_FILTERS_bad() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" export GANTRY_SERVICES_FILTERS="BadFilterValue" run_gantry "${TEST_NAME}" @@ -67,9 +67,9 @@ Describe 'filters' SERVICE_NAME="gantry-test-$(unique_id)" MAX_SERVICES_NUM=10 test_SERVICES_EXCLUDED_multiple_services() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} - local MAX_SERVICES_NUM=${3} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" + local MAX_SERVICES_NUM="${3}" local NUM_SERVICES_EXCLUDED=$((MAX_SERVICES_NUM/2)) local NUM_SERVICES_EXCLUDED_FILTER_START=$((NUM_SERVICES_EXCLUDED+1)) reset_gantry_env "${SERVICE_NAME}" @@ -120,8 +120,8 @@ Describe 'filters' IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_SERVICES_EXCLUDED_FILTERS_bad() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" export GANTRY_SERVICES_EXCLUDED_FILTERS="BadFilterValue" run_gantry "${TEST_NAME}" diff --git a/tests/gantry_login_spec.sh b/tests/gantry_login_spec.sh index 6e1341a..95bdd0a 100644 --- a/tests/gantry_login_spec.sh +++ b/tests/gantry_login_spec.sh @@ -27,12 +27,12 @@ Describe 'login' CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_config() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} - local CONFIG=${3} - local REGISTRY=${4} - local USERNAME=${5} - local PASSWORD=${6} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" + local CONFIG="${3}" + local REGISTRY="${4}" + local USERNAME="${5}" + local PASSWORD="${6}" if [ -z "${REGISTRY}" ] || [ -z "${USERNAME}" ] || [ -z "${PASSWORD}" ]; then echo "No REGISTRY, USERNAME or PASSWORD provided." >&2 return 1 @@ -95,12 +95,12 @@ Describe 'login' CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_REGISTRY_CONFIGS_FILE() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} - local CONFIG=${3} - local REGISTRY=${4} - local USERNAME=${5} - local PASSWORD=${6} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" + local CONFIG="${3}" + local REGISTRY="${4}" + local USERNAME="${5}" + local PASSWORD="${6}" if [ -z "${REGISTRY}" ] || [ -z "${USERNAME}" ] || [ -z "${PASSWORD}" ]; then echo "No REGISTRY, USERNAME or PASSWORD provided." >&2 return 1 @@ -165,12 +165,12 @@ Describe 'login' CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_REGISTRY_CONFIGS_FILE_bad_format() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} - local CONFIG=${3} - local REGISTRY=${4} - local USERNAME=${5} - local PASSWORD=${6} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" + local CONFIG="${3}" + local REGISTRY="${4}" + local USERNAME="${5}" + local PASSWORD="${6}" if [ -z "${REGISTRY}" ] || [ -z "${USERNAME}" ] || [ -z "${PASSWORD}" ]; then echo "No REGISTRY, USERNAME or PASSWORD provided." >&2 return 1 @@ -182,7 +182,7 @@ Describe 'login' # Add an extra item to the line. echo "${CONFIG} ${REGISTRY} ${USERNAME} ${PASSWORD} Extra" >> "${CONFIGS_FILE}" # Missing an item from the line. - echo "${REGISTRY} ${USERNAME} ${PASSWORD}" >> "${CONFIGS_FILE}" + echo "The-Only-Item-In-The-Line" >> "${CONFIGS_FILE}" reset_gantry_env "${SERVICE_NAME}" export GANTRY_REGISTRY_CONFIGS_FILE="${CONFIGS_FILE}" local RETURN_VALUE= @@ -233,12 +233,12 @@ Describe 'login' CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_file_not_exist() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} - local CONFIG=${3} - local REGISTRY=${4} - local USERNAME=${5} - local PASSWORD=${6} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" + local CONFIG="${3}" + local REGISTRY="${4}" + local USERNAME="${5}" + local PASSWORD="${6}" if [ -z "${REGISTRY}" ] || [ -z "${USERNAME}" ] || [ -z "${PASSWORD}" ]; then echo "No REGISTRY, USERNAME or PASSWORD provided." >&2 return 1 diff --git a/tests/gantry_manifest_spec.sh b/tests/gantry_manifest_spec.sh index 8dde54b..3865256 100644 --- a/tests/gantry_manifest_spec.sh +++ b/tests/gantry_manifest_spec.sh @@ -24,8 +24,8 @@ Describe 'manifest-command' IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_MANIFEST_CMD_none() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" export GANTRY_MANIFEST_CMD="none" export GANTRY_UPDATE_OPTIONS="--force" @@ -73,8 +73,8 @@ Describe 'manifest-command' SERVICE_NAME="gantry-test-$(unique_id)" test_MANIFEST_CMD_none_SERVICES_SELF() { # If the service is self, it will always run manifest checking. Even if the CMD is set to none - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" # Explicitly set GANTRY_SERVICES_SELF export GANTRY_SERVICES_SELF="${SERVICE_NAME}" @@ -116,8 +116,8 @@ Describe 'manifest-command' IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_MANIFEST_CMD_manifest() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" export GANTRY_MANIFEST_OPTIONS="--insecure" export GANTRY_MANIFEST_CMD="manifest" @@ -158,8 +158,8 @@ Describe 'manifest-command' IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_MANIFEST_CMD_unsupported_cmd() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" export GANTRY_MANIFEST_OPTIONS="--insecure" export GANTRY_MANIFEST_CMD="unsupported_cmd" @@ -204,17 +204,17 @@ Describe 'manifest-command' test_start() { # This test assumes that the IMAGE_WITH_TAG does not exist on the registry. # get_image_with_tag should return an image with a unique tag. - local TEST_NAME=${1} - local IMAGE_WITH_TAG=${2} - local SERVICE_NAME=${3} + local TEST_NAME="${1}" + local IMAGE_WITH_TAG="${2}" + local SERVICE_NAME="${3}" initialize_test "${TEST_NAME}" # No push image to the registry. Checking new image would fail. build_test_image "${IMAGE_WITH_TAG}" start_replicated_service "${SERVICE_NAME}" "${IMAGE_WITH_TAG}" 2>&1 } test_MANIFEST_CMD_failure() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" run_gantry "${TEST_NAME}" } diff --git a/tests/gantry_notify_spec.sh b/tests/gantry_notify_spec.sh index 45afe42..a6764e2 100644 --- a/tests/gantry_notify_spec.sh +++ b/tests/gantry_notify_spec.sh @@ -26,8 +26,8 @@ Describe 'notify' IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_notify_apprise() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" local RETURN_VALUE=0 local APPRISE_PORT=8000 local SMTP_PORT=1025 @@ -98,8 +98,8 @@ Describe 'notify' IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_notify_apprise_bad_url() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" export GANTRY_NOTIFICATION_APPRISE_URL="http://bad-url/notify" run_gantry "${TEST_NAME}" diff --git a/tests/gantry_parallel_spec.sh b/tests/gantry_parallel_spec.sh index 35d2b2c..c0f4336 100644 --- a/tests/gantry_parallel_spec.sh +++ b/tests/gantry_parallel_spec.sh @@ -26,11 +26,11 @@ Describe 'service-parallel' MAX_SERVICES_NUM=6 MAX_NO_NEW_IMAGE=3 test_start() { - local TEST_NAME=${1} - local IMAGE_WITH_TAG=${2} - local SERVICE_NAME=${3} - local MAX_SERVICES_NUM=${4} - local MAX_NO_NEW_IMAGE=${5} + local TEST_NAME="${1}" + local IMAGE_WITH_TAG="${2}" + local SERVICE_NAME="${3}" + local MAX_SERVICES_NUM="${4}" + local MAX_NO_NEW_IMAGE="${5}" common_setup_new_image_multiple "${TEST_NAME}" "${IMAGE_WITH_TAG}" "${SERVICE_NAME}" "${MAX_SERVICES_NUM}" local NO_NEW_IAMGE_START=$((MAX_SERVICES_NUM+1)) local NO_NEW_IAMGE_END=$((MAX_SERVICES_NUM+MAX_NO_NEW_IMAGE)) @@ -46,9 +46,9 @@ Describe 'service-parallel' wait ${PIDS} } test_parallel_less_workers() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} - local MAX_SERVICES_NUM=${3} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" + local MAX_SERVICES_NUM="${3}" reset_gantry_env "${SERVICE_NAME}" export GANTRY_UPDATE_NUM_WORKERS=$((MAX_SERVICES_NUM/2+1)) run_gantry "${TEST_NAME}" @@ -101,9 +101,9 @@ Describe 'service-parallel' SERVICE_NAME="gantry-test-$(unique_id)" MAX_SERVICES_NUM=10 test_parallel_more_workers() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} - local MAX_SERVICES_NUM=${3} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" + local MAX_SERVICES_NUM="${3}" reset_gantry_env "${SERVICE_NAME}" export GANTRY_UPDATE_NUM_WORKERS=$((MAX_SERVICES_NUM*3)) run_gantry "${TEST_NAME}" @@ -145,8 +145,8 @@ Describe 'service-parallel' IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_parallel_GANTRY_UPDATE_NUM_WORKERS_not_a_number() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" export GANTRY_UPDATE_NUM_WORKERS="NotANumber" run_gantry "${TEST_NAME}" diff --git a/tests/gantry_rollback_spec.sh b/tests/gantry_rollback_spec.sh index fe6f3b0..2b7f15d 100644 --- a/tests/gantry_rollback_spec.sh +++ b/tests/gantry_rollback_spec.sh @@ -25,9 +25,9 @@ Describe 'rollback' SERVICE_NAME="gantry-test-$(unique_id)" TIMEOUT=3 test_rollback_due_to_timeout() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} - local TIMEOUT=${3} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" + local TIMEOUT="${3}" reset_gantry_env "${SERVICE_NAME}" # Assume service update won't be done within TIMEOUT second. export GANTRY_UPDATE_TIMEOUT_SECONDS="${TIMEOUT}" @@ -68,9 +68,9 @@ Describe 'rollback' SERVICE_NAME="gantry-test-$(unique_id)" TIMEOUT=3 test_rollback_failed() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} - local TIMEOUT=${3} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" + local TIMEOUT="${3}" reset_gantry_env "${SERVICE_NAME}" # Assume service update won't be done within TIMEOUT second. export GANTRY_UPDATE_TIMEOUT_SECONDS="${TIMEOUT}" @@ -114,9 +114,9 @@ Describe 'rollback' SERVICE_NAME="gantry-test-$(unique_id)" TIMEOUT=3 test_rollback_ROLLBACK_ON_FAILURE_false() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} - local TIMEOUT=${3} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" + local TIMEOUT="${3}" reset_gantry_env "${SERVICE_NAME}" # Assume service update won't be done within TIMEOUT second. export GANTRY_UPDATE_TIMEOUT_SECONDS="${TIMEOUT}" diff --git a/tests/gantry_service_multiple_spec.sh b/tests/gantry_service_multiple_spec.sh index fab8ca5..8a087ae 100644 --- a/tests/gantry_service_multiple_spec.sh +++ b/tests/gantry_service_multiple_spec.sh @@ -30,9 +30,9 @@ Describe 'service-multiple-services' SERVICE_NAME4="${SERVICE_NAME}-4" SERVICE_NAME5="${SERVICE_NAME}-5" test_start() { - local TEST_NAME=${1} - local IMAGE_WITH_TAG=${2} - local SERVICE_NAME=${3} + local TEST_NAME="${1}" + local IMAGE_WITH_TAG="${2}" + local SERVICE_NAME="${3}" local SERVICE_NAME0="${SERVICE_NAME}-0" local SERVICE_NAME1="${SERVICE_NAME}-1" local SERVICE_NAME2="${SERVICE_NAME}-2" @@ -51,8 +51,8 @@ Describe 'service-multiple-services' start_replicated_service "${SERVICE_NAME5}" "${IMAGE_WITH_TAG}" } test_multiple_services_excluded_filters() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" local SERVICE_NAME1="${SERVICE_NAME}-1" local SERVICE_NAME2="${SERVICE_NAME}-2" reset_gantry_env "${SERVICE_NAME}" @@ -62,9 +62,9 @@ Describe 'service-multiple-services' run_gantry "${TEST_NAME}" } test_end() { - local TEST_NAME=${1} - local IMAGE_WITH_TAG=${2} - local SERVICE_NAME=${3} + local TEST_NAME="${1}" + local IMAGE_WITH_TAG="${2}" + local SERVICE_NAME="${3}" local SERVICE_NAME0="${SERVICE_NAME}-0" local SERVICE_NAME1="${SERVICE_NAME}-1" local SERVICE_NAME2="${SERVICE_NAME}-2" diff --git a/tests/gantry_service_no_running_tasks_spec.sh b/tests/gantry_service_no_running_tasks_spec.sh index 3fb9ad9..2f8144e 100644 --- a/tests/gantry_service_no_running_tasks_spec.sh +++ b/tests/gantry_service_no_running_tasks_spec.sh @@ -40,8 +40,8 @@ Describe "service-no-running-tasks" build_and_push_test_image "${IMAGE_WITH_TAG}" } test_no_running_tasks_replicated() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" local SERVICE_NAME_SUFFIX="${SERVICE_NAME}-suffix" # Set running tasks to 0 for SERVICE_NAME. # But keep tasks running for SERVICE_NAME_SUFFIX. @@ -102,9 +102,9 @@ Describe "service-no-running-tasks" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_start() { - local TEST_NAME=${1} - local IMAGE_WITH_TAG=${2} - local SERVICE_NAME=${3} + local TEST_NAME="${1}" + local IMAGE_WITH_TAG="${2}" + local SERVICE_NAME="${3}" local TASK_SECONDS=15 initialize_test "${TEST_NAME}" # The task will finish in ${TASK_SECONDS} seconds @@ -115,8 +115,8 @@ Describe "service-no-running-tasks" wait_zero_running_tasks "${SERVICE_NAME}" } test_no_running_tasks_global() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" run_gantry "${TEST_NAME}" } diff --git a/tests/gantry_service_single_spec.sh b/tests/gantry_service_single_spec.sh index c9672f6..1bc2e29 100644 --- a/tests/gantry_service_single_spec.sh +++ b/tests/gantry_service_single_spec.sh @@ -24,8 +24,8 @@ Describe 'service-single-service' IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_new_image_no() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" run_gantry "${TEST_NAME}" } @@ -63,8 +63,8 @@ Describe 'service-single-service' IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_new_image_yes() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" run_gantry "${TEST_NAME}" } @@ -102,9 +102,9 @@ Describe 'service-single-service' IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_start() { - local TEST_NAME=${1} - local IMAGE_WITH_TAG=${2} - local SERVICE_NAME=${3} + local TEST_NAME="${1}" + local IMAGE_WITH_TAG="${2}" + local SERVICE_NAME="${3}" # Start a service with image not available on the registry, the digest will not be available. build_test_image "${IMAGE_WITH_TAG}" start_replicated_service "${SERVICE_NAME}" "${IMAGE_WITH_TAG}" 2>&1 @@ -112,8 +112,8 @@ Describe 'service-single-service' build_and_push_test_image "${IMAGE_WITH_TAG}" } test_new_image_no_digest() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" run_gantry "${TEST_NAME}" } diff --git a/tests/gantry_update_options_spec.sh b/tests/gantry_update_options_spec.sh index 05f3689..7a82a2c 100644 --- a/tests/gantry_update_options_spec.sh +++ b/tests/gantry_update_options_spec.sh @@ -37,8 +37,8 @@ Describe 'update-options' start_replicated_service "${SERVICE_NAME}" "${IMAGE_WITH_TAG}" } test_update_jobs_skipping() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" run_gantry "${TEST_NAME}" } @@ -87,8 +87,8 @@ Describe 'update-options' IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_update_jobs_UPDATE_JOBS_true() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" export GANTRY_UPDATE_JOBS="true" # The job may not reach the desired "Complete" state and blocking update CLI. So add "--detach=true" @@ -132,8 +132,8 @@ Describe 'update-options' SERVICE_NAME="gantry-test-$(unique_id)" TASK_SECONDS=15 test_update_jobs_no_running_tasks() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" # The tasks should exit after TASK_SECONDS seconds sleep. Then it will have 0 running tasks. wait_zero_running_tasks "${SERVICE_NAME}" reset_gantry_env "${SERVICE_NAME}" @@ -183,8 +183,8 @@ Describe 'update-options' docker service inspect -f "{{index .Spec.Labels \"${LABEL}\"}}" "${SERVICE_NAME}" } test_update_UPDATE_OPTIONS() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" local LABEL="gantry.test" local LABEL_VALUE= LABEL_VALUE=$(_read_service_label "${SERVICE_NAME}" "${LABEL}") @@ -236,8 +236,8 @@ Describe 'update-options' IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" test_update_UPDATE_TIMEOUT_SECONDS_not_a_number() { - local TEST_NAME=${1} - local SERVICE_NAME=${2} + local TEST_NAME="${1}" + local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" export GANTRY_UPDATE_TIMEOUT_SECONDS="NotANumber" run_gantry "${TEST_NAME}" diff --git a/tests/spec_gantry_test_helper.sh b/tests/spec_gantry_test_helper.sh index e5ecb87..6eb2709 100644 --- a/tests/spec_gantry_test_helper.sh +++ b/tests/spec_gantry_test_helper.sh @@ -487,7 +487,7 @@ wait_zero_running_tasks() { # https://docs.docker.com/engine/reference/commandline/service_ls/#examples # The REPLICAS is like "5/5" or "1/1 (3/5 completed)" # Get the number before the first "/". - NUM_RUNS=$(echo "${REPLICAS}" | cut -d '/' -f 1) + NUM_RUNS=$(echo "${REPLICAS}/" | cut -d '/' -f 1) sleep 1 USED_SECONDS=$((USED_SECONDS+1)) done