From 73991e854933aafa1c4625453fd0c0f6a9a2f92e Mon Sep 17 00:00:00 2001
From: Guillaume Caillet <cailletg@amazon.com>
Date: Mon, 27 Nov 2023 11:52:13 -0500
Subject: [PATCH] Fix AWS integration test launch

---
 .gitlab-ci.yml                                           | 2 +-
 devops/aws/pipeline/override-stages.yml                  | 9 ++++++---
 provider/notification-aws/pom.xml                        | 2 +-
 .../build-aws/push-endpoint/pom.xml                      | 2 +-
 .../build-aws/push-endpoint/setup_teardown_endpoint.py   | 8 ++++++--
 5 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 3bc4d47c8..0d301d39a 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -157,7 +157,7 @@ azure_test:
   image: community.opengroup.org:5555/osdu/platform/deployment-and-operations/base-containers-azure/azure-maven17:v0.0.1
 
 aws-test-java:
-  image: $CI_REGISTRY/osdu/platform/deployment-and-operations/base-containers-aws/aws-maven/aws-maven:v2.0
+  image: $CI_REGISTRY/osdu/platform/deployment-and-operations/base-containers-aws/aws-maven/aws-maven:v2.1
 
 
 fossa-analyze:
diff --git a/devops/aws/pipeline/override-stages.yml b/devops/aws/pipeline/override-stages.yml
index 319799970..bcdc513f7 100644
--- a/devops/aws/pipeline/override-stages.yml
+++ b/devops/aws/pipeline/override-stages.yml
@@ -25,10 +25,13 @@ include:
 aws-test-java:
   script:
     - export KUBECONFIG=/tmp/kubeconfig-${RANDOM}.yaml
-    - echo "ROLE $EKS_CLUSTER_MGMT_ROLE"
-    - echo "CLUSTER $EKS_CLUSTER_NAME"
     - aws eks update-kubeconfig --region $AWS_REGION --name $EKS_CLUSTER_NAME --role-arn $EKS_CLUSTER_MGMT_ROLE
     - chmod 600 $KUBECONFIG
-
+    - pip3 install boto3
+    - export PUSH_ENDPOINT_PATH=testing/notification-test-aws/build-aws/push-endpoint
+    - echo "PUSH_ENDPOINT_PATH ${PUSH_ENDPOINT_PATH}"
+    - python3 $PUSH_ENDPOINT_PATH/setup_teardown_endpoint.py --create --environment_file $PUSH_ENDPOINT_PATH/environment_file.sh --kube_file $PUSH_ENDPOINT_PATH/push-endpoint-manifest.yaml
+    - trap "python3 $PUSH_ENDPOINT_PATH/setup_teardown_endpoint.py --delete --environment_file $PUSH_ENDPOINT_PATH/environment_file.sh --kube_file $PUSH_ENDPOINT_PATH/push-endpoint-manifest.yaml" EXIT
+    - source $PUSH_ENDPOINT_PATH/environment_file.sh
     - $MAVEN_BUILD $INTEGRATION_TEST_DIR maven-aws-integration-test-output.log ${AWS_MAVEN_TEST_COMMAND_OVERRIDE:-test} --update-snapshots -DdisableXmlReport=true
 
diff --git a/provider/notification-aws/pom.xml b/provider/notification-aws/pom.xml
index 802095c0d..bd5067fe4 100644
--- a/provider/notification-aws/pom.xml
+++ b/provider/notification-aws/pom.xml
@@ -76,7 +76,7 @@
         <dependency>
             <groupId>org.opengroup.osdu.core.aws</groupId>
             <artifactId>os-core-lib-aws</artifactId>
-            <version>0.24.1-SNAPSHOT</version>
+            <version>0.25.1-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>commons-io</groupId>
diff --git a/testing/notification-test-aws/build-aws/push-endpoint/pom.xml b/testing/notification-test-aws/build-aws/push-endpoint/pom.xml
index ea6830a6c..8b8855dad 100644
--- a/testing/notification-test-aws/build-aws/push-endpoint/pom.xml
+++ b/testing/notification-test-aws/build-aws/push-endpoint/pom.xml
@@ -36,7 +36,7 @@ limitations under the License.
         <maven.compiler.source>17</maven.compiler.source>
         <maven.compiler.target>17</maven.compiler.target>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <os-core-common.version>0.23.0-SNAPSHOT</os-core-common.version>
+        <os-core-common.version>0.25.0-rc2</os-core-common.version>
         <spring-boot-maven-plugin.version>2.7.6</spring-boot-maven-plugin.version>
         <aws-java-sdk.version>1.11.1018</aws-java-sdk.version>
         <aws-encryption-sdk-java.version>2.4.0</aws-encryption-sdk-java.version>
diff --git a/testing/notification-test-aws/build-aws/push-endpoint/setup_teardown_endpoint.py b/testing/notification-test-aws/build-aws/push-endpoint/setup_teardown_endpoint.py
index 959f85e3b..922e9d2b3 100644
--- a/testing/notification-test-aws/build-aws/push-endpoint/setup_teardown_endpoint.py
+++ b/testing/notification-test-aws/build-aws/push-endpoint/setup_teardown_endpoint.py
@@ -281,7 +281,7 @@ class CommonParameters:
             self.kube_file = f"{self.push_namespace}.yaml"
 
     def _set_parameters(self):
-        sns_client = boto3.client('ssm')
+        sns_client = boto3.client('ssm', region_name=self.region)
         parameters = {
             f"/osdu/eks/{self.eks_cluster}/amp/workspace/id": "amp_workspace",
             f"/osdu/eks/{self.eks_cluster}/instances/{self.osdu_instance}/ingress/osdu-gateway/name": "osdu_gateway",
@@ -358,7 +358,11 @@ class CommonParameters:
         if len(image_parts) != 2:
             raise RuntimeError("Unexpected result from Kubectl command.")
 
-        endpoint_image_tag = f"push_endpoint.{image_parts[1].split('.', 1)[1]}"
+        # Depending on build env, images names could have two formats:
+        # - `build.dev.1101.COMMIT_HASH` on CodePipeline
+        # - `COMMIT_HASH` on Gitlab
+        # Using -1 as an index here after the split avoid an IndexError with the second case
+        endpoint_image_tag = f"push_endpoint.{image_parts[1].split('.', 1)[-1]}"
         endpoint_image = f"{image_parts[0]}:{endpoint_image_tag[:120]}"
         env_file.write(f"export HMAC_SECRET={hmac_secret}\n")
 
-- 
GitLab