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 RICSIM A1 simulators |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 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 | __RICSIM_imagesetup() { |
| 28 | __check_and_create_image_var RICSIM "RIC_SIM_IMAGE" "RIC_SIM_IMAGE_BASE" "RIC_SIM_IMAGE_TAG" $1 "$RIC_SIM_DISPLAY_NAME" |
| 29 | } |
| 30 | |
| 31 | # Pull image from remote repo or use locally built image |
| 32 | # arg: <pull-policy-override> <pull-policy-original> |
| 33 | # <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images |
| 34 | # <pull-policy-original> Shall be used for images that does not allow overriding |
| 35 | # Both var may contain: 'remote', 'remote-remove' or 'local' |
| 36 | __RICSIM_imagepull() { |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame] | 37 | __check_and_pull_image $1 "$RIC_SIM_DISPLAY_NAME" $RIC_SIM_PREFIX"_"$RIC_SIM_BASE RIC_SIM_IMAGE |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | # 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] | 41 | # 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] | 42 | # arg: <docker-images-format-string> <file-to-append> |
| 43 | __RICSIM_image_data() { |
| 44 | echo -e "$RIC_SIM_DISPLAY_NAME\t$(docker images --format $1 $RIC_SIM_IMAGE)" >> $2 |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame] | 45 | if [ ! -z "$RIC_SIM_IMAGE_SOURCE" ]; then |
| 46 | echo -e "-- source image --\t$(docker images --format $1 $RIC_SIM_IMAGE_SOURCE)" >> $2 |
| 47 | fi |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | # Scale kubernetes resources to zero |
| 51 | # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action. |
| 52 | # This function is called for apps fully managed by the test script |
| 53 | __RICSIM_kube_scale_zero() { |
| 54 | __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest RICSIM |
| 55 | } |
| 56 | |
| 57 | # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action. |
| 58 | # This function is called for prestarted apps not managed by the test script. |
| 59 | __RICSIM_kube_scale_zero_and_wait() { |
| 60 | __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app nonrtric-a1simulator |
| 61 | } |
| 62 | |
| 63 | # Delete all kube resouces for the app |
| 64 | # This function is called for apps managed by the test script. |
| 65 | __RICSIM_kube_delete_all() { |
| 66 | __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest RICSIM |
| 67 | } |
| 68 | |
| 69 | # Store docker logs |
| 70 | # This function is called for apps managed by the test script. |
| 71 | # args: <log-dir> <file-prexix> |
| 72 | __RICSIM_store_docker_logs() { |
| 73 | rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "status=running" --format {{.Names}}) |
| 74 | for ric in $rics; do |
| 75 | docker logs $ric > $1$2_$ric.log 2>&1 |
| 76 | done |
| 77 | } |
| 78 | |
| 79 | ####################################################### |
| 80 | |
| 81 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 82 | RIC_SIM_HTTPX="http" |
| 83 | RIC_SIM_HOST=$RIC_SIM_HTTPX"://"$LOCALHOST_NAME |
| 84 | RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT |
| 85 | |
| 86 | |
| 87 | #Vars for A1 interface version and container count |
| 88 | G1_A1_VERSION="" |
| 89 | G2_A1_VERSION="" |
| 90 | G3_A1_VERSION="" |
| 91 | G4_A1_VERSION="" |
| 92 | G5_A1_VERSION="" |
| 93 | G1_COUNT=0 |
| 94 | G2_COUNT=0 |
| 95 | G3_COUNT=0 |
| 96 | G4_COUNT=0 |
| 97 | G5_COUNT=0 |
| 98 | |
| 99 | |
| 100 | ########################### |
| 101 | ### RIC Simulator functions |
| 102 | ########################### |
| 103 | |
| 104 | use_simulator_http() { |
| 105 | echo -e $BOLD"RICSIM protocol setting"$EBOLD |
| 106 | echo -e " Using $BOLD http $EBOLD towards the simulators" |
| 107 | RIC_SIM_HTTPX="http" |
| 108 | RIC_SIM_HOST=$RIC_SIM_HTTPX"://"$LOCALHOST_NAME |
| 109 | RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT |
| 110 | echo "" |
| 111 | } |
| 112 | |
| 113 | use_simulator_https() { |
| 114 | echo -e $BOLD"RICSIM protocol setting"$EBOLD |
| 115 | echo -e " Using $BOLD https $EBOLD towards the simulators" |
| 116 | RIC_SIM_HTTPX="https" |
| 117 | RIC_SIM_HOST=$RIC_SIM_HTTPX"://"$LOCALHOST_NAME |
| 118 | RIC_SIM_PORT=$RIC_SIM_INTERNAL_SECURE_PORT |
| 119 | echo "" |
| 120 | } |
| 121 | |
| 122 | # Start one group (ricsim_g1, ricsim_g2 .. ricsim_g5) with a number of RIC Simulators using a given A interface |
| 123 | # 'ricsim' may be set on command line to other prefix |
| 124 | # args: ricsim_g1|ricsim_g2|ricsim_g3|ricsim_g4|ricsim_g5 <count> <interface-id> |
| 125 | # (Function for test scripts) |
| 126 | start_ric_simulators() { |
| 127 | |
| 128 | echo -e $BOLD"Starting $RIC_SIM_DISPLAY_NAME"$EBOLD |
| 129 | |
| 130 | if [ $RUNMODE == "KUBE" ]; then |
| 131 | |
| 132 | # Check if app shall be fully managed by the test script |
| 133 | __check_included_image "RICSIM" |
| 134 | retcode_i=$? |
| 135 | |
| 136 | # Check if app shall only be used by the testscipt |
| 137 | __check_prestarted_image "RICSIM" |
| 138 | retcode_p=$? |
| 139 | |
| 140 | if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then |
| 141 | echo -e $RED"The $1 app is not included as managed nor prestarted in this test script"$ERED |
| 142 | echo -e $RED"The $1 will not be started"$ERED |
| 143 | exit |
| 144 | fi |
| 145 | if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then |
| 146 | echo -e $RED"The $1 stub app is included both as managed and prestarted in this test script"$ERED |
| 147 | echo -e $RED"The $1 will not be started"$ERED |
| 148 | exit |
| 149 | fi |
| 150 | |
| 151 | if [ $retcode_p -eq 0 ]; then |
| 152 | echo -e " Using existing $1 statefulset and service" |
| 153 | echo " Using existing simulator deployment and service for statefulset $1" |
| 154 | echo " Setting $1 replicas=$2" |
| 155 | __kube_scale statefulset $1 $KUBE_NONRTRIC_NAMESPACE $2 |
| 156 | echo "" |
| 157 | return |
| 158 | fi |
| 159 | fi |
| 160 | |
| 161 | RIC1=$RIC_SIM_PREFIX"_g1" |
| 162 | RIC2=$RIC_SIM_PREFIX"_g2" |
| 163 | RIC3=$RIC_SIM_PREFIX"_g3" |
| 164 | RIC4=$RIC_SIM_PREFIX"_g4" |
| 165 | RIC5=$RIC_SIM_PREFIX"_g5" |
| 166 | |
| 167 | if [ $# != 3 ]; then |
| 168 | ((RES_CONF_FAIL++)) |
| 169 | __print_err "need three args, $RIC1|$RIC2|$RIC3|$RIC4|$RIC5 <count> <interface-id>" $@ |
| 170 | exit 1 |
| 171 | fi |
| 172 | |
| 173 | echo " $2 simulators using basename: $1 on interface: $3" |
| 174 | #Set env var for simulator count and A1 interface vesion for the given group |
| 175 | if [ $1 == "$RIC1" ]; then |
| 176 | G1_COUNT=$2 |
| 177 | G1_A1_VERSION=$3 |
| 178 | elif [ $1 == "$RIC2" ]; then |
| 179 | G2_COUNT=$2 |
| 180 | G2_A1_VERSION=$3 |
| 181 | elif [ $1 == "$RIC3" ]; then |
| 182 | G3_COUNT=$2 |
| 183 | G3_A1_VERSION=$3 |
| 184 | elif [ $1 == "$RIC4" ]; then |
| 185 | G4_COUNT=$2 |
| 186 | G4_A1_VERSION=$3 |
| 187 | elif [ $1 == "$RIC5" ]; then |
| 188 | G5_COUNT=$2 |
| 189 | G5_A1_VERSION=$3 |
| 190 | else |
| 191 | ((RES_CONF_FAIL++)) |
| 192 | __print_err "need three args, $RIC1|$RIC2|$RIC3|$RIC4|$RIC5 <count> <interface-id>" $@ |
| 193 | exit 1 |
| 194 | fi |
| 195 | |
| 196 | if [ $RUNMODE == "KUBE" ]; then |
| 197 | |
| 198 | if [ $retcode_i -eq 0 ]; then |
| 199 | |
| 200 | #export needed env var for statefulset |
| 201 | export RIC_SIM_SET_NAME=$(echo "$1" | tr '_' '-') #kube does not accept underscore in names |
| 202 | export KUBE_NONRTRIC_NAMESPACE |
| 203 | export RIC_SIM_IMAGE |
| 204 | #Adding 1 more instance, instance 0 is never used. This is done to keep test scripts compatible |
| 205 | # with docker that starts instance index on 1..... |
| 206 | export RIC_SIM_COUNT=$(($2+1)) |
| 207 | export A1_VERSION=$3 |
| 208 | export RIC_SIM_INTERNAL_PORT |
| 209 | export RIC_SIM_INTERNAL_SECURE_PORT |
| 210 | |
| 211 | echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service" |
| 212 | |
| 213 | #Check if nonrtric namespace exists, if not create it |
| 214 | __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE |
| 215 | |
| 216 | # Create service |
| 217 | input_yaml=$SIM_GROUP"/"$RIC_SIM_COMPOSE_DIR"/"svc.yaml |
| 218 | output_yaml=$PWD/tmp/ric_${1}_svc.yaml |
| 219 | __kube_create_instance service $RIC_SIM_SET_NAME $input_yaml $output_yaml |
| 220 | |
| 221 | # Create app |
| 222 | input_yaml=$SIM_GROUP"/"$RIC_SIM_COMPOSE_DIR"/"app.yaml |
| 223 | output_yaml=$PWD/tmp/pa_${1}_app.yaml |
| 224 | __kube_create_instance app $RIC_SIM_SET_NAME $input_yaml $output_yaml |
| 225 | |
| 226 | #Using only instance from index 1 to keep compatability with docker |
| 227 | for (( count=1; count<${RIC_SIM_COUNT}; count++ )); do |
| 228 | host=$(__find_sim_host $RIC_SIM_SET_NAME"-"$count) |
| 229 | __check_service_start $RIC_SIM_SET_NAME"-"$count $host"/" |
| 230 | done |
| 231 | fi |
| 232 | else |
| 233 | |
| 234 | __check_included_image 'RICSIM' |
| 235 | if [ $? -eq 1 ]; then |
| 236 | echo -e $RED"The Near-RT RIC Simulator app is not included as managed in this test script"$ERED |
| 237 | echo -e $RED"Near-RT RIC Simulator will not be started"$ERED |
| 238 | exit 1 |
| 239 | fi |
| 240 | |
| 241 | # Create .env file to compose project, all ric container will get this prefix |
| 242 | echo "COMPOSE_PROJECT_NAME="$RIC_SIM_PREFIX > $SIM_GROUP/$RIC_SIM_COMPOSE_DIR/.env |
| 243 | |
| 244 | export G1_A1_VERSION |
| 245 | export G2_A1_VERSION |
| 246 | export G3_A1_VERSION |
| 247 | export G4_A1_VERSION |
| 248 | export G5_A1_VERSION |
| 249 | export RIC_SIM_INTERNAL_PORT |
| 250 | export RIC_SIM_INTERNAL_SECURE_PORT |
| 251 | export RIC_SIM_CERT_MOUNT_DIR |
| 252 | export DOCKER_SIM_NWNAME |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 253 | export RIC_SIM_DISPLAY_NAME |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 254 | |
| 255 | docker_args="--scale g1=$G1_COUNT --scale g2=$G2_COUNT --scale g3=$G3_COUNT --scale g4=$G4_COUNT --scale g5=$G5_COUNT" |
| 256 | app_data="" |
| 257 | cntr=1 |
| 258 | while [ $cntr -le $2 ]; do |
| 259 | app=$1"_"$cntr |
| 260 | app_data="$app_data $app" |
| 261 | let cntr=cntr+1 |
| 262 | done |
| 263 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 264 | __start_container $RIC_SIM_COMPOSE_DIR "" "$docker_args" $2 $app_data |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 265 | |
| 266 | cntr=1 |
| 267 | while [ $cntr -le $2 ]; do |
| 268 | app=$1"_"$cntr |
| 269 | localport=0 |
| 270 | |
| 271 | while [ $localport -eq 0 ]; do |
| 272 | echo -ne " Waiting for container ${app} to publish its ports...${SAMELINE}" |
| 273 | localport=$(__find_sim_port $app) |
| 274 | sleep 0.5 |
| 275 | echo -ne " Waiting for container ${app} to publish its ports...retrying....${SAMELINE}" |
| 276 | done |
| 277 | echo -e " Waiting for container ${app} to publish its ports...retrying....$GREEN OK $EGREEN" |
| 278 | __check_service_start $app $RIC_SIM_HOST":"$localport$RIC_SIM_ALIVE_URL |
| 279 | let cntr=cntr+1 |
| 280 | done |
| 281 | fi |
| 282 | echo "" |
| 283 | return 0 |
| 284 | } |
| 285 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 286 | # Translate ric name to kube host name |
| 287 | # args: <ric-name> |
| 288 | # For test scripts |
| 289 | get_kube_sim_host() { |
| 290 | name=$(echo "$1" | tr '_' '-') #kube does not accept underscore in names |
| 291 | #example gnb_1_2 -> gnb-1-2 |
| 292 | set_name=$(echo $name | rev | cut -d- -f2- | rev) # Cut index part of ric name to get the name of statefulset |
| 293 | # example gnb-g1-2 -> gnb-g1 where gnb-g1-2 is the ric name and gnb-g1 is the set name |
| 294 | echo $name"."$set_name"."$KUBE_NONRTRIC_NAMESPACE |
| 295 | } |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 296 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 297 | # Helper function to get a the port of a specific ric simulator |
| 298 | # args: <ric-id> |
| 299 | # (Not for test scripts) |
| 300 | __find_sim_port() { |
| 301 | name=$1" " #Space appended to prevent matching 10 if 1 is desired.... |
| 302 | cmdstr="docker inspect --format='{{(index (index .NetworkSettings.Ports \"$RIC_SIM_PORT/tcp\") 0).HostPort}}' ${name}" |
| 303 | res=$(eval $cmdstr) |
| 304 | if [[ "$res" =~ ^[0-9]+$ ]]; then |
| 305 | echo $res |
| 306 | else |
| 307 | echo "0" |
| 308 | fi |
| 309 | } |
| 310 | |
| 311 | # Helper function to get a the port and host name of a specific ric simulator |
| 312 | # args: <ric-id> |
| 313 | # (Not for test scripts) |
| 314 | __find_sim_host() { |
| 315 | if [ $RUNMODE == "KUBE" ]; then |
| 316 | ricname=$(echo "$1" | tr '_' '-') |
| 317 | for timeout in {1..60}; do |
| 318 | host=$(kubectl get pod $ricname -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.status.podIP}' 2> /dev/null) |
| 319 | if [ ! -z "$host" ]; then |
| 320 | echo $RIC_SIM_HTTPX"://"$host":"$RIC_SIM_PORT |
| 321 | return 0 |
| 322 | fi |
| 323 | sleep 0.5 |
| 324 | done |
| 325 | echo "host-not-found-fatal-error" |
| 326 | else |
| 327 | name=$1" " #Space appended to prevent matching 10 if 1 is desired.... |
| 328 | cmdstr="docker inspect --format='{{(index (index .NetworkSettings.Ports \"$RIC_SIM_PORT/tcp\") 0).HostPort}}' ${name}" |
| 329 | res=$(eval $cmdstr) |
| 330 | if [[ "$res" =~ ^[0-9]+$ ]]; then |
| 331 | echo $RIC_SIM_HOST:$res |
| 332 | return 0 |
| 333 | else |
| 334 | echo "0" |
| 335 | fi |
| 336 | fi |
| 337 | return 1 |
| 338 | } |
| 339 | |
| 340 | # Generate a UUID to use as prefix for policy ids |
| 341 | generate_policy_uuid() { |
| 342 | UUID=$(python3 -c 'import sys,uuid; sys.stdout.write(uuid.uuid4().hex)') |
| 343 | #Reduce length to make space for serial id, uses 'a' as marker where the serial id is added |
| 344 | UUID=${UUID:0:${#UUID}-4}"a" |
| 345 | } |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 346 | |
| 347 | # Excute a curl cmd towards a ricsimulator and check the response code. |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 348 | # args: <expected-response-code> <curl-cmd-string> |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 349 | __execute_curl_to_sim() { |
| 350 | echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 351 | proxyflag="" |
| 352 | if [ $RUNMODE == "KUBE" ]; then |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame] | 353 | if [ ! -z "$KUBE_PROXY_PATH" ]; then |
| 354 | proxyflag=" --proxy $KUBE_PROXY_PATH" |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 355 | fi |
| 356 | fi |
| 357 | echo " CMD: $2 $proxyflag" >> $HTTPLOG |
| 358 | res="$($2 $proxyflag)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 359 | echo " RESP: $res" >> $HTTPLOG |
| 360 | retcode=$? |
| 361 | if [ $retcode -ne 0 ]; then |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 362 | ((RES_CONF_FAIL++)) |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 363 | echo " RETCODE: "$retcode |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 364 | echo -e $RED" FAIL - fatal error when executing curl."$ERED |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 365 | return 1 |
| 366 | fi |
| 367 | status=${res:${#res}-3} |
| 368 | if [ $status -eq $1 ]; then |
| 369 | echo -e $GREEN" OK"$EGREEN |
| 370 | return 0 |
| 371 | fi |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 372 | echo -e $RED" FAIL - expected http response: "$1" but got http response: "$status $ERED |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 373 | ((RES_CONF_FAIL++)) |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 374 | return 1 |
| 375 | } |
| 376 | |
| 377 | # Tests if a variable value in the ricsimulator is equal to a target value and and optional timeout. |
| 378 | # Arg: <ric-id> <variable-name> <target-value> - This test set pass or fail depending on if the variable is |
| 379 | # equal to the target or not. |
| 380 | # Arg: <ric-id> <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 381 | # before setting pass or fail depending on if the variable value becomes equal to the target |
| 382 | # value or not. |
| 383 | # (Function for test scripts) |
| 384 | sim_equal() { |
| 385 | |
| 386 | if [ $# -eq 3 ] || [ $# -eq 4 ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 387 | host=$(__find_sim_host $1) |
| 388 | __var_test $1 "$host/counter/" $2 "=" $3 $4 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 389 | return 0 |
| 390 | else |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 391 | __print_err "needs three or four args: <ric-id> <sim-param> <target-value> [ timeout ]" |
| 392 | return 1 |
| 393 | fi |
| 394 | } |
| 395 | |
| 396 | # Print a variable value from the RIC sim. |
| 397 | # args: <ric-id> <variable-name> |
| 398 | # (Function for test scripts) |
| 399 | sim_print() { |
| 400 | |
| 401 | if [ $# != 2 ]; then |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 402 | __print_err "need two args, <ric-id> <sim-param>" $@ |
| 403 | exit 1 |
| 404 | fi |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 405 | host=$(__find_sim_host $1) |
| 406 | echo -e $BOLD"INFO(${BASH_LINENO[0]}): $1, $2 = $(__do_curl $host/counter/$2)"$EBOLD |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 407 | } |
| 408 | |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 409 | # Tests if a variable value in the RIC simulator contains the target string and and optional timeout |
| 410 | # Arg: <ric-id> <variable-name> <target-value> - This test set pass or fail depending on if the variable contains |
| 411 | # the target or not. |
| 412 | # Arg: <ric-id> <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 413 | # before setting pass or fail depending on if the variable value contains the target |
| 414 | # value or not. |
| 415 | # (Function for test scripts) |
| 416 | sim_contains_str() { |
| 417 | |
| 418 | if [ $# -eq 3 ] || [ $# -eq 4 ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 419 | host=$(__find_sim_host $1) |
| 420 | __var_test $1 "$host/counter/" $2 "contain_str" $3 $4 |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 421 | return 0 |
| 422 | else |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 423 | __print_err "needs three or four args: <ric-id> <sim-param> <target-value> [ timeout ]" |
| 424 | return 1 |
| 425 | fi |
| 426 | } |
| 427 | |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 428 | # Simulator API: Put a policy type in a ric |
| 429 | # args: <response-code> <ric-id> <policy-type-id> <policy-type-file> |
| 430 | # (Function for test scripts) |
| 431 | sim_put_policy_type() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 432 | __log_conf_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 433 | if [ $# -ne 4 ]; then |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 434 | __print_err "<response-code> <ric-id> <policy-type-id> <policy-type-file>" $@ |
| 435 | return 1 |
| 436 | fi |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 437 | host=$(__find_sim_host $2) |
| 438 | curlString="curl -X PUT -skw %{http_code} "$host"/policytype?id="$3" -H Content-Type:application/json --data-binary @"$4 |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 439 | __execute_curl_to_sim $1 "$curlString" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 440 | return $? |
| 441 | } |
| 442 | |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 443 | # Simulator API: Delete a policy type in a ric |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 444 | # <response-code> <ric-id> <policy-type-id> |
| 445 | # (Function for test scripts) |
| 446 | sim_delete_policy_type() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 447 | __log_conf_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 448 | if [ $# -ne 3 ]; then |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 449 | __print_err "<response-code> <ric-id> <policy_type_id>" $@ |
| 450 | return 1 |
| 451 | fi |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 452 | host=$(__find_sim_host $2) |
| 453 | curlString="curl -X DELETE -skw %{http_code} "$host"/policytype?id="$3 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 454 | __execute_curl_to_sim $1 "$curlString" |
| 455 | return $? |
| 456 | } |
| 457 | |
| 458 | # Simulator API: Delete instances (and status), for one ric |
| 459 | # <response-code> <ric-id> |
| 460 | # (Function for test scripts) |
| 461 | sim_post_delete_instances() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 462 | __log_conf_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 463 | if [ $# -ne 2 ]; then |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 464 | __print_err "<response-code> <ric-id>" $@ |
| 465 | return 1 |
| 466 | fi |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 467 | host=$(__find_sim_host $2) |
| 468 | curlString="curl -X POST -skw %{http_code} "$host"/deleteinstances" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 469 | __execute_curl_to_sim $1 "$curlString" |
| 470 | return $? |
| 471 | } |
| 472 | |
| 473 | # Simulator API: Delete all (instances/types/statuses/settings), for one ric |
| 474 | # <response-code> <ric-id> |
| 475 | # (Function for test scripts) |
| 476 | sim_post_delete_all() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 477 | __log_conf_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 478 | if [ $# -ne 3 ]; then |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 479 | __print_err "<response-code> <numericic-id>" $@ |
| 480 | return 1 |
| 481 | fi |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 482 | host=$(__find_sim_host $2) |
| 483 | curlString="curl -X POST -skw %{http_code} "$host"/deleteall" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 484 | __execute_curl_to_sim $1 "$curlString" |
| 485 | return $? |
| 486 | } |
| 487 | |
| 488 | # Simulator API: Set (or reset) response code for next A1 message, for one ric |
| 489 | # <response-code> <ric-id> [<forced_response_code>] |
| 490 | # (Function for test scripts) |
| 491 | sim_post_forcedresponse() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 492 | __log_conf_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 493 | if [ $# -ne 3 ]; then |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 494 | __print_err "<response-code> <ric-id> <forced_response_code>" $@ |
| 495 | return 1 |
| 496 | fi |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 497 | host=$(__find_sim_host $2) |
| 498 | curlString="curl -X POST -skw %{http_code} "$host"/forceresponse" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 499 | if [ $# -eq 3 ]; then |
| 500 | curlString=$curlString"?code="$3 |
| 501 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 502 | __execute_curl_to_sim $1 "$curlString" |
| 503 | return $? |
| 504 | } |
| 505 | |
| 506 | # Simulator API: Set (or reset) A1 response delay, for one ric |
| 507 | # <response-code> <ric-id> [<delay-in-seconds>] |
| 508 | # (Function for test scripts) |
| 509 | sim_post_forcedelay() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 510 | __log_conf_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 511 | if [ $# -ne 3 ]; then |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 512 | __print_err "<response-code> <ric-id> [<delay-in-seconds>]" $@ |
| 513 | return 1 |
| 514 | fi |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 515 | host=$(__find_sim_host $2) |
| 516 | curlString="curl -X POST -skw %{http_code} $host/forcedelay" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 517 | if [ $# -eq 3 ]; then |
| 518 | curlString=$curlString"?delay="$3 |
| 519 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 520 | __execute_curl_to_sim $1 "$curlString" |
| 521 | return $? |
| 522 | } |