blob: cbb62e6d56aa941a2f0cda237beb25e5a52a1397 [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.tavares9fc9fa42023-02-09 11:56:27 +000036 docker ps --format "table {{ .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"
45 source "${WORKSPACE}"/compose/start-compose.sh policy-clamp-runtime-acm --grafana
adheli.tavares80e382e2024-05-01 14:08:35 +010046 sleep 30
47 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() {
51 export ROBOT_FILES="policy-clamp-test.robot"
52 export TEST_ENV="docker"
53 source "${WORKSPACE}"/compose/start-acm-replica.sh 2
54 sleep 30
55 bash "${SCRIPTS}"/wait_for_rest.sh localhost "${ACM_PORT}"
56}
57
adheli.tavares80e382e2024-05-01 14:08:35 +010058function setup_api() {
59 export ROBOT_FILES="api-test.robot api-slas.robot"
60 source "${WORKSPACE}"/compose/start-compose.sh api --grafana
61 sleep 10
62 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${API_PORT}
63}
Taka Cho6d188af2021-01-11 16:48:33 -050064
adheli.tavares80e382e2024-05-01 14:08:35 +010065function setup_pap() {
66 export ROBOT_FILES="pap-test.robot pap-slas.robot"
67 source "${WORKSPACE}"/compose/start-compose.sh apex-pdp --grafana
68 sleep 10
69 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${PAP_PORT}
70}
71
72function setup_apex() {
73 export ROBOT_FILES="apex-pdp-test.robot apex-slas.robot"
74 source "${WORKSPACE}"/compose/start-compose.sh apex-pdp --grafana
75 sleep 10
76 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${PAP_PORT}
77 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${APEX_PORT}
78 apex_healthcheck
79}
80
81function setup_apex_postgres() {
82 export ROBOT_FILES="apex-pdp-test.robot"
adheli.tavaresdaecbb92024-07-19 13:50:04 +010083 source "${WORKSPACE}"/compose/start-postgres-tests.sh apex-pdp 1
adheli.tavares80e382e2024-05-01 14:08:35 +010084 sleep 10
85 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${PAP_PORT}
86 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${APEX_PORT}
87 apex_healthcheck
88}
89
90function setup_apex_medium() {
91 export SUITES="apex-slas-3.robot"
92 source "${WORKSPACE}"/compose/start-multiple-pdp.sh 3
93 sleep 10
94 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${PAP_PORT}
95 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${APEX_PORT}
96 apex_healthcheck
97}
98
99function setup_apex_large() {
100 export ROBOT_FILES="apex-slas-10.robot"
101 source "${WORKSPACE}"/compose/start-multiple-pdp.sh 10
102 sleep 10
103 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${PAP_PORT}
104 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${APEX_PORT}
105 apex_healthcheck
106}
107
108function apex_healthcheck() {
109 sleep 20
110
111 healthy=false
112
113 while [ $healthy = false ]
114 do
115 msg=`curl -s -k --user 'policyadmin:zb!XztG34' http://localhost:${APEX_PORT}/policy/apex-pdp/v1/healthcheck`
116 echo "${msg}" | grep -q true
117 if [ "${?}" -eq 0 ]
118 then
119 healthy=true
120 break
121 fi
122 sleep 10s
Taka Cho6d188af2021-01-11 16:48:33 -0500123 done
Taka Cho6d188af2021-01-11 16:48:33 -0500124}
125
adheli.tavares80e382e2024-05-01 14:08:35 +0100126function setup_drools_apps() {
127 export ROBOT_FILES="drools-applications-test.robot"
128 source "${WORKSPACE}"/compose/start-compose.sh drools-applications
129 sleep 10
130 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${PAP_PORT}
131 sleep 10
132 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${DROOLS_APPS_PORT}
133 sleep 10
134 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${DROOLS_APPS_TELEMETRY_PORT}
Taka Cho6d188af2021-01-11 16:48:33 -0500135}
136
adheli.tavares80e382e2024-05-01 14:08:35 +0100137function setup_xacml_pdp() {
138 export ROBOT_FILES="xacml-pdp-test.robot"
139 source "${WORKSPACE}"/compose/start-compose.sh xacml-pdp
140 sleep 10
141 bash "${SCRIPTS}"/wait_for_rest.sh localhost "${XACML_PORT}"
Taka Cho6d188af2021-01-11 16:48:33 -0500142}
143
adheli.tavaresdaecbb92024-07-19 13:50:04 +0100144function setup_xacml_pdp_postgres() {
145 export ROBOT_FILES="xacml-pdp-test.robot"
146 source "${WORKSPACE}"/compose/start-postgres-tests.sh xacml-pdp 1
147 sleep 10
148 bash "${SCRIPTS}"/wait_for_rest.sh localhost "${XACML_PORT}"
149}
150
adheli.tavares80e382e2024-05-01 14:08:35 +0100151function setup_drools_pdp() {
152 export ROBOT_FILES="drools-pdp-test.robot"
153 source "${WORKSPACE}"/compose/start-compose.sh drools-pdp
154 sleep 30
155 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${DROOLS_TELEMETRY_PORT}
Taka Cho6d188af2021-01-11 16:48:33 -0500156}
157
adheli.tavares80e382e2024-05-01 14:08:35 +0100158function setup_distribution() {
159 zip -F ${WORKSPACE}/csit/resources/tests/data/csar/sample_csar_with_apex_policy.csar \
160 --out ${WORKSPACE}/csit/resources/tests/data/csar/csar_temp.csar -q
Taka Cho6d188af2021-01-11 16:48:33 -0500161
adheli.tavares80e382e2024-05-01 14:08:35 +0100162 # Remake temp directory
163 sudo rm -rf /tmp/distribution
164 sudo mkdir /tmp/distribution
Taka Cho6d188af2021-01-11 16:48:33 -0500165
adheli.tavares80e382e2024-05-01 14:08:35 +0100166 export ROBOT_FILES="distribution-test.robot"
167 source "${WORKSPACE}"/compose/start-compose.sh distribution
168 sleep 10
169 bash "${SCRIPTS}"/wait_for_rest.sh localhost "${DIST_PORT}"
170}
Taka Cho6d188af2021-01-11 16:48:33 -0500171
adheli.tavares80e382e2024-05-01 14:08:35 +0100172function build_robot_image() {
173 bash "${SCRIPTS}"/build-csit-docker-image.sh
174 cd ${WORKSPACE}
175}
176
177function run_robot() {
178 docker compose -f "${WORKSPACE}"/compose/docker-compose.yml up csit-tests
179 export RC=$?
180}
181
182function set_project_config() {
183 echo "Setting project configuration for: $PROJECT"
184 case $PROJECT in
185
186 clamp | policy-clamp)
187 setup_clamp
188 ;;
189
rameshiyer27f851a5e2024-07-02 09:16:56 +0000190 clamp-replica | policy-clamp-replica)
191 setup_clamp_replica
192 ;;
193
adheli.tavares80e382e2024-05-01 14:08:35 +0100194 api | policy-api)
195 setup_api
196 ;;
197
198 pap | policy-pap)
199 setup_pap
200 ;;
201
202 apex-pdp | policy-apex-pdp)
203 setup_apex
204 ;;
205
206 apex-pdp-postgres | policy-apex-pdp-postgres)
adheli.tavaresdaecbb92024-07-19 13:50:04 +0100207 setup_apex_postgres
adheli.tavares80e382e2024-05-01 14:08:35 +0100208 ;;
209
210 apex-pdp-medium | policy-apex-pdp-medium)
rameshiyer27f851a5e2024-07-02 09:16:56 +0000211 setup_apex_medium
adheli.tavares80e382e2024-05-01 14:08:35 +0100212 ;;
213
214 apex-pdp-large | policy-apex-pdp-large)
rameshiyer27f851a5e2024-07-02 09:16:56 +0000215 setup_apex_large
adheli.tavares80e382e2024-05-01 14:08:35 +0100216 ;;
217
218 xacml-pdp | policy-xacml-pdp)
219 setup_xacml_pdp
220 ;;
221
adheli.tavaresdaecbb92024-07-19 13:50:04 +0100222 xacml-pdp-postgres | policy-xacml-pdp-postgres)
223 setup_xacml_pdp_postgres
224 ;;
225
adheli.tavares80e382e2024-05-01 14:08:35 +0100226 drools-pdp | policy-drools-pdp)
227 setup_drools_pdp
228 ;;
229
230 drools-applications | policy-drools-applications | drools-apps | policy-drools-apps)
231 setup_drools_apps
232 ;;
233
234 distribution | policy-distribution)
235 setup_distribution
236 ;;
237
238 *)
239 echo "Unknown project supplied. No test will run."
240 exit 1
241 ;;
242 esac
243}
244
245# even with forced finish, clean up docker containers
246function on_exit(){
247 rm -rf ${WORKSPACE}/csit/resources/tests/data/csar/csar_temp.csar
248 source ${WORKSPACE}/compose/stop-compose.sh
249 cp ${WORKSPACE}/compose/*.log ${WORKSPACE}/csit/archives/${PROJECT}
250 exit $RC
251}
252
253# ensure that teardown and other finalizing steps are always executed
254trap on_exit EXIT
255
256# setup all directories used for test resources
Jim Hahn3486a922021-05-10 15:36:30 -0400257if [ -z "${WORKSPACE}" ]; then
adheli.tavares1f339f82023-02-17 15:14:07 +0000258 WORKSPACE=$(git rev-parse --show-toplevel)
259 export WORKSPACE
Taka Cho6d188af2021-01-11 16:48:33 -0500260fi
261
adheli.tavares80e382e2024-05-01 14:08:35 +0100262export GERRIT_BRANCH=$(awk -F= '$1 == "defaultbranch" { print $2 }' "${WORKSPACE}"/.gitreview)
Taka Cho6d188af2021-01-11 16:48:33 -0500263export PROJECT="${1}"
adheli.tavares80e382e2024-05-01 14:08:35 +0100264export ROBOT_LOG_DIR=${WORKSPACE}/csit/archives/${PROJECT}
265export SCRIPTS="${WORKSPACE}/csit/resources/scripts"
266export ROBOT_FILES=""
adheli.tavaresdaecbb92024-07-19 13:50:04 +0100267# always 'docker' if running docker compose
268export TEST_ENV="docker"
Jim Hahn3486a922021-05-10 15:36:30 -0400269
adheli.tavares1f339f82023-02-17 15:14:07 +0000270cd "${WORKSPACE}"
Taka Cho6d188af2021-01-11 16:48:33 -0500271
adheli.tavares80e382e2024-05-01 14:08:35 +0100272# recreate the log folder with test results
273sudo rm -rf ${ROBOT_LOG_DIR}
274mkdir -p ${ROBOT_LOG_DIR}
Taka Cho6d188af2021-01-11 16:48:33 -0500275
adheli.tavares80e382e2024-05-01 14:08:35 +0100276# log into nexus docker
Taka Cho6d188af2021-01-11 16:48:33 -0500277docker login -u docker -p docker nexus3.onap.org:10001
278
adheli.tavares80e382e2024-05-01 14:08:35 +0100279# based on $PROJECT var, setup robot test files and docker compose execution
280compose_version=$(docker compose version)
281
282if [[ $compose_version == *"Docker Compose version"* ]]; then
283 echo $compose_version
284else
285 echo "Docker Compose Plugin not installed. Installing now..."
286 sudo mkdir -p /usr/local/lib/docker/cli-plugins
287 sudo curl -SL https://github.com/docker/compose/releases/download/v2.27.0/docker-compose-linux-x86_64 -o /usr/local/lib/docker/cli-plugins/docker-compose
288 sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
Taka Cho6d188af2021-01-11 16:48:33 -0500289fi
290
adheli.tavares80e382e2024-05-01 14:08:35 +0100291set_project_config
292
293unset http_proxy https_proxy
294
295export ROBOT_FILES
296
adheli.tavaresf11e6d92024-08-01 14:18:34 +0100297# use a separate script to build a CSIT docker image, to isolate the test run
adheli.tavares80e382e2024-05-01 14:08:35 +0100298if [ "${2}" == "--skip-build-csit" ]; then
299 echo "Skipping build csit robot image"
300else
301 build_robot_image
302fi
303
Jim Hahn3486a922021-05-10 15:36:30 -0400304docker_stats | tee "${WORKSPACE}/csit/archives/${PROJECT}/_sysinfo-1-after-setup.txt"
Taka Cho6d188af2021-01-11 16:48:33 -0500305
adheli.tavares80e382e2024-05-01 14:08:35 +0100306# start the CSIT container and run the tests
307run_robot
Taka Cho6d188af2021-01-11 16:48:33 -0500308
adheli.tavares80e382e2024-05-01 14:08:35 +0100309docker ps --format "table {{ .Names }}\t{{ .Status }}"