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