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