BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # ============LICENSE_START=============================================== |
| 4 | # Copyright (C) 2020 Nordix Foundation. All rights reserved. |
| 5 | # ======================================================================== |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # ============LICENSE_END================================================= |
| 18 | # |
| 19 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 20 | # This is a script that contains container/service management functions and test functions for A1 Controller API |
| 21 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 22 | ################ Test engine functions ################ |
| 23 | |
| 24 | # Create the image var used during the test |
| 25 | # arg: <image-tag-suffix> (selects staging, snapshot, release etc) |
| 26 | # <image-tag-suffix> is present only for images with staging, snapshot,release tags |
| 27 | __SDNC_imagesetup() { |
| 28 | |
| 29 | sdnc_suffix_tag=$1 |
| 30 | |
| 31 | for oia_name in $ONAP_IMAGES_APP_NAMES; do |
| 32 | if [ "$oia_name" == "SDNC" ]; then |
| 33 | sdnc_suffix_tag="REMOTE_RELEASE_ONAP" |
| 34 | fi |
| 35 | done |
| 36 | __check_and_create_image_var SDNC "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_IMAGE_BASE" "SDNC_A1_CONTROLLER_IMAGE_TAG" $sdnc_suffix_tag "$SDNC_DISPLAY_NAME" |
| 37 | __check_and_create_image_var SDNC "SDNC_DB_IMAGE" "SDNC_DB_IMAGE_BASE" "SDNC_DB_IMAGE_TAG" REMOTE_PROXY "SDNC DB" |
| 38 | |
| 39 | } |
| 40 | |
| 41 | # Pull image from remote repo or use locally built image |
| 42 | # arg: <pull-policy-override> <pull-policy-original> |
| 43 | # <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images |
| 44 | # <pull-policy-original> Shall be used for images that does not allow overriding |
| 45 | # Both var may contain: 'remote', 'remote-remove' or 'local' |
| 46 | __SDNC_imagepull() { |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame^] | 47 | __check_and_pull_image $1 "$SDNC_DISPLAY_NAME" $SDNC_APP_NAME SDNC_A1_CONTROLLER_IMAGE |
| 48 | __check_and_pull_image $2 "SDNC DB" $SDNC_APP_NAME SDNC_DB_IMAGE |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | # Build image (only for simulator or interfaces stubs owned by the test environment) |
| 52 | # arg: <image-tag-suffix> (selects staging, snapshot, release etc) |
| 53 | # <image-tag-suffix> is present only for images with staging, snapshot,release tags |
| 54 | __SDNC_imagebuild() { |
| 55 | echo -e $RED" Image for app SDNC shall never be built"$ERED |
| 56 | } |
| 57 | |
| 58 | # Generate a string for each included image using the app display name and a docker images format string |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame^] | 59 | # If a custom image repo is used then also the source image from the local repo is listed |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 60 | # arg: <docker-images-format-string> <file-to-append> |
| 61 | __SDNC_image_data() { |
| 62 | echo -e "$SDNC_DISPLAY_NAME\t$(docker images --format $1 $SDNC_A1_CONTROLLER_IMAGE)" >> $2 |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame^] | 63 | if [ ! -z "$SDNC_A1_CONTROLLER_IMAGE_SOURCE" ]; then |
| 64 | echo -e "-- source image --\t$(docker images --format $1 $SDNC_A1_CONTROLLER_IMAGE_SOURCE)" >> $2 |
| 65 | fi |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 66 | echo -e "SDNC DB\t$(docker images --format $1 $SDNC_DB_IMAGE)" >> $2 |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame^] | 67 | if [ ! -z "$SDNC_DB_IMAGE_SOURCE" ]; then |
| 68 | echo -e "-- source image --\t$(docker images --format $1 $SDNC_DB_IMAGE_SOURCE)" >> $2 |
| 69 | fi |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | # Scale kubernetes resources to zero |
| 73 | # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action. |
| 74 | # This function is called for apps fully managed by the test script |
| 75 | __SDNC_kube_scale_zero() { |
| 76 | __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest SDNC |
| 77 | } |
| 78 | |
| 79 | # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action. |
| 80 | # This function is called for prestarted apps not managed by the test script. |
| 81 | __SDNC_kube_scale_zero_and_wait() { |
| 82 | echo -e " SDNC replicas kept as is" |
| 83 | } |
| 84 | |
| 85 | # Delete all kube resouces for the app |
| 86 | # This function is called for apps managed by the test script. |
| 87 | __SDNC_kube_delete_all() { |
| 88 | __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest SDNC |
| 89 | } |
| 90 | |
| 91 | # Store docker logs |
| 92 | # This function is called for apps managed by the test script. |
| 93 | # args: <log-dir> <file-prexix> |
| 94 | __SDNC_store_docker_logs() { |
| 95 | docker exec -t $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $1$2_SDNC_karaf.log 2>&1 |
| 96 | } |
| 97 | |
| 98 | ####################################################### |
| 99 | |
| 100 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 101 | SDNC_HTTPX="http" |
| 102 | SDNC_HOST_NAME=$LOCALHOST_NAME |
| 103 | SDNC_PATH=$SDNC_HTTPX"://"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_PORT |
| 104 | SDNC_API_PATH=$SDNC_HTTPX"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_PORT$SDNC_API_URL |
| 105 | #Docker/Kube internal path |
| 106 | if [ $RUNMODE == "KUBE" ]; then |
| 107 | SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_EXTERNAL_PORT |
| 108 | #presume correct |
| 109 | SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME"."$KUBE_NONRTRIC_NAMESPACE":"$SDNC_EXTERNAL_PORT |
| 110 | #test |
| 111 | #SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME"."$KUBE_NONRTRIC_NAMESPACE":"$SDNC_EXTERNAL_PORT |
| 112 | else |
| 113 | SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_INTERNAL_PORT |
| 114 | fi |
| 115 | |
| 116 | use_sdnc_http() { |
| 117 | echo -e $BOLD"SDNC NB protocol setting"$EBOLD |
| 118 | echo -e " Using $BOLD http $EBOLD towards SDNC" |
| 119 | SDNC_HTTPX="http" |
| 120 | SDNC_PATH=$SDNC_HTTPX"://"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_PORT |
| 121 | SDNC_API_PATH=$SDNC_HTTPX"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_PORT$SDNC_API_URL |
| 122 | if [ $RUNMODE == "KUBE" ]; then |
| 123 | #presume correct |
| 124 | SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME"."$KUBE_NONRTRIC_NAMESPACE":"$SDNC_EXTERNAL_PORT |
| 125 | #test |
| 126 | #SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_EXTERNAL_PORT |
| 127 | else |
| 128 | SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_INTERNAL_PORT |
| 129 | fi |
| 130 | echo "" |
| 131 | } |
| 132 | |
| 133 | use_sdnc_https() { |
| 134 | echo -e $BOLD"SDNC NB protocol setting"$EBOLD |
| 135 | echo -e " Using $BOLD https $EBOLD towards SDNC" |
| 136 | SDNC_HTTPX="https" |
| 137 | SDNC_PATH=$SDNC_HTTPX"://"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_SECURE_PORT |
| 138 | SDNC_API_PATH=$SDNC_HTTPX"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_SECURE_PORT$SDNC_API_URL |
| 139 | if [ $RUNMODE == "KUBE" ]; then |
| 140 | #presume correct |
| 141 | SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME"."$KUBE_NONRTRIC_NAMESPACE":"$SDNC_EXTERNAL_SECURE_PORT |
| 142 | #test |
| 143 | #SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_EXTERNAL_SECURE_PORT |
| 144 | else |
| 145 | SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_INTERNAL_SECURE_PORT |
| 146 | fi |
| 147 | echo "" |
| 148 | } |
| 149 | |
| 150 | ################## |
| 151 | ### SDNC functions |
| 152 | ################## |
| 153 | |
| 154 | # Start the SDNC A1 Controller |
| 155 | # args: - |
| 156 | # (Function for test scripts) |
| 157 | start_sdnc() { |
| 158 | |
| 159 | echo -e $BOLD"Starting $SDNC_DISPLAY_NAME"$EBOLD |
| 160 | |
| 161 | if [ $RUNMODE == "KUBE" ]; then |
| 162 | |
| 163 | # Check if app shall be fully managed by the test script |
| 164 | __check_included_image "SDNC" |
| 165 | retcode_i=$? |
| 166 | |
| 167 | # Check if app shall only be used by the testscipt |
| 168 | __check_prestarted_image "SDNC" |
| 169 | retcode_p=$? |
| 170 | |
| 171 | if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then |
| 172 | echo -e $RED"The $SDNC_APP_NAME app is not included as managed nor prestarted in this test script"$ERED |
| 173 | echo -e $RED"The $SDNC_APP_NAME will not be started"$ERED |
| 174 | exit |
| 175 | fi |
| 176 | if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then |
| 177 | echo -e $RED"The $SDNC_APP_NAME app is included both as managed and prestarted in this test script"$ERED |
| 178 | echo -e $RED"The $SDNC_APP_NAME will not be started"$ERED |
| 179 | exit |
| 180 | fi |
| 181 | |
| 182 | |
| 183 | if [ $retcode_p -eq 0 ]; then |
| 184 | echo -e " Using existing $SDNC_APP_NAME deployment and service" |
| 185 | echo " Setting SDNC replicas=1" |
| 186 | __kube_scale deployment $SDNC_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1 |
| 187 | fi |
| 188 | |
| 189 | # Check if app shall be fully managed by the test script |
| 190 | if [ $retcode_i -eq 0 ]; then |
| 191 | |
| 192 | echo -e " Creating $SDNC_APP_NAME app and expose service" |
| 193 | |
| 194 | #Check if nonrtric namespace exists, if not create it |
| 195 | __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE |
| 196 | |
| 197 | export KUBE_NONRTRIC_NAMESPACE |
| 198 | export SDNC_APP_NAME |
| 199 | export SDNC_A1_CONTROLLER_IMAGE |
| 200 | export SDNC_INTERNAL_PORT |
| 201 | export SDNC_EXTERNAL_PORT |
| 202 | export SDNC_INTERNAL_SECURE_PORT |
| 203 | export SDNC_EXTERNAL_SECURE_PORT |
| 204 | export SDNC_A1_TRUSTSTORE_PASSWORD |
| 205 | export SDNC_DB_APP_NAME |
| 206 | export SDNC_DB_IMAGE |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 207 | export SDNC_USER |
| 208 | export SDNC_PWD |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 209 | |
| 210 | # Create service |
| 211 | input_yaml=$SIM_GROUP"/"$SDNC_COMPOSE_DIR"/"svc.yaml |
| 212 | output_yaml=$PWD/tmp/sdnc_svc.yaml |
| 213 | __kube_create_instance service $SDNC_APP_NAME $input_yaml $output_yaml |
| 214 | |
| 215 | # Create app |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 216 | input_yaml=$SIM_GROUP"/"$SDNC_COMPOSE_DIR"/"$SDNC_KUBE_APP_FILE |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 217 | output_yaml=$PWD/tmp/sdnc_app.yaml |
| 218 | __kube_create_instance app $SDNC_APP_NAME $input_yaml $output_yaml |
| 219 | |
| 220 | fi |
| 221 | |
| 222 | echo " Retrieving host and ports for service..." |
| 223 | SDNC_HOST_NAME=$(__kube_get_service_host $SDNC_APP_NAME $KUBE_NONRTRIC_NAMESPACE) |
| 224 | SDNC_EXTERNAL_PORT=$(__kube_get_service_port $SDNC_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http") |
| 225 | SDNC_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $SDNC_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https") |
| 226 | |
| 227 | echo " Host IP, http port, https port: $SDNC_HOST_NAME $SDNC_EXTERNAL_PORT $SDNC_EXTERNAL_SECURE_PORT" |
| 228 | |
| 229 | if [ $SDNC_HTTPX == "http" ]; then |
| 230 | SDNC_PATH=$SDNC_HTTPX"://"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_PORT |
| 231 | SDNC_API_PATH=$SDNC_HTTPX"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_PORT$SDNC_API_URL |
| 232 | #presume correct |
| 233 | SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME"."$KUBE_NONRTRIC_NAMESPACE":"$SDNC_EXTERNAL_PORT |
| 234 | #test |
| 235 | #SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_EXTERNAL_PORT |
| 236 | else |
| 237 | SDNC_PATH=$SDNC_HTTPX"://"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_SECURE_PORT |
| 238 | SDNC_API_PATH=$SDNC_HTTPX"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_SECURE_PORT$SDNC_API_URL |
| 239 | #presume correct |
| 240 | SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME"."$KUBE_NONRTRIC_NAMESPACE":"$SDNC_EXTERNAL_SECURE_PORT |
| 241 | #test |
| 242 | #SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_EXTERNAL_SECURE_PORT |
| 243 | fi |
| 244 | |
| 245 | __check_service_start $SDNC_APP_NAME $SDNC_PATH$SDNC_ALIVE_URL |
| 246 | else |
| 247 | |
| 248 | __check_included_image 'SDNC' |
| 249 | if [ $? -eq 1 ]; then |
| 250 | echo -e $RED"The SDNC A1 Controller app is not included in this test script"$ERED |
| 251 | echo -e $RED"The Policy Agent will not be started"$ERED |
| 252 | exit |
| 253 | fi |
| 254 | |
| 255 | export SDNC_DB_APP_NAME |
| 256 | export SDNC_APP_NAME |
| 257 | export SDNC_INTERNAL_PORT |
| 258 | export SDNC_EXTERNAL_PORT |
| 259 | export SDNC_INTERNAL_SECURE_PORT |
| 260 | export SDNC_EXTERNAL_SECURE_PORT |
| 261 | export SDNC_A1_TRUSTSTORE_PASSWORD |
| 262 | export DOCKER_SIM_NWNAME |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 263 | export SDNC_DISPLAY_NAME |
| 264 | export SDNC_USER |
| 265 | export SDNC_PWD |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 266 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 267 | __start_container $SDNC_COMPOSE_DIR $SDNC_COMPOSE_FILE NODOCKERARGS 1 $SDNC_APP_NAME |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 268 | |
| 269 | __check_service_start $SDNC_APP_NAME $SDNC_PATH$SDNC_ALIVE_URL |
| 270 | fi |
| 271 | echo "" |
| 272 | return 0 |
| 273 | } |
| 274 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 275 | # Check the agent logs for WARNINGs and ERRORs |
| 276 | # args: - |
| 277 | # (Function for test scripts) |
| 278 | check_sdnc_logs() { |
| 279 | __check_container_logs "SDNC A1 Controller" $SDNC_APP_NAME $SDNC_KARAF_LOG WARN ERROR |
| 280 | } |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 281 | |
| 282 | # Generic function to query the RICs via the A1-controller API. |
| 283 | # args: <operation> <url> [<body>] |
| 284 | # <operation>: getA1Policy,putA1Policy,getA1PolicyType,deleteA1Policy,getA1PolicyStatus |
| 285 | # response: <json-body><3-digit-response-code> |
| 286 | # (Not for test scripts) |
| 287 | __do_curl_to_controller() { |
| 288 | echo " (${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 289 | if [ $# -ne 2 ] && [ $# -ne 3 ]; then |
| 290 | ((RES_CONF_FAIL++)) |
| 291 | echo "-Incorrect number of parameters to __do_curl_to_controller " $@ >> $HTTPLOG |
| 292 | echo "-Expected: <operation> <url> [<body>]" >> $HTTPLOG |
| 293 | echo "-Returning response 000" >> $HTTPLOG |
| 294 | echo "000" |
| 295 | return 1 |
| 296 | fi |
| 297 | if [ $# -eq 2 ]; then |
| 298 | json='{"input":{"near-rt-ric-url":"'$2'"}}' |
| 299 | else |
| 300 | # Escape quotes in the body |
| 301 | body=$(echo "$3" | sed 's/"/\\"/g') |
| 302 | json='{"input":{"near-rt-ric-url":"'$2'","body":"'"$body"'"}}' |
| 303 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 304 | payload="./tmp/.sdnc.payload.json" |
| 305 | echo "$json" > $payload |
| 306 | echo " FILE ($payload) : $json" >> $HTTPLOG |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 307 | proxyflag="" |
| 308 | if [ $RUNMODE == "KUBE" ]; then |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame^] | 309 | if [ ! -z "$KUBE_PROXY_PATH" ]; then |
| 310 | proxyflag=" --proxy KUBE_PROXY_PATH" |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 311 | fi |
| 312 | fi |
| 313 | curlString="curl -skw %{http_code} $proxyflag -X POST $SDNC_API_PATH$1 -H accept:application/json -H Content-Type:application/json --data-binary @$payload" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 314 | echo " CMD: "$curlString >> $HTTPLOG |
| 315 | res=$($curlString) |
| 316 | retcode=$? |
| 317 | echo " RESP: "$res >> $HTTPLOG |
| 318 | if [ $retcode -ne 0 ]; then |
| 319 | echo " RETCODE: "$retcode >> $HTTPLOG |
| 320 | echo "000" |
| 321 | return 1 |
| 322 | fi |
| 323 | |
| 324 | status=${res:${#res}-3} |
| 325 | |
| 326 | if [ $status -ne 200 ]; then |
| 327 | echo "000" |
| 328 | return 1 |
| 329 | fi |
| 330 | body=${res:0:${#res}-3} |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 331 | echo " JSON: "$body >> $HTTPLOG |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 332 | reply="./tmp/.sdnc-reply.json" |
| 333 | echo "$body" > $reply |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 334 | res=$(python3 ../common/extract_sdnc_reply.py $SDNC_RESPONSE_JSON_KEY $reply) |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 335 | echo " EXTRACED BODY+CODE: "$res >> $HTTPLOG |
| 336 | echo "$res" |
| 337 | return 0 |
| 338 | } |
| 339 | |
| 340 | # Controller API Test function: getA1Policy (return ids only) |
| 341 | # arg: <response-code> (OSC <ric-id> <policy-type-id> [ <policy-id> [<policy-id>]* ]) | ( STD <ric-id> [ <policy-id> [<policy-id>]* ] ) |
| 342 | # (Function for test scripts) |
| 343 | controller_api_get_A1_policy_ids() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 344 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 345 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 346 | ric_id=$3 |
| 347 | if [ $RUNMODE == "KUBE" ]; then |
| 348 | ric_id=$(get_kube_sim_host $3) |
| 349 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 350 | paramError=1 |
| 351 | if [ $# -gt 3 ] && [ $2 == "OSC" ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 352 | url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4/policies" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 353 | paramError=0 |
| 354 | elif [ $# -gt 2 ] && [ $2 == "STD" ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 355 | url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 356 | paramError=0 |
| 357 | fi |
| 358 | |
| 359 | if [ $paramError -ne 0 ]; then |
| 360 | __print_err "<response-code> (OSC <ric-id> <policy-type-id> [ <policy-id> [<policy-id>]* ]) | ( STD <ric-id> [ <policy-id> [<policy-id>]* ] )" $@ |
| 361 | return 1 |
| 362 | fi |
| 363 | |
| 364 | res=$(__do_curl_to_controller getA1Policy "$url") |
| 365 | retcode=$? |
| 366 | status=${res:${#res}-3} |
| 367 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 368 | if [ $retcode -ne 0 ]; then |
| 369 | __log_test_fail_status_code $1 $retcode "(likely remote server error)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 370 | return 1 |
| 371 | fi |
| 372 | |
| 373 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 374 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 375 | return 1 |
| 376 | fi |
| 377 | body=${res:0:${#res}-3} |
| 378 | |
| 379 | targetJson="[" |
| 380 | start=4 |
| 381 | if [ $2 == "OSC" ]; then |
| 382 | start=5 |
| 383 | fi |
| 384 | for pid in ${@:$start} ; do |
| 385 | if [ "$targetJson" != "[" ]; then |
| 386 | targetJson=$targetJson"," |
| 387 | fi |
BjornMagnussonXA | ad04778 | 2020-06-08 15:54:11 +0200 | [diff] [blame] | 388 | targetJson=$targetJson"\"$UUID$pid\"" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 389 | done |
| 390 | targetJson=$targetJson"]" |
| 391 | |
| 392 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 393 | |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 394 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 395 | |
| 396 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 397 | __log_test_fail_body |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 398 | return 1 |
| 399 | fi |
| 400 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 401 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 402 | return 0 |
| 403 | } |
| 404 | |
| 405 | |
| 406 | # Controller API Test function: getA1PolicyType |
| 407 | # arg: <response-code> OSC <ric-id> <policy-type-id> [<policy-type-file>] |
| 408 | # (Function for test scripts) |
| 409 | controller_api_get_A1_policy_type() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 410 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 411 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 412 | ric_id=$3 |
| 413 | if [ $RUNMODE == "KUBE" ]; then |
| 414 | ric_id=$(get_kube_sim_host $3) |
| 415 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 416 | paramError=1 |
| 417 | if [ $# -gt 3 ] && [ $2 == "OSC" ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 418 | url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 419 | paramError=0 |
| 420 | fi |
| 421 | |
| 422 | if [ $paramError -ne 0 ]; then |
| 423 | __print_err "<response-code> OSC <ric-id> <policy-type-id> [<policy-type-file>]" $@ |
| 424 | return 1 |
| 425 | fi |
| 426 | |
| 427 | res=$(__do_curl_to_controller getA1PolicyType "$url") |
| 428 | retcode=$? |
| 429 | status=${res:${#res}-3} |
| 430 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 431 | if [ $retcode -ne 0 ]; then |
| 432 | __log_test_fail_status_code $1 $retcode "(likely remote server error)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 433 | return 1 |
| 434 | fi |
| 435 | |
| 436 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 437 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 438 | return 1 |
| 439 | fi |
| 440 | body=${res:0:${#res}-3} |
| 441 | |
| 442 | if [ $# -eq 5 ]; then |
| 443 | |
| 444 | body=${res:0:${#res}-3} |
| 445 | |
| 446 | targetJson=$(< $5) |
| 447 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 448 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 449 | |
| 450 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 451 | __log_test_fail_body |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 452 | return 1 |
| 453 | fi |
| 454 | fi |
| 455 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 456 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 457 | return 0 |
| 458 | } |
| 459 | |
| 460 | # Controller API Test function: deleteA1Policy |
| 461 | # arg: <response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>) |
| 462 | # (Function for test scripts) |
| 463 | controller_api_delete_A1_policy() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 464 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 465 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 466 | ric_id=$3 |
| 467 | if [ $RUNMODE == "KUBE" ]; then |
| 468 | ric_id=$(get_kube_sim_host $3) |
| 469 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 470 | paramError=1 |
| 471 | if [ $# -eq 5 ] && [ $2 == "OSC" ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 472 | url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 473 | paramError=0 |
| 474 | elif [ $# -eq 4 ] && [ $2 == "STD" ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 475 | url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 476 | paramError=0 |
| 477 | fi |
| 478 | |
| 479 | if [ $paramError -ne 0 ]; then |
| 480 | __print_err "<response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)" $@ |
| 481 | return 1 |
| 482 | fi |
| 483 | |
| 484 | res=$(__do_curl_to_controller deleteA1Policy "$url") |
| 485 | retcode=$? |
| 486 | status=${res:${#res}-3} |
| 487 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 488 | if [ $retcode -ne 0 ]; then |
| 489 | __log_test_fail_status_code $1 $retcode "(likely remote server error)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 490 | return 1 |
| 491 | fi |
| 492 | |
| 493 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 494 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 495 | return 1 |
| 496 | fi |
| 497 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 498 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 499 | return 0 |
| 500 | } |
| 501 | |
| 502 | # Controller API Test function: putA1Policy |
| 503 | # arg: <response-code> (STD <ric-id> <policy-id> <template-file> ) | (OSC <ric-id> <policy-type-id> <policy-id> <template-file>) |
| 504 | # (Function for test scripts) |
| 505 | controller_api_put_A1_policy() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 506 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 507 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 508 | ric_id=$3 |
| 509 | if [ $RUNMODE == "KUBE" ]; then |
| 510 | ric_id=$(get_kube_sim_host $3) |
| 511 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 512 | paramError=1 |
| 513 | if [ $# -eq 6 ] && [ $2 == "OSC" ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 514 | url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 515 | body=$(sed 's/XXX/'${5}'/g' $6) |
| 516 | |
| 517 | paramError=0 |
| 518 | elif [ $# -eq 5 ] && [ $2 == "STD" ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 519 | url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 520 | body=$(sed 's/XXX/'${4}'/g' $5) |
| 521 | paramError=0 |
| 522 | fi |
| 523 | |
| 524 | if [ $paramError -ne 0 ]; then |
| 525 | __print_err "<response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)" $@ |
| 526 | return 1 |
| 527 | fi |
| 528 | |
| 529 | res=$(__do_curl_to_controller putA1Policy "$url" "$body") |
| 530 | retcode=$? |
| 531 | status=${res:${#res}-3} |
| 532 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 533 | if [ $retcode -ne 0 ]; then |
| 534 | __log_test_fail_status_code $1 $retcode "(likely remote server error)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 535 | return 1 |
| 536 | fi |
| 537 | |
| 538 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 539 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 540 | return 1 |
| 541 | fi |
| 542 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 543 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 544 | return 0 |
| 545 | } |
| 546 | |
| 547 | |
| 548 | # Controller API Test function: getA1PolicyStatus |
| 549 | # arg: <response-code> (STD <ric-id> <policy-id> <enforce-status> [<reason>]) | (OSC <ric-id> <policy-type-id> <policy-id> <instance-status> <has-been-deleted>) |
| 550 | # (Function for test scripts) |
| 551 | controller_api_get_A1_policy_status() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 552 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 553 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 554 | ric_id=$3 |
| 555 | if [ $RUNMODE == "KUBE" ]; then |
| 556 | ric_id=$(get_kube_sim_host $3) |
| 557 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 558 | targetJson="" |
| 559 | paramError=1 |
| 560 | if [ $# -ge 5 ] && [ $2 == "OSC" ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 561 | url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5/status" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 562 | if [ $# -gt 5 ]; then |
| 563 | targetJson="{\"instance_status\":\"$6\"" |
| 564 | targetJson=$targetJson",\"has_been_deleted\":\"$7\"" |
| 565 | targetJson=$targetJson",\"created_at\":\"????\"}" |
| 566 | fi |
| 567 | paramError=0 |
| 568 | elif [ $# -ge 4 ] && [ $2 == "STD" ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 569 | url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4/status" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 570 | if [ $# -gt 4 ]; then |
| 571 | targetJson="{\"enforceStatus\":\"$5\"" |
| 572 | if [ $# -eq 6 ]; then |
| 573 | targetJson=$targetJson",\"reason\":\"$6\"" |
| 574 | fi |
| 575 | targetJson=$targetJson"}" |
| 576 | fi |
| 577 | paramError=0 |
| 578 | fi |
| 579 | |
| 580 | if [ $paramError -ne 0 ]; then |
| 581 | __print_err "<response-code> (STD <ric-id> <policy-id> <enforce-status> [<reason>]) | (OSC <ric-id> <policy-type-id> <policy-id> <instance-status> <has-been-deleted>)" $@ |
| 582 | return 1 |
| 583 | fi |
| 584 | |
| 585 | res=$(__do_curl_to_controller getA1PolicyStatus "$url") |
| 586 | retcode=$? |
| 587 | status=${res:${#res}-3} |
| 588 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 589 | if [ $retcode -ne 0 ]; then |
| 590 | __log_test_fail_status_code $1 $retcode "(likely remote server error)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 591 | return 1 |
| 592 | fi |
| 593 | |
| 594 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 595 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 596 | return 1 |
| 597 | fi |
| 598 | |
| 599 | if [ ! -z "$targetJson" ]; then |
| 600 | |
| 601 | body=${res:0:${#res}-3} |
| 602 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 603 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 604 | |
| 605 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 606 | __log_test_fail_body |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 607 | return 1 |
| 608 | fi |
| 609 | fi |
| 610 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 611 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 612 | return 0 |
| 613 | } |