blob: bd2a33eb73221f7f058ce4824ef76e6ee8da9bc1 [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}"
Taka Cho6d188af2021-01-11 16:48:33 -050048}
49
adheli.tavares80e382e2024-05-01 14:08:35 +010050function setup_api() {
51 export ROBOT_FILES="api-test.robot api-slas.robot"
52 source "${WORKSPACE}"/compose/start-compose.sh api --grafana
53 sleep 10
54 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${API_PORT}
55}
Taka Cho6d188af2021-01-11 16:48:33 -050056
adheli.tavares80e382e2024-05-01 14:08:35 +010057function setup_pap() {
58 export ROBOT_FILES="pap-test.robot pap-slas.robot"
59 source "${WORKSPACE}"/compose/start-compose.sh apex-pdp --grafana
60 sleep 10
61 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${PAP_PORT}
62}
63
64function setup_apex() {
65 export ROBOT_FILES="apex-pdp-test.robot apex-slas.robot"
66 source "${WORKSPACE}"/compose/start-compose.sh apex-pdp --grafana
67 sleep 10
68 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${PAP_PORT}
69 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${APEX_PORT}
70 apex_healthcheck
71}
72
73function setup_apex_postgres() {
74 export ROBOT_FILES="apex-pdp-test.robot"
75 source "${WORKSPACE}"/compose/start-postgres-tests.sh 1
76 sleep 10
77 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${PAP_PORT}
78 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${APEX_PORT}
79 apex_healthcheck
80}
81
82function setup_apex_medium() {
83 export SUITES="apex-slas-3.robot"
84 source "${WORKSPACE}"/compose/start-multiple-pdp.sh 3
85 sleep 10
86 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${PAP_PORT}
87 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${APEX_PORT}
88 apex_healthcheck
89}
90
91function setup_apex_large() {
92 export ROBOT_FILES="apex-slas-10.robot"
93 source "${WORKSPACE}"/compose/start-multiple-pdp.sh 10
94 sleep 10
95 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${PAP_PORT}
96 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${APEX_PORT}
97 apex_healthcheck
98}
99
100function apex_healthcheck() {
101 sleep 20
102
103 healthy=false
104
105 while [ $healthy = false ]
106 do
107 msg=`curl -s -k --user 'policyadmin:zb!XztG34' http://localhost:${APEX_PORT}/policy/apex-pdp/v1/healthcheck`
108 echo "${msg}" | grep -q true
109 if [ "${?}" -eq 0 ]
110 then
111 healthy=true
112 break
113 fi
114 sleep 10s
Taka Cho6d188af2021-01-11 16:48:33 -0500115 done
Taka Cho6d188af2021-01-11 16:48:33 -0500116}
117
adheli.tavares80e382e2024-05-01 14:08:35 +0100118function setup_drools_apps() {
119 export ROBOT_FILES="drools-applications-test.robot"
120 source "${WORKSPACE}"/compose/start-compose.sh drools-applications
121 sleep 10
122 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${PAP_PORT}
123 sleep 10
124 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${DROOLS_APPS_PORT}
125 sleep 10
126 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${DROOLS_APPS_TELEMETRY_PORT}
Taka Cho6d188af2021-01-11 16:48:33 -0500127}
128
adheli.tavares80e382e2024-05-01 14:08:35 +0100129function setup_xacml_pdp() {
130 export ROBOT_FILES="xacml-pdp-test.robot"
131 source "${WORKSPACE}"/compose/start-compose.sh xacml-pdp
132 sleep 10
133 bash "${SCRIPTS}"/wait_for_rest.sh localhost "${XACML_PORT}"
Taka Cho6d188af2021-01-11 16:48:33 -0500134}
135
adheli.tavares80e382e2024-05-01 14:08:35 +0100136function setup_drools_pdp() {
137 export ROBOT_FILES="drools-pdp-test.robot"
138 source "${WORKSPACE}"/compose/start-compose.sh drools-pdp
139 sleep 30
140 bash "${SCRIPTS}"/wait_for_rest.sh localhost ${DROOLS_TELEMETRY_PORT}
Taka Cho6d188af2021-01-11 16:48:33 -0500141}
142
adheli.tavares80e382e2024-05-01 14:08:35 +0100143function setup_distribution() {
144 zip -F ${WORKSPACE}/csit/resources/tests/data/csar/sample_csar_with_apex_policy.csar \
145 --out ${WORKSPACE}/csit/resources/tests/data/csar/csar_temp.csar -q
Taka Cho6d188af2021-01-11 16:48:33 -0500146
adheli.tavares80e382e2024-05-01 14:08:35 +0100147 # Remake temp directory
148 sudo rm -rf /tmp/distribution
149 sudo mkdir /tmp/distribution
Taka Cho6d188af2021-01-11 16:48:33 -0500150
adheli.tavares80e382e2024-05-01 14:08:35 +0100151 export ROBOT_FILES="distribution-test.robot"
152 source "${WORKSPACE}"/compose/start-compose.sh distribution
153 sleep 10
154 bash "${SCRIPTS}"/wait_for_rest.sh localhost "${DIST_PORT}"
155}
Taka Cho6d188af2021-01-11 16:48:33 -0500156
adheli.tavares80e382e2024-05-01 14:08:35 +0100157function build_robot_image() {
158 bash "${SCRIPTS}"/build-csit-docker-image.sh
159 cd ${WORKSPACE}
160}
161
162function run_robot() {
163 docker compose -f "${WORKSPACE}"/compose/docker-compose.yml up csit-tests
164 export RC=$?
165}
166
167function set_project_config() {
168 echo "Setting project configuration for: $PROJECT"
169 case $PROJECT in
170
171 clamp | policy-clamp)
172 setup_clamp
173 ;;
174
175 api | policy-api)
176 setup_api
177 ;;
178
179 pap | policy-pap)
180 setup_pap
181 ;;
182
183 apex-pdp | policy-apex-pdp)
184 setup_apex
185 ;;
186
187 apex-pdp-postgres | policy-apex-pdp-postgres)
188 setup_apex
189 ;;
190
191 apex-pdp-medium | policy-apex-pdp-medium)
192 setup_apex
193 ;;
194
195 apex-pdp-large | policy-apex-pdp-large)
196 setup_apex
197 ;;
198
199 xacml-pdp | policy-xacml-pdp)
200 setup_xacml_pdp
201 ;;
202
203 drools-pdp | policy-drools-pdp)
204 setup_drools_pdp
205 ;;
206
207 drools-applications | policy-drools-applications | drools-apps | policy-drools-apps)
208 setup_drools_apps
209 ;;
210
211 distribution | policy-distribution)
212 setup_distribution
213 ;;
214
215 *)
216 echo "Unknown project supplied. No test will run."
217 exit 1
218 ;;
219 esac
220}
221
222# even with forced finish, clean up docker containers
223function on_exit(){
224 rm -rf ${WORKSPACE}/csit/resources/tests/data/csar/csar_temp.csar
225 source ${WORKSPACE}/compose/stop-compose.sh
226 cp ${WORKSPACE}/compose/*.log ${WORKSPACE}/csit/archives/${PROJECT}
227 exit $RC
228}
229
230# ensure that teardown and other finalizing steps are always executed
231trap on_exit EXIT
232
233# setup all directories used for test resources
Jim Hahn3486a922021-05-10 15:36:30 -0400234if [ -z "${WORKSPACE}" ]; then
adheli.tavares1f339f82023-02-17 15:14:07 +0000235 WORKSPACE=$(git rev-parse --show-toplevel)
236 export WORKSPACE
Taka Cho6d188af2021-01-11 16:48:33 -0500237fi
238
adheli.tavares80e382e2024-05-01 14:08:35 +0100239export GERRIT_BRANCH=$(awk -F= '$1 == "defaultbranch" { print $2 }' "${WORKSPACE}"/.gitreview)
Taka Cho6d188af2021-01-11 16:48:33 -0500240export PROJECT="${1}"
adheli.tavares80e382e2024-05-01 14:08:35 +0100241export ROBOT_LOG_DIR=${WORKSPACE}/csit/archives/${PROJECT}
242export SCRIPTS="${WORKSPACE}/csit/resources/scripts"
243export ROBOT_FILES=""
Jim Hahn3486a922021-05-10 15:36:30 -0400244
adheli.tavares1f339f82023-02-17 15:14:07 +0000245cd "${WORKSPACE}"
Taka Cho6d188af2021-01-11 16:48:33 -0500246
adheli.tavares80e382e2024-05-01 14:08:35 +0100247# recreate the log folder with test results
248sudo rm -rf ${ROBOT_LOG_DIR}
249mkdir -p ${ROBOT_LOG_DIR}
Taka Cho6d188af2021-01-11 16:48:33 -0500250
adheli.tavares80e382e2024-05-01 14:08:35 +0100251# log into nexus docker
Taka Cho6d188af2021-01-11 16:48:33 -0500252docker login -u docker -p docker nexus3.onap.org:10001
253
adheli.tavares80e382e2024-05-01 14:08:35 +0100254# based on $PROJECT var, setup robot test files and docker compose execution
255compose_version=$(docker compose version)
256
257if [[ $compose_version == *"Docker Compose version"* ]]; then
258 echo $compose_version
259else
260 echo "Docker Compose Plugin not installed. Installing now..."
261 sudo mkdir -p /usr/local/lib/docker/cli-plugins
262 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
263 sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
Taka Cho6d188af2021-01-11 16:48:33 -0500264fi
265
adheli.tavares80e382e2024-05-01 14:08:35 +0100266set_project_config
267
268unset http_proxy https_proxy
269
270export ROBOT_FILES
271
272# use a separate script to build a CSIT docker image, to containerize the test run
273if [ "${2}" == "--skip-build-csit" ]; then
274 echo "Skipping build csit robot image"
275else
276 build_robot_image
277fi
278
Jim Hahn3486a922021-05-10 15:36:30 -0400279docker_stats | tee "${WORKSPACE}/csit/archives/${PROJECT}/_sysinfo-1-after-setup.txt"
Taka Cho6d188af2021-01-11 16:48:33 -0500280
adheli.tavares80e382e2024-05-01 14:08:35 +0100281# start the CSIT container and run the tests
282run_robot
Taka Cho6d188af2021-01-11 16:48:33 -0500283
adheli.tavares80e382e2024-05-01 14:08:35 +0100284docker ps --format "table {{ .Names }}\t{{ .Status }}"