blob: 8183cdee003fac6a5b768b9b58ef73d4417ebaf1 [file] [log] [blame]
waynedunicane4ff7e52023-03-01 09:07:31 +00001#!/bin/bash
Taka Cho6d188af2021-01-11 16:48:33 -05002#
3# Copyright 2016-2017 Huawei Technologies Co., Ltd.
4# Modification Copyright 2019 © Samsung Electronics Co., Ltd.
5# Modification Copyright 2021 © AT&T Intellectual Property.
adheli.tavares80e382e2024-05-01 14:08:35 +01006# Modification Copyright 2021-2024 Nordix Foundation.
Taka Cho6d188af2021-01-11 16:48:33 -05007#
8# Licensed under the Apache License, Version 2.0 (the "License");
9# you may not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS,
16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19#
Taka Cho6d188af2021-01-11 16:48:33 -050020
21function docker_stats(){
liamfallonfaac45b2022-09-01 12:05:47 +010022 # General memory details
23 if [ "$(uname -s)" == "Darwin" ]
24 then
liamfallonfaac45b2022-09-01 12:05:47 +010025 sh -c "top -l1 | head -10"
26 echo
27 else
liamfallonfaac45b2022-09-01 12:05:47 +010028 sh -c "top -bn1 | head -3"
29 echo
Taka Cho6d188af2021-01-11 16:48:33 -050030
liamfallonfaac45b2022-09-01 12:05:47 +010031 sh -c "free -h"
32 echo
33 fi
Taka Cho6d188af2021-01-11 16:48:33 -050034
liamfallonfaac45b2022-09-01 12:05:47 +010035 # Memory details per Docker
adheli.tavaresd802fd92024-08-15 12:39:19 +010036 docker ps --format "table {{ .Image }}\t{{ .Names }}\t{{ .Status }}"
Taka Cho6d188af2021-01-11 16:48:33 -050037 echo
38
Taka Cho6d188af2021-01-11 16:48:33 -050039 docker stats --no-stream
40 echo
41}
42
adheli.tavares80e382e2024-05-01 14:08:35 +010043function setup_clamp() {
rameshiyer273397d842024-08-18 11:12:23 +010044 export ROBOT_FILES="policy-clamp-test.robot clamp-slas.robot"
adheli.tavaresd802fd92024-08-15 12:39:19 +010045 source ${DOCKER_COMPOSE_DIR}/start-compose.sh policy-clamp-runtime-acm --grafana
adheli.tavares80e382e2024-05-01 14:08:35 +010046 sleep 30
adheli.tavaresd802fd92024-08-15 12:39:19 +010047 bash ${SCRIPTS}/wait_for_rest.sh localhost "${ACM_PORT}"
Taka Cho6d188af2021-01-11 16:48:33 -050048}
49
rameshiyer27f851a5e2024-07-02 09:16:56 +000050function setup_clamp_replica() {
adheli.tavaresd802fd92024-08-15 12:39:19 +010051 export ACM_REPLICA_TEARDOWN=true
rameshiyer27f851a5e2024-07-02 09:16:56 +000052 export ROBOT_FILES="policy-clamp-test.robot"
53 export TEST_ENV="docker"
adheli.tavaresd802fd92024-08-15 12:39:19 +010054 export PROJECT=clamp
55 source ${DOCKER_COMPOSE_DIR}/start-acm-replica.sh --start --replicas=2
56 echo "Waiting a minute for the replicas to be started..."
57 sleep 60
58 # checking on apex-pdp status because acm-r replicas only start after apex-pdp is running
59 bash ${SCRIPTS}/wait_for_rest.sh localhost ${APEX_PORT}
60 apex_healthcheck
61 bash ${SCRIPTS}/wait_for_rest.sh localhost ${ACM_PORT}
rameshiyer27f851a5e2024-07-02 09:16:56 +000062}
63
adheli.tavares80e382e2024-05-01 14:08:35 +010064function setup_api() {
65 export ROBOT_FILES="api-test.robot api-slas.robot"
adheli.tavaresd802fd92024-08-15 12:39:19 +010066 source ${DOCKER_COMPOSE_DIR}/start-compose.sh api --grafana
adheli.tavares80e382e2024-05-01 14:08:35 +010067 sleep 10
adheli.tavaresd802fd92024-08-15 12:39:19 +010068 bash ${SCRIPTS}/wait_for_rest.sh localhost ${API_PORT}
adheli.tavares80e382e2024-05-01 14:08:35 +010069}
Taka Cho6d188af2021-01-11 16:48:33 -050070
adheli.tavares80e382e2024-05-01 14:08:35 +010071function setup_pap() {
72 export ROBOT_FILES="pap-test.robot pap-slas.robot"
adheli.tavaresd802fd92024-08-15 12:39:19 +010073 source ${DOCKER_COMPOSE_DIR}/start-compose.sh apex-pdp --grafana
adheli.tavares80e382e2024-05-01 14:08:35 +010074 sleep 10
adheli.tavaresd802fd92024-08-15 12:39:19 +010075 bash ${SCRIPTS}/wait_for_rest.sh localhost ${PAP_PORT}
adheli.tavares80e382e2024-05-01 14:08:35 +010076}
77
78function setup_apex() {
79 export ROBOT_FILES="apex-pdp-test.robot apex-slas.robot"
adheli.tavaresd802fd92024-08-15 12:39:19 +010080 source ${DOCKER_COMPOSE_DIR}/start-compose.sh apex-pdp --grafana
adheli.tavares80e382e2024-05-01 14:08:35 +010081 sleep 10
adheli.tavaresd802fd92024-08-15 12:39:19 +010082 bash ${SCRIPTS}/wait_for_rest.sh localhost ${PAP_PORT}
83 bash ${SCRIPTS}/wait_for_rest.sh localhost ${APEX_PORT}
adheli.tavares80e382e2024-05-01 14:08:35 +010084 apex_healthcheck
85}
86
87function setup_apex_medium() {
88 export SUITES="apex-slas-3.robot"
adheli.tavaresd802fd92024-08-15 12:39:19 +010089 export APEX_REPLICA_TEARDOWN=true
90 source ${DOCKER_COMPOSE_DIR}/start-multiple-pdp.sh --start --replicas=3
adheli.tavares80e382e2024-05-01 14:08:35 +010091 sleep 10
adheli.tavaresd802fd92024-08-15 12:39:19 +010092 bash ${SCRIPTS}/wait_for_rest.sh localhost ${PAP_PORT}
93 bash ${SCRIPTS}/wait_for_rest.sh localhost ${APEX_PORT}
adheli.tavares80e382e2024-05-01 14:08:35 +010094 apex_healthcheck
95}
96
97function setup_apex_large() {
98 export ROBOT_FILES="apex-slas-10.robot"
adheli.tavaresd802fd92024-08-15 12:39:19 +010099 export APEX_REPLICA_TEARDOWN=true
100 source ${DOCKER_COMPOSE_DIR}/start-multiple-pdp.sh --start --replicas=10
adheli.tavares80e382e2024-05-01 14:08:35 +0100101 sleep 10
adheli.tavaresd802fd92024-08-15 12:39:19 +0100102 bash ${SCRIPTS}/wait_for_rest.sh localhost ${PAP_PORT}
103 bash ${SCRIPTS}/wait_for_rest.sh localhost ${APEX_PORT}
adheli.tavares80e382e2024-05-01 14:08:35 +0100104 apex_healthcheck
105}
106
107function apex_healthcheck() {
108 sleep 20
109
110 healthy=false
111
112 while [ $healthy = false ]
113 do
114 msg=`curl -s -k --user 'policyadmin:zb!XztG34' http://localhost:${APEX_PORT}/policy/apex-pdp/v1/healthcheck`
115 echo "${msg}" | grep -q true
116 if [ "${?}" -eq 0 ]
117 then
118 healthy=true
119 break
120 fi
121 sleep 10s
Taka Cho6d188af2021-01-11 16:48:33 -0500122 done
Taka Cho6d188af2021-01-11 16:48:33 -0500123}
124
adheli.tavares80e382e2024-05-01 14:08:35 +0100125function setup_drools_apps() {
rameshiyer27630801c2024-10-01 15:19:25 +0100126 export ROBOT_FILES="drools-applications-test.robot drools-applications-slas.robot"
127 source ${DOCKER_COMPOSE_DIR}/start-compose.sh drools-applications --grafana
adheli.tavares80e382e2024-05-01 14:08:35 +0100128 sleep 10
adheli.tavaresd802fd92024-08-15 12:39:19 +0100129 bash ${SCRIPTS}/wait_for_rest.sh localhost ${PAP_PORT}
adheli.tavares80e382e2024-05-01 14:08:35 +0100130 sleep 10
adheli.tavaresd802fd92024-08-15 12:39:19 +0100131 bash ${SCRIPTS}/wait_for_rest.sh localhost ${DROOLS_APPS_PORT}
adheli.tavares80e382e2024-05-01 14:08:35 +0100132 sleep 10
adheli.tavaresd802fd92024-08-15 12:39:19 +0100133 bash ${SCRIPTS}/wait_for_rest.sh localhost ${DROOLS_APPS_TELEMETRY_PORT}
Taka Cho6d188af2021-01-11 16:48:33 -0500134}
135
adheli.tavares80e382e2024-05-01 14:08:35 +0100136function setup_xacml_pdp() {
rameshiyer27630801c2024-10-01 15:19:25 +0100137 export ROBOT_FILES="xacml-pdp-test.robot xacml-pdp-slas.robot"
138 source ${DOCKER_COMPOSE_DIR}/start-compose.sh xacml-pdp --grafana
adheli.tavares80e382e2024-05-01 14:08:35 +0100139 sleep 10
adheli.tavaresd802fd92024-08-15 12:39:19 +0100140 bash ${SCRIPTS}/wait_for_rest.sh localhost "${XACML_PORT}"
adheli.tavaresdaecbb92024-07-19 13:50:04 +0100141}
142
adheli.tavares80e382e2024-05-01 14:08:35 +0100143function setup_drools_pdp() {
144 export ROBOT_FILES="drools-pdp-test.robot"
adheli.tavaresd802fd92024-08-15 12:39:19 +0100145 source ${DOCKER_COMPOSE_DIR}/start-compose.sh drools-pdp
adheli.tavares80e382e2024-05-01 14:08:35 +0100146 sleep 30
adheli.tavaresd802fd92024-08-15 12:39:19 +0100147 bash ${SCRIPTS}/wait_for_rest.sh localhost ${DROOLS_TELEMETRY_PORT}
Taka Cho6d188af2021-01-11 16:48:33 -0500148}
149
adheli.tavares80e382e2024-05-01 14:08:35 +0100150function setup_distribution() {
adheli.tavaresd802fd92024-08-15 12:39:19 +0100151 zip -F ${CSAR_DIR}/sample_csar_with_apex_policy.csar --out ${CSAR_DIR}/csar_temp.csar -q
Taka Cho6d188af2021-01-11 16:48:33 -0500152
adheli.tavares80e382e2024-05-01 14:08:35 +0100153 # Remake temp directory
154 sudo rm -rf /tmp/distribution
155 sudo mkdir /tmp/distribution
Taka Cho6d188af2021-01-11 16:48:33 -0500156
adheli.tavares80e382e2024-05-01 14:08:35 +0100157 export ROBOT_FILES="distribution-test.robot"
adheli.tavaresd802fd92024-08-15 12:39:19 +0100158 source ${DOCKER_COMPOSE_DIR}/start-compose.sh distribution
adheli.tavares80e382e2024-05-01 14:08:35 +0100159 sleep 10
adheli.tavaresd802fd92024-08-15 12:39:19 +0100160 bash ${SCRIPTS}/wait_for_rest.sh localhost "${DIST_PORT}"
adheli.tavares80e382e2024-05-01 14:08:35 +0100161}
Taka Cho6d188af2021-01-11 16:48:33 -0500162
adheli.tavares80e382e2024-05-01 14:08:35 +0100163function build_robot_image() {
adheli.tavaresd802fd92024-08-15 12:39:19 +0100164 bash ${SCRIPTS}/build-csit-docker-image.sh
adheli.tavares80e382e2024-05-01 14:08:35 +0100165 cd ${WORKSPACE}
166}
167
168function run_robot() {
adheli.tavaresd802fd92024-08-15 12:39:19 +0100169 docker compose -f ${DOCKER_COMPOSE_DIR}/compose.yaml up csit-tests
adheli.tavares80e382e2024-05-01 14:08:35 +0100170 export RC=$?
171}
172
173function set_project_config() {
174 echo "Setting project configuration for: $PROJECT"
175 case $PROJECT in
176
177 clamp | policy-clamp)
178 setup_clamp
179 ;;
180
rameshiyer27f851a5e2024-07-02 09:16:56 +0000181 clamp-replica | policy-clamp-replica)
182 setup_clamp_replica
183 ;;
184
adheli.tavares80e382e2024-05-01 14:08:35 +0100185 api | policy-api)
186 setup_api
187 ;;
188
189 pap | policy-pap)
190 setup_pap
191 ;;
192
193 apex-pdp | policy-apex-pdp)
194 setup_apex
195 ;;
196
197 apex-pdp-postgres | policy-apex-pdp-postgres)
adheli.tavaresd802fd92024-08-15 12:39:19 +0100198 setup_apex
adheli.tavares80e382e2024-05-01 14:08:35 +0100199 ;;
200
201 apex-pdp-medium | policy-apex-pdp-medium)
rameshiyer27f851a5e2024-07-02 09:16:56 +0000202 setup_apex_medium
adheli.tavares80e382e2024-05-01 14:08:35 +0100203 ;;
204
205 apex-pdp-large | policy-apex-pdp-large)
rameshiyer27f851a5e2024-07-02 09:16:56 +0000206 setup_apex_large
adheli.tavares80e382e2024-05-01 14:08:35 +0100207 ;;
208
209 xacml-pdp | policy-xacml-pdp)
210 setup_xacml_pdp
211 ;;
212
213 drools-pdp | policy-drools-pdp)
214 setup_drools_pdp
215 ;;
216
217 drools-applications | policy-drools-applications | drools-apps | policy-drools-apps)
218 setup_drools_apps
219 ;;
220
221 distribution | policy-distribution)
222 setup_distribution
223 ;;
224
225 *)
226 echo "Unknown project supplied. No test will run."
227 exit 1
228 ;;
229 esac
230}
231
232# even with forced finish, clean up docker containers
233function on_exit(){
adheli.tavaresd802fd92024-08-15 12:39:19 +0100234 rm -rf ${CSAR_DIR}/csar_temp.csar
235
236 # teardown of compose containers for acm-replicas doesn't work with normal stop-compose script
237 if [ "${ACM_REPLICA_TEARDOWN}" = true ]; then
238 source ${DOCKER_COMPOSE_DIR}/start-acm-replica.sh --stop --replicas=2
239 elif [ "${APEX_REPLICA_TEARDOWN}" = true ]; then
240 source ${DOCKER_COMPOSE_DIR}/start-multiple-pdp.sh --stop --replicas=2
241 else
242 source ${DOCKER_COMPOSE_DIR}/stop-compose.sh ${PROJECT}
243 fi
244
245 mv ${DOCKER_COMPOSE_DIR}/*.log ${ROBOT_LOG_DIR}
adheli.tavares80e382e2024-05-01 14:08:35 +0100246 exit $RC
247}
248
249# ensure that teardown and other finalizing steps are always executed
250trap on_exit EXIT
251
252# setup all directories used for test resources
Jim Hahn3486a922021-05-10 15:36:30 -0400253if [ -z "${WORKSPACE}" ]; then
adheli.tavares1f339f82023-02-17 15:14:07 +0000254 WORKSPACE=$(git rev-parse --show-toplevel)
255 export WORKSPACE
Taka Cho6d188af2021-01-11 16:48:33 -0500256fi
257
adheli.tavares80e382e2024-05-01 14:08:35 +0100258export GERRIT_BRANCH=$(awk -F= '$1 == "defaultbranch" { print $2 }' "${WORKSPACE}"/.gitreview)
Taka Cho6d188af2021-01-11 16:48:33 -0500259export PROJECT="${1}"
adheli.tavaresd802fd92024-08-15 12:39:19 +0100260export ROBOT_LOG_DIR="${WORKSPACE}/csit/archives/${PROJECT}"
adheli.tavares80e382e2024-05-01 14:08:35 +0100261export SCRIPTS="${WORKSPACE}/csit/resources/scripts"
adheli.tavaresd802fd92024-08-15 12:39:19 +0100262export CSAR_DIR="${WORKSPACE}/csit/resources/tests/data/csar"
263export DOCKER_COMPOSE_DIR="${WORKSPACE}/compose"
adheli.tavares80e382e2024-05-01 14:08:35 +0100264export ROBOT_FILES=""
adheli.tavaresd802fd92024-08-15 12:39:19 +0100265export ACM_REPLICA_TEARDOWN=false
266export APEX_REPLICA_TEARDOWN=false
Jim Hahn3486a922021-05-10 15:36:30 -0400267
adheli.tavares1f339f82023-02-17 15:14:07 +0000268cd "${WORKSPACE}"
Taka Cho6d188af2021-01-11 16:48:33 -0500269
adheli.tavares80e382e2024-05-01 14:08:35 +0100270# recreate the log folder with test results
271sudo rm -rf ${ROBOT_LOG_DIR}
272mkdir -p ${ROBOT_LOG_DIR}
Taka Cho6d188af2021-01-11 16:48:33 -0500273
adheli.tavares80e382e2024-05-01 14:08:35 +0100274# log into nexus docker
Taka Cho6d188af2021-01-11 16:48:33 -0500275docker login -u docker -p docker nexus3.onap.org:10001
276
adheli.tavares80e382e2024-05-01 14:08:35 +0100277# based on $PROJECT var, setup robot test files and docker compose execution
278compose_version=$(docker compose version)
279
280if [[ $compose_version == *"Docker Compose version"* ]]; then
281 echo $compose_version
282else
283 echo "Docker Compose Plugin not installed. Installing now..."
284 sudo mkdir -p /usr/local/lib/docker/cli-plugins
adheli.tavaresd802fd92024-08-15 12:39:19 +0100285 sudo curl -SL https://github.com/docker/compose/releases/download/v2.29.1/docker-compose-linux-x86_64 -o /usr/local/lib/docker/cli-plugins/docker-compose
adheli.tavares80e382e2024-05-01 14:08:35 +0100286 sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
Taka Cho6d188af2021-01-11 16:48:33 -0500287fi
288
adheli.tavares80e382e2024-05-01 14:08:35 +0100289set_project_config
290
291unset http_proxy https_proxy
292
293export ROBOT_FILES
294
adheli.tavaresf11e6d92024-08-01 14:18:34 +0100295# use a separate script to build a CSIT docker image, to isolate the test run
adheli.tavares80e382e2024-05-01 14:08:35 +0100296if [ "${2}" == "--skip-build-csit" ]; then
297 echo "Skipping build csit robot image"
298else
299 build_robot_image
300fi
301
adheli.tavaresd802fd92024-08-15 12:39:19 +0100302docker_stats | tee "${ROBOT_LOG_DIR}/_sysinfo-1-after-setup.txt"
Taka Cho6d188af2021-01-11 16:48:33 -0500303
adheli.tavares80e382e2024-05-01 14:08:35 +0100304# start the CSIT container and run the tests
305run_robot
Taka Cho6d188af2021-01-11 16:48:33 -0500306
adheli.tavaresd802fd92024-08-15 12:39:19 +0100307docker ps --format "table {{ .Image }}\t{{ .Names }}\t{{ .Status }}"