From 218cc963535efd4aaaad3dabdcb470b5c200d7c0 Mon Sep 17 00:00:00 2001 From: Carson Ip Date: Tue, 4 Jun 2024 11:32:03 +0100 Subject: [PATCH] Test SNAPSHOT in smoketests (#13147) Support "latest" in lagacy-managed and legacy-standalone-major-managed by testing snapshots. --- testing/smoke/legacy-managed/test.sh | 17 ++++++++---- .../legacy-standalone-major-managed/test.sh | 26 ++++++++++++++----- testing/smoke/lib.sh | 11 +++++++- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/testing/smoke/legacy-managed/test.sh b/testing/smoke/legacy-managed/test.sh index 5d28b7b49e6..3317bac0fba 100755 --- a/testing/smoke/legacy-managed/test.sh +++ b/testing/smoke/legacy-managed/test.sh @@ -2,7 +2,7 @@ set -eo pipefail -if [[ "${1}" != "7.17" ]]; then +if [[ "${1}" != "7.17" && "${1}" != "latest" ]]; then echo "-> Skipping smoke test ['${1}' is not supported]..." exit 0 fi @@ -11,8 +11,15 @@ fi VERSION=7.17 get_versions -get_latest_patch ${VERSION} -LATEST_VERSION=${VERSION}.${LATEST_PATCH} +if [[ "${1}" == "latest" ]]; then + get_latest_snapshot_for_version ${VERSION} + LATEST_VERSION=${LATEST_SNAPSHOT_VERSION} + ASSERTION_VERSION=${LATEST_SNAPSHOT_VERSION%-*} # strip -SNAPSHOT suffix +else + get_latest_patch ${VERSION} + LATEST_VERSION=${VERSION}.${LATEST_PATCH} + ASSERTION_VERSION=${LATEST_VERSION} +fi echo "-> Running ${LATEST_VERSION} standalone to ${LATEST_VERSION} managed upgrade" @@ -27,10 +34,10 @@ append_tfvar "integrations_server" ${INTEGRATIONS_SERVER} terraform_apply healthcheck 1 send_events -legacy_assertions ${LATEST_VERSION} +legacy_assertions ${ASSERTION_VERSION} echo "-> Upgrading APM Server to managed mode" upgrade_managed ${LATEST_VERSION} ${INTEGRATIONS_SERVER} healthcheck 1 send_events -data_stream_assertions ${LATEST_VERSION} +data_stream_assertions ${ASSERTION_VERSION} diff --git a/testing/smoke/legacy-standalone-major-managed/test.sh b/testing/smoke/legacy-standalone-major-managed/test.sh index e641441f3af..c22c1cd1ecd 100755 --- a/testing/smoke/legacy-standalone-major-managed/test.sh +++ b/testing/smoke/legacy-standalone-major-managed/test.sh @@ -2,7 +2,7 @@ set -eo pipefail -if [[ "${1}" != "7.17" ]]; then +if [[ "${1}" != "7.17" && "${1}" != "latest" ]]; then echo "-> Skipping smoke test ['${1}' is not supported]..." exit 0 fi @@ -11,9 +11,21 @@ fi VERSION=7.17 get_versions -get_latest_patch ${VERSION} -LATEST_VERSION=${VERSION}.${LATEST_PATCH} -NEXT_MAJOR_LATEST=$(echo ${VERSIONS} | jq -r '[.[] | select(. | startswith("8"))] | last') +if [[ "${1}" == "latest" ]]; then + # a SNAPSHOT version can only be upgraded to another SNAPSHOT version + get_latest_snapshot_for_version ${VERSION} + LATEST_VERSION=${LATEST_SNAPSHOT_VERSION} + ASSERTION_VERSION=${LATEST_SNAPSHOT_VERSION%-*} # strip -SNAPSHOT suffix + get_latest_snapshot + NEXT_MAJOR_LATEST=$(echo $VERSIONS | jq -r -c '.[-1]') + ASSERTION_NEXT_MAJOR_LATEST=${NEXT_MAJOR_LATEST%-*} # strip -SNAPSHOT suffix +else + get_latest_patch ${VERSION} + LATEST_VERSION=${VERSION}.${LATEST_PATCH} + ASSERTION_VERSION=${LATEST_VERSION} + NEXT_MAJOR_LATEST=$(echo ${VERSIONS} | jq -r '[.[] | select(. | startswith("8"))] | last') + ASSERTION_NEXT_MAJOR_LATEST=${NEXT_MAJOR_LATEST} +fi echo "-> Running ${LATEST_VERSION} standalone to ${NEXT_MAJOR_LATEST} to ${NEXT_MAJOR_LATEST} managed" @@ -28,7 +40,7 @@ append_tfvar "integrations_server" ${INTEGRATIONS_SERVER} terraform_apply healthcheck 1 send_events -legacy_assertions ${LATEST_VERSION} +legacy_assertions ${ASSERTION_VERSION} cleanup_tfvar append_tfvar "stack_version" ${NEXT_MAJOR_LATEST} @@ -36,11 +48,11 @@ append_tfvar "integrations_server" ${INTEGRATIONS_SERVER} terraform_apply healthcheck 1 send_events -data_stream_assertions ${NEXT_MAJOR_LATEST} +data_stream_assertions ${ASSERTION_NEXT_MAJOR_LATEST} upgrade_managed ${NEXT_MAJOR_LATEST} healthcheck 1 send_events # Assert there are 2 instances of the same event, since we ingested data twice # using the same APM Server version. -data_stream_assertions ${NEXT_MAJOR_LATEST} 2 +data_stream_assertions ${ASSERTION_NEXT_MAJOR_LATEST} 2 diff --git a/testing/smoke/lib.sh b/testing/smoke/lib.sh index e1c896d4f9e..dfad2b74228 100644 --- a/testing/smoke/lib.sh +++ b/testing/smoke/lib.sh @@ -44,6 +44,15 @@ get_latest_snapshot() { VERSIONS=$(echo "${RES}" | jq -r -c '[.stacks[].version | select(. | contains("-SNAPSHOT"))] | sort' | sed 's#-SNAPSHOT#.0#g' | jq -r -c ' sort_by(.| split(".") | map(tonumber))' | sed 's#.0"#-SNAPSHOT"#g' | jq -r -c .) } +get_latest_snapshot_for_version() { + if [[ -z "${1}" ]]; then + echo "-> Version not set" + return 1 + fi + get_latest_snapshot + LATEST_SNAPSHOT_VERSION=$(echo "$VERSIONS" | jq -r -c "map(select(. | startswith(\"${1}\"))) | .[-1]") +} + terraform_init() { if [[ ! -f main.tf ]]; then cp ../main.tf .; fi terraform init >> tf.log @@ -103,7 +112,7 @@ assert_document() { RESULT=$(curl_fail -u ${AUTH} -XGET "${URL}" -H 'Content-Type: application/json' -d"{\"query\":{\"bool\":{\"must\":[{\"match\":{\"${FIELD}\":\"${VALUE}\"}},{\"match\":{\"observer.version\":\"${VERSION}\"}}]}}}") || RC=$? if [ $RC -ne 0 ]; then echo "${RESULT}"; fi - echo "-> Asserting ${INDEX} contains expected documents documents..." + echo "-> Asserting ${INDEX} contains expected documents..." assert_entry ${FIELD} ${VALUE} ${ENTRIES} }