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 | |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 99 | #Save first worker node the pod is started on |
| 100 | __ECS_WORKER_NODE="" |
| 101 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 102 | ########################### |
| 103 | ### ECS functions |
| 104 | ########################### |
| 105 | |
| 106 | # All calls to ECS will be directed to the ECS REST interface from now on |
| 107 | # args: - |
| 108 | # (Function for test scripts) |
| 109 | use_ecs_rest_http() { |
| 110 | echo -e $BOLD"ECS protocol setting"$EBOLD |
| 111 | echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS" |
| 112 | ECS_HTTPX="http" |
| 113 | ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT |
| 114 | |
| 115 | ECS_ADAPTER_TYPE="REST" |
| 116 | ECS_ADAPTER=$ECS_PATH |
| 117 | echo "" |
| 118 | } |
| 119 | |
| 120 | # All calls to ECS will be directed to the ECS REST interface from now on |
| 121 | # args: - |
| 122 | # (Function for test scripts) |
| 123 | use_ecs_rest_https() { |
| 124 | echo -e $BOLD"ECS protocol setting"$EBOLD |
| 125 | echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS" |
| 126 | ECS_HTTPX="https" |
| 127 | ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT |
| 128 | |
| 129 | ECS_ADAPTER_TYPE="REST" |
| 130 | ECS_ADAPTER=$ECS_PATH |
| 131 | echo "" |
| 132 | } |
| 133 | |
| 134 | # All calls to ECS will be directed to the ECS dmaap interface over http from now on |
| 135 | # args: - |
| 136 | # (Function for test scripts) |
| 137 | use_ecs_dmaap_http() { |
| 138 | echo -e $BOLD"ECS dmaap protocol setting"$EBOLD |
| 139 | echo -e $RED" - NOT SUPPORTED - "$ERED |
| 140 | echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS" |
| 141 | ECS_ADAPTER_TYPE="MR-HTTP" |
| 142 | echo "" |
| 143 | } |
| 144 | |
| 145 | # All calls to ECS will be directed to the ECS dmaap interface over https from now on |
| 146 | # args: - |
| 147 | # (Function for test scripts) |
| 148 | use_ecs_dmaap_https() { |
| 149 | echo -e $BOLD"RICSIM protocol setting"$EBOLD |
| 150 | echo -e $RED" - NOT SUPPORTED - "$ERED |
| 151 | echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS" |
| 152 | ECS_ADAPTER_TYPE="MR-HTTPS" |
| 153 | echo "" |
| 154 | } |
| 155 | |
| 156 | # Start the ECS |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 157 | # args: PROXY|NOPROXY <config-file> |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 158 | # (Function for test scripts) |
| 159 | start_ecs() { |
| 160 | |
| 161 | echo -e $BOLD"Starting $ECS_DISPLAY_NAME"$EBOLD |
| 162 | |
| 163 | if [ $RUNMODE == "KUBE" ]; then |
| 164 | |
| 165 | # Check if app shall be fully managed by the test script |
| 166 | __check_included_image "ECS" |
| 167 | retcode_i=$? |
| 168 | |
| 169 | # Check if app shall only be used by the testscipt |
| 170 | __check_prestarted_image "ECS" |
| 171 | retcode_p=$? |
| 172 | |
| 173 | if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then |
| 174 | echo -e $RED"The $ECS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED |
| 175 | echo -e $RED"The $ECS_APP_NAME will not be started"$ERED |
| 176 | exit |
| 177 | fi |
| 178 | if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then |
| 179 | echo -e $RED"The $ECS_APP_NAME app is included both as managed and prestarted in this test script"$ERED |
| 180 | echo -e $RED"The $ECS_APP_NAME will not be started"$ERED |
| 181 | exit |
| 182 | fi |
| 183 | |
| 184 | |
| 185 | if [ $retcode_p -eq 0 ]; then |
| 186 | echo -e " Using existing $ECS_APP_NAME deployment and service" |
| 187 | echo " Setting ECS replicas=1" |
| 188 | __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1 |
| 189 | fi |
| 190 | |
| 191 | # Check if app shall be fully managed by the test script |
| 192 | if [ $retcode_i -eq 0 ]; then |
| 193 | echo -e " Creating $ECS_APP_NAME app and expose service" |
| 194 | |
| 195 | #Check if nonrtric namespace exists, if not create it |
| 196 | __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE |
| 197 | |
| 198 | export ECS_APP_NAME |
| 199 | export KUBE_NONRTRIC_NAMESPACE |
| 200 | export ECS_IMAGE |
| 201 | export ECS_INTERNAL_PORT |
| 202 | export ECS_INTERNAL_SECURE_PORT |
| 203 | export ECS_EXTERNAL_PORT |
| 204 | export ECS_EXTERNAL_SECURE_PORT |
| 205 | export ECS_CONFIG_MOUNT_PATH |
| 206 | export ECS_CONFIG_CONFIGMAP_NAME=$ECS_APP_NAME"-config" |
| 207 | export ECS_DATA_CONFIGMAP_NAME=$ECS_APP_NAME"-data" |
| 208 | export ECS_CONTAINER_MNT_DIR |
| 209 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 210 | export ECS_DATA_PV_NAME=$ECS_APP_NAME"-pv" |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 211 | export ECS_DATA_PVC_NAME=$ECS_APP_NAME"-pvc" |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 212 | #Create a unique path for the pv each time to prevent a previous volume to be reused |
| 213 | export ECS_PV_PATH="ecsdata-"$(date +%s) |
| 214 | |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 215 | if [ $1 == "PROXY" ]; then |
| 216 | ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started |
| 217 | ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started |
| 218 | if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then |
| 219 | echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW |
| 220 | else |
| 221 | echo " Configured with http proxy" |
| 222 | fi |
| 223 | else |
| 224 | ECS_HTTP_PROXY_CONFIG_PORT=0 |
| 225 | ECS_HTTP_PROXY_CONFIG_HOST_NAME="" |
| 226 | echo " Configured without http proxy" |
| 227 | fi |
| 228 | export ECS_HTTP_PROXY_CONFIG_PORT |
| 229 | export ECS_HTTP_PROXY_CONFIG_HOST_NAME |
| 230 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 231 | # Create config map for config |
| 232 | datafile=$PWD/tmp/$ECS_CONFIG_FILE |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 233 | cp $2 $datafile |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 234 | output_yaml=$PWD/tmp/ecs_cfc.yaml |
| 235 | __kube_create_configmap $ECS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ECS $datafile $output_yaml |
| 236 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 237 | # Create pv |
| 238 | input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pv.yaml |
| 239 | output_yaml=$PWD/tmp/ecs_pv.yaml |
| 240 | __kube_create_instance pv $ECS_APP_NAME $input_yaml $output_yaml |
| 241 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 242 | # Create pvc |
| 243 | input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pvc.yaml |
| 244 | output_yaml=$PWD/tmp/ecs_pvc.yaml |
| 245 | __kube_create_instance pvc $ECS_APP_NAME $input_yaml $output_yaml |
| 246 | |
| 247 | # Create service |
| 248 | input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"svc.yaml |
| 249 | output_yaml=$PWD/tmp/ecs_svc.yaml |
| 250 | __kube_create_instance service $ECS_APP_NAME $input_yaml $output_yaml |
| 251 | |
| 252 | # Create app |
| 253 | input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"app.yaml |
| 254 | output_yaml=$PWD/tmp/ecs_app.yaml |
| 255 | __kube_create_instance app $ECS_APP_NAME $input_yaml $output_yaml |
| 256 | fi |
| 257 | |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 258 | # Tie the ECS to a worker node so that ECS will always be scheduled to the same worker node if the ECS pod is restarted |
| 259 | # A PVC of type hostPath is mounted to ECS, for persistent storage, so the ECS must always be on the node which mounted the volume |
| 260 | |
| 261 | # Keep the initial worker node in case the pod need to be "restarted" - must be made to the same node due to a volume mounted on the host |
BjornMagnussonXA | a549157 | 2021-05-04 09:21:24 +0200 | [diff] [blame] | 262 | if [ $retcode_i -eq 0 ]; then |
| 263 | __ECS_WORKER_NODE=$(kubectl get pod -l "autotest=ECS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}') |
| 264 | if [ -z "$__ECS_WORKER_NODE" ]; then |
| 265 | echo -e $YELLOW" Cannot find worker node for pod for $ECS_APP_NAME, persistency may not work"$EYELLOW |
| 266 | fi |
| 267 | else |
| 268 | echo -e $YELLOW" Persistency may not work for app $ECS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 269 | fi |
| 270 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 271 | echo " Retrieving host and ports for service..." |
| 272 | ECS_HOST_NAME=$(__kube_get_service_host $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE) |
| 273 | ECS_EXTERNAL_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http") |
| 274 | ECS_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https") |
| 275 | |
| 276 | echo " Host IP, http port, https port: $ECS_HOST_NAME $ECS_EXTERNAL_PORT $ECS_EXTERNAL_SECURE_PORT" |
| 277 | |
| 278 | if [ $ECS_HTTPX == "http" ]; then |
| 279 | ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT |
| 280 | else |
| 281 | ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT |
| 282 | fi |
| 283 | |
| 284 | __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL |
| 285 | |
| 286 | if [ $ECS_ADAPTER_TYPE == "REST" ]; then |
| 287 | ECS_ADAPTER=$ECS_PATH |
| 288 | fi |
| 289 | else |
| 290 | __check_included_image 'ECS' |
| 291 | if [ $? -eq 1 ]; then |
| 292 | echo -e $RED"The ECS app is not included in this test script"$ERED |
| 293 | echo -e $RED"ECS will not be started"$ERED |
| 294 | exit 1 |
| 295 | fi |
| 296 | |
| 297 | curdir=$PWD |
| 298 | cd $SIM_GROUP |
| 299 | cd ecs |
| 300 | cd $ECS_HOST_MNT_DIR |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 301 | #cd .. |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 302 | if [ -d db ]; then |
| 303 | if [ "$(ls -A $DIR)" ]; then |
| 304 | echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD |
| 305 | rm -rf db/* &> /dev/null |
| 306 | if [ $? -ne 0 ]; then |
| 307 | echo -e $RED" Cannot remove database files in: $PWD"$ERED |
| 308 | exit 1 |
| 309 | fi |
| 310 | fi |
| 311 | else |
| 312 | echo " No files in mounted dir or dir does not exists" |
| 313 | fi |
| 314 | cd $curdir |
| 315 | |
| 316 | export ECS_APP_NAME |
| 317 | export ECS_APP_NAME_ALIAS |
| 318 | export ECS_HOST_MNT_DIR |
| 319 | export ECS_CONTAINER_MNT_DIR |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 320 | export ECS_CONFIG_MOUNT_PATH |
| 321 | export ECS_CONFIG_FILE |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 322 | export ECS_INTERNAL_PORT |
| 323 | export ECS_EXTERNAL_PORT |
| 324 | export ECS_INTERNAL_SECURE_PORT |
| 325 | export ECS_EXTERNAL_SECURE_PORT |
| 326 | export DOCKER_SIM_NWNAME |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 327 | export ECS_DISPLAY_NAME |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 328 | |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 329 | if [ $1 == "PROXY" ]; then |
| 330 | ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started |
| 331 | ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started |
| 332 | if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then |
| 333 | echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW |
| 334 | else |
| 335 | echo " Configured with http proxy" |
| 336 | fi |
| 337 | else |
| 338 | ECS_HTTP_PROXY_CONFIG_PORT=0 |
| 339 | ECS_HTTP_PROXY_CONFIG_HOST_NAME="" |
| 340 | echo " Configured without http proxy" |
| 341 | fi |
| 342 | export ECS_HTTP_PROXY_CONFIG_PORT |
| 343 | export ECS_HTTP_PROXY_CONFIG_HOST_NAME |
| 344 | |
| 345 | dest_file=$SIM_GROUP/$ECS_COMPOSE_DIR/$ECS_HOST_MNT_DIR/$ECS_CONFIG_FILE |
| 346 | |
| 347 | envsubst < $2 > $dest_file |
| 348 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 349 | __start_container $ECS_COMPOSE_DIR "" NODOCKERARGS 1 $ECS_APP_NAME |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 350 | |
| 351 | __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL |
| 352 | fi |
| 353 | echo "" |
| 354 | return 0 |
| 355 | } |
| 356 | |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 357 | # Stop the ecs |
| 358 | # args: - |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 359 | # args: - |
| 360 | # (Function for test scripts) |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 361 | stop_ecs() { |
| 362 | echo -e $BOLD"Stopping $ECS_DISPLAY_NAME"$EBOLD |
| 363 | |
| 364 | if [ $RUNMODE == "KUBE" ]; then |
BjornMagnussonXA | a549157 | 2021-05-04 09:21:24 +0200 | [diff] [blame] | 365 | |
| 366 | __check_prestarted_image "ECS" |
| 367 | if [ $? -eq 0 ]; then |
| 368 | echo -e $YELLOW" Persistency may not work for app $ECS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW |
| 369 | __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0 |
| 370 | return 0 |
| 371 | fi |
| 372 | |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 373 | __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS |
| 374 | echo " Deleting the replica set - a new will be started when the app is started" |
| 375 | tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=ECS") |
| 376 | if [ $? -ne 0 ]; then |
| 377 | echo -e $RED" Could not delete replica set "$RED |
| 378 | ((RES_CONF_FAIL++)) |
| 379 | return 1 |
| 380 | fi |
| 381 | else |
| 382 | docker stop $ECS_APP_NAME &> ./tmp/.dockererr |
| 383 | if [ $? -ne 0 ]; then |
| 384 | __print_err "Could not stop $ECS_APP_NAME" $@ |
| 385 | cat ./tmp/.dockererr |
| 386 | ((RES_CONF_FAIL++)) |
| 387 | return 1 |
| 388 | fi |
| 389 | fi |
| 390 | echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD |
| 391 | echo "" |
| 392 | return 0 |
| 393 | } |
| 394 | |
| 395 | # Start a previously stopped ecs |
| 396 | # args: - |
| 397 | # (Function for test scripts) |
| 398 | start_stopped_ecs() { |
| 399 | echo -e $BOLD"Starting (the previously stopped) $ECS_DISPLAY_NAME"$EBOLD |
| 400 | |
| 401 | if [ $RUNMODE == "KUBE" ]; then |
| 402 | |
BjornMagnussonXA | a549157 | 2021-05-04 09:21:24 +0200 | [diff] [blame] | 403 | __check_prestarted_image "ECS" |
| 404 | if [ $? -eq 0 ]; then |
| 405 | echo -e $YELLOW" Persistency may not work for app $ECS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW |
| 406 | __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1 |
| 407 | __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL |
| 408 | return 0 |
| 409 | fi |
| 410 | |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 411 | # Tie the PMS to the same worker node it was initially started on |
| 412 | # A PVC of type hostPath is mounted to PMS, for persistent storage, so the PMS must always be on the node which mounted the volume |
| 413 | if [ -z "$__ECS_WORKER_NODE" ]; then |
| 414 | echo -e $RED" No initial worker node found for pod "$RED |
| 415 | ((RES_CONF_FAIL++)) |
| 416 | return 1 |
| 417 | else |
| 418 | echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__ECS_WORKER_NODE to deployment for $ECS_APP_NAME. Pod will always run on this worker node: $__PA_WORKER_NODE"$BOLD |
| 419 | echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD |
| 420 | tmp=$(kubectl patch deployment $ECS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__ECS_WORKER_NODE'"}}}}}') |
| 421 | if [ $? -ne 0 ]; then |
| 422 | echo -e $YELLOW" Cannot set nodeSelector to deployment for $ECS_APP_NAME, persistency may not work"$EYELLOW |
| 423 | fi |
| 424 | __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1 |
| 425 | fi |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 426 | else |
| 427 | docker start $ECS_APP_NAME &> ./tmp/.dockererr |
| 428 | if [ $? -ne 0 ]; then |
| 429 | __print_err "Could not start (the stopped) $ECS_APP_NAME" $@ |
| 430 | cat ./tmp/.dockererr |
| 431 | ((RES_CONF_FAIL++)) |
| 432 | return 1 |
| 433 | fi |
| 434 | fi |
| 435 | __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 436 | if [ $? -ne 0 ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 437 | return 1 |
| 438 | fi |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 439 | echo "" |
| 440 | return 0 |
| 441 | } |
| 442 | |
| 443 | # Turn on debug level tracing in ECS |
| 444 | # args: - |
| 445 | # (Function for test scripts) |
| 446 | set_ecs_debug() { |
| 447 | echo -e $BOLD"Setting ecs debug logging"$EBOLD |
| 448 | curlString="$ECS_PATH$ECS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}" |
| 449 | result=$(__do_curl "$curlString") |
| 450 | if [ $? -ne 0 ]; then |
| 451 | __print_err "Could not set debug mode" $@ |
| 452 | ((RES_CONF_FAIL++)) |
| 453 | return 1 |
| 454 | fi |
| 455 | echo "" |
| 456 | return 0 |
| 457 | } |
| 458 | |
| 459 | # Turn on trace level tracing in ECS |
| 460 | # args: - |
| 461 | # (Function for test scripts) |
| 462 | set_ecs_trace() { |
| 463 | echo -e $BOLD"Setting ecs trace logging"$EBOLD |
| 464 | curlString="$ECS_PATH/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}" |
| 465 | result=$(__do_curl "$curlString") |
| 466 | if [ $? -ne 0 ]; then |
| 467 | __print_err "Could not set trace mode" $@ |
| 468 | ((RES_CONF_FAIL++)) |
| 469 | return 1 |
| 470 | fi |
| 471 | echo "" |
| 472 | return 0 |
| 473 | } |
| 474 | |
| 475 | # Perform curl retries when making direct call to ECS for the specified http response codes |
| 476 | # Speace separated list of http response codes |
| 477 | # args: [<response-code>]* |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 478 | use_ecs_retries() { |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 479 | 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] | 480 | ECS_RETRY_CODES=$@ |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 481 | echo "" |
| 482 | return 0 |
| 483 | } |
| 484 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 485 | # Check the ecs logs for WARNINGs and ERRORs |
| 486 | # args: - |
| 487 | # (Function for test scripts) |
| 488 | check_ecs_logs() { |
| 489 | __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR |
| 490 | } |
| 491 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 492 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 493 | # Tests if a variable value in the ECS is equal to a target value and and optional timeout. |
| 494 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is |
| 495 | # equal to the target or not. |
| 496 | # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 497 | # before setting pass or fail depending on if the variable value becomes equal to the target |
| 498 | # value or not. |
| 499 | # (Function for test scripts) |
| 500 | ecs_equal() { |
| 501 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 502 | __var_test ECS "$ECS_PATH/" $1 "=" $2 $3 |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 503 | else |
| 504 | __print_err "Wrong args to ecs_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@ |
| 505 | fi |
| 506 | } |
| 507 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 508 | |
| 509 | ########################################## |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 510 | ######### A1-E Enrichment API ########## |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 511 | ########################################## |
| 512 | #Function prefix: ecs_api_a1 |
| 513 | |
| 514 | # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 515 | # args: <response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ] |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 516 | # 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] | 517 | # (Function for test scripts) |
| 518 | ecs_api_a1_get_job_ids() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 519 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 520 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 521 | if [ -z "$FLAT_A1_EI" ]; then |
| 522 | # Valid number of parameters 4,5,6 etc |
| 523 | if [ $# -lt 3 ]; then |
| 524 | __print_err "<response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@ |
| 525 | return 1 |
| 526 | fi |
| 527 | else |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 528 | echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 529 | # Valid number of parameters 4,5,6 etc |
| 530 | if [ $# -lt 3 ]; then |
| 531 | __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@ |
| 532 | return 1 |
| 533 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 534 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 535 | search="" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 536 | if [ $3 != "NOWNER" ]; then |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 537 | search="?owner="$3 |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 538 | fi |
| 539 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 540 | if [ -z "$FLAT_A1_EI" ]; then |
| 541 | query="/A1-EI/v1/eitypes/$2/eijobs$search" |
| 542 | else |
| 543 | if [ $2 != "NOTYPE" ]; then |
| 544 | if [ -z "$search" ]; then |
| 545 | search="?eiTypeId="$2 |
| 546 | else |
| 547 | search=$search"&eiTypeId="$2 |
| 548 | fi |
| 549 | fi |
| 550 | query="/A1-EI/v1/eijobs$search" |
| 551 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 552 | res="$(__do_curl_to_api ECS GET $query)" |
| 553 | status=${res:${#res}-3} |
| 554 | |
| 555 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 556 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 557 | return 1 |
| 558 | fi |
| 559 | |
| 560 | if [ $# -gt 3 ]; then |
| 561 | body=${res:0:${#res}-3} |
| 562 | targetJson="[" |
| 563 | |
| 564 | for pid in ${@:4} ; do |
| 565 | if [ "$targetJson" != "[" ]; then |
| 566 | targetJson=$targetJson"," |
| 567 | fi |
| 568 | if [ $pid != "EMPTY" ]; then |
| 569 | targetJson=$targetJson"\"$pid\"" |
| 570 | fi |
| 571 | done |
| 572 | |
| 573 | targetJson=$targetJson"]" |
| 574 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 575 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 576 | |
| 577 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 578 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 579 | return 1 |
| 580 | fi |
| 581 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 582 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 583 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 584 | return 0 |
| 585 | } |
| 586 | |
| 587 | # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 588 | # args: <response-code> <type-id> [<schema-file>] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 589 | # (Function for test scripts) |
| 590 | ecs_api_a1_get_type() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 591 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 592 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 593 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 594 | __print_err "<response-code> <type-id> [<schema-file>]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 595 | return 1 |
| 596 | fi |
| 597 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 598 | query="/A1-EI/v1/eitypes/$2" |
| 599 | res="$(__do_curl_to_api ECS GET $query)" |
| 600 | status=${res:${#res}-3} |
| 601 | |
| 602 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 603 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 604 | return 1 |
| 605 | fi |
| 606 | |
| 607 | if [ $# -eq 3 ]; then |
| 608 | body=${res:0:${#res}-3} |
| 609 | if [ -f $3 ]; then |
| 610 | schema=$(cat $3) |
| 611 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 612 | __log_test_fail_general "Schema file "$3", does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 613 | return 1 |
| 614 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 615 | if [ -z "$FLAT_A1_EI" ]; then |
| 616 | targetJson="{\"eiJobParametersSchema\":$schema}" |
| 617 | else |
| 618 | targetJson=$schema |
| 619 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 620 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 621 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 622 | |
| 623 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 624 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 625 | return 1 |
| 626 | fi |
| 627 | fi |
| 628 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 629 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 630 | return 0 |
| 631 | } |
| 632 | |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 633 | # API Test function: GET /A1-EI/v1/eitypes |
| 634 | # args: <response-code> [ (EMPTY | [<type-id>]+) ] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 635 | # (Function for test scripts) |
| 636 | ecs_api_a1_get_type_ids() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 637 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 638 | |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 639 | if [ $# -lt 1 ]; then |
| 640 | __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@ |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 641 | return 1 |
| 642 | fi |
| 643 | |
| 644 | query="/A1-EI/v1/eitypes" |
| 645 | res="$(__do_curl_to_api ECS GET $query)" |
| 646 | status=${res:${#res}-3} |
| 647 | |
| 648 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 649 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 650 | return 1 |
| 651 | fi |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 652 | if [ $# -gt 1 ]; then |
| 653 | body=${res:0:${#res}-3} |
| 654 | targetJson="[" |
| 655 | if [ $2 != "EMPTY" ]; then |
| 656 | for pid in ${@:2} ; do |
| 657 | if [ "$targetJson" != "[" ]; then |
| 658 | targetJson=$targetJson"," |
| 659 | fi |
| 660 | targetJson=$targetJson"\"$pid\"" |
| 661 | done |
| 662 | fi |
| 663 | targetJson=$targetJson"]" |
| 664 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 665 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 666 | |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 667 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 668 | __log_test_fail_body |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 669 | return 1 |
| 670 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 671 | fi |
| 672 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 673 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 674 | return 0 |
| 675 | } |
| 676 | |
| 677 | # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}/status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 678 | # args: <response-code> <type-id> <job-id> [<status>] |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 679 | # args (flat uri structure): <response-code> <job-id> [<status> [<timeout>]] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 680 | # (Function for test scripts) |
| 681 | ecs_api_a1_get_job_status() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 682 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 683 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 684 | if [ -z "$FLAT_A1_EI" ]; then |
| 685 | if [ $# -ne 3 ] && [ $# -ne 4 ]; then |
| 686 | __print_err "<response-code> <type-id> <job-id> [<status>]" $@ |
| 687 | return 1 |
| 688 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 689 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 690 | query="/A1-EI/v1/eitypes/$2/eijobs/$3/status" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 691 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 692 | res="$(__do_curl_to_api ECS GET $query)" |
| 693 | status=${res:${#res}-3} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 694 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 695 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 696 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 697 | return 1 |
| 698 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 699 | if [ $# -eq 4 ]; then |
| 700 | body=${res:0:${#res}-3} |
| 701 | targetJson="{\"operationalState\": \"$4\"}" |
| 702 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 703 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 704 | |
| 705 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 706 | __log_test_fail_body |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 707 | return 1 |
| 708 | fi |
| 709 | fi |
| 710 | else |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 711 | echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 712 | if [ $# -lt 2 ] && [ $# -gt 4 ]; then |
| 713 | __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@ |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 714 | return 1 |
| 715 | fi |
| 716 | |
| 717 | query="/A1-EI/v1/eijobs/$2/status" |
| 718 | |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 719 | start=$SECONDS |
| 720 | for (( ; ; )); do |
| 721 | res="$(__do_curl_to_api ECS GET $query)" |
| 722 | status=${res:${#res}-3} |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 723 | |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 724 | if [ $# -eq 4 ]; then |
| 725 | duration=$((SECONDS-start)) |
| 726 | echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}" |
| 727 | if [ $duration -gt $4 ]; then |
| 728 | echo "" |
| 729 | duration=-1 #Last iteration |
| 730 | fi |
| 731 | else |
| 732 | duration=-1 #single test, no wait |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 733 | fi |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 734 | |
| 735 | if [ $status -ne $1 ]; then |
| 736 | if [ $duration -eq -1 ]; then |
| 737 | __log_test_fail_status_code $1 $status |
| 738 | return 1 |
| 739 | fi |
| 740 | fi |
| 741 | if [ $# -ge 3 ] && [ $status -eq $1 ]; then |
| 742 | body=${res:0:${#res}-3} |
| 743 | targetJson="{\"eiJobStatus\": \"$3\"}" |
| 744 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 745 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 746 | |
| 747 | if [ $res -ne 0 ]; then |
| 748 | if [ $duration -eq -1 ]; then |
| 749 | __log_test_fail_body |
| 750 | return 1 |
| 751 | fi |
| 752 | else |
| 753 | duration=-1 #Goto pass |
| 754 | fi |
| 755 | fi |
| 756 | if [ $duration -eq -1 ]; then |
| 757 | if [ $# -eq 4 ]; then |
| 758 | echo "" |
| 759 | fi |
| 760 | __log_test_pass |
| 761 | return 0 |
| 762 | else |
| 763 | sleep 1 |
| 764 | fi |
| 765 | done |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 766 | fi |
| 767 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 768 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 769 | return 0 |
| 770 | } |
| 771 | |
| 772 | # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 773 | # 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] | 774 | # 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] | 775 | # (Function for test scripts) |
| 776 | ecs_api_a1_get_job() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 777 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 778 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 779 | if [ -z "$FLAT_A1_EI" ]; then |
| 780 | if [ $# -ne 3 ] && [ $# -ne 6 ]; then |
| 781 | __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@ |
| 782 | return 1 |
| 783 | fi |
| 784 | query="/A1-EI/v1/eitypes/$2/eijobs/$3" |
| 785 | else |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 786 | echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 787 | if [ $# -ne 2 ] && [ $# -ne 7 ]; then |
| 788 | __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@ |
| 789 | return 1 |
| 790 | fi |
| 791 | query="/A1-EI/v1/eijobs/$2" |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 792 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 793 | res="$(__do_curl_to_api ECS GET $query)" |
| 794 | status=${res:${#res}-3} |
| 795 | |
| 796 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 797 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 798 | return 1 |
| 799 | fi |
| 800 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 801 | if [ -z "$FLAT_A1_EI" ]; then |
| 802 | if [ $# -eq 6 ]; then |
| 803 | body=${res:0:${#res}-3} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 804 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 805 | if [ -f $6 ]; then |
| 806 | jobfile=$(cat $6) |
| 807 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") |
| 808 | else |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame^] | 809 | __log_test_fail_general "Job template file "$6", does not exist" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 810 | return 1 |
| 811 | fi |
| 812 | targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}" |
| 813 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 814 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 815 | |
| 816 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 817 | __log_test_fail_body |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 818 | return 1 |
| 819 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 820 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 821 | else |
| 822 | if [ $# -eq 7 ]; then |
| 823 | body=${res:0:${#res}-3} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 824 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 825 | if [ -f $7 ]; then |
| 826 | jobfile=$(cat $7) |
| 827 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g") |
| 828 | else |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame^] | 829 | __log_test_fail_general "Job template file "$6", does not exist" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 830 | return 1 |
| 831 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 832 | targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 833 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 834 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 835 | |
| 836 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 837 | __log_test_fail_body |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 838 | return 1 |
| 839 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 840 | fi |
| 841 | fi |
| 842 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 843 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 844 | return 0 |
| 845 | } |
| 846 | |
| 847 | # API Test function: DELETE /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 848 | # args: <response-code> <type-id> <job-id> |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 849 | # args (flat uri structure): <response-code> <job-id> |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 850 | # (Function for test scripts) |
| 851 | ecs_api_a1_delete_job() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 852 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 853 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 854 | if [ -z "$FLAT_A1_EI" ]; then |
| 855 | if [ $# -ne 3 ]; then |
| 856 | __print_err "<response-code> <type-id> <job-id>" $@ |
| 857 | return 1 |
| 858 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 859 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 860 | query="/A1-EI/v1/eitypes/$2/eijobs/$3" |
| 861 | else |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 862 | echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 863 | if [ $# -ne 2 ]; then |
| 864 | __print_err "<response-code> <job-id>" $@ |
| 865 | return 1 |
| 866 | fi |
| 867 | query="/A1-EI/v1/eijobs/$2" |
| 868 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 869 | res="$(__do_curl_to_api ECS DELETE $query)" |
| 870 | status=${res:${#res}-3} |
| 871 | |
| 872 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 873 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 874 | return 1 |
| 875 | fi |
| 876 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 877 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 878 | return 0 |
| 879 | } |
| 880 | |
| 881 | # API Test function: PUT /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 882 | # 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] | 883 | # 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] | 884 | # (Function for test scripts) |
| 885 | ecs_api_a1_put_job() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 886 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 887 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 888 | if [ -z "$FLAT_A1_EI" ]; then |
| 889 | if [ $# -lt 6 ]; then |
| 890 | __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@ |
| 891 | return 1 |
| 892 | fi |
| 893 | if [ -f $6 ]; then |
| 894 | jobfile=$(cat $6) |
| 895 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") |
| 896 | else |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame^] | 897 | __log_test_fail_general "Job template file "$6", does not exist" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 898 | return 1 |
| 899 | fi |
| 900 | |
| 901 | inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}" |
| 902 | file="./tmp/.p.json" |
| 903 | echo "$inputJson" > $file |
| 904 | |
| 905 | query="/A1-EI/v1/eitypes/$2/eijobs/$3" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 906 | else |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 907 | echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 908 | if [ $# -lt 7 ]; then |
| 909 | __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@ |
| 910 | return 1 |
| 911 | fi |
| 912 | if [ -f $7 ]; then |
| 913 | jobfile=$(cat $7) |
| 914 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g") |
| 915 | else |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame^] | 916 | __log_test_fail_general "Job template file "$7", does not exist" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 917 | return 1 |
| 918 | fi |
| 919 | |
| 920 | inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}" |
| 921 | file="./tmp/.p.json" |
| 922 | echo "$inputJson" > $file |
| 923 | |
| 924 | query="/A1-EI/v1/eijobs/$2" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 925 | fi |
| 926 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 927 | res="$(__do_curl_to_api ECS PUT $query $file)" |
| 928 | status=${res:${#res}-3} |
| 929 | |
| 930 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 931 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 932 | return 1 |
| 933 | fi |
| 934 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 935 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 936 | return 0 |
| 937 | } |
| 938 | |
| 939 | |
| 940 | ########################################## |
| 941 | #### Enrichment Data Producer API #### |
| 942 | ########################################## |
| 943 | # Function prefix: ecs_api_edp |
| 944 | |
| 945 | # API Test function: GET /ei-producer/v1/eitypes |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 946 | # args: <response-code> [ EMPTY | <type-id>+] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 947 | # (Function for test scripts) |
| 948 | ecs_api_edp_get_type_ids() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 949 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 950 | |
| 951 | if [ $# -lt 1 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 952 | __print_err "<response-code> [ EMPTY | <type-id>+]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 953 | return 1 |
| 954 | fi |
| 955 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 956 | query="/ei-producer/v1/eitypes" |
| 957 | res="$(__do_curl_to_api ECS GET $query)" |
| 958 | status=${res:${#res}-3} |
| 959 | |
| 960 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 961 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 962 | return 1 |
| 963 | fi |
| 964 | |
| 965 | if [ $# -gt 1 ]; then |
| 966 | body=${res:0:${#res}-3} |
| 967 | targetJson="[" |
| 968 | if [ $2 != "EMPTY" ]; then |
| 969 | for pid in ${@:2} ; do |
| 970 | if [ "$targetJson" != "[" ]; then |
| 971 | targetJson=$targetJson"," |
| 972 | fi |
| 973 | targetJson=$targetJson"\"$pid\"" |
| 974 | done |
| 975 | fi |
| 976 | targetJson=$targetJson"]" |
| 977 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 978 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 979 | |
| 980 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 981 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 982 | return 1 |
| 983 | fi |
| 984 | fi |
| 985 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 986 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 987 | return 0 |
| 988 | } |
| 989 | |
| 990 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 991 | # args: <response-code> <producer-id> [<status> [<timeout>]] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 992 | # (Function for test scripts) |
| 993 | ecs_api_edp_get_producer_status() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 994 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 995 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 996 | if [ $# -lt 2 ] || [ $# -gt 4 ]; then |
| 997 | __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 998 | return 1 |
| 999 | fi |
| 1000 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1001 | query="/ei-producer/v1/eiproducers/$2/status" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1002 | start=$SECONDS |
| 1003 | for (( ; ; )); do |
| 1004 | res="$(__do_curl_to_api ECS GET $query)" |
| 1005 | status=${res:${#res}-3} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1006 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1007 | if [ $# -eq 4 ]; then |
| 1008 | duration=$((SECONDS-start)) |
| 1009 | echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}" |
| 1010 | if [ $duration -gt $4 ]; then |
| 1011 | echo "" |
| 1012 | duration=-1 #Last iteration |
| 1013 | fi |
| 1014 | else |
| 1015 | duration=-1 #single test, no wait |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1016 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1017 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1018 | if [ $status -ne $1 ]; then |
| 1019 | if [ $duration -eq -1 ]; then |
| 1020 | __log_test_fail_status_code $1 $status |
| 1021 | return 1 |
| 1022 | fi |
| 1023 | fi |
| 1024 | if [ $# -ge 3 ] && [ $status -eq $1 ]; then |
| 1025 | body=${res:0:${#res}-3} |
| 1026 | targetJson="{\"operational_state\": \"$3\"}" |
| 1027 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1028 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1029 | |
| 1030 | if [ $res -ne 0 ]; then |
| 1031 | if [ $duration -eq -1 ]; then |
| 1032 | __log_test_fail_body |
| 1033 | return 1 |
| 1034 | fi |
| 1035 | else |
| 1036 | duration=-1 #Goto pass |
| 1037 | fi |
| 1038 | fi |
| 1039 | if [ $duration -eq -1 ]; then |
| 1040 | if [ $# -eq 4 ]; then |
| 1041 | echo "" |
| 1042 | fi |
| 1043 | __log_test_pass |
| 1044 | return 0 |
| 1045 | else |
| 1046 | sleep 1 |
| 1047 | fi |
| 1048 | done |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | |
| 1052 | # API Test function: GET /ei-producer/v1/eiproducers |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1053 | # args (v1_1): <response-code> [ EMPTY | <producer-id>+] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1054 | # (Function for test scripts) |
| 1055 | ecs_api_edp_get_producer_ids() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1056 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1057 | |
| 1058 | if [ $# -lt 1 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1059 | __print_err "<response-code> [ EMPTY | <producer-id>+]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1060 | return 1 |
| 1061 | fi |
| 1062 | |
| 1063 | query="/ei-producer/v1/eiproducers" |
| 1064 | res="$(__do_curl_to_api ECS GET $query)" |
| 1065 | status=${res:${#res}-3} |
| 1066 | |
| 1067 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1068 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1069 | return 1 |
| 1070 | fi |
| 1071 | |
| 1072 | if [ $# -gt 1 ]; then |
| 1073 | body=${res:0:${#res}-3} |
| 1074 | targetJson="[" |
| 1075 | |
| 1076 | for pid in ${@:2} ; do |
| 1077 | if [ "$targetJson" != "[" ]; then |
| 1078 | targetJson=$targetJson"," |
| 1079 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1080 | if [ $pid != "EMPTY" ]; then |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1081 | targetJson=$targetJson"\"$pid\"" |
| 1082 | fi |
| 1083 | done |
| 1084 | |
| 1085 | targetJson=$targetJson"]" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1086 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1087 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1088 | |
| 1089 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1090 | __log_test_fail_body |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1091 | return 1 |
| 1092 | fi |
| 1093 | fi |
| 1094 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1095 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1096 | return 0 |
| 1097 | } |
| 1098 | |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1099 | # API Test function: GET /ei-producer/v1/eiproducers |
| 1100 | # args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ] |
| 1101 | # (Function for test scripts) |
| 1102 | ecs_api_edp_get_producer_ids_2() { |
| 1103 | __log_test_start $@ |
| 1104 | |
| 1105 | if [ $# -lt 1 ]; then |
| 1106 | __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@ |
| 1107 | return 1 |
| 1108 | fi |
| 1109 | |
| 1110 | query="/ei-producer/v1/eiproducers" |
| 1111 | if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then |
| 1112 | query=$query"?ei_type_id=$2" |
| 1113 | fi |
| 1114 | res="$(__do_curl_to_api ECS GET $query)" |
| 1115 | status=${res:${#res}-3} |
| 1116 | |
| 1117 | if [ $status -ne $1 ]; then |
| 1118 | __log_test_fail_status_code $1 $status |
| 1119 | return 1 |
| 1120 | fi |
| 1121 | |
| 1122 | if [ $# -gt 2 ]; then |
| 1123 | body=${res:0:${#res}-3} |
| 1124 | targetJson="[" |
| 1125 | |
| 1126 | for pid in ${@:3} ; do |
| 1127 | if [ "$targetJson" != "[" ]; then |
| 1128 | targetJson=$targetJson"," |
| 1129 | fi |
| 1130 | if [ $pid != "EMPTY" ]; then |
| 1131 | targetJson=$targetJson"\"$pid\"" |
| 1132 | fi |
| 1133 | done |
| 1134 | |
| 1135 | targetJson=$targetJson"]" |
| 1136 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1137 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1138 | |
| 1139 | if [ $res -ne 0 ]; then |
| 1140 | __log_test_fail_body |
| 1141 | return 1 |
| 1142 | fi |
| 1143 | fi |
| 1144 | |
| 1145 | __log_test_pass |
| 1146 | return 0 |
| 1147 | } |
| 1148 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1149 | # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId} |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1150 | # args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1151 | # (Function for test scripts) |
| 1152 | ecs_api_edp_get_type() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1153 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1154 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1155 | paramError=1 |
| 1156 | if [ $# -eq 2 ]; then |
| 1157 | paramError=0 |
| 1158 | fi |
| 1159 | if [ $# -gt 3 ]; then |
| 1160 | paramError=0 |
| 1161 | fi |
| 1162 | if [ $paramError -ne 0 ]; then |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 1163 | __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1164 | return 1 |
| 1165 | fi |
| 1166 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1167 | query="/ei-producer/v1/eitypes/$2" |
| 1168 | res="$(__do_curl_to_api ECS GET $query)" |
| 1169 | status=${res:${#res}-3} |
| 1170 | |
| 1171 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1172 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1173 | return 1 |
| 1174 | fi |
| 1175 | if [ $# -gt 3 ]; then |
| 1176 | body=${res:0:${#res}-3} |
| 1177 | |
| 1178 | if [ -f $3 ]; then |
| 1179 | schema=$(cat $3) |
| 1180 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1181 | __log_test_fail_general "Job template file "$3", does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1182 | return 1 |
| 1183 | fi |
| 1184 | |
| 1185 | targetJson="" |
| 1186 | if [ $4 != "EMPTY" ]; then |
| 1187 | for pid in ${@:4} ; do |
| 1188 | if [ "$targetJson" != "" ]; then |
| 1189 | targetJson=$targetJson"," |
| 1190 | fi |
| 1191 | targetJson=$targetJson"\"$pid\"" |
| 1192 | done |
| 1193 | fi |
| 1194 | targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}" |
| 1195 | |
| 1196 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1197 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1198 | |
| 1199 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1200 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1201 | return 1 |
| 1202 | fi |
| 1203 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1204 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1205 | return 0 |
| 1206 | } |
| 1207 | |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1208 | # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId} |
| 1209 | # args: (v1_2) <response-code> <type-id> [<job-schema-file> ] |
| 1210 | # (Function for test scripts) |
| 1211 | ecs_api_edp_get_type_2() { |
| 1212 | __log_test_start $@ |
| 1213 | |
| 1214 | paramError=1 |
| 1215 | if [ $# -eq 2 ]; then |
| 1216 | paramError=0 |
| 1217 | fi |
| 1218 | if [ $# -eq 3 ]; then |
| 1219 | paramError=0 |
| 1220 | fi |
| 1221 | if [ $paramError -ne 0 ]; then |
| 1222 | __print_err "<response-code> <type-id> [<job-schema-file> ]" $@ |
| 1223 | return 1 |
| 1224 | fi |
| 1225 | |
| 1226 | query="/ei-producer/v1/eitypes/$2" |
| 1227 | res="$(__do_curl_to_api ECS GET $query)" |
| 1228 | status=${res:${#res}-3} |
| 1229 | |
| 1230 | if [ $status -ne $1 ]; then |
| 1231 | __log_test_fail_status_code $1 $status |
| 1232 | return 1 |
| 1233 | fi |
| 1234 | if [ $# -eq 3 ]; then |
| 1235 | body=${res:0:${#res}-3} |
| 1236 | |
| 1237 | if [ -f $3 ]; then |
| 1238 | schema=$(cat $3) |
| 1239 | else |
| 1240 | __log_test_fail_general "Job template file "$3", does not exist" |
| 1241 | return 1 |
| 1242 | fi |
| 1243 | |
| 1244 | targetJson="{\"ei_job_data_schema\":$schema}" |
| 1245 | |
| 1246 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1247 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1248 | |
| 1249 | if [ $res -ne 0 ]; then |
| 1250 | __log_test_fail_body |
| 1251 | return 1 |
| 1252 | fi |
| 1253 | fi |
| 1254 | __log_test_pass |
| 1255 | return 0 |
| 1256 | } |
| 1257 | |
| 1258 | # API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId} |
| 1259 | # args: (v1_2) <response-code> <type-id> <job-schema-file> |
| 1260 | # (Function for test scripts) |
| 1261 | ecs_api_edp_put_type_2() { |
| 1262 | __log_test_start $@ |
| 1263 | |
| 1264 | if [ $# -ne 3 ]; then |
| 1265 | __print_err "<response-code> <type-id> <job-schema-file>" $@ |
| 1266 | return 1 |
| 1267 | fi |
| 1268 | |
| 1269 | if [ ! -f $3 ]; then |
| 1270 | __log_test_fail_general "Job schema file "$3", does not exist" |
| 1271 | return 1 |
| 1272 | fi |
| 1273 | schema=$(cat $3) |
| 1274 | input_json="{\"ei_job_data_schema\":$schema}" |
| 1275 | file="./tmp/put_type.json" |
| 1276 | echo $input_json > $file |
| 1277 | |
| 1278 | query="/ei-producer/v1/eitypes/$2" |
| 1279 | res="$(__do_curl_to_api ECS PUT $query $file)" |
| 1280 | status=${res:${#res}-3} |
| 1281 | |
| 1282 | if [ $status -ne $1 ]; then |
| 1283 | __log_test_fail_status_code $1 $status |
| 1284 | return 1 |
| 1285 | fi |
| 1286 | |
| 1287 | __log_test_pass |
| 1288 | return 0 |
| 1289 | } |
| 1290 | |
| 1291 | # API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId} |
| 1292 | # args: (v1_2) <response-code> <type-id> |
| 1293 | # (Function for test scripts) |
| 1294 | ecs_api_edp_delete_type_2() { |
| 1295 | __log_test_start $@ |
| 1296 | |
| 1297 | if [ $# -ne 2 ]; then |
| 1298 | __print_err "<response-code> <type-id>" $@ |
| 1299 | return 1 |
| 1300 | fi |
| 1301 | |
| 1302 | query="/ei-producer/v1/eitypes/$2" |
| 1303 | res="$(__do_curl_to_api ECS DELETE $query)" |
| 1304 | status=${res:${#res}-3} |
| 1305 | |
| 1306 | if [ $status -ne $1 ]; then |
| 1307 | __log_test_fail_status_code $1 $status |
| 1308 | return 1 |
| 1309 | fi |
| 1310 | |
| 1311 | __log_test_pass |
| 1312 | return 0 |
| 1313 | } |
| 1314 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1315 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId} |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1316 | # 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] | 1317 | # (Function for test scripts) |
| 1318 | ecs_api_edp_get_producer() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1319 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1320 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1321 | #Possible arg count: 2, 5 6, 8, 10 etc |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1322 | paramError=1 |
| 1323 | if [ $# -eq 2 ]; then |
| 1324 | paramError=0 |
| 1325 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1326 | if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1327 | paramError=0 |
| 1328 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1329 | variablecount=$(($#-4)) |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1330 | if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then |
| 1331 | paramError=0 |
| 1332 | fi |
| 1333 | |
| 1334 | if [ $paramError -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1335 | __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] | 1336 | return 1 |
| 1337 | fi |
| 1338 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1339 | query="/ei-producer/v1/eiproducers/$2" |
| 1340 | res="$(__do_curl_to_api ECS GET $query)" |
| 1341 | status=${res:${#res}-3} |
| 1342 | |
| 1343 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1344 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1345 | return 1 |
| 1346 | fi |
| 1347 | |
| 1348 | if [ $# -gt 2 ]; then |
| 1349 | body=${res:0:${#res}-3} |
| 1350 | targetJson="[" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1351 | if [ $# -gt 5 ]; then |
| 1352 | arr=(${@:5}) |
| 1353 | for ((i=0; i<$(($#-5)); i=i+2)); do |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1354 | if [ "$targetJson" != "[" ]; then |
| 1355 | targetJson=$targetJson"," |
| 1356 | fi |
| 1357 | if [ -f ${arr[$i+1]} ]; then |
| 1358 | schema=$(cat ${arr[$i+1]}) |
| 1359 | else |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame^] | 1360 | __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1361 | return 1 |
| 1362 | fi |
| 1363 | |
| 1364 | targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}" |
| 1365 | done |
| 1366 | fi |
| 1367 | targetJson=$targetJson"]" |
| 1368 | if [ $# -gt 4 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1369 | 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] | 1370 | fi |
| 1371 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1372 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1373 | |
| 1374 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1375 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1376 | return 1 |
| 1377 | fi |
| 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 | |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1384 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId} |
| 1385 | # args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ] |
| 1386 | # (Function for test scripts) |
| 1387 | ecs_api_edp_get_producer_2() { |
| 1388 | __log_test_start $@ |
| 1389 | |
| 1390 | #Possible arg count: 2, 5, 6, 7, 8 etc |
| 1391 | paramError=1 |
| 1392 | if [ $# -eq 2 ]; then |
| 1393 | paramError=0 |
| 1394 | fi |
| 1395 | if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then |
| 1396 | paramError=0 |
| 1397 | fi |
| 1398 | if [ $# -ge 5 ]; then |
| 1399 | paramError=0 |
| 1400 | fi |
| 1401 | |
| 1402 | if [ $paramError -ne 0 ]; then |
| 1403 | __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@ |
| 1404 | return 1 |
| 1405 | fi |
| 1406 | |
| 1407 | query="/ei-producer/v1/eiproducers/$2" |
| 1408 | res="$(__do_curl_to_api ECS GET $query)" |
| 1409 | status=${res:${#res}-3} |
| 1410 | |
| 1411 | if [ $status -ne $1 ]; then |
| 1412 | __log_test_fail_status_code $1 $status |
| 1413 | return 1 |
| 1414 | fi |
| 1415 | |
| 1416 | if [ $# -gt 2 ]; then |
| 1417 | body=${res:0:${#res}-3} |
| 1418 | targetJson="[" |
| 1419 | if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then |
| 1420 | arr=(${@:5}) |
| 1421 | for ((i=0; i<$(($#-4)); i=i+1)); do |
| 1422 | if [ "$targetJson" != "[" ]; then |
| 1423 | targetJson=$targetJson"," |
| 1424 | fi |
| 1425 | targetJson=$targetJson"\"${arr[$i]}\"" |
| 1426 | done |
| 1427 | fi |
| 1428 | targetJson=$targetJson"]" |
| 1429 | if [ $# -gt 4 ]; then |
| 1430 | targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}" |
| 1431 | fi |
| 1432 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1433 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1434 | |
| 1435 | if [ $res -ne 0 ]; then |
| 1436 | __log_test_fail_body |
| 1437 | return 1 |
| 1438 | fi |
| 1439 | fi |
| 1440 | |
| 1441 | __log_test_pass |
| 1442 | return 0 |
| 1443 | } |
| 1444 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1445 | # API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1446 | # args: <response-code> <producer-id> |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1447 | # (Function for test scripts) |
| 1448 | ecs_api_edp_delete_producer() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1449 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1450 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1451 | if [ $# -lt 2 ]; then |
| 1452 | __print_err "<response-code> <producer-id>" $@ |
| 1453 | return 1 |
| 1454 | fi |
| 1455 | |
| 1456 | query="/ei-producer/v1/eiproducers/$2" |
| 1457 | res="$(__do_curl_to_api ECS DELETE $query)" |
| 1458 | status=${res:${#res}-3} |
| 1459 | |
| 1460 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1461 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1462 | return 1 |
| 1463 | fi |
| 1464 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1465 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1466 | return 0 |
| 1467 | } |
| 1468 | |
| 1469 | # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId} |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1470 | # 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] | 1471 | # (Function for test scripts) |
| 1472 | ecs_api_edp_put_producer() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1473 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1474 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1475 | #Valid number of parametrer 5,6,8,10, |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1476 | paramError=1 |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1477 | if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1478 | paramError=0 |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1479 | elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1480 | paramError=0 |
| 1481 | fi |
| 1482 | if [ $paramError -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1483 | __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] | 1484 | return 1 |
| 1485 | fi |
| 1486 | |
| 1487 | inputJson="[" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1488 | if [ $# -gt 5 ]; then |
| 1489 | arr=(${@:5}) |
| 1490 | for ((i=0; i<$(($#-5)); i=i+2)); do |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1491 | if [ "$inputJson" != "[" ]; then |
| 1492 | inputJson=$inputJson"," |
| 1493 | fi |
| 1494 | if [ -f ${arr[$i+1]} ]; then |
| 1495 | schema=$(cat ${arr[$i+1]}) |
| 1496 | else |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame^] | 1497 | __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1498 | return 1 |
| 1499 | fi |
| 1500 | inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}" |
| 1501 | done |
| 1502 | fi |
| 1503 | inputJson="\"supported_ei_types\":"$inputJson"]" |
| 1504 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1505 | inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1506 | |
| 1507 | inputJson="{"$inputJson"}" |
| 1508 | |
| 1509 | file="./tmp/.p.json" |
| 1510 | echo "$inputJson" > $file |
| 1511 | query="/ei-producer/v1/eiproducers/$2" |
| 1512 | res="$(__do_curl_to_api ECS PUT $query $file)" |
| 1513 | status=${res:${#res}-3} |
| 1514 | |
| 1515 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1516 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1517 | return 1 |
| 1518 | fi |
| 1519 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1520 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1521 | return 0 |
| 1522 | } |
| 1523 | |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1524 | # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId} |
| 1525 | # args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+] |
| 1526 | # (Function for test scripts) |
| 1527 | ecs_api_edp_put_producer_2() { |
| 1528 | __log_test_start $@ |
| 1529 | |
| 1530 | #Valid number of parametrer 5,6,8,10, |
| 1531 | paramError=1 |
| 1532 | if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then |
| 1533 | paramError=0 |
| 1534 | elif [ $# -ge 5 ]; then |
| 1535 | paramError=0 |
| 1536 | fi |
| 1537 | if [ $paramError -ne 0 ]; then |
| 1538 | __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@ |
| 1539 | return 1 |
| 1540 | fi |
| 1541 | |
| 1542 | inputJson="[" |
| 1543 | if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then |
| 1544 | arr=(${@:5}) |
| 1545 | for ((i=0; i<$(($#-4)); i=i+1)); do |
| 1546 | if [ "$inputJson" != "[" ]; then |
| 1547 | inputJson=$inputJson"," |
| 1548 | fi |
| 1549 | inputJson=$inputJson"\""${arr[$i]}"\"" |
| 1550 | done |
| 1551 | fi |
| 1552 | inputJson="\"supported_ei_types\":"$inputJson"]" |
| 1553 | |
| 1554 | inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"" |
| 1555 | |
| 1556 | inputJson="{"$inputJson"}" |
| 1557 | |
| 1558 | file="./tmp/.p.json" |
| 1559 | echo "$inputJson" > $file |
| 1560 | query="/ei-producer/v1/eiproducers/$2" |
| 1561 | res="$(__do_curl_to_api ECS PUT $query $file)" |
| 1562 | status=${res:${#res}-3} |
| 1563 | |
| 1564 | if [ $status -ne $1 ]; then |
| 1565 | __log_test_fail_status_code $1 $status |
| 1566 | return 1 |
| 1567 | fi |
| 1568 | |
| 1569 | __log_test_pass |
| 1570 | return 0 |
| 1571 | } |
| 1572 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1573 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 1574 | # 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] | 1575 | # (Function for test scripts) |
| 1576 | ecs_api_edp_get_producer_jobs() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1577 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1578 | |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 1579 | #Valid number of parameter 2,3,7,11 |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1580 | paramError=1 |
| 1581 | if [ $# -eq 2 ]; then |
| 1582 | paramError=0 |
| 1583 | fi |
| 1584 | if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then |
| 1585 | paramError=0 |
| 1586 | fi |
| 1587 | variablecount=$(($#-2)) |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 1588 | if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1589 | paramError=0 |
| 1590 | fi |
| 1591 | if [ $paramError -eq 1 ]; then |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 1592 | __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] | 1593 | return 1 |
| 1594 | fi |
| 1595 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1596 | query="/ei-producer/v1/eiproducers/$2/eijobs" |
| 1597 | res="$(__do_curl_to_api ECS GET $query)" |
| 1598 | status=${res:${#res}-3} |
| 1599 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1600 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1601 | return 1 |
| 1602 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1603 | if [ $# -gt 2 ]; then |
| 1604 | body=${res:0:${#res}-3} |
| 1605 | targetJson="[" |
| 1606 | if [ $# -gt 3 ]; then |
| 1607 | arr=(${@:3}) |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 1608 | for ((i=0; i<$(($#-3)); i=i+5)); do |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1609 | if [ "$targetJson" != "[" ]; then |
| 1610 | targetJson=$targetJson"," |
| 1611 | fi |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 1612 | if [ -f ${arr[$i+4]} ]; then |
| 1613 | jobfile=$(cat ${arr[$i+4]}) |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1614 | jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g") |
| 1615 | else |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame^] | 1616 | __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1617 | return 1 |
| 1618 | fi |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 1619 | 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] | 1620 | done |
| 1621 | fi |
| 1622 | targetJson=$targetJson"]" |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1623 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1624 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1625 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1626 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1627 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1628 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1629 | return 1 |
| 1630 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1631 | fi |
| 1632 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1633 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1634 | return 0 |
| 1635 | } |
| 1636 | |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 1637 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs |
| 1638 | # args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+) |
| 1639 | # (Function for test scripts) |
| 1640 | ecs_api_edp_get_producer_jobs_2() { |
| 1641 | __log_test_start $@ |
| 1642 | |
| 1643 | #Valid number of parameter 2,3,7,11 |
| 1644 | paramError=1 |
| 1645 | if [ $# -eq 2 ]; then |
| 1646 | paramError=0 |
| 1647 | fi |
| 1648 | if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then |
| 1649 | paramError=0 |
| 1650 | fi |
| 1651 | variablecount=$(($#-2)) |
| 1652 | if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then |
| 1653 | paramError=0 |
| 1654 | fi |
| 1655 | if [ $paramError -eq 1 ]; then |
| 1656 | __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@ |
| 1657 | return 1 |
| 1658 | fi |
| 1659 | |
| 1660 | query="/ei-producer/v1/eiproducers/$2/eijobs" |
| 1661 | res="$(__do_curl_to_api ECS GET $query)" |
| 1662 | status=${res:${#res}-3} |
| 1663 | if [ $status -ne $1 ]; then |
| 1664 | __log_test_fail_status_code $1 $status |
| 1665 | return 1 |
| 1666 | fi |
| 1667 | if [ $# -gt 2 ]; then |
| 1668 | body=${res:0:${#res}-3} |
| 1669 | targetJson="[" |
| 1670 | if [ $# -gt 3 ]; then |
| 1671 | arr=(${@:3}) |
| 1672 | for ((i=0; i<$(($#-3)); i=i+5)); do |
| 1673 | if [ "$targetJson" != "[" ]; then |
| 1674 | targetJson=$targetJson"," |
| 1675 | fi |
| 1676 | if [ -f ${arr[$i+4]} ]; then |
| 1677 | jobfile=$(cat ${arr[$i+4]}) |
| 1678 | jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g") |
| 1679 | else |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame^] | 1680 | __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist" |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 1681 | return 1 |
| 1682 | fi |
| 1683 | 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\":\"????\"}" |
| 1684 | done |
| 1685 | fi |
| 1686 | targetJson=$targetJson"]" |
| 1687 | |
| 1688 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1689 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1690 | |
| 1691 | if [ $res -ne 0 ]; then |
| 1692 | __log_test_fail_body |
| 1693 | return 1 |
| 1694 | fi |
| 1695 | fi |
| 1696 | |
| 1697 | __log_test_pass |
| 1698 | return 0 |
| 1699 | } |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1700 | |
| 1701 | ########################################## |
| 1702 | #### Service status #### |
| 1703 | ########################################## |
| 1704 | # Function prefix: ecs_api_service |
| 1705 | |
| 1706 | # API Test function: GET /status |
| 1707 | # args: <response-code> |
| 1708 | # (Function for test scripts) |
| 1709 | ecs_api_service_status() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1710 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1711 | |
| 1712 | if [ $# -lt 1 ]; then |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame^] | 1713 | __print_err "<response-code>" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1714 | return 1 |
| 1715 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1716 | res="$(__do_curl_to_api ECS GET /status)" |
| 1717 | status=${res:${#res}-3} |
| 1718 | if [ $status -ne $1 ]; then |
| 1719 | __log_test_fail_status_code $1 $status |
| 1720 | return 1 |
| 1721 | fi |
| 1722 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1723 | return 0 |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 1724 | } |
| 1725 | |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame^] | 1726 | ########################################### |
| 1727 | ######### Info data consumer API ########## |
| 1728 | ########################################### |
| 1729 | #Function prefix: ecs_api_idc |
| 1730 | |
| 1731 | |
| 1732 | # API Test function: GET /data-consumer/v1/info-types |
| 1733 | # args: <response-code> [ (EMPTY | [<type-id>]+) ] |
| 1734 | # (Function for test scripts) |
| 1735 | ecs_api_idc_get_type_ids() { |
| 1736 | __log_test_start $@ |
| 1737 | |
| 1738 | if [ $# -lt 1 ]; then |
| 1739 | __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@ |
| 1740 | return 1 |
| 1741 | fi |
| 1742 | |
| 1743 | query="/data-consumer/v1/info-types" |
| 1744 | res="$(__do_curl_to_api ECS GET $query)" |
| 1745 | status=${res:${#res}-3} |
| 1746 | |
| 1747 | if [ $status -ne $1 ]; then |
| 1748 | __log_test_fail_status_code $1 $status |
| 1749 | return 1 |
| 1750 | fi |
| 1751 | if [ $# -gt 1 ]; then |
| 1752 | body=${res:0:${#res}-3} |
| 1753 | targetJson="[" |
| 1754 | if [ $2 != "EMPTY" ]; then |
| 1755 | for pid in ${@:2} ; do |
| 1756 | if [ "$targetJson" != "[" ]; then |
| 1757 | targetJson=$targetJson"," |
| 1758 | fi |
| 1759 | targetJson=$targetJson"\"$pid\"" |
| 1760 | done |
| 1761 | fi |
| 1762 | targetJson=$targetJson"]" |
| 1763 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1764 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1765 | |
| 1766 | if [ $res -ne 0 ]; then |
| 1767 | __log_test_fail_body |
| 1768 | return 1 |
| 1769 | fi |
| 1770 | fi |
| 1771 | |
| 1772 | __log_test_pass |
| 1773 | return 0 |
| 1774 | } |
| 1775 | |
| 1776 | # API Test function: GET /data-consumer/v1/info-jobs |
| 1777 | # args: <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ] |
| 1778 | # (Function for test scripts) |
| 1779 | ecs_api_idc_get_job_ids() { |
| 1780 | __log_test_start $@ |
| 1781 | |
| 1782 | # Valid number of parameters 4,5,6 etc |
| 1783 | if [ $# -lt 3 ]; then |
| 1784 | __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@ |
| 1785 | return 1 |
| 1786 | fi |
| 1787 | search="" |
| 1788 | if [ $3 != "NOWNER" ]; then |
| 1789 | search="?owner="$3 |
| 1790 | fi |
| 1791 | |
| 1792 | if [ $2 != "NOTYPE" ]; then |
| 1793 | if [ -z "$search" ]; then |
| 1794 | search="?infoTypeId="$2 |
| 1795 | else |
| 1796 | search=$search"&infoTypeId="$2 |
| 1797 | fi |
| 1798 | fi |
| 1799 | query="/data-consumer/v1/info-jobs$search" |
| 1800 | |
| 1801 | res="$(__do_curl_to_api ECS GET $query)" |
| 1802 | status=${res:${#res}-3} |
| 1803 | |
| 1804 | if [ $status -ne $1 ]; then |
| 1805 | __log_test_fail_status_code $1 $status |
| 1806 | return 1 |
| 1807 | fi |
| 1808 | |
| 1809 | if [ $# -gt 3 ]; then |
| 1810 | body=${res:0:${#res}-3} |
| 1811 | targetJson="[" |
| 1812 | |
| 1813 | for pid in ${@:4} ; do |
| 1814 | if [ "$targetJson" != "[" ]; then |
| 1815 | targetJson=$targetJson"," |
| 1816 | fi |
| 1817 | if [ $pid != "EMPTY" ]; then |
| 1818 | targetJson=$targetJson"\"$pid\"" |
| 1819 | fi |
| 1820 | done |
| 1821 | |
| 1822 | targetJson=$targetJson"]" |
| 1823 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1824 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1825 | |
| 1826 | if [ $res -ne 0 ]; then |
| 1827 | __log_test_fail_body |
| 1828 | return 1 |
| 1829 | fi |
| 1830 | fi |
| 1831 | |
| 1832 | __log_test_pass |
| 1833 | return 0 |
| 1834 | } |
| 1835 | |
| 1836 | # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId} |
| 1837 | # args: <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>] |
| 1838 | # (Function for test scripts) |
| 1839 | ecs_api_idc_get_job() { |
| 1840 | __log_test_start $@ |
| 1841 | |
| 1842 | if [ $# -ne 2 ] && [ $# -ne 7 ]; then |
| 1843 | __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@ |
| 1844 | return 1 |
| 1845 | fi |
| 1846 | query="/data-consumer/v1/info-jobs/$2" |
| 1847 | res="$(__do_curl_to_api ECS GET $query)" |
| 1848 | status=${res:${#res}-3} |
| 1849 | |
| 1850 | if [ $status -ne $1 ]; then |
| 1851 | __log_test_fail_status_code $1 $status |
| 1852 | return 1 |
| 1853 | fi |
| 1854 | |
| 1855 | if [ $# -eq 7 ]; then |
| 1856 | body=${res:0:${#res}-3} |
| 1857 | |
| 1858 | if [ -f $7 ]; then |
| 1859 | jobfile=$(cat $7) |
| 1860 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g") |
| 1861 | else |
| 1862 | __log_test_fail_general "Job template file "$6", does not exist" |
| 1863 | return 1 |
| 1864 | fi |
| 1865 | targetJson="{\"infoTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}" |
| 1866 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1867 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1868 | |
| 1869 | if [ $res -ne 0 ]; then |
| 1870 | __log_test_fail_body |
| 1871 | return 1 |
| 1872 | fi |
| 1873 | fi |
| 1874 | |
| 1875 | __log_test_pass |
| 1876 | return 0 |
| 1877 | } |
| 1878 | |
| 1879 | |
| 1880 | # API Test function: PUT /data-consumer/v1/info-jobs/{infoJobId} |
| 1881 | # args: <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ] |
| 1882 | # (Function for test scripts) |
| 1883 | ecs_api_idc_put_job() { |
| 1884 | __log_test_start $@ |
| 1885 | |
| 1886 | if [ $# -lt 7 ] || [ $# -gt 8 ]; then |
| 1887 | __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]" $@ |
| 1888 | return 1 |
| 1889 | fi |
| 1890 | if [ -f $7 ]; then |
| 1891 | jobfile=$(cat $7) |
| 1892 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g") |
| 1893 | else |
| 1894 | __log_test_fail_general "Job template file "$7", does not exist" |
| 1895 | return 1 |
| 1896 | fi |
| 1897 | |
| 1898 | inputJson="{\"infoTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}" |
| 1899 | file="./tmp/.p.json" |
| 1900 | echo "$inputJson" > $file |
| 1901 | |
| 1902 | query="/data-consumer/v1/info-jobs/$2" |
| 1903 | |
| 1904 | if [ $# -eq 8 ]; then |
| 1905 | if [ $8 == "VALIDATE" ]; then |
| 1906 | query=$query"?typeCheck=true" |
| 1907 | fi |
| 1908 | fi |
| 1909 | |
| 1910 | res="$(__do_curl_to_api ECS PUT $query $file)" |
| 1911 | status=${res:${#res}-3} |
| 1912 | |
| 1913 | if [ $status -ne $1 ]; then |
| 1914 | __log_test_fail_status_code $1 $status |
| 1915 | return 1 |
| 1916 | fi |
| 1917 | |
| 1918 | __log_test_pass |
| 1919 | return 0 |
| 1920 | } |
| 1921 | |
| 1922 | # API Test function: DELETE /data-consumer/v1/info-jobs/{infoJobId} |
| 1923 | # args: <response-code> <job-id> |
| 1924 | # (Function for test scripts) |
| 1925 | ecs_api_idc_delete_job() { |
| 1926 | __log_test_start $@ |
| 1927 | |
| 1928 | if [ $# -ne 2 ]; then |
| 1929 | __print_err "<response-code> <job-id>" $@ |
| 1930 | return 1 |
| 1931 | fi |
| 1932 | query="/data-consumer/v1/info-jobs/$2" |
| 1933 | res="$(__do_curl_to_api ECS DELETE $query)" |
| 1934 | status=${res:${#res}-3} |
| 1935 | |
| 1936 | if [ $status -ne $1 ]; then |
| 1937 | __log_test_fail_status_code $1 $status |
| 1938 | return 1 |
| 1939 | fi |
| 1940 | |
| 1941 | __log_test_pass |
| 1942 | return 0 |
| 1943 | } |
| 1944 | |
| 1945 | # API Test function: GET /data-consumer/v1/info-types/{infoTypeId} |
| 1946 | # args: <response-code> <type-id> [<schema-file>] |
| 1947 | # (Function for test scripts) |
| 1948 | ecs_api_idc_get_type() { |
| 1949 | __log_test_start $@ |
| 1950 | |
| 1951 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 1952 | __print_err "<response-code> <type-id> [<schema-file>]" $@ |
| 1953 | return 1 |
| 1954 | fi |
| 1955 | |
| 1956 | query="/data-consumer/v1/info-types/$2" |
| 1957 | res="$(__do_curl_to_api ECS GET $query)" |
| 1958 | status=${res:${#res}-3} |
| 1959 | |
| 1960 | if [ $status -ne $1 ]; then |
| 1961 | __log_test_fail_status_code $1 $status |
| 1962 | return 1 |
| 1963 | fi |
| 1964 | |
| 1965 | if [ $# -eq 3 ]; then |
| 1966 | body=${res:0:${#res}-3} |
| 1967 | if [ -f $3 ]; then |
| 1968 | schema=$(cat $3) |
| 1969 | else |
| 1970 | __log_test_fail_general "Schema file "$3", does not exist" |
| 1971 | return 1 |
| 1972 | fi |
| 1973 | targetJson="{\"consumer_job_data_schema\":$schema}" |
| 1974 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1975 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1976 | |
| 1977 | if [ $res -ne 0 ]; then |
| 1978 | __log_test_fail_body |
| 1979 | return 1 |
| 1980 | fi |
| 1981 | fi |
| 1982 | |
| 1983 | __log_test_pass |
| 1984 | return 0 |
| 1985 | } |
| 1986 | |
| 1987 | # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status |
| 1988 | # args: <response-code> <job-id> [<status> [<timeout>]] |
| 1989 | # (Function for test scripts) |
| 1990 | ecs_api_idc_get_job_status() { |
| 1991 | __log_test_start $@ |
| 1992 | |
| 1993 | if [ $# -lt 2 ] && [ $# -gt 4 ]; then |
| 1994 | __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@ |
| 1995 | return 1 |
| 1996 | fi |
| 1997 | |
| 1998 | query="/data-consumer/v1/info-jobs/$2/status" |
| 1999 | |
| 2000 | start=$SECONDS |
| 2001 | for (( ; ; )); do |
| 2002 | res="$(__do_curl_to_api ECS GET $query)" |
| 2003 | status=${res:${#res}-3} |
| 2004 | |
| 2005 | if [ $# -eq 4 ]; then |
| 2006 | duration=$((SECONDS-start)) |
| 2007 | echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}" |
| 2008 | if [ $duration -gt $4 ]; then |
| 2009 | echo "" |
| 2010 | duration=-1 #Last iteration |
| 2011 | fi |
| 2012 | else |
| 2013 | duration=-1 #single test, no wait |
| 2014 | fi |
| 2015 | |
| 2016 | if [ $status -ne $1 ]; then |
| 2017 | if [ $duration -eq -1 ]; then |
| 2018 | __log_test_fail_status_code $1 $status |
| 2019 | return 1 |
| 2020 | fi |
| 2021 | fi |
| 2022 | if [ $# -ge 3 ] && [ $status -eq $1 ]; then |
| 2023 | body=${res:0:${#res}-3} |
| 2024 | targetJson="{\"eiJobStatus\": \"$3\"}" |
| 2025 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 2026 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 2027 | |
| 2028 | if [ $res -ne 0 ]; then |
| 2029 | if [ $duration -eq -1 ]; then |
| 2030 | __log_test_fail_body |
| 2031 | return 1 |
| 2032 | fi |
| 2033 | else |
| 2034 | duration=-1 #Goto pass |
| 2035 | fi |
| 2036 | fi |
| 2037 | if [ $duration -eq -1 ]; then |
| 2038 | if [ $# -eq 4 ]; then |
| 2039 | echo "" |
| 2040 | fi |
| 2041 | __log_test_pass |
| 2042 | return 0 |
| 2043 | else |
| 2044 | sleep 1 |
| 2045 | fi |
| 2046 | done |
| 2047 | |
| 2048 | __log_test_pass |
| 2049 | return 0 |
| 2050 | } |
| 2051 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 2052 | |
| 2053 | ########################################## |
| 2054 | #### Reset jobs #### |
| 2055 | ########################################## |
| 2056 | # Function prefix: ecs_api_admin |
| 2057 | |
| 2058 | # Admin to remove all jobs |
BjornMagnussonXA | 366e36a | 2021-01-27 11:48:56 +0100 | [diff] [blame] | 2059 | # args: <response-code> [ <type> ] |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 2060 | # (Function for test scripts) |
| 2061 | |
| 2062 | ecs_api_admin_reset() { |
| 2063 | __log_test_start $@ |
| 2064 | |
| 2065 | if [ -z "$FLAT_A1_EI" ]; then |
| 2066 | query="/A1-EI/v1/eitypes/$2/eijobs" |
| 2067 | else |
| 2068 | query="/A1-EI/v1/eijobs" |
| 2069 | fi |
| 2070 | res="$(__do_curl_to_api ECS GET $query)" |
| 2071 | status=${res:${#res}-3} |
| 2072 | |
| 2073 | if [ $status -ne 200 ]; then |
| 2074 | __log_test_fail_status_code $1 $status |
| 2075 | return 1 |
| 2076 | fi |
| 2077 | |
| 2078 | #Remove brackets and response code |
| 2079 | body=${res:1:${#res}-4} |
| 2080 | list=$(echo ${body//,/ }) |
| 2081 | list=$(echo ${list//[/}) |
| 2082 | list=$(echo ${list//]/}) |
| 2083 | list=$(echo ${list//\"/}) |
| 2084 | list=$list" " |
| 2085 | for job in $list; do |
| 2086 | if [ -z "$FLAT_A1_EI" ]; then |
| 2087 | echo "Not supported for non-flat EI api" |
| 2088 | else |
| 2089 | query="/A1-EI/v1/eijobs/$job" |
| 2090 | res="$(__do_curl_to_api ECS DELETE $query)" |
| 2091 | status=${res:${#res}-3} |
| 2092 | if [ $status -ne 204 ]; then |
| 2093 | __log_test_fail_status_code $1 $status |
| 2094 | return 1 |
| 2095 | fi |
| 2096 | echo " Deleted job: "$job |
| 2097 | fi |
| 2098 | done |
| 2099 | |
| 2100 | __log_test_pass |
| 2101 | return 0 |
BjornMagnussonXA | a549157 | 2021-05-04 09:21:24 +0200 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | ########################################## |
| 2105 | #### Reset jobs and producers #### |
| 2106 | ########################################## |
| 2107 | |
| 2108 | |
| 2109 | # Admin reset to remove all data in ecs; jobs, producers etc |
| 2110 | # NOTE - only works in kubernetes and the pod should not be running |
| 2111 | # args: - |
| 2112 | # (Function for test scripts) |
| 2113 | |
| 2114 | ecs_kube_pvc_reset() { |
| 2115 | __log_test_start $@ |
| 2116 | |
| 2117 | __kube_clean_pvc $ECS_APP_NAME nonrtric enrichmentservice-pvc /var/enrichment-coordinator-service/database |
| 2118 | |
| 2119 | __log_test_pass |
| 2120 | return 0 |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 2121 | } |