waynedunican | e4ff7e5 | 2023-03-01 09:07:31 +0000 | [diff] [blame] | 1 | #!/bin/bash |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 2 | # |
| 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.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 6 | # Modification Copyright 2021-2024 Nordix Foundation. |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 7 | # |
| 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 Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 20 | |
| 21 | function docker_stats(){ |
liamfallon | faac45b | 2022-09-01 12:05:47 +0100 | [diff] [blame] | 22 | # General memory details |
| 23 | if [ "$(uname -s)" == "Darwin" ] |
| 24 | then |
liamfallon | faac45b | 2022-09-01 12:05:47 +0100 | [diff] [blame] | 25 | sh -c "top -l1 | head -10" |
| 26 | echo |
| 27 | else |
liamfallon | faac45b | 2022-09-01 12:05:47 +0100 | [diff] [blame] | 28 | sh -c "top -bn1 | head -3" |
| 29 | echo |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 30 | |
liamfallon | faac45b | 2022-09-01 12:05:47 +0100 | [diff] [blame] | 31 | sh -c "free -h" |
| 32 | echo |
| 33 | fi |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 34 | |
liamfallon | faac45b | 2022-09-01 12:05:47 +0100 | [diff] [blame] | 35 | # Memory details per Docker |
adheli.tavares | 9fc9fa4 | 2023-02-09 11:56:27 +0000 | [diff] [blame] | 36 | docker ps --format "table {{ .Names }}\t{{ .Status }}" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 37 | echo |
| 38 | |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 39 | docker stats --no-stream |
| 40 | echo |
| 41 | } |
| 42 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 43 | function 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 Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 49 | } |
| 50 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 51 | function 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 Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 57 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 58 | function 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 | |
| 65 | function 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 | |
| 74 | function 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 | |
| 83 | function 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 | |
| 92 | function 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 | |
| 101 | function 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 Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 116 | done |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 117 | } |
| 118 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 119 | function 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 Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 128 | } |
| 129 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 130 | function 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 Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 135 | } |
| 136 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 137 | function 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 Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 142 | } |
| 143 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 144 | function 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 Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 147 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 148 | # Remake temp directory |
| 149 | sudo rm -rf /tmp/distribution |
| 150 | sudo mkdir /tmp/distribution |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 151 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 152 | 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 Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 157 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 158 | function build_robot_image() { |
| 159 | bash "${SCRIPTS}"/build-csit-docker-image.sh |
| 160 | cd ${WORKSPACE} |
| 161 | } |
| 162 | |
| 163 | function run_robot() { |
| 164 | docker compose -f "${WORKSPACE}"/compose/docker-compose.yml up csit-tests |
| 165 | export RC=$? |
| 166 | } |
| 167 | |
| 168 | function 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 |
| 224 | function 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 |
| 232 | trap on_exit EXIT |
| 233 | |
| 234 | # setup all directories used for test resources |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 235 | if [ -z "${WORKSPACE}" ]; then |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 236 | WORKSPACE=$(git rev-parse --show-toplevel) |
| 237 | export WORKSPACE |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 238 | fi |
| 239 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 240 | export GERRIT_BRANCH=$(awk -F= '$1 == "defaultbranch" { print $2 }' "${WORKSPACE}"/.gitreview) |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 241 | export PROJECT="${1}" |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 242 | export ROBOT_LOG_DIR=${WORKSPACE}/csit/archives/${PROJECT} |
| 243 | export SCRIPTS="${WORKSPACE}/csit/resources/scripts" |
| 244 | export ROBOT_FILES="" |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 245 | |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 246 | cd "${WORKSPACE}" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 247 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 248 | # recreate the log folder with test results |
| 249 | sudo rm -rf ${ROBOT_LOG_DIR} |
| 250 | mkdir -p ${ROBOT_LOG_DIR} |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 251 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 252 | # log into nexus docker |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 253 | docker login -u docker -p docker nexus3.onap.org:10001 |
| 254 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 255 | # based on $PROJECT var, setup robot test files and docker compose execution |
| 256 | compose_version=$(docker compose version) |
| 257 | |
| 258 | if [[ $compose_version == *"Docker Compose version"* ]]; then |
| 259 | echo $compose_version |
| 260 | else |
| 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 Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 265 | fi |
| 266 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 267 | set_project_config |
| 268 | |
| 269 | unset http_proxy https_proxy |
| 270 | |
| 271 | export ROBOT_FILES |
| 272 | |
| 273 | # use a separate script to build a CSIT docker image, to containerize the test run |
| 274 | if [ "${2}" == "--skip-build-csit" ]; then |
| 275 | echo "Skipping build csit robot image" |
| 276 | else |
| 277 | build_robot_image |
| 278 | fi |
| 279 | |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 280 | docker_stats | tee "${WORKSPACE}/csit/archives/${PROJECT}/_sysinfo-1-after-setup.txt" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 281 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 282 | # start the CSIT container and run the tests |
| 283 | run_robot |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 284 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 285 | docker ps --format "table {{ .Names }}\t{{ .Status }}" |