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}" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 48 | } |
| 49 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 50 | function 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 Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 56 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 57 | function 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 | |
| 64 | function 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 | |
| 73 | function 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 | |
| 82 | function 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 | |
| 91 | function 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 | |
| 100 | function 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 Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 115 | done |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 116 | } |
| 117 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 118 | function 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 Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 127 | } |
| 128 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 129 | function 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 Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 134 | } |
| 135 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 136 | function 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 Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 141 | } |
| 142 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 143 | function 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 Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 146 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 147 | # Remake temp directory |
| 148 | sudo rm -rf /tmp/distribution |
| 149 | sudo mkdir /tmp/distribution |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 150 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 151 | 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 Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 156 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 157 | function build_robot_image() { |
| 158 | bash "${SCRIPTS}"/build-csit-docker-image.sh |
| 159 | cd ${WORKSPACE} |
| 160 | } |
| 161 | |
| 162 | function run_robot() { |
| 163 | docker compose -f "${WORKSPACE}"/compose/docker-compose.yml up csit-tests |
| 164 | export RC=$? |
| 165 | } |
| 166 | |
| 167 | function 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 |
| 223 | function 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 |
| 231 | trap on_exit EXIT |
| 232 | |
| 233 | # setup all directories used for test resources |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 234 | if [ -z "${WORKSPACE}" ]; then |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 235 | WORKSPACE=$(git rev-parse --show-toplevel) |
| 236 | export WORKSPACE |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 237 | fi |
| 238 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 239 | export GERRIT_BRANCH=$(awk -F= '$1 == "defaultbranch" { print $2 }' "${WORKSPACE}"/.gitreview) |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 240 | export PROJECT="${1}" |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 241 | export ROBOT_LOG_DIR=${WORKSPACE}/csit/archives/${PROJECT} |
| 242 | export SCRIPTS="${WORKSPACE}/csit/resources/scripts" |
| 243 | export ROBOT_FILES="" |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 244 | |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 245 | cd "${WORKSPACE}" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 246 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 247 | # recreate the log folder with test results |
| 248 | sudo rm -rf ${ROBOT_LOG_DIR} |
| 249 | mkdir -p ${ROBOT_LOG_DIR} |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 250 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 251 | # log into nexus docker |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 252 | docker login -u docker -p docker nexus3.onap.org:10001 |
| 253 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 254 | # based on $PROJECT var, setup robot test files and docker compose execution |
| 255 | compose_version=$(docker compose version) |
| 256 | |
| 257 | if [[ $compose_version == *"Docker Compose version"* ]]; then |
| 258 | echo $compose_version |
| 259 | else |
| 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 Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 264 | fi |
| 265 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 266 | set_project_config |
| 267 | |
| 268 | unset http_proxy https_proxy |
| 269 | |
| 270 | export ROBOT_FILES |
| 271 | |
| 272 | # use a separate script to build a CSIT docker image, to containerize the test run |
| 273 | if [ "${2}" == "--skip-build-csit" ]; then |
| 274 | echo "Skipping build csit robot image" |
| 275 | else |
| 276 | build_robot_image |
| 277 | fi |
| 278 | |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 279 | docker_stats | tee "${WORKSPACE}/csit/archives/${PROJECT}/_sysinfo-1-after-setup.txt" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 280 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 281 | # start the CSIT container and run the tests |
| 282 | run_robot |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 283 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 284 | docker ps --format "table {{ .Names }}\t{{ .Status }}" |