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 | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 20 | # This is a script that contains container/service management functions and test functions for ICS |
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 |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 27 | __ICS_imagesetup() { |
| 28 | __check_and_create_image_var ICS "ICS_IMAGE" "ICS_IMAGE_BASE" "ICS_IMAGE_TAG" $1 "$ICS_DISPLAY_NAME" |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 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' |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 36 | __ICS_imagepull() { |
| 37 | __check_and_pull_image $1 "$ICS_DISPLAY_NAME" $ICS_APP_NAME ICS_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 |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 43 | __ICS_imagebuild() { |
| 44 | echo -e $RED" Image for app ICS shall never be built"$ERED |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 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> |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 50 | __ICS_image_data() { |
| 51 | echo -e "$ICS_DISPLAY_NAME\t$(docker images --format $1 $ICS_IMAGE)" >> $2 |
| 52 | if [ ! -z "$ICS_IMAGE_SOURCE" ]; then |
| 53 | echo -e "-- source image --\t$(docker images --format $1 $ICS_IMAGE_SOURCE)" >> $2 |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame] | 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 |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 60 | __ICS_kube_scale_zero() { |
| 61 | __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ICS |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 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. |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 66 | __ICS_kube_scale_zero_and_wait() { |
| 67 | __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app "$KUBE_NONRTRIC_NAMESPACE"-informationservice |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | # Delete all kube resouces for the app |
| 71 | # This function is called for apps managed by the test script. |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 72 | __ICS_kube_delete_all() { |
| 73 | __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ICS |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | # Store docker logs |
| 77 | # This function is called for apps managed by the test script. |
| 78 | # args: <log-dir> <file-prexix> |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 79 | __ICS_store_docker_logs() { |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 80 | if [ $RUNMODE == "KUBE" ]; then |
BjornMagnussonXA | cb6113e | 2022-02-17 15:01:28 +0100 | [diff] [blame] | 81 | kubectl $KUBECONF logs -l "autotest=ICS" -n $KUBE_NONRTRIC_NAMESPACE --tail=-1 > $1$2_ics.log 2>&1 |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 82 | else |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 83 | docker logs $ICS_APP_NAME > $1$2_ics.log 2>&1 |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 84 | fi |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 85 | } |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 86 | |
| 87 | # Initial setup of protocol, host and ports |
| 88 | # This function is called for apps managed by the test script. |
| 89 | # args: - |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 90 | __ICS_initial_setup() { |
| 91 | use_ics_rest_http |
BjornMagnussonXA | 145762b | 2022-03-22 10:35:10 +0100 | [diff] [blame^] | 92 | export ICS_SIDECAR_JWT_FILE="" |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 93 | } |
| 94 | |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 95 | # Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers |
| 96 | # For docker, the namespace shall be excluded |
| 97 | # This function is called for apps managed by the test script as well as for prestarted apps. |
| 98 | # args: - |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 99 | __ICS_statisics_setup() { |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 100 | if [ $RUNMODE == "KUBE" ]; then |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 101 | echo "ICS $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE" |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 102 | else |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 103 | echo "ICS $ICS_APP_NAME" |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 104 | fi |
| 105 | } |
| 106 | |
BjornMagnussonXA | e60d04e | 2021-12-27 13:38:01 +0100 | [diff] [blame] | 107 | # Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied |
| 108 | # args: - |
| 109 | __ICS_test_requirements() { |
| 110 | : |
| 111 | } |
| 112 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 113 | ####################################################### |
| 114 | |
| 115 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 116 | # Make curl retries towards ICS for http response codes set in this env var, space separated list of codes |
| 117 | ICS_RETRY_CODES="" |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 118 | |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 119 | #Save first worker node the pod is started on |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 120 | __ICS_WORKER_NODE="" |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 121 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 122 | ########################### |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 123 | ### ICS functions |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 124 | ########################### |
| 125 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 126 | # All calls to ICS will be directed to the ICS REST interface from now on |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 127 | # args: - |
| 128 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 129 | use_ics_rest_http() { |
| 130 | __ics_set_protocoll "http" $ICS_INTERNAL_PORT $ICS_EXTERNAL_PORT |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 131 | } |
| 132 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 133 | # All calls to ICS will be directed to the ICS REST interface from now on |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 134 | # args: - |
| 135 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 136 | use_ics_rest_https() { |
| 137 | __ics_set_protocoll "https" $ICS_INTERNAL_SECURE_PORT $ICS_EXTERNAL_SECURE_PORT |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 138 | } |
| 139 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 140 | # All calls to ICS will be directed to the ICS dmaap interface over http from now on |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 141 | # args: - |
| 142 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 143 | use_ics_dmaap_http() { |
| 144 | echo -e $BOLD"ICS dmaap protocol setting"$EBOLD |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 145 | echo -e $RED" - NOT SUPPORTED - "$ERED |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 146 | echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ICS" |
| 147 | ICS_ADAPTER_TYPE="MR-HTTP" |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 148 | echo "" |
| 149 | } |
| 150 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 151 | # Setup paths to svc/container for internal and external access |
| 152 | # args: <protocol> <internal-port> <external-port> |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 153 | __ics_set_protocoll() { |
| 154 | echo -e $BOLD"$ICS_DISPLAY_NAME protocol setting"$EBOLD |
| 155 | echo -e " Using $BOLD $1 $EBOLD towards $ICS_DISPLAY_NAME" |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 156 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 157 | ## Access to ICS |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 158 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 159 | ICS_SERVICE_PATH=$1"://"$ICS_APP_NAME":"$2 # docker access, container->container and script->container via proxy |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 160 | if [ $RUNMODE == "KUBE" ]; then |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 161 | ICS_SERVICE_PATH=$1"://"$ICS_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 162 | fi |
| 163 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 164 | # ICS_ADAPTER used for switching between REST and DMAAP (only REST supported currently) |
| 165 | ICS_ADAPTER_TYPE="REST" |
| 166 | ICS_ADAPTER=$ICS_SERVICE_PATH |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 167 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 168 | echo "" |
| 169 | } |
| 170 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 171 | # Export env vars for config files, docker compose and kube resources |
| 172 | # args: PROXY|NOPROXY |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 173 | __ics_export_vars() { |
| 174 | export ICS_APP_NAME |
| 175 | export ICS_APP_NAME_ALIAS |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 176 | export KUBE_NONRTRIC_NAMESPACE |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 177 | export ICS_IMAGE |
| 178 | export ICS_INTERNAL_PORT |
| 179 | export ICS_INTERNAL_SECURE_PORT |
| 180 | export ICS_EXTERNAL_PORT |
| 181 | export ICS_EXTERNAL_SECURE_PORT |
| 182 | export ICS_CONFIG_MOUNT_PATH |
| 183 | export ICS_CONFIG_CONFIGMAP_NAME=$ICS_APP_NAME"-config" |
| 184 | export ICS_DATA_CONFIGMAP_NAME=$ICS_APP_NAME"-data" |
| 185 | export ICS_CONTAINER_MNT_DIR |
| 186 | export ICS_HOST_MNT_DIR |
| 187 | export ICS_CONFIG_FILE |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 188 | export DOCKER_SIM_NWNAME |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 189 | export ICS_DISPLAY_NAME |
BjornMagnussonXA | 05bfe48 | 2021-12-02 08:47:41 +0100 | [diff] [blame] | 190 | export ICS_LOGPATH |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 191 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 192 | export ICS_DATA_PV_NAME=$ICS_APP_NAME"-pv" |
| 193 | export ICS_DATA_PVC_NAME=$ICS_APP_NAME"-pvc" |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 194 | #Create a unique path for the pv each time to prevent a previous volume to be reused |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 195 | export ICS_PV_PATH="icsdata-"$(date +%s) |
BjornMagnussonXA | c8f92e9 | 2022-02-28 15:16:37 +0100 | [diff] [blame] | 196 | export HOST_PATH_BASE_DIR |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 197 | |
| 198 | if [ $1 == "PROXY" ]; then |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 199 | export ICS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started |
| 200 | export ICS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started |
| 201 | if [ $ICS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ICS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 202 | echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW |
| 203 | else |
| 204 | echo " Configured with http proxy" |
| 205 | fi |
| 206 | else |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 207 | export ICS_HTTP_PROXY_CONFIG_PORT=0 |
| 208 | export ICS_HTTP_PROXY_CONFIG_HOST_NAME="" |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 209 | echo " Configured without http proxy" |
| 210 | fi |
| 211 | } |
| 212 | |
| 213 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 214 | # Start the ICS |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 215 | # args: PROXY|NOPROXY <config-file> |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 216 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 217 | start_ics() { |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 218 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 219 | echo -e $BOLD"Starting $ICS_DISPLAY_NAME"$EBOLD |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 220 | |
| 221 | if [ $RUNMODE == "KUBE" ]; then |
| 222 | |
| 223 | # Check if app shall be fully managed by the test script |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 224 | __check_included_image "ICS" |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 225 | retcode_i=$? |
| 226 | |
| 227 | # Check if app shall only be used by the testscipt |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 228 | __check_prestarted_image "ICS" |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 229 | retcode_p=$? |
| 230 | |
| 231 | if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 232 | echo -e $RED"The $ICS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED |
| 233 | echo -e $RED"The $ICS_APP_NAME will not be started"$ERED |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 234 | exit |
| 235 | fi |
| 236 | if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 237 | echo -e $RED"The $ICS_APP_NAME app is included both as managed and prestarted in this test script"$ERED |
| 238 | echo -e $RED"The $ICS_APP_NAME will not be started"$ERED |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 239 | exit |
| 240 | fi |
| 241 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 242 | if [ $retcode_p -eq 0 ]; then |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 243 | echo -e " Using existing $ICS_APP_NAME deployment and service" |
| 244 | echo " Setting ICS replicas=1" |
| 245 | res_type=$(__kube_get_resource_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE) |
| 246 | __kube_scale $res_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1 |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 247 | fi |
| 248 | |
| 249 | # Check if app shall be fully managed by the test script |
| 250 | if [ $retcode_i -eq 0 ]; then |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 251 | echo -e " Creating $ICS_APP_NAME app and expose service" |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 252 | |
| 253 | #Check if nonrtric namespace exists, if not create it |
| 254 | __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE |
| 255 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 256 | __ics_export_vars $1 |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 257 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 258 | # Create config map for config |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 259 | datafile=$PWD/tmp/$ICS_CONFIG_FILE |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 260 | cp $2 $datafile |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 261 | output_yaml=$PWD/tmp/ics_cfc.yaml |
| 262 | __kube_create_configmap $ICS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ICS $datafile $output_yaml |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 263 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 264 | # Create pv |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 265 | input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"pv.yaml |
| 266 | output_yaml=$PWD/tmp/ics_pv.yaml |
| 267 | __kube_create_instance pv $ICS_APP_NAME $input_yaml $output_yaml |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 268 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 269 | # Create pvc |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 270 | input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"pvc.yaml |
| 271 | output_yaml=$PWD/tmp/ics_pvc.yaml |
| 272 | __kube_create_instance pvc $ICS_APP_NAME $input_yaml $output_yaml |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 273 | |
| 274 | # Create service |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 275 | input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"svc.yaml |
| 276 | output_yaml=$PWD/tmp/ics_svc.yaml |
| 277 | __kube_create_instance service $ICS_APP_NAME $input_yaml $output_yaml |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 278 | |
| 279 | # Create app |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 280 | input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"app.yaml |
| 281 | output_yaml=$PWD/tmp/ics_app.yaml |
BjornMagnussonXA | 145762b | 2022-03-22 10:35:10 +0100 | [diff] [blame^] | 282 | if [ -z "$ICS_SIDECAR_JWT_FILE" ]; then |
| 283 | cat $input_yaml | sed '/#ICS_JWT_START/,/#ICS_JWT_STOP/d' > $PWD/tmp/ics_app_tmp.yaml |
| 284 | input_yaml=$PWD/tmp/ics_app_tmp.yaml |
| 285 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 286 | __kube_create_instance app $ICS_APP_NAME $input_yaml $output_yaml |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 287 | fi |
| 288 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 289 | # Tie the ICS to a worker node so that ICS will always be scheduled to the same worker node if the ICS pod is restarted |
| 290 | # A PVC of type hostPath is mounted to ICS, for persistent storage, so the ICS must always be on the node which mounted the volume |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 291 | |
| 292 | # 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] | 293 | if [ $retcode_i -eq 0 ]; then |
BjornMagnussonXA | c8f92e9 | 2022-02-28 15:16:37 +0100 | [diff] [blame] | 294 | __ICS_WORKER_NODE=$(kubectl $KUBECONF get pod -l "autotest=ICS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}') |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 295 | if [ -z "$__ICS_WORKER_NODE" ]; then |
| 296 | echo -e $YELLOW" Cannot find worker node for pod for $ICS_APP_NAME, persistency may not work"$EYELLOW |
BjornMagnussonXA | a549157 | 2021-05-04 09:21:24 +0200 | [diff] [blame] | 297 | fi |
| 298 | else |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 299 | echo -e $YELLOW" Persistency may not work for app $ICS_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] | 300 | fi |
| 301 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 302 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 303 | __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 304 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 305 | else |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 306 | __check_included_image 'ICS' |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 307 | if [ $? -eq 1 ]; then |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 308 | echo -e $RED"The ICS app is not included in this test script"$ERED |
| 309 | echo -e $RED"ICS will not be started"$ERED |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 310 | exit 1 |
| 311 | fi |
| 312 | |
| 313 | curdir=$PWD |
| 314 | cd $SIM_GROUP |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 315 | cd ics |
| 316 | cd $ICS_HOST_MNT_DIR |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 317 | #cd .. |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 318 | if [ -d db ]; then |
| 319 | if [ "$(ls -A $DIR)" ]; then |
| 320 | echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD |
| 321 | rm -rf db/* &> /dev/null |
| 322 | if [ $? -ne 0 ]; then |
| 323 | echo -e $RED" Cannot remove database files in: $PWD"$ERED |
| 324 | exit 1 |
| 325 | fi |
| 326 | fi |
| 327 | else |
| 328 | echo " No files in mounted dir or dir does not exists" |
| 329 | fi |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 330 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 331 | cd $curdir |
| 332 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 333 | __ics_export_vars $1 |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 334 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 335 | dest_file=$SIM_GROUP/$ICS_COMPOSE_DIR/$ICS_HOST_MNT_DIR/$ICS_CONFIG_FILE |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 336 | |
| 337 | envsubst < $2 > $dest_file |
| 338 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 339 | __start_container $ICS_COMPOSE_DIR "" NODOCKERARGS 1 $ICS_APP_NAME |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 340 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 341 | __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 342 | fi |
| 343 | echo "" |
| 344 | return 0 |
| 345 | } |
| 346 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 347 | # Stop the ics |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 348 | # args: - |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 349 | # args: - |
| 350 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 351 | stop_ics() { |
| 352 | echo -e $BOLD"Stopping $ICS_DISPLAY_NAME"$EBOLD |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 353 | |
| 354 | if [ $RUNMODE == "KUBE" ]; then |
BjornMagnussonXA | a549157 | 2021-05-04 09:21:24 +0200 | [diff] [blame] | 355 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 356 | __check_prestarted_image "ICS" |
BjornMagnussonXA | a549157 | 2021-05-04 09:21:24 +0200 | [diff] [blame] | 357 | if [ $? -eq 0 ]; then |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 358 | echo -e $YELLOW" Persistency may not work for app $ICS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW |
| 359 | res_type=$(__kube_get_resource_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE) |
| 360 | __kube_scale $res_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0 |
BjornMagnussonXA | a549157 | 2021-05-04 09:21:24 +0200 | [diff] [blame] | 361 | return 0 |
| 362 | fi |
| 363 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 364 | __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ICS |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 365 | echo " Deleting the replica set - a new will be started when the app is started" |
BjornMagnussonXA | cb6113e | 2022-02-17 15:01:28 +0100 | [diff] [blame] | 366 | tmp=$(kubectl $KUBECONF delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=ICS") |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 367 | if [ $? -ne 0 ]; then |
| 368 | echo -e $RED" Could not delete replica set "$RED |
| 369 | ((RES_CONF_FAIL++)) |
| 370 | return 1 |
| 371 | fi |
| 372 | else |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 373 | docker stop $ICS_APP_NAME &> ./tmp/.dockererr |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 374 | if [ $? -ne 0 ]; then |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 375 | __print_err "Could not stop $ICS_APP_NAME" $@ |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 376 | cat ./tmp/.dockererr |
| 377 | ((RES_CONF_FAIL++)) |
| 378 | return 1 |
| 379 | fi |
| 380 | fi |
| 381 | echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD |
| 382 | echo "" |
| 383 | return 0 |
| 384 | } |
| 385 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 386 | # Start a previously stopped ics |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 387 | # args: - |
| 388 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 389 | start_stopped_ics() { |
| 390 | echo -e $BOLD"Starting (the previously stopped) $ICS_DISPLAY_NAME"$EBOLD |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 391 | |
| 392 | if [ $RUNMODE == "KUBE" ]; then |
| 393 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 394 | __check_prestarted_image "ICS" |
BjornMagnussonXA | a549157 | 2021-05-04 09:21:24 +0200 | [diff] [blame] | 395 | if [ $? -eq 0 ]; then |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 396 | echo -e $YELLOW" Persistency may not work for app $ICS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW |
| 397 | res_type=$(__kube_get_resource_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE) |
| 398 | __kube_scale $res_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1 |
| 399 | __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL |
BjornMagnussonXA | a549157 | 2021-05-04 09:21:24 +0200 | [diff] [blame] | 400 | return 0 |
| 401 | fi |
| 402 | |
BjornMagnussonXA | c8f92e9 | 2022-02-28 15:16:37 +0100 | [diff] [blame] | 403 | # Tie the ICS to the same worker node it was initially started on |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 404 | # A PVC of type hostPath is mounted to A1PMS, for persistent storage, so the A1PMS must always be on the node which mounted the volume |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 405 | if [ -z "$__ICS_WORKER_NODE" ]; then |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 406 | echo -e $RED" No initial worker node found for pod "$RED |
| 407 | ((RES_CONF_FAIL++)) |
| 408 | return 1 |
| 409 | else |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 410 | echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__ICS_WORKER_NODE to deployment for $ICS_APP_NAME. Pod will always run on this worker node: $__ICS_WORKER_NODE"$BOLD |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 411 | echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD |
BjornMagnussonXA | cb6113e | 2022-02-17 15:01:28 +0100 | [diff] [blame] | 412 | tmp=$(kubectl $KUBECONF patch deployment $ICS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__ICS_WORKER_NODE'"}}}}}') |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 413 | if [ $? -ne 0 ]; then |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 414 | echo -e $YELLOW" Cannot set nodeSelector to deployment for $ICS_APP_NAME, persistency may not work"$EYELLOW |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 415 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 416 | __kube_scale deployment $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1 |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 417 | fi |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 418 | else |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 419 | docker start $ICS_APP_NAME &> ./tmp/.dockererr |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 420 | if [ $? -ne 0 ]; then |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 421 | __print_err "Could not start (the stopped) $ICS_APP_NAME" $@ |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 422 | cat ./tmp/.dockererr |
| 423 | ((RES_CONF_FAIL++)) |
| 424 | return 1 |
| 425 | fi |
| 426 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 427 | __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 428 | if [ $? -ne 0 ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 429 | return 1 |
| 430 | fi |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 431 | echo "" |
| 432 | return 0 |
| 433 | } |
| 434 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 435 | # Turn on debug level tracing in ICS |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 436 | # args: - |
| 437 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 438 | set_ics_debug() { |
| 439 | echo -e $BOLD"Setting ics debug logging"$EBOLD |
| 440 | curlString="$ICS_SERVICE_PATH$ICS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}" |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 441 | result=$(__do_curl "$curlString") |
| 442 | if [ $? -ne 0 ]; then |
| 443 | __print_err "Could not set debug mode" $@ |
| 444 | ((RES_CONF_FAIL++)) |
| 445 | return 1 |
| 446 | fi |
| 447 | echo "" |
| 448 | return 0 |
| 449 | } |
| 450 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 451 | # Turn on trace level tracing in ICS |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 452 | # args: - |
| 453 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 454 | set_ics_trace() { |
| 455 | echo -e $BOLD"Setting ics trace logging"$EBOLD |
BjornMagnussonXA | 145762b | 2022-03-22 10:35:10 +0100 | [diff] [blame^] | 456 | curlString="$ICS_SERVICE_PATH$ICS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}" |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 457 | result=$(__do_curl "$curlString") |
| 458 | if [ $? -ne 0 ]; then |
| 459 | __print_err "Could not set trace mode" $@ |
| 460 | ((RES_CONF_FAIL++)) |
| 461 | return 1 |
| 462 | fi |
| 463 | echo "" |
| 464 | return 0 |
| 465 | } |
| 466 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 467 | # Perform curl retries when making direct call to ICS for the specified http response codes |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 468 | # Speace separated list of http response codes |
| 469 | # args: [<response-code>]* |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 470 | use_ics_retries() { |
| 471 | echo -e $BOLD"Do curl retries to the ICS REST inteface for these response codes:$@"$EBOLD |
| 472 | ICS_RETRY_CODES=$@ |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 473 | echo "" |
| 474 | return 0 |
| 475 | } |
| 476 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 477 | # Check the ics logs for WARNINGs and ERRORs |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 478 | # args: - |
| 479 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 480 | check_ics_logs() { |
| 481 | __check_container_logs "ICS" $ICS_APP_NAME $ICS_LOGPATH WARN ERR |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 482 | } |
| 483 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 484 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 485 | # Tests if a variable value in the ICS is equal to a target value and and optional timeout. |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 486 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is |
| 487 | # equal to the target or not. |
| 488 | # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 489 | # before setting pass or fail depending on if the variable value becomes equal to the target |
| 490 | # value or not. |
| 491 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 492 | ics_equal() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 493 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 494 | __var_test ICS "$ICS_SERVICE_PATH/" $1 "=" $2 $3 |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 495 | else |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 496 | __print_err "Wrong args to ics_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@ |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 497 | fi |
| 498 | } |
| 499 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 500 | |
| 501 | ########################################## |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 502 | ######### A1-E information API ########## |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 503 | ########################################## |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 504 | #Function prefix: ics_api_a1 |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 505 | |
| 506 | # API Test function: GET /A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 507 | # args: <response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ] |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 508 | # 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] | 509 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 510 | ics_api_a1_get_job_ids() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 511 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 512 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 513 | if [ -z "$FLAT_A1_EI" ]; then |
| 514 | # Valid number of parameters 4,5,6 etc |
| 515 | if [ $# -lt 3 ]; then |
| 516 | __print_err "<response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@ |
| 517 | return 1 |
| 518 | fi |
| 519 | else |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 520 | echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 521 | # Valid number of parameters 4,5,6 etc |
| 522 | if [ $# -lt 3 ]; then |
| 523 | __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@ |
| 524 | return 1 |
| 525 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 526 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 527 | search="" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 528 | if [ $3 != "NOWNER" ]; then |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 529 | search="?owner="$3 |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 530 | fi |
| 531 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 532 | if [ -z "$FLAT_A1_EI" ]; then |
| 533 | query="/A1-EI/v1/eitypes/$2/eijobs$search" |
| 534 | else |
| 535 | if [ $2 != "NOTYPE" ]; then |
| 536 | if [ -z "$search" ]; then |
| 537 | search="?eiTypeId="$2 |
| 538 | else |
| 539 | search=$search"&eiTypeId="$2 |
| 540 | fi |
| 541 | fi |
| 542 | query="/A1-EI/v1/eijobs$search" |
| 543 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 544 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 545 | status=${res:${#res}-3} |
| 546 | |
| 547 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 548 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 549 | return 1 |
| 550 | fi |
| 551 | |
| 552 | if [ $# -gt 3 ]; then |
| 553 | body=${res:0:${#res}-3} |
| 554 | targetJson="[" |
| 555 | |
| 556 | for pid in ${@:4} ; do |
| 557 | if [ "$targetJson" != "[" ]; then |
| 558 | targetJson=$targetJson"," |
| 559 | fi |
| 560 | if [ $pid != "EMPTY" ]; then |
| 561 | targetJson=$targetJson"\"$pid\"" |
| 562 | fi |
| 563 | done |
| 564 | |
| 565 | targetJson=$targetJson"]" |
| 566 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 567 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 568 | |
| 569 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 570 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 571 | return 1 |
| 572 | fi |
| 573 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 574 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 575 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 576 | return 0 |
| 577 | } |
| 578 | |
| 579 | # API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 580 | # args: <response-code> <type-id> [<schema-file>] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 581 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 582 | ics_api_a1_get_type() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 583 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 584 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 585 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 586 | __print_err "<response-code> <type-id> [<schema-file>]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 587 | return 1 |
| 588 | fi |
| 589 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 590 | query="/A1-EI/v1/eitypes/$2" |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 591 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 592 | status=${res:${#res}-3} |
| 593 | |
| 594 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 595 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 596 | return 1 |
| 597 | fi |
| 598 | |
| 599 | if [ $# -eq 3 ]; then |
| 600 | body=${res:0:${#res}-3} |
| 601 | if [ -f $3 ]; then |
| 602 | schema=$(cat $3) |
| 603 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 604 | __log_test_fail_general "Schema file "$3", does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 605 | return 1 |
| 606 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 607 | if [ -z "$FLAT_A1_EI" ]; then |
| 608 | targetJson="{\"eiJobParametersSchema\":$schema}" |
| 609 | else |
| 610 | targetJson=$schema |
| 611 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 612 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 613 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 614 | |
| 615 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 616 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 617 | return 1 |
| 618 | fi |
| 619 | fi |
| 620 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 621 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 622 | return 0 |
| 623 | } |
| 624 | |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 625 | # API Test function: GET /A1-EI/v1/eitypes |
| 626 | # args: <response-code> [ (EMPTY | [<type-id>]+) ] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 627 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 628 | ics_api_a1_get_type_ids() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 629 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 630 | |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 631 | if [ $# -lt 1 ]; then |
| 632 | __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@ |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 633 | return 1 |
| 634 | fi |
| 635 | |
| 636 | query="/A1-EI/v1/eitypes" |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 637 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 638 | status=${res:${#res}-3} |
| 639 | |
| 640 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 641 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 642 | return 1 |
| 643 | fi |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 644 | if [ $# -gt 1 ]; then |
| 645 | body=${res:0:${#res}-3} |
| 646 | targetJson="[" |
| 647 | if [ $2 != "EMPTY" ]; then |
| 648 | for pid in ${@:2} ; do |
| 649 | if [ "$targetJson" != "[" ]; then |
| 650 | targetJson=$targetJson"," |
| 651 | fi |
| 652 | targetJson=$targetJson"\"$pid\"" |
| 653 | done |
| 654 | fi |
| 655 | targetJson=$targetJson"]" |
| 656 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 657 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 658 | |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 659 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 660 | __log_test_fail_body |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 661 | return 1 |
| 662 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 663 | fi |
| 664 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 665 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 666 | return 0 |
| 667 | } |
| 668 | |
| 669 | # API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 670 | # args: <response-code> <type-id> <job-id> [<status>] |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 671 | # args (flat uri structure): <response-code> <job-id> [<status> [<timeout>]] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 672 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 673 | ics_api_a1_get_job_status() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 674 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 675 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 676 | if [ -z "$FLAT_A1_EI" ]; then |
| 677 | if [ $# -ne 3 ] && [ $# -ne 4 ]; then |
| 678 | __print_err "<response-code> <type-id> <job-id> [<status>]" $@ |
| 679 | return 1 |
| 680 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 681 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 682 | query="/A1-EI/v1/eitypes/$2/eijobs/$3/status" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 683 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 684 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 685 | status=${res:${#res}-3} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 686 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 687 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 688 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 689 | return 1 |
| 690 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 691 | if [ $# -eq 4 ]; then |
| 692 | body=${res:0:${#res}-3} |
| 693 | targetJson="{\"operationalState\": \"$4\"}" |
| 694 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 695 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 696 | |
| 697 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 698 | __log_test_fail_body |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 699 | return 1 |
| 700 | fi |
| 701 | fi |
| 702 | else |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 703 | echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 704 | if [ $# -lt 2 ] && [ $# -gt 4 ]; then |
| 705 | __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@ |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 706 | return 1 |
| 707 | fi |
| 708 | |
| 709 | query="/A1-EI/v1/eijobs/$2/status" |
| 710 | |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 711 | start=$SECONDS |
| 712 | for (( ; ; )); do |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 713 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 714 | status=${res:${#res}-3} |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 715 | |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 716 | if [ $# -eq 4 ]; then |
| 717 | duration=$((SECONDS-start)) |
| 718 | echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}" |
| 719 | if [ $duration -gt $4 ]; then |
| 720 | echo "" |
| 721 | duration=-1 #Last iteration |
| 722 | fi |
| 723 | else |
| 724 | duration=-1 #single test, no wait |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 725 | fi |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 726 | |
| 727 | if [ $status -ne $1 ]; then |
| 728 | if [ $duration -eq -1 ]; then |
| 729 | __log_test_fail_status_code $1 $status |
| 730 | return 1 |
| 731 | fi |
| 732 | fi |
| 733 | if [ $# -ge 3 ] && [ $status -eq $1 ]; then |
| 734 | body=${res:0:${#res}-3} |
| 735 | targetJson="{\"eiJobStatus\": \"$3\"}" |
| 736 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 737 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 738 | |
| 739 | if [ $res -ne 0 ]; then |
| 740 | if [ $duration -eq -1 ]; then |
| 741 | __log_test_fail_body |
| 742 | return 1 |
| 743 | fi |
| 744 | else |
| 745 | duration=-1 #Goto pass |
| 746 | fi |
| 747 | fi |
| 748 | if [ $duration -eq -1 ]; then |
| 749 | if [ $# -eq 4 ]; then |
| 750 | echo "" |
| 751 | fi |
| 752 | __log_test_pass |
| 753 | return 0 |
| 754 | else |
| 755 | sleep 1 |
| 756 | fi |
| 757 | done |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 758 | fi |
| 759 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 760 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 761 | return 0 |
| 762 | } |
| 763 | |
| 764 | # API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 765 | # 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] | 766 | # 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] | 767 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 768 | ics_api_a1_get_job() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 769 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 770 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 771 | if [ -z "$FLAT_A1_EI" ]; then |
| 772 | if [ $# -ne 3 ] && [ $# -ne 6 ]; then |
| 773 | __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@ |
| 774 | return 1 |
| 775 | fi |
| 776 | query="/A1-EI/v1/eitypes/$2/eijobs/$3" |
| 777 | else |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 778 | echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 779 | if [ $# -ne 2 ] && [ $# -ne 7 ]; then |
| 780 | __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@ |
| 781 | return 1 |
| 782 | fi |
| 783 | query="/A1-EI/v1/eijobs/$2" |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 784 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 785 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 786 | status=${res:${#res}-3} |
| 787 | |
| 788 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 789 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 790 | return 1 |
| 791 | fi |
| 792 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 793 | if [ -z "$FLAT_A1_EI" ]; then |
| 794 | if [ $# -eq 6 ]; then |
| 795 | body=${res:0:${#res}-3} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 796 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 797 | if [ -f $6 ]; then |
| 798 | jobfile=$(cat $6) |
| 799 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") |
| 800 | else |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 801 | __log_test_fail_general "Job template file "$6", does not exist" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 802 | return 1 |
| 803 | fi |
| 804 | targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}" |
| 805 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 806 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 807 | |
| 808 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 809 | __log_test_fail_body |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 810 | return 1 |
| 811 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 812 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 813 | else |
| 814 | if [ $# -eq 7 ]; then |
| 815 | body=${res:0:${#res}-3} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 816 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 817 | if [ -f $7 ]; then |
| 818 | jobfile=$(cat $7) |
| 819 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g") |
| 820 | else |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 821 | __log_test_fail_general "Job template file "$6", does not exist" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 822 | return 1 |
| 823 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 824 | targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 825 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 826 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 827 | |
| 828 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 829 | __log_test_fail_body |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 830 | return 1 |
| 831 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 832 | fi |
| 833 | fi |
| 834 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 835 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 836 | return 0 |
| 837 | } |
| 838 | |
| 839 | # API Test function: DELETE ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 840 | # args: <response-code> <type-id> <job-id> |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 841 | # args (flat uri structure): <response-code> <job-id> |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 842 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 843 | ics_api_a1_delete_job() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 844 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 845 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 846 | if [ -z "$FLAT_A1_EI" ]; then |
| 847 | if [ $# -ne 3 ]; then |
| 848 | __print_err "<response-code> <type-id> <job-id>" $@ |
| 849 | return 1 |
| 850 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 851 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 852 | query="/A1-EI/v1/eitypes/$2/eijobs/$3" |
| 853 | else |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 854 | echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 855 | if [ $# -ne 2 ]; then |
| 856 | __print_err "<response-code> <job-id>" $@ |
| 857 | return 1 |
| 858 | fi |
| 859 | query="/A1-EI/v1/eijobs/$2" |
| 860 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 861 | res="$(__do_curl_to_api ICS DELETE $query)" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 862 | status=${res:${#res}-3} |
| 863 | |
| 864 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 865 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 866 | return 1 |
| 867 | fi |
| 868 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 869 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 870 | return 0 |
| 871 | } |
| 872 | |
| 873 | # API Test function: PUT ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 874 | # 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] | 875 | # 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] | 876 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 877 | ics_api_a1_put_job() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 878 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 879 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 880 | if [ -z "$FLAT_A1_EI" ]; then |
| 881 | if [ $# -lt 6 ]; then |
| 882 | __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@ |
| 883 | return 1 |
| 884 | fi |
| 885 | if [ -f $6 ]; then |
| 886 | jobfile=$(cat $6) |
| 887 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") |
| 888 | else |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 889 | __log_test_fail_general "Job template file "$6", does not exist" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 890 | return 1 |
| 891 | fi |
| 892 | |
| 893 | inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}" |
| 894 | file="./tmp/.p.json" |
| 895 | echo "$inputJson" > $file |
| 896 | |
| 897 | query="/A1-EI/v1/eitypes/$2/eijobs/$3" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 898 | else |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 899 | echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 900 | if [ $# -lt 7 ]; then |
| 901 | __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@ |
| 902 | return 1 |
| 903 | fi |
| 904 | if [ -f $7 ]; then |
| 905 | jobfile=$(cat $7) |
| 906 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g") |
| 907 | else |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 908 | __log_test_fail_general "Job template file "$7", does not exist" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 909 | return 1 |
| 910 | fi |
| 911 | |
| 912 | inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}" |
| 913 | file="./tmp/.p.json" |
| 914 | echo "$inputJson" > $file |
| 915 | |
| 916 | query="/A1-EI/v1/eijobs/$2" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 917 | fi |
| 918 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 919 | res="$(__do_curl_to_api ICS PUT $query $file)" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 920 | status=${res:${#res}-3} |
| 921 | |
| 922 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 923 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 924 | return 1 |
| 925 | fi |
| 926 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 927 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 928 | return 0 |
| 929 | } |
| 930 | |
| 931 | |
| 932 | ########################################## |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 933 | #### information Data Producer API #### |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 934 | ########################################## |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 935 | # Function prefix: ics_api_edp |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 936 | |
| 937 | # API Test function: GET /ei-producer/v1/eitypes |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 938 | # API Test function: GET /data-producer/v1/info-types |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 939 | # args: <response-code> [ EMPTY | <type-id>+] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 940 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 941 | ics_api_edp_get_type_ids() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 942 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 943 | |
| 944 | if [ $# -lt 1 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 945 | __print_err "<response-code> [ EMPTY | <type-id>+]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 946 | return 1 |
| 947 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 948 | if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 949 | query="/data-producer/v1/info-types" |
| 950 | else |
| 951 | query="/ei-producer/v1/eitypes" |
| 952 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 953 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 954 | status=${res:${#res}-3} |
| 955 | |
| 956 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 957 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 958 | return 1 |
| 959 | fi |
| 960 | |
| 961 | if [ $# -gt 1 ]; then |
| 962 | body=${res:0:${#res}-3} |
| 963 | targetJson="[" |
| 964 | if [ $2 != "EMPTY" ]; then |
| 965 | for pid in ${@:2} ; do |
| 966 | if [ "$targetJson" != "[" ]; then |
| 967 | targetJson=$targetJson"," |
| 968 | fi |
| 969 | targetJson=$targetJson"\"$pid\"" |
| 970 | done |
| 971 | fi |
| 972 | targetJson=$targetJson"]" |
| 973 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 974 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 975 | |
| 976 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 977 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 978 | return 1 |
| 979 | fi |
| 980 | fi |
| 981 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 982 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 983 | return 0 |
| 984 | } |
| 985 | |
| 986 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 987 | # API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/status |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 988 | # args: <response-code> <producer-id> [<status> [<timeout>]] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 989 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 990 | ics_api_edp_get_producer_status() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 991 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 992 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 993 | if [ $# -lt 2 ] || [ $# -gt 4 ]; then |
| 994 | __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 995 | return 1 |
| 996 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 997 | if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 998 | query="/data-producer/v1/info-producers/$2/status" |
| 999 | else |
| 1000 | query="/ei-producer/v1/eiproducers/$2/status" |
| 1001 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1002 | start=$SECONDS |
| 1003 | for (( ; ; )); do |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1004 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 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) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1055 | ics_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" |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1064 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 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 |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1100 | # API Test function: GET /data-producer/v1/info-producers |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1101 | # args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ] |
| 1102 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1103 | ics_api_edp_get_producer_ids_2() { |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1104 | __log_test_start $@ |
| 1105 | |
| 1106 | if [ $# -lt 1 ]; then |
| 1107 | __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@ |
| 1108 | return 1 |
| 1109 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1110 | if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1111 | query="/data-producer/v1/info-producers" |
| 1112 | if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then |
BjornMagnussonXA | c8f92e9 | 2022-02-28 15:16:37 +0100 | [diff] [blame] | 1113 | query=$query"?info_type_id=$2&infoTypeId=$2" #info_type_id changed to infoTypeId in F-release. |
| 1114 | #Remove info_type_id when F-release is no longer supported |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1115 | fi |
| 1116 | else |
| 1117 | query="/ei-producer/v1/eiproducers" |
| 1118 | if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then |
| 1119 | query=$query"?ei_type_id=$2" |
| 1120 | fi |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1121 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1122 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1123 | status=${res:${#res}-3} |
| 1124 | |
| 1125 | if [ $status -ne $1 ]; then |
| 1126 | __log_test_fail_status_code $1 $status |
| 1127 | return 1 |
| 1128 | fi |
| 1129 | |
| 1130 | if [ $# -gt 2 ]; then |
| 1131 | body=${res:0:${#res}-3} |
| 1132 | targetJson="[" |
| 1133 | |
| 1134 | for pid in ${@:3} ; do |
| 1135 | if [ "$targetJson" != "[" ]; then |
| 1136 | targetJson=$targetJson"," |
| 1137 | fi |
| 1138 | if [ $pid != "EMPTY" ]; then |
| 1139 | targetJson=$targetJson"\"$pid\"" |
| 1140 | fi |
| 1141 | done |
| 1142 | |
| 1143 | targetJson=$targetJson"]" |
| 1144 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1145 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1146 | |
| 1147 | if [ $res -ne 0 ]; then |
| 1148 | __log_test_fail_body |
| 1149 | return 1 |
| 1150 | fi |
| 1151 | fi |
| 1152 | |
| 1153 | __log_test_pass |
| 1154 | return 0 |
| 1155 | } |
| 1156 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1157 | # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId} |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1158 | # args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1159 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1160 | ics_api_edp_get_type() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1161 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1162 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1163 | paramError=1 |
| 1164 | if [ $# -eq 2 ]; then |
| 1165 | paramError=0 |
| 1166 | fi |
| 1167 | if [ $# -gt 3 ]; then |
| 1168 | paramError=0 |
| 1169 | fi |
| 1170 | if [ $paramError -ne 0 ]; then |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 1171 | __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1172 | return 1 |
| 1173 | fi |
| 1174 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1175 | query="/ei-producer/v1/eitypes/$2" |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1176 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1177 | status=${res:${#res}-3} |
| 1178 | |
| 1179 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1180 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1181 | return 1 |
| 1182 | fi |
| 1183 | if [ $# -gt 3 ]; then |
| 1184 | body=${res:0:${#res}-3} |
| 1185 | |
| 1186 | if [ -f $3 ]; then |
| 1187 | schema=$(cat $3) |
| 1188 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1189 | __log_test_fail_general "Job template file "$3", does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1190 | return 1 |
| 1191 | fi |
| 1192 | |
| 1193 | targetJson="" |
| 1194 | if [ $4 != "EMPTY" ]; then |
| 1195 | for pid in ${@:4} ; do |
| 1196 | if [ "$targetJson" != "" ]; then |
| 1197 | targetJson=$targetJson"," |
| 1198 | fi |
| 1199 | targetJson=$targetJson"\"$pid\"" |
| 1200 | done |
| 1201 | fi |
| 1202 | targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}" |
| 1203 | |
| 1204 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1205 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1206 | |
| 1207 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1208 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1209 | return 1 |
| 1210 | fi |
| 1211 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1212 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1213 | return 0 |
| 1214 | } |
| 1215 | |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1216 | # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId} |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1217 | # API Test function: GET /data-producer/v1/info-types/{infoTypeId} |
BjornMagnussonXA | 83a750f | 2021-09-21 20:39:58 +0200 | [diff] [blame] | 1218 | # args: (v1_2) <response-code> <type-id> [<job-schema-file> [ <info-type-info> ]] |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1219 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1220 | ics_api_edp_get_type_2() { |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1221 | __log_test_start $@ |
| 1222 | |
| 1223 | paramError=1 |
| 1224 | if [ $# -eq 2 ]; then |
| 1225 | paramError=0 |
| 1226 | fi |
| 1227 | if [ $# -eq 3 ]; then |
| 1228 | paramError=0 |
| 1229 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1230 | if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then |
BjornMagnussonXA | 83a750f | 2021-09-21 20:39:58 +0200 | [diff] [blame] | 1231 | if [ $# -eq 4 ]; then |
| 1232 | paramError=0 |
| 1233 | fi |
| 1234 | fi |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1235 | if [ $paramError -ne 0 ]; then |
BjornMagnussonXA | 83a750f | 2021-09-21 20:39:58 +0200 | [diff] [blame] | 1236 | __print_err "<response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]" $@ |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1237 | return 1 |
| 1238 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1239 | if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1240 | query="/data-producer/v1/info-types/$2" |
| 1241 | else |
| 1242 | query="/ei-producer/v1/eitypes/$2" |
| 1243 | fi |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1244 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1245 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1246 | status=${res:${#res}-3} |
| 1247 | |
| 1248 | if [ $status -ne $1 ]; then |
| 1249 | __log_test_fail_status_code $1 $status |
| 1250 | return 1 |
| 1251 | fi |
BjornMagnussonXA | 83a750f | 2021-09-21 20:39:58 +0200 | [diff] [blame] | 1252 | if [ $# -ge 3 ]; then |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1253 | body=${res:0:${#res}-3} |
| 1254 | |
| 1255 | if [ -f $3 ]; then |
| 1256 | schema=$(cat $3) |
| 1257 | else |
| 1258 | __log_test_fail_general "Job template file "$3", does not exist" |
| 1259 | return 1 |
| 1260 | fi |
BjornMagnussonXA | 83a750f | 2021-09-21 20:39:58 +0200 | [diff] [blame] | 1261 | info_data="" |
| 1262 | if [ $# -gt 3 ]; then |
| 1263 | if [ -f $4 ]; then |
| 1264 | info_data=$(cat $4) |
| 1265 | else |
| 1266 | __log_test_fail_general "Info-data file "$4", does not exist" |
| 1267 | return 1 |
| 1268 | fi |
| 1269 | info_data=",\"info_type_information\":$info_data" |
| 1270 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1271 | if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then |
BjornMagnussonXA | 83a750f | 2021-09-21 20:39:58 +0200 | [diff] [blame] | 1272 | targetJson="{\"info_job_data_schema\":$schema $info_data}" |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1273 | else |
| 1274 | targetJson="{\"ei_job_data_schema\":$schema}" |
| 1275 | fi |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1276 | |
| 1277 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1278 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1279 | |
| 1280 | if [ $res -ne 0 ]; then |
| 1281 | __log_test_fail_body |
| 1282 | return 1 |
| 1283 | fi |
| 1284 | fi |
| 1285 | __log_test_pass |
| 1286 | return 0 |
| 1287 | } |
| 1288 | |
| 1289 | # API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId} |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1290 | # API Test function: PUT /data-producer/v1/info-types/{infoTypeId} |
BjornMagnussonXA | 83a750f | 2021-09-21 20:39:58 +0200 | [diff] [blame] | 1291 | # args: (v1_2) <response-code> <type-id> <job-schema-file> [ <info-type-info> ] |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1292 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1293 | ics_api_edp_put_type_2() { |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1294 | __log_test_start $@ |
| 1295 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1296 | if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then |
BjornMagnussonXA | 83a750f | 2021-09-21 20:39:58 +0200 | [diff] [blame] | 1297 | if [ $# -lt 3 ] || [ $# -gt 4 ]; then |
| 1298 | __print_err "<response-code> <type-id> <job-schema-file> [ <info-type-info> ]" $@ |
| 1299 | return 1 |
| 1300 | fi |
| 1301 | else |
| 1302 | if [ $# -ne 3 ]; then |
| 1303 | __print_err "<response-code> <type-id> <job-schema-file>" $@ |
| 1304 | return 1 |
| 1305 | fi |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1306 | fi |
| 1307 | |
| 1308 | if [ ! -f $3 ]; then |
| 1309 | __log_test_fail_general "Job schema file "$3", does not exist" |
| 1310 | return 1 |
| 1311 | fi |
BjornMagnussonXA | 83a750f | 2021-09-21 20:39:58 +0200 | [diff] [blame] | 1312 | |
| 1313 | info_data="" |
| 1314 | if [ $# -gt 3 ]; then |
| 1315 | if [ -f $4 ]; then |
| 1316 | info_data=$(cat $4) |
| 1317 | else |
| 1318 | __log_test_fail_general "Info-data file "$4", does not exist" |
| 1319 | return 1 |
| 1320 | fi |
| 1321 | info_data=",\"info_type_information\":$info_data" |
| 1322 | fi |
| 1323 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1324 | if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1325 | schema=$(cat $3) |
BjornMagnussonXA | 83a750f | 2021-09-21 20:39:58 +0200 | [diff] [blame] | 1326 | input_json="{\"info_job_data_schema\":$schema $info_data}" |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1327 | file="./tmp/put_type.json" |
| 1328 | echo $input_json > $file |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1329 | |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1330 | query="/data-producer/v1/info-types/$2" |
| 1331 | else |
| 1332 | schema=$(cat $3) |
| 1333 | input_json="{\"ei_job_data_schema\":$schema}" |
| 1334 | file="./tmp/put_type.json" |
| 1335 | echo $input_json > $file |
| 1336 | |
| 1337 | query="/ei-producer/v1/eitypes/$2" |
| 1338 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1339 | res="$(__do_curl_to_api ICS PUT $query $file)" |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1340 | status=${res:${#res}-3} |
| 1341 | |
| 1342 | if [ $status -ne $1 ]; then |
| 1343 | __log_test_fail_status_code $1 $status |
| 1344 | return 1 |
| 1345 | fi |
| 1346 | |
| 1347 | __log_test_pass |
| 1348 | return 0 |
| 1349 | } |
| 1350 | |
| 1351 | # API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId} |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1352 | # API Test function: DELETE /data-producer/v1/info-types/{infoTypeId} |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1353 | # args: (v1_2) <response-code> <type-id> |
| 1354 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1355 | ics_api_edp_delete_type_2() { |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1356 | __log_test_start $@ |
| 1357 | |
| 1358 | if [ $# -ne 2 ]; then |
| 1359 | __print_err "<response-code> <type-id>" $@ |
| 1360 | return 1 |
| 1361 | fi |
| 1362 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1363 | if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1364 | query="/data-producer/v1/info-types/$2" |
| 1365 | else |
| 1366 | query="/ei-producer/v1/eitypes/$2" |
| 1367 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1368 | res="$(__do_curl_to_api ICS DELETE $query)" |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1369 | status=${res:${#res}-3} |
| 1370 | |
| 1371 | if [ $status -ne $1 ]; then |
| 1372 | __log_test_fail_status_code $1 $status |
| 1373 | return 1 |
| 1374 | fi |
| 1375 | |
| 1376 | __log_test_pass |
| 1377 | return 0 |
| 1378 | } |
| 1379 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1380 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId} |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1381 | # 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] | 1382 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1383 | ics_api_edp_get_producer() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1384 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1385 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1386 | #Possible arg count: 2, 5 6, 8, 10 etc |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1387 | paramError=1 |
| 1388 | if [ $# -eq 2 ]; then |
| 1389 | paramError=0 |
| 1390 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1391 | if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1392 | paramError=0 |
| 1393 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1394 | variablecount=$(($#-4)) |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1395 | if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then |
| 1396 | paramError=0 |
| 1397 | fi |
| 1398 | |
| 1399 | if [ $paramError -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1400 | __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] | 1401 | return 1 |
| 1402 | fi |
| 1403 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1404 | query="/ei-producer/v1/eiproducers/$2" |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1405 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1406 | status=${res:${#res}-3} |
| 1407 | |
| 1408 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1409 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1410 | return 1 |
| 1411 | fi |
| 1412 | |
| 1413 | if [ $# -gt 2 ]; then |
| 1414 | body=${res:0:${#res}-3} |
| 1415 | targetJson="[" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1416 | if [ $# -gt 5 ]; then |
| 1417 | arr=(${@:5}) |
| 1418 | for ((i=0; i<$(($#-5)); i=i+2)); do |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1419 | if [ "$targetJson" != "[" ]; then |
| 1420 | targetJson=$targetJson"," |
| 1421 | fi |
| 1422 | if [ -f ${arr[$i+1]} ]; then |
| 1423 | schema=$(cat ${arr[$i+1]}) |
| 1424 | else |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 1425 | __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1426 | return 1 |
| 1427 | fi |
| 1428 | |
| 1429 | targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}" |
| 1430 | done |
| 1431 | fi |
| 1432 | targetJson=$targetJson"]" |
| 1433 | if [ $# -gt 4 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1434 | 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] | 1435 | fi |
| 1436 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1437 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1438 | |
| 1439 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1440 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1441 | return 1 |
| 1442 | fi |
| 1443 | fi |
| 1444 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1445 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1446 | return 0 |
| 1447 | } |
| 1448 | |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1449 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId} |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1450 | # API Test function: GET /data-producer/v1/info-producers/{infoProducerId} |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1451 | # args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ] |
| 1452 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1453 | ics_api_edp_get_producer_2() { |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1454 | __log_test_start $@ |
| 1455 | |
| 1456 | #Possible arg count: 2, 5, 6, 7, 8 etc |
| 1457 | paramError=1 |
| 1458 | if [ $# -eq 2 ]; then |
| 1459 | paramError=0 |
| 1460 | fi |
| 1461 | if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then |
| 1462 | paramError=0 |
| 1463 | fi |
| 1464 | if [ $# -ge 5 ]; then |
| 1465 | paramError=0 |
| 1466 | fi |
| 1467 | |
| 1468 | if [ $paramError -ne 0 ]; then |
| 1469 | __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@ |
| 1470 | return 1 |
| 1471 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1472 | if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1473 | query="/data-producer/v1/info-producers/$2" |
| 1474 | else |
| 1475 | query="/ei-producer/v1/eiproducers/$2" |
| 1476 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1477 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1478 | status=${res:${#res}-3} |
| 1479 | |
| 1480 | if [ $status -ne $1 ]; then |
| 1481 | __log_test_fail_status_code $1 $status |
| 1482 | return 1 |
| 1483 | fi |
| 1484 | |
| 1485 | if [ $# -gt 2 ]; then |
| 1486 | body=${res:0:${#res}-3} |
| 1487 | targetJson="[" |
| 1488 | if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then |
| 1489 | arr=(${@:5}) |
| 1490 | for ((i=0; i<$(($#-4)); i=i+1)); do |
| 1491 | if [ "$targetJson" != "[" ]; then |
| 1492 | targetJson=$targetJson"," |
| 1493 | fi |
| 1494 | targetJson=$targetJson"\"${arr[$i]}\"" |
| 1495 | done |
| 1496 | fi |
| 1497 | targetJson=$targetJson"]" |
| 1498 | if [ $# -gt 4 ]; then |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1499 | if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1500 | targetJson="{\"supported_info_types\":$targetJson,\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\"}" |
| 1501 | else |
| 1502 | targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}" |
| 1503 | fi |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1504 | fi |
| 1505 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1506 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1507 | |
| 1508 | if [ $res -ne 0 ]; then |
| 1509 | __log_test_fail_body |
| 1510 | return 1 |
| 1511 | fi |
| 1512 | fi |
| 1513 | |
| 1514 | __log_test_pass |
| 1515 | return 0 |
| 1516 | } |
| 1517 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1518 | # API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId} |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1519 | # API Test function: DELETE /data-producer/v1/info-producers/{infoProducerId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1520 | # args: <response-code> <producer-id> |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1521 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1522 | ics_api_edp_delete_producer() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1523 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1524 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1525 | if [ $# -lt 2 ]; then |
| 1526 | __print_err "<response-code> <producer-id>" $@ |
| 1527 | return 1 |
| 1528 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1529 | if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1530 | query="/data-producer/v1/info-producers/$2" |
| 1531 | else |
| 1532 | query="/ei-producer/v1/eiproducers/$2" |
| 1533 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1534 | res="$(__do_curl_to_api ICS DELETE $query)" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1535 | status=${res:${#res}-3} |
| 1536 | |
| 1537 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1538 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1539 | return 1 |
| 1540 | fi |
| 1541 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1542 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1543 | return 0 |
| 1544 | } |
| 1545 | |
| 1546 | # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId} |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1547 | # 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] | 1548 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1549 | ics_api_edp_put_producer() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1550 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1551 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1552 | #Valid number of parametrer 5,6,8,10, |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1553 | paramError=1 |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1554 | if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1555 | paramError=0 |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1556 | elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1557 | paramError=0 |
| 1558 | fi |
| 1559 | if [ $paramError -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1560 | __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] | 1561 | return 1 |
| 1562 | fi |
| 1563 | |
| 1564 | inputJson="[" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1565 | if [ $# -gt 5 ]; then |
| 1566 | arr=(${@:5}) |
| 1567 | for ((i=0; i<$(($#-5)); i=i+2)); do |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1568 | if [ "$inputJson" != "[" ]; then |
| 1569 | inputJson=$inputJson"," |
| 1570 | fi |
| 1571 | if [ -f ${arr[$i+1]} ]; then |
| 1572 | schema=$(cat ${arr[$i+1]}) |
| 1573 | else |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 1574 | __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1575 | return 1 |
| 1576 | fi |
| 1577 | inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}" |
| 1578 | done |
| 1579 | fi |
| 1580 | inputJson="\"supported_ei_types\":"$inputJson"]" |
| 1581 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1582 | inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1583 | |
| 1584 | inputJson="{"$inputJson"}" |
| 1585 | |
| 1586 | file="./tmp/.p.json" |
| 1587 | echo "$inputJson" > $file |
| 1588 | query="/ei-producer/v1/eiproducers/$2" |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1589 | res="$(__do_curl_to_api ICS PUT $query $file)" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1590 | status=${res:${#res}-3} |
| 1591 | |
| 1592 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1593 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1594 | return 1 |
| 1595 | fi |
| 1596 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1597 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1598 | return 0 |
| 1599 | } |
| 1600 | |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1601 | # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId} |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1602 | # API Test function: PUT /data-producer/v1/info-producers/{infoProducerId} |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1603 | # args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+] |
| 1604 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1605 | ics_api_edp_put_producer_2() { |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1606 | __log_test_start $@ |
| 1607 | |
| 1608 | #Valid number of parametrer 5,6,8,10, |
| 1609 | paramError=1 |
| 1610 | if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then |
| 1611 | paramError=0 |
| 1612 | elif [ $# -ge 5 ]; then |
| 1613 | paramError=0 |
| 1614 | fi |
| 1615 | if [ $paramError -ne 0 ]; then |
| 1616 | __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@ |
| 1617 | return 1 |
| 1618 | fi |
| 1619 | |
| 1620 | inputJson="[" |
| 1621 | if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then |
| 1622 | arr=(${@:5}) |
| 1623 | for ((i=0; i<$(($#-4)); i=i+1)); do |
| 1624 | if [ "$inputJson" != "[" ]; then |
| 1625 | inputJson=$inputJson"," |
| 1626 | fi |
| 1627 | inputJson=$inputJson"\""${arr[$i]}"\"" |
| 1628 | done |
| 1629 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1630 | if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1631 | inputJson="\"supported_info_types\":"$inputJson"]" |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1632 | |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1633 | inputJson=$inputJson",\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\"" |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1634 | |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1635 | inputJson="{"$inputJson"}" |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1636 | |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1637 | file="./tmp/.p.json" |
| 1638 | echo "$inputJson" > $file |
| 1639 | query="/data-producer/v1/info-producers/$2" |
| 1640 | else |
| 1641 | inputJson="\"supported_ei_types\":"$inputJson"]" |
| 1642 | |
| 1643 | inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"" |
| 1644 | |
| 1645 | inputJson="{"$inputJson"}" |
| 1646 | |
| 1647 | file="./tmp/.p.json" |
| 1648 | echo "$inputJson" > $file |
| 1649 | query="/ei-producer/v1/eiproducers/$2" |
| 1650 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1651 | res="$(__do_curl_to_api ICS PUT $query $file)" |
BjornMagnussonXA | 27db02f | 2021-01-19 08:13:00 +0100 | [diff] [blame] | 1652 | status=${res:${#res}-3} |
| 1653 | |
| 1654 | if [ $status -ne $1 ]; then |
| 1655 | __log_test_fail_status_code $1 $status |
| 1656 | return 1 |
| 1657 | fi |
| 1658 | |
| 1659 | __log_test_pass |
| 1660 | return 0 |
| 1661 | } |
| 1662 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1663 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 1664 | # 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] | 1665 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1666 | ics_api_edp_get_producer_jobs() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1667 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1668 | |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 1669 | #Valid number of parameter 2,3,7,11 |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1670 | paramError=1 |
| 1671 | if [ $# -eq 2 ]; then |
| 1672 | paramError=0 |
| 1673 | fi |
| 1674 | if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then |
| 1675 | paramError=0 |
| 1676 | fi |
| 1677 | variablecount=$(($#-2)) |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 1678 | if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1679 | paramError=0 |
| 1680 | fi |
| 1681 | if [ $paramError -eq 1 ]; then |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 1682 | __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] | 1683 | return 1 |
| 1684 | fi |
| 1685 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1686 | query="/ei-producer/v1/eiproducers/$2/eijobs" |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1687 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1688 | status=${res:${#res}-3} |
| 1689 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1690 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1691 | return 1 |
| 1692 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1693 | if [ $# -gt 2 ]; then |
| 1694 | body=${res:0:${#res}-3} |
| 1695 | targetJson="[" |
| 1696 | if [ $# -gt 3 ]; then |
| 1697 | arr=(${@:3}) |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 1698 | for ((i=0; i<$(($#-3)); i=i+5)); do |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1699 | if [ "$targetJson" != "[" ]; then |
| 1700 | targetJson=$targetJson"," |
| 1701 | fi |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 1702 | if [ -f ${arr[$i+4]} ]; then |
| 1703 | jobfile=$(cat ${arr[$i+4]}) |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1704 | jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g") |
| 1705 | else |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 1706 | __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1707 | return 1 |
| 1708 | fi |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 1709 | 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] | 1710 | done |
| 1711 | fi |
| 1712 | targetJson=$targetJson"]" |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1713 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1714 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1715 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1716 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1717 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1718 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1719 | return 1 |
| 1720 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1721 | fi |
| 1722 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1723 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1724 | return 0 |
| 1725 | } |
| 1726 | |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 1727 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1728 | # API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/info-jobs |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 1729 | # args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+) |
| 1730 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1731 | ics_api_edp_get_producer_jobs_2() { |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 1732 | __log_test_start $@ |
| 1733 | |
| 1734 | #Valid number of parameter 2,3,7,11 |
| 1735 | paramError=1 |
| 1736 | if [ $# -eq 2 ]; then |
| 1737 | paramError=0 |
| 1738 | fi |
| 1739 | if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then |
| 1740 | paramError=0 |
| 1741 | fi |
| 1742 | variablecount=$(($#-2)) |
| 1743 | if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then |
| 1744 | paramError=0 |
| 1745 | fi |
| 1746 | if [ $paramError -eq 1 ]; then |
| 1747 | __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@ |
| 1748 | return 1 |
| 1749 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1750 | if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1751 | query="/data-producer/v1/info-producers/$2/info-jobs" |
| 1752 | else |
| 1753 | query="/ei-producer/v1/eiproducers/$2/eijobs" |
| 1754 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1755 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 1756 | status=${res:${#res}-3} |
| 1757 | if [ $status -ne $1 ]; then |
| 1758 | __log_test_fail_status_code $1 $status |
| 1759 | return 1 |
| 1760 | fi |
| 1761 | if [ $# -gt 2 ]; then |
| 1762 | body=${res:0:${#res}-3} |
| 1763 | targetJson="[" |
| 1764 | if [ $# -gt 3 ]; then |
| 1765 | arr=(${@:3}) |
| 1766 | for ((i=0; i<$(($#-3)); i=i+5)); do |
| 1767 | if [ "$targetJson" != "[" ]; then |
| 1768 | targetJson=$targetJson"," |
| 1769 | fi |
| 1770 | if [ -f ${arr[$i+4]} ]; then |
| 1771 | jobfile=$(cat ${arr[$i+4]}) |
| 1772 | jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g") |
| 1773 | else |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 1774 | __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist" |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 1775 | return 1 |
| 1776 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1777 | if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1778 | targetJson=$targetJson"{\"info_job_identity\":\"${arr[$i]}\",\"info_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"info_job_data\":$jobfile, \"last_updated\":\"????\"}" |
| 1779 | else |
| 1780 | 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\":\"????\"}" |
| 1781 | fi |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 1782 | done |
| 1783 | fi |
| 1784 | targetJson=$targetJson"]" |
| 1785 | |
| 1786 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1787 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1788 | |
| 1789 | if [ $res -ne 0 ]; then |
| 1790 | __log_test_fail_body |
| 1791 | return 1 |
| 1792 | fi |
| 1793 | fi |
| 1794 | |
| 1795 | __log_test_pass |
| 1796 | return 0 |
| 1797 | } |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1798 | |
| 1799 | ########################################## |
| 1800 | #### Service status #### |
| 1801 | ########################################## |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1802 | # Function prefix: ics_api_service |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1803 | |
| 1804 | # API Test function: GET ​/status |
| 1805 | # args: <response-code> |
| 1806 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1807 | ics_api_service_status() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1808 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1809 | |
| 1810 | if [ $# -lt 1 ]; then |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 1811 | __print_err "<response-code>" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1812 | return 1 |
| 1813 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1814 | res="$(__do_curl_to_api ICS GET /status)" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 1815 | status=${res:${#res}-3} |
| 1816 | if [ $status -ne $1 ]; then |
| 1817 | __log_test_fail_status_code $1 $status |
| 1818 | return 1 |
| 1819 | fi |
| 1820 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1821 | return 0 |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 1822 | } |
| 1823 | |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 1824 | ########################################### |
| 1825 | ######### Info data consumer API ########## |
| 1826 | ########################################### |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1827 | #Function prefix: ics_api_idc |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 1828 | |
| 1829 | |
| 1830 | # API Test function: GET /data-consumer/v1/info-types |
| 1831 | # args: <response-code> [ (EMPTY | [<type-id>]+) ] |
| 1832 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1833 | ics_api_idc_get_type_ids() { |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 1834 | __log_test_start $@ |
| 1835 | |
| 1836 | if [ $# -lt 1 ]; then |
| 1837 | __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@ |
| 1838 | return 1 |
| 1839 | fi |
| 1840 | |
| 1841 | query="/data-consumer/v1/info-types" |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1842 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 1843 | status=${res:${#res}-3} |
| 1844 | |
| 1845 | if [ $status -ne $1 ]; then |
| 1846 | __log_test_fail_status_code $1 $status |
| 1847 | return 1 |
| 1848 | fi |
| 1849 | if [ $# -gt 1 ]; then |
| 1850 | body=${res:0:${#res}-3} |
| 1851 | targetJson="[" |
| 1852 | if [ $2 != "EMPTY" ]; then |
| 1853 | for pid in ${@:2} ; do |
| 1854 | if [ "$targetJson" != "[" ]; then |
| 1855 | targetJson=$targetJson"," |
| 1856 | fi |
| 1857 | targetJson=$targetJson"\"$pid\"" |
| 1858 | done |
| 1859 | fi |
| 1860 | targetJson=$targetJson"]" |
| 1861 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1862 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1863 | |
| 1864 | if [ $res -ne 0 ]; then |
| 1865 | __log_test_fail_body |
| 1866 | return 1 |
| 1867 | fi |
| 1868 | fi |
| 1869 | |
| 1870 | __log_test_pass |
| 1871 | return 0 |
| 1872 | } |
| 1873 | |
| 1874 | # API Test function: GET /data-consumer/v1/info-jobs |
| 1875 | # args: <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ] |
| 1876 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1877 | ics_api_idc_get_job_ids() { |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 1878 | __log_test_start $@ |
| 1879 | |
| 1880 | # Valid number of parameters 4,5,6 etc |
| 1881 | if [ $# -lt 3 ]; then |
| 1882 | __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@ |
| 1883 | return 1 |
| 1884 | fi |
| 1885 | search="" |
| 1886 | if [ $3 != "NOWNER" ]; then |
| 1887 | search="?owner="$3 |
| 1888 | fi |
| 1889 | |
| 1890 | if [ $2 != "NOTYPE" ]; then |
| 1891 | if [ -z "$search" ]; then |
| 1892 | search="?infoTypeId="$2 |
| 1893 | else |
| 1894 | search=$search"&infoTypeId="$2 |
| 1895 | fi |
| 1896 | fi |
| 1897 | query="/data-consumer/v1/info-jobs$search" |
| 1898 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1899 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 1900 | status=${res:${#res}-3} |
| 1901 | |
| 1902 | if [ $status -ne $1 ]; then |
| 1903 | __log_test_fail_status_code $1 $status |
| 1904 | return 1 |
| 1905 | fi |
| 1906 | |
| 1907 | if [ $# -gt 3 ]; then |
| 1908 | body=${res:0:${#res}-3} |
| 1909 | targetJson="[" |
| 1910 | |
| 1911 | for pid in ${@:4} ; do |
| 1912 | if [ "$targetJson" != "[" ]; then |
| 1913 | targetJson=$targetJson"," |
| 1914 | fi |
| 1915 | if [ $pid != "EMPTY" ]; then |
| 1916 | targetJson=$targetJson"\"$pid\"" |
| 1917 | fi |
| 1918 | done |
| 1919 | |
| 1920 | targetJson=$targetJson"]" |
| 1921 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1922 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1923 | |
| 1924 | if [ $res -ne 0 ]; then |
| 1925 | __log_test_fail_body |
| 1926 | return 1 |
| 1927 | fi |
| 1928 | fi |
| 1929 | |
| 1930 | __log_test_pass |
| 1931 | return 0 |
| 1932 | } |
| 1933 | |
| 1934 | # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId} |
| 1935 | # args: <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>] |
| 1936 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1937 | ics_api_idc_get_job() { |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 1938 | __log_test_start $@ |
| 1939 | |
| 1940 | if [ $# -ne 2 ] && [ $# -ne 7 ]; then |
| 1941 | __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@ |
| 1942 | return 1 |
| 1943 | fi |
| 1944 | query="/data-consumer/v1/info-jobs/$2" |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1945 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 1946 | status=${res:${#res}-3} |
| 1947 | |
| 1948 | if [ $status -ne $1 ]; then |
| 1949 | __log_test_fail_status_code $1 $status |
| 1950 | return 1 |
| 1951 | fi |
| 1952 | |
| 1953 | if [ $# -eq 7 ]; then |
| 1954 | body=${res:0:${#res}-3} |
| 1955 | |
| 1956 | if [ -f $7 ]; then |
| 1957 | jobfile=$(cat $7) |
| 1958 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g") |
| 1959 | else |
| 1960 | __log_test_fail_general "Job template file "$6", does not exist" |
| 1961 | return 1 |
| 1962 | fi |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1963 | targetJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}" |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 1964 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1965 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1966 | |
| 1967 | if [ $res -ne 0 ]; then |
| 1968 | __log_test_fail_body |
| 1969 | return 1 |
| 1970 | fi |
| 1971 | fi |
| 1972 | |
| 1973 | __log_test_pass |
| 1974 | return 0 |
| 1975 | } |
| 1976 | |
| 1977 | |
| 1978 | # API Test function: PUT ​/data-consumer/v1/info-jobs/{infoJobId} |
| 1979 | # args: <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ] |
| 1980 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 1981 | ics_api_idc_put_job() { |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 1982 | __log_test_start $@ |
| 1983 | |
| 1984 | if [ $# -lt 7 ] || [ $# -gt 8 ]; then |
| 1985 | __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]" $@ |
| 1986 | return 1 |
| 1987 | fi |
| 1988 | if [ -f $7 ]; then |
| 1989 | jobfile=$(cat $7) |
| 1990 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g") |
| 1991 | else |
| 1992 | __log_test_fail_general "Job template file "$7", does not exist" |
| 1993 | return 1 |
| 1994 | fi |
| 1995 | |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 1996 | inputJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}" |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 1997 | file="./tmp/.p.json" |
| 1998 | echo "$inputJson" > $file |
| 1999 | |
| 2000 | query="/data-consumer/v1/info-jobs/$2" |
| 2001 | |
| 2002 | if [ $# -eq 8 ]; then |
| 2003 | if [ $8 == "VALIDATE" ]; then |
| 2004 | query=$query"?typeCheck=true" |
| 2005 | fi |
| 2006 | fi |
| 2007 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2008 | res="$(__do_curl_to_api ICS PUT $query $file)" |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 2009 | status=${res:${#res}-3} |
| 2010 | |
| 2011 | if [ $status -ne $1 ]; then |
| 2012 | __log_test_fail_status_code $1 $status |
| 2013 | return 1 |
| 2014 | fi |
| 2015 | |
| 2016 | __log_test_pass |
| 2017 | return 0 |
| 2018 | } |
| 2019 | |
| 2020 | # API Test function: DELETE ​/data-consumer/v1/info-jobs/{infoJobId} |
| 2021 | # args: <response-code> <job-id> |
| 2022 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2023 | ics_api_idc_delete_job() { |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 2024 | __log_test_start $@ |
| 2025 | |
| 2026 | if [ $# -ne 2 ]; then |
| 2027 | __print_err "<response-code> <job-id>" $@ |
| 2028 | return 1 |
| 2029 | fi |
| 2030 | query="/data-consumer/v1/info-jobs/$2" |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2031 | res="$(__do_curl_to_api ICS DELETE $query)" |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 2032 | status=${res:${#res}-3} |
| 2033 | |
| 2034 | if [ $status -ne $1 ]; then |
| 2035 | __log_test_fail_status_code $1 $status |
| 2036 | return 1 |
| 2037 | fi |
| 2038 | |
| 2039 | __log_test_pass |
| 2040 | return 0 |
| 2041 | } |
| 2042 | |
| 2043 | # API Test function: GET ​/data-consumer/v1/info-types/{infoTypeId} |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 2044 | # args: <response-code> <type-id> [<schema-file> [<type-status> <producers-count]] |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 2045 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2046 | ics_api_idc_get_type() { |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 2047 | __log_test_start $@ |
| 2048 | |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 2049 | if [ $# -lt 2 ] || [ $# -gt 5 ]; then |
| 2050 | __print_err "<response-code> <type-id> [<schema-file> [<type-status> <producers-count]]" $@ |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 2051 | return 1 |
| 2052 | fi |
| 2053 | |
| 2054 | query="/data-consumer/v1/info-types/$2" |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2055 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 2056 | status=${res:${#res}-3} |
| 2057 | |
| 2058 | if [ $status -ne $1 ]; then |
| 2059 | __log_test_fail_status_code $1 $status |
| 2060 | return 1 |
| 2061 | fi |
| 2062 | |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 2063 | if [ $# -gt 2 ]; then |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 2064 | body=${res:0:${#res}-3} |
| 2065 | if [ -f $3 ]; then |
| 2066 | schema=$(cat $3) |
| 2067 | else |
| 2068 | __log_test_fail_general "Schema file "$3", does not exist" |
| 2069 | return 1 |
| 2070 | fi |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 2071 | if [ $# -eq 5 ]; then |
| 2072 | targetJson="{\"job_data_schema\":$schema, \"type_status\":\"$4\", \"no_of_producers\":$5}" |
| 2073 | else |
| 2074 | targetJson="{\"job_data_schema\":$schema}" |
| 2075 | fi |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 2076 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 2077 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 2078 | |
| 2079 | if [ $res -ne 0 ]; then |
| 2080 | __log_test_fail_body |
| 2081 | return 1 |
| 2082 | fi |
| 2083 | fi |
| 2084 | |
| 2085 | __log_test_pass |
| 2086 | return 0 |
| 2087 | } |
| 2088 | |
| 2089 | # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status |
BjornMagnussonXA | e45cd2c | 2021-06-18 09:00:49 +0200 | [diff] [blame] | 2090 | # This test only status during an optional timeout. No test of the list of producers |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 2091 | # args: <response-code> <job-id> [<status> [<timeout>]] |
| 2092 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2093 | ics_api_idc_get_job_status() { |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 2094 | __log_test_start $@ |
| 2095 | |
| 2096 | if [ $# -lt 2 ] && [ $# -gt 4 ]; then |
| 2097 | __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@ |
| 2098 | return 1 |
| 2099 | fi |
| 2100 | |
| 2101 | query="/data-consumer/v1/info-jobs/$2/status" |
| 2102 | |
| 2103 | start=$SECONDS |
| 2104 | for (( ; ; )); do |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2105 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 2106 | status=${res:${#res}-3} |
| 2107 | |
| 2108 | if [ $# -eq 4 ]; then |
| 2109 | duration=$((SECONDS-start)) |
| 2110 | echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}" |
| 2111 | if [ $duration -gt $4 ]; then |
| 2112 | echo "" |
| 2113 | duration=-1 #Last iteration |
| 2114 | fi |
| 2115 | else |
| 2116 | duration=-1 #single test, no wait |
| 2117 | fi |
| 2118 | |
| 2119 | if [ $status -ne $1 ]; then |
| 2120 | if [ $duration -eq -1 ]; then |
| 2121 | __log_test_fail_status_code $1 $status |
| 2122 | return 1 |
| 2123 | fi |
| 2124 | fi |
| 2125 | if [ $# -ge 3 ] && [ $status -eq $1 ]; then |
| 2126 | body=${res:0:${#res}-3} |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 2127 | targetJson="{\"info_job_status\": \"$3\"}" |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 2128 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 2129 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 2130 | |
| 2131 | if [ $res -ne 0 ]; then |
| 2132 | if [ $duration -eq -1 ]; then |
| 2133 | __log_test_fail_body |
| 2134 | return 1 |
| 2135 | fi |
| 2136 | else |
| 2137 | duration=-1 #Goto pass |
| 2138 | fi |
| 2139 | fi |
| 2140 | if [ $duration -eq -1 ]; then |
| 2141 | if [ $# -eq 4 ]; then |
| 2142 | echo "" |
| 2143 | fi |
| 2144 | __log_test_pass |
| 2145 | return 0 |
| 2146 | else |
| 2147 | sleep 1 |
| 2148 | fi |
| 2149 | done |
| 2150 | |
| 2151 | __log_test_pass |
| 2152 | return 0 |
| 2153 | } |
| 2154 | |
BjornMagnussonXA | e45cd2c | 2021-06-18 09:00:49 +0200 | [diff] [blame] | 2155 | # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status |
| 2156 | # This function test status and the list of producers with and optional timeout |
| 2157 | # args: <response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]] |
| 2158 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2159 | ics_api_idc_get_job_status2() { |
BjornMagnussonXA | e45cd2c | 2021-06-18 09:00:49 +0200 | [diff] [blame] | 2160 | |
| 2161 | __log_test_start $@ |
| 2162 | param_error=0 |
| 2163 | if [ $# -lt 2 ]; then |
| 2164 | param_error=1 |
| 2165 | fi |
| 2166 | args=("$@") |
| 2167 | timeout=0 |
| 2168 | if [ $# -gt 2 ]; then |
| 2169 | if [ $# -lt 4 ]; then |
| 2170 | param_error=1 |
| 2171 | fi |
| 2172 | targetJson="{\"info_job_status\": \"$3\"" |
| 2173 | if [ "$4" == "EMPTYPROD" ]; then |
| 2174 | targetJson=$targetJson",\"producers\": []}" |
| 2175 | if [ $# -gt 4 ]; then |
| 2176 | timeout=$5 |
| 2177 | fi |
| 2178 | else |
| 2179 | targetJson=$targetJson",\"producers\": [" |
| 2180 | if [ $# -eq $(($4+5)) ]; then |
| 2181 | idx=$(($4+4)) |
| 2182 | timeout=${args[$idx]} |
| 2183 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2184 | for ((ics_i = 0 ; ics_i < $4 ; ics_i++)); do |
| 2185 | idx=$(($ics_i+4)) |
| 2186 | if [ $ics_i -gt 0 ]; then |
BjornMagnussonXA | e45cd2c | 2021-06-18 09:00:49 +0200 | [diff] [blame] | 2187 | targetJson=$targetJson"," |
| 2188 | fi |
| 2189 | targetJson=$targetJson"\""${args[$idx]}"\"" |
| 2190 | done |
| 2191 | targetJson=$targetJson"]}" |
| 2192 | fi |
| 2193 | fi |
| 2194 | |
| 2195 | if [ $param_error -ne 0 ]; then |
| 2196 | __print_err "<response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]" $@ |
| 2197 | return 1 |
| 2198 | fi |
| 2199 | |
| 2200 | query="/data-consumer/v1/info-jobs/$2/status" |
| 2201 | |
| 2202 | start=$SECONDS |
| 2203 | for (( ; ; )); do |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2204 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | e45cd2c | 2021-06-18 09:00:49 +0200 | [diff] [blame] | 2205 | status=${res:${#res}-3} |
| 2206 | |
| 2207 | if [ $# -gt 2 ]; then |
| 2208 | duration=$((SECONDS-start)) |
| 2209 | echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}" |
| 2210 | if [ $duration -gt $timeout ]; then |
| 2211 | echo "" |
| 2212 | duration=-1 #Last iteration |
| 2213 | fi |
| 2214 | else |
| 2215 | duration=-1 #single test, no wait |
| 2216 | fi |
| 2217 | |
| 2218 | if [ $status -ne $1 ]; then |
| 2219 | if [ $duration -eq -1 ]; then |
| 2220 | __log_test_fail_status_code $1 $status |
| 2221 | return 1 |
| 2222 | fi |
| 2223 | fi |
| 2224 | if [ $# -gt 2 ] && [ $status -eq $1 ]; then |
| 2225 | body=${res:0:${#res}-3} |
| 2226 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 2227 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 2228 | |
| 2229 | if [ $res -ne 0 ]; then |
| 2230 | if [ $duration -eq -1 ]; then |
| 2231 | __log_test_fail_body |
| 2232 | return 1 |
| 2233 | fi |
| 2234 | else |
| 2235 | duration=-1 #Goto pass |
| 2236 | fi |
| 2237 | fi |
| 2238 | if [ $duration -eq -1 ]; then |
| 2239 | if [ $# -eq 4 ]; then |
| 2240 | echo "" |
| 2241 | fi |
| 2242 | __log_test_pass |
| 2243 | return 0 |
| 2244 | else |
| 2245 | sleep 1 |
| 2246 | fi |
| 2247 | done |
| 2248 | |
| 2249 | __log_test_pass |
| 2250 | return 0 |
| 2251 | } |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 2252 | |
| 2253 | ########################################## |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 2254 | #### Type subscriptions #### |
| 2255 | ########################################## |
| 2256 | |
| 2257 | # API Test function: GET /data-consumer/v1/info-type-subscription |
| 2258 | # args: <response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+] |
| 2259 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2260 | ics_api_idc_get_subscription_ids() { |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 2261 | __log_test_start $@ |
| 2262 | |
| 2263 | if [ $# -lt 3 ]; then |
| 2264 | __print_err "<response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]" $@ |
| 2265 | return 1 |
| 2266 | fi |
| 2267 | |
| 2268 | query="/data-consumer/v1/info-type-subscription" |
| 2269 | search="" |
| 2270 | if [ $2 != "NOOWNER" ]; then |
| 2271 | search="?owner="$2 |
| 2272 | fi |
| 2273 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2274 | res="$(__do_curl_to_api ICS GET $query$search)" |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 2275 | status=${res:${#res}-3} |
| 2276 | |
| 2277 | if [ $status -ne $1 ]; then |
| 2278 | __log_test_fail_status_code $1 $status |
| 2279 | return 1 |
| 2280 | fi |
| 2281 | |
| 2282 | if [ $# -gt 2 ]; then |
| 2283 | body=${res:0:${#res}-3} |
| 2284 | targetJson="[" |
| 2285 | if [ $3 != "EMPTY" ]; then |
| 2286 | for pid in ${@:3} ; do |
| 2287 | if [ "$targetJson" != "[" ]; then |
| 2288 | targetJson=$targetJson"," |
| 2289 | fi |
| 2290 | targetJson=$targetJson"\"$pid\"" |
| 2291 | done |
| 2292 | fi |
| 2293 | targetJson=$targetJson"]" |
| 2294 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 2295 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 2296 | |
| 2297 | if [ $res -ne 0 ]; then |
| 2298 | __log_test_fail_body |
| 2299 | return 1 |
| 2300 | fi |
| 2301 | fi |
| 2302 | |
| 2303 | __log_test_pass |
| 2304 | return 0 |
| 2305 | } |
| 2306 | |
| 2307 | # API Test function: GET /data-consumer/v1/info-type-subscription/{subscriptionId} |
| 2308 | # args: <response-code> <subscription-id> [ <owner-id> <status-uri> ] |
| 2309 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2310 | ics_api_idc_get_subscription() { |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 2311 | __log_test_start $@ |
| 2312 | |
| 2313 | if [ $# -ne 2 ] && [ $# -ne 4 ]; then |
| 2314 | __print_err "<response-code> <subscription-id> [ <owner-id> <status-uri> ]" $@ |
| 2315 | return 1 |
| 2316 | fi |
| 2317 | |
| 2318 | query="/data-consumer/v1/info-type-subscription/$2" |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2319 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 2320 | status=${res:${#res}-3} |
| 2321 | |
| 2322 | if [ $status -ne $1 ]; then |
| 2323 | __log_test_fail_status_code $1 $status |
| 2324 | return 1 |
| 2325 | fi |
| 2326 | |
| 2327 | if [ $# -gt 2 ]; then |
| 2328 | body=${res:0:${#res}-3} |
| 2329 | targetJson="{\"owner\":\"$3\",\"status_result_uri\":\"$4\"}" |
| 2330 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 2331 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 2332 | |
| 2333 | if [ $res -ne 0 ]; then |
| 2334 | __log_test_fail_body |
| 2335 | return 1 |
| 2336 | fi |
| 2337 | fi |
| 2338 | |
| 2339 | __log_test_pass |
| 2340 | return 0 |
| 2341 | } |
| 2342 | |
| 2343 | # API Test function: PUT /data-consumer/v1/info-type-subscription/{subscriptionId} |
| 2344 | # args: <response-code> <subscription-id> <owner-id> <status-uri> |
| 2345 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2346 | ics_api_idc_put_subscription() { |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 2347 | __log_test_start $@ |
| 2348 | |
| 2349 | if [ $# -ne 4 ]; then |
| 2350 | __print_err "<response-code> <subscription-id> <owner-id> <status-uri>" $@ |
| 2351 | return 1 |
| 2352 | fi |
| 2353 | |
| 2354 | inputJson="{\"owner\": \"$3\",\"status_result_uri\": \"$4\"}" |
| 2355 | file="./tmp/.p.json" |
| 2356 | echo "$inputJson" > $file |
| 2357 | |
| 2358 | query="/data-consumer/v1/info-type-subscription/$2" |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2359 | res="$(__do_curl_to_api ICS PUT $query $file)" |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 2360 | status=${res:${#res}-3} |
| 2361 | |
| 2362 | if [ $status -ne $1 ]; then |
| 2363 | __log_test_fail_status_code $1 $status |
| 2364 | return 1 |
| 2365 | fi |
| 2366 | |
| 2367 | __log_test_pass |
| 2368 | return 0 |
| 2369 | } |
| 2370 | |
| 2371 | # API Test function: DELETE /data-consumer/v1/info-type-subscription/{subscriptionId} |
| 2372 | # args: <response-code> <subscription-id> |
| 2373 | # (Function for test scripts) |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2374 | ics_api_idc_delete_subscription() { |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 2375 | __log_test_start $@ |
| 2376 | |
| 2377 | if [ $# -ne 2 ]; then |
| 2378 | __print_err "<response-code> <subscription-id> " $@ |
| 2379 | return 1 |
| 2380 | fi |
| 2381 | |
| 2382 | query="/data-consumer/v1/info-type-subscription/$2" |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2383 | res="$(__do_curl_to_api ICS DELETE $query)" |
BjornMagnussonXA | 3cc0b58 | 2021-08-30 10:46:41 +0200 | [diff] [blame] | 2384 | status=${res:${#res}-3} |
| 2385 | |
| 2386 | if [ $status -ne $1 ]; then |
| 2387 | __log_test_fail_status_code $1 $status |
| 2388 | return 1 |
| 2389 | fi |
| 2390 | |
| 2391 | __log_test_pass |
| 2392 | return 0 |
| 2393 | } |
| 2394 | |
| 2395 | ########################################## |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 2396 | #### Reset jobs #### |
| 2397 | ########################################## |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2398 | # Function prefix: ics_api_admin |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 2399 | |
| 2400 | # Admin to remove all jobs |
BjornMagnussonXA | 366e36a | 2021-01-27 11:48:56 +0100 | [diff] [blame] | 2401 | # args: <response-code> [ <type> ] |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 2402 | # (Function for test scripts) |
| 2403 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2404 | ics_api_admin_reset() { |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 2405 | __log_test_start $@ |
| 2406 | |
| 2407 | if [ -z "$FLAT_A1_EI" ]; then |
| 2408 | query="/A1-EI/v1/eitypes/$2/eijobs" |
| 2409 | else |
| 2410 | query="/A1-EI/v1/eijobs" |
| 2411 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2412 | res="$(__do_curl_to_api ICS GET $query)" |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 2413 | status=${res:${#res}-3} |
| 2414 | |
| 2415 | if [ $status -ne 200 ]; then |
| 2416 | __log_test_fail_status_code $1 $status |
| 2417 | return 1 |
| 2418 | fi |
| 2419 | |
| 2420 | #Remove brackets and response code |
| 2421 | body=${res:1:${#res}-4} |
| 2422 | list=$(echo ${body//,/ }) |
| 2423 | list=$(echo ${list//[/}) |
| 2424 | list=$(echo ${list//]/}) |
| 2425 | list=$(echo ${list//\"/}) |
| 2426 | list=$list" " |
| 2427 | for job in $list; do |
| 2428 | if [ -z "$FLAT_A1_EI" ]; then |
| 2429 | echo "Not supported for non-flat EI api" |
| 2430 | else |
| 2431 | query="/A1-EI/v1/eijobs/$job" |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2432 | res="$(__do_curl_to_api ICS DELETE $query)" |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 2433 | status=${res:${#res}-3} |
| 2434 | if [ $status -ne 204 ]; then |
| 2435 | __log_test_fail_status_code $1 $status |
| 2436 | return 1 |
| 2437 | fi |
| 2438 | echo " Deleted job: "$job |
| 2439 | fi |
| 2440 | done |
| 2441 | |
| 2442 | __log_test_pass |
| 2443 | return 0 |
BjornMagnussonXA | a549157 | 2021-05-04 09:21:24 +0200 | [diff] [blame] | 2444 | } |
| 2445 | |
| 2446 | ########################################## |
| 2447 | #### Reset jobs and producers #### |
| 2448 | ########################################## |
| 2449 | |
| 2450 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2451 | # Admin reset to remove all data in ics; jobs, producers etc |
BjornMagnussonXA | a549157 | 2021-05-04 09:21:24 +0200 | [diff] [blame] | 2452 | # NOTE - only works in kubernetes and the pod should not be running |
| 2453 | # args: - |
| 2454 | # (Function for test scripts) |
| 2455 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2456 | ics_kube_pvc_reset() { |
BjornMagnussonXA | a549157 | 2021-05-04 09:21:24 +0200 | [diff] [blame] | 2457 | __log_test_start $@ |
| 2458 | |
BjornMagnussonXA | cb6113e | 2022-02-17 15:01:28 +0100 | [diff] [blame] | 2459 | pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep information) |
BjornMagnussonXA | 6f9c2b2 | 2021-06-11 16:31:40 +0200 | [diff] [blame] | 2460 | if [ -z "$pvc_name" ]; then |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2461 | pvc_name=informationservice-pvc |
BjornMagnussonXA | 6f9c2b2 | 2021-06-11 16:31:40 +0200 | [diff] [blame] | 2462 | fi |
| 2463 | echo " Trying to reset pvc: "$pvc_name |
| 2464 | |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 2465 | __kube_clean_pvc $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $ICS_CONTAINER_MNT_DIR |
BjornMagnussonXA | a549157 | 2021-05-04 09:21:24 +0200 | [diff] [blame] | 2466 | |
| 2467 | __log_test_pass |
| 2468 | return 0 |
BjornMagnussonXA | 145762b | 2022-03-22 10:35:10 +0100 | [diff] [blame^] | 2469 | } |
| 2470 | |
| 2471 | # args: <realm> <client-name> <client-secret> |
| 2472 | ics_configure_sec() { |
| 2473 | export ICS_CREDS_GRANT_TYPE="client_credentials" |
| 2474 | export ICS_CREDS_CLIENT_SECRET=$3 |
| 2475 | export ICS_CREDS_CLIENT_ID=$2 |
| 2476 | export ICS_AUTH_SERVICE_URL=$KEYCLOAK_SERVICE_PATH$KEYCLOAK_TOKEN_URL_PREFIX/$1/protocol/openid-connect/token |
| 2477 | export ICS_SIDECAR_MOUNT="/token-cache" |
| 2478 | export ICS_SIDECAR_JWT_FILE=$ICS_SIDECAR_MOUNT"/jwt.txt" |
| 2479 | |
| 2480 | export AUTHSIDECAR_APP_NAME |
| 2481 | export AUTHSIDECAR_DISPLAY_NAME |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 2482 | } |