summaryrefslogtreecommitdiffstats
path: root/csit/run-acm-regression.sh
blob: 677c26306e5b976cdb225584df12d16fa32fd207 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
#
# Copyright 2024 Nordix Foundation.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Script to run the ACM regression test suite in cucumber.
# Deploys ACM-R and participants in two different release branch/versions for testing backward compatibility.

function usage() {
  echo "Usage: $0 --release <acmr-release_branch> <ppnt-release_branch> | --version <acmr-version> <ppnt-version>"
  exit 1
}

# Legacy config files for releases up to 'newdelhi'
function release_config_path() {
  if [ $1 == 'master' ] || [[ "$(echo "$1" | cut -c1 )" > 'n' ]]; then
    echo "config/clamp"
  else
    echo "config/clamp/legacy"
  fi
}

# Legacy config files for versions before 8.0.0
function version_config_path() {
  if [[ "$(printf '%s\n' "$1" "8.0.0" | sort -V | head -n 1)" == "8.0.0" ]]; then
    echo "config/clamp"
  else
    echo "config/clamp/legacy"
  fi
}

function validate_version() {
    local version=$1
    if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
        echo "Invalid version format: $version. Expected format: x.y.z where x, y, and z are numbers."
        usage
    fi
}

function validate_release() {
    local release=$1
    if [[ ! $release =~ ^[a-zA-Z._-]+$ ]]; then
        echo "Invalid release format: $release. Expected a string release name"
        usage
    fi
}

# Invalid input
if [ "$#" -ne 0 ] && [ "$#" -ne 3 ]; then
  usage
fi

if [ -z "${WORKSPACE}" ]; then
    WORKSPACE=$(git rev-parse --show-toplevel)
    export WORKSPACE
fi

if [ -z "$ROBOT_LOG_DIR" ]; then
  export ROBOT_LOG_DIR=/tmp/
fi

export SCRIPTS="${WORKSPACE}/csit/resources/scripts"
COMPOSE_FOLDER="${WORKSPACE}"/compose
REGRESSION_FOLDER="${WORKSPACE}"/policy-regression-tests/policy-clamp-regression/
export PROJECT='clamp'
DEFAULT_BRANCH=$(awk -F= '$1 == "defaultbranch" { print $2 }' \
                            "${WORKSPACE}"/.gitreview)

# Run from default branch
if [ $# -eq 0 ]
then
  echo "Usage: $0 --release <acmr-release_branch> <ppnt-release_branch> | --version <acmr-version> <ppnt-version>"
  echo "*** No release_branch/versions provided. Default branch will be used."
  echo "Fetching image versions for all components..."
  source ${COMPOSE_FOLDER}/get-versions-regression.sh $DEFAULT_BRANCH $DEFAULT_BRANCH > /dev/null 2>&1
  echo "Starting Regression with ACM-R and PPNT from the default release branch $DEFAULT_BRANCH ***"
  export CLAMP_CONFIG_PATH=$(release_config_path "$DEFAULT_BRANCH")
  export PPNT_CONFIG_PATH="$CLAMP_CONFIG_PATH"
  echo "Using configuration file located at $CLAMP_CONFIG_PATH for ACM-R and $PPNT_CONFIG_PATH for PPNTS."

# Run with specific release/version
elif [ "$#" -gt 0 ]
then
  case $1 in
    --release)
      validate_release $2
      validate_release $3
      echo "Fetching image versions for all components..."
      source ${COMPOSE_FOLDER}/get-versions-regression.sh $2 $3 > /dev/null 2>&1
      echo "*** Starting Regression with ACM-R from branch $2 and PPNT from branch $3 ***"
      export CLAMP_CONFIG_PATH=$(release_config_path $2)
      export PPNT_CONFIG_PATH=$(release_config_path $3)
      echo "Using configuration file located at $CLAMP_CONFIG_PATH for ACM-R and $PPNT_CONFIG_PATH for PPNTS." 
      ;;
    --version)
      validate_version $2
      validate_version $3
      echo "Fetching image versions for all components..."
      source ${COMPOSE_FOLDER}/get-versions-regression.sh $DEFAULT_BRANCH $DEFAULT_BRANCH > /dev/null 2>&1
      export POLICY_CLAMP_VERSION=$2
      export POLICY_CLAMP_PPNT_VERSION=$3
      echo "*** Starting Regression with ACM-R version $2 and PPNT version $3 ***"
      export CLAMP_CONFIG_PATH=$(version_config_path "$2")
      export PPNT_CONFIG_PATH=$(version_config_path "$3")
      echo "Using configuration file located at $CLAMP_CONFIG_PATH for ACM-R and $PPNT_CONFIG_PATH for PPNTS."
      ;;
    *)
      echo "Unknown parameter: $1"
      usage
      ;;
  esac
fi

echo "*** Configure docker compose and trigger deployment***"
cd ${COMPOSE_FOLDER}
docker login -u docker -p docker nexus3.onap.org:10001 > /dev/null 2>&1
source export-ports.sh > /dev/null 2>&1

docker compose -f docker-compose.yml up -d "policy-clamp-runtime-acm"

# wait for the app to start up
"${SCRIPTS}"/wait_for_rest.sh localhost "${ACM_PORT}"

cd ${REGRESSION_FOLDER}

# Invoke the regression test cases
mvn clean test -Dtests.skip=false