From 0c56a44a42ead3cea1aed86319a36db36a012d3d Mon Sep 17 00:00:00 2001 From: Shizun Ge Date: Wed, 17 Jan 2024 23:38:10 -0800 Subject: [PATCH] update options to PRE_RUN_CMD and POST_RUN_CMD --- src/entrypoint.sh | 30 ++++++++++++++++-------------- tests/lib-gantry-test.sh | 2 ++ tests/run_all_tests.sh | 2 +- tests/test_entrypoint.sh | 6 +++--- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/entrypoint.sh b/src/entrypoint.sh index 8a51d4e..27b7ef0 100755 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -50,24 +50,26 @@ skip_current_node() { return 1 } -run_pre_update_cmd() { - local CMD RT - CMD=${GANTRY_PRE_UPDATE_CMD:-""} +exec_pre_run_cmd() { + local CMD RT LOG + CMD=${GANTRY_PRE_RUN_CMD:-""} [ -z "${CMD}" ] && return 0 - log INFO "Run pre update command: ${CMD}" - eval "${CMD}" + log INFO "Run pre-run command: ${CMD}" + LOG=$(eval "${CMD}") RT=$? - log INFO "Finish pre update command. Return value ${RT}." + log_lines INFO ${LOG} + log INFO "Finish pre-run command. Return value ${RT}." } -run_post_update_cmd() { - local CMD RT - CMD=${GANTRY_POST_UPDATE_CMD:-""} +exec_post_run_cmd() { + local CMD RT LOG + CMD=${GANTRY_POST_RUN_CMD:-""} [ -z "${CMD}" ] && return 0 - log INFO "Run post update command: ${CMD}" - eval "${CMD}" + log INFO "Run post-run command: ${CMD}" + LOG=$(eval "${CMD}") RT=$? - log INFO "Finish post update command. Return value ${RT}." + log_lines INFO ${LOG} + log INFO "Finish post-run command. Return value ${RT}." } gantry() { @@ -84,7 +86,7 @@ gantry() { local DOCKER_HUB_RATE_USED= local TIME_ELAPSED= - run_pre_update_cmd + exec_pre_run_cmd log INFO "Starting." gantry_initialize "${STACK}" @@ -118,7 +120,7 @@ gantry() { log INFO "${MESSAGE}" fi - run_post_update_cmd + exec_post_run_cmd return ${ACCUMULATED_ERRORS} } diff --git a/tests/lib-gantry-test.sh b/tests/lib-gantry-test.sh index 6ef7cff..aa13197 100755 --- a/tests/lib-gantry-test.sh +++ b/tests/lib-gantry-test.sh @@ -334,6 +334,8 @@ run_gantry_container() { --env "GANTRY_SERVICES_SELF=${GANTRY_SERVICES_SELF}" \ --env "GANTRY_MANIFEST_CMD=${GANTRY_MANIFEST_CMD}" \ --env "GANTRY_MANIFEST_OPTIONS=${GANTRY_MANIFEST_OPTIONS}" \ + --env "GANTRY_PRE_RUN_CMD=${GANTRY_PRE_RUN_CMD}" \ + --env "GANTRY_POST_RUN_CMD=${GANTRY_POST_RUN_CMD}" \ --env "GANTRY_ROLLBACK_ON_FAILURE=${GANTRY_ROLLBACK_ON_FAILURE}" \ --env "GANTRY_ROLLBACK_OPTIONS=${GANTRY_ROLLBACK_OPTIONS}" \ --env "GANTRY_UPDATE_JOBS=${GANTRY_UPDATE_JOBS}" \ diff --git a/tests/run_all_tests.sh b/tests/run_all_tests.sh index f2f56c7..051a9a9 100755 --- a/tests/run_all_tests.sh +++ b/tests/run_all_tests.sh @@ -102,7 +102,7 @@ main() { test_options_LOG_LEVEL_none \ test_options_UPDATE_OPTIONS \ test_options_CLEANUP_IMAGES_false \ - test_options_PRE_POST_UPDATE_CMD \ + test_options_PRE_POST_RUN_CMD \ " local LOGIN_TESTS="\ test_login_config \ diff --git a/tests/test_entrypoint.sh b/tests/test_entrypoint.sh index 4df7eb7..9b8e66b 100755 --- a/tests/test_entrypoint.sh +++ b/tests/test_entrypoint.sh @@ -866,7 +866,7 @@ test_options_CLEANUP_IMAGES_false() { finalize_test "${FUNCNAME[0]}" } -test_options_PRE_POST_UPDATE_CMD() { +test_options_PRE_POST_RUN_CMD() { local IMAGE_WITH_TAG="${1}" local SERVICE_NAME STDOUT SERVICE_NAME="gantry-test-$(unique_id)" @@ -876,8 +876,8 @@ test_options_PRE_POST_UPDATE_CMD() { start_replicated_service "${SERVICE_NAME}" "${IMAGE_WITH_TAG}" export GANTRY_SERVICES_FILTERS="name=${SERVICE_NAME}" - export GANTRY_PRE_UPDATE_CMD="echo \"Pre update\"" - export GANTRY_POST_UPDATE_CMD="echo \"Post update\"" + export GANTRY_PRE_RUN_CMD="echo \"Pre update\"" + export GANTRY_POST_RUN_CMD="echo \"Post update\"" STDOUT=$(run_gantry "${FUNCNAME[0]}" 2>&1 | tee >(cat 1>&2)) expect_message "${STDOUT}" "Pre update"