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