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() { |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 76 | __kube_scale_all_resources $KUBE_SNDC_NAMESPACE autotest SDNC |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 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() { |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 88 | __kube_delete_all_resources $KUBE_SNDC_NAMESPACE autotest SDNC |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 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() { |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 95 | if [ $RUNMODE == "KUBE" ]; then |
| 96 | kubectl logs -l "autotest=SDNC" -n $KUBE_SNDC_NAMESPACE --tail=-1 > $1$2_SDNC.log 2>&1 |
| 97 | podname=$(kubectl get pods -n $KUBE_SNDC_NAMESPACE -l "autotest=SDNC" -o custom-columns=":metadata.name") |
| 98 | kubectl exec -t -n $KUBE_SNDC_NAMESPACE $podname -- cat $SDNC_KARAF_LOG> $1$2_SDNC_karaf.log 2>&1 |
| 99 | else |
| 100 | docker exec -t $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $1$2_SDNC_karaf.log 2>&1 |
| 101 | fi |
| 102 | } |
| 103 | |
| 104 | # Initial setup of protocol, host and ports |
| 105 | # This function is called for apps managed by the test script. |
| 106 | # args: - |
| 107 | __SDNC_initial_setup() { |
| 108 | use_sdnc_http |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | ####################################################### |
| 112 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 113 | # Set http as the protocol to use for all communication to SDNC |
| 114 | # args: - |
| 115 | # (Function for test scripts) |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 116 | use_sdnc_http() { |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 117 | __sdnc_set_protocoll "http" $SDNC_INTERNAL_PORT $SDNC_EXTERNAL_PORT |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 118 | } |
| 119 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 120 | # Set https as the protocol to use for all communication to SDNC |
| 121 | # args: - |
| 122 | # (Function for test scripts) |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 123 | use_sdnc_https() { |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 124 | __sdnc_set_protocoll "https" $SDNC_INTERNAL_SECURE_PORT $SDNC_EXTERNAL_SECURE_PORT |
| 125 | } |
| 126 | |
| 127 | # Setup paths to svc/container for internal and external access |
| 128 | # args: <protocol> <internal-port> <external-port> |
| 129 | __sdnc_set_protocoll() { |
| 130 | echo -e $BOLD"$SDNC_DISPLAY_NAME protocol setting"$EBOLD |
| 131 | echo -e " Using $BOLD http $EBOLD towards $SDNC_DISPLAY_NAME" |
| 132 | |
| 133 | ## Access to SDNC |
| 134 | |
| 135 | SDNC_SERVICE_PATH=$1"://"$SDNC_APP_NAME":"$2 # docker access, container->container and script->container via proxy |
| 136 | SDNC_SERVICE_API_PATH=$1"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_APP_NAME":"$1$SDNC_API_URL |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 137 | if [ $RUNMODE == "KUBE" ]; then |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 138 | SDNC_SERVICE_PATH=$1"://"$SDNC_APP_NAME.$KUBE_SNDC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy |
| 139 | SDNC_SERVICE_API_PATH=$1"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_APP_NAME.KUBE_SNDC_NAMESPACE":"$1$SDNC_API_URL |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 140 | fi |
| 141 | echo "" |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 142 | |
| 143 | } |
| 144 | |
| 145 | # Export env vars for config files, docker compose and kube resources |
| 146 | # args: |
| 147 | __sdnc_export_vars() { |
| 148 | export KUBE_SNDC_NAMESPACE |
| 149 | export DOCKER_SIM_NWNAME |
| 150 | |
| 151 | export SDNC_APP_NAME |
| 152 | export SDNC_DISPLAY_NAME |
| 153 | |
| 154 | export SDNC_A1_CONTROLLER_IMAGE |
| 155 | export SDNC_INTERNAL_PORT |
| 156 | export SDNC_EXTERNAL_PORT |
| 157 | export SDNC_INTERNAL_SECURE_PORT |
| 158 | export SDNC_EXTERNAL_SECURE_PORT |
| 159 | export SDNC_A1_TRUSTSTORE_PASSWORD |
| 160 | export SDNC_DB_APP_NAME |
| 161 | export SDNC_DB_IMAGE |
| 162 | export SDNC_USER |
| 163 | export SDNC_PWD |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | ################## |
| 167 | ### SDNC functions |
| 168 | ################## |
| 169 | |
| 170 | # Start the SDNC A1 Controller |
| 171 | # args: - |
| 172 | # (Function for test scripts) |
| 173 | start_sdnc() { |
| 174 | |
| 175 | echo -e $BOLD"Starting $SDNC_DISPLAY_NAME"$EBOLD |
| 176 | |
| 177 | if [ $RUNMODE == "KUBE" ]; then |
| 178 | |
| 179 | # Check if app shall be fully managed by the test script |
| 180 | __check_included_image "SDNC" |
| 181 | retcode_i=$? |
| 182 | |
| 183 | # Check if app shall only be used by the testscipt |
| 184 | __check_prestarted_image "SDNC" |
| 185 | retcode_p=$? |
| 186 | |
| 187 | if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then |
| 188 | echo -e $RED"The $SDNC_APP_NAME app is not included as managed nor prestarted in this test script"$ERED |
| 189 | echo -e $RED"The $SDNC_APP_NAME will not be started"$ERED |
| 190 | exit |
| 191 | fi |
| 192 | if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then |
| 193 | echo -e $RED"The $SDNC_APP_NAME app is included both as managed and prestarted in this test script"$ERED |
| 194 | echo -e $RED"The $SDNC_APP_NAME will not be started"$ERED |
| 195 | exit |
| 196 | fi |
| 197 | |
| 198 | |
| 199 | if [ $retcode_p -eq 0 ]; then |
| 200 | echo -e " Using existing $SDNC_APP_NAME deployment and service" |
| 201 | echo " Setting SDNC replicas=1" |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 202 | __kube_scale deployment $SDNC_APP_NAME $KUBE_SNDC_NAMESPACE 1 |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 203 | fi |
| 204 | |
| 205 | # Check if app shall be fully managed by the test script |
| 206 | if [ $retcode_i -eq 0 ]; then |
| 207 | |
| 208 | echo -e " Creating $SDNC_APP_NAME app and expose service" |
| 209 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 210 | #Check if namespace exists, if not create it |
| 211 | __kube_create_namespace $KUBE_SNDC_NAMESPACE |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 212 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 213 | __sdnc_export_vars |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 214 | |
| 215 | # Create service |
| 216 | input_yaml=$SIM_GROUP"/"$SDNC_COMPOSE_DIR"/"svc.yaml |
| 217 | output_yaml=$PWD/tmp/sdnc_svc.yaml |
| 218 | __kube_create_instance service $SDNC_APP_NAME $input_yaml $output_yaml |
| 219 | |
| 220 | # Create app |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 221 | input_yaml=$SIM_GROUP"/"$SDNC_COMPOSE_DIR"/"$SDNC_KUBE_APP_FILE |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 222 | output_yaml=$PWD/tmp/sdnc_app.yaml |
| 223 | __kube_create_instance app $SDNC_APP_NAME $input_yaml $output_yaml |
| 224 | |
| 225 | fi |
| 226 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 227 | __check_service_start $SDNC_APP_NAME $SDNC_SERVICE_PATH$SDNC_ALIVE_URL |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 228 | else |
| 229 | |
| 230 | __check_included_image 'SDNC' |
| 231 | if [ $? -eq 1 ]; then |
| 232 | echo -e $RED"The SDNC A1 Controller app is not included in this test script"$ERED |
| 233 | echo -e $RED"The Policy Agent will not be started"$ERED |
| 234 | exit |
| 235 | fi |
| 236 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 237 | __sdnc_export_vars |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 238 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 239 | __start_container $SDNC_COMPOSE_DIR $SDNC_COMPOSE_FILE NODOCKERARGS 1 $SDNC_APP_NAME |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 240 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 241 | __check_service_start $SDNC_APP_NAME $SDNC_SERVICE_PATH$SDNC_ALIVE_URL |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 242 | fi |
| 243 | echo "" |
| 244 | return 0 |
| 245 | } |
| 246 | |
BjornMagnussonXA | 83a750f | 2021-09-21 20:39:58 +0200 | [diff] [blame] | 247 | |
| 248 | # Stop the sndc |
| 249 | # args: - |
| 250 | # args: - |
| 251 | # (Function for test scripts) |
| 252 | stop_sdnc() { |
| 253 | echo -e $BOLD"Stopping $SDNC_DISPLAY_NAME"$EBOLD |
| 254 | |
| 255 | if [ $RUNMODE == "KUBE" ]; then |
| 256 | __log_conf_fail_not_supported " Cannot stop sndc in KUBE mode" |
| 257 | return 1 |
| 258 | else |
| 259 | docker stop $SDNC_APP_NAME &> ./tmp/.dockererr |
| 260 | if [ $? -ne 0 ]; then |
| 261 | __print_err "Could not stop $SDNC_APP_NAME" $@ |
| 262 | cat ./tmp/.dockererr |
| 263 | ((RES_CONF_FAIL++)) |
| 264 | return 1 |
| 265 | fi |
| 266 | fi |
| 267 | echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD |
| 268 | echo "" |
| 269 | return 0 |
| 270 | } |
| 271 | |
| 272 | # Start a previously stopped sdnc |
| 273 | # args: - |
| 274 | # (Function for test scripts) |
| 275 | start_stopped_sdnc() { |
| 276 | echo -e $BOLD"Starting (the previously stopped) $SDNC_DISPLAY_NAME"$EBOLD |
| 277 | |
| 278 | if [ $RUNMODE == "KUBE" ]; then |
| 279 | __log_conf_fail_not_supported " Cannot restart sndc in KUBE mode" |
| 280 | return 1 |
| 281 | else |
| 282 | docker start $SDNC_APP_NAME &> ./tmp/.dockererr |
| 283 | if [ $? -ne 0 ]; then |
| 284 | __print_err "Could not start (the stopped) $SDNC_APP_NAME" $@ |
| 285 | cat ./tmp/.dockererr |
| 286 | ((RES_CONF_FAIL++)) |
| 287 | return 1 |
| 288 | fi |
| 289 | fi |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 290 | __check_service_start $SDNC_APP_NAME $SDNC_SERVICE_PATH$SDNC_ALIVE_URL |
BjornMagnussonXA | 83a750f | 2021-09-21 20:39:58 +0200 | [diff] [blame] | 291 | if [ $? -ne 0 ]; then |
| 292 | return 1 |
| 293 | fi |
| 294 | echo "" |
| 295 | return 0 |
| 296 | } |
| 297 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 298 | # Check the agent logs for WARNINGs and ERRORs |
| 299 | # args: - |
| 300 | # (Function for test scripts) |
| 301 | check_sdnc_logs() { |
| 302 | __check_container_logs "SDNC A1 Controller" $SDNC_APP_NAME $SDNC_KARAF_LOG WARN ERROR |
| 303 | } |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 304 | |
| 305 | # Generic function to query the RICs via the A1-controller API. |
| 306 | # args: <operation> <url> [<body>] |
| 307 | # <operation>: getA1Policy,putA1Policy,getA1PolicyType,deleteA1Policy,getA1PolicyStatus |
| 308 | # response: <json-body><3-digit-response-code> |
| 309 | # (Not for test scripts) |
| 310 | __do_curl_to_controller() { |
| 311 | echo " (${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 312 | if [ $# -ne 2 ] && [ $# -ne 3 ]; then |
| 313 | ((RES_CONF_FAIL++)) |
| 314 | echo "-Incorrect number of parameters to __do_curl_to_controller " $@ >> $HTTPLOG |
| 315 | echo "-Expected: <operation> <url> [<body>]" >> $HTTPLOG |
| 316 | echo "-Returning response 000" >> $HTTPLOG |
| 317 | echo "000" |
| 318 | return 1 |
| 319 | fi |
| 320 | if [ $# -eq 2 ]; then |
| 321 | json='{"input":{"near-rt-ric-url":"'$2'"}}' |
| 322 | else |
| 323 | # Escape quotes in the body |
| 324 | body=$(echo "$3" | sed 's/"/\\"/g') |
| 325 | json='{"input":{"near-rt-ric-url":"'$2'","body":"'"$body"'"}}' |
| 326 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 327 | payload="./tmp/.sdnc.payload.json" |
| 328 | echo "$json" > $payload |
| 329 | echo " FILE ($payload) : $json" >> $HTTPLOG |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 330 | proxyflag="" |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 331 | if [ ! -z "$KUBE_PROXY_PATH" ]; then |
| 332 | if [ $KUBE_PROXY_HTTPX == "http" ]; then |
| 333 | proxyflag=" --proxy $KUBE_PROXY_PATH" |
| 334 | else |
| 335 | proxyflag=" --proxy-insecure --proxy $KUBE_PROXY_PATH" |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 336 | fi |
| 337 | fi |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 338 | curlString="curl -skw %{http_code} $proxyflag -X POST $SDNC_SERVICE_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] | 339 | echo " CMD: "$curlString >> $HTTPLOG |
| 340 | res=$($curlString) |
| 341 | retcode=$? |
| 342 | echo " RESP: "$res >> $HTTPLOG |
| 343 | if [ $retcode -ne 0 ]; then |
| 344 | echo " RETCODE: "$retcode >> $HTTPLOG |
| 345 | echo "000" |
| 346 | return 1 |
| 347 | fi |
| 348 | |
| 349 | status=${res:${#res}-3} |
| 350 | |
| 351 | if [ $status -ne 200 ]; then |
| 352 | echo "000" |
| 353 | return 1 |
| 354 | fi |
| 355 | body=${res:0:${#res}-3} |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 356 | echo " JSON: "$body >> $HTTPLOG |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 357 | reply="./tmp/.sdnc-reply.json" |
| 358 | echo "$body" > $reply |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 359 | res=$(python3 ../common/extract_sdnc_reply.py $SDNC_RESPONSE_JSON_KEY $reply) |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 360 | echo " EXTRACED BODY+CODE: "$res >> $HTTPLOG |
| 361 | echo "$res" |
| 362 | return 0 |
| 363 | } |
| 364 | |
| 365 | # Controller API Test function: getA1Policy (return ids only) |
| 366 | # arg: <response-code> (OSC <ric-id> <policy-type-id> [ <policy-id> [<policy-id>]* ]) | ( STD <ric-id> [ <policy-id> [<policy-id>]* ] ) |
| 367 | # (Function for test scripts) |
| 368 | controller_api_get_A1_policy_ids() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 369 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 370 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 371 | ric_id=$3 |
| 372 | if [ $RUNMODE == "KUBE" ]; then |
| 373 | ric_id=$(get_kube_sim_host $3) |
| 374 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 375 | paramError=1 |
| 376 | if [ $# -gt 3 ] && [ $2 == "OSC" ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 377 | 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] | 378 | paramError=0 |
| 379 | elif [ $# -gt 2 ] && [ $2 == "STD" ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 380 | url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 381 | paramError=0 |
| 382 | fi |
| 383 | |
| 384 | if [ $paramError -ne 0 ]; then |
| 385 | __print_err "<response-code> (OSC <ric-id> <policy-type-id> [ <policy-id> [<policy-id>]* ]) | ( STD <ric-id> [ <policy-id> [<policy-id>]* ] )" $@ |
| 386 | return 1 |
| 387 | fi |
| 388 | |
| 389 | res=$(__do_curl_to_controller getA1Policy "$url") |
| 390 | retcode=$? |
| 391 | status=${res:${#res}-3} |
| 392 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 393 | if [ $retcode -ne 0 ]; then |
| 394 | __log_test_fail_status_code $1 $retcode "(likely remote server error)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 395 | return 1 |
| 396 | fi |
| 397 | |
| 398 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 399 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 400 | return 1 |
| 401 | fi |
| 402 | body=${res:0:${#res}-3} |
| 403 | |
| 404 | targetJson="[" |
| 405 | start=4 |
| 406 | if [ $2 == "OSC" ]; then |
| 407 | start=5 |
| 408 | fi |
| 409 | for pid in ${@:$start} ; do |
| 410 | if [ "$targetJson" != "[" ]; then |
| 411 | targetJson=$targetJson"," |
| 412 | fi |
BjornMagnussonXA | ad04778 | 2020-06-08 15:54:11 +0200 | [diff] [blame] | 413 | targetJson=$targetJson"\"$UUID$pid\"" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 414 | done |
| 415 | targetJson=$targetJson"]" |
| 416 | |
| 417 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 418 | |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 419 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 420 | |
| 421 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 422 | __log_test_fail_body |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 423 | return 1 |
| 424 | fi |
| 425 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 426 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 427 | return 0 |
| 428 | } |
| 429 | |
| 430 | |
| 431 | # Controller API Test function: getA1PolicyType |
| 432 | # arg: <response-code> OSC <ric-id> <policy-type-id> [<policy-type-file>] |
| 433 | # (Function for test scripts) |
| 434 | controller_api_get_A1_policy_type() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 435 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 436 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 437 | ric_id=$3 |
| 438 | if [ $RUNMODE == "KUBE" ]; then |
| 439 | ric_id=$(get_kube_sim_host $3) |
| 440 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 441 | paramError=1 |
| 442 | if [ $# -gt 3 ] && [ $2 == "OSC" ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 443 | url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 444 | paramError=0 |
| 445 | fi |
| 446 | |
| 447 | if [ $paramError -ne 0 ]; then |
| 448 | __print_err "<response-code> OSC <ric-id> <policy-type-id> [<policy-type-file>]" $@ |
| 449 | return 1 |
| 450 | fi |
| 451 | |
| 452 | res=$(__do_curl_to_controller getA1PolicyType "$url") |
| 453 | retcode=$? |
| 454 | status=${res:${#res}-3} |
| 455 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 456 | if [ $retcode -ne 0 ]; then |
| 457 | __log_test_fail_status_code $1 $retcode "(likely remote server error)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 458 | return 1 |
| 459 | fi |
| 460 | |
| 461 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 462 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 463 | return 1 |
| 464 | fi |
| 465 | body=${res:0:${#res}-3} |
| 466 | |
| 467 | if [ $# -eq 5 ]; then |
| 468 | |
| 469 | body=${res:0:${#res}-3} |
| 470 | |
| 471 | targetJson=$(< $5) |
| 472 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 473 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 474 | |
| 475 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 476 | __log_test_fail_body |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 477 | return 1 |
| 478 | fi |
| 479 | fi |
| 480 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 481 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 482 | return 0 |
| 483 | } |
| 484 | |
| 485 | # Controller API Test function: deleteA1Policy |
| 486 | # arg: <response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>) |
| 487 | # (Function for test scripts) |
| 488 | controller_api_delete_A1_policy() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 489 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 490 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 491 | ric_id=$3 |
| 492 | if [ $RUNMODE == "KUBE" ]; then |
| 493 | ric_id=$(get_kube_sim_host $3) |
| 494 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 495 | paramError=1 |
| 496 | if [ $# -eq 5 ] && [ $2 == "OSC" ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 497 | 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] | 498 | paramError=0 |
| 499 | elif [ $# -eq 4 ] && [ $2 == "STD" ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 500 | 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] | 501 | paramError=0 |
| 502 | fi |
| 503 | |
| 504 | if [ $paramError -ne 0 ]; then |
| 505 | __print_err "<response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)" $@ |
| 506 | return 1 |
| 507 | fi |
| 508 | |
| 509 | res=$(__do_curl_to_controller deleteA1Policy "$url") |
| 510 | retcode=$? |
| 511 | status=${res:${#res}-3} |
| 512 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 513 | if [ $retcode -ne 0 ]; then |
| 514 | __log_test_fail_status_code $1 $retcode "(likely remote server error)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 515 | return 1 |
| 516 | fi |
| 517 | |
| 518 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 519 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 520 | return 1 |
| 521 | fi |
| 522 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 523 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 524 | return 0 |
| 525 | } |
| 526 | |
| 527 | # Controller API Test function: putA1Policy |
| 528 | # arg: <response-code> (STD <ric-id> <policy-id> <template-file> ) | (OSC <ric-id> <policy-type-id> <policy-id> <template-file>) |
| 529 | # (Function for test scripts) |
| 530 | controller_api_put_A1_policy() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 531 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 532 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 533 | ric_id=$3 |
| 534 | if [ $RUNMODE == "KUBE" ]; then |
| 535 | ric_id=$(get_kube_sim_host $3) |
| 536 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 537 | paramError=1 |
| 538 | if [ $# -eq 6 ] && [ $2 == "OSC" ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 539 | 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] | 540 | body=$(sed 's/XXX/'${5}'/g' $6) |
| 541 | |
| 542 | paramError=0 |
| 543 | elif [ $# -eq 5 ] && [ $2 == "STD" ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 544 | 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] | 545 | body=$(sed 's/XXX/'${4}'/g' $5) |
| 546 | paramError=0 |
| 547 | fi |
| 548 | |
| 549 | if [ $paramError -ne 0 ]; then |
| 550 | __print_err "<response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)" $@ |
| 551 | return 1 |
| 552 | fi |
| 553 | |
| 554 | res=$(__do_curl_to_controller putA1Policy "$url" "$body") |
| 555 | retcode=$? |
| 556 | status=${res:${#res}-3} |
| 557 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 558 | if [ $retcode -ne 0 ]; then |
| 559 | __log_test_fail_status_code $1 $retcode "(likely remote server error)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 560 | return 1 |
| 561 | fi |
| 562 | |
| 563 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 564 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 565 | return 1 |
| 566 | fi |
| 567 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 568 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 569 | return 0 |
| 570 | } |
| 571 | |
| 572 | |
| 573 | # Controller API Test function: getA1PolicyStatus |
| 574 | # arg: <response-code> (STD <ric-id> <policy-id> <enforce-status> [<reason>]) | (OSC <ric-id> <policy-type-id> <policy-id> <instance-status> <has-been-deleted>) |
| 575 | # (Function for test scripts) |
| 576 | controller_api_get_A1_policy_status() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 577 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 578 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 579 | ric_id=$3 |
| 580 | if [ $RUNMODE == "KUBE" ]; then |
| 581 | ric_id=$(get_kube_sim_host $3) |
| 582 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 583 | targetJson="" |
| 584 | paramError=1 |
| 585 | if [ $# -ge 5 ] && [ $2 == "OSC" ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 586 | 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] | 587 | if [ $# -gt 5 ]; then |
| 588 | targetJson="{\"instance_status\":\"$6\"" |
| 589 | targetJson=$targetJson",\"has_been_deleted\":\"$7\"" |
| 590 | targetJson=$targetJson",\"created_at\":\"????\"}" |
| 591 | fi |
| 592 | paramError=0 |
| 593 | elif [ $# -ge 4 ] && [ $2 == "STD" ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 594 | 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] | 595 | if [ $# -gt 4 ]; then |
| 596 | targetJson="{\"enforceStatus\":\"$5\"" |
| 597 | if [ $# -eq 6 ]; then |
| 598 | targetJson=$targetJson",\"reason\":\"$6\"" |
| 599 | fi |
| 600 | targetJson=$targetJson"}" |
| 601 | fi |
| 602 | paramError=0 |
| 603 | fi |
| 604 | |
| 605 | if [ $paramError -ne 0 ]; then |
| 606 | __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>)" $@ |
| 607 | return 1 |
| 608 | fi |
| 609 | |
| 610 | res=$(__do_curl_to_controller getA1PolicyStatus "$url") |
| 611 | retcode=$? |
| 612 | status=${res:${#res}-3} |
| 613 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 614 | if [ $retcode -ne 0 ]; then |
| 615 | __log_test_fail_status_code $1 $retcode "(likely remote server error)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 616 | return 1 |
| 617 | fi |
| 618 | |
| 619 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 620 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 621 | return 1 |
| 622 | fi |
| 623 | |
| 624 | if [ ! -z "$targetJson" ]; then |
| 625 | |
| 626 | body=${res:0:${#res}-3} |
| 627 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 628 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 629 | |
| 630 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 631 | __log_test_fail_body |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 632 | return 1 |
| 633 | fi |
| 634 | fi |
| 635 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 636 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 637 | return 0 |
| 638 | } |