blob: 677c26306e5b976cdb225584df12d16fa32fd207 [file] [log] [blame]
rameshiyer27b15eda62024-02-14 10:13:16 +00001#!/bin/bash
2#
3# Copyright 2024 Nordix Foundation.
4
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18# Script to run the ACM regression test suite in cucumber.
rameshiyer279c4e66a2024-07-17 23:19:44 +000019# Deploys ACM-R and participants in two different release branch/versions for testing backward compatibility.
rameshiyer27b15eda62024-02-14 10:13:16 +000020
rameshiyer279c4e66a2024-07-17 23:19:44 +000021function usage() {
22 echo "Usage: $0 --release <acmr-release_branch> <ppnt-release_branch> | --version <acmr-version> <ppnt-version>"
23 exit 1
24}
rameshiyer27b15eda62024-02-14 10:13:16 +000025
rameshiyer279c4e66a2024-07-17 23:19:44 +000026# Legacy config files for releases up to 'newdelhi'
27function release_config_path() {
28 if [ $1 == 'master' ] || [[ "$(echo "$1" | cut -c1 )" > 'n' ]]; then
29 echo "config/clamp"
30 else
31 echo "config/clamp/legacy"
32 fi
33}
rameshiyer27b15eda62024-02-14 10:13:16 +000034
rameshiyer279c4e66a2024-07-17 23:19:44 +000035# Legacy config files for versions before 8.0.0
36function version_config_path() {
37 if [[ "$(printf '%s\n' "$1" "8.0.0" | sort -V | head -n 1)" == "8.0.0" ]]; then
38 echo "config/clamp"
39 else
40 echo "config/clamp/legacy"
41 fi
42}
43
44function validate_version() {
45 local version=$1
46 if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
47 echo "Invalid version format: $version. Expected format: x.y.z where x, y, and z are numbers."
48 usage
49 fi
50}
51
52function validate_release() {
53 local release=$1
54 if [[ ! $release =~ ^[a-zA-Z._-]+$ ]]; then
55 echo "Invalid release format: $release. Expected a string release name"
56 usage
57 fi
58}
59
60# Invalid input
61if [ "$#" -ne 0 ] && [ "$#" -ne 3 ]; then
62 usage
rameshiyer27b15eda62024-02-14 10:13:16 +000063fi
64
65if [ -z "${WORKSPACE}" ]; then
66 WORKSPACE=$(git rev-parse --show-toplevel)
67 export WORKSPACE
68fi
69
rameshiyer279c4e66a2024-07-17 23:19:44 +000070if [ -z "$ROBOT_LOG_DIR" ]; then
71 export ROBOT_LOG_DIR=/tmp/
72fi
rameshiyer27b15eda62024-02-14 10:13:16 +000073
74export SCRIPTS="${WORKSPACE}/csit/resources/scripts"
rameshiyer27b15eda62024-02-14 10:13:16 +000075COMPOSE_FOLDER="${WORKSPACE}"/compose
76REGRESSION_FOLDER="${WORKSPACE}"/policy-regression-tests/policy-clamp-regression/
77export PROJECT='clamp'
rameshiyer279c4e66a2024-07-17 23:19:44 +000078DEFAULT_BRANCH=$(awk -F= '$1 == "defaultbranch" { print $2 }' \
79 "${WORKSPACE}"/.gitreview)
rameshiyer27b15eda62024-02-14 10:13:16 +000080
rameshiyer279c4e66a2024-07-17 23:19:44 +000081# Run from default branch
82if [ $# -eq 0 ]
83then
84 echo "Usage: $0 --release <acmr-release_branch> <ppnt-release_branch> | --version <acmr-version> <ppnt-version>"
85 echo "*** No release_branch/versions provided. Default branch will be used."
86 echo "Fetching image versions for all components..."
87 source ${COMPOSE_FOLDER}/get-versions-regression.sh $DEFAULT_BRANCH $DEFAULT_BRANCH > /dev/null 2>&1
88 echo "Starting Regression with ACM-R and PPNT from the default release branch $DEFAULT_BRANCH ***"
89 export CLAMP_CONFIG_PATH=$(release_config_path "$DEFAULT_BRANCH")
90 export PPNT_CONFIG_PATH="$CLAMP_CONFIG_PATH"
91 echo "Using configuration file located at $CLAMP_CONFIG_PATH for ACM-R and $PPNT_CONFIG_PATH for PPNTS."
rameshiyer27b15eda62024-02-14 10:13:16 +000092
rameshiyer279c4e66a2024-07-17 23:19:44 +000093# Run with specific release/version
94elif [ "$#" -gt 0 ]
95then
96 case $1 in
97 --release)
98 validate_release $2
99 validate_release $3
100 echo "Fetching image versions for all components..."
101 source ${COMPOSE_FOLDER}/get-versions-regression.sh $2 $3 > /dev/null 2>&1
102 echo "*** Starting Regression with ACM-R from branch $2 and PPNT from branch $3 ***"
103 export CLAMP_CONFIG_PATH=$(release_config_path $2)
104 export PPNT_CONFIG_PATH=$(release_config_path $3)
105 echo "Using configuration file located at $CLAMP_CONFIG_PATH for ACM-R and $PPNT_CONFIG_PATH for PPNTS."
106 ;;
107 --version)
108 validate_version $2
109 validate_version $3
110 echo "Fetching image versions for all components..."
111 source ${COMPOSE_FOLDER}/get-versions-regression.sh $DEFAULT_BRANCH $DEFAULT_BRANCH > /dev/null 2>&1
112 export POLICY_CLAMP_VERSION=$2
113 export POLICY_CLAMP_PPNT_VERSION=$3
114 echo "*** Starting Regression with ACM-R version $2 and PPNT version $3 ***"
115 export CLAMP_CONFIG_PATH=$(version_config_path "$2")
116 export PPNT_CONFIG_PATH=$(version_config_path "$3")
117 echo "Using configuration file located at $CLAMP_CONFIG_PATH for ACM-R and $PPNT_CONFIG_PATH for PPNTS."
118 ;;
119 *)
120 echo "Unknown parameter: $1"
121 usage
122 ;;
123 esac
124fi
125
126echo "*** Configure docker compose and trigger deployment***"
rameshiyer27b15eda62024-02-14 10:13:16 +0000127cd ${COMPOSE_FOLDER}
rameshiyer279c4e66a2024-07-17 23:19:44 +0000128docker login -u docker -p docker nexus3.onap.org:10001 > /dev/null 2>&1
rameshiyer27b15eda62024-02-14 10:13:16 +0000129source export-ports.sh > /dev/null 2>&1
rameshiyer27b15eda62024-02-14 10:13:16 +0000130
rameshiyer279c4e66a2024-07-17 23:19:44 +0000131docker compose -f docker-compose.yml up -d "policy-clamp-runtime-acm"
rameshiyer27b15eda62024-02-14 10:13:16 +0000132
133# wait for the app to start up
134"${SCRIPTS}"/wait_for_rest.sh localhost "${ACM_PORT}"
135
136cd ${REGRESSION_FOLDER}
137
138# Invoke the regression test cases
rameshiyer279c4e66a2024-07-17 23:19:44 +0000139mvn clean test -Dtests.skip=false
140