From af9ceafa6e5203f86868ad4563f76be2947d5562 Mon Sep 17 00:00:00 2001 From: Eric Yap Date: Fri, 16 Jan 2026 16:42:14 +0800 Subject: [PATCH] Fix smoke test issue due to EC API change --- testing/smoke/lib.sh | 33 +++++++++++------------------- testing/smoke/test_supported_os.sh | 19 ++++++++--------- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/testing/smoke/lib.sh b/testing/smoke/lib.sh index ae654b892fb..bac25752811 100755 --- a/testing/smoke/lib.sh +++ b/testing/smoke/lib.sh @@ -9,7 +9,7 @@ get_versions() { return 1 fi # initialize terraform, so we can obtain the configured region. - terraform_init + # terraform_init local REGION=$(echo var.region | terraform console | tr -d '"') local EC_VERSION_ENDPOINT="https://cloud.elastic.co/api/v1/regions/${REGION}/stack/versions?show_deleted=false&show_unusable=false" @@ -21,33 +21,24 @@ get_versions() { VERSIONS=$(echo "${RES}" | jq -r -c '[.stacks[].version | select(. | contains("-") | not)] | sort_by(.| split(".") | map(tonumber))') } -get_latest_version() { - if [[ -z "${VERSIONS}" ]]; then - echo "-> Version not set, call get_versions first" - return 1 - fi - local version - version=$(echo ${VERSIONS} | jq -r -c "max_by(. | select(. | startswith(\"${1}\")) | if endswith(\"-SNAPSHOT\") then .[:-9] else . end | split(\".\") | map(tonumber))") - echo "${version}" -} - -get_latest_patch() { +get_latest_version_for() { if [[ -z "${1}" ]]; then - echo "-> Version not set" + echo "-> Version parameter not set" return 1 fi - LATEST_PATCH=$(get_latest_version "${1}" | cut -d '.' -f3) + get_versions + VERSION=$(echo ${VERSIONS} | jq -r -c "max_by(. | select(. | startswith(\"${1}\")) | if endswith(\"-SNAPSHOT\") then .[:-9] else . end | split(\".\") | map(tonumber))") } -get_latest_snapshot() { +get_snapshots() { if [[ -z ${EC_API_KEY} ]]; then echo "-> ESS API Key not set, please set the EC_API_KEY environment variable." return 1 fi # initialize terraform, so we can obtain the configured region. - terraform_init + # terraform_init - local REGION=$(echo var.region | terraform console | tr -d '"') + # local REGION=$(echo var.region | terraform console | tr -d '"') local EC_VERSION_ENDPOINT="https://cloud.elastic.co/api/v1/regions/${REGION}/stack/versions?show_deleted=false&show_unusable=true" local RES local RC=0 @@ -58,13 +49,13 @@ 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() { +get_latest_snapshot_for() { if [[ -z "${1}" ]]; then - echo "-> Version not set" + echo "-> Version parameter not set" return 1 fi - get_latest_snapshot - LATEST_SNAPSHOT_VERSION=$(echo "$VERSIONS" | jq -r -c "map(select(. | startswith(\"${1}\"))) | .[-1]") + get_snapshots + VERSION=$(echo "$VERSIONS" | jq -r -c "map(select(. | startswith(\"${1}\"))) | .[-1]") } terraform_init() { diff --git a/testing/smoke/test_supported_os.sh b/testing/smoke/test_supported_os.sh index d8604a58924..c1ac72bcb53 100755 --- a/testing/smoke/test_supported_os.sh +++ b/testing/smoke/test_supported_os.sh @@ -9,18 +9,17 @@ ssh-keygen -f ${KEY_NAME} -N "" # Load common lib . $(git rev-parse --show-toplevel)/testing/smoke/lib.sh -# Get all the snapshot versions from the current region. -get_latest_snapshot - # APM `major.minor` version e.g. 8.17. APM_SERVER_VERSION=$(echo ${1} | cut -d '.' -f1-2) -# `VERSIONS` only contains snapshot versions and is in sorted order. -# We retrieve the appropriate stack snapshot version from the list by: -# 1. Selecting the ones that start with APM's `major.minor`. -# 2. Get the last one, which should be latest. -VERSION=$(echo ${VERSIONS} | jq -r --arg VS ${APM_SERVER_VERSION} '[.[] | select(. | startswith($VS))] | last') -OBSERVER_VERSION=$(echo ${VERSION} | cut -d '-' -f1 ) -MAJOR_VERSION=$(echo ${VERSION} | cut -d '.' -f1 ) + +# Get latest snapshot for the version, and if not available, fallback to released version. +get_latest_snapshot_for "${APM_SERVER_VERSION}" +if [[ -n "$VERSION" ]]; then + get_latest_version_for "${APM_SERVER_VERSION}" +fi + +OBSERVER_VERSION=$(echo "${VERSION}" | cut -d '-' -f1 ) +MAJOR_VERSION=$(echo "${VERSION}" | cut -d '.' -f1 ) if [[ ${MAJOR_VERSION} -eq 8 ]] || [[ ${MAJOR_VERSION} -eq 9 ]]; then ASSERT_EVENTS_FUNC=data_stream_assertions