Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 12 additions & 21 deletions testing/smoke/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 '"')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we plan to use this terraform code again? If not, shouldn't we remove it?

Suggested change
# local REGION=$(echo var.region | terraform console | tr -d '"')

The terraform code we are initializing here could be removed (at least partially)?

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
Expand All @@ -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() {
Expand Down
19 changes: 9 additions & 10 deletions testing/smoke/test_supported_os.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading