diff --git a/src/lib-common.sh b/src/lib-common.sh index d3b3753..e89ef56 100755 --- a/src/lib-common.sh +++ b/src/lib-common.sh @@ -15,6 +15,10 @@ # along with this program. If not, see . # +_random_string() { + head /dev/urandom | LANG=C tr -dc 'a-zA-Z0-9' | head -c 8 +} + # Run "grep -q" and avoid broken pipe errors. grep_q() { # "grep -q" will exit immediately when the first line of data matches, and leading to broken pipe errors. @@ -191,6 +195,13 @@ _log_docker_line() { _log_formatter "${LEVEL}" "${TIME}" "${NODE}" "${SCOPE}" "${MESSAGE}"; } +_log_docker_multiple_lines() { + local LINE= + while read -r LINE; do + _log_docker_line "${LINE}" + done +} + # Usage: echo "${LOGS}" | log_lines INFO log_lines() { local LEVEL="${1}"; @@ -296,6 +307,27 @@ attach_tag_to_log_scope() { echo "${OLD_LOG_SCOPE}${SEP}${TAG}" } +_eval_cmd_core() { + local STDOUT_CMD="${1}"; shift; + local CMD="${*}" + local RANDOM_STR= + RANDOM_STR=$(_random_string) + local TIMESTAMP= + TIMESTAMP=$(date +%s) + local PIPE_NAME="/tmp/eval-cmd-stdout-pipe-$$-${TIMESTAMP}-${RANDOM_STR}" + mkfifo "${PIPE_NAME}" + local PID= + eval "${STDOUT_CMD}" < "${PIPE_NAME}" & + PID="${!}" + local RETURN_VALUE= + # No redirect for stderr, unless it is done by the CMD. + eval "${CMD}" > "${PIPE_NAME}" + RETURN_VALUE=$? + wait "${PID}" + rm "${PIPE_NAME}" + return "${RETURN_VALUE}" +} + eval_cmd() { local TAG="${1}"; shift; local CMD="${*}" @@ -304,21 +336,17 @@ eval_cmd() { LOG_SCOPE=$(attach_tag_to_log_scope "${TAG}") export LOG_SCOPE log INFO "Run ${TAG} command: ${CMD}" - local EVAL_OUTPUT= - local EVAL_RETURN= - EVAL_OUTPUT=$(mktemp) - eval "${CMD}" > "${EVAL_OUTPUT}" - EVAL_RETURN=$? - if [ "${EVAL_RETURN}" = "0" ]; then - log_lines INFO < "${EVAL_OUTPUT}" + local LOG_CMD="log_lines INFO" + local RETURN_VALUE=0 + _eval_cmd_core "${LOG_CMD}" "${CMD}" + RETURN_VALUE=$? + if [ "${RETURN_VALUE}" = "0" ]; then + log INFO "Finish ${TAG} command." else - log_lines WARN < "${EVAL_OUTPUT}" - log WARN "${TAG} command returned a non-zero value ${EVAL_RETURN}." + log ERROR "Finish ${TAG} command with a non-zero return value ${RETURN_VALUE}." fi - rm "${EVAL_OUTPUT}" - log INFO "Finish ${TAG} command." export LOG_SCOPE="${OLD_LOG_SCOPE}" - return "${EVAL_RETURN}" + return "${RETURN_VALUE}" } swarm_network_arguments() { @@ -349,34 +377,50 @@ _get_docker_command_name_arg() { } _get_docker_command_detach() { - if echo "${@}" | grep_q "--detach"; then + if echo "${@}" | grep_q "--detach=false"; then + echo "false" + elif echo "${@}" | grep_q "--detach"; then + # assume we find --detach or --detach=true. echo "true" - return 0 + else + echo "false" fi - echo "false" + return 0 } -docker_service_logs () { +docker_service_logs() { local SERVICE_NAME="${1}" + local LOG_CMD="_log_docker_multiple_lines" + local CMD="docker service logs --timestamps --no-task-ids ${SERVICE_NAME} 2>&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}." - RETURN_VALUE=1 - fi - echo "${LOGS}" | - while read -r LINE; do - _log_docker_line "${LINE}" - done + _eval_cmd_core "${LOG_CMD}" "${CMD}" + RETURN_VALUE=$? + [ "${RETURN_VALUE}" != 0 ] && log ERROR "Failed to obtain logs of service ${SERVICE_NAME}. Return code ${RETURN_VALUE}." return "${RETURN_VALUE}" } -docker_service_logs_follow() { +_docker_service_exists() { local SERVICE_NAME="${1}" - docker service logs --timestamps --no-task-ids --follow "${SERVICE_NAME}" 2>&1 | - while read -r LINE; do - _log_docker_line "${LINE}" + docker service inspect --format '{{.ID}}' "${SERVICE_NAME}" >/dev/null 2>&1 +} + +# "docker service logs --follow" does not stop when the service stops. +# This function will check the status of the service and stop the "docker service logs" command. +_docker_service_logs_follow_and_stop() { + local SERVICE_NAME="${1}" + ! _docker_service_exists "${SERVICE_NAME}" && return 1; + local PID= + docker service logs --timestamps --no-task-ids --follow "${SERVICE_NAME}" 2>&1 & + PID="${!}" + while _docker_service_exists "${SERVICE_NAME}"; do + sleep 1s done + kill "${PID}" 2>&1 +} + +docker_service_logs_follow() { + local SERVICE_NAME="${1}" + _docker_service_logs_follow_and_stop "${SERVICE_NAME}" | _log_docker_multiple_lines } _docker_service_task_states() { @@ -388,6 +432,7 @@ _docker_service_task_states() { return 1 fi local NAME_LIST= + local LINE= echo "${STATES}" | while read -r LINE; do local NAME= local NODE_STATE_AND_ERROR= @@ -401,71 +446,144 @@ _docker_service_task_states() { done } -# Usage: wait_service_state [--running] [--complete] -# Wait for the service, usually a global job or a replicated job, to reach either running or complete state. -# The function returns immediately when any of the tasks of the service fails. +# Echo the return value from the tasks. +# Return 0: All tasks reach the want state, or there is an error. +# Return 1: Keep waiting. +_all_tasks_reach_state() { + local WANT_STATE="${1}" + local CHECK_FAILURES="${2}" + local STATES="${3}" + local NUM_LINES=0 + local NUM_STATES=0 + local NUM_FAILS=0 + local LINE= + while read -r LINE; do + [ -z "${LINE}" ] && continue; + NUM_LINES=$((NUM_LINES+1)); + echo "${LINE}" | grep_q "${WANT_STATE}" && NUM_STATES=$((NUM_STATES+1)); + "${CHECK_FAILURES}" && echo "${LINE}" | grep_q "Failed" && NUM_FAILS=$((NUM_FAILS+1)); + done < <(echo "${STATES}") + if [ "${NUM_LINES}" -le 0 ]; then + # continue + return 1 + fi + if [ "${NUM_STATES}" = "${NUM_LINES}" ]; then + # break + echo "0" + return 0 + fi + if [ "${NUM_FAILS}" = 0 ]; then + # continue + return 1 + fi + # 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= + RETURN_VALUE=$(extract_string "${TASK_RETURN_VALUE:-1}" ' ' 1) + # break + echo "${RETURN_VALUE}" + return 0 +} + +# Usage: wait_service_state +# Wait for the service, usually a global job or a replicated job, +# to reach either running or complete state. +# Valid WANT_STATE includes "Running" and "Complete" +# When the WANT_STATE is complete, the function returns immediately +# when any of the tasks of the service fails. # In case of task failing, the function returns a non-zero value. wait_service_state() { - local SERVICE_NAME="${1}"; shift; - 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 SERVICE_NAME="${1}"; + local WANT_STATE="${2}"; + local CHECK_FAILURES=false + [ "${WANT_STATE}" = "Complete" ] && CHECK_FAILURES=true local SLEEP_SECONDS=1 + local DOCKER_CMD_ERROR=1 + local RETURN_VALUE=0 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 - local LINE= - while read -r LINE; do - [ -z "${LINE}" ] && continue; - 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)); - echo "${LINE}" | grep_q "Failed" && NUM_FAILS=$((NUM_FAILS+1)); - done < <(echo "${STATES}") - if [ "${NUM_LINES}" -gt 0 ]; then - if "${WAIT_RUNNING}" && [ "${NUM_RUNS}" -eq "${NUM_LINES}" ]; then - RETURN_VALUE=0 - DOCKER_CMD_ERROR=0 - break - fi - if "${WAIT_COMPLETE}" && [ "${NUM_DONES}" -eq "${NUM_LINES}" ]; then - 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. - RETURN_VALUE=$(extract_string "${TASK_RETURN_VALUE:-1}" ' ' 1) - DOCKER_CMD_ERROR=0 - break - fi - fi + DOCKER_CMD_ERROR=0 + RETURN_VALUE=$(_all_tasks_reach_state "${WANT_STATE}" "${CHECK_FAILURES}" "${STATES}") && break sleep "${SLEEP_SECONDS}" + DOCKER_CMD_ERROR=1 done if [ "${DOCKER_CMD_ERROR}" != "0" ]; then log ERROR "Failed to obtain task states of service ${SERVICE_NAME}: ${STATES}" return 1 fi local LINE= - while read -r LINE; do + echo "${STATES}" | while read -r LINE; do log INFO "Service ${SERVICE_NAME}: ${LINE}." - done < <(echo "${STATES}") + done return "${RETURN_VALUE}" } +docker_service_remove() { + local SERVICE_NAME="${1}" + local POST_COMMAND="${2}" + ! _docker_service_exists "${SERVICE_NAME}" && return 0 + log INFO "Removing service ${SERVICE_NAME}." + local LOG= + if ! LOG=$(docker service rm "${SERVICE_NAME}" 2>&1); then + log ERROR "Failed to remove docker service ${SERVICE_NAME}: ${LOG}" + return 1 + fi + if [ -n "${POST_COMMAND}" ]; then + eval "${POST_COMMAND}" + fi + log INFO "Removed service ${SERVICE_NAME}." + return 0 +} + +# Works with the service started (e.g. via docker_global_job) with --detach. +docker_service_follow_logs_wait_complete() { + local SERVICE_NAME="${1}" + local PID= + docker_service_logs_follow "${SERVICE_NAME}" & + PID="${!}" + wait_service_state "${SERVICE_NAME}" "Complete" + docker_service_remove "${SERVICE_NAME}" "wait ${PID}" +} + +# We do not expect failures when using docker_global_job. +# Docker will try to restart the failed tasks. +# We do not check the converge of the service, thus some jobs may failed on some nodes. +# It is better to be used togther with wait_service_state. +docker_global_job() { + local SERVICE_NAME= + SERVICE_NAME=$(_get_docker_command_name_arg "${@}") + log INFO "Starting global-job ${SERVICE_NAME}." + local LOG= + if ! LOG=$(docker service create --mode global-job "${@}" 2>&1); then + log ERROR "Failed to create global-job ${SERVICE_NAME}: ${LOG}" + return 1 + fi + return 0 +} + +# A job could fail when using docker_replicated_job. +docker_replicated_job() { + local SERVICE_NAME= + local IS_DETACH= + SERVICE_NAME=$(_get_docker_command_name_arg "${@}") + IS_DETACH=$(_get_docker_command_detach "${@}") + # Add "--detach" to work around https://github.com/docker/cli/issues/2979 + # The Docker CLI does not exit on failures. + log INFO "Starting replicated-job ${SERVICE_NAME}." + local LOG= + if ! LOG=$(docker service create --mode replicated-job --detach "${@}" 2>&1); then + log ERROR "Failed to create replicated-job ${SERVICE_NAME}: ${LOG}" + return 1 + fi + # If the command line does not contain '--detach', the function returns til the replicated job is complete. + if ! "${IS_DETACH}"; then + wait_service_state "${SERVICE_NAME}" "Complete" || return $? + fi + return 0 +} + docker_version() { local cver capi sver sapi if ! cver=$(docker version --format '{{.Client.Version}}' 2>&1); then log ERROR "${cver}"; cver="error"; fi @@ -517,58 +635,6 @@ docker_current_container_name() { done } -docker_service_remove() { - local SERVICE_NAME="${1}" - if ! docker service inspect --format '{{.JobStatus}}' "${SERVICE_NAME}" >/dev/null 2>&1; then - return 0 - fi - log INFO "Removing service ${SERVICE_NAME}." - local LOG= - if ! LOG=$(docker service rm "${SERVICE_NAME}" 2>&1); then - log ERROR "Failed to remove docker service ${SERVICE_NAME}: ${LOG}" - return 1 - fi - log INFO "Removed service ${SERVICE_NAME}." - return 0 -} - -# We do not expect failures when using docker_global_job. -# Docker will try to restart the failed tasks. -# We do not check the converge of the service, thus some jobs may failed on some nodes. -# It is better to be used togther with wait_service_state. -docker_global_job() { - local SERVICE_NAME= - SERVICE_NAME=$(_get_docker_command_name_arg "${@}") - log INFO "Starting global-job ${SERVICE_NAME}." - local LOG= - if ! LOG=$(docker service create --mode global-job "${@}" 2>&1); then - log ERROR "Failed to create global-job ${SERVICE_NAME}: ${LOG}" - return 1 - fi - return 0 -} - -# A job could fail when using docker_replicated_job. -docker_replicated_job() { - local SERVICE_NAME= - local IS_DETACH= - SERVICE_NAME=$(_get_docker_command_name_arg "${@}") - IS_DETACH=$(_get_docker_command_detach "${@}") - # Add "--detach" to work around https://github.com/docker/cli/issues/2979 - # The Docker CLI does not exit on failures. - log INFO "Starting replicated-job ${SERVICE_NAME}." - local LOG= - if ! LOG=$(docker service create --mode replicated-job --detach "${@}" 2>&1); then - log ERROR "Failed to create replicated-job ${SERVICE_NAME}: ${LOG}" - return 1 - fi - # If the command line does not contain '--detach', the function returns til the replicated job is complete. - if ! "${IS_DETACH}"; then - wait_service_state "${SERVICE_NAME}" --complete || return $? - fi - return 0 -} - _container_status() { local CNAME="${1}" docker container inspect --format '{{.State.Status}}' "${CNAME}" 2>/dev/null diff --git a/src/lib-gantry.sh b/src/lib-gantry.sh index cd7cf60..c80117f 100755 --- a/src/lib-gantry.sh +++ b/src/lib-gantry.sh @@ -449,15 +449,14 @@ _remove_images() { # SC2086: Double quote to prevent globbing and word splitting. # shellcheck disable=SC2086 docker_global_job --name "${SERVICE_NAME}" \ + --detach=true \ --restart-condition on-failure \ --restart-max-attempts 1 \ --mount type=bind,source=/var/run/docker.sock,destination=/var/run/docker.sock \ --env "GANTRY_IMAGES_TO_REMOVE=${IMAGES_TO_REMOVE_LIST}" \ ${CLEANUP_IMAGES_OPTIONS} \ "${IMAGES_REMOVER}"; - wait_service_state "${SERVICE_NAME}" - docker_service_logs "${SERVICE_NAME}" - docker_service_remove "${SERVICE_NAME}" + docker_service_follow_logs_wait_complete "${SERVICE_NAME}" } _report_list() { diff --git a/tests/gantry_cleanup_images_spec.sh b/tests/gantry_cleanup_images_spec.sh index 245b854..3189ed0 100644 --- a/tests/gantry_cleanup_images_spec.sh +++ b/tests/gantry_cleanup_images_spec.sh @@ -60,6 +60,7 @@ Describe 'cleanup-images' The stderr should satisfy spec_expect_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_CLEANUP_IMAGES_OPTIONS_bad" "container_test:true" "coverage:true" @@ -106,6 +107,7 @@ Describe 'cleanup-images' The stderr should satisfy spec_expect_message "Failed.*--incorrect-option" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_CLEANUP_IMAGES_OPTIONS_good" "container_test:true" "coverage:true" @@ -151,6 +153,7 @@ Describe 'cleanup-images' The stderr should satisfy spec_expect_no_message "Failed.*--container-label=test" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End Describe "test_IMAGES_TO_REMOVE_none_empty" "container_test:true" "coverage:true" @@ -221,6 +224,7 @@ Describe 'cleanup-images' The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG0}" The stderr should satisfy spec_expect_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG1}" The stderr should satisfy spec_expect_message "There is no image.*${IMAGE_WITH_TAG2}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End End # Describe 'Single service' diff --git a/tests/gantry_common_options_spec.sh b/tests/gantry_common_options_spec.sh index b6d0985..f659d7d 100644 --- a/tests/gantry_common_options_spec.sh +++ b/tests/gantry_common_options_spec.sh @@ -64,6 +64,7 @@ Describe 'common-options' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${SCHEDULE_NEXT_UPDATE_AT}" The stderr should satisfy spec_expect_no_message "${SLEEP_SECONDS_BEFORE_NEXT_UPDATE}" End @@ -146,8 +147,10 @@ Describe 'common-options' export GANTRY_CLEANUP_IMAGES= # Test that pre-run command can change the global configurations. export GANTRY_PRE_RUN_CMD="echo \"Pre update\"; GANTRY_UPDATE_OPTIONS=--detach=true; GANTRY_CLEANUP_IMAGES=false;" + # This command outputs multiple lines. + local POST_CMD="for I in \$(seq 3 5); do echo \"OUTPUT_LINE=\$I\"; done" # Test that the command returns a non-zero value. - export GANTRY_POST_RUN_CMD="echo \"Post update\"; false;" + export GANTRY_POST_RUN_CMD="echo \"Post update\"; ${POST_CMD}; false;" run_gantry "${TEST_NAME}" } BeforeEach "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" @@ -160,7 +163,7 @@ Describe 'common-options' The stderr should satisfy display_output The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" The stderr should satisfy spec_expect_message "Pre update" - The stderr should satisfy spec_expect_no_message "pre-run command returned a non-zero value" + The stderr should satisfy spec_expect_message "Finish pre-run command." The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_message "${PERFORM_UPDATING}.*${SERVICE_NAME}.*${PERFORM_REASON_HAS_NEWER_IMAGE}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" @@ -182,8 +185,12 @@ Describe 'common-options' The stderr should satisfy spec_expect_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "Post update" - The stderr should satisfy spec_expect_message "post-run command returned a non-zero value" + The stderr should satisfy spec_expect_message "OUTPUT_LINE=3" + The stderr should satisfy spec_expect_message "OUTPUT_LINE=4" + The stderr should satisfy spec_expect_message "OUTPUT_LINE=5" + The stderr should satisfy spec_expect_message "Finish post-run command with a non-zero return value 1." The stderr should satisfy spec_expect_no_message "${SCHEDULE_NEXT_UPDATE_AT}" The stderr should satisfy spec_expect_no_message "${SLEEP_SECONDS_BEFORE_NEXT_UPDATE}" End @@ -236,6 +243,7 @@ Describe 'common-options' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" # Check messages between iterations. The stderr should satisfy spec_expect_message "${SCHEDULE_NEXT_UPDATE_AT}" The stderr should satisfy spec_expect_message "${SLEEP_SECONDS_BEFORE_NEXT_UPDATE}" @@ -283,6 +291,7 @@ Describe 'common-options' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${SCHEDULE_NEXT_UPDATE_AT}" The stderr should satisfy spec_expect_no_message "${SLEEP_SECONDS_BEFORE_NEXT_UPDATE}" End diff --git a/tests/gantry_filters_spec.sh b/tests/gantry_filters_spec.sh index 98be545..d14ebcb 100644 --- a/tests/gantry_filters_spec.sh +++ b/tests/gantry_filters_spec.sh @@ -61,6 +61,7 @@ Describe 'filters' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_SERVICES_EXCLUDED_multiple_services" "container_test:true" "coverage:true" @@ -118,6 +119,7 @@ Describe 'filters' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_SERVICES_EXCLUDED_FILTERS_default" "container_test:true" "coverage:true" @@ -168,6 +170,7 @@ Describe 'filters' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_SERVICES_EXCLUDED_FILTERS_bad" "container_test:false" "coverage:true" @@ -212,6 +215,7 @@ Describe 'filters' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End End # Describe 'Filters' \ No newline at end of file diff --git a/tests/gantry_jobs_spec.sh b/tests/gantry_jobs_spec.sh index 6bd7171..0bd26ae 100644 --- a/tests/gantry_jobs_spec.sh +++ b/tests/gantry_jobs_spec.sh @@ -19,12 +19,12 @@ Describe 'update-jobs' SUITE_NAME="update-jobs" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_update_jobs_skipping" "container_test:true" "coverage:true" + Describe "test_jobs_skipping" "container_test:true" "coverage:true" # For `docker service ls --filter`, the name filter matches on all or the prefix of a service's name # See https://docs.docker.com/engine/reference/commandline/service_ls/#name # It does not do the exact match of the name. See https://github.com/moby/moby/issues/32985 # This test also checks whether we do an extra step to to perform the exact match. - TEST_NAME="test_update_jobs_skipping" + TEST_NAME="test_jobs_skipping" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") SERVICE_NAME_SUFFIX="${SERVICE_NAME}-suffix" @@ -36,7 +36,7 @@ Describe 'update-jobs' common_setup_job "${TEST_NAME}" "${IMAGE_WITH_TAG}" "${SERVICE_NAME_SUFFIX}" start_replicated_service "${SERVICE_NAME}" "${IMAGE_WITH_TAG}" } - test_update_jobs_skipping() { + test_jobs_skipping() { local TEST_NAME="${1}" local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" @@ -53,7 +53,7 @@ Describe 'update-jobs' BeforeEach "test_start ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" AfterEach "test_end ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" It 'run_test' - When run test_update_jobs_skipping "${TEST_NAME}" "${SERVICE_NAME}" + When run test_jobs_skipping "${TEST_NAME}" "${SERVICE_NAME}" The status should be success The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" @@ -83,16 +83,17 @@ Describe 'update-jobs' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_update_jobs_UPDATE_JOBS_true" "container_test:true" "coverage:true" - TEST_NAME="test_update_jobs_UPDATE_JOBS_true" + Describe "test_jobs_UPDATE_JOBS_true" "container_test:true" "coverage:true" + TEST_NAME="test_jobs_UPDATE_JOBS_true" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") TASK_SECONDS=-1 # Use a long EXIT_SECONDS, because we want the task keep running for a while after updating to trigger the image removing failure. EXIT_SECONDS=30 - test_update_jobs_UPDATE_JOBS_true() { + test_jobs_UPDATE_JOBS_true() { local TEST_NAME="${1}" local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" @@ -104,7 +105,7 @@ Describe 'update-jobs' BeforeEach "common_setup_job ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME} ${TASK_SECONDS} ${EXIT_SECONDS}" AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" It 'run_test' - When run test_update_jobs_UPDATE_JOBS_true "${TEST_NAME}" "${SERVICE_NAME}" + When run test_jobs_UPDATE_JOBS_true "${TEST_NAME}" "${SERVICE_NAME}" The status should be success The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" @@ -133,16 +134,17 @@ Describe 'update-jobs' # Since the job may not reach the desired state, they are still using the image. Image remover will fail. The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_update_jobs_label_UPDATE_JOBS_true" "container_test:true" "coverage:true" - TEST_NAME="test_update_jobs_label_UPDATE_JOBS_true" + Describe "test_jobs_label_UPDATE_JOBS_true" "container_test:true" "coverage:true" + TEST_NAME="test_jobs_label_UPDATE_JOBS_true" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") TASK_SECONDS=-1 # Use a long EXIT_SECONDS, because we want the task keep running for a while after updating to trigger the image removing failure. EXIT_SECONDS=30 - test_update_jobs_label_UPDATE_JOBS_true() { + test_jobs_label_UPDATE_JOBS_true() { local TEST_NAME="${1}" local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" @@ -160,7 +162,7 @@ Describe 'update-jobs' BeforeEach "common_setup_job ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME} ${TASK_SECONDS} ${EXIT_SECONDS}" AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" It 'run_test' - When run test_update_jobs_label_UPDATE_JOBS_true "${TEST_NAME}" "${SERVICE_NAME}" + When run test_jobs_label_UPDATE_JOBS_true "${TEST_NAME}" "${SERVICE_NAME}" The status should be success The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" @@ -189,10 +191,11 @@ Describe 'update-jobs' # Since the job may not reach the desired state, they are still using the image. Image remover will fail. The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_update_jobs_no_running_tasks" "container_test:true" "coverage:true" - TEST_NAME="test_update_jobs_no_running_tasks" + Describe "test_jobs_no_running_tasks" "container_test:true" "coverage:true" + TEST_NAME="test_jobs_no_running_tasks" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") # Use a short TASK_SECONDS, because we want the task finishes soon. @@ -206,7 +209,7 @@ Describe 'update-jobs' # The tasks should exit after TASK_SECONDS seconds sleep. Then it will have 0 running tasks. wait_zero_running_tasks "${SERVICE_NAME}" } - test_update_jobs_no_running_tasks() { + test_jobs_no_running_tasks() { local TEST_NAME="${1}" local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" @@ -217,7 +220,7 @@ Describe 'update-jobs' BeforeEach "test_start ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME} ${TASK_SECONDS}" AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" It 'run_test' - When run test_update_jobs_no_running_tasks "${TEST_NAME}" "${SERVICE_NAME}" + When run test_jobs_no_running_tasks "${TEST_NAME}" "${SERVICE_NAME}" The status should be success The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" @@ -247,6 +250,7 @@ Describe 'update-jobs' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End End # Describe 'update-jobs' diff --git a/tests/gantry_login_docker_config_spec.sh b/tests/gantry_login_docker_config_spec.sh index 6afa5cb..d8a14db 100644 --- a/tests/gantry_login_docker_config_spec.sh +++ b/tests/gantry_login_docker_config_spec.sh @@ -103,6 +103,7 @@ Describe 'login_docker_config' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End Describe "test_login_docker_config_default_config" "container_test:true" "coverage:true" @@ -173,6 +174,7 @@ Describe 'login_docker_config' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End Describe "test_login_docker_config_label_override" "container_test:false" "coverage:true" @@ -291,6 +293,7 @@ Describe 'login_docker_config' The stderr should satisfy spec_expect_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End End # Describe 'login_docker_config' diff --git a/tests/gantry_login_negative_spec.sh b/tests/gantry_login_negative_spec.sh index a54e61a..6db85d2 100644 --- a/tests/gantry_login_negative_spec.sh +++ b/tests/gantry_login_negative_spec.sh @@ -67,6 +67,7 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_login_incorrect_password" "container_test:false" "coverage:true" @@ -135,6 +136,7 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_login_read_only_file" "container_test:false" "coverage:true" @@ -205,6 +207,7 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_login_config_mismatch_default" "container_test:false" "coverage:true" @@ -289,6 +292,7 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_login_config_mismatch_no_default" "container_test:false" "coverage:true" @@ -367,6 +371,7 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_login_multi_services_no_label" "container_test:false" "coverage:true" @@ -481,6 +486,7 @@ Describe 'login_negative' The stderr should satisfy spec_expect_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_login_REGISTRY_CONFIGS_FILE_bad_format" "container_test:false" "coverage:true" @@ -550,6 +556,7 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_login_file_not_exist" "container_test:false" "coverage:true" @@ -615,6 +622,7 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End End # Describe 'login_negative' diff --git a/tests/gantry_login_spec.sh b/tests/gantry_login_spec.sh index 1b5c0b4..4c26906 100644 --- a/tests/gantry_login_spec.sh +++ b/tests/gantry_login_spec.sh @@ -93,6 +93,7 @@ Describe 'login' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End Describe "test_login_default_config" "container_test:true" "coverage:true" @@ -162,6 +163,7 @@ Describe 'login' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End Describe "test_login_REGISTRY_CONFIGS_FILE" "container_test:true" "coverage:true" @@ -236,6 +238,7 @@ Describe 'login' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End Describe "test_login_external_config" "container_test:true" "coverage:true" @@ -307,6 +310,7 @@ Describe 'login' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End End # Describe 'Login' diff --git a/tests/gantry_manifest_spec.sh b/tests/gantry_manifest_spec.sh index 493b21e..d79ca32 100644 --- a/tests/gantry_manifest_spec.sh +++ b/tests/gantry_manifest_spec.sh @@ -67,6 +67,7 @@ Describe 'manifest-command' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_MANIFEST_CMD_none_SERVICES_SELF" "container_test:true" "coverage:true" @@ -114,6 +115,7 @@ Describe 'manifest-command' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_MANIFEST_CMD_manifest" "container_test:true" "coverage:true" @@ -158,6 +160,7 @@ Describe 'manifest-command' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End Describe "test_MANIFEST_CMD_label" "container_test:true" "coverage:true" @@ -207,6 +210,7 @@ Describe 'manifest-command' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End Describe "test_MANIFEST_CMD_unsupported_cmd" "container_test:false" "coverage:true" @@ -253,6 +257,7 @@ Describe 'manifest-command' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_MANIFEST_CMD_failure" "container_test:false" "coverage:true" @@ -307,6 +312,7 @@ Describe 'manifest-command' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End End # Describe 'Manifest command' diff --git a/tests/gantry_notify_spec.sh b/tests/gantry_notify_spec.sh index d20ad15..02dacdd 100644 --- a/tests/gantry_notify_spec.sh +++ b/tests/gantry_notify_spec.sh @@ -115,6 +115,7 @@ Describe 'notify' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${SKIP_NOTIFY_APPRISE}" The stderr should satisfy spec_expect_message "${SEND_NOTIFY_APPRISE}" End @@ -166,6 +167,7 @@ Describe 'notify' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${SKIP_NOTIFY_APPRISE}" The stderr should satisfy spec_expect_message "${SEND_NOTIFY_APPRISE}" End @@ -210,6 +212,7 @@ Describe 'notify' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${SKIP_NOTIFY_APPRISE}" The stderr should satisfy spec_expect_message "Failed to send notification via Apprise" End @@ -261,6 +264,7 @@ Describe 'notify' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${SKIP_NOTIFY_APPRISE}" The stderr should satisfy spec_expect_message "${SEND_NOTIFY_APPRISE}" End @@ -311,6 +315,7 @@ Describe 'notify' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${NO_UPDATES_OR_ERRORS_FOR_NOTIFICATION}" The stderr should satisfy spec_expect_message "${SKIP_SENDING_NOTIFICATION}" End @@ -362,6 +367,7 @@ Describe 'notify' The stderr should satisfy spec_expect_no_message "${REMOVING_NUM_IMAGES}" The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${SKIP_NOTIFY_APPRISE}" The stderr should satisfy spec_expect_message "${SEND_NOTIFY_APPRISE}" End diff --git a/tests/gantry_parallel_spec.sh b/tests/gantry_parallel_spec.sh index 4d4e467..b1f77ab 100644 --- a/tests/gantry_parallel_spec.sh +++ b/tests/gantry_parallel_spec.sh @@ -82,6 +82,7 @@ Describe 'service-parallel' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End Describe "test_parallel_more_workers" "container_test:true" "coverage:true" @@ -128,6 +129,7 @@ Describe 'service-parallel' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End Describe "test_parallel_GANTRY_MANIFEST_NUM_WORKERS_not_a_number" "container_test:false" "coverage:true" @@ -171,6 +173,7 @@ Describe 'service-parallel' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_parallel_GANTRY_UPDATE_NUM_WORKERS_not_a_number" "container_test:false" "coverage:true" @@ -214,6 +217,7 @@ Describe 'service-parallel' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End End # Describe 'Multiple services' diff --git a/tests/gantry_rollback_spec.sh b/tests/gantry_rollback_spec.sh index 256a355..0e561bf 100644 --- a/tests/gantry_rollback_spec.sh +++ b/tests/gantry_rollback_spec.sh @@ -65,6 +65,7 @@ Describe 'rollback' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_rollback_failed" "container_test:false" "coverage:true" @@ -116,6 +117,7 @@ Describe 'rollback' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_rollback_ROLLBACK_ON_FAILURE_false" "container_test:false" "coverage:true" @@ -165,6 +167,7 @@ Describe 'rollback' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_rollback_label_failed" "container_test:false" "coverage:true" @@ -219,6 +222,7 @@ Describe 'rollback' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_rollback_label_ROLLBACK_ON_FAILURE_false" "container_test:false" "coverage:true" @@ -270,6 +274,7 @@ Describe 'rollback' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End End # Describe 'Rollback' diff --git a/tests/gantry_service_no_running_tasks_spec.sh b/tests/gantry_service_no_running_tasks_spec.sh index 78ebc1e..f39be20 100644 --- a/tests/gantry_service_no_running_tasks_spec.sh +++ b/tests/gantry_service_no_running_tasks_spec.sh @@ -96,6 +96,7 @@ Describe "service-no-running-tasks" The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End Describe "test_no_running_tasks_global" "container_test:true" "coverage:true" @@ -156,6 +157,7 @@ Describe "service-no-running-tasks" The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End End # Describe "No Running Tasks" diff --git a/tests/gantry_service_single_spec.sh b/tests/gantry_service_single_spec.sh index c37fedf..9daeb2b 100644 --- a/tests/gantry_service_single_spec.sh +++ b/tests/gantry_service_single_spec.sh @@ -61,6 +61,7 @@ Describe 'service-single-service' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${SCHEDULE_NEXT_UPDATE_AT}" End End @@ -106,6 +107,7 @@ Describe 'service-single-service' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${SCHEDULE_NEXT_UPDATE_AT}" End End @@ -162,6 +164,7 @@ Describe 'service-single-service' # Failed to removing the old image due to it has no digest. The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${SCHEDULE_NEXT_UPDATE_AT}" End End @@ -211,6 +214,7 @@ Describe 'service-single-service' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${SCHEDULE_NEXT_UPDATE_AT}" End End diff --git a/tests/gantry_update_options_spec.sh b/tests/gantry_update_options_spec.sh index 91bb74a..8d97030 100644 --- a/tests/gantry_update_options_spec.sh +++ b/tests/gantry_update_options_spec.sh @@ -78,6 +78,7 @@ Describe 'update-options' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End Describe "test_update_label_UPDATE_OPTIONS" "container_test:true" "coverage:true" @@ -136,6 +137,7 @@ Describe 'update-options' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End Describe "test_update_UPDATE_TIMEOUT_SECONDS_not_a_number" "container_test:false" "coverage:true" @@ -180,6 +182,7 @@ Describe 'update-options' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End Describe "test_update_lable_UPDATE_TIMEOUT_SECONDS" "container_test:true" "coverage:true" @@ -242,6 +245,7 @@ Describe 'update-options' The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" + The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End End # Describe 'update-options' diff --git a/tests/spec_gantry_test_helper.sh b/tests/spec_gantry_test_helper.sh index 9082fb1..04787fd 100644 --- a/tests/spec_gantry_test_helper.sh +++ b/tests/spec_gantry_test_helper.sh @@ -67,6 +67,7 @@ export REMOVING_NUM_IMAGES="Removing [0-9]+ image\(s\)" export SKIP_REMOVING_IMAGES="Skip removing images" export REMOVED_IMAGE="Removed image" export FAILED_TO_REMOVE_IMAGE="Failed to remove image" +export DONE_REMOVING_IMAGES="Done removing images" export SCHEDULE_NEXT_UPDATE_AT="Schedule next update at" export SLEEP_SECONDS_BEFORE_NEXT_UPDATE="Sleep [0-9]+ seconds before next update" @@ -246,7 +247,8 @@ _login_test_registry() { local USERNAME="${3}" local PASSWORD="${4}" if ! _enforce_login_enabled "${ENFORCE_LOGIN}"; then - return 0 + USERNAME="username" + PASSWORD="password" fi echo "Logging in ${REGISTRY}." local CONFIG= @@ -522,7 +524,7 @@ _expect_message() { MESSAGE="${2}" local GREEN='\033[0;32m' local NO_COLOR='\033[0m' - if ! ACTUAL_MSG=$(echo "${TEXT}" | grep -Po "${MESSAGE}"); then + if ! ACTUAL_MSG=$(echo -e "${TEXT}" | grep -Po "${MESSAGE}"); then _handle_failure "Failed to find expected message \"${MESSAGE}\"." return 1 fi @@ -534,7 +536,7 @@ _expect_no_message() { MESSAGE="${2}" local GREEN='\033[0;32m' local NO_COLOR='\033[0m' - if ACTUAL_MSG=$(echo "${TEXT}" | grep -Po "${MESSAGE}"); then + if ACTUAL_MSG=$(echo -e "${TEXT}" | grep -Po "${MESSAGE}"); then _handle_failure "The following message should not present: \"${ACTUAL_MSG}\"" return 1 fi @@ -573,7 +575,7 @@ build_test_image() { echo "FROM ${TEST_SERVICE_IMAGE}" > "${FILE}" echo "ENTRYPOINT [\"sh\", \"-c\", \"echo $(unique_id); trap \\\"${EXIT_CMD}\\\" HUP INT TERM; ${TASK_CMD}\"]" >> "${FILE}" pull_image_if_not_exist "${TEST_SERVICE_IMAGE}" - echo "Building ${IMAGE_WITH_TAG} from ${FILE}" + echo "Building image ${IMAGE_WITH_TAG} from ${FILE}" timeout 120 docker build --quiet --tag "${IMAGE_WITH_TAG}" --file "${FILE}" . rm "${FILE}" } @@ -583,7 +585,7 @@ build_and_push_test_image() { local TASK_SECONDS="${2}" local EXIT_SECONDS="${3}" build_test_image "${IMAGE_WITH_TAG}" "${TASK_SECONDS}" "${EXIT_SECONDS}" - echo "Pushing image " + echo "Pushing image ${IMAGE_WITH_TAG}" # SC2046 (warning): Quote this to prevent word splitting. # shellcheck disable=SC2046 docker $(_get_docker_config_argument "${IMAGE_WITH_TAG}") push --quiet "${IMAGE_WITH_TAG}" @@ -591,8 +593,8 @@ build_and_push_test_image() { prune_local_test_image() { local IMAGE_WITH_TAG="${1}" - echo "Removing image ${IMAGE_WITH_TAG} " - docker image rm "${IMAGE_WITH_TAG}" --force & + echo "Removing image ${IMAGE_WITH_TAG}" + docker image rm "${IMAGE_WITH_TAG}" --force } docker_service_update() { @@ -814,8 +816,8 @@ _start_replicated_job() { stop_service() { local SERVICE_NAME="${1}" - echo "Removing service " - docker service rm "${SERVICE_NAME}" & + echo "Removing service ${SERVICE_NAME}" + docker service rm "${SERVICE_NAME}" } stop_multiple_services() {