From 143f1eae454e6b98e9aad05ca2a8536157641206 Mon Sep 17 00:00:00 2001 From: Abhay Krishna Arunachalam Date: Fri, 31 May 2024 18:55:44 -0700 Subject: [PATCH] Fetch latest E2E test AMI ID dynamically --- .../build/script/create_infra_config.sh | 18 ++++++++++- scripts/e2e_test_docker.sh | 30 ++++++++++++++----- test/e2e/E2E_AMI_FILTER_VARS | 3 ++ 3 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 test/e2e/E2E_AMI_FILTER_VARS diff --git a/cmd/integration_test/build/script/create_infra_config.sh b/cmd/integration_test/build/script/create_infra_config.sh index 438735076e30..f5a01cf6f643 100755 --- a/cmd/integration_test/build/script/create_infra_config.sh +++ b/cmd/integration_test/build/script/create_infra_config.sh @@ -17,11 +17,27 @@ set -e set -x set -o pipefail +REPO_ROOT=$(git rev-parse --show-toplevel) +source $REPO_ROOT/test/e2e/E2E_AMI_FILTER_VARS + +INTEGRATION_TEST_AMI_ID=$(aws ec2 describe-images \ + --profile ${AWS_PROFILE} \ + --owners ${AMI_OWNER_ID_FILTER} \ + --filters "Name=name,Values=${AMI_NAME_FILTER}" "Name=description,Values=${AMI_DESCRIPTION_FILTER}" \ + --query 'sort_by(Images, &CreationDate)[-1].[ImageId]' \ + --output text +) + +if [ -z "$INTEGRATION_TEST_AMI_ID" ]; then + echo "INTEGRATION_TEST_AMI_ID cannot be empty. Exiting" + exit 1 +fi + cat << EOF > ${INTEGRATION_TEST_INFRA_CONFIG} --- ec2: - amiId: ${INTEGRATION_TEST_AL2_AMI_ID} + amiId: ${INTEGRATION_TEST_AMI_ID} subnetId: ${INTEGRATION_TEST_SUBNET_ID} vSphere: diff --git a/scripts/e2e_test_docker.sh b/scripts/e2e_test_docker.sh index 278a15872126..d96c00b3a21f 100755 --- a/scripts/e2e_test_docker.sh +++ b/scripts/e2e_test_docker.sh @@ -38,37 +38,51 @@ REPO_ROOT=$(git rev-parse --show-toplevel) BIN_FOLDER=$REPO_ROOT/bin TEST_REGEX="${1:-TestDockerKubernetes130SimpleFlow}" BRANCH_NAME="${2:-main}" +source $REPO_ROOT/test/e2e/E2E_AMI_FILTER_VARS +export AWS_SDK_LOAD_CONFIG=true +export AWS_CONFIG_FILE=$(pwd)/config_file +export AWS_PROFILE=e2e-docker-test -cat << EOF > config_file +cat << EOF > ${AWS_CONFIG_FILE} [default] output=json region=${AWS_REGION:-${AWS_DEFAULT_REGION:-us-west-2}} role_arn=$AWS_ROLE_ARN web_identity_token_file=/var/run/secrets/eks.amazonaws.com/serviceaccount/token -[profile e2e-docker-test] +[profile ${AWS_PROFILE}] role_arn=$TEST_ROLE_ARN region=${AWS_REGION:-${AWS_DEFAULT_REGION:-us-west-2}} source_profile=default EOF +unset AWS_ROLE_ARN AWS_WEB_IDENTITY_TOKEN_FILE + INTEGRATION_TEST_INFRA_CONFIG="/tmp/test-infra.yml" export T_TINKERBELL_S3_INVENTORY_CSV_KEY="inventory/den80/den80-hardware.csv" +INTEGRATION_TEST_AMI_ID=$(aws ec2 describe-images \ + --profile ${AWS_PROFILE} \ + --owners ${AMI_OWNER_ID_FILTER} \ + --filters "Name=name,Values=${AMI_NAME_FILTER}" "Name=description,Values=${AMI_DESCRIPTION_FILTER}" \ + --query 'sort_by(Images, &CreationDate)[-1].[ImageId]' \ + --output text +) + +if [ -z $INTEGRATION_TEST_AMI_ID ]; then + echo "INTEGRATION_TEST_AMI_ID cannot be empty. Exiting" + exit 1 +fi + cat << EOF > ${INTEGRATION_TEST_INFRA_CONFIG} --- ec2: - amiId: ${INTEGRATION_TEST_AL2_AMI_ID} + amiId: ${INTEGRATION_TEST_AMI_ID} subnetId: EOF -export AWS_SDK_LOAD_CONFIG=true -export AWS_CONFIG_FILE=$(pwd)/config_file -export AWS_PROFILE=e2e-docker-test -unset AWS_ROLE_ARN AWS_WEB_IDENTITY_TOKEN_FILE - BUNDLES_OVERRIDE=false if [ -f "$BIN_FOLDER/local-bundle-release.yaml" ]; then BUNDLES_OVERRIDE=true diff --git a/test/e2e/E2E_AMI_FILTER_VARS b/test/e2e/E2E_AMI_FILTER_VARS new file mode 100644 index 000000000000..c78543c92150 --- /dev/null +++ b/test/e2e/E2E_AMI_FILTER_VARS @@ -0,0 +1,3 @@ +AMI_OWNER_ID_FILTER=857151390494 +AMI_NAME_FILTER=eksa-integration-test-AL2-* +AMI_DESCRIPTION_FILTER="*Kernel version 5.X*"