From 97a9fc8f106bd0bc5dc204cb8e0a5e5f9ebfc4b6 Mon Sep 17 00:00:00 2001 From: Shizun Ge Date: Sun, 24 Nov 2024 22:32:19 -0800 Subject: [PATCH] [tests] allow more tests to run with a container. Use busybox time explicitly for docker service update. --- .github/workflows/on-push.yml | 2 +- src/lib-common.sh | 56 ++++--- src/lib-gantry.sh | 11 +- tests/README.md | 7 +- tests/gantry_cleanup_images_spec.sh | 8 +- tests/gantry_common_options_spec.sh | 41 +++-- tests/gantry_filters_spec.sh | 8 +- tests/gantry_jobs_spec.sh | 14 +- tests/gantry_login_docker_config_spec.sh | 51 +++--- tests/gantry_login_negative_spec.sh | 112 ++++++++----- tests/gantry_login_spec.sh | 40 +++-- tests/gantry_manifest_spec.sh | 12 +- tests/gantry_notify_spec.sh | 12 +- tests/gantry_parallel_spec.sh | 8 +- tests/gantry_rollback_spec.sh | 10 +- tests/gantry_service_multiple_spec.sh | 2 +- tests/gantry_service_no_running_tasks_spec.sh | 4 +- tests/gantry_service_single_spec.sh | 12 +- tests/gantry_update_options_spec.sh | 8 +- tests/spec_gantry_test_helper.sh | 156 ++++++++++++------ 20 files changed, 342 insertions(+), 232 deletions(-) diff --git a/.github/workflows/on-push.yml b/.github/workflows/on-push.yml index 56152b6..91592ab 100644 --- a/.github/workflows/on-push.yml +++ b/.github/workflows/on-push.yml @@ -162,4 +162,4 @@ jobs: export DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }} export GANTRY_TEST_CONTAINER_REPO_TAG=$(cat tag.txt) echo "GANTRY_TEST_CONTAINER_REPO_TAG=${GANTRY_TEST_CONTAINER_REPO_TAG}" - bash shellspec --jobs 50 --tag "container_test:true" + bash shellspec --jobs 50 diff --git a/src/lib-common.sh b/src/lib-common.sh index c01ee1f..c7411d5 100755 --- a/src/lib-common.sh +++ b/src/lib-common.sh @@ -21,11 +21,12 @@ _random_string() { _pipe_name() { local BASE_NAME="${1:-pipe-base-name}" - local RANDOM_STR= - RANDOM_STR=$(_random_string) + local PID=$$ local TIMESTAMP= TIMESTAMP=$(date +%s) - local PIPE_NAME="/tmp/${BASE_NAME}-$$-${TIMESTAMP}-${RANDOM_STR}" + local RANDOM_STR= + RANDOM_STR=$(_random_string) + local PIPE_NAME="/tmp/${BASE_NAME}-${PID}-${TIMESTAMP}-${RANDOM_STR}" echo "${PIPE_NAME}" } @@ -79,6 +80,7 @@ extract_string() { # All lower or all upper. No mix. _log_level_to_upper() { local LEVEL="${1}"; + # tr is slow. case "${LEVEL}" in "debug") echo "DEBUG"; ;; "info") echo "INFO"; ;; @@ -177,6 +179,8 @@ _color_iso_time() { local TIME_STR= TIME_STR=$(busybox date -d "@${EPOCH}" +"\033[1;30m%Y-%m-%dT\033[0;37m%H:%M:%S\033[1;30m%z") # +0000 -> +00:00 + # SC2028 (info): echo may not expand escape sequences. Use printf. + # shellcheck disable=SC2028 echo "${TIME_STR:0:-2}:${TIME_STR:0-2}\033[0m" } @@ -202,7 +206,14 @@ _log_formatter() { SCOPE_STR="${DGRAY}${SCOPE}:${NO_COLOR} " fi local MSG_STR= - MSG_STR=$(echo "${*}" | tr '\n' ' ') + # echo without quotes remove carriage returns, tabs and multiple spaces. + # SC2116 (style): Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'. + # SC2048 (warning): Use "$@" (with quotes) to prevent whitespace problems. + # SC2086 (info): Double quote to prevent globbing and word splitting. + # shellcheck disable=SC2048,SC2086,2116 + MSG_STR=$(echo ${*}) + # tr is slow. + # MSG_STR=$(echo "${*}" | tr '\n' ' ') echo -e "${TIME_STR}${LOC_STR}${LEVEL_STR}${SCOPE_STR}${MSG_STR}" >&2 } @@ -441,15 +452,10 @@ _get_docker_command_name_arg() { } _get_docker_command_detach() { - if echo "${@}" | grep_q "--detach=false"; then - echo "false" - elif echo "${@}" | grep_q "--detach"; then - # assume we find --detach or --detach=true. - echo "true" - else - echo "false" - fi - return 0 + echo "${@}" | grep_q "--detach=false" && return 1; + # assume we find --detach or --detach=true. + echo "${@}" | grep_q "--detach" && return 0; + return 1; } docker_service_logs() { @@ -557,25 +563,35 @@ _all_tasks_reach_state() { return 0 } -# Usage: wait_service_state +# Usage: wait_service_state [timeout in seconds] # 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. +# 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 the first failing task's return value. wait_service_state() { local SERVICE_NAME="${1}"; local WANT_STATE="${2}"; + local TIMEOUT_SECONDS="${3}"; local CHECK_FAILURES=false [ "${WANT_STATE}" = "Complete" ] && CHECK_FAILURES=true local SLEEP_SECONDS=1 - local DOCKER_CMD_ERROR=1 + local START_TIME= + START_TIME=$(date +%s) local RETURN_VALUE=0 + local DOCKER_CMD_ERROR=1 local STATES= while STATES=$(_docker_service_task_states "${SERVICE_NAME}" 2>&1); do DOCKER_CMD_ERROR=0 RETURN_VALUE=$(_all_tasks_reach_state "${WANT_STATE}" "${CHECK_FAILURES}" "${STATES}") && break + local SECONDS_ELAPSED= + if is_number "${TIMEOUT_SECONDS}" \ + && SECONDS_ELAPSED=$(first_minus_second "$(date +%s)" "${START_TIME}") \ + && [ "${SECONDS_ELAPSED}" -ge "${TIMEOUT_SECONDS}" ]; then + log ERROR "wait_service_state ${SERVICE_NAME} ${WANT_STATE} timeout after ${SECONDS_ELAPSED}s." + RETURN_VALUE=2 + break + fi sleep "${SLEEP_SECONDS}" DOCKER_CMD_ERROR=1 done @@ -636,9 +652,7 @@ docker_global_job() { # 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}." @@ -648,7 +662,7 @@ docker_replicated_job() { return 1 fi # If the command line does not contain '--detach', the function returns til the replicated job is complete. - if ! "${IS_DETACH}"; then + if ! _get_docker_command_detach "${@}"; then wait_service_state "${SERVICE_NAME}" "Complete" || return $? fi return 0 diff --git a/src/lib-gantry.sh b/src/lib-gantry.sh index 18766a6..51e9d8d 100755 --- a/src/lib-gantry.sh +++ b/src/lib-gantry.sh @@ -978,7 +978,7 @@ _get_timeout_command() { fi local TIMEOUT_COMMAND="" if [ "${UPDATE_TIMEOUT_SECONDS}" != "0" ]; then - TIMEOUT_COMMAND="timeout ${UPDATE_TIMEOUT_SECONDS}" + TIMEOUT_COMMAND="busybox timeout ${UPDATE_TIMEOUT_SECONDS}" log DEBUG "Set timeout to ${UPDATE_TIMEOUT_SECONDS} for updating ${SERVICE_NAME}." fi echo "${TIMEOUT_COMMAND}" @@ -1013,14 +1013,17 @@ _update_single_service() { local UPDATE_COMMAND="${TIMEOUT_COMMAND} docker ${AUTH_CONFIG} service update" local UPDATE_RETURN_VALUE=0 local UPDATE_MSG= + # Add "2>/dev/null" outside the $(cmd) to suppress the "Terminated" message from "busybox timeout". # Add "-quiet" to suppress progress output. # SC2086: Double quote to prevent globbing and word splitting. # shellcheck disable=SC2086 - UPDATE_MSG=$(${UPDATE_COMMAND} --quiet ${AUTOMATIC_OPTIONS} ${UPDATE_OPTIONS} --image="${IMAGE}" "${SERVICE_NAME}" 2>&1); + UPDATE_MSG=$(${UPDATE_COMMAND} --quiet ${AUTOMATIC_OPTIONS} ${UPDATE_OPTIONS} --image="${IMAGE}" "${SERVICE_NAME}" 2>&1) 2>/dev/null; UPDATE_RETURN_VALUE=$? if [ "${UPDATE_RETURN_VALUE}" != 0 ]; then - # https://git.savannah.gnu.org/cgit/coreutils.git/tree/src/timeout.c - local TIMEOUT_RETURN_CODE=124 + # When there is a timeout: + # * coreutils timeout returns 124: https://git.savannah.gnu.org/cgit/coreutils.git/tree/src/timeout.c + # * busybox timeout returns 143 + local TIMEOUT_RETURN_CODE=143 local TIMEOUT_MSG="" if [ -n "${TIMEOUT_COMMAND}" ] && [ "${UPDATE_RETURN_VALUE}" = "${TIMEOUT_RETURN_CODE}" ]; then TIMEOUT_MSG="The return value ${UPDATE_RETURN_VALUE} indicates the job timed out." diff --git a/tests/README.md b/tests/README.md index b334374..57ccdf2 100644 --- a/tests/README.md +++ b/tests/README.md @@ -29,14 +29,11 @@ bash shellspec --jobs 50 To generate coverage (require [kcov](https://github.com/SimonKagstrom/kcov) installed): ``` -bash shellspec --kcov --tag coverage:true +bash shellspec --kcov --tag "coverage:true" ``` If you want to test a container image of *Gantry*, you need to specify the image of *Gantry* via the environment variable `GANTRY_TEST_CONTAINER_REPO_TAG`. ``` export GANTRY_TEST_CONTAINER_REPO_TAG=: -bash shellspec --tag "container_test:true" "coverage:true" +bash shellspec --jobs 50 ``` - -> NOTE: Negative tests will hang when testing a *Gantry* container, which may be due to a bug in shellspec. So when testing *Gantry* images, we should run only tests with tag `container_test:true`. - diff --git a/tests/gantry_cleanup_images_spec.sh b/tests/gantry_cleanup_images_spec.sh index 3189ed0..95c6889 100644 --- a/tests/gantry_cleanup_images_spec.sh +++ b/tests/gantry_cleanup_images_spec.sh @@ -20,7 +20,7 @@ Describe 'cleanup-images' SUITE_NAME="cleanup-images" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_CLEANUP_IMAGES_false" "container_test:true" "coverage:true" + Describe "test_CLEANUP_IMAGES_false" "coverage:true" TEST_NAME="test_CLEANUP_IMAGES_false" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -63,7 +63,7 @@ Describe 'cleanup-images' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_CLEANUP_IMAGES_OPTIONS_bad" "container_test:true" "coverage:true" + Describe "test_CLEANUP_IMAGES_OPTIONS_bad" "coverage:true" TEST_NAME="test_CLEANUP_IMAGES_OPTIONS_bad" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -110,7 +110,7 @@ Describe 'cleanup-images' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_CLEANUP_IMAGES_OPTIONS_good" "container_test:true" "coverage:true" + Describe "test_CLEANUP_IMAGES_OPTIONS_good" "coverage:true" TEST_NAME="test_CLEANUP_IMAGES_OPTIONS_good" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -156,7 +156,7 @@ Describe 'cleanup-images' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_IMAGES_TO_REMOVE_none_empty" "container_test:true" "coverage:true" + Describe "test_IMAGES_TO_REMOVE_none_empty" "coverage:true" # Test the remove image entrypoint. To improve coverage. TEST_NAME="test_IMAGES_TO_REMOVE_none_empty" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") diff --git a/tests/gantry_common_options_spec.sh b/tests/gantry_common_options_spec.sh index f659d7d..d9bc750 100644 --- a/tests/gantry_common_options_spec.sh +++ b/tests/gantry_common_options_spec.sh @@ -19,7 +19,7 @@ Describe 'common-options' SUITE_NAME="common-options" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_common_DOCKER_HOST_not_swarm_manager" "container_test:false" "coverage:true" + Describe "test_common_DOCKER_HOST_not_swarm_manager" "coverage:true" TEST_NAME="test_common_DOCKER_HOST_not_swarm_manager" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -27,12 +27,8 @@ Describe 'common-options' 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 + export GANTRY_TEST_DOCKER_HOST="8.8.8.8:53" run_gantry "${TEST_NAME}" - RETURN_VALUE="${?}" - export DOCKER_HOST= - return "${RETURN_VALUE}" } BeforeEach "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" @@ -69,7 +65,7 @@ Describe 'common-options' The stderr should satisfy spec_expect_no_message "${SLEEP_SECONDS_BEFORE_NEXT_UPDATE}" End End - Describe "test_common_LOG_LEVEL_none" "container_test:true" "coverage:true" + Describe "test_common_LOG_LEVEL_none" "coverage:true" TEST_NAME="test_common_LOG_LEVEL_none" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -93,10 +89,12 @@ Describe 'common-options' End End # Do not run test_common_no_new_env with the kcov, which alters the environment variables. - Describe "test_common_no_new_env" "container_test:false" "coverage:false" + Describe "test_common_no_new_env" "coverage:false" # Check there is no new variable set, # to avoid errors like https://github.com/shizunge/gantry/issues/64#issuecomment-2475499085 - # We don't need to run this test using containers because we check env on the host, while the container test set env inside the container. + # + # It makes no sense to run run this test using containers because we check env on the host, while the container test set env inside the container. + # But it should not failed with a container. We are just testing GANTRY_LOG_LEVEL=WARN. TEST_NAME="test_common_no_new_env" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -135,7 +133,7 @@ Describe 'common-options' The stderr should satisfy spec_expect_no_message ".+" End End - Describe "test_common_PRE_POST_RUN_CMD" "container_test:true" "coverage:true" + Describe "test_common_PRE_POST_RUN_CMD" "coverage:true" TEST_NAME="test_common_PRE_POST_RUN_CMD" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -162,8 +160,8 @@ Describe 'common-options' The stdout should satisfy spec_expect_no_message ".+" 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_message "Finish pre-run command." + The stderr should satisfy spec_expect_message "Pre update$" + 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}" @@ -186,19 +184,16 @@ Describe 'common-options' 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 "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_message "Post update$" + 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 End - # run_gantry prints logs after gantry exists, while testing a container. - # In thes test, gantry never exit, but will be killed, thus there is no log. - # Therefore we disable the container test for this test. - Describe "test_common_SLEEP_SECONDS" "container_test:false" "coverage:true" + Describe "test_common_SLEEP_SECONDS" "coverage:true" TEST_NAME="test_common_SLEEP_SECONDS" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -207,9 +202,11 @@ Describe 'common-options' local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" export GANTRY_SLEEP_SECONDS="7" + # Run run_gantry in background. run_gantry "${TEST_NAME}" & local PID="${!}" sleep $((GANTRY_SLEEP_SECONDS*3+1)) + stop_gantry_container "${TEST_NAME}" kill "${PID}" } BeforeEach "common_setup_no_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" @@ -249,7 +246,7 @@ Describe 'common-options' The stderr should satisfy spec_expect_message "${SLEEP_SECONDS_BEFORE_NEXT_UPDATE}" End End - Describe "test_common_SLEEP_SECONDS_not_a_number" "container_test:false" "coverage:true" + Describe "test_common_SLEEP_SECONDS_not_a_number" "coverage:true" TEST_NAME="test_common_SLEEP_SECONDS_not_a_number" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") diff --git a/tests/gantry_filters_spec.sh b/tests/gantry_filters_spec.sh index d14ebcb..023d971 100644 --- a/tests/gantry_filters_spec.sh +++ b/tests/gantry_filters_spec.sh @@ -19,7 +19,7 @@ Describe 'filters' SUITE_NAME="filters" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_SERVICES_FILTERS_bad" "container_test:false" "coverage:true" + Describe "test_SERVICES_FILTERS_bad" "coverage:true" TEST_NAME="test_SERVICES_FILTERS_bad" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -64,7 +64,7 @@ Describe 'filters' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_SERVICES_EXCLUDED_multiple_services" "container_test:true" "coverage:true" + Describe "test_SERVICES_EXCLUDED_multiple_services" "coverage:true" TEST_NAME="test_SERVICES_EXCLUDED_multiple_services" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -122,7 +122,7 @@ Describe 'filters' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_SERVICES_EXCLUDED_FILTERS_default" "container_test:true" "coverage:true" + Describe "test_SERVICES_EXCLUDED_FILTERS_default" "coverage:true" TEST_NAME="test_SERVICES_EXCLUDED_FILTERS_default" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -173,7 +173,7 @@ Describe 'filters' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_SERVICES_EXCLUDED_FILTERS_bad" "container_test:false" "coverage:true" + Describe "test_SERVICES_EXCLUDED_FILTERS_bad" "coverage:true" TEST_NAME="test_SERVICES_EXCLUDED_FILTERS_bad" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") diff --git a/tests/gantry_jobs_spec.sh b/tests/gantry_jobs_spec.sh index 0bd26ae..b9744e3 100644 --- a/tests/gantry_jobs_spec.sh +++ b/tests/gantry_jobs_spec.sh @@ -15,11 +15,11 @@ # along with this program. If not, see . # -Describe 'update-jobs' - SUITE_NAME="update-jobs" +Describe 'jobs' + SUITE_NAME="jobs" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_jobs_skipping" "container_test:true" "coverage:true" + Describe "test_jobs_skipping" "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 @@ -86,7 +86,7 @@ Describe 'update-jobs' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_jobs_UPDATE_JOBS_true" "container_test:true" "coverage:true" + Describe "test_jobs_UPDATE_JOBS_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}") @@ -137,7 +137,7 @@ Describe 'update-jobs' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_jobs_label_UPDATE_JOBS_true" "container_test:true" "coverage:true" + Describe "test_jobs_label_UPDATE_JOBS_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}") @@ -194,7 +194,7 @@ Describe 'update-jobs' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_jobs_no_running_tasks" "container_test:true" "coverage:true" + Describe "test_jobs_no_running_tasks" "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}") @@ -253,4 +253,4 @@ Describe 'update-jobs' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End -End # Describe 'update-jobs' +End # Describe 'jobs' diff --git a/tests/gantry_login_docker_config_spec.sh b/tests/gantry_login_docker_config_spec.sh index d8a14db..aec7091 100644 --- a/tests/gantry_login_docker_config_spec.sh +++ b/tests/gantry_login_docker_config_spec.sh @@ -31,15 +31,18 @@ # D=1 C=1 L=0 test_login_docker_config_no_label # D=1 C=1 L=1 test_login_docker_config_label_override SERVICE_NAME1 -Describe 'login_docker_config' - SUITE_NAME="login_docker_config" +Describe 'login-docker-config' + SUITE_NAME="login-docker-config" BeforeAll "initialize_all_tests ${SUITE_NAME} ENFORCE_LOGIN" AfterAll "finish_all_tests ${SUITE_NAME} ENFORCE_LOGIN" - Describe "test_login_docker_config_no_label" "container_test:true" "coverage:true" + Describe "test_login_docker_config_no_label" "coverage:true" TEST_NAME="test_login_docker_config_no_label" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_docker_config_no_label() { local TEST_NAME="${1}" @@ -52,7 +55,7 @@ Describe 'login_docker_config' local USER_FILE=; USER_FILE=$(mktemp); echo "${USERNAME}" > "${USER_FILE}"; local PASS_FILE=; PASS_FILE=$(mktemp); echo "${PASSWORD}" > "${PASS_FILE}"; reset_gantry_env "${SERVICE_NAME}" - export DOCKER_CONFIG="${CONFIG}" + export GANTRY_TEST_DOCKER_CONFIG="${CONFIG}" export GANTRY_REGISTRY_CONFIG="${CONFIG}" export GANTRY_REGISTRY_HOST="${REGISTRY}" export GANTRY_REGISTRY_PASSWORD_FILE="${PASS_FILE}" @@ -68,14 +71,14 @@ Describe 'login_docker_config' BeforeEach "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" It 'run_test' - When run test_login_docker_config_no_label "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_docker_config_no_label "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be success The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" 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_no_message "${LOGGED_INTO_REGISTRY}.*${DEFAULT_CONFIGURATION}" - The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_LOGIN_TO_REGISTRY}" The stderr should satisfy spec_expect_no_message "${CONFIG_IS_NOT_A_DIRECTORY}" The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME}" @@ -106,11 +109,14 @@ Describe 'login_docker_config' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_docker_config_default_config" "container_test:true" "coverage:true" + Describe "test_login_docker_config_default_config" "coverage:true" TEST_NAME="test_login_docker_config_default_config" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_docker_config_default_config() { local TEST_NAME="${1}" @@ -124,7 +130,7 @@ Describe 'login_docker_config' local PASS_FILE=; PASS_FILE=$(mktemp); echo "${PASSWORD}" > "${PASS_FILE}"; # Do not set GANTRY_AUTH_CONFIG_LABEL on the service. reset_gantry_env "${SERVICE_NAME}" - export DOCKER_CONFIG="${CONFIG}" + export GANTRY_TEST_DOCKER_CONFIG="${CONFIG}" # Do not set GANTRY_REGISTRY_CONFIG to login to the default configuration. export GANTRY_REGISTRY_HOST="${REGISTRY}" export GANTRY_REGISTRY_PASSWORD_FILE="${PASS_FILE}" @@ -141,7 +147,7 @@ Describe 'login_docker_config' BeforeEach "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" It 'run_test' - When run test_login_docker_config_default_config "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_docker_config_default_config "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be success The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" @@ -177,14 +183,17 @@ Describe 'login_docker_config' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_docker_config_label_override" "container_test:false" "coverage:true" + Describe "test_login_docker_config_label_override" "coverage:true" TEST_NAME="test_login_docker_config_label_override" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") SERVICE_NAME0="${SERVICE_NAME}-0" SERVICE_NAME1="${SERVICE_NAME}-1" SERVICE_NAME2="${SERVICE_NAME}-2" - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_start() { local TEST_NAME="${1}" @@ -218,7 +227,7 @@ Describe 'login_docker_config' docker_service_update --label-add "${GANTRY_AUTH_CONFIG_LABEL}=${CONFIG}" "${SERVICE_NAME1}" reset_gantry_env "${SERVICE_NAME}" # Inspection and updating should use DOCKER_CONFIG or the label. - export DOCKER_CONFIG="${CONFIG}" + export GANTRY_TEST_DOCKER_CONFIG="${CONFIG}" export GANTRY_REGISTRY_CONFIGS_FILE="${CONFIGS_FILE}" # Set GANTRY_CLEANUP_IMAGES="false" to speedup the test. We are not testing removing image here. export GANTRY_CLEANUP_IMAGES="false" @@ -241,21 +250,21 @@ Describe 'login_docker_config' 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_login_docker_config_label_override "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_docker_config_label_override "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be failure The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" 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 "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_LOGIN_TO_REGISTRY}" - The stderr should satisfy spec_expect_message "incorrect-${CONFIG}.*${CONFIG_IS_NOT_A_DIRECTORY}" + The stderr should satisfy spec_expect_message "incorrect-${AUTH_CONFIG}.*${CONFIG_IS_NOT_A_DIRECTORY}" # Check warnings The stderr should satisfy spec_expect_message "${THERE_ARE_NUM_CONFIGURATIONS}.*" The stderr should satisfy spec_expect_message "${USER_LOGGED_INTO_DEFAULT}.*" - The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config incorrect-${CONFIG}.*${SERVICE_NAME0}" - The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config ${CONFIG}.*${SERVICE_NAME1}" - The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--config ${CONFIG}.*${SERVICE_NAME2}" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config incorrect-${AUTH_CONFIG}.*${SERVICE_NAME0}" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config ${AUTH_CONFIG}.*${SERVICE_NAME1}" + The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--config ${AUTH_CONFIG}.*${SERVICE_NAME2}" The stderr should satisfy spec_expect_no_message "${PERFORM_UPDATING}.*${SERVICE_NAME0}.*" The stderr should satisfy spec_expect_message "${SKIP_UPDATING}.*${SERVICE_NAME0}.*${SKIP_REASON_MANIFEST_FAILURE}" The stderr should satisfy spec_expect_message "${PERFORM_UPDATING}.*${SERVICE_NAME1}.*${PERFORM_REASON_HAS_NEWER_IMAGE}" @@ -296,4 +305,4 @@ Describe 'login_docker_config' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End -End # Describe 'login_docker_config' +End # Describe 'login-docker-config' diff --git a/tests/gantry_login_negative_spec.sh b/tests/gantry_login_negative_spec.sh index 6db85d2..9f4ba54 100644 --- a/tests/gantry_login_negative_spec.sh +++ b/tests/gantry_login_negative_spec.sh @@ -15,15 +15,18 @@ # along with this program. If not, see . # -Describe 'login_negative' - SUITE_NAME="login_negative" +Describe 'login-negative' + SUITE_NAME="login-negative" BeforeAll "initialize_all_tests ${SUITE_NAME} ENFORCE_LOGIN" AfterAll "finish_all_tests ${SUITE_NAME} ENFORCE_LOGIN" - Describe "test_login_no_login" "container_test:false" "coverage:true" + Describe "test_login_no_login" "coverage:true" TEST_NAME="test_login_no_login" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_no_login() { local TEST_NAME="${1}" @@ -34,7 +37,7 @@ Describe 'login_negative' BeforeEach "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" It 'run_test' - When run test_login_no_login "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_no_login "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be failure The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" @@ -70,11 +73,14 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_incorrect_password" "container_test:false" "coverage:true" + Describe "test_login_incorrect_password" "coverage:true" TEST_NAME="test_login_incorrect_password" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_incorrect_password() { local TEST_NAME="${1}" @@ -104,14 +110,14 @@ Describe 'login_negative' BeforeEach "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" It 'run_test' - When run test_login_incorrect_password "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_incorrect_password "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be failure The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" 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_no_message "${LOGGED_INTO_REGISTRY}" - The stderr should satisfy spec_expect_message "${FAILED_TO_LOGIN_TO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_message "${FAILED_TO_LOGIN_TO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${CONFIG_IS_NOT_A_DIRECTORY}" The stderr should satisfy spec_expect_message "${SKIP_UPDATING_ALL}.*${SKIP_REASON_PREVIOUS_ERRORS}" The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME}" @@ -139,11 +145,11 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_read_only_file" "container_test:false" "coverage:true" + Describe "test_login_read_only_file" "coverage:true" TEST_NAME="test_login_read_only_file" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + AUTH_CONFIG=$(mktemp -d) TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_read_only_file() { local TEST_NAME="${1}" @@ -153,13 +159,16 @@ Describe 'login_negative' local USERNAME="${5}" local PASSWORD="${6}" check_login_input "${REGISTRY}" "${USERNAME}" "${PASSWORD}" || return 1; - # Set the config folder to read only. (It won't work for container_test) + # When running with an image, we are not changing the folder inside the contianer. + # So do not run the test with a container/image. mkdir -p "${CONFIG}" chmod 444 "${CONFIG}" local USER_FILE=; USER_FILE=$(mktemp); echo "${USERNAME}" > "${USER_FILE}"; local PASS_FILE=; PASS_FILE=$(mktemp); echo "${PASSWORD}" > "${PASS_FILE}"; docker_service_update --label-add "${GANTRY_AUTH_CONFIG_LABEL}=${CONFIG}" "${SERVICE_NAME}" reset_gantry_env "${SERVICE_NAME}" + # Use GANTRY_TEST_HOST_TO_CONTAINER to mount the file from host to the container. + export GANTRY_TEST_HOST_TO_CONTAINER="${CONFIG}" export GANTRY_REGISTRY_CONFIG="${CONFIG}" export GANTRY_REGISTRY_HOST="${REGISTRY}" export GANTRY_REGISTRY_PASSWORD_FILE="${PASS_FILE}" @@ -169,20 +178,20 @@ Describe 'login_negative' RETURN_VALUE="${?}" rm "${USER_FILE}" rm "${PASS_FILE}" - [ -d "${CONFIG}" ] && chmod 777 "${CONFIG}" && rm -r "${CONFIG}" + # [ -d "${CONFIG}" ] && chmod 777 "${CONFIG}" && rm -r "${CONFIG}" return "${RETURN_VALUE}" } BeforeEach "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" It 'run_test' - When run test_login_read_only_file "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_read_only_file "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be failure The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" 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_no_message "${LOGGED_INTO_REGISTRY}" - The stderr should satisfy spec_expect_message "${FAILED_TO_LOGIN_TO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_message "${FAILED_TO_LOGIN_TO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${CONFIG_IS_NOT_A_DIRECTORY}" The stderr should satisfy spec_expect_message "${SKIP_UPDATING_ALL}.*${SKIP_REASON_PREVIOUS_ERRORS}" The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME}" @@ -210,11 +219,14 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_config_mismatch_default" "container_test:false" "coverage:true" + Describe "test_login_config_mismatch_default" "coverage:true" TEST_NAME="test_login_config_mismatch_default" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_config_mismatch_default() { local TEST_NAME="${1}" @@ -254,21 +266,21 @@ Describe 'login_negative' BeforeEach "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" It 'run_test' - When run test_login_config_mismatch_default "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_config_mismatch_default "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be failure The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" 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 "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${DEFAULT_CONFIGURATION}" - The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_LOGIN_TO_REGISTRY}" - The stderr should satisfy spec_expect_message "incorrect-${CONFIG}.*${CONFIG_IS_NOT_A_DIRECTORY}" + The stderr should satisfy spec_expect_message "incorrect-${AUTH_CONFIG}.*${CONFIG_IS_NOT_A_DIRECTORY}" # Check warnings The stderr should satisfy spec_expect_message "${THERE_ARE_NUM_CONFIGURATIONS}.*" The stderr should satisfy spec_expect_message "${USER_LOGGED_INTO_DEFAULT}.*" - The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--config ${CONFIG}.*" - The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config incorrect-${CONFIG}.*${SERVICE_NAME}" + The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--config ${AUTH_CONFIG}.*" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config incorrect-${AUTH_CONFIG}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_message "${SKIP_UPDATING}.*${SERVICE_NAME}.*${SKIP_REASON_MANIFEST_FAILURE}" The stderr should satisfy spec_expect_no_message "${PERFORM_UPDATING}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" @@ -295,11 +307,14 @@ Describe 'login_negative' 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" + Describe "test_login_config_mismatch_no_default" "coverage:true" TEST_NAME="test_login_config_mismatch_no_default" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_config_mismatch_no_default() { local TEST_NAME="${1}" @@ -332,22 +347,22 @@ Describe 'login_negative' BeforeEach "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" It 'run_test' - When run test_login_config_mismatch_no_default "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_config_mismatch_no_default "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be failure The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" 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_no_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${DEFAULT_CONFIGURATION}" - The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_LOGIN_TO_REGISTRY}" - The stderr should satisfy spec_expect_message "incorrect-${CONFIG}.*${CONFIG_IS_NOT_A_DIRECTORY}" + The stderr should satisfy spec_expect_message "incorrect-${AUTH_CONFIG}.*${CONFIG_IS_NOT_A_DIRECTORY}" # Check warnings The stderr should satisfy spec_expect_message "${THERE_ARE_NUM_CONFIGURATIONS}.*" # This message does not present, because we don't login with the default configuration. The stderr should satisfy spec_expect_no_message "${USER_LOGGED_INTO_DEFAULT}.*" - The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--config ${CONFIG}.*" - The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config incorrect-${CONFIG}.*${SERVICE_NAME}" + The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--config ${AUTH_CONFIG}.*" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config incorrect-${AUTH_CONFIG}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_message "${SKIP_UPDATING}.*${SERVICE_NAME}.*${SKIP_REASON_MANIFEST_FAILURE}" The stderr should satisfy spec_expect_no_message "${PERFORM_UPDATING}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" @@ -374,7 +389,7 @@ Describe 'login_negative' 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" + Describe "test_login_multi_services_no_label" "coverage:true" # To test https://github.com/shizunge/gantry/issues/64#issuecomment-2475499085 TEST_NAME="test_login_multi_services_no_label" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") @@ -383,7 +398,10 @@ Describe 'login_negative' IMAGE_WITH_TAG1="${IMAGE_WITH_TAG}-1" SERVICE_NAME0="${SERVICE_NAME}-0" SERVICE_NAME1="${SERVICE_NAME}-1" - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_start() { local TEST_NAME="${1}" @@ -446,16 +464,16 @@ Describe 'login_negative' 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_login_multi_services_no_label "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_multi_services_no_label "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be failure The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" 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 "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_LOGIN_TO_REGISTRY}" - The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--config ${CONFIG}.*${SERVICE_NAME0}" - The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config ${CONFIG}.*${SERVICE_NAME1}" + The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--config ${AUTH_CONFIG}.*${SERVICE_NAME0}" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config ${AUTH_CONFIG}.*${SERVICE_NAME1}" The stderr should satisfy spec_expect_no_message "${PERFORM_UPDATING}.*${SERVICE_NAME0}.*" The stderr should satisfy spec_expect_message "${SKIP_UPDATING}.*${SERVICE_NAME0}.*${SKIP_REASON_MANIFEST_FAILURE}" The stderr should satisfy spec_expect_message "${PERFORM_UPDATING}.*${SERVICE_NAME1}.*${PERFORM_REASON_HAS_NEWER_IMAGE}" @@ -489,11 +507,14 @@ Describe 'login_negative' 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" + Describe "test_login_REGISTRY_CONFIGS_FILE_bad_format" "coverage:true" TEST_NAME="test_login_REGISTRY_CONFIGS_FILE_bad_format" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_REGISTRY_CONFIGS_FILE_bad_format() { local TEST_NAME="${1}" @@ -522,7 +543,7 @@ Describe 'login_negative' BeforeEach "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" It 'run_test' - When run test_login_REGISTRY_CONFIGS_FILE_bad_format "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_REGISTRY_CONFIGS_FILE_bad_format "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be failure The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" @@ -530,7 +551,7 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" The stderr should satisfy spec_expect_message "format error.*Found extra item\(s\)" The stderr should satisfy spec_expect_message "format error.*Missing item\(s\)" - The stderr should satisfy spec_expect_no_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_no_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_LOGIN_TO_REGISTRY}" The stderr should satisfy spec_expect_no_message "${CONFIG_IS_NOT_A_DIRECTORY}" The stderr should satisfy spec_expect_message "${SKIP_UPDATING_ALL}.*${SKIP_REASON_PREVIOUS_ERRORS}" @@ -559,11 +580,14 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_file_not_exist" "container_test:false" "coverage:true" + Describe "test_login_file_not_exist" "coverage:true" TEST_NAME="test_login_file_not_exist" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_file_not_exist() { local TEST_NAME="${1}" @@ -590,13 +614,13 @@ Describe 'login_negative' BeforeEach "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" It 'run_test' - When run test_login_file_not_exist "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_file_not_exist "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be failure The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" 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_no_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_no_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_LOGIN_TO_REGISTRY}" The stderr should satisfy spec_expect_no_message "${CONFIG_IS_NOT_A_DIRECTORY}" The stderr should satisfy spec_expect_message "${SKIP_UPDATING_ALL}.*${SKIP_REASON_PREVIOUS_ERRORS}" @@ -625,4 +649,4 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End -End # Describe 'login_negative' +End # Describe 'login-negative' diff --git a/tests/gantry_login_spec.sh b/tests/gantry_login_spec.sh index 4c26906..dc534b3 100644 --- a/tests/gantry_login_spec.sh +++ b/tests/gantry_login_spec.sh @@ -22,11 +22,14 @@ Describe 'login' SUITE_NAME="login" BeforeAll "initialize_all_tests ${SUITE_NAME} ENFORCE_LOGIN" AfterAll "finish_all_tests ${SUITE_NAME} ENFORCE_LOGIN" - Describe "test_login_config" "container_test:true" "coverage:true" + Describe "test_login_config" "coverage:true" TEST_NAME="test_login_config" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_config() { local TEST_NAME="${1}" @@ -58,14 +61,14 @@ Describe 'login' BeforeEach "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" It 'run_test' - When run test_login_config "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_config "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be success The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" 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_no_message "${LOGGED_INTO_REGISTRY}.*${DEFAULT_CONFIGURATION}" - The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_LOGIN_TO_REGISTRY}" The stderr should satisfy spec_expect_no_message "${CONFIG_IS_NOT_A_DIRECTORY}" The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME}" @@ -74,7 +77,7 @@ Describe 'login' The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_INSPECT_FAILURE}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_NO_NEW_IMAGES}" The stderr should satisfy spec_expect_message "${NUM_SERVICES_UPDATING}" - The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config ${CONFIG}.*${SERVICE_NAME}" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config ${AUTH_CONFIG}.*${SERVICE_NAME}" # 2 "--with-registry-auth" for SERVICE_NAME. One is automatically added. The other is from user. The stderr should satisfy spec_expect_message "${ADDING_OPTIONS_WITH_REGISTRY_AUTH}.*automatically.*${SERVICE_NAME}" The stderr should satisfy spec_expect_message "${ADDING_OPTIONS_WITH_REGISTRY_AUTH}.*specified by user.*${SERVICE_NAME}" @@ -96,11 +99,11 @@ Describe 'login' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_default_config" "container_test:true" "coverage:true" + Describe "test_login_default_config" "coverage:true" TEST_NAME="test_login_default_config" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="NotUsed" + AUTH_CONFIG="NotUsed" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_default_config() { local TEST_NAME="${1}" @@ -130,7 +133,7 @@ Describe 'login' BeforeEach "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" It 'run_test' - When run test_login_default_config "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_default_config "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be success The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" @@ -166,11 +169,14 @@ Describe 'login' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_REGISTRY_CONFIGS_FILE" "container_test:true" "coverage:true" + Describe "test_login_REGISTRY_CONFIGS_FILE" "coverage:true" TEST_NAME="test_login_REGISTRY_CONFIGS_FILE" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_REGISTRY_CONFIGS_FILE() { local TEST_NAME="${1}" @@ -204,14 +210,14 @@ Describe 'login' BeforeEach "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" It 'run_test' - When run test_login_REGISTRY_CONFIGS_FILE "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_REGISTRY_CONFIGS_FILE "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be success The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" 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_no_message "${LOGGED_INTO_REGISTRY}.*${DEFAULT_CONFIGURATION}" - The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_LOGIN_TO_REGISTRY}" The stderr should satisfy spec_expect_no_message "${CONFIG_IS_NOT_A_DIRECTORY}" The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME}" @@ -220,7 +226,7 @@ Describe 'login' The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_INSPECT_FAILURE}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_NO_NEW_IMAGES}" The stderr should satisfy spec_expect_message "${NUM_SERVICES_UPDATING}" - The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config ${CONFIG}.*${SERVICE_NAME}" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config ${AUTH_CONFIG}.*${SERVICE_NAME}" # Gantry adds --with-registry-auth for finding GANTRY_AUTH_CONFIG_LABEL on the service. The stderr should satisfy spec_expect_message "${ADDING_OPTIONS_WITH_REGISTRY_AUTH}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${THERE_ARE_ADDITIONAL_MESSAGES}.*${SERVICE_NAME}.*" @@ -241,11 +247,11 @@ Describe 'login' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_external_config" "container_test:true" "coverage:true" + Describe "test_login_external_config" "coverage:true" TEST_NAME="test_login_external_config" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="$(mktemp -d)" + AUTH_CONFIG="$(mktemp -d)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_external_config() { local TEST_NAME="${1}" @@ -260,7 +266,7 @@ Describe 'login' chmod 555 "${CONFIG}" # Do not set GANTRY_AUTH_CONFIG_LABEL on service. reset_gantry_env "${SERVICE_NAME}" - export DOCKER_CONFIG="${CONFIG}" + export GANTRY_TEST_DOCKER_CONFIG="${CONFIG}" # Use manifest to avoid write to DOCKER_CONFIG. # When running container test, Gantry runs as root. # We cannot remove DOCKER_CONFIG when it containes data from root. @@ -276,7 +282,7 @@ Describe 'login' BeforeEach "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" It 'run_test' - When run test_login_external_config "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_external_config "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be success The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" diff --git a/tests/gantry_manifest_spec.sh b/tests/gantry_manifest_spec.sh index d79ca32..d2d5888 100644 --- a/tests/gantry_manifest_spec.sh +++ b/tests/gantry_manifest_spec.sh @@ -19,7 +19,7 @@ Describe 'manifest-command' SUITE_NAME="manifest-command" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_MANIFEST_CMD_none" "container_test:true" "coverage:true" + Describe "test_MANIFEST_CMD_none" "coverage:true" TEST_NAME="test_MANIFEST_CMD_none" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -70,7 +70,7 @@ Describe 'manifest-command' 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" + Describe "test_MANIFEST_CMD_none_SERVICES_SELF" "coverage:true" TEST_NAME="test_MANIFEST_CMD_none_SERVICES_SELF" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -118,7 +118,7 @@ Describe 'manifest-command' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_MANIFEST_CMD_manifest" "container_test:true" "coverage:true" + Describe "test_MANIFEST_CMD_manifest" "coverage:true" TEST_NAME="test_MANIFEST_CMD_manifest" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -163,7 +163,7 @@ Describe 'manifest-command' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_MANIFEST_CMD_label" "container_test:true" "coverage:true" + Describe "test_MANIFEST_CMD_label" "coverage:true" TEST_NAME="test_MANIFEST_CMD_label" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -213,7 +213,7 @@ Describe 'manifest-command' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_MANIFEST_CMD_unsupported_cmd" "container_test:false" "coverage:true" + Describe "test_MANIFEST_CMD_unsupported_cmd" "coverage:true" TEST_NAME="test_MANIFEST_CMD_unsupported_cmd" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -260,7 +260,7 @@ Describe 'manifest-command' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_MANIFEST_CMD_failure" "container_test:false" "coverage:true" + Describe "test_MANIFEST_CMD_failure" "coverage:true" TEST_NAME="test_MANIFEST_CMD_failure" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") diff --git a/tests/gantry_notify_spec.sh b/tests/gantry_notify_spec.sh index 02dacdd..d071a4d 100644 --- a/tests/gantry_notify_spec.sh +++ b/tests/gantry_notify_spec.sh @@ -69,7 +69,7 @@ Describe 'notify' SUITE_NAME="notify" BeforeAll "_notify_before_all ${SUITE_NAME}" AfterAll "_notify_after_all ${SUITE_NAME}" - Describe "test_notify_apprise" "container_test:true" "coverage:true" + Describe "test_notify_apprise" "coverage:true" TEST_NAME="test_notify_apprise" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -120,7 +120,7 @@ Describe 'notify' The stderr should satisfy spec_expect_message "${SEND_NOTIFY_APPRISE}" End End - Describe "test_notify_apprise_no_new_image" "container_test:true" "coverage:true" + Describe "test_notify_apprise_no_new_image" "coverage:true" TEST_NAME="test_notify_apprise_no_new_image" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -172,7 +172,7 @@ Describe 'notify' The stderr should satisfy spec_expect_message "${SEND_NOTIFY_APPRISE}" End End - Describe "test_notify_apprise_bad_url" "container_test:true" "coverage:true" + Describe "test_notify_apprise_bad_url" "coverage:true" TEST_NAME="test_notify_apprise_bad_url" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -217,7 +217,7 @@ Describe 'notify' The stderr should satisfy spec_expect_message "Failed to send notification via Apprise" End End - Describe "test_notify_on_change_new_image" "container_test:true" "coverage:true" + Describe "test_notify_on_change_new_image" "coverage:true" TEST_NAME="test_notify_on_change_new_image" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -269,7 +269,7 @@ Describe 'notify' The stderr should satisfy spec_expect_message "${SEND_NOTIFY_APPRISE}" End End - Describe "test_notify_on_change_no_updates" "container_test:true" "coverage:true" + Describe "test_notify_on_change_no_updates" "coverage:true" TEST_NAME="test_notify_on_change_no_updates" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -320,7 +320,7 @@ Describe 'notify' The stderr should satisfy spec_expect_message "${SKIP_SENDING_NOTIFICATION}" End End - Describe "test_notify_on_change_errors" "container_test:false" "coverage:true" + Describe "test_notify_on_change_errors" "coverage:true" TEST_NAME="test_notify_on_change_errors" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") diff --git a/tests/gantry_parallel_spec.sh b/tests/gantry_parallel_spec.sh index b1f77ab..08c4e78 100644 --- a/tests/gantry_parallel_spec.sh +++ b/tests/gantry_parallel_spec.sh @@ -19,7 +19,7 @@ Describe 'service-parallel' SUITE_NAME="service-parallel" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_parallel_less_workers" "container_test:true" "coverage:true" + Describe "test_parallel_less_workers" "coverage:true" TEST_NAME="test_parallel_less_workers" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -85,7 +85,7 @@ Describe 'service-parallel' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_parallel_more_workers" "container_test:true" "coverage:true" + Describe "test_parallel_more_workers" "coverage:true" TEST_NAME="test_parallel_more_workers" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -132,7 +132,7 @@ Describe 'service-parallel' 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" + Describe "test_parallel_GANTRY_MANIFEST_NUM_WORKERS_not_a_number" "coverage:true" TEST_NAME="test_parallel_GANTRY_MANIFEST_NUM_WORKERS_not_a_number" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -176,7 +176,7 @@ Describe 'service-parallel' 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" + Describe "test_parallel_GANTRY_UPDATE_NUM_WORKERS_not_a_number" "coverage:true" TEST_NAME="test_parallel_GANTRY_UPDATE_NUM_WORKERS_not_a_number" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") diff --git a/tests/gantry_rollback_spec.sh b/tests/gantry_rollback_spec.sh index 0e561bf..e16d6e9 100644 --- a/tests/gantry_rollback_spec.sh +++ b/tests/gantry_rollback_spec.sh @@ -19,7 +19,7 @@ Describe 'rollback' SUITE_NAME="rollback" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_rollback_due_to_timeout" "container_test:false" "coverage:true" + Describe "test_rollback_due_to_timeout" "coverage:true" TEST_NAME="test_rollback_due_to_timeout" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -68,7 +68,7 @@ Describe 'rollback' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_rollback_failed" "container_test:false" "coverage:true" + Describe "test_rollback_failed" "coverage:true" TEST_NAME="test_rollback_failed" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -120,7 +120,7 @@ Describe 'rollback' 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" + Describe "test_rollback_ROLLBACK_ON_FAILURE_false" "coverage:true" TEST_NAME="test_rollback_ROLLBACK_ON_FAILURE_false" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -170,7 +170,7 @@ Describe 'rollback' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_rollback_label_failed" "container_test:false" "coverage:true" + Describe "test_rollback_label_failed" "coverage:true" TEST_NAME="test_rollback_label_failed" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -225,7 +225,7 @@ Describe 'rollback' 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" + Describe "test_rollback_label_ROLLBACK_ON_FAILURE_false" "coverage:true" TEST_NAME="test_rollback_label_ROLLBACK_ON_FAILURE_false" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") diff --git a/tests/gantry_service_multiple_spec.sh b/tests/gantry_service_multiple_spec.sh index 1da1dfa..7df9ec0 100644 --- a/tests/gantry_service_multiple_spec.sh +++ b/tests/gantry_service_multiple_spec.sh @@ -19,7 +19,7 @@ Describe 'service-multiple-services' SUITE_NAME="service-multiple-services" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_multiple_services_excluded_filters" "container_test:true" "coverage:true" + Describe "test_multiple_services_excluded_filters" "coverage:true" TEST_NAME="test_multiple_services_excluded_filters" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") diff --git a/tests/gantry_service_no_running_tasks_spec.sh b/tests/gantry_service_no_running_tasks_spec.sh index f39be20..1298f5e 100644 --- a/tests/gantry_service_no_running_tasks_spec.sh +++ b/tests/gantry_service_no_running_tasks_spec.sh @@ -19,7 +19,7 @@ Describe "service-no-running-tasks" SUITE_NAME="service-no-running-tasks" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_no_running_tasks_replicated" "container_test:true" "coverage:true" + Describe "test_no_running_tasks_replicated" "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 @@ -99,7 +99,7 @@ Describe "service-no-running-tasks" The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_no_running_tasks_global" "container_test:true" "coverage:true" + Describe "test_no_running_tasks_global" "coverage:true" TEST_NAME="test_no_running_tasks_global" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") diff --git a/tests/gantry_service_single_spec.sh b/tests/gantry_service_single_spec.sh index 9daeb2b..9772cb4 100644 --- a/tests/gantry_service_single_spec.sh +++ b/tests/gantry_service_single_spec.sh @@ -19,7 +19,7 @@ Describe 'service-single-service' SUITE_NAME="service-single-service" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_new_image_no" "container_test:true" "coverage:true" + Describe "test_new_image_no" "coverage:true" TEST_NAME="test_new_image_no" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -41,6 +41,7 @@ Describe 'service-single-service' The stderr should satisfy spec_expect_message "${SKIP_UPDATING}.*${SERVICE_NAME}.*${SKIP_REASON_CURRENT_IS_LATEST}" The stderr should satisfy spec_expect_no_message "${PERFORM_UPDATING}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${SET_TIMEOUT_TO}" + The stderr should satisfy spec_expect_no_message "${RETURN_VALUE_INDICATES_TIMEOUT}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_INSPECT_FAILURE}" The stderr should satisfy spec_expect_message "${NUM_SERVICES_NO_NEW_IMAGES}" @@ -65,7 +66,7 @@ Describe 'service-single-service' The stderr should satisfy spec_expect_no_message "${SCHEDULE_NEXT_UPDATE_AT}" End End - Describe "test_new_image_yes" "container_test:true" "coverage:true" + Describe "test_new_image_yes" "coverage:true" TEST_NAME="test_new_image_yes" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -87,6 +88,7 @@ Describe 'service-single-service' 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 "${SET_TIMEOUT_TO}" + The stderr should satisfy spec_expect_no_message "${RETURN_VALUE_INDICATES_TIMEOUT}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_INSPECT_FAILURE}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_NO_NEW_IMAGES}" @@ -111,7 +113,7 @@ Describe 'service-single-service' The stderr should satisfy spec_expect_no_message "${SCHEDULE_NEXT_UPDATE_AT}" End End - Describe "test_new_image_no_digest" "container_test:true" "coverage:true" + Describe "test_new_image_no_digest" "coverage:true" TEST_NAME="test_new_image_no_digest" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -143,6 +145,7 @@ Describe 'service-single-service' 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_DIGEST_IS_EMPTY}" The stderr should satisfy spec_expect_no_message "${SET_TIMEOUT_TO}" + The stderr should satisfy spec_expect_no_message "${RETURN_VALUE_INDICATES_TIMEOUT}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_INSPECT_FAILURE}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_NO_NEW_IMAGES}" @@ -168,7 +171,7 @@ Describe 'service-single-service' The stderr should satisfy spec_expect_no_message "${SCHEDULE_NEXT_UPDATE_AT}" End End - Describe "test_new_image_SERVICES_SELF" "container_test:true" "coverage:true" + Describe "test_new_image_SERVICES_SELF" "coverage:true" TEST_NAME="test_new_image_SERVICES_SELF" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -192,6 +195,7 @@ Describe 'service-single-service' 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 "${SET_TIMEOUT_TO}" + The stderr should satisfy spec_expect_no_message "${RETURN_VALUE_INDICATES_TIMEOUT}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_INSPECT_FAILURE}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_NO_NEW_IMAGES}" diff --git a/tests/gantry_update_options_spec.sh b/tests/gantry_update_options_spec.sh index 8d97030..24dedda 100644 --- a/tests/gantry_update_options_spec.sh +++ b/tests/gantry_update_options_spec.sh @@ -25,7 +25,7 @@ Describe 'update-options' SUITE_NAME="update-options" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_update_UPDATE_OPTIONS" "container_test:true" "coverage:true" + Describe "test_update_UPDATE_OPTIONS" "coverage:true" TEST_NAME="test_update_UPDATE_OPTIONS" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -81,7 +81,7 @@ Describe 'update-options' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_update_label_UPDATE_OPTIONS" "container_test:true" "coverage:true" + Describe "test_update_label_UPDATE_OPTIONS" "coverage:true" TEST_NAME="test_update_label_UPDATE_OPTIONS" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -140,7 +140,7 @@ Describe 'update-options' 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" + Describe "test_update_UPDATE_TIMEOUT_SECONDS_not_a_number" "coverage:true" TEST_NAME="test_update_UPDATE_TIMEOUT_SECONDS_not_a_number" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -185,7 +185,7 @@ Describe 'update-options' 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" + Describe "test_update_lable_UPDATE_TIMEOUT_SECONDS" "coverage:true" TEST_NAME="test_update_lable_UPDATE_TIMEOUT_SECONDS" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") diff --git a/tests/spec_gantry_test_helper.sh b/tests/spec_gantry_test_helper.sh index 0d4be29..21a1dd1 100644 --- a/tests/spec_gantry_test_helper.sh +++ b/tests/spec_gantry_test_helper.sh @@ -15,8 +15,6 @@ # along with this program. If not, see . # -set -a - # Constant strings for checks. # START_WITHOUT_A_SQUARE_BRACKET ignores color codes. Use test_log not to trigger this check. export START_WITHOUT_A_SQUARE_BRACKET="^(?!(?:\x1b\[[0-9;]*[mG])?\[)" @@ -46,7 +44,7 @@ export USER_LOGGED_INTO_DEFAULT="User logged in using the default Docker configu export ADDING_OPTIONS="Adding options" export ADDING_OPTIONS_WITH_REGISTRY_AUTH="Adding options.*--with-registry-auth" export SET_TIMEOUT_TO="Set timeout to" -export RETURN_VALUE_INDICATES_TIMEOUT="The return value 124 indicates the job timed out." +export RETURN_VALUE_INDICATES_TIMEOUT="The return value [0-9]+ indicates the job timed out." export THERE_ARE_ADDITIONAL_MESSAGES="There are additional messages from updating" export NUM_SERVICES_SKIP_JOBS="Skip updating [0-9]+ service\(s\) due to they are job\(s\)" export NUM_SERVICES_INSPECT_FAILURE="Failed to inspect [0-9]+ service\(s\)" @@ -76,6 +74,8 @@ export TEST_SERVICE_IMAGE="alpine:latest" test_log() { echo "${GANTRY_LOG_LEVEL}" | grep -q -i "^NONE$" && return 0; + echo "${GANTRY_LOG_LEVEL}" | grep -q -i "^ERROR$" && return 0; + echo "${GANTRY_LOG_LEVEL}" | grep -q -i "^WARN$" && return 0; [ -n "${GANTRY_IMAGES_TO_REMOVE}" ] && echo "${*}" >&2 && return 0; echo "[$(date -Iseconds)] Test: ${*}" >&2 } @@ -144,14 +144,14 @@ common_setup_timeout() { local IMAGE_WITH_TAG="${2}" local SERVICE_NAME="${3}" local TIMEOUT="${4}" - local TIMEOUT_PLUS_ONE=$((TIMEOUT+1)) - local TIMEOUT_PLUS_TWO=$((TIMEOUT+2)) + local TIMEOUT_PLUS=$((TIMEOUT+1)) + local TIMEOUT_MORE=$((TIMEOUT+2)) initialize_test "${TEST_NAME}" # -1 thus the task runs forever. # exit will take longer than the timeout. - build_and_push_test_image "${IMAGE_WITH_TAG}" "-1" "${TIMEOUT_PLUS_TWO}" + build_and_push_test_image "${IMAGE_WITH_TAG}" "-1" "${TIMEOUT_MORE}" # Timeout set by "service create" should be smaller than the exit time above. - start_replicated_service "${SERVICE_NAME}" "${IMAGE_WITH_TAG}" "${TIMEOUT_PLUS_ONE}" + start_replicated_service "${SERVICE_NAME}" "${IMAGE_WITH_TAG}" "${TIMEOUT_PLUS}" build_and_push_test_image "${IMAGE_WITH_TAG}" } @@ -420,8 +420,9 @@ initialize_test() { reset_gantry_env() { local SERVICE_NAME="${1}" - export DOCKER_CONFIG= - export DOCKER_HOST= + export GANTRY_TEST_HOST_TO_CONTAINER= + export GANTRY_TEST_DOCKER_CONFIG= + export GANTRY_TEST_DOCKER_HOST= export GANTRY_LOG_LEVEL="DEBUG" export GANTRY_NODE_NAME= export GANTRY_POST_RUN_CMD= @@ -622,7 +623,7 @@ wait_zero_running_tasks() { # 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 # We do an extra step to to perform the exact match. - REPLICAS=$(echo "${REPLICAS}" | sed -n "s/\(.*\) ${SERVICE_NAME}$/\1/p") + REPLICAS=$(echo "${REPLICAS}" | sed -n -E "s/(.*) ${SERVICE_NAME}$/\1/p") if [ "${TRIES}" -ge "${MAX_RETRIES}" ]; then echo "wait_zero_running_tasks Reach MAX_RETRIES ${MAX_RETRIES}" >&2 return 1 @@ -665,7 +666,7 @@ pull_image_if_not_exist() { _enforce_login_enabled() { local ENFORCE_LOGIN="${1}" - test "${ENFORCE_LOGIN}" == "ENFORCE_LOGIN" + test "${ENFORCE_LOGIN}" = "ENFORCE_LOGIN" } _add_htpasswd() { @@ -688,21 +689,13 @@ _add_htpasswd() { } _wait_service_state() { - local SERVICE_NAME="${1}" - local STATE="${2}" - local TRIES=0 - local MAX_RETRIES=120 - while ! docker service ps --format "{{.CurrentState}}" "${SERVICE_NAME}" | grep -q "${STATE}"; do - if [ "${TRIES}" -ge "${MAX_RETRIES}" ]; then - echo "_wait_service_state Reach MAX_RETRIES ${MAX_RETRIES}" >&2 - return 1 - fi - TRIES=$((TRIES+1)) - sleep 1 - done + local SERVICE_NAME="${1}"; + local WANT_STATE="${2}"; + local TIMEOUT_SECONDS="${3}"; + wait_service_state "${SERVICE_NAME}" "${WANT_STATE}" "${TIMEOUT_SECONDS}" 1>/dev/null 2>&1 } -_correct_test_service_name() { +_sanitize_test_service_name() { local SERVICE_NAME="${1}" [ "${#SERVICE_NAME}" -gt 63 ] && SERVICE_NAME=${SERVICE_NAME:0:63} echo "${SERVICE_NAME}" @@ -724,7 +717,7 @@ start_replicated_service() { local SERVICE_NAME="${1}" local IMAGE_WITH_TAG="${2}" local TIMEOUT_SECONDS="${3:-1}" - SERVICE_NAME=$(_correct_test_service_name "${SERVICE_NAME}") + SERVICE_NAME=$(_sanitize_test_service_name "${SERVICE_NAME}") echo "Creating service ${SERVICE_NAME} in replicated mode " # During creation: # * Add --detach to reduce the test runtime. @@ -746,8 +739,8 @@ start_replicated_service() { $(_location_constraints) \ --mode=replicated \ --detach=true \ - "${IMAGE_WITH_TAG}" - _wait_service_state "${SERVICE_NAME}" "Running" + "${IMAGE_WITH_TAG}"; + _wait_service_state "${SERVICE_NAME}" "Running" 120 } start_multiple_replicated_services() { @@ -771,7 +764,7 @@ start_global_service() { local SERVICE_NAME="${1}" local IMAGE_WITH_TAG="${2}" local TIMEOUT_SECONDS="${3:-1}" - SERVICE_NAME=$(_correct_test_service_name "${SERVICE_NAME}") + SERVICE_NAME=$(_sanitize_test_service_name "${SERVICE_NAME}") echo "Creating service ${SERVICE_NAME} in global mode " # Do not add --detach, because we want to wait for the job finishes. # SC2046 (warning): Quote this to prevent word splitting. @@ -794,7 +787,7 @@ _start_replicated_job() { local IMAGE_WITH_TAG="${2}" local TASK_SECONDS="${3:-1}" local EXIT_SECONDS="${4:-1}" - SERVICE_NAME=$(_correct_test_service_name "${SERVICE_NAME}") + SERVICE_NAME=$(_sanitize_test_service_name "${SERVICE_NAME}") echo "Creating service ${SERVICE_NAME} in replicated job mode " # Always add --detach=true, do not wait for the job finishes. # SC2046 (warning): Quote this to prevent word splitting. @@ -808,9 +801,9 @@ _start_replicated_job() { $(_location_constraints) \ --mode=replicated-job \ --detach=true \ - "${IMAGE_WITH_TAG}" + "${IMAGE_WITH_TAG}"; # wait until the job is running - _wait_service_state "${SERVICE_NAME}" "Running" + _wait_service_state "${SERVICE_NAME}" "Running" 120 } stop_service() { @@ -867,6 +860,15 @@ _get_entrypoint() { echo "source ${STATIC_VAR_ENTRYPOINT}" } +_get_file_readonly() { + local NAME="${1}" + if [ -w "${NAME}" ]; then + echo "false" + else + echo "true" + fi +} + _add_file_to_mount_options() { local MOUNT_OPTIONS="${1}" local HOST_PATH="${2}" @@ -874,40 +876,63 @@ _add_file_to_mount_options() { # Use the absolute path inside the container. local TARGET= TARGET=$(readlink -f "${HOST_PATH}") - MOUNT_OPTIONS="${MOUNT_OPTIONS} --mount type=bind,source=${HOST_PATH},target=${TARGET}" + local READONLY= + READONLY=$(_get_file_readonly "${HOST_PATH}") + MOUNT_OPTIONS="${MOUNT_OPTIONS} --mount type=bind,source=${HOST_PATH},target=${TARGET},readonly=${READONLY}" fi echo "${MOUNT_OPTIONS}" } -_run_gantry_container() { +stop_gantry_container() { local STACK="${1}" local SUT_REPO_TAG= SUT_REPO_TAG="$(_get_sut_image)" if [ -z "${SUT_REPO_TAG}" ]; then - return 1 + return 0; fi + local RETURN_VALUE=0 local SERVICE_NAME= - SERVICE_NAME="gantry-test-SUT-$(unique_id)" + SERVICE_NAME="gantry-test-SUT-${STACK}" + SERVICE_NAME=$(_sanitize_test_service_name "${SERVICE_NAME}") + local CMD_OUTPUT= + docker service logs --raw "${SERVICE_NAME}" + if ! CMD_OUTPUT=$(docker service rm "${SERVICE_NAME}" 2>&1); then + echo "Failed to remove service ${SERVICE_NAME}: ${CMD_OUTPUT}" >&2 + RETURN_VALUE=1 + fi + return "${RETURN_VALUE}" +} + +_run_gantry_container() { + local STACK="${1}" + local SUT_REPO_TAG="${2}" + pull_image_if_not_exist "${SUT_REPO_TAG}" + local SERVICE_NAME= + SERVICE_NAME="gantry-test-SUT-${STACK}" + SERVICE_NAME=$(_sanitize_test_service_name "${SERVICE_NAME}") docker service rm "${SERVICE_NAME}" >/dev/null 2>&1; local MOUNT_OPTIONS= - MOUNT_OPTIONS=$(_add_file_to_mount_options "${MOUNT_OPTIONS}" "${DOCKER_CONFIG}") + MOUNT_OPTIONS=$(_add_file_to_mount_options "${MOUNT_OPTIONS}" "${GANTRY_TEST_HOST_TO_CONTAINER}") + MOUNT_OPTIONS=$(_add_file_to_mount_options "${MOUNT_OPTIONS}" "${GANTRY_TEST_DOCKER_CONFIG}") MOUNT_OPTIONS=$(_add_file_to_mount_options "${MOUNT_OPTIONS}" "${GANTRY_REGISTRY_CONFIG_FILE}") MOUNT_OPTIONS=$(_add_file_to_mount_options "${MOUNT_OPTIONS}" "${GANTRY_REGISTRY_CONFIGS_FILE}") MOUNT_OPTIONS=$(_add_file_to_mount_options "${MOUNT_OPTIONS}" "${GANTRY_REGISTRY_HOST_FILE}") MOUNT_OPTIONS=$(_add_file_to_mount_options "${MOUNT_OPTIONS}" "${GANTRY_REGISTRY_PASSWORD_FILE}") MOUNT_OPTIONS=$(_add_file_to_mount_options "${MOUNT_OPTIONS}" "${GANTRY_REGISTRY_USER_FILE}") test_log "Starting SUT service ${SERVICE_NAME} with image ${SUT_REPO_TAG}." + test_log "MOUNT_OPTIONS=${MOUNT_OPTIONS}" local RETURN_VALUE=0 local CMD_OUTPUT= # SC2086 (info): Double quote to prevent globbing and word splitting. # shellcheck disable=SC2086 if ! CMD_OUTPUT=$(docker service create --name "${SERVICE_NAME}" \ + --detach=true \ --mode replicated-job --restart-condition=none --network host \ --constraint "node.role==manager" \ --mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \ ${MOUNT_OPTIONS} \ - --env "DOCKER_CONFIG=${DOCKER_CONFIG}" \ - --env "DOCKER_HOST=${DOCKER_HOST}" \ + --env "DOCKER_CONFIG=${GANTRY_TEST_DOCKER_CONFIG}" \ + --env "DOCKER_HOST=${GANTRY_TEST_DOCKER_HOST}" \ --env "GANTRY_LOG_LEVEL=${GANTRY_LOG_LEVEL}" \ --env "GANTRY_NODE_NAME=${GANTRY_NODE_NAME}" \ --env "GANTRY_POST_RUN_CMD=${GANTRY_POST_RUN_CMD}" \ @@ -948,22 +973,53 @@ _run_gantry_container() { echo "Failed to create service ${SERVICE_NAME}: ${CMD_OUTPUT}" >&2 RETURN_VALUE=1 fi - docker service logs --raw "${SERVICE_NAME}" - if ! CMD_OUTPUT=$(docker service rm "${SERVICE_NAME}" 2>&1); then - echo "Failed to remove service ${SERVICE_NAME}: ${CMD_OUTPUT}" >&2 - RETURN_VALUE=1 - fi + _wait_service_state "${SERVICE_NAME}" "Complete" 120 + RETURN_VALUE=$? + stop_gantry_container "${STACK}" || return 1 return "${RETURN_VALUE}" } +_restore_env() { + local ENV_NAME="${1}" + local ENV_SET="${2}" + local ENV_VALUE="${3}" + if [ "${ENV_SET}" = "1" ]; then + eval "export ${ENV_NAME}=\"${ENV_VALUE}\"" + else + unset "${ENV_NAME}" + fi +} + run_gantry() { local STACK="${1}" - if _run_gantry_container "${STACK}"; then - return 0 + local DOCKER_CONFIG_SET=0 + local OLD_DOCKER_CONFIG= + local DOCKER_HOST_SET=0 + local OLD_DOCKER_HOST= + if env | grep_q "^DOCKER_CONFIG="; then + DOCKER_CONFIG_SET=1 + OLD_DOCKER_CONFIG="${DOCKER_CONFIG}" + fi + if env | grep_q "^DOCKER_HOST="; then + DOCKER_HOST_SET=1 + OLD_DOCKER_HOST="${DOCKER_HOST}" fi - local ENTRYPOINT= - ENTRYPOINT=$(_get_entrypoint) || return 1 - ${ENTRYPOINT} "${STACK}" + local RETURN_VALUE=1 + local SUT_REPO_TAG= + SUT_REPO_TAG="$(_get_sut_image)" + if [ -n "${SUT_REPO_TAG}" ]; then + _run_gantry_container "${STACK}" "${SUT_REPO_TAG}" + RETURN_VALUE=$? + else + [ -n "${GANTRY_TEST_DOCKER_CONFIG}" ] && export DOCKER_CONFIG="${GANTRY_TEST_DOCKER_CONFIG}" + [ -n "${GANTRY_TEST_DOCKER_HOST}" ] && export DOCKER_HOST="${GANTRY_TEST_DOCKER_HOST}" + local ENTRYPOINT= + if ENTRYPOINT=$(_get_entrypoint); then + ${ENTRYPOINT} "${STACK}" + RETURN_VALUE=$? + fi + fi + _restore_env "DOCKER_CONFIG" "${DOCKER_CONFIG_SET}" "${OLD_DOCKER_CONFIG}" + _restore_env "DOCKER_HOST" "${DOCKER_HOST_SET}" "${OLD_DOCKER_HOST}" + return "${RETURN_VALUE}" } - -set +a