BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [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 ECS |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [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 | __ECS_imagesetup() { |
| 28 | __check_and_create_image_var ECS "ECS_IMAGE" "ECS_IMAGE_BASE" "ECS_IMAGE_TAG" $1 "$ECS_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 | __ECS_imagepull() { |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame^] | 37 | __check_and_pull_image $1 "$ECS_DISPLAY_NAME" $ECS_APP_NAME ECS_IMAGE |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | # Build image (only for simulator or interfaces stubs owned by the test environment) |
| 41 | # arg: <image-tag-suffix> (selects staging, snapshot, release etc) |
| 42 | # <image-tag-suffix> is present only for images with staging, snapshot,release tags |
| 43 | __ECS_imagebuild() { |
| 44 | echo -e $RED" Image for app ECS shall never be built"$ERED |
| 45 | } |
| 46 | |
| 47 | # 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^] | 48 | # 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] | 49 | # arg: <docker-images-format-string> <file-to-append> |
| 50 | __ECS_image_data() { |
| 51 | echo -e "$ECS_DISPLAY_NAME\t$(docker images --format $1 $ECS_IMAGE)" >> $2 |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame^] | 52 | if [ ! -z "$ECS_IMAGE_SOURCE" ]; then |
| 53 | echo -e "-- source image --\t$(docker images --format $1 $ECS_IMAGE_SOURCE)" >> $2 |
| 54 | fi |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | # Scale kubernetes resources to zero |
| 58 | # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action. |
| 59 | # This function is called for apps fully managed by the test script |
| 60 | __ECS_kube_scale_zero() { |
| 61 | __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS |
| 62 | } |
| 63 | |
| 64 | # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action. |
| 65 | # This function is called for prestarted apps not managed by the test script. |
| 66 | __ECS_kube_scale_zero_and_wait() { |
| 67 | __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app nonrtric-enrichmentservice |
| 68 | } |
| 69 | |
| 70 | # Delete all kube resouces for the app |
| 71 | # This function is called for apps managed by the test script. |
| 72 | __ECS_kube_delete_all() { |
| 73 | __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS |
| 74 | } |
| 75 | |
| 76 | # Store docker logs |
| 77 | # This function is called for apps managed by the test script. |
| 78 | # args: <log-dir> <file-prexix> |
| 79 | __ECS_store_docker_logs() { |
| 80 | docker logs $ECS_APP_NAME > $1$2_ecs.log 2>&1 |
| 81 | } |
| 82 | ####################################################### |
| 83 | |
| 84 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 85 | ## Access to ECS |
| 86 | # Host name may be changed if app started by kube |
| 87 | # Direct access |
| 88 | ECS_HTTPX="http" |
| 89 | ECS_HOST_NAME=$LOCALHOST_NAME |
| 90 | ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT |
| 91 | |
| 92 | # ECS_ADAPTER used for switch between REST and DMAAP (only REST supported currently) |
| 93 | ECS_ADAPTER_TYPE="REST" |
| 94 | ECS_ADAPTER=$ECS_PATH |
| 95 | |
| 96 | # Make curl retries towards ECS for http response codes set in this env var, space separated list of codes |
| 97 | ECS_RETRY_CODES="" |
| 98 | |
| 99 | ########################### |
| 100 | ### ECS functions |
| 101 | ########################### |
| 102 | |
| 103 | # All calls to ECS will be directed to the ECS REST interface from now on |
| 104 | # args: - |
| 105 | # (Function for test scripts) |
| 106 | use_ecs_rest_http() { |
| 107 | echo -e $BOLD"ECS protocol setting"$EBOLD |
| 108 | echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS" |
| 109 | ECS_HTTPX="http" |
| 110 | ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT |
| 111 | |
| 112 | ECS_ADAPTER_TYPE="REST" |
| 113 | ECS_ADAPTER=$ECS_PATH |
| 114 | echo "" |
| 115 | } |
| 116 | |
| 117 | # All calls to ECS will be directed to the ECS REST interface from now on |
| 118 | # args: - |
| 119 | # (Function for test scripts) |
| 120 | use_ecs_rest_https() { |
| 121 | echo -e $BOLD"ECS protocol setting"$EBOLD |
| 122 | echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS" |
| 123 | ECS_HTTPX="https" |
| 124 | ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT |
| 125 | |
| 126 | ECS_ADAPTER_TYPE="REST" |
| 127 | ECS_ADAPTER=$ECS_PATH |
| 128 | echo "" |
| 129 | } |
| 130 | |
| 131 | # All calls to ECS will be directed to the ECS dmaap interface over http from now on |
| 132 | # args: - |
| 133 | # (Function for test scripts) |
| 134 | use_ecs_dmaap_http() { |
| 135 | echo -e $BOLD"ECS dmaap protocol setting"$EBOLD |
| 136 | echo -e $RED" - NOT SUPPORTED - "$ERED |
| 137 | echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS" |
| 138 | ECS_ADAPTER_TYPE="MR-HTTP" |
| 139 | echo "" |
| 140 | } |
| 141 | |
| 142 | # All calls to ECS will be directed to the ECS dmaap interface over https from now on |
| 143 | # args: - |
| 144 | # (Function for test scripts) |
| 145 | use_ecs_dmaap_https() { |
| 146 | echo -e $BOLD"RICSIM protocol setting"$EBOLD |
| 147 | echo -e $RED" - NOT SUPPORTED - "$ERED |
| 148 | echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS" |
| 149 | ECS_ADAPTER_TYPE="MR-HTTPS" |
| 150 | echo "" |
| 151 | } |
| 152 | |
| 153 | # Start the ECS |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 154 | # args: PROXY|NOPROXY <config-file> |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 155 | # (Function for test scripts) |
| 156 | start_ecs() { |
| 157 | |
| 158 | echo -e $BOLD"Starting $ECS_DISPLAY_NAME"$EBOLD |
| 159 | |
| 160 | if [ $RUNMODE == "KUBE" ]; then |
| 161 | |
| 162 | # Check if app shall be fully managed by the test script |
| 163 | __check_included_image "ECS" |
| 164 | retcode_i=$? |
| 165 | |
| 166 | # Check if app shall only be used by the testscipt |
| 167 | __check_prestarted_image "ECS" |
| 168 | retcode_p=$? |
| 169 | |
| 170 | if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then |
| 171 | echo -e $RED"The $ECS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED |
| 172 | echo -e $RED"The $ECS_APP_NAME will not be started"$ERED |
| 173 | exit |
| 174 | fi |
| 175 | if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then |
| 176 | echo -e $RED"The $ECS_APP_NAME app is included both as managed and prestarted in this test script"$ERED |
| 177 | echo -e $RED"The $ECS_APP_NAME will not be started"$ERED |
| 178 | exit |
| 179 | fi |
| 180 | |
| 181 | |
| 182 | if [ $retcode_p -eq 0 ]; then |
| 183 | echo -e " Using existing $ECS_APP_NAME deployment and service" |
| 184 | echo " Setting ECS replicas=1" |
| 185 | __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1 |
| 186 | fi |
| 187 | |
| 188 | # Check if app shall be fully managed by the test script |
| 189 | if [ $retcode_i -eq 0 ]; then |
| 190 | echo -e " Creating $ECS_APP_NAME app and expose service" |
| 191 | |
| 192 | #Check if nonrtric namespace exists, if not create it |
| 193 | __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE |
| 194 | |
| 195 | export ECS_APP_NAME |
| 196 | export KUBE_NONRTRIC_NAMESPACE |
| 197 | export ECS_IMAGE |
| 198 | export ECS_INTERNAL_PORT |
| 199 | export ECS_INTERNAL_SECURE_PORT |
| 200 | export ECS_EXTERNAL_PORT |
| 201 | export ECS_EXTERNAL_SECURE_PORT |
| 202 | export ECS_CONFIG_MOUNT_PATH |
| 203 | export ECS_CONFIG_CONFIGMAP_NAME=$ECS_APP_NAME"-config" |
| 204 | export ECS_DATA_CONFIGMAP_NAME=$ECS_APP_NAME"-data" |
| 205 | export ECS_CONTAINER_MNT_DIR |
| 206 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 207 | export ECS_DATA_PV_NAME=$ECS_APP_NAME"-pv" |
| 208 | #Create a unique path for the pv each time to prevent a previous volume to be reused |
| 209 | export ECS_PV_PATH="ecsdata-"$(date +%s) |
| 210 | |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 211 | if [ $1 == "PROXY" ]; then |
| 212 | ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started |
| 213 | ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started |
| 214 | if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then |
| 215 | echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW |
| 216 | else |
| 217 | echo " Configured with http proxy" |
| 218 | fi |
| 219 | else |
| 220 | ECS_HTTP_PROXY_CONFIG_PORT=0 |
| 221 | ECS_HTTP_PROXY_CONFIG_HOST_NAME="" |
| 222 | echo " Configured without http proxy" |
| 223 | fi |
| 224 | export ECS_HTTP_PROXY_CONFIG_PORT |
| 225 | export ECS_HTTP_PROXY_CONFIG_HOST_NAME |
| 226 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 227 | # Create config map for config |
| 228 | datafile=$PWD/tmp/$ECS_CONFIG_FILE |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 229 | cp $2 $datafile |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 230 | output_yaml=$PWD/tmp/ecs_cfc.yaml |
| 231 | __kube_create_configmap $ECS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ECS $datafile $output_yaml |
| 232 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 233 | # Create pv |
| 234 | input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pv.yaml |
| 235 | output_yaml=$PWD/tmp/ecs_pv.yaml |
| 236 | __kube_create_instance pv $ECS_APP_NAME $input_yaml $output_yaml |
| 237 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 238 | # Create pvc |
| 239 | input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pvc.yaml |
| 240 | output_yaml=$PWD/tmp/ecs_pvc.yaml |
| 241 | __kube_create_instance pvc $ECS_APP_NAME $input_yaml $output_yaml |
| 242 | |
| 243 | # Create service |
| 244 | input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"svc.yaml |
| 245 | output_yaml=$PWD/tmp/ecs_svc.yaml |
| 246 | __kube_create_instance service $ECS_APP_NAME $input_yaml $output_yaml |
| 247 | |
| 248 | # Create app |
| 249 | input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"app.yaml |
| 250 | output_yaml=$PWD/tmp/ecs_app.yaml |
| 251 | __kube_create_instance app $ECS_APP_NAME $input_yaml $output_yaml |
| 252 | fi |
| 253 | |
| 254 | echo " Retrieving host and ports for service..." |
| 255 | ECS_HOST_NAME=$(__kube_get_service_host $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE) |
| 256 | ECS_EXTERNAL_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http") |
| 257 | ECS_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https") |
| 258 | |
| 259 | echo " Host IP, http port, https port: $ECS_HOST_NAME $ECS_EXTERNAL_PORT $ECS_EXTERNAL_SECURE_PORT" |
| 260 | |
| 261 | if [ $ECS_HTTPX == "http" ]; then |
| 262 | ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT |
| 263 | else |
| 264 | ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT |
| 265 | fi |
| 266 | |
| 267 | __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL |
| 268 | |
| 269 | if [ $ECS_ADAPTER_TYPE == "REST" ]; then |
| 270 | ECS_ADAPTER=$ECS_PATH |
| 271 | fi |
| 272 | else |
| 273 | __check_included_image 'ECS' |
| 274 | if [ $? -eq 1 ]; then |
| 275 | echo -e $RED"The ECS app is not included in this test script"$ERED |
| 276 | echo -e $RED"ECS will not be started"$ERED |
| 277 | exit 1 |
| 278 | fi |
| 279 | |
| 280 | curdir=$PWD |
| 281 | cd $SIM_GROUP |
| 282 | cd ecs |
| 283 | cd $ECS_HOST_MNT_DIR |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 284 | #cd .. |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 285 | if [ -d db ]; then |
| 286 | if [ "$(ls -A $DIR)" ]; then |
| 287 | echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD |
| 288 | rm -rf db/* &> /dev/null |
| 289 | if [ $? -ne 0 ]; then |
| 290 | echo -e $RED" Cannot remove database files in: $PWD"$ERED |
| 291 | exit 1 |
| 292 | fi |
| 293 | fi |
| 294 | else |
| 295 | echo " No files in mounted dir or dir does not exists" |
| 296 | fi |
| 297 | cd $curdir |
| 298 | |
| 299 | export ECS_APP_NAME |
| 300 | export ECS_APP_NAME_ALIAS |
| 301 | export ECS_HOST_MNT_DIR |
| 302 | export ECS_CONTAINER_MNT_DIR |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 303 | export ECS_CONFIG_MOUNT_PATH |
| 304 | export ECS_CONFIG_FILE |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 305 | export ECS_INTERNAL_PORT |
| 306 | export ECS_EXTERNAL_PORT |
| 307 | export ECS_INTERNAL_SECURE_PORT |
| 308 | export ECS_EXTERNAL_SECURE_PORT |
| 309 | export DOCKER_SIM_NWNAME |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 310 | export ECS_DISPLAY_NAME |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 311 | |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 312 | if [ $1 == "PROXY" ]; then |
| 313 | ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started |
| 314 | ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started |
| 315 | if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then |
| 316 | echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW |
| 317 | else |
| 318 | echo " Configured with http proxy" |
| 319 | fi |
| 320 | else |
| 321 | ECS_HTTP_PROXY_CONFIG_PORT=0 |
| 322 | ECS_HTTP_PROXY_CONFIG_HOST_NAME="" |
| 323 | echo " Configured without http proxy" |
| 324 | fi |
| 325 | export ECS_HTTP_PROXY_CONFIG_PORT |
| 326 | export ECS_HTTP_PROXY_CONFIG_HOST_NAME |
| 327 | |
| 328 | dest_file=$SIM_GROUP/$ECS_COMPOSE_DIR/$ECS_HOST_MNT_DIR/$ECS_CONFIG_FILE |
| 329 | |
| 330 | envsubst < $2 > $dest_file |
| 331 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 332 | __start_container $ECS_COMPOSE_DIR "" NODOCKERARGS 1 $ECS_APP_NAME |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 333 | |
| 334 | __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL |
| 335 | fi |
| 336 | echo "" |
| 337 | return 0 |
| 338 | } |
| 339 | |
| 340 | # Restart ECS |
| 341 | # args: - |
| 342 | # (Function for test scripts) |
| 343 | restart_ecs() { |
| 344 | echo -e $BOLD"Re-starting ECS"$EBOLD |
| 345 | docker restart $ECS_APP_NAME &> ./tmp/.dockererr |
| 346 | if [ $? -ne 0 ]; then |
| 347 | __print_err "Could not restart $ECS_APP_NAME" $@ |
| 348 | cat ./tmp/.dockererr |
| 349 | ((RES_CONF_FAIL++)) |
| 350 | return 1 |
| 351 | fi |
| 352 | |
| 353 | __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL |
| 354 | echo "" |
| 355 | return 0 |
| 356 | } |
| 357 | |
| 358 | # Turn on debug level tracing in ECS |
| 359 | # args: - |
| 360 | # (Function for test scripts) |
| 361 | set_ecs_debug() { |
| 362 | echo -e $BOLD"Setting ecs debug logging"$EBOLD |
| 363 | curlString="$ECS_PATH$ECS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}" |
| 364 | result=$(__do_curl "$curlString") |
| 365 | if [ $? -ne 0 ]; then |
| 366 | __print_err "Could not set debug mode" $@ |
| 367 | ((RES_CONF_FAIL++)) |
| 368 | return 1 |
| 369 | fi |
| 370 | echo "" |
| 371 | return 0 |
| 372 | } |
| 373 | |
| 374 | # Turn on trace level tracing in ECS |
| 375 | # args: - |
| 376 | # (Function for test scripts) |
| 377 | set_ecs_trace() { |
| 378 | echo -e $BOLD"Setting ecs trace logging"$EBOLD |
| 379 | curlString="$ECS_PATH/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}" |
| 380 | result=$(__do_curl "$curlString") |
| 381 | if [ $? -ne 0 ]; then |
| 382 | __print_err "Could not set trace mode" $@ |
| 383 | ((RES_CONF_FAIL++)) |
| 384 | return 1 |
| 385 | fi |
| 386 | echo "" |
| 387 | return 0 |
| 388 | } |
| 389 | |
| 390 | # Perform curl retries when making direct call to ECS for the specified http response codes |
| 391 | # Speace separated list of http response codes |
| 392 | # args: [<response-code>]* |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 393 | use_ecs_retries() { |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 394 | echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 395 | ECS_RETRY_CODES=$@ |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 396 | echo "" |
| 397 | return 0 |
| 398 | } |
| 399 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 400 | # Check the ecs logs for WARNINGs and ERRORs |
| 401 | # args: - |
| 402 | # (Function for test scripts) |
| 403 | check_ecs_logs() { |
| 404 | __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR |
| 405 | } |
| 406 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 407 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 408 | # Tests if a variable value in the ECS is equal to a target value and and optional timeout. |
| 409 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is |
| 410 | # equal to the target or not. |
| 411 | # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 412 | # before setting pass or fail depending on if the variable value becomes equal to the target |
| 413 | # value or not. |
| 414 | # (Function for test scripts) |
| 415 | ecs_equal() { |
| 416 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 417 | __var_test ECS "$ECS_PATH/" $1 "=" $2 $3 |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 418 | else |
| 419 | __print_err "Wrong args to ecs_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@ |
| 420 | fi |
| 421 | } |
| 422 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 423 | |
| 424 | ########################################## |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 425 | ######### A1-E Enrichment API ########## |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 426 | ########################################## |
| 427 | #Function prefix: ecs_api_a1 |
| 428 | |
| 429 | # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 430 | # args: <response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ] |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 431 | # args (flat uri structure): <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 432 | # (Function for test scripts) |
| 433 | ecs_api_a1_get_job_ids() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 434 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 435 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 436 | if [ -z "$FLAT_A1_EI" ]; then |
| 437 | # Valid number of parameters 4,5,6 etc |
| 438 | if [ $# -lt 3 ]; then |
| 439 | __print_err "<response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@ |
| 440 | return 1 |
| 441 | fi |
| 442 | else |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 443 | echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 444 | # Valid number of parameters 4,5,6 etc |
| 445 | if [ $# -lt 3 ]; then |
| 446 | __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@ |
| 447 | return 1 |
| 448 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 449 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 450 | search="" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 451 | if [ $3 != "NOWNER" ]; then |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 452 | search="?owner="$3 |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 453 | fi |
| 454 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 455 | if [ -z "$FLAT_A1_EI" ]; then |
| 456 | query="/A1-EI/v1/eitypes/$2/eijobs$search" |
| 457 | else |
| 458 | if [ $2 != "NOTYPE" ]; then |
| 459 | if [ -z "$search" ]; then |
| 460 | search="?eiTypeId="$2 |
| 461 | else |
| 462 | search=$search"&eiTypeId="$2 |
| 463 | fi |
| 464 | fi |
| 465 | query="/A1-EI/v1/eijobs$search" |
| 466 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 467 | res="$(__do_curl_to_api ECS GET $query)" |
| 468 | status=${res:${#res}-3} |
| 469 | |
| 470 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 471 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 472 | return 1 |
| 473 | fi |
| 474 | |
| 475 | if [ $# -gt 3 ]; then |
| 476 | body=${res:0:${#res}-3} |
| 477 | targetJson="[" |
| 478 | |
| 479 | for pid in ${@:4} ; do |
| 480 | if [ "$targetJson" != "[" ]; then |
| 481 | targetJson=$targetJson"," |
| 482 | fi |
| 483 | if [ $pid != "EMPTY" ]; then |
| 484 | targetJson=$targetJson"\"$pid\"" |
| 485 | fi |
| 486 | done |
| 487 | |
| 488 | targetJson=$targetJson"]" |
| 489 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 490 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 491 | |
| 492 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 493 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 494 | return 1 |
| 495 | fi |
| 496 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 497 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 498 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 499 | return 0 |
| 500 | } |
| 501 | |
| 502 | # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 503 | # args: <response-code> <type-id> [<schema-file>] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 504 | # (Function for test scripts) |
| 505 | ecs_api_a1_get_type() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 506 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 507 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 508 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 509 | __print_err "<response-code> <type-id> [<schema-file>]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 510 | return 1 |
| 511 | fi |
| 512 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 513 | query="/A1-EI/v1/eitypes/$2" |
| 514 | res="$(__do_curl_to_api ECS GET $query)" |
| 515 | status=${res:${#res}-3} |
| 516 | |
| 517 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 518 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 519 | return 1 |
| 520 | fi |
| 521 | |
| 522 | if [ $# -eq 3 ]; then |
| 523 | body=${res:0:${#res}-3} |
| 524 | if [ -f $3 ]; then |
| 525 | schema=$(cat $3) |
| 526 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 527 | __log_test_fail_general "Schema file "$3", does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 528 | return 1 |
| 529 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 530 | if [ -z "$FLAT_A1_EI" ]; then |
| 531 | targetJson="{\"eiJobParametersSchema\":$schema}" |
| 532 | else |
| 533 | targetJson=$schema |
| 534 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 535 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 536 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 537 | |
| 538 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 539 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 540 | return 1 |
| 541 | fi |
| 542 | fi |
| 543 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 544 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 545 | return 0 |
| 546 | } |
| 547 | |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 548 | # API Test function: GET /A1-EI/v1/eitypes |
| 549 | # args: <response-code> [ (EMPTY | [<type-id>]+) ] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 550 | # (Function for test scripts) |
| 551 | ecs_api_a1_get_type_ids() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 552 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 553 | |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 554 | if [ $# -lt 1 ]; then |
| 555 | __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@ |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 556 | return 1 |
| 557 | fi |
| 558 | |
| 559 | query="/A1-EI/v1/eitypes" |
| 560 | res="$(__do_curl_to_api ECS GET $query)" |
| 561 | status=${res:${#res}-3} |
| 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 | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 565 | return 1 |
| 566 | fi |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 567 | if [ $# -gt 1 ]; then |
| 568 | body=${res:0:${#res}-3} |
| 569 | targetJson="[" |
| 570 | if [ $2 != "EMPTY" ]; then |
| 571 | for pid in ${@:2} ; do |
| 572 | if [ "$targetJson" != "[" ]; then |
| 573 | targetJson=$targetJson"," |
| 574 | fi |
| 575 | targetJson=$targetJson"\"$pid\"" |
| 576 | done |
| 577 | fi |
| 578 | targetJson=$targetJson"]" |
| 579 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 580 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 581 | |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 582 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 583 | __log_test_fail_body |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 584 | return 1 |
| 585 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 586 | fi |
| 587 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 588 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 589 | return 0 |
| 590 | } |
| 591 | |
| 592 | # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}/status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 593 | # args: <response-code> <type-id> <job-id> [<status>] |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 594 | # args (flat uri structure): <response-code> <job-id> [<status> [<timeout>]] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 595 | # (Function for test scripts) |
| 596 | ecs_api_a1_get_job_status() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 597 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 598 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 599 | if [ -z "$FLAT_A1_EI" ]; then |
| 600 | if [ $# -ne 3 ] && [ $# -ne 4 ]; then |
| 601 | __print_err "<response-code> <type-id> <job-id> [<status>]" $@ |
| 602 | return 1 |
| 603 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 604 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 605 | query="/A1-EI/v1/eitypes/$2/eijobs/$3/status" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 606 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 607 | res="$(__do_curl_to_api ECS GET $query)" |
| 608 | status=${res:${#res}-3} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 609 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 610 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 611 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 612 | return 1 |
| 613 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 614 | if [ $# -eq 4 ]; then |
| 615 | body=${res:0:${#res}-3} |
| 616 | targetJson="{\"operationalState\": \"$4\"}" |
| 617 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 618 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 619 | |
| 620 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 621 | __log_test_fail_body |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 622 | return 1 |
| 623 | fi |
| 624 | fi |
| 625 | else |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 626 | echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 627 | if [ $# -lt 2 ] && [ $# -gt 4 ]; then |
| 628 | __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@ |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 629 | return 1 |
| 630 | fi |
| 631 | |
| 632 | query="/A1-EI/v1/eijobs/$2/status" |
| 633 | |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 634 | start=$SECONDS |
| 635 | for (( ; ; )); do |
| 636 | res="$(__do_curl_to_api ECS GET $query)" |
| 637 | status=${res:${#res}-3} |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 638 | |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 639 | if [ $# -eq 4 ]; then |
| 640 | duration=$((SECONDS-start)) |
| 641 | echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}" |
| 642 | if [ $duration -gt $4 ]; then |
| 643 | echo "" |
| 644 | duration=-1 #Last iteration |
| 645 | fi |
| 646 | else |
| 647 | duration=-1 #single test, no wait |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 648 | fi |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 649 | |
| 650 | if [ $status -ne $1 ]; then |
| 651 | if [ $duration -eq -1 ]; then |
| 652 | __log_test_fail_status_code $1 $status |
| 653 | return 1 |
| 654 | fi |
| 655 | fi |
| 656 | if [ $# -ge 3 ] && [ $status -eq $1 ]; then |
| 657 | body=${res:0:${#res}-3} |
| 658 | targetJson="{\"eiJobStatus\": \"$3\"}" |
| 659 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 660 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 661 | |
| 662 | if [ $res -ne 0 ]; then |
| 663 | if [ $duration -eq -1 ]; then |
| 664 | __log_test_fail_body |
| 665 | return 1 |
| 666 | fi |
| 667 | else |
| 668 | duration=-1 #Goto pass |
| 669 | fi |
| 670 | fi |
| 671 | if [ $duration -eq -1 ]; then |
| 672 | if [ $# -eq 4 ]; then |
| 673 | echo "" |
| 674 | fi |
| 675 | __log_test_pass |
| 676 | return 0 |
| 677 | else |
| 678 | sleep 1 |
| 679 | fi |
| 680 | done |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 681 | fi |
| 682 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 683 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 684 | return 0 |
| 685 | } |
| 686 | |
| 687 | # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 688 | # args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>] |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 689 | # args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 690 | # (Function for test scripts) |
| 691 | ecs_api_a1_get_job() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 692 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 693 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 694 | if [ -z "$FLAT_A1_EI" ]; then |
| 695 | if [ $# -ne 3 ] && [ $# -ne 6 ]; then |
| 696 | __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@ |
| 697 | return 1 |
| 698 | fi |
| 699 | query="/A1-EI/v1/eitypes/$2/eijobs/$3" |
| 700 | else |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 701 | echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 702 | if [ $# -ne 2 ] && [ $# -ne 7 ]; then |
| 703 | __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@ |
| 704 | return 1 |
| 705 | fi |
| 706 | query="/A1-EI/v1/eijobs/$2" |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 707 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 708 | res="$(__do_curl_to_api ECS GET $query)" |
| 709 | status=${res:${#res}-3} |
| 710 | |
| 711 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 712 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 713 | return 1 |
| 714 | fi |
| 715 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 716 | if [ -z "$FLAT_A1_EI" ]; then |
| 717 | if [ $# -eq 6 ]; then |
| 718 | body=${res:0:${#res}-3} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 719 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 720 | if [ -f $6 ]; then |
| 721 | jobfile=$(cat $6) |
| 722 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") |
| 723 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 724 | _log_test_fail_general "Job template file "$6", does not exist" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 725 | return 1 |
| 726 | fi |
| 727 | targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}" |
| 728 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 729 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 730 | |
| 731 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 732 | __log_test_fail_body |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 733 | return 1 |
| 734 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 735 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 736 | else |
| 737 | if [ $# -eq 7 ]; then |
| 738 | body=${res:0:${#res}-3} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 739 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 740 | if [ -f $7 ]; then |
| 741 | jobfile=$(cat $7) |
| 742 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g") |
| 743 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 744 | _log_test_fail_general "Job template file "$6", does not exist" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 745 | return 1 |
| 746 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 747 | targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 748 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 749 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 750 | |
| 751 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 752 | __log_test_fail_body |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 753 | return 1 |
| 754 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 755 | fi |
| 756 | fi |
| 757 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 758 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 759 | return 0 |
| 760 | } |
| 761 | |
| 762 | # API Test function: DELETE /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 763 | # args: <response-code> <type-id> <job-id> |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 764 | # args (flat uri structure): <response-code> <job-id> |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 765 | # (Function for test scripts) |
| 766 | ecs_api_a1_delete_job() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 767 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 768 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 769 | if [ -z "$FLAT_A1_EI" ]; then |
| 770 | if [ $# -ne 3 ]; then |
| 771 | __print_err "<response-code> <type-id> <job-id>" $@ |
| 772 | return 1 |
| 773 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 774 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 775 | query="/A1-EI/v1/eitypes/$2/eijobs/$3" |
| 776 | else |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 777 | echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 778 | if [ $# -ne 2 ]; then |
| 779 | __print_err "<response-code> <job-id>" $@ |
| 780 | return 1 |
| 781 | fi |
| 782 | query="/A1-EI/v1/eijobs/$2" |
| 783 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 784 | res="$(__do_curl_to_api ECS DELETE $query)" |
| 785 | status=${res:${#res}-3} |
| 786 | |
| 787 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 788 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 789 | return 1 |
| 790 | fi |
| 791 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 792 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 793 | return 0 |
| 794 | } |
| 795 | |
| 796 | # API Test function: PUT /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 797 | # args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file> |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 798 | # args (flat uri structure): <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 799 | # (Function for test scripts) |
| 800 | ecs_api_a1_put_job() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 801 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 802 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 803 | if [ -z "$FLAT_A1_EI" ]; then |
| 804 | if [ $# -lt 6 ]; then |
| 805 | __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@ |
| 806 | return 1 |
| 807 | fi |
| 808 | if [ -f $6 ]; then |
| 809 | jobfile=$(cat $6) |
| 810 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") |
| 811 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 812 | _log_test_fail_general "Job template file "$6", does not exist" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 813 | return 1 |
| 814 | fi |
| 815 | |
| 816 | inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}" |
| 817 | file="./tmp/.p.json" |
| 818 | echo "$inputJson" > $file |
| 819 | |
| 820 | query="/A1-EI/v1/eitypes/$2/eijobs/$3" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 821 | else |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 822 | echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 823 | if [ $# -lt 7 ]; then |
| 824 | __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@ |
| 825 | return 1 |
| 826 | fi |
| 827 | if [ -f $7 ]; then |
| 828 | jobfile=$(cat $7) |
| 829 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g") |
| 830 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 831 | _log_test_fail_general "Job template file "$7", does not exist" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 832 | return 1 |
| 833 | fi |
| 834 | |
| 835 | inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}" |
| 836 | file="./tmp/.p.json" |
| 837 | echo "$inputJson" > $file |
| 838 | |
| 839 | query="/A1-EI/v1/eijobs/$2" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 840 | fi |
| 841 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 842 | res="$(__do_curl_to_api ECS PUT $query $file)" |
| 843 | status=${res:${#res}-3} |
| 844 | |
| 845 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 846 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 847 | return 1 |
| 848 | fi |
| 849 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 850 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 851 | return 0 |
| 852 | } |
| 853 | |
| 854 | |
| 855 | ########################################## |
| 856 | #### Enrichment Data Producer API #### |
| 857 | ########################################## |
| 858 | # Function prefix: ecs_api_edp |
| 859 | |
| 860 | # API Test function: GET /ei-producer/v1/eitypes |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 861 | # args: <response-code> [ EMPTY | <type-id>+] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 862 | # (Function for test scripts) |
| 863 | ecs_api_edp_get_type_ids() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 864 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 865 | |
| 866 | if [ $# -lt 1 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 867 | __print_err "<response-code> [ EMPTY | <type-id>+]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 868 | return 1 |
| 869 | fi |
| 870 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 871 | query="/ei-producer/v1/eitypes" |
| 872 | res="$(__do_curl_to_api ECS GET $query)" |
| 873 | status=${res:${#res}-3} |
| 874 | |
| 875 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 876 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 877 | return 1 |
| 878 | fi |
| 879 | |
| 880 | if [ $# -gt 1 ]; then |
| 881 | body=${res:0:${#res}-3} |
| 882 | targetJson="[" |
| 883 | if [ $2 != "EMPTY" ]; then |
| 884 | for pid in ${@:2} ; do |
| 885 | if [ "$targetJson" != "[" ]; then |
| 886 | targetJson=$targetJson"," |
| 887 | fi |
| 888 | targetJson=$targetJson"\"$pid\"" |
| 889 | done |
| 890 | fi |
| 891 | targetJson=$targetJson"]" |
| 892 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 893 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 894 | |
| 895 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 896 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 897 | return 1 |
| 898 | fi |
| 899 | fi |
| 900 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 901 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 902 | return 0 |
| 903 | } |
| 904 | |
| 905 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 906 | # args: <response-code> <producer-id> [<status> [<timeout>]] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 907 | # (Function for test scripts) |
| 908 | ecs_api_edp_get_producer_status() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 909 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 910 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 911 | if [ $# -lt 2 ] || [ $# -gt 4 ]; then |
| 912 | __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 913 | return 1 |
| 914 | fi |
| 915 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 916 | query="/ei-producer/v1/eiproducers/$2/status" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 917 | start=$SECONDS |
| 918 | for (( ; ; )); do |
| 919 | res="$(__do_curl_to_api ECS GET $query)" |
| 920 | status=${res:${#res}-3} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 921 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 922 | if [ $# -eq 4 ]; then |
| 923 | duration=$((SECONDS-start)) |
| 924 | echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}" |
| 925 | if [ $duration -gt $4 ]; then |
| 926 | echo "" |
| 927 | duration=-1 #Last iteration |
| 928 | fi |
| 929 | else |
| 930 | duration=-1 #single test, no wait |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 931 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 932 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 933 | if [ $status -ne $1 ]; then |
| 934 | if [ $duration -eq -1 ]; then |
| 935 | __log_test_fail_status_code $1 $status |
| 936 | return 1 |
| 937 | fi |
| 938 | fi |
| 939 | if [ $# -ge 3 ] && [ $status -eq $1 ]; then |
| 940 | body=${res:0:${#res}-3} |
| 941 | targetJson="{\"operational_state\": \"$3\"}" |
| 942 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 943 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 944 | |
| 945 | if [ $res -ne 0 ]; then |
| 946 | if [ $duration -eq -1 ]; then |
| 947 | __log_test_fail_body |
| 948 | return 1 |
| 949 | fi |
| 950 | else |
| 951 | duration=-1 #Goto pass |
| 952 | fi |
| 953 | fi |
| 954 | if [ $duration -eq -1 ]; then |
| 955 | if [ $# -eq 4 ]; then |
| 956 | echo "" |
| 957 | fi |
| 958 | __log_test_pass |
| 959 | return 0 |
| 960 | else |
| 961 | sleep 1 |
| 962 | fi |
| 963 | done |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | |
| 967 | # API Test function: GET /ei-producer/v1/eiproducers |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 968 | # args (v1_1): <response-code> [ EMPTY | <producer-id>+] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 969 | # (Function for test scripts) |
| 970 | ecs_api_edp_get_producer_ids() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 971 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 972 | |
| 973 | if [ $# -lt 1 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 974 | __print_err "<response-code> [ EMPTY | <producer-id>+]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 975 | return 1 |
| 976 | fi |
| 977 | |
| 978 | query="/ei-producer/v1/eiproducers" |
| 979 | res="$(__do_curl_to_api ECS GET $query)" |
| 980 | status=${res:${#res}-3} |
| 981 | |
| 982 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 983 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 984 | return 1 |
| 985 | fi |
| 986 | |
| 987 | if [ $# -gt 1 ]; then |
| 988 | body=${res:0:${#res}-3} |
| 989 | targetJson="[" |
| 990 | |
| 991 | for pid in ${@:2} ; do |
| 992 | if [ "$targetJson" != "[" ]; then |
| 993 | targetJson=$targetJson"," |
| 994 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 995 | if [ $pid != "EMPTY" ]; then |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 996 | targetJson=$targetJson"\"$pid\"" |
| 997 | fi |
| 998 | done |
| 999 | |
| 1000 | targetJson=$targetJson"]" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1001 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1002 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1003 | |
| 1004 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1005 | __log_test_fail_body |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1006 | return 1 |
| 1007 | fi |
| 1008 | fi |
| 1009 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1010 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1011 | return 0 |
| 1012 | } |
| 1013 | |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1014 | # API Test function: GET /ei-producer/v1/eiproducers |
| 1015 | # args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ] |
| 1016 | # (Function for test scripts) |
| 1017 | ecs_api_edp_get_producer_ids_2() { |
| 1018 | __log_test_start $@ |
| 1019 | |
| 1020 | if [ $# -lt 1 ]; then |
| 1021 | __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@ |
| 1022 | return 1 |
| 1023 | fi |
| 1024 | |
| 1025 | query="/ei-producer/v1/eiproducers" |
| 1026 | if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then |
| 1027 | query=$query"?ei_type_id=$2" |
| 1028 | fi |
| 1029 | res="$(__do_curl_to_api ECS GET $query)" |
| 1030 | status=${res:${#res}-3} |
| 1031 | |
| 1032 | if [ $status -ne $1 ]; then |
| 1033 | __log_test_fail_status_code $1 $status |
| 1034 | return 1 |
| 1035 | fi |
| 1036 | |
| 1037 | if [ $# -gt 2 ]; then |
| 1038 | body=${res:0:${#res}-3} |
| 1039 | targetJson="[" |
| 1040 | |
| 1041 | for pid in ${@:3} ; do |
| 1042 | if [ "$targetJson" != "[" ]; then |
| 1043 | targetJson=$targetJson"," |
| 1044 | fi |
| 1045 | if [ $pid != "EMPTY" ]; then |
| 1046 | targetJson=$targetJson"\"$pid\"" |
| 1047 | fi |
| 1048 | done |
| 1049 | |
| 1050 | targetJson=$targetJson"]" |
| 1051 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1052 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1053 | |
| 1054 | if [ $res -ne 0 ]; then |
| 1055 | __log_test_fail_body |
| 1056 | return 1 |
| 1057 | fi |
| 1058 | fi |
| 1059 | |
| 1060 | __log_test_pass |
| 1061 | return 0 |
| 1062 | } |
| 1063 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1064 | # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId} |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1065 | # args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1066 | # (Function for test scripts) |
| 1067 | ecs_api_edp_get_type() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1068 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1069 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1070 | paramError=1 |
| 1071 | if [ $# -eq 2 ]; then |
| 1072 | paramError=0 |
| 1073 | fi |
| 1074 | if [ $# -gt 3 ]; then |
| 1075 | paramError=0 |
| 1076 | fi |
| 1077 | if [ $paramError -ne 0 ]; then |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 1078 | __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1079 | return 1 |
| 1080 | fi |
| 1081 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1082 | query="/ei-producer/v1/eitypes/$2" |
| 1083 | res="$(__do_curl_to_api ECS GET $query)" |
| 1084 | status=${res:${#res}-3} |
| 1085 | |
| 1086 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1087 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1088 | return 1 |
| 1089 | fi |
| 1090 | if [ $# -gt 3 ]; then |
| 1091 | body=${res:0:${#res}-3} |
| 1092 | |
| 1093 | if [ -f $3 ]; then |
| 1094 | schema=$(cat $3) |
| 1095 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1096 | __log_test_fail_general "Job template file "$3", does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1097 | return 1 |
| 1098 | fi |
| 1099 | |
| 1100 | targetJson="" |
| 1101 | if [ $4 != "EMPTY" ]; then |
| 1102 | for pid in ${@:4} ; do |
| 1103 | if [ "$targetJson" != "" ]; then |
| 1104 | targetJson=$targetJson"," |
| 1105 | fi |
| 1106 | targetJson=$targetJson"\"$pid\"" |
| 1107 | done |
| 1108 | fi |
| 1109 | targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}" |
| 1110 | |
| 1111 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1112 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1113 | |
| 1114 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1115 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1116 | return 1 |
| 1117 | fi |
| 1118 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1119 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1120 | return 0 |
| 1121 | } |
| 1122 | |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1123 | # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId} |
| 1124 | # args: (v1_2) <response-code> <type-id> [<job-schema-file> ] |
| 1125 | # (Function for test scripts) |
| 1126 | ecs_api_edp_get_type_2() { |
| 1127 | __log_test_start $@ |
| 1128 | |
| 1129 | paramError=1 |
| 1130 | if [ $# -eq 2 ]; then |
| 1131 | paramError=0 |
| 1132 | fi |
| 1133 | if [ $# -eq 3 ]; then |
| 1134 | paramError=0 |
| 1135 | fi |
| 1136 | if [ $paramError -ne 0 ]; then |
| 1137 | __print_err "<response-code> <type-id> [<job-schema-file> ]" $@ |
| 1138 | return 1 |
| 1139 | fi |
| 1140 | |
| 1141 | query="/ei-producer/v1/eitypes/$2" |
| 1142 | res="$(__do_curl_to_api ECS GET $query)" |
| 1143 | status=${res:${#res}-3} |
| 1144 | |
| 1145 | if [ $status -ne $1 ]; then |
| 1146 | __log_test_fail_status_code $1 $status |
| 1147 | return 1 |
| 1148 | fi |
| 1149 | if [ $# -eq 3 ]; then |
| 1150 | body=${res:0:${#res}-3} |
| 1151 | |
| 1152 | if [ -f $3 ]; then |
| 1153 | schema=$(cat $3) |
| 1154 | else |
| 1155 | __log_test_fail_general "Job template file "$3", does not exist" |
| 1156 | return 1 |
| 1157 | fi |
| 1158 | |
| 1159 | targetJson="{\"ei_job_data_schema\":$schema}" |
| 1160 | |
| 1161 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1162 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1163 | |
| 1164 | if [ $res -ne 0 ]; then |
| 1165 | __log_test_fail_body |
| 1166 | return 1 |
| 1167 | fi |
| 1168 | fi |
| 1169 | __log_test_pass |
| 1170 | return 0 |
| 1171 | } |
| 1172 | |
| 1173 | # API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId} |
| 1174 | # args: (v1_2) <response-code> <type-id> <job-schema-file> |
| 1175 | # (Function for test scripts) |
| 1176 | ecs_api_edp_put_type_2() { |
| 1177 | __log_test_start $@ |
| 1178 | |
| 1179 | if [ $# -ne 3 ]; then |
| 1180 | __print_err "<response-code> <type-id> <job-schema-file>" $@ |
| 1181 | return 1 |
| 1182 | fi |
| 1183 | |
| 1184 | if [ ! -f $3 ]; then |
| 1185 | __log_test_fail_general "Job schema file "$3", does not exist" |
| 1186 | return 1 |
| 1187 | fi |
| 1188 | schema=$(cat $3) |
| 1189 | input_json="{\"ei_job_data_schema\":$schema}" |
| 1190 | file="./tmp/put_type.json" |
| 1191 | echo $input_json > $file |
| 1192 | |
| 1193 | query="/ei-producer/v1/eitypes/$2" |
| 1194 | res="$(__do_curl_to_api ECS PUT $query $file)" |
| 1195 | status=${res:${#res}-3} |
| 1196 | |
| 1197 | if [ $status -ne $1 ]; then |
| 1198 | __log_test_fail_status_code $1 $status |
| 1199 | return 1 |
| 1200 | fi |
| 1201 | |
| 1202 | __log_test_pass |
| 1203 | return 0 |
| 1204 | } |
| 1205 | |
| 1206 | # API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId} |
| 1207 | # args: (v1_2) <response-code> <type-id> |
| 1208 | # (Function for test scripts) |
| 1209 | ecs_api_edp_delete_type_2() { |
| 1210 | __log_test_start $@ |
| 1211 | |
| 1212 | if [ $# -ne 2 ]; then |
| 1213 | __print_err "<response-code> <type-id>" $@ |
| 1214 | return 1 |
| 1215 | fi |
| 1216 | |
| 1217 | query="/ei-producer/v1/eitypes/$2" |
| 1218 | res="$(__do_curl_to_api ECS DELETE $query)" |
| 1219 | status=${res:${#res}-3} |
| 1220 | |
| 1221 | if [ $status -ne $1 ]; then |
| 1222 | __log_test_fail_status_code $1 $status |
| 1223 | return 1 |
| 1224 | fi |
| 1225 | |
| 1226 | __log_test_pass |
| 1227 | return 0 |
| 1228 | } |
| 1229 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1230 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId} |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1231 | # args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1232 | # (Function for test scripts) |
| 1233 | ecs_api_edp_get_producer() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1234 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1235 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1236 | #Possible arg count: 2, 5 6, 8, 10 etc |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1237 | paramError=1 |
| 1238 | if [ $# -eq 2 ]; then |
| 1239 | paramError=0 |
| 1240 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1241 | if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1242 | paramError=0 |
| 1243 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1244 | variablecount=$(($#-4)) |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1245 | if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then |
| 1246 | paramError=0 |
| 1247 | fi |
| 1248 | |
| 1249 | if [ $paramError -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1250 | __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1251 | return 1 |
| 1252 | fi |
| 1253 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1254 | query="/ei-producer/v1/eiproducers/$2" |
| 1255 | res="$(__do_curl_to_api ECS GET $query)" |
| 1256 | status=${res:${#res}-3} |
| 1257 | |
| 1258 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1259 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1260 | return 1 |
| 1261 | fi |
| 1262 | |
| 1263 | if [ $# -gt 2 ]; then |
| 1264 | body=${res:0:${#res}-3} |
| 1265 | targetJson="[" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1266 | if [ $# -gt 5 ]; then |
| 1267 | arr=(${@:5}) |
| 1268 | for ((i=0; i<$(($#-5)); i=i+2)); do |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1269 | if [ "$targetJson" != "[" ]; then |
| 1270 | targetJson=$targetJson"," |
| 1271 | fi |
| 1272 | if [ -f ${arr[$i+1]} ]; then |
| 1273 | schema=$(cat ${arr[$i+1]}) |
| 1274 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1275 | _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1276 | return 1 |
| 1277 | fi |
| 1278 | |
| 1279 | targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}" |
| 1280 | done |
| 1281 | fi |
| 1282 | targetJson=$targetJson"]" |
| 1283 | if [ $# -gt 4 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1284 | targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1285 | fi |
| 1286 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1287 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1288 | |
| 1289 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1290 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1291 | return 1 |
| 1292 | fi |
| 1293 | fi |
| 1294 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1295 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1296 | return 0 |
| 1297 | } |
| 1298 | |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1299 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId} |
| 1300 | # args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ] |
| 1301 | # (Function for test scripts) |
| 1302 | ecs_api_edp_get_producer_2() { |
| 1303 | __log_test_start $@ |
| 1304 | |
| 1305 | #Possible arg count: 2, 5, 6, 7, 8 etc |
| 1306 | paramError=1 |
| 1307 | if [ $# -eq 2 ]; then |
| 1308 | paramError=0 |
| 1309 | fi |
| 1310 | if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then |
| 1311 | paramError=0 |
| 1312 | fi |
| 1313 | if [ $# -ge 5 ]; then |
| 1314 | paramError=0 |
| 1315 | fi |
| 1316 | |
| 1317 | if [ $paramError -ne 0 ]; then |
| 1318 | __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@ |
| 1319 | return 1 |
| 1320 | fi |
| 1321 | |
| 1322 | query="/ei-producer/v1/eiproducers/$2" |
| 1323 | res="$(__do_curl_to_api ECS GET $query)" |
| 1324 | status=${res:${#res}-3} |
| 1325 | |
| 1326 | if [ $status -ne $1 ]; then |
| 1327 | __log_test_fail_status_code $1 $status |
| 1328 | return 1 |
| 1329 | fi |
| 1330 | |
| 1331 | if [ $# -gt 2 ]; then |
| 1332 | body=${res:0:${#res}-3} |
| 1333 | targetJson="[" |
| 1334 | if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then |
| 1335 | arr=(${@:5}) |
| 1336 | for ((i=0; i<$(($#-4)); i=i+1)); do |
| 1337 | if [ "$targetJson" != "[" ]; then |
| 1338 | targetJson=$targetJson"," |
| 1339 | fi |
| 1340 | targetJson=$targetJson"\"${arr[$i]}\"" |
| 1341 | done |
| 1342 | fi |
| 1343 | targetJson=$targetJson"]" |
| 1344 | if [ $# -gt 4 ]; then |
| 1345 | targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}" |
| 1346 | fi |
| 1347 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1348 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1349 | |
| 1350 | if [ $res -ne 0 ]; then |
| 1351 | __log_test_fail_body |
| 1352 | return 1 |
| 1353 | fi |
| 1354 | fi |
| 1355 | |
| 1356 | __log_test_pass |
| 1357 | return 0 |
| 1358 | } |
| 1359 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1360 | # API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1361 | # args: <response-code> <producer-id> |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1362 | # (Function for test scripts) |
| 1363 | ecs_api_edp_delete_producer() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1364 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1365 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1366 | if [ $# -lt 2 ]; then |
| 1367 | __print_err "<response-code> <producer-id>" $@ |
| 1368 | return 1 |
| 1369 | fi |
| 1370 | |
| 1371 | query="/ei-producer/v1/eiproducers/$2" |
| 1372 | res="$(__do_curl_to_api ECS DELETE $query)" |
| 1373 | status=${res:${#res}-3} |
| 1374 | |
| 1375 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1376 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1377 | return 1 |
| 1378 | fi |
| 1379 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1380 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1381 | return 0 |
| 1382 | } |
| 1383 | |
| 1384 | # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId} |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1385 | # args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1386 | # (Function for test scripts) |
| 1387 | ecs_api_edp_put_producer() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1388 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1389 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1390 | #Valid number of parametrer 5,6,8,10, |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1391 | paramError=1 |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1392 | if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1393 | paramError=0 |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1394 | elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1395 | paramError=0 |
| 1396 | fi |
| 1397 | if [ $paramError -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1398 | __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@ |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1399 | return 1 |
| 1400 | fi |
| 1401 | |
| 1402 | inputJson="[" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1403 | if [ $# -gt 5 ]; then |
| 1404 | arr=(${@:5}) |
| 1405 | for ((i=0; i<$(($#-5)); i=i+2)); do |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1406 | if [ "$inputJson" != "[" ]; then |
| 1407 | inputJson=$inputJson"," |
| 1408 | fi |
| 1409 | if [ -f ${arr[$i+1]} ]; then |
| 1410 | schema=$(cat ${arr[$i+1]}) |
| 1411 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1412 | _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1413 | return 1 |
| 1414 | fi |
| 1415 | inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}" |
| 1416 | done |
| 1417 | fi |
| 1418 | inputJson="\"supported_ei_types\":"$inputJson"]" |
| 1419 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1420 | inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1421 | |
| 1422 | inputJson="{"$inputJson"}" |
| 1423 | |
| 1424 | file="./tmp/.p.json" |
| 1425 | echo "$inputJson" > $file |
| 1426 | query="/ei-producer/v1/eiproducers/$2" |
| 1427 | res="$(__do_curl_to_api ECS PUT $query $file)" |
| 1428 | status=${res:${#res}-3} |
| 1429 | |
| 1430 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1431 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1432 | return 1 |
| 1433 | fi |
| 1434 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1435 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1436 | return 0 |
| 1437 | } |
| 1438 | |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1439 | # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId} |
| 1440 | # args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+] |
| 1441 | # (Function for test scripts) |
| 1442 | ecs_api_edp_put_producer_2() { |
| 1443 | __log_test_start $@ |
| 1444 | |
| 1445 | #Valid number of parametrer 5,6,8,10, |
| 1446 | paramError=1 |
| 1447 | if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then |
| 1448 | paramError=0 |
| 1449 | elif [ $# -ge 5 ]; then |
| 1450 | paramError=0 |
| 1451 | fi |
| 1452 | if [ $paramError -ne 0 ]; then |
| 1453 | __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@ |
| 1454 | return 1 |
| 1455 | fi |
| 1456 | |
| 1457 | inputJson="[" |
| 1458 | if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then |
| 1459 | arr=(${@:5}) |
| 1460 | for ((i=0; i<$(($#-4)); i=i+1)); do |
| 1461 | if [ "$inputJson" != "[" ]; then |
| 1462 | inputJson=$inputJson"," |
| 1463 | fi |
| 1464 | inputJson=$inputJson"\""${arr[$i]}"\"" |
| 1465 | done |
| 1466 | fi |
| 1467 | inputJson="\"supported_ei_types\":"$inputJson"]" |
| 1468 | |
| 1469 | inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"" |
| 1470 | |
| 1471 | inputJson="{"$inputJson"}" |
| 1472 | |
| 1473 | file="./tmp/.p.json" |
| 1474 | echo "$inputJson" > $file |
| 1475 | query="/ei-producer/v1/eiproducers/$2" |
| 1476 | res="$(__do_curl_to_api ECS PUT $query $file)" |
| 1477 | status=${res:${#res}-3} |
| 1478 | |
| 1479 | if [ $status -ne $1 ]; then |
| 1480 | __log_test_fail_status_code $1 $status |
| 1481 | return 1 |
| 1482 | fi |
| 1483 | |
| 1484 | __log_test_pass |
| 1485 | return 0 |
| 1486 | } |
| 1487 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1488 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 1489 | # args: (V1-1) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+) |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1490 | # (Function for test scripts) |
| 1491 | ecs_api_edp_get_producer_jobs() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1492 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1493 | |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 1494 | #Valid number of parameter 2,3,7,11 |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1495 | paramError=1 |
| 1496 | if [ $# -eq 2 ]; then |
| 1497 | paramError=0 |
| 1498 | fi |
| 1499 | if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then |
| 1500 | paramError=0 |
| 1501 | fi |
| 1502 | variablecount=$(($#-2)) |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 1503 | if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1504 | paramError=0 |
| 1505 | fi |
| 1506 | if [ $paramError -eq 1 ]; then |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 1507 | __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1508 | return 1 |
| 1509 | fi |
| 1510 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1511 | query="/ei-producer/v1/eiproducers/$2/eijobs" |
| 1512 | res="$(__do_curl_to_api ECS GET $query)" |
| 1513 | status=${res:${#res}-3} |
| 1514 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1515 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1516 | return 1 |
| 1517 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1518 | if [ $# -gt 2 ]; then |
| 1519 | body=${res:0:${#res}-3} |
| 1520 | targetJson="[" |
| 1521 | if [ $# -gt 3 ]; then |
| 1522 | arr=(${@:3}) |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 1523 | for ((i=0; i<$(($#-3)); i=i+5)); do |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1524 | if [ "$targetJson" != "[" ]; then |
| 1525 | targetJson=$targetJson"," |
| 1526 | fi |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 1527 | if [ -f ${arr[$i+4]} ]; then |
| 1528 | jobfile=$(cat ${arr[$i+4]}) |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1529 | jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g") |
| 1530 | else |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 1531 | _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1532 | return 1 |
| 1533 | fi |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 1534 | targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"ei_job_data\":$jobfile}" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1535 | done |
| 1536 | fi |
| 1537 | targetJson=$targetJson"]" |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1538 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1539 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1540 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1541 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1542 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1543 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1544 | return 1 |
| 1545 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1546 | fi |
| 1547 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1548 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1549 | return 0 |
| 1550 | } |
| 1551 | |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 1552 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs |
| 1553 | # args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+) |
| 1554 | # (Function for test scripts) |
| 1555 | ecs_api_edp_get_producer_jobs_2() { |
| 1556 | __log_test_start $@ |
| 1557 | |
| 1558 | #Valid number of parameter 2,3,7,11 |
| 1559 | paramError=1 |
| 1560 | if [ $# -eq 2 ]; then |
| 1561 | paramError=0 |
| 1562 | fi |
| 1563 | if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then |
| 1564 | paramError=0 |
| 1565 | fi |
| 1566 | variablecount=$(($#-2)) |
| 1567 | if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then |
| 1568 | paramError=0 |
| 1569 | fi |
| 1570 | if [ $paramError -eq 1 ]; then |
| 1571 | __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@ |
| 1572 | return 1 |
| 1573 | fi |
| 1574 | |
| 1575 | query="/ei-producer/v1/eiproducers/$2/eijobs" |
| 1576 | res="$(__do_curl_to_api ECS GET $query)" |
| 1577 | status=${res:${#res}-3} |
| 1578 | if [ $status -ne $1 ]; then |
| 1579 | __log_test_fail_status_code $1 $status |
| 1580 | return 1 |
| 1581 | fi |
| 1582 | if [ $# -gt 2 ]; then |
| 1583 | body=${res:0:${#res}-3} |
| 1584 | targetJson="[" |
| 1585 | if [ $# -gt 3 ]; then |
| 1586 | arr=(${@:3}) |
| 1587 | for ((i=0; i<$(($#-3)); i=i+5)); do |
| 1588 | if [ "$targetJson" != "[" ]; then |
| 1589 | targetJson=$targetJson"," |
| 1590 | fi |
| 1591 | if [ -f ${arr[$i+4]} ]; then |
| 1592 | jobfile=$(cat ${arr[$i+4]}) |
| 1593 | jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g") |
| 1594 | else |
| 1595 | _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist" |
| 1596 | return 1 |
| 1597 | fi |
| 1598 | targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"ei_job_data\":$jobfile, \"last_updated\":\"????\"}" |
| 1599 | done |
| 1600 | fi |
| 1601 | targetJson=$targetJson"]" |
| 1602 | |
| 1603 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1604 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1605 | |
| 1606 | if [ $res -ne 0 ]; then |
| 1607 | __log_test_fail_body |
| 1608 | return 1 |
| 1609 | fi |
| 1610 | fi |
| 1611 | |
| 1612 | __log_test_pass |
| 1613 | return 0 |
| 1614 | } |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1615 | |
| 1616 | ########################################## |
| 1617 | #### Service status #### |
| 1618 | ########################################## |
| 1619 | # Function prefix: ecs_api_service |
| 1620 | |
| 1621 | # API Test function: GET /status |
| 1622 | # args: <response-code> |
| 1623 | # (Function for test scripts) |
| 1624 | ecs_api_service_status() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1625 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1626 | |
| 1627 | if [ $# -lt 1 ]; then |
| 1628 | __print_err "<response-code> [<producer-id>]*|NOID" $@ |
| 1629 | return 1 |
| 1630 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1631 | res="$(__do_curl_to_api ECS GET /status)" |
| 1632 | status=${res:${#res}-3} |
| 1633 | if [ $status -ne $1 ]; then |
| 1634 | __log_test_fail_status_code $1 $status |
| 1635 | return 1 |
| 1636 | fi |
| 1637 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1638 | return 0 |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | |
| 1642 | ########################################## |
| 1643 | #### Reset jobs #### |
| 1644 | ########################################## |
| 1645 | # Function prefix: ecs_api_admin |
| 1646 | |
| 1647 | # Admin to remove all jobs |
BjornMagnussonXA | 366e36a | 2021-01-27 11:48:56 +0100 | [diff] [blame] | 1648 | # args: <response-code> [ <type> ] |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 1649 | # (Function for test scripts) |
| 1650 | |
| 1651 | ecs_api_admin_reset() { |
| 1652 | __log_test_start $@ |
| 1653 | |
| 1654 | if [ -z "$FLAT_A1_EI" ]; then |
| 1655 | query="/A1-EI/v1/eitypes/$2/eijobs" |
| 1656 | else |
| 1657 | query="/A1-EI/v1/eijobs" |
| 1658 | fi |
| 1659 | res="$(__do_curl_to_api ECS GET $query)" |
| 1660 | status=${res:${#res}-3} |
| 1661 | |
| 1662 | if [ $status -ne 200 ]; then |
| 1663 | __log_test_fail_status_code $1 $status |
| 1664 | return 1 |
| 1665 | fi |
| 1666 | |
| 1667 | #Remove brackets and response code |
| 1668 | body=${res:1:${#res}-4} |
| 1669 | list=$(echo ${body//,/ }) |
| 1670 | list=$(echo ${list//[/}) |
| 1671 | list=$(echo ${list//]/}) |
| 1672 | list=$(echo ${list//\"/}) |
| 1673 | list=$list" " |
| 1674 | for job in $list; do |
| 1675 | if [ -z "$FLAT_A1_EI" ]; then |
| 1676 | echo "Not supported for non-flat EI api" |
| 1677 | else |
| 1678 | query="/A1-EI/v1/eijobs/$job" |
| 1679 | res="$(__do_curl_to_api ECS DELETE $query)" |
| 1680 | status=${res:${#res}-3} |
| 1681 | if [ $status -ne 204 ]; then |
| 1682 | __log_test_fail_status_code $1 $status |
| 1683 | return 1 |
| 1684 | fi |
| 1685 | echo " Deleted job: "$job |
| 1686 | fi |
| 1687 | done |
| 1688 | |
| 1689 | __log_test_pass |
| 1690 | return 0 |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1691 | } |