BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +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 managemnt functions test functions for the Callback Reciver |
BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +0100 | [diff] [blame] | 21 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 22 | |
| 23 | ################ Test engine functions ################ |
| 24 | |
| 25 | # Create the image var used during the test |
| 26 | # arg: <image-tag-suffix> (selects staging, snapshot, release etc) |
| 27 | # <image-tag-suffix> is present only for images with staging, snapshot,release tags |
| 28 | __CR_imagesetup() { |
| 29 | __check_and_create_image_var CR "CR_IMAGE" "CR_IMAGE_BASE" "CR_IMAGE_TAG" LOCAL "$CR_DISPLAY_NAME" |
| 30 | } |
| 31 | |
| 32 | # Pull image from remote repo or use locally built image |
| 33 | # arg: <pull-policy-override> <pull-policy-original> |
| 34 | # <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images |
| 35 | # <pull-policy-original> Shall be used for images that does not allow overriding |
| 36 | # Both var may contain: 'remote', 'remote-remove' or 'local' |
| 37 | __CR_imagepull() { |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 38 | echo -e $RED" Image for app CR shall never be pulled from remote repo"$ERED |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | # Build image (only for simulator or interfaces stubs owned by the test environment) |
| 42 | # arg: <image-tag-suffix> (selects staging, snapshot, release etc) |
| 43 | # <image-tag-suffix> is present only for images with staging, snapshot,release tags |
| 44 | __CR_imagebuild() { |
| 45 | cd ../cr |
| 46 | echo " Building CR - $CR_DISPLAY_NAME - image: $CR_IMAGE" |
| 47 | docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $CR_IMAGE . &> .dockererr |
| 48 | if [ $? -eq 0 ]; then |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame] | 49 | echo -e $GREEN" Build Ok"$EGREEN |
| 50 | __retag_and_push_image CR_IMAGE |
| 51 | if [ $? -ne 0 ]; then |
| 52 | exit 1 |
| 53 | fi |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 54 | else |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame] | 55 | echo -e $RED" Build Failed"$ERED |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 56 | ((RES_CONF_FAIL++)) |
| 57 | cat .dockererr |
| 58 | echo -e $RED"Exiting...."$ERED |
| 59 | exit 1 |
| 60 | fi |
| 61 | } |
| 62 | |
| 63 | # 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] | 64 | # 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] | 65 | # arg: <docker-images-format-string> <file-to-append> |
| 66 | __CR_image_data() { |
| 67 | echo -e "$CR_DISPLAY_NAME\t$(docker images --format $1 $CR_IMAGE)" >> $2 |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame] | 68 | if [ ! -z "$CR_IMAGE_SOURCE" ]; then |
| 69 | echo -e "-- source image --\t$(docker images --format $1 $CR_IMAGE_SOURCE)" >> $2 |
| 70 | fi |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | # Scale kubernetes resources to zero |
| 74 | # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action. |
| 75 | # This function is called for apps fully managed by the test script |
| 76 | __CR_kube_scale_zero() { |
| 77 | __kube_scale_all_resources $KUBE_SIM_NAMESPACE autotest CR |
| 78 | } |
| 79 | |
| 80 | # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action. |
| 81 | # This function is called for prestarted apps not managed by the test script. |
| 82 | __CR_kube_scale_zero_and_wait() { |
| 83 | echo -e $RED" CR app is not scaled in this state"$ERED |
| 84 | } |
| 85 | |
| 86 | # Delete all kube resouces for the app |
| 87 | # This function is called for apps managed by the test script. |
| 88 | __CR_kube_delete_all() { |
| 89 | __kube_delete_all_resources $KUBE_SIM_NAMESPACE autotest CR |
| 90 | } |
| 91 | |
| 92 | # Store docker logs |
| 93 | # This function is called for apps managed by the test script. |
| 94 | # args: <log-dir> <file-prexix> |
| 95 | __CR_store_docker_logs() { |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 96 | if [ $RUNMODE == "KUBE" ]; then |
BjornMagnussonXA | cb6113e | 2022-02-17 15:01:28 +0100 | [diff] [blame] | 97 | for podname in $(kubectl $KUBECONF get pods -n $KUBE_SIM_NAMESPACE -l "autotest=CR" -o custom-columns=":metadata.name"); do |
| 98 | kubectl $KUBECONF logs -n $KUBE_SIM_NAMESPACE $podname --tail=-1 > $1$2_$podname.log 2>&1 |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 99 | done |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 100 | else |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 101 | crs=$(docker ps --filter "name=$CR_APP_NAME" --filter "network=$DOCKER_SIM_NWNAME" --filter "status=running" --format {{.Names}}) |
| 102 | for crid in $crs; do |
| 103 | docker logs $crid > $1$2_$crid.log 2>&1 |
| 104 | done |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 105 | fi |
| 106 | } |
| 107 | |
| 108 | # Initial setup of protocol, host and ports |
| 109 | # This function is called for apps managed by the test script. |
| 110 | # args: - |
| 111 | __CR_initial_setup() { |
| 112 | use_cr_http |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 113 | } |
| 114 | |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 115 | # Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers |
| 116 | # For docker, the namespace shall be excluded |
| 117 | # This function is called for apps managed by the test script as well as for prestarted apps. |
| 118 | # args: - |
| 119 | __CR_statisics_setup() { |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 120 | for ((CR_INSTANCE=MAX_CR_APP_COUNT; CR_INSTANCE>0; CR_INSTANCE-- )); do |
| 121 | if [ $RUNMODE == "KUBE" ]; then |
| 122 | CR_INSTANCE_KUBE=$(($CR_INSTANCE-1)) |
| 123 | echo -n " CR-$CR_INSTANCE_KUBE $CR_APP_NAME-$CR_INSTANCE_KUBE $KUBE_SIM_NAMESPACE " |
| 124 | else |
BjornMagnussonXA | 51f04f0 | 2021-11-23 09:22:35 +0100 | [diff] [blame] | 125 | if [ $DOCKER_COMPOSE_VERION == "V1" ]; then |
| 126 | echo -n " CR_$CR_INSTANCE ${CR_APP_NAME}_cr_$CR_INSTANCE " |
| 127 | else |
| 128 | echo -n " CR_$CR_INSTANCE ${CR_APP_NAME}-cr-$CR_INSTANCE " |
| 129 | fi |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 130 | fi |
| 131 | done |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 132 | } |
| 133 | |
BjornMagnussonXA | e60d04e | 2021-12-27 13:38:01 +0100 | [diff] [blame] | 134 | # Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied |
| 135 | # args: - |
| 136 | __CR_test_requirements() { |
| 137 | : |
| 138 | } |
| 139 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 140 | ####################################################### |
| 141 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 142 | ################ |
| 143 | ### CR functions |
| 144 | ################ |
BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +0100 | [diff] [blame] | 145 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 146 | #Var to hold the current number of CR instances |
| 147 | CR_APP_COUNT=1 |
| 148 | MAX_CR_APP_COUNT=10 |
| 149 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 150 | # Set http as the protocol to use for all communication to the Dmaap adapter |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 151 | # args: - |
| 152 | # (Function for test scripts) |
| 153 | use_cr_http() { |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 154 | __cr_set_protocoll "http" $CR_INTERNAL_PORT $CR_EXTERNAL_PORT |
BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +0100 | [diff] [blame] | 155 | } |
| 156 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 157 | # Set https as the protocol to use for all communication to the Dmaap adapter |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 158 | # args: - |
| 159 | # (Function for test scripts) |
| 160 | use_cr_https() { |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 161 | __cr_set_protocoll "https" $CR_INTERNAL_SECURE_PORT $CR_EXTERNAL_SECURE_PORT |
| 162 | } |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 163 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 164 | # Setup paths to svc/container for internal and external access |
| 165 | # args: <protocol> <internal-port> <external-port> |
| 166 | __cr_set_protocoll() { |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 167 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 168 | echo -e $BOLD"$CR_DISPLAY_NAME protocol setting"$EBOLD |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 169 | echo -e " Using $BOLD $1 $EBOLD towards $CR_DISPLAY_NAME" |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 170 | ## Access to Dmaap adapter |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 171 | for ((CR_INSTANCE=0; CR_INSTANCE<$MAX_CR_APP_COUNT; CR_INSTANCE++ )); do |
| 172 | CR_DOCKER_INSTANCE=$(($CR_INSTANCE+1)) |
| 173 | # CR_SERVICE_PATH is the base path to cr |
BjornMagnussonXA | 51f04f0 | 2021-11-23 09:22:35 +0100 | [diff] [blame] | 174 | if [ $DOCKER_COMPOSE_VERION == "V1" ]; then |
| 175 | __CR_SERVICE_PATH=$1"://"$CR_APP_NAME"_cr_"${CR_DOCKER_INSTANCE}":"$2 # docker access, container->container and script->container via proxy |
| 176 | else |
| 177 | __CR_SERVICE_PATH=$1"://"$CR_APP_NAME"-cr-"${CR_DOCKER_INSTANCE}":"$2 # docker access, container->container and script->container via proxy |
| 178 | fi |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 179 | if [ $RUNMODE == "KUBE" ]; then |
| 180 | __CR_SERVICE_PATH=$1"://"$CR_APP_NAME"-"$CR_INSTANCE.$CR_APP_NAME"."$KUBE_SIM_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy |
| 181 | fi |
| 182 | export CR_SERVICE_PATH"_"${CR_INSTANCE}=$__CR_SERVICE_PATH |
| 183 | # Service paths are used in test script to provide callbacck urls to app |
| 184 | export CR_SERVICE_MR_PATH"_"${CR_INSTANCE}=$__CR_SERVICE_PATH$CR_APP_CALLBACK_MR #Only for messages from dmaap adapter/mediator |
| 185 | export CR_SERVICE_TEXT_PATH"_"${CR_INSTANCE}=$__CR_SERVICE_PATH$CR_APP_CALLBACK_TEXT #Callbacks for text payload |
| 186 | export CR_SERVICE_APP_PATH"_"${CR_INSTANCE}=$__CR_SERVICE_PATH$CR_APP_CALLBACK #For general callbacks from apps |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 187 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 188 | if [ $CR_INSTANCE -eq 0 ]; then |
| 189 | # CR_ADAPTER used for switching between REST and DMAAP (only REST supported currently) |
| 190 | # CR_ADDAPTER need to be set before each call to CR....only set for instance 0 here |
| 191 | CR_ADAPTER_TYPE="REST" |
| 192 | CR_ADAPTER=$__CR_SERVICE_PATH |
| 193 | fi |
| 194 | done |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 195 | echo "" |
| 196 | } |
| 197 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 198 | # Export env vars for config files, docker compose and kube resources |
| 199 | # args: <proxy-flag> |
| 200 | __cr_export_vars() { |
| 201 | export CR_APP_NAME |
| 202 | export CR_DISPLAY_NAME |
| 203 | |
| 204 | export KUBE_SIM_NAMESPACE |
| 205 | export DOCKER_SIM_NWNAME |
| 206 | |
| 207 | export CR_IMAGE |
| 208 | |
| 209 | export CR_INTERNAL_PORT |
| 210 | export CR_INTERNAL_SECURE_PORT |
| 211 | export CR_EXTERNAL_PORT |
| 212 | export CR_EXTERNAL_SECURE_PORT |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 213 | |
| 214 | export CR_APP_COUNT |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 215 | } |
| 216 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 217 | # Start the Callback reciver in the simulator group |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 218 | # args: <app-count> |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 219 | # (Function for test scripts) |
| 220 | start_cr() { |
| 221 | |
| 222 | echo -e $BOLD"Starting $CR_DISPLAY_NAME"$EBOLD |
| 223 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 224 | if [ $# -ne 1 ]; then |
| 225 | echo -e $RED" Number of CR instances missing, usage: start_cr <app-count>"$ERED |
| 226 | exit 1 |
| 227 | fi |
| 228 | if [ $1 -lt 1 ] || [ $1 -gt 10 ]; then |
| 229 | echo -e $RED" Number of CR shall be 1...10, usage: start_cr <app-count>"$ERED |
| 230 | exit 1 |
| 231 | fi |
| 232 | export CR_APP_COUNT=$1 |
| 233 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 234 | if [ $RUNMODE == "KUBE" ]; then |
| 235 | |
| 236 | # Check if app shall be fully managed by the test script |
| 237 | __check_included_image "CR" |
| 238 | retcode_i=$? |
| 239 | |
| 240 | # Check if app shall only be used by the testscipt |
| 241 | __check_prestarted_image "CR" |
| 242 | retcode_p=$? |
| 243 | |
| 244 | if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then |
| 245 | echo -e $RED"The $CR_APP_NAME app is not included as managed nor prestarted in this test script"$ERED |
| 246 | echo -e $RED"The $CR_APP_NAME will not be started"$ERED |
| 247 | exit |
| 248 | fi |
| 249 | if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then |
| 250 | echo -e $RED"The $CR_APP_NAME app is included both as managed and prestarted in this test script"$ERED |
| 251 | echo -e $RED"The $CR_APP_NAME will not be started"$ERED |
| 252 | exit |
| 253 | fi |
| 254 | |
| 255 | # Check if app shall be used - not managed - by the test script |
| 256 | if [ $retcode_p -eq 0 ]; then |
| 257 | echo -e " Using existing $CR_APP_NAME deployment and service" |
| 258 | echo " Setting CR replicas=1" |
| 259 | __kube_scale deployment $CR_APP_NAME $KUBE_SIM_NAMESPACE 1 |
| 260 | fi |
| 261 | |
| 262 | if [ $retcode_i -eq 0 ]; then |
| 263 | echo -e " Creating $CR_APP_NAME deployment and service" |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 264 | |
| 265 | __cr_export_vars |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 266 | |
| 267 | __kube_create_namespace $KUBE_SIM_NAMESPACE |
| 268 | |
| 269 | # Create service |
| 270 | input_yaml=$SIM_GROUP"/"$CR_COMPOSE_DIR"/"svc.yaml |
| 271 | output_yaml=$PWD/tmp/cr_svc.yaml |
| 272 | __kube_create_instance service $CR_APP_NAME $input_yaml $output_yaml |
| 273 | |
| 274 | # Create app |
| 275 | input_yaml=$SIM_GROUP"/"$CR_COMPOSE_DIR"/"app.yaml |
| 276 | output_yaml=$PWD/tmp/cr_app.yaml |
| 277 | __kube_create_instance app $CR_APP_NAME $input_yaml $output_yaml |
| 278 | |
| 279 | fi |
| 280 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 281 | for ((CR_INSTANCE=0; CR_INSTANCE<$CR_APP_COUNT; CR_INSTANCE++ )); do |
| 282 | __dynvar="CR_SERVICE_PATH_"$CR_INSTANCE |
| 283 | __cr_app_name=$CR_APP_NAME"-"$CR_INSTANCE |
| 284 | __check_service_start $__cr_app_name ${!__dynvar}$CR_ALIVE_URL |
| 285 | result=$(__do_curl ${!__dynvar}/reset) |
| 286 | done |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 287 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 288 | else |
| 289 | # Check if docker app shall be fully managed by the test script |
| 290 | __check_included_image 'CR' |
| 291 | if [ $? -eq 1 ]; then |
| 292 | echo -e $RED"The Callback Receiver app is not included in this test script"$ERED |
| 293 | echo -e $RED"The Callback Receiver will not be started"$ERED |
| 294 | exit |
| 295 | fi |
| 296 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 297 | __cr_export_vars |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 298 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 299 | app_data="" |
| 300 | cntr=1 |
| 301 | while [ $cntr -le $CR_APP_COUNT ]; do |
BjornMagnussonXA | 51f04f0 | 2021-11-23 09:22:35 +0100 | [diff] [blame] | 302 | if [ $DOCKER_COMPOSE_VERION == "V1" ]; then |
| 303 | app=$CR_APP_NAME"_cr_"$cntr |
| 304 | else |
| 305 | app=$CR_APP_NAME"-cr-"$cntr |
| 306 | fi |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 307 | app_data="$app_data $app" |
| 308 | let cntr=cntr+1 |
| 309 | done |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 310 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 311 | echo "COMPOSE_PROJECT_NAME="$CR_APP_NAME > $SIM_GROUP/$CR_COMPOSE_DIR/.env |
| 312 | |
| 313 | __start_container $CR_COMPOSE_DIR "" NODOCKERARGS $CR_APP_COUNT $app_data |
| 314 | |
| 315 | cntr=1 #Counter for docker instance, starts on 1 |
| 316 | cntr2=0 #Couter for env var name, starts with 0 to be compablible with kube |
| 317 | while [ $cntr -le $CR_APP_COUNT ]; do |
BjornMagnussonXA | 51f04f0 | 2021-11-23 09:22:35 +0100 | [diff] [blame] | 318 | if [ $DOCKER_COMPOSE_VERION == "V1" ]; then |
| 319 | app=$CR_APP_NAME"_cr_"$cntr |
| 320 | else |
| 321 | app=$CR_APP_NAME"-cr-"$cntr |
| 322 | fi |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 323 | __dynvar="CR_SERVICE_PATH_"$cntr2 |
| 324 | __check_service_start $app ${!__dynvar}$CR_ALIVE_URL |
| 325 | let cntr=cntr+1 |
| 326 | let cntr2=cntr2+1 |
| 327 | done |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 328 | fi |
| 329 | echo "" |
| 330 | } |
| 331 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 332 | #Convert a cr path id to the value of the environment var holding the url |
| 333 | # arg: <cr-path-id> |
| 334 | # returns: <base-url-to-the-app> |
| 335 | __cr_get_service_path(){ |
| 336 | if [ $# -ne 1 ]; then |
| 337 | echo "DUMMY" |
| 338 | return 1 |
| 339 | fi |
| 340 | if [ $1 -lt 0 ] || [ $1 -ge $MAX_CR_APP_COUNT ]; then |
| 341 | echo "DUMMY" |
| 342 | return 1 |
| 343 | fi |
| 344 | __dynvar="CR_SERVICE_PATH_"$1 |
| 345 | echo ${!__dynvar} |
| 346 | return 0 |
| 347 | } |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 348 | |
BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +0100 | [diff] [blame] | 349 | # Tests if a variable value in the CR is equal to a target value and and optional timeout. |
| 350 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is |
| 351 | # equal to the target or not. |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 352 | # Arg: <cr-path-id> <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +0100 | [diff] [blame] | 353 | # before setting pass or fail depending on if the variable value becomes equal to the target |
| 354 | # value or not. |
| 355 | # (Function for test scripts) |
| 356 | cr_equal() { |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 357 | if [ $# -eq 3 ] || [ $# -eq 4 ]; then |
| 358 | CR_SERVICE_PATH=$(__cr_get_service_path $1) |
| 359 | CR_ADAPTER=$CR_SERVICE_PATH |
| 360 | if [ $? -ne 0 ]; then |
| 361 | __print_err "<cr-path-id> missing or incorrect" $@ |
| 362 | return 1 |
| 363 | fi |
| 364 | __var_test "CR" "$CR_SERVICE_PATH/counter/" $2 "=" $3 $4 |
BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +0100 | [diff] [blame] | 365 | else |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 366 | __print_err "Wrong args to cr_equal, needs three or four args: <cr-path-id> <variable-name> <target-value> [ timeout ]" $@ |
BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +0100 | [diff] [blame] | 367 | fi |
| 368 | } |
| 369 | |
BjornMagnussonXA | 8fbb226 | 2022-01-24 15:20:15 +0100 | [diff] [blame] | 370 | # Tests if a variable value in the CR is equal to or greater than the target value and and optional timeout. |
| 371 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is |
| 372 | # equal to the target or not. |
| 373 | # Arg: <cr-path-id> <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 374 | # before setting pass or fail depending on if the variable value becomes equal to or greater than the target |
| 375 | # value or not. |
| 376 | # (Function for test scripts) |
| 377 | cr_greater_or_equal() { |
| 378 | if [ $# -eq 3 ] || [ $# -eq 4 ]; then |
| 379 | CR_SERVICE_PATH=$(__cr_get_service_path $1) |
| 380 | CR_ADAPTER=$CR_SERVICE_PATH |
| 381 | if [ $? -ne 0 ]; then |
| 382 | __print_err "<cr-path-id> missing or incorrect" $@ |
| 383 | return 1 |
| 384 | fi |
| 385 | __var_test "CR" "$CR_SERVICE_PATH/counter/" $2 ">=" $3 $4 |
| 386 | else |
| 387 | __print_err "Wrong args to cr_equal, needs three or four args: <cr-path-id> <variable-name> <target-value> [ timeout ]" $@ |
| 388 | fi |
| 389 | } |
| 390 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 391 | # Tests if a variable value in the CR contains the target string and and optional timeout |
| 392 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable contains |
| 393 | # the target or not. |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 394 | # Arg: <cr-path-id> <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 395 | # before setting pass or fail depending on if the variable value contains the target |
| 396 | # value or not. |
| 397 | # (Function for test scripts) |
| 398 | cr_contains_str() { |
| 399 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 400 | if [ $# -eq 3 ] || [ $# -eq 4 ]; then |
| 401 | CR_SERVICE_PATH=$(__cr_get_service_path $1) |
| 402 | CR_ADAPTER=$CR_SERVICE_PATH |
| 403 | if [ $? -ne 0 ]; then |
| 404 | __print_err "<cr-path-id> missing or incorrect" $@ |
| 405 | return 1 |
| 406 | fi |
| 407 | __var_test "CR" "$CR_SERVICE_PATH/counter/" $2 "contain_str" $3 $4 |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 408 | return 0 |
| 409 | else |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 410 | __print_err "needs two or three args: <cr-path-id> <variable-name> <target-value> [ timeout ]" |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 411 | return 1 |
| 412 | fi |
| 413 | } |
| 414 | |
BjornMagnussonXA | 8fbb226 | 2022-01-24 15:20:15 +0100 | [diff] [blame] | 415 | # Read a variable value from CR sim and send to stdout. Arg: <cr-path-id> <variable-name> |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 416 | cr_read() { |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 417 | CR_SERVICE_PATH=$(__cr_get_service_path $1) |
| 418 | CR_ADAPTER=$CR_SERVICE_PATH |
| 419 | if [ $? -ne 0 ]; then |
| 420 | __print_err "<cr-path-id> missing or incorrect" $@ |
| 421 | return 1 |
| 422 | fi |
BjornMagnussonXA | 8fbb226 | 2022-01-24 15:20:15 +0100 | [diff] [blame] | 423 | echo "$(__do_curl $CR_SERVICE_PATH/counter/$2)" |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | # Function to configure write delay on callbacks |
| 427 | # Delay given in seconds. |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 428 | # arg <response-code> <cr-path-id> <delay-in-sec> |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 429 | # (Function for test scripts) |
| 430 | cr_delay_callback() { |
| 431 | __log_conf_start $@ |
| 432 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 433 | if [ $# -ne 3 ]; then |
| 434 | __print_err "<response-code> <cr-path-id> <delay-in-sec>]" $@ |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 435 | return 1 |
| 436 | fi |
| 437 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 438 | CR_SERVICE_PATH=$(__cr_get_service_path $2) |
| 439 | CR_ADAPTER=$CR_SERVICE_PATH |
| 440 | if [ $? -ne 0 ]; then |
| 441 | __print_err "<cr-path-id> missing or incorrect" $@ |
| 442 | return 1 |
| 443 | fi |
| 444 | |
| 445 | res="$(__do_curl_to_api CR POST /forcedelay?delay=$3)" |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 446 | status=${res:${#res}-3} |
| 447 | |
| 448 | if [ $status -ne 200 ]; then |
| 449 | __log_conf_fail_status_code $1 $status |
| 450 | return 1 |
| 451 | fi |
| 452 | |
| 453 | __log_conf_ok |
| 454 | return 0 |
| 455 | } |
| 456 | |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame^] | 457 | # CR API: Check the contents of all current ric sync events for one id from A1PMS |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 458 | # <response-code> <cr-path-id> <id> [ EMPTY | ( <ric-id> )+ ] |
BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +0100 | [diff] [blame] | 459 | # (Function for test scripts) |
| 460 | cr_api_check_all_sync_events() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 461 | __log_test_start $@ |
BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +0100 | [diff] [blame] | 462 | |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame^] | 463 | if [ "$A1PMS_VERSION" != "V2" ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 464 | __log_test_fail_not_supported |
BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +0100 | [diff] [blame] | 465 | return 1 |
| 466 | fi |
| 467 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 468 | if [ $# -lt 3 ]; then |
| 469 | __print_err "<response-code> <cr-path-id> <id> [ EMPTY | ( <ric-id> )+ ]" $@ |
BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +0100 | [diff] [blame] | 470 | return 1 |
| 471 | fi |
| 472 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 473 | CR_SERVICE_PATH=$(__cr_get_service_path $2) |
| 474 | CR_ADAPTER=$CR_SERVICE_PATH |
| 475 | if [ $? -ne 0 ]; then |
| 476 | __print_err "<cr-path-id> missing or incorrect" $@ |
| 477 | return 1 |
| 478 | fi |
| 479 | |
| 480 | query="/get-all-events/"$3 |
BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +0100 | [diff] [blame] | 481 | res="$(__do_curl_to_api CR GET $query)" |
| 482 | status=${res:${#res}-3} |
| 483 | |
| 484 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 485 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +0100 | [diff] [blame] | 486 | return 1 |
| 487 | fi |
| 488 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 489 | if [ $# -gt 3 ]; then |
BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +0100 | [diff] [blame] | 490 | body=${res:0:${#res}-3} |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 491 | if [ $# -eq 4 ] && [ $4 == "EMPTY" ]; then |
BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +0100 | [diff] [blame] | 492 | targetJson="[" |
| 493 | else |
| 494 | targetJson="[" |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 495 | arr=(${@:4}) |
BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +0100 | [diff] [blame] | 496 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 497 | for ((i=0; i<$(($#-3)); i=i+1)); do |
BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +0100 | [diff] [blame] | 498 | |
| 499 | if [ "$targetJson" != "[" ]; then |
| 500 | targetJson=$targetJson"," |
| 501 | fi |
| 502 | targetJson=$targetJson"{\"ric_id\":\"${arr[$i]}\",\"event_type\":\"AVAILABLE\"}" |
| 503 | done |
| 504 | fi |
| 505 | |
| 506 | targetJson=$targetJson"]" |
| 507 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
| 508 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 509 | |
| 510 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 511 | __log_test_fail_body |
BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +0100 | [diff] [blame] | 512 | return 1 |
| 513 | fi |
| 514 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 515 | __log_test_pass |
| 516 | return 0 |
| 517 | } |
| 518 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 519 | # CR API: Check the contents of all current status events for one id from ICS |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 520 | # <response-code> <cr-path-id> <id> [ EMPTY | ( <status> )+ ] |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 521 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 522 | cr_api_check_all_ics_events() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 523 | __log_test_start $@ |
| 524 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 525 | if [ $# -lt 3 ]; then |
| 526 | __print_err "<response-code> <cr-path-id> <id> [ EMPTY | ( <status> )+ ]" $@ |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 527 | return 1 |
| 528 | fi |
| 529 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 530 | CR_SERVICE_PATH=$(__cr_get_service_path $2) |
| 531 | CR_ADAPTER=$CR_SERVICE_PATH |
| 532 | if [ $? -ne 0 ]; then |
| 533 | __print_err "<cr-path-id> missing or incorrect" $@ |
| 534 | return 1 |
| 535 | fi |
| 536 | |
| 537 | query="/get-all-events/"$3 |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 538 | res="$(__do_curl_to_api CR GET $query)" |
| 539 | status=${res:${#res}-3} |
| 540 | |
| 541 | if [ $status -ne $1 ]; then |
| 542 | __log_test_fail_status_code $1 $status |
| 543 | return 1 |
| 544 | fi |
| 545 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 546 | if [ $# -gt 3 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 547 | body=${res:0:${#res}-3} |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 548 | if [ $# -eq 4 ] && [ $4 == "EMPTY" ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 549 | targetJson="[" |
| 550 | else |
| 551 | targetJson="[" |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 552 | arr=(${@:4}) |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 553 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 554 | for ((i=0; i<$(($#-3)); i=i+1)); do |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 555 | |
| 556 | if [ "$targetJson" != "[" ]; then |
| 557 | targetJson=$targetJson"," |
| 558 | fi |
| 559 | targetJson=$targetJson"{\"eiJobStatus\":\"${arr[$i]}\"}" |
| 560 | done |
| 561 | fi |
| 562 | |
| 563 | targetJson=$targetJson"]" |
| 564 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
| 565 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 566 | |
| 567 | if [ $res -ne 0 ]; then |
| 568 | __log_test_fail_body |
| 569 | return 1 |
| 570 | fi |
| 571 | fi |
| 572 | __log_test_pass |
BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +0100 | [diff] [blame] | 573 | return 0 |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 574 | } |
| 575 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 576 | # CR API: Check the contents of all current type subscription events for one id from ICS |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 577 | # <response-code> <cr-path-id> <id> [ EMPTY | ( <type-id> <schema> <registration-status> )+ ] |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 578 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 579 | cr_api_check_all_ics_subscription_events() { |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 580 | __log_test_start $@ |
| 581 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 582 | #Valid number of parameter 3,4,8,12 |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 583 | paramError=1 |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 584 | if [ $# -eq 3 ]; then |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 585 | paramError=0 |
| 586 | fi |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 587 | if [ $# -eq 4 ] && [ "$4" == "EMPTY" ]; then |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 588 | paramError=0 |
| 589 | fi |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 590 | variablecount=$(($#-3)) |
| 591 | if [ $# -gt 4 ] && [ $(($variablecount%3)) -eq 0 ]; then |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 592 | paramError=0 |
| 593 | fi |
| 594 | if [ $paramError -eq 1 ]; then |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 595 | __print_err "<response-code> <cr-path-id> <id> [ EMPTY | ( <type-id> <schema> <registration-status> )+ ]" $@ |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 596 | return 1 |
| 597 | fi |
| 598 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 599 | CR_SERVICE_PATH=$(__cr_get_service_path $2) |
| 600 | CR_ADAPTER=$CR_SERVICE_PATH |
| 601 | if [ $? -ne 0 ]; then |
| 602 | __print_err "<cr-path-id> missing or incorrect" $@ |
| 603 | return 1 |
| 604 | fi |
| 605 | |
| 606 | query="/get-all-events/"$3 |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 607 | res="$(__do_curl_to_api CR GET $query)" |
| 608 | status=${res:${#res}-3} |
| 609 | |
| 610 | if [ $status -ne $1 ]; then |
| 611 | __log_test_fail_status_code $1 $status |
| 612 | return 1 |
| 613 | fi |
| 614 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 615 | if [ $# -gt 3 ]; then |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 616 | body=${res:0:${#res}-3} |
| 617 | targetJson="[" |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 618 | if [ $# -gt 4 ]; then |
| 619 | arr=(${@:4}) |
| 620 | for ((i=0; i<$(($#-4)); i=i+3)); do |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 621 | if [ "$targetJson" != "[" ]; then |
| 622 | targetJson=$targetJson"," |
| 623 | fi |
| 624 | if [ -f ${arr[$i+1]} ]; then |
| 625 | jobfile=$(cat ${arr[$i+1]}) |
| 626 | else |
| 627 | __log_test_fail_general "Job schema file "${arr[$i+1]}", does not exist" |
| 628 | return 1 |
| 629 | fi |
| 630 | targetJson=$targetJson"{\"info_type_id\":\"${arr[$i]}\",\"job_data_schema\":$jobfile,\"status\":\"${arr[$i+2]}\"}" |
| 631 | done |
| 632 | fi |
| 633 | targetJson=$targetJson"]" |
| 634 | |
| 635 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 636 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 637 | |
| 638 | if [ $res -ne 0 ]; then |
| 639 | __log_test_fail_body |
| 640 | return 1 |
| 641 | fi |
| 642 | fi |
| 643 | |
| 644 | __log_test_pass |
| 645 | return 0 |
| 646 | } |
| 647 | |
| 648 | |
| 649 | # CR API: Reset all events and counters |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 650 | # Arg: <cr-path-id> |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 651 | # (Function for test scripts) |
| 652 | cr_api_reset() { |
| 653 | __log_conf_start $@ |
| 654 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 655 | if [ $# -ne 1 ]; then |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 656 | __print_err "<cr-path-id>" $@ |
| 657 | return 1 |
| 658 | fi |
| 659 | |
| 660 | CR_SERVICE_PATH=$(__cr_get_service_path $1) |
| 661 | CR_ADAPTER=$CR_SERVICE_PATH |
| 662 | if [ $? -ne 0 ]; then |
| 663 | __print_err "<cr-path-id> missing or incorrect" $@ |
| 664 | return 1 |
| 665 | fi |
| 666 | |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 667 | res="$(__do_curl_to_api CR GET /reset)" |
| 668 | status=${res:${#res}-3} |
| 669 | |
| 670 | if [ $status -ne 200 ]; then |
| 671 | __log_conf_fail_status_code $1 $status |
| 672 | return 1 |
| 673 | fi |
| 674 | |
| 675 | __log_conf_ok |
| 676 | return 0 |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | |
| 680 | # CR API: Check the contents of all json events for path |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 681 | # <response-code> <cr-path-id> <topic-url> (EMPTY | <json-msg>+ ) |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 682 | # (Function for test scripts) |
| 683 | cr_api_check_all_genric_json_events() { |
| 684 | __log_test_start $@ |
| 685 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 686 | if [ $# -lt 4 ]; then |
| 687 | __print_err "<response-code> <cr-path-id> <topic-url> (EMPTY | <json-msg>+ )" $@ |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 688 | return 1 |
| 689 | fi |
| 690 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 691 | CR_SERVICE_PATH=$(__cr_get_service_path $2) |
| 692 | CR_ADAPTER=$CR_SERVICE_PATH |
| 693 | if [ $? -ne 0 ]; then |
| 694 | __print_err "<cr-path-id> missing or incorrect" $@ |
| 695 | return 1 |
| 696 | fi |
| 697 | |
| 698 | query="/get-all-events/"$3 |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 699 | res="$(__do_curl_to_api CR GET $query)" |
| 700 | status=${res:${#res}-3} |
| 701 | |
| 702 | if [ $status -ne $1 ]; then |
| 703 | __log_test_fail_status_code $1 $status |
| 704 | return 1 |
| 705 | fi |
| 706 | body=${res:0:${#res}-3} |
| 707 | targetJson="[" |
| 708 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 709 | if [ $4 != "EMPTY" ]; then |
| 710 | shift |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 711 | shift |
| 712 | shift |
| 713 | while [ $# -gt 0 ]; do |
| 714 | if [ "$targetJson" != "[" ]; then |
| 715 | targetJson=$targetJson"," |
| 716 | fi |
| 717 | targetJson=$targetJson$1 |
| 718 | shift |
| 719 | done |
| 720 | fi |
| 721 | targetJson=$targetJson"]" |
| 722 | |
| 723 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 724 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 725 | |
| 726 | if [ $res -ne 0 ]; then |
| 727 | __log_test_fail_body |
| 728 | return 1 |
| 729 | fi |
| 730 | |
| 731 | __log_test_pass |
| 732 | return 0 |
| 733 | } |
| 734 | |
| 735 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 736 | # CR API: Check a single (oldest) json event (or none if empty) for path |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 737 | # <response-code> <cr-path-id> <topic-url> (EMPTY | <json-msg> ) |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 738 | # (Function for test scripts) |
| 739 | cr_api_check_single_genric_json_event() { |
| 740 | __log_test_start $@ |
| 741 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 742 | if [ $# -ne 4 ]; then |
| 743 | __print_err "<response-code> <cr-path-id> <topic-url> (EMPTY | <json-msg> )" $@ |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 744 | return 1 |
| 745 | fi |
| 746 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 747 | CR_SERVICE_PATH=$(__cr_get_service_path $2) |
| 748 | CR_ADAPTER=$CR_SERVICE_PATH |
| 749 | if [ $? -ne 0 ]; then |
| 750 | __print_err "<cr-path-id> missing or incorrect" $@ |
| 751 | return 1 |
| 752 | fi |
| 753 | |
| 754 | query="/get-event/"$3 |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 755 | res="$(__do_curl_to_api CR GET $query)" |
| 756 | status=${res:${#res}-3} |
| 757 | |
| 758 | if [ $status -ne $1 ]; then |
| 759 | __log_test_fail_status_code $1 $status |
| 760 | return 1 |
| 761 | fi |
| 762 | body=${res:0:${#res}-3} |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 763 | targetJson=$4 |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 764 | |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 765 | if [ $targetJson == "EMPTY" ] && [ ${#body} -ne 0 ]; then |
| 766 | __log_test_fail_body |
| 767 | return 1 |
| 768 | fi |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 769 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 770 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 771 | |
| 772 | if [ $res -ne 0 ]; then |
| 773 | __log_test_fail_body |
| 774 | return 1 |
| 775 | fi |
| 776 | |
| 777 | __log_test_pass |
| 778 | return 0 |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | # CR API: Check a single (oldest) json in md5 format (or none if empty) for path. |
| 782 | # Note that if a json message is given, it shall be compact, no ws except inside string. |
| 783 | # The MD5 will generate different hash if ws is present or not in otherwise equivalent json |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 784 | # arg: <response-code> <cr-path-id> <topic-url> (EMPTY | <data-msg> ) |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 785 | # (Function for test scripts) |
| 786 | cr_api_check_single_genric_event_md5() { |
| 787 | __log_test_start $@ |
| 788 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 789 | if [ $# -ne 4 ]; then |
| 790 | __print_err "<response-code> <cr-path-id> <topic-url> (EMPTY | <data-msg> )" $@ |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 791 | return 1 |
| 792 | fi |
| 793 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 794 | CR_SERVICE_PATH=$(__cr_get_service_path $2) |
| 795 | CR_ADAPTER=$CR_SERVICE_PATH |
| 796 | if [ $? -ne 0 ]; then |
| 797 | __print_err "<cr-path-id> missing or incorrect" $@ |
| 798 | return 1 |
| 799 | fi |
| 800 | |
| 801 | query="/get-event/"$3 |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 802 | res="$(__do_curl_to_api CR GET $query)" |
| 803 | status=${res:${#res}-3} |
| 804 | |
| 805 | if [ $status -ne $1 ]; then |
| 806 | __log_test_fail_status_code $1 $status |
| 807 | return 1 |
| 808 | fi |
| 809 | body=${res:0:${#res}-3} |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 810 | if [ $4 == "EMPTY" ]; then |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 811 | if [ ${#body} -ne 0 ]; then |
| 812 | __log_test_fail_body |
| 813 | return 1 |
| 814 | else |
| 815 | __log_test_pass |
| 816 | return 0 |
| 817 | fi |
| 818 | fi |
| 819 | command -v md5 > /dev/null # Mac |
| 820 | if [ $? -eq 0 ]; then |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 821 | targetMd5=$(echo -n "$4" | md5) |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 822 | else |
| 823 | command -v md5sum > /dev/null # Linux |
| 824 | if [ $? -eq 0 ]; then |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 825 | targetMd5=$(echo -n "$4" | md5sum | cut -d' ' -f 1) # Need to cut additional info printed by cmd |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 826 | else |
| 827 | __log_test_fail_general "Command md5 nor md5sum is available" |
| 828 | return 1 |
| 829 | fi |
| 830 | fi |
| 831 | targetMd5="\""$targetMd5"\"" #Quotes needed |
| 832 | |
| 833 | echo " TARGET MD5 hash: $targetMd5" >> $HTTPLOG |
| 834 | |
| 835 | if [ "$body" != "$targetMd5" ]; then |
| 836 | __log_test_fail_body |
| 837 | return 1 |
| 838 | fi |
| 839 | |
| 840 | __log_test_pass |
| 841 | return 0 |
| 842 | } |
| 843 | |
| 844 | # CR API: Check a single (oldest) event in md5 format (or none if empty) for path. |
| 845 | # Note that if a file with json message is given, the json shall be compact, no ws except inside string and not newlines. |
| 846 | # The MD5 will generate different hash if ws/newlines is present or not in otherwise equivalent json |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 847 | # arg: <response-code> <cr-path-id> <topic-url> (EMPTY | <data-file> ) |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 848 | # (Function for test scripts) |
| 849 | cr_api_check_single_genric_event_md5_file() { |
| 850 | __log_test_start $@ |
| 851 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 852 | if [ $# -ne 4 ]; then |
| 853 | __print_err "<response-code> <cr-path-id> <topic-url> (EMPTY | <data-file> )" $@ |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 854 | return 1 |
| 855 | fi |
| 856 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 857 | CR_SERVICE_PATH=$(__cr_get_service_path $2) |
| 858 | CR_ADAPTER=$CR_SERVICE_PATH |
| 859 | if [ $? -ne 0 ]; then |
| 860 | __print_err "<cr-path-id> missing or incorrect" $@ |
| 861 | return 1 |
| 862 | fi |
| 863 | |
| 864 | query="/get-event/"$3 |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 865 | res="$(__do_curl_to_api CR GET $query)" |
| 866 | status=${res:${#res}-3} |
| 867 | |
| 868 | if [ $status -ne $1 ]; then |
| 869 | __log_test_fail_status_code $1 $status |
| 870 | return 1 |
| 871 | fi |
| 872 | body=${res:0:${#res}-3} |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 873 | if [ $4 == "EMPTY" ]; then |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 874 | if [ ${#body} -ne 0 ]; then |
| 875 | __log_test_fail_body |
| 876 | return 1 |
| 877 | else |
| 878 | __log_test_pass |
| 879 | return 0 |
| 880 | fi |
| 881 | fi |
| 882 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 883 | if [ ! -f $4 ]; then |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 884 | __log_test_fail_general "File $3 does not exist" |
| 885 | return 1 |
| 886 | fi |
| 887 | |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 888 | filedata=$(cat $4) |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 889 | |
| 890 | command -v md5 > /dev/null # Mac |
| 891 | if [ $? -eq 0 ]; then |
| 892 | targetMd5=$(echo -n "$filedata" | md5) |
| 893 | else |
| 894 | command -v md5sum > /dev/null # Linux |
| 895 | if [ $? -eq 0 ]; then |
| 896 | targetMd5=$(echo -n "$filedata" | md5sum | cut -d' ' -f 1) # Need to cut additional info printed by cmd |
| 897 | else |
| 898 | __log_test_fail_general "Command md5 nor md5sum is available" |
| 899 | return 1 |
| 900 | fi |
| 901 | fi |
| 902 | targetMd5="\""$targetMd5"\"" #Quotes needed |
| 903 | |
| 904 | echo " TARGET MD5 hash: $targetMd5" >> $HTTPLOG |
| 905 | |
| 906 | if [ "$body" != "$targetMd5" ]; then |
| 907 | __log_test_fail_body |
| 908 | return 1 |
| 909 | fi |
| 910 | |
| 911 | __log_test_pass |
| 912 | return 0 |
BjornMagnussonXA | 2791e08 | 2020-11-12 00:52:08 +0100 | [diff] [blame] | 913 | } |