blob: a7f7e865e61f9beb474faa7a23e8c745751db813 [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() {
44 export ROBOT_FILES="policy-clamp-test.robot"
45 source "${WORKSPACE}"/compose/start-compose.sh policy-clamp-runtime-acm
46 sleep 30
47 bash "${SCRIPTS}"/wait_for_rest.sh localhost "${ACM_PORT}"
48 export CLAMP_K8S_TEST=false
Taka Cho6d188af2021-01-11 16:48:33 -050049}
50
adheli.tavares80e382e2024-05-01 14:08:35 +010051function setup_api() {
52 export ROBOT_FILES="api-test.robot api-slas.robot"
53 source "${WORKSPACE}"/compose/start-compose.sh api --grafana
54 sleep 10
55 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${API_PORT}
56}
Taka Cho6d188af2021-01-11 16:48:33 -050057
adheli.tavares80e382e2024-05-01 14:08:35 +010058function setup_pap() {
59 export ROBOT_FILES="pap-test.robot pap-slas.robot"
60 source "${WORKSPACE}"/compose/start-compose.sh apex-pdp --grafana
61 sleep 10
62 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${PAP_PORT}
63}
64
65function setup_apex() {
66 export ROBOT_FILES="apex-pdp-test.robot apex-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 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${APEX_PORT}
71 apex_healthcheck
72}
73
74function setup_apex_postgres() {
75 export ROBOT_FILES="apex-pdp-test.robot"
76 source "${WORKSPACE}"/compose/start-postgres-tests.sh 1
77 sleep 10
78 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${PAP_PORT}
79 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${APEX_PORT}
80 apex_healthcheck
81}
82
83function setup_apex_medium() {
84 export SUITES="apex-slas-3.robot"
85 source "${WORKSPACE}"/compose/start-multiple-pdp.sh 3
86 sleep 10
87 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${PAP_PORT}
88 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${APEX_PORT}
89 apex_healthcheck
90}
91
92function setup_apex_large() {
93 export ROBOT_FILES="apex-slas-10.robot"
94 source "${WORKSPACE}"/compose/start-multiple-pdp.sh 10
95 sleep 10
96 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${PAP_PORT}
97 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${APEX_PORT}
98 apex_healthcheck
99}
100
101function apex_healthcheck() {
102 sleep 20
103
104 healthy=false
105
106 while [ $healthy = false ]
107 do
108 msg=`curl -s -k --user 'policyadmin:zb!XztG34' http://localhost:${APEX_PORT}/policy/apex-pdp/v1/healthcheck`
109 echo "${msg}" | grep -q true
110 if [ "${?}" -eq 0 ]
111 then
112 healthy=true
113 break
114 fi
115 sleep 10s
Taka Cho6d188af2021-01-11 16:48:33 -0500116 done
Taka Cho6d188af2021-01-11 16:48:33 -0500117}
118
adheli.tavares80e382e2024-05-01 14:08:35 +0100119function setup_drools_apps() {
120 export ROBOT_FILES="drools-applications-test.robot"
121 source "${WORKSPACE}"/compose/start-compose.sh drools-applications
122 sleep 10
123 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${PAP_PORT}
124 sleep 10
125 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${DROOLS_APPS_PORT}
126 sleep 10
127 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${DROOLS_APPS_TELEMETRY_PORT}
Taka Cho6d188af2021-01-11 16:48:33 -0500128}
129
adheli.tavares80e382e2024-05-01 14:08:35 +0100130function setup_xacml_pdp() {
131 export ROBOT_FILES="xacml-pdp-test.robot"
132 source "${WORKSPACE}"/compose/start-compose.sh xacml-pdp
133 sleep 10
134 bash "${SCRIPTS}"/wait_for_rest.sh localhost "${XACML_PORT}"
Taka Cho6d188af2021-01-11 16:48:33 -0500135}
136
adheli.tavares80e382e2024-05-01 14:08:35 +0100137function setup_drools_pdp() {
138 export ROBOT_FILES="drools-pdp-test.robot"
139 source "${WORKSPACE}"/compose/start-compose.sh drools-pdp
140 sleep 30
141 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${DROOLS_TELEMETRY_PORT}
Taka Cho6d188af2021-01-11 16:48:33 -0500142}
143
adheli.tavares80e382e2024-05-01 14:08:35 +0100144function setup_distribution() {
145 zip -F ${WORKSPACE}/csit/resources/tests/data/csar/sample_csar_with_apex_policy.csar \
146 --out ${WORKSPACE}/csit/resources/tests/data/csar/csar_temp.csar -q
Taka Cho6d188af2021-01-11 16:48:33 -0500147
adheli.tavares80e382e2024-05-01 14:08:35 +0100148 # Remake temp directory
149 sudo rm -rf /tmp/distribution
150 sudo mkdir /tmp/distribution
Taka Cho6d188af2021-01-11 16:48:33 -0500151
adheli.tavares80e382e2024-05-01 14:08:35 +0100152 export ROBOT_FILES="distribution-test.robot"
153 source "${WORKSPACE}"/compose/start-compose.sh distribution
154 sleep 10
155 bash "${SCRIPTS}"/wait_for_rest.sh localhost "${DIST_PORT}"
156}
Taka Cho6d188af2021-01-11 16:48:33 -0500157
adheli.tavares80e382e2024-05-01 14:08:35 +0100158function build_robot_image() {
159 bash "${SCRIPTS}"/build-csit-docker-image.sh
160 cd ${WORKSPACE}
161}
162
163function run_robot() {
164 docker compose -f "${WORKSPACE}"/compose/docker-compose.yml up csit-tests
165 export RC=$?
166}
167
168function set_project_config() {
169 echo "Setting project configuration for: $PROJECT"
170 case $PROJECT in
171
172 clamp | policy-clamp)
173 setup_clamp
174 ;;
175
176 api | policy-api)
177 setup_api
178 ;;
179
180 pap | policy-pap)
181 setup_pap
182 ;;
183
184 apex-pdp | policy-apex-pdp)
185 setup_apex
186 ;;
187
188 apex-pdp-postgres | policy-apex-pdp-postgres)
189 setup_apex
190 ;;
191
192 apex-pdp-medium | policy-apex-pdp-medium)
193 setup_apex
194 ;;
195
196 apex-pdp-large | policy-apex-pdp-large)
197 setup_apex
198 ;;
199
200 xacml-pdp | policy-xacml-pdp)
201 setup_xacml_pdp
202 ;;
203
204 drools-pdp | policy-drools-pdp)
205 setup_drools_pdp
206 ;;
207
208 drools-applications | policy-drools-applications | drools-apps | policy-drools-apps)
209 setup_drools_apps
210 ;;
211
212 distribution | policy-distribution)
213 setup_distribution
214 ;;
215
216 *)
217 echo "Unknown project supplied. No test will run."
218 exit 1
219 ;;
220 esac
221}
222
223# even with forced finish, clean up docker containers
224function on_exit(){
225 rm -rf ${WORKSPACE}/csit/resources/tests/data/csar/csar_temp.csar
226 source ${WORKSPACE}/compose/stop-compose.sh
227 cp ${WORKSPACE}/compose/*.log ${WORKSPACE}/csit/archives/${PROJECT}
228 exit $RC
229}
230
231# ensure that teardown and other finalizing steps are always executed
232trap on_exit EXIT
233
234# setup all directories used for test resources
Jim Hahn3486a922021-05-10 15:36:30 -0400235if [ -z "${WORKSPACE}" ]; then
adheli.tavares1f339f82023-02-17 15:14:07 +0000236 WORKSPACE=$(git rev-parse --show-toplevel)
237 export WORKSPACE
Taka Cho6d188af2021-01-11 16:48:33 -0500238fi
239
adheli.tavares80e382e2024-05-01 14:08:35 +0100240export GERRIT_BRANCH=$(awk -F= '$1 == "defaultbranch" { print $2 }' "${WORKSPACE}"/.gitreview)
Taka Cho6d188af2021-01-11 16:48:33 -0500241export PROJECT="${1}"
adheli.tavares80e382e2024-05-01 14:08:35 +0100242export ROBOT_LOG_DIR=${WORKSPACE}/csit/archives/${PROJECT}
243export SCRIPTS="${WORKSPACE}/csit/resources/scripts"
244export ROBOT_FILES=""
Jim Hahn3486a922021-05-10 15:36:30 -0400245
adheli.tavares1f339f82023-02-17 15:14:07 +0000246cd "${WORKSPACE}"
Taka Cho6d188af2021-01-11 16:48:33 -0500247
adheli.tavares80e382e2024-05-01 14:08:35 +0100248# recreate the log folder with test results
249sudo rm -rf ${ROBOT_LOG_DIR}
250mkdir -p ${ROBOT_LOG_DIR}
Taka Cho6d188af2021-01-11 16:48:33 -0500251
adheli.tavares80e382e2024-05-01 14:08:35 +0100252# log into nexus docker
Taka Cho6d188af2021-01-11 16:48:33 -0500253docker login -u docker -p docker nexus3.onap.org:10001
254
adheli.tavares80e382e2024-05-01 14:08:35 +0100255# based on $PROJECT var, setup robot test files and docker compose execution
256compose_version=$(docker compose version)
257
258if [[ $compose_version == *"Docker Compose version"* ]]; then
259 echo $compose_version
260else
261 echo "Docker Compose Plugin not installed. Installing now..."
262 sudo mkdir -p /usr/local/lib/docker/cli-plugins
263 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
264 sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
Taka Cho6d188af2021-01-11 16:48:33 -0500265fi
266
adheli.tavares80e382e2024-05-01 14:08:35 +0100267set_project_config
268
269unset http_proxy https_proxy
270
271export ROBOT_FILES
272
273# use a separate script to build a CSIT docker image, to containerize the test run
274if [ "${2}" == "--skip-build-csit" ]; then
275 echo "Skipping build csit robot image"
276else
277 build_robot_image
278fi
279
Jim Hahn3486a922021-05-10 15:36:30 -0400280docker_stats | tee "${WORKSPACE}/csit/archives/${PROJECT}/_sysinfo-1-after-setup.txt"
Taka Cho6d188af2021-01-11 16:48:33 -0500281
adheli.tavares80e382e2024-05-01 14:08:35 +0100282# start the CSIT container and run the tests
283run_robot
Taka Cho6d188af2021-01-11 16:48:33 -0500284
adheli.tavares80e382e2024-05-01 14:08:35 +0100285docker ps --format "table {{ .Names }}\t{{ .Status }}"