From 0ac0a6df7bea2be534898030136dc6b8378f4085 Mon Sep 17 00:00:00 2001 From: Shizun Ge Date: Sun, 18 Feb 2024 08:39:49 -0800 Subject: [PATCH] [tests] update checks for ADDING_OPTIONS. fix using subprocess variables in login tests. --- src/lib-gantry.sh | 2 +- tests/gantry_cleanup_images_spec.sh | 4 +- tests/gantry_login_spec.sh | 51 +++++++++++-------- tests/gantry_manifest_spec.sh | 6 +-- tests/gantry_rollback_spec.sh | 2 +- tests/gantry_service_no_running_tasks_spec.sh | 6 +-- tests/gantry_update_options_spec.sh | 6 +-- 7 files changed, 42 insertions(+), 35 deletions(-) diff --git a/src/lib-gantry.sh b/src/lib-gantry.sh index 1562f32..8bd8473 100755 --- a/src/lib-gantry.sh +++ b/src/lib-gantry.sh @@ -651,7 +651,7 @@ _inspect_image() { fi local DOCKER_CONFIG= DOCKER_CONFIG=$(_get_config_from_service "${SERVICE}") - [ -n "${DOCKER_CONFIG}" ] && log DEBUG "Adding options \"${DOCKER_CONFIG}\" to docker commands." + [ -n "${DOCKER_CONFIG}" ] && log DEBUG "Adding options \"${DOCKER_CONFIG}\" to docker commands for ${SERVICE_NAME}." local IMAGE_INFO= if ! IMAGE_INFO=$(_get_image_info "${MANIFEST_CMD}" "${IMAGE}" "${DOCKER_CONFIG}"); then log DEBUG "Skip updating ${SERVICE_NAME} because there is a failure to obtain the manifest from the registry of image ${IMAGE}." diff --git a/tests/gantry_cleanup_images_spec.sh b/tests/gantry_cleanup_images_spec.sh index 2915dcf..a7a1a32 100644 --- a/tests/gantry_cleanup_images_spec.sh +++ b/tests/gantry_cleanup_images_spec.sh @@ -98,7 +98,7 @@ Describe 'cleanup-images' The stderr should satisfy spec_expect_no_message "${NO_IMAGES_TO_REMOVE}" The stderr should satisfy spec_expect_message "${REMOVING_NUM_IMAGES}" The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" - The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--incorrect-option" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--incorrect-option.*" 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}" @@ -141,7 +141,7 @@ Describe 'cleanup-images' The stderr should satisfy spec_expect_no_message "${NO_IMAGES_TO_REMOVE}" The stderr should satisfy spec_expect_message "${REMOVING_NUM_IMAGES}" The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" - The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--container-label=test" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--container-label=test.*" 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}" diff --git a/tests/gantry_login_spec.sh b/tests/gantry_login_spec.sh index 9002fbd..6e1341a 100644 --- a/tests/gantry_login_spec.sh +++ b/tests/gantry_login_spec.sh @@ -24,19 +24,21 @@ Describe 'login' TEST_NAME="test_login_config" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" + CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_config() { local TEST_NAME=${1} local SERVICE_NAME=${2} - local REGISTRY=${3} - local USERNAME=${4} - local PASSWORD=${5} + local CONFIG=${3} + local REGISTRY=${4} + local USERNAME=${5} + local PASSWORD=${6} if [ -z "${REGISTRY}" ] || [ -z "${USERNAME}" ] || [ -z "${PASSWORD}" ]; then echo "No REGISTRY, USERNAME or PASSWORD provided." >&2 return 1 fi local LABEL="gantry.auth.config" - CONFIG="C$(unique_id)" + local USER_FILE PASS_FILE USER_FILE=$(mktemp) PASS_FILE=$(mktemp) docker service update --quiet --label-add "${LABEL}=${CONFIG}" "${SERVICE_NAME}" @@ -58,7 +60,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_config "${TEST_NAME}" "${SERVICE_NAME}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_config "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be success The stdout should satisfy display_output The stderr should satisfy display_output @@ -69,7 +71,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}" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config ${CONFIG}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_message "${UPDATED}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${NO_UPDATES}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${ROLLING_BACK}.*${SERVICE_NAME}" @@ -90,19 +92,21 @@ Describe 'login' TEST_NAME="test_login_REGISTRY_CONFIGS_FILE" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" + CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_REGISTRY_CONFIGS_FILE() { local TEST_NAME=${1} local SERVICE_NAME=${2} - local REGISTRY=${3} - local USERNAME=${4} - local PASSWORD=${5} + local CONFIG=${3} + local REGISTRY=${4} + local USERNAME=${5} + local PASSWORD=${6} if [ -z "${REGISTRY}" ] || [ -z "${USERNAME}" ] || [ -z "${PASSWORD}" ]; then echo "No REGISTRY, USERNAME or PASSWORD provided." >&2 return 1 fi local LABEL="gantry.auth.config" - CONFIG="C$(unique_id)" + local CONFIGS_FILE= CONFIGS_FILE=$(mktemp) docker service update --quiet --label-add "${LABEL}=${CONFIG}" "${SERVICE_NAME}" echo "# Test comments: CONFIG REGISTRY USERNAME PASSWORD" >> "${CONFIGS_FILE}" @@ -126,7 +130,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_REGISTRY_CONFIGS_FILE "${TEST_NAME}" "${SERVICE_NAME}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_REGISTRY_CONFIGS_FILE "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be success The stdout should satisfy display_output The stderr should satisfy display_output @@ -137,7 +141,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}" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config ${CONFIG}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_message "${UPDATED}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${NO_UPDATES}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${ROLLING_BACK}.*${SERVICE_NAME}" @@ -158,19 +162,21 @@ Describe 'login' TEST_NAME="test_login_REGISTRY_CONFIGS_FILE_bad_format" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" + CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_REGISTRY_CONFIGS_FILE_bad_format() { local TEST_NAME=${1} local SERVICE_NAME=${2} - local REGISTRY=${3} - local USERNAME=${4} - local PASSWORD=${5} + local CONFIG=${3} + local REGISTRY=${4} + local USERNAME=${5} + local PASSWORD=${6} if [ -z "${REGISTRY}" ] || [ -z "${USERNAME}" ] || [ -z "${PASSWORD}" ]; then echo "No REGISTRY, USERNAME or PASSWORD provided." >&2 return 1 fi local LABEL="gantry.auth.config" - CONFIG="C$(unique_id)" + local CONFIGS_FILE= CONFIGS_FILE=$(mktemp) docker service update --quiet --label-add "${LABEL}=${CONFIG}" "${SERVICE_NAME}" # Add an extra item to the line. @@ -189,7 +195,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_REGISTRY_CONFIGS_FILE_bad_format "${TEST_NAME}" "${SERVICE_NAME}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_REGISTRY_CONFIGS_FILE_bad_format "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be failure The stdout should satisfy display_output The stderr should satisfy display_output @@ -224,19 +230,20 @@ Describe 'login' TEST_NAME="test_login_file_not_exist" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME="gantry-test-$(unique_id)" + CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_file_not_exist() { local TEST_NAME=${1} local SERVICE_NAME=${2} - local REGISTRY=${3} - local USERNAME=${4} - local PASSWORD=${5} + local CONFIG=${3} + local REGISTRY=${4} + local USERNAME=${5} + local PASSWORD=${6} if [ -z "${REGISTRY}" ] || [ -z "${USERNAME}" ] || [ -z "${PASSWORD}" ]; then echo "No REGISTRY, USERNAME or PASSWORD provided." >&2 return 1 fi local LABEL="gantry.auth.config" - CONFIG="C$(unique_id)" docker service update --quiet --label-add "${LABEL}=${CONFIG}" "${SERVICE_NAME}" local FILE_NOT_EXIST="/tmp/${CONFIG}" reset_gantry_env "${SERVICE_NAME}" @@ -254,7 +261,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_file_not_exist "${TEST_NAME}" "${SERVICE_NAME}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_file_not_exist "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be failure The stdout should satisfy display_output The stderr should satisfy display_output diff --git a/tests/gantry_manifest_spec.sh b/tests/gantry_manifest_spec.sh index a97b7a7..8dde54b 100644 --- a/tests/gantry_manifest_spec.sh +++ b/tests/gantry_manifest_spec.sh @@ -50,7 +50,7 @@ Describe 'manifest-command' 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}.*--force" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--force.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${UPDATED}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_message "${NO_UPDATES}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${ROLLING_BACK}.*${SERVICE_NAME}" @@ -130,7 +130,7 @@ Describe 'manifest-command' The status should be success The stdout should satisfy display_output The stderr should satisfy display_output - The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--insecure" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--insecure.*" 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}" @@ -173,7 +173,7 @@ Describe 'manifest-command' The stdout should satisfy display_output The stderr should satisfy display_output # No options are added to the unknwon command. - The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--insecure" + The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--insecure.*" The stderr should satisfy spec_expect_message "Unknown MANIFEST_CMD.*unsupported_cmd" 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}" diff --git a/tests/gantry_rollback_spec.sh b/tests/gantry_rollback_spec.sh index f7adc0a..fe6f3b0 100644 --- a/tests/gantry_rollback_spec.sh +++ b/tests/gantry_rollback_spec.sh @@ -93,7 +93,7 @@ Describe 'rollback' The stderr should satisfy spec_expect_message "${NUM_SERVICES_UPDATING}" The stderr should satisfy spec_expect_no_message "${UPDATED}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${NO_UPDATES}.*${SERVICE_NAME}" - The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--incorrect-option" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--incorrect-option.*${SERVICE_NAME}" The stderr should satisfy spec_expect_message "${ROLLING_BACK}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_message "${FAILED_TO_ROLLBACK}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${ROLLED_BACK}.*${SERVICE_NAME}" diff --git a/tests/gantry_service_no_running_tasks_spec.sh b/tests/gantry_service_no_running_tasks_spec.sh index c34a895..3fb9ad9 100644 --- a/tests/gantry_service_no_running_tasks_spec.sh +++ b/tests/gantry_service_no_running_tasks_spec.sh @@ -71,8 +71,8 @@ Describe "service-no-running-tasks" # https://github.com/docker/cli/issues/627 The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--detach=true.*${SERVICE_NAME}\." The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--replicas=0.*${SERVICE_NAME}\." - The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--detach=true.*${SERVICE_NAME_SUFFIX}\." - The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--replicas=0.*${SERVICE_NAME_SUFFIX}\." + The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--detach=true.*${SERVICE_NAME_SUFFIX}" + The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--replicas=0.*${SERVICE_NAME_SUFFIX}" 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 "${SKIP_UPDATING}.*${SERVICE_NAME_SUFFIX}" @@ -129,7 +129,7 @@ Describe "service-no-running-tasks" The stderr should satisfy display_output # Add "--detach=true" when there is no running tasks. # https://github.com/docker/cli/issues/627 - The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--detach=true" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--detach=true.*${SERVICE_NAME}" # Cannot add "--replicas" to global mode The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--replicas=0" The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME}" diff --git a/tests/gantry_update_options_spec.sh b/tests/gantry_update_options_spec.sh index 5b147af..05f3689 100644 --- a/tests/gantry_update_options_spec.sh +++ b/tests/gantry_update_options_spec.sh @@ -108,7 +108,7 @@ Describe 'update-options' 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}.*--detach=true" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--detach=true.*${SERVICE_NAME}" The stderr should satisfy spec_expect_message "${UPDATED}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${NO_UPDATES}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${ROLLING_BACK}.*${SERVICE_NAME}" @@ -148,7 +148,7 @@ Describe 'update-options' The status should be success The stdout should satisfy display_output The stderr should satisfy display_output - The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--detach=true" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--detach=true.*${SERVICE_NAME}" # Cannot add "--replicas" to replicated job The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--replicas=0" The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME}" @@ -214,7 +214,7 @@ Describe 'update-options' 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}.*--label-add=gantry.test=${SERVICE_NAME}" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--label-add=gantry.test=${SERVICE_NAME}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_message "${UPDATED}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${NO_UPDATES}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${ROLLING_BACK}.*${SERVICE_NAME}"