blob: 2152de9e3000d7213bf489f3af2041d9eb9de20e [file] [log] [blame]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001#!/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
BjornMagnussonXA007b6452021-11-29 08:03:38 +010020# This is a script that contains container/service management functions and test functions for ICS
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020021
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010022################ 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
BjornMagnussonXA007b6452021-11-29 08:03:38 +010027__ICS_imagesetup() {
28 __check_and_create_image_var ICS "ICS_IMAGE" "ICS_IMAGE_BASE" "ICS_IMAGE_TAG" $1 "$ICS_DISPLAY_NAME"
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010029}
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'
BjornMagnussonXA007b6452021-11-29 08:03:38 +010036__ICS_imagepull() {
37 __check_and_pull_image $1 "$ICS_DISPLAY_NAME" $ICS_APP_NAME ICS_IMAGE
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010038}
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
BjornMagnussonXA007b6452021-11-29 08:03:38 +010043__ICS_imagebuild() {
44 echo -e $RED" Image for app ICS shall never be built"$ERED
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010045}
46
47# Generate a string for each included image using the app display name and a docker images format string
BjornMagnussonXA483ee332021-04-08 01:35:24 +020048# If a custom image repo is used then also the source image from the local repo is listed
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010049# arg: <docker-images-format-string> <file-to-append>
BjornMagnussonXA007b6452021-11-29 08:03:38 +010050__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
BjornMagnussonXA483ee332021-04-08 01:35:24 +020054 fi
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010055}
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
BjornMagnussonXA007b6452021-11-29 08:03:38 +010060__ICS_kube_scale_zero() {
61 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ICS
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010062}
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.
BjornMagnussonXA007b6452021-11-29 08:03:38 +010066__ICS_kube_scale_zero_and_wait() {
67 __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app "$KUBE_NONRTRIC_NAMESPACE"-informationservice
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010068}
69
70# Delete all kube resouces for the app
71# This function is called for apps managed by the test script.
BjornMagnussonXA007b6452021-11-29 08:03:38 +010072__ICS_kube_delete_all() {
73 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ICS
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010074}
75
76# Store docker logs
77# This function is called for apps managed by the test script.
78# args: <log-dir> <file-prexix>
BjornMagnussonXA007b6452021-11-29 08:03:38 +010079__ICS_store_docker_logs() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +010080 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAcb6113e2022-02-17 15:01:28 +010081 kubectl $KUBECONF logs -l "autotest=ICS" -n $KUBE_NONRTRIC_NAMESPACE --tail=-1 > $1$2_ics.log 2>&1
BjornMagnussonXA663566c2021-11-08 10:25:07 +010082 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +010083 docker logs $ICS_APP_NAME > $1$2_ics.log 2>&1
BjornMagnussonXA663566c2021-11-08 10:25:07 +010084 fi
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010085}
BjornMagnussonXA663566c2021-11-08 10:25:07 +010086
87# Initial setup of protocol, host and ports
88# This function is called for apps managed by the test script.
89# args: -
BjornMagnussonXA007b6452021-11-29 08:03:38 +010090__ICS_initial_setup() {
91 use_ics_rest_http
BjornMagnussonXA145762b2022-03-22 10:35:10 +010092 export ICS_SIDECAR_JWT_FILE=""
BjornMagnussonXA663566c2021-11-08 10:25:07 +010093}
94
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +010095# Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers
96# For docker, the namespace shall be excluded
97# This function is called for apps managed by the test script as well as for prestarted apps.
98# args: -
BjornMagnussonXA007b6452021-11-29 08:03:38 +010099__ICS_statisics_setup() {
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100100 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100101 echo "ICS $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE"
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100102 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100103 echo "ICS $ICS_APP_NAME"
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100104 fi
105}
106
BjornMagnussonXAe60d04e2021-12-27 13:38:01 +0100107# Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
108# args: -
109__ICS_test_requirements() {
110 :
111}
112
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100113#######################################################
114
115
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100116# Make curl retries towards ICS for http response codes set in this env var, space separated list of codes
117ICS_RETRY_CODES=""
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100118
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200119#Save first worker node the pod is started on
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100120__ICS_WORKER_NODE=""
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200121
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100122###########################
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100123### ICS functions
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100124###########################
125
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100126# All calls to ICS will be directed to the ICS REST interface from now on
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100127# args: -
128# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100129use_ics_rest_http() {
130 __ics_set_protocoll "http" $ICS_INTERNAL_PORT $ICS_EXTERNAL_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100131}
132
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100133# All calls to ICS will be directed to the ICS REST interface from now on
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100134# args: -
135# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100136use_ics_rest_https() {
137 __ics_set_protocoll "https" $ICS_INTERNAL_SECURE_PORT $ICS_EXTERNAL_SECURE_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100138}
139
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100140# All calls to ICS will be directed to the ICS dmaap interface over http from now on
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100141# args: -
142# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100143use_ics_dmaap_http() {
144 echo -e $BOLD"ICS dmaap protocol setting"$EBOLD
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100145 echo -e $RED" - NOT SUPPORTED - "$ERED
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100146 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ICS"
147 ICS_ADAPTER_TYPE="MR-HTTP"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100148 echo ""
149}
150
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100151# Setup paths to svc/container for internal and external access
152# args: <protocol> <internal-port> <external-port>
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100153__ics_set_protocoll() {
154 echo -e $BOLD"$ICS_DISPLAY_NAME protocol setting"$EBOLD
155 echo -e " Using $BOLD $1 $EBOLD towards $ICS_DISPLAY_NAME"
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100156
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100157 ## Access to ICS
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100158
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100159 ICS_SERVICE_PATH=$1"://"$ICS_APP_NAME":"$2 # docker access, container->container and script->container via proxy
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100160 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100161 ICS_SERVICE_PATH=$1"://"$ICS_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100162 fi
163
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100164 # ICS_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
165 ICS_ADAPTER_TYPE="REST"
166 ICS_ADAPTER=$ICS_SERVICE_PATH
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100167
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100168 echo ""
169}
170
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100171# Export env vars for config files, docker compose and kube resources
172# args: PROXY|NOPROXY
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100173__ics_export_vars() {
174 export ICS_APP_NAME
175 export ICS_APP_NAME_ALIAS
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100176 export KUBE_NONRTRIC_NAMESPACE
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100177 export ICS_IMAGE
178 export ICS_INTERNAL_PORT
179 export ICS_INTERNAL_SECURE_PORT
180 export ICS_EXTERNAL_PORT
181 export ICS_EXTERNAL_SECURE_PORT
182 export ICS_CONFIG_MOUNT_PATH
183 export ICS_CONFIG_CONFIGMAP_NAME=$ICS_APP_NAME"-config"
184 export ICS_DATA_CONFIGMAP_NAME=$ICS_APP_NAME"-data"
185 export ICS_CONTAINER_MNT_DIR
186 export ICS_HOST_MNT_DIR
187 export ICS_CONFIG_FILE
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100188 export DOCKER_SIM_NWNAME
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100189 export ICS_DISPLAY_NAME
BjornMagnussonXA05bfe482021-12-02 08:47:41 +0100190 export ICS_LOGPATH
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100191
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100192 export ICS_DATA_PV_NAME=$ICS_APP_NAME"-pv"
193 export ICS_DATA_PVC_NAME=$ICS_APP_NAME"-pvc"
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100194 #Create a unique path for the pv each time to prevent a previous volume to be reused
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100195 export ICS_PV_PATH="icsdata-"$(date +%s)
BjornMagnussonXAc8f92e92022-02-28 15:16:37 +0100196 export HOST_PATH_BASE_DIR
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100197
198 if [ $1 == "PROXY" ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100199 export ICS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
200 export ICS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
201 if [ $ICS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ICS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100202 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
203 else
204 echo " Configured with http proxy"
205 fi
206 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100207 export ICS_HTTP_PROXY_CONFIG_PORT=0
208 export ICS_HTTP_PROXY_CONFIG_HOST_NAME=""
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100209 echo " Configured without http proxy"
210 fi
211}
212
213
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100214# Start the ICS
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100215# args: PROXY|NOPROXY <config-file>
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100216# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100217start_ics() {
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100218
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100219 echo -e $BOLD"Starting $ICS_DISPLAY_NAME"$EBOLD
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100220
221 if [ $RUNMODE == "KUBE" ]; then
222
223 # Check if app shall be fully managed by the test script
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100224 __check_included_image "ICS"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100225 retcode_i=$?
226
227 # Check if app shall only be used by the testscipt
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100228 __check_prestarted_image "ICS"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100229 retcode_p=$?
230
231 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100232 echo -e $RED"The $ICS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
233 echo -e $RED"The $ICS_APP_NAME will not be started"$ERED
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100234 exit
235 fi
236 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100237 echo -e $RED"The $ICS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
238 echo -e $RED"The $ICS_APP_NAME will not be started"$ERED
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100239 exit
240 fi
241
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100242 if [ $retcode_p -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100243 echo -e " Using existing $ICS_APP_NAME deployment and service"
244 echo " Setting ICS replicas=1"
245 res_type=$(__kube_get_resource_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
246 __kube_scale $res_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100247 fi
248
249 # Check if app shall be fully managed by the test script
250 if [ $retcode_i -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100251 echo -e " Creating $ICS_APP_NAME app and expose service"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100252
253 #Check if nonrtric namespace exists, if not create it
254 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
255
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100256 __ics_export_vars $1
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100257
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100258 # Create config map for config
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100259 datafile=$PWD/tmp/$ICS_CONFIG_FILE
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100260 cp $2 $datafile
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100261 output_yaml=$PWD/tmp/ics_cfc.yaml
262 __kube_create_configmap $ICS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ICS $datafile $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100263
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100264 # Create pv
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100265 input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"pv.yaml
266 output_yaml=$PWD/tmp/ics_pv.yaml
267 __kube_create_instance pv $ICS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100268
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100269 # Create pvc
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100270 input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"pvc.yaml
271 output_yaml=$PWD/tmp/ics_pvc.yaml
272 __kube_create_instance pvc $ICS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100273
274 # Create service
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100275 input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"svc.yaml
276 output_yaml=$PWD/tmp/ics_svc.yaml
277 __kube_create_instance service $ICS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100278
279 # Create app
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100280 input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"app.yaml
281 output_yaml=$PWD/tmp/ics_app.yaml
BjornMagnussonXA145762b2022-03-22 10:35:10 +0100282 if [ -z "$ICS_SIDECAR_JWT_FILE" ]; then
283 cat $input_yaml | sed '/#ICS_JWT_START/,/#ICS_JWT_STOP/d' > $PWD/tmp/ics_app_tmp.yaml
284 input_yaml=$PWD/tmp/ics_app_tmp.yaml
285 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100286 __kube_create_instance app $ICS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100287 fi
288
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100289 # Tie the ICS to a worker node so that ICS will always be scheduled to the same worker node if the ICS pod is restarted
290 # A PVC of type hostPath is mounted to ICS, for persistent storage, so the ICS must always be on the node which mounted the volume
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200291
292 # Keep the initial worker node in case the pod need to be "restarted" - must be made to the same node due to a volume mounted on the host
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200293 if [ $retcode_i -eq 0 ]; then
BjornMagnussonXAc8f92e92022-02-28 15:16:37 +0100294 __ICS_WORKER_NODE=$(kubectl $KUBECONF get pod -l "autotest=ICS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100295 if [ -z "$__ICS_WORKER_NODE" ]; then
296 echo -e $YELLOW" Cannot find worker node for pod for $ICS_APP_NAME, persistency may not work"$EYELLOW
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200297 fi
298 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100299 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
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200300 fi
301
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100302
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100303 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100304
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100305 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100306 __check_included_image 'ICS'
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100307 if [ $? -eq 1 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100308 echo -e $RED"The ICS app is not included in this test script"$ERED
309 echo -e $RED"ICS will not be started"$ERED
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100310 exit 1
311 fi
312
313 curdir=$PWD
314 cd $SIM_GROUP
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100315 cd ics
316 cd $ICS_HOST_MNT_DIR
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100317 #cd ..
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100318 if [ -d db ]; then
319 if [ "$(ls -A $DIR)" ]; then
320 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
321 rm -rf db/* &> /dev/null
322 if [ $? -ne 0 ]; then
323 echo -e $RED" Cannot remove database files in: $PWD"$ERED
324 exit 1
325 fi
326 fi
327 else
328 echo " No files in mounted dir or dir does not exists"
329 fi
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100330
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100331 cd $curdir
332
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100333 __ics_export_vars $1
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100334
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100335 dest_file=$SIM_GROUP/$ICS_COMPOSE_DIR/$ICS_HOST_MNT_DIR/$ICS_CONFIG_FILE
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100336
337 envsubst < $2 > $dest_file
338
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100339 __start_container $ICS_COMPOSE_DIR "" NODOCKERARGS 1 $ICS_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100340
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100341 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100342 fi
343 echo ""
344 return 0
345}
346
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100347# Stop the ics
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200348# args: -
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100349# args: -
350# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100351stop_ics() {
352 echo -e $BOLD"Stopping $ICS_DISPLAY_NAME"$EBOLD
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200353
354 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200355
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100356 __check_prestarted_image "ICS"
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200357 if [ $? -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100358 echo -e $YELLOW" Persistency may not work for app $ICS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
359 res_type=$(__kube_get_resource_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
360 __kube_scale $res_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200361 return 0
362 fi
363
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100364 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ICS
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200365 echo " Deleting the replica set - a new will be started when the app is started"
BjornMagnussonXAcb6113e2022-02-17 15:01:28 +0100366 tmp=$(kubectl $KUBECONF delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=ICS")
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200367 if [ $? -ne 0 ]; then
368 echo -e $RED" Could not delete replica set "$RED
369 ((RES_CONF_FAIL++))
370 return 1
371 fi
372 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100373 docker stop $ICS_APP_NAME &> ./tmp/.dockererr
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200374 if [ $? -ne 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100375 __print_err "Could not stop $ICS_APP_NAME" $@
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200376 cat ./tmp/.dockererr
377 ((RES_CONF_FAIL++))
378 return 1
379 fi
380 fi
381 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
382 echo ""
383 return 0
384}
385
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100386# Start a previously stopped ics
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200387# args: -
388# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100389start_stopped_ics() {
390 echo -e $BOLD"Starting (the previously stopped) $ICS_DISPLAY_NAME"$EBOLD
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200391
392 if [ $RUNMODE == "KUBE" ]; then
393
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100394 __check_prestarted_image "ICS"
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200395 if [ $? -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100396 echo -e $YELLOW" Persistency may not work for app $ICS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
397 res_type=$(__kube_get_resource_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
398 __kube_scale $res_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
399 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200400 return 0
401 fi
402
BjornMagnussonXAc8f92e92022-02-28 15:16:37 +0100403 # Tie the ICS to the same worker node it was initially started on
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100404 # 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
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100405 if [ -z "$__ICS_WORKER_NODE" ]; then
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200406 echo -e $RED" No initial worker node found for pod "$RED
407 ((RES_CONF_FAIL++))
408 return 1
409 else
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100410 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
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200411 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
BjornMagnussonXAcb6113e2022-02-17 15:01:28 +0100412 tmp=$(kubectl $KUBECONF patch deployment $ICS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__ICS_WORKER_NODE'"}}}}}')
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200413 if [ $? -ne 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100414 echo -e $YELLOW" Cannot set nodeSelector to deployment for $ICS_APP_NAME, persistency may not work"$EYELLOW
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200415 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100416 __kube_scale deployment $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200417 fi
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200418 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100419 docker start $ICS_APP_NAME &> ./tmp/.dockererr
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200420 if [ $? -ne 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100421 __print_err "Could not start (the stopped) $ICS_APP_NAME" $@
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200422 cat ./tmp/.dockererr
423 ((RES_CONF_FAIL++))
424 return 1
425 fi
426 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100427 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100428 if [ $? -ne 0 ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100429 return 1
430 fi
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100431 echo ""
432 return 0
433}
434
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100435# Turn on debug level tracing in ICS
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100436# args: -
437# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100438set_ics_debug() {
439 echo -e $BOLD"Setting ics debug logging"$EBOLD
440 curlString="$ICS_SERVICE_PATH$ICS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100441 result=$(__do_curl "$curlString")
442 if [ $? -ne 0 ]; then
443 __print_err "Could not set debug mode" $@
444 ((RES_CONF_FAIL++))
445 return 1
446 fi
447 echo ""
448 return 0
449}
450
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100451# Turn on trace level tracing in ICS
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100452# args: -
453# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100454set_ics_trace() {
455 echo -e $BOLD"Setting ics trace logging"$EBOLD
BjornMagnussonXA145762b2022-03-22 10:35:10 +0100456 curlString="$ICS_SERVICE_PATH$ICS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100457 result=$(__do_curl "$curlString")
458 if [ $? -ne 0 ]; then
459 __print_err "Could not set trace mode" $@
460 ((RES_CONF_FAIL++))
461 return 1
462 fi
463 echo ""
464 return 0
465}
466
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100467# Perform curl retries when making direct call to ICS for the specified http response codes
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100468# Speace separated list of http response codes
469# args: [<response-code>]*
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100470use_ics_retries() {
471 echo -e $BOLD"Do curl retries to the ICS REST inteface for these response codes:$@"$EBOLD
472 ICS_RETRY_CODES=$@
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100473 echo ""
474 return 0
475}
476
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100477# Check the ics logs for WARNINGs and ERRORs
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100478# args: -
479# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100480check_ics_logs() {
481 __check_container_logs "ICS" $ICS_APP_NAME $ICS_LOGPATH WARN ERR
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100482}
483
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200484
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100485# Tests if a variable value in the ICS is equal to a target value and and optional timeout.
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100486# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
487# equal to the target or not.
488# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
489# before setting pass or fail depending on if the variable value becomes equal to the target
490# value or not.
491# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100492ics_equal() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100493 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100494 __var_test ICS "$ICS_SERVICE_PATH/" $1 "=" $2 $3
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100495 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100496 __print_err "Wrong args to ics_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100497 fi
498}
499
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200500
501##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100502######### A1-E information API ##########
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200503##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100504#Function prefix: ics_api_a1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200505
506# API Test function: GET /A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200507# args: <response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100508# args (flat uri structure): <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200509# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100510ics_api_a1_get_job_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100511 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200512
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100513 if [ -z "$FLAT_A1_EI" ]; then
514 # Valid number of parameters 4,5,6 etc
515 if [ $# -lt 3 ]; then
516 __print_err "<response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
517 return 1
518 fi
519 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100520 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100521 # Valid number of parameters 4,5,6 etc
522 if [ $# -lt 3 ]; then
523 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
524 return 1
525 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200526 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100527 search=""
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200528 if [ $3 != "NOWNER" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100529 search="?owner="$3
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200530 fi
531
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100532 if [ -z "$FLAT_A1_EI" ]; then
533 query="/A1-EI/v1/eitypes/$2/eijobs$search"
534 else
535 if [ $2 != "NOTYPE" ]; then
536 if [ -z "$search" ]; then
537 search="?eiTypeId="$2
538 else
539 search=$search"&eiTypeId="$2
540 fi
541 fi
542 query="/A1-EI/v1/eijobs$search"
543 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100544 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200545 status=${res:${#res}-3}
546
547 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100548 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200549 return 1
550 fi
551
552 if [ $# -gt 3 ]; then
553 body=${res:0:${#res}-3}
554 targetJson="["
555
556 for pid in ${@:4} ; do
557 if [ "$targetJson" != "[" ]; then
558 targetJson=$targetJson","
559 fi
560 if [ $pid != "EMPTY" ]; then
561 targetJson=$targetJson"\"$pid\""
562 fi
563 done
564
565 targetJson=$targetJson"]"
566 echo " TARGET JSON: $targetJson" >> $HTTPLOG
567 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
568
569 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100570 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200571 return 1
572 fi
573 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200574
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100575 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200576 return 0
577}
578
579# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200580# args: <response-code> <type-id> [<schema-file>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200581# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100582ics_api_a1_get_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100583 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200584
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200585 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
586 __print_err "<response-code> <type-id> [<schema-file>]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200587 return 1
588 fi
589
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200590 query="/A1-EI/v1/eitypes/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100591 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200592 status=${res:${#res}-3}
593
594 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100595 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200596 return 1
597 fi
598
599 if [ $# -eq 3 ]; then
600 body=${res:0:${#res}-3}
601 if [ -f $3 ]; then
602 schema=$(cat $3)
603 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100604 __log_test_fail_general "Schema file "$3", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200605 return 1
606 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100607 if [ -z "$FLAT_A1_EI" ]; then
608 targetJson="{\"eiJobParametersSchema\":$schema}"
609 else
610 targetJson=$schema
611 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200612 echo " TARGET JSON: $targetJson" >> $HTTPLOG
613 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
614
615 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100616 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200617 return 1
618 fi
619 fi
620
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100621 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200622 return 0
623}
624
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200625# API Test function: GET /A1-EI/v1/eitypes
626# args: <response-code> [ (EMPTY | [<type-id>]+) ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200627# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100628ics_api_a1_get_type_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100629 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200630
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200631 if [ $# -lt 1 ]; then
632 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200633 return 1
634 fi
635
636 query="/A1-EI/v1/eitypes"
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100637 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200638 status=${res:${#res}-3}
639
640 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100641 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200642 return 1
643 fi
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200644 if [ $# -gt 1 ]; then
645 body=${res:0:${#res}-3}
646 targetJson="["
647 if [ $2 != "EMPTY" ]; then
648 for pid in ${@:2} ; do
649 if [ "$targetJson" != "[" ]; then
650 targetJson=$targetJson","
651 fi
652 targetJson=$targetJson"\"$pid\""
653 done
654 fi
655 targetJson=$targetJson"]"
656 echo " TARGET JSON: $targetJson" >> $HTTPLOG
657 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200658
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200659 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100660 __log_test_fail_body
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200661 return 1
662 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200663 fi
664
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100665 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200666 return 0
667}
668
669# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200670# args: <response-code> <type-id> <job-id> [<status>]
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100671# args (flat uri structure): <response-code> <job-id> [<status> [<timeout>]]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200672# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100673ics_api_a1_get_job_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100674 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200675
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100676 if [ -z "$FLAT_A1_EI" ]; then
677 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
678 __print_err "<response-code> <type-id> <job-id> [<status>]" $@
679 return 1
680 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200681
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100682 query="/A1-EI/v1/eitypes/$2/eijobs/$3/status"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200683
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100684 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100685 status=${res:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200686
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100687 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100688 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200689 return 1
690 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100691 if [ $# -eq 4 ]; then
692 body=${res:0:${#res}-3}
693 targetJson="{\"operationalState\": \"$4\"}"
694 echo " TARGET JSON: $targetJson" >> $HTTPLOG
695 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
696
697 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100698 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100699 return 1
700 fi
701 fi
702 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100703 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100704 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
705 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100706 return 1
707 fi
708
709 query="/A1-EI/v1/eijobs/$2/status"
710
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100711 start=$SECONDS
712 for (( ; ; )); do
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100713 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100714 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100715
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100716 if [ $# -eq 4 ]; then
717 duration=$((SECONDS-start))
718 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
719 if [ $duration -gt $4 ]; then
720 echo ""
721 duration=-1 #Last iteration
722 fi
723 else
724 duration=-1 #single test, no wait
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100725 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100726
727 if [ $status -ne $1 ]; then
728 if [ $duration -eq -1 ]; then
729 __log_test_fail_status_code $1 $status
730 return 1
731 fi
732 fi
733 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
734 body=${res:0:${#res}-3}
735 targetJson="{\"eiJobStatus\": \"$3\"}"
736 echo " TARGET JSON: $targetJson" >> $HTTPLOG
737 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
738
739 if [ $res -ne 0 ]; then
740 if [ $duration -eq -1 ]; then
741 __log_test_fail_body
742 return 1
743 fi
744 else
745 duration=-1 #Goto pass
746 fi
747 fi
748 if [ $duration -eq -1 ]; then
749 if [ $# -eq 4 ]; then
750 echo ""
751 fi
752 __log_test_pass
753 return 0
754 else
755 sleep 1
756 fi
757 done
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200758 fi
759
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100760 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200761 return 0
762}
763
764# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200765# args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100766# args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200767# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100768ics_api_a1_get_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100769 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200770
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100771 if [ -z "$FLAT_A1_EI" ]; then
772 if [ $# -ne 3 ] && [ $# -ne 6 ]; then
773 __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@
774 return 1
775 fi
776 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
777 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100778 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100779 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
780 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
781 return 1
782 fi
783 query="/A1-EI/v1/eijobs/$2"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200784 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100785 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200786 status=${res:${#res}-3}
787
788 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100789 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200790 return 1
791 fi
792
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100793 if [ -z "$FLAT_A1_EI" ]; then
794 if [ $# -eq 6 ]; then
795 body=${res:0:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200796
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100797 if [ -f $6 ]; then
798 jobfile=$(cat $6)
799 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
800 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200801 __log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100802 return 1
803 fi
804 targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
805 echo " TARGET JSON: $targetJson" >> $HTTPLOG
806 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
807
808 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100809 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100810 return 1
811 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200812 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100813 else
814 if [ $# -eq 7 ]; then
815 body=${res:0:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200816
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100817 if [ -f $7 ]; then
818 jobfile=$(cat $7)
819 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
820 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200821 __log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100822 return 1
823 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100824 targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100825 echo " TARGET JSON: $targetJson" >> $HTTPLOG
826 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
827
828 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100829 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100830 return 1
831 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200832 fi
833 fi
834
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100835 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200836 return 0
837}
838
839# API Test function: DELETE ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200840# args: <response-code> <type-id> <job-id>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100841# args (flat uri structure): <response-code> <job-id>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200842# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100843ics_api_a1_delete_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100844 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200845
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100846 if [ -z "$FLAT_A1_EI" ]; then
847 if [ $# -ne 3 ]; then
848 __print_err "<response-code> <type-id> <job-id>" $@
849 return 1
850 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200851
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100852 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
853 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100854 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100855 if [ $# -ne 2 ]; then
856 __print_err "<response-code> <job-id>" $@
857 return 1
858 fi
859 query="/A1-EI/v1/eijobs/$2"
860 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100861 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200862 status=${res:${#res}-3}
863
864 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100865 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200866 return 1
867 fi
868
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100869 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200870 return 0
871}
872
873# API Test function: PUT ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200874# args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100875# args (flat uri structure): <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200876# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100877ics_api_a1_put_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100878 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200879
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100880 if [ -z "$FLAT_A1_EI" ]; then
881 if [ $# -lt 6 ]; then
882 __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@
883 return 1
884 fi
885 if [ -f $6 ]; then
886 jobfile=$(cat $6)
887 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
888 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200889 __log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100890 return 1
891 fi
892
893 inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
894 file="./tmp/.p.json"
895 echo "$inputJson" > $file
896
897 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200898 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100899 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100900 if [ $# -lt 7 ]; then
901 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@
902 return 1
903 fi
904 if [ -f $7 ]; then
905 jobfile=$(cat $7)
906 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
907 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200908 __log_test_fail_general "Job template file "$7", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100909 return 1
910 fi
911
912 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
913 file="./tmp/.p.json"
914 echo "$inputJson" > $file
915
916 query="/A1-EI/v1/eijobs/$2"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200917 fi
918
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100919 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200920 status=${res:${#res}-3}
921
922 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100923 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200924 return 1
925 fi
926
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100927 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200928 return 0
929}
930
931
932##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100933#### information Data Producer API ####
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200934##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100935# Function prefix: ics_api_edp
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200936
937# API Test function: GET /ei-producer/v1/eitypes
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200938# API Test function: GET /data-producer/v1/info-types
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200939# args: <response-code> [ EMPTY | <type-id>+]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200940# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100941ics_api_edp_get_type_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100942 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200943
944 if [ $# -lt 1 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200945 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200946 return 1
947 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100948 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200949 query="/data-producer/v1/info-types"
950 else
951 query="/ei-producer/v1/eitypes"
952 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100953 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200954 status=${res:${#res}-3}
955
956 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100957 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200958 return 1
959 fi
960
961 if [ $# -gt 1 ]; then
962 body=${res:0:${#res}-3}
963 targetJson="["
964 if [ $2 != "EMPTY" ]; then
965 for pid in ${@:2} ; do
966 if [ "$targetJson" != "[" ]; then
967 targetJson=$targetJson","
968 fi
969 targetJson=$targetJson"\"$pid\""
970 done
971 fi
972 targetJson=$targetJson"]"
973 echo " TARGET JSON: $targetJson" >> $HTTPLOG
974 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
975
976 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100977 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200978 return 1
979 fi
980 fi
981
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100982 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200983 return 0
984}
985
986# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200987# API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100988# args: <response-code> <producer-id> [<status> [<timeout>]]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200989# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100990ics_api_edp_get_producer_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100991 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200992
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100993 if [ $# -lt 2 ] || [ $# -gt 4 ]; then
994 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200995 return 1
996 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100997 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200998 query="/data-producer/v1/info-producers/$2/status"
999 else
1000 query="/ei-producer/v1/eiproducers/$2/status"
1001 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001002 start=$SECONDS
1003 for (( ; ; )); do
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001004 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001005 status=${res:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001006
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001007 if [ $# -eq 4 ]; then
1008 duration=$((SECONDS-start))
1009 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
1010 if [ $duration -gt $4 ]; then
1011 echo ""
1012 duration=-1 #Last iteration
1013 fi
1014 else
1015 duration=-1 #single test, no wait
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001016 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001017
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001018 if [ $status -ne $1 ]; then
1019 if [ $duration -eq -1 ]; then
1020 __log_test_fail_status_code $1 $status
1021 return 1
1022 fi
1023 fi
1024 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
1025 body=${res:0:${#res}-3}
1026 targetJson="{\"operational_state\": \"$3\"}"
1027 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1028 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1029
1030 if [ $res -ne 0 ]; then
1031 if [ $duration -eq -1 ]; then
1032 __log_test_fail_body
1033 return 1
1034 fi
1035 else
1036 duration=-1 #Goto pass
1037 fi
1038 fi
1039 if [ $duration -eq -1 ]; then
1040 if [ $# -eq 4 ]; then
1041 echo ""
1042 fi
1043 __log_test_pass
1044 return 0
1045 else
1046 sleep 1
1047 fi
1048 done
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001049}
1050
1051
1052# API Test function: GET /ei-producer/v1/eiproducers
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001053# args (v1_1): <response-code> [ EMPTY | <producer-id>+]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001054# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001055ics_api_edp_get_producer_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001056 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001057
1058 if [ $# -lt 1 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001059 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001060 return 1
1061 fi
1062
1063 query="/ei-producer/v1/eiproducers"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001064 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001065 status=${res:${#res}-3}
1066
1067 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001068 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001069 return 1
1070 fi
1071
1072 if [ $# -gt 1 ]; then
1073 body=${res:0:${#res}-3}
1074 targetJson="["
1075
1076 for pid in ${@:2} ; do
1077 if [ "$targetJson" != "[" ]; then
1078 targetJson=$targetJson","
1079 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001080 if [ $pid != "EMPTY" ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001081 targetJson=$targetJson"\"$pid\""
1082 fi
1083 done
1084
1085 targetJson=$targetJson"]"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001086 echo " TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001087 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1088
1089 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001090 __log_test_fail_body
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001091 return 1
1092 fi
1093 fi
1094
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001095 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001096 return 0
1097}
1098
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001099# API Test function: GET /ei-producer/v1/eiproducers
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001100# API Test function: GET /data-producer/v1/info-producers
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001101# args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]
1102# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001103ics_api_edp_get_producer_ids_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001104 __log_test_start $@
1105
1106 if [ $# -lt 1 ]; then
1107 __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
1108 return 1
1109 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001110 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001111 query="/data-producer/v1/info-producers"
1112 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
BjornMagnussonXAc8f92e92022-02-28 15:16:37 +01001113 query=$query"?info_type_id=$2&infoTypeId=$2" #info_type_id changed to infoTypeId in F-release.
1114 #Remove info_type_id when F-release is no longer supported
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001115 fi
1116 else
1117 query="/ei-producer/v1/eiproducers"
1118 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1119 query=$query"?ei_type_id=$2"
1120 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001121 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001122 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001123 status=${res:${#res}-3}
1124
1125 if [ $status -ne $1 ]; then
1126 __log_test_fail_status_code $1 $status
1127 return 1
1128 fi
1129
1130 if [ $# -gt 2 ]; then
1131 body=${res:0:${#res}-3}
1132 targetJson="["
1133
1134 for pid in ${@:3} ; do
1135 if [ "$targetJson" != "[" ]; then
1136 targetJson=$targetJson","
1137 fi
1138 if [ $pid != "EMPTY" ]; then
1139 targetJson=$targetJson"\"$pid\""
1140 fi
1141 done
1142
1143 targetJson=$targetJson"]"
1144 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1145 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1146
1147 if [ $res -ne 0 ]; then
1148 __log_test_fail_body
1149 return 1
1150 fi
1151 fi
1152
1153 __log_test_pass
1154 return 0
1155}
1156
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001157# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001158# args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001159# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001160ics_api_edp_get_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001161 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001162
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001163 paramError=1
1164 if [ $# -eq 2 ]; then
1165 paramError=0
1166 fi
1167 if [ $# -gt 3 ]; then
1168 paramError=0
1169 fi
1170 if [ $paramError -ne 0 ]; then
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +02001171 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001172 return 1
1173 fi
1174
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001175 query="/ei-producer/v1/eitypes/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001176 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001177 status=${res:${#res}-3}
1178
1179 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001180 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001181 return 1
1182 fi
1183 if [ $# -gt 3 ]; then
1184 body=${res:0:${#res}-3}
1185
1186 if [ -f $3 ]; then
1187 schema=$(cat $3)
1188 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001189 __log_test_fail_general "Job template file "$3", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001190 return 1
1191 fi
1192
1193 targetJson=""
1194 if [ $4 != "EMPTY" ]; then
1195 for pid in ${@:4} ; do
1196 if [ "$targetJson" != "" ]; then
1197 targetJson=$targetJson","
1198 fi
1199 targetJson=$targetJson"\"$pid\""
1200 done
1201 fi
1202 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
1203
1204 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1205 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1206
1207 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001208 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001209 return 1
1210 fi
1211 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001212 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001213 return 0
1214}
1215
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001216# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001217# API Test function: GET /data-producer/v1/info-types/{infoTypeId}
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001218# args: (v1_2) <response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001219# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001220ics_api_edp_get_type_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001221 __log_test_start $@
1222
1223 paramError=1
1224 if [ $# -eq 2 ]; then
1225 paramError=0
1226 fi
1227 if [ $# -eq 3 ]; then
1228 paramError=0
1229 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001230 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001231 if [ $# -eq 4 ]; then
1232 paramError=0
1233 fi
1234 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001235 if [ $paramError -ne 0 ]; then
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001236 __print_err "<response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]" $@
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001237 return 1
1238 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001239 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001240 query="/data-producer/v1/info-types/$2"
1241 else
1242 query="/ei-producer/v1/eitypes/$2"
1243 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001244
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001245 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001246 status=${res:${#res}-3}
1247
1248 if [ $status -ne $1 ]; then
1249 __log_test_fail_status_code $1 $status
1250 return 1
1251 fi
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001252 if [ $# -ge 3 ]; then
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001253 body=${res:0:${#res}-3}
1254
1255 if [ -f $3 ]; then
1256 schema=$(cat $3)
1257 else
1258 __log_test_fail_general "Job template file "$3", does not exist"
1259 return 1
1260 fi
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001261 info_data=""
1262 if [ $# -gt 3 ]; then
1263 if [ -f $4 ]; then
1264 info_data=$(cat $4)
1265 else
1266 __log_test_fail_general "Info-data file "$4", does not exist"
1267 return 1
1268 fi
1269 info_data=",\"info_type_information\":$info_data"
1270 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001271 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001272 targetJson="{\"info_job_data_schema\":$schema $info_data}"
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001273 else
1274 targetJson="{\"ei_job_data_schema\":$schema}"
1275 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001276
1277 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1278 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1279
1280 if [ $res -ne 0 ]; then
1281 __log_test_fail_body
1282 return 1
1283 fi
1284 fi
1285 __log_test_pass
1286 return 0
1287}
1288
1289# API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001290# API Test function: PUT /data-producer/v1/info-types/{infoTypeId}
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001291# args: (v1_2) <response-code> <type-id> <job-schema-file> [ <info-type-info> ]
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001292# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001293ics_api_edp_put_type_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001294 __log_test_start $@
1295
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001296 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001297 if [ $# -lt 3 ] || [ $# -gt 4 ]; then
1298 __print_err "<response-code> <type-id> <job-schema-file> [ <info-type-info> ]" $@
1299 return 1
1300 fi
1301 else
1302 if [ $# -ne 3 ]; then
1303 __print_err "<response-code> <type-id> <job-schema-file>" $@
1304 return 1
1305 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001306 fi
1307
1308 if [ ! -f $3 ]; then
1309 __log_test_fail_general "Job schema file "$3", does not exist"
1310 return 1
1311 fi
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001312
1313 info_data=""
1314 if [ $# -gt 3 ]; then
1315 if [ -f $4 ]; then
1316 info_data=$(cat $4)
1317 else
1318 __log_test_fail_general "Info-data file "$4", does not exist"
1319 return 1
1320 fi
1321 info_data=",\"info_type_information\":$info_data"
1322 fi
1323
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001324 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001325 schema=$(cat $3)
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001326 input_json="{\"info_job_data_schema\":$schema $info_data}"
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001327 file="./tmp/put_type.json"
1328 echo $input_json > $file
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001329
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001330 query="/data-producer/v1/info-types/$2"
1331 else
1332 schema=$(cat $3)
1333 input_json="{\"ei_job_data_schema\":$schema}"
1334 file="./tmp/put_type.json"
1335 echo $input_json > $file
1336
1337 query="/ei-producer/v1/eitypes/$2"
1338 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001339 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001340 status=${res:${#res}-3}
1341
1342 if [ $status -ne $1 ]; then
1343 __log_test_fail_status_code $1 $status
1344 return 1
1345 fi
1346
1347 __log_test_pass
1348 return 0
1349}
1350
1351# API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001352# API Test function: DELETE /data-producer/v1/info-types/{infoTypeId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001353# args: (v1_2) <response-code> <type-id>
1354# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001355ics_api_edp_delete_type_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001356 __log_test_start $@
1357
1358 if [ $# -ne 2 ]; then
1359 __print_err "<response-code> <type-id>" $@
1360 return 1
1361 fi
1362
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001363 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001364 query="/data-producer/v1/info-types/$2"
1365 else
1366 query="/ei-producer/v1/eitypes/$2"
1367 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001368 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001369 status=${res:${#res}-3}
1370
1371 if [ $status -ne $1 ]; then
1372 __log_test_fail_status_code $1 $status
1373 return 1
1374 fi
1375
1376 __log_test_pass
1377 return 0
1378}
1379
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001380# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001381# args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001382# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001383ics_api_edp_get_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001384 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001385
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001386 #Possible arg count: 2, 5 6, 8, 10 etc
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001387 paramError=1
1388 if [ $# -eq 2 ]; then
1389 paramError=0
1390 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001391 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001392 paramError=0
1393 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001394 variablecount=$(($#-4))
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001395 if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
1396 paramError=0
1397 fi
1398
1399 if [ $paramError -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001400 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001401 return 1
1402 fi
1403
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001404 query="/ei-producer/v1/eiproducers/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001405 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001406 status=${res:${#res}-3}
1407
1408 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001409 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001410 return 1
1411 fi
1412
1413 if [ $# -gt 2 ]; then
1414 body=${res:0:${#res}-3}
1415 targetJson="["
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001416 if [ $# -gt 5 ]; then
1417 arr=(${@:5})
1418 for ((i=0; i<$(($#-5)); i=i+2)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001419 if [ "$targetJson" != "[" ]; then
1420 targetJson=$targetJson","
1421 fi
1422 if [ -f ${arr[$i+1]} ]; then
1423 schema=$(cat ${arr[$i+1]})
1424 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001425 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001426 return 1
1427 fi
1428
1429 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1430 done
1431 fi
1432 targetJson=$targetJson"]"
1433 if [ $# -gt 4 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001434 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001435 fi
1436 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1437 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1438
1439 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001440 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001441 return 1
1442 fi
1443 fi
1444
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001445 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001446 return 0
1447}
1448
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001449# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001450# API Test function: GET /data-producer/v1/info-producers/{infoProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001451# args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]
1452# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001453ics_api_edp_get_producer_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001454 __log_test_start $@
1455
1456 #Possible arg count: 2, 5, 6, 7, 8 etc
1457 paramError=1
1458 if [ $# -eq 2 ]; then
1459 paramError=0
1460 fi
1461 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1462 paramError=0
1463 fi
1464 if [ $# -ge 5 ]; then
1465 paramError=0
1466 fi
1467
1468 if [ $paramError -ne 0 ]; then
1469 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
1470 return 1
1471 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001472 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001473 query="/data-producer/v1/info-producers/$2"
1474 else
1475 query="/ei-producer/v1/eiproducers/$2"
1476 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001477 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001478 status=${res:${#res}-3}
1479
1480 if [ $status -ne $1 ]; then
1481 __log_test_fail_status_code $1 $status
1482 return 1
1483 fi
1484
1485 if [ $# -gt 2 ]; then
1486 body=${res:0:${#res}-3}
1487 targetJson="["
1488 if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
1489 arr=(${@:5})
1490 for ((i=0; i<$(($#-4)); i=i+1)); do
1491 if [ "$targetJson" != "[" ]; then
1492 targetJson=$targetJson","
1493 fi
1494 targetJson=$targetJson"\"${arr[$i]}\""
1495 done
1496 fi
1497 targetJson=$targetJson"]"
1498 if [ $# -gt 4 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001499 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001500 targetJson="{\"supported_info_types\":$targetJson,\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\"}"
1501 else
1502 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1503 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001504 fi
1505 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1506 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1507
1508 if [ $res -ne 0 ]; then
1509 __log_test_fail_body
1510 return 1
1511 fi
1512 fi
1513
1514 __log_test_pass
1515 return 0
1516}
1517
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001518# API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001519# API Test function: DELETE /data-producer/v1/info-producers/{infoProducerId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001520# args: <response-code> <producer-id>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001521# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001522ics_api_edp_delete_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001523 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001524
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001525 if [ $# -lt 2 ]; then
1526 __print_err "<response-code> <producer-id>" $@
1527 return 1
1528 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001529 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001530 query="/data-producer/v1/info-producers/$2"
1531 else
1532 query="/ei-producer/v1/eiproducers/$2"
1533 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001534 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001535 status=${res:${#res}-3}
1536
1537 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001538 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001539 return 1
1540 fi
1541
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001542 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001543 return 0
1544}
1545
1546# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001547# args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001548# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001549ics_api_edp_put_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001550 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001551
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001552 #Valid number of parametrer 5,6,8,10,
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001553 paramError=1
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001554 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001555 paramError=0
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001556 elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001557 paramError=0
1558 fi
1559 if [ $paramError -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001560 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001561 return 1
1562 fi
1563
1564 inputJson="["
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001565 if [ $# -gt 5 ]; then
1566 arr=(${@:5})
1567 for ((i=0; i<$(($#-5)); i=i+2)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001568 if [ "$inputJson" != "[" ]; then
1569 inputJson=$inputJson","
1570 fi
1571 if [ -f ${arr[$i+1]} ]; then
1572 schema=$(cat ${arr[$i+1]})
1573 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001574 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001575 return 1
1576 fi
1577 inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1578 done
1579 fi
1580 inputJson="\"supported_ei_types\":"$inputJson"]"
1581
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001582 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001583
1584 inputJson="{"$inputJson"}"
1585
1586 file="./tmp/.p.json"
1587 echo "$inputJson" > $file
1588 query="/ei-producer/v1/eiproducers/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001589 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001590 status=${res:${#res}-3}
1591
1592 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001593 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001594 return 1
1595 fi
1596
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001597 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001598 return 0
1599}
1600
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001601# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001602# API Test function: PUT /data-producer/v1/info-producers/{infoProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001603# args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]
1604# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001605ics_api_edp_put_producer_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001606 __log_test_start $@
1607
1608 #Valid number of parametrer 5,6,8,10,
1609 paramError=1
1610 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1611 paramError=0
1612 elif [ $# -ge 5 ]; then
1613 paramError=0
1614 fi
1615 if [ $paramError -ne 0 ]; then
1616 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
1617 return 1
1618 fi
1619
1620 inputJson="["
1621 if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
1622 arr=(${@:5})
1623 for ((i=0; i<$(($#-4)); i=i+1)); do
1624 if [ "$inputJson" != "[" ]; then
1625 inputJson=$inputJson","
1626 fi
1627 inputJson=$inputJson"\""${arr[$i]}"\""
1628 done
1629 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001630 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001631 inputJson="\"supported_info_types\":"$inputJson"]"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001632
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001633 inputJson=$inputJson",\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\""
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001634
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001635 inputJson="{"$inputJson"}"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001636
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001637 file="./tmp/.p.json"
1638 echo "$inputJson" > $file
1639 query="/data-producer/v1/info-producers/$2"
1640 else
1641 inputJson="\"supported_ei_types\":"$inputJson"]"
1642
1643 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1644
1645 inputJson="{"$inputJson"}"
1646
1647 file="./tmp/.p.json"
1648 echo "$inputJson" > $file
1649 query="/ei-producer/v1/eiproducers/$2"
1650 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001651 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001652 status=${res:${#res}-3}
1653
1654 if [ $status -ne $1 ]; then
1655 __log_test_fail_status_code $1 $status
1656 return 1
1657 fi
1658
1659 __log_test_pass
1660 return 0
1661}
1662
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001663# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001664# args: (V1-1) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001665# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001666ics_api_edp_get_producer_jobs() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001667 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001668
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001669 #Valid number of parameter 2,3,7,11
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001670 paramError=1
1671 if [ $# -eq 2 ]; then
1672 paramError=0
1673 fi
1674 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1675 paramError=0
1676 fi
1677 variablecount=$(($#-2))
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001678 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001679 paramError=0
1680 fi
1681 if [ $paramError -eq 1 ]; then
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001682 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001683 return 1
1684 fi
1685
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001686 query="/ei-producer/v1/eiproducers/$2/eijobs"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001687 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001688 status=${res:${#res}-3}
1689 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001690 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001691 return 1
1692 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001693 if [ $# -gt 2 ]; then
1694 body=${res:0:${#res}-3}
1695 targetJson="["
1696 if [ $# -gt 3 ]; then
1697 arr=(${@:3})
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001698 for ((i=0; i<$(($#-3)); i=i+5)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001699 if [ "$targetJson" != "[" ]; then
1700 targetJson=$targetJson","
1701 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001702 if [ -f ${arr[$i+4]} ]; then
1703 jobfile=$(cat ${arr[$i+4]})
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001704 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1705 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001706 __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001707 return 1
1708 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001709 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}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001710 done
1711 fi
1712 targetJson=$targetJson"]"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001713
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001714 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1715 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001716
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001717 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001718 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001719 return 1
1720 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001721 fi
1722
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001723 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001724 return 0
1725}
1726
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001727# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001728# API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/info-jobs
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001729# args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1730# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001731ics_api_edp_get_producer_jobs_2() {
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001732 __log_test_start $@
1733
1734 #Valid number of parameter 2,3,7,11
1735 paramError=1
1736 if [ $# -eq 2 ]; then
1737 paramError=0
1738 fi
1739 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1740 paramError=0
1741 fi
1742 variablecount=$(($#-2))
1743 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1744 paramError=0
1745 fi
1746 if [ $paramError -eq 1 ]; then
1747 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1748 return 1
1749 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001750 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001751 query="/data-producer/v1/info-producers/$2/info-jobs"
1752 else
1753 query="/ei-producer/v1/eiproducers/$2/eijobs"
1754 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001755 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001756 status=${res:${#res}-3}
1757 if [ $status -ne $1 ]; then
1758 __log_test_fail_status_code $1 $status
1759 return 1
1760 fi
1761 if [ $# -gt 2 ]; then
1762 body=${res:0:${#res}-3}
1763 targetJson="["
1764 if [ $# -gt 3 ]; then
1765 arr=(${@:3})
1766 for ((i=0; i<$(($#-3)); i=i+5)); do
1767 if [ "$targetJson" != "[" ]; then
1768 targetJson=$targetJson","
1769 fi
1770 if [ -f ${arr[$i+4]} ]; then
1771 jobfile=$(cat ${arr[$i+4]})
1772 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1773 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001774 __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001775 return 1
1776 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001777 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001778 targetJson=$targetJson"{\"info_job_identity\":\"${arr[$i]}\",\"info_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"info_job_data\":$jobfile, \"last_updated\":\"????\"}"
1779 else
1780 targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"ei_job_data\":$jobfile, \"last_updated\":\"????\"}"
1781 fi
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001782 done
1783 fi
1784 targetJson=$targetJson"]"
1785
1786 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1787 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1788
1789 if [ $res -ne 0 ]; then
1790 __log_test_fail_body
1791 return 1
1792 fi
1793 fi
1794
1795 __log_test_pass
1796 return 0
1797}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001798
1799##########################################
1800#### Service status ####
1801##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001802# Function prefix: ics_api_service
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001803
1804# API Test function: GET ​/status
1805# args: <response-code>
1806# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001807ics_api_service_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001808 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001809
1810 if [ $# -lt 1 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001811 __print_err "<response-code>" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001812 return 1
1813 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001814 res="$(__do_curl_to_api ICS GET /status)"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001815 status=${res:${#res}-3}
1816 if [ $status -ne $1 ]; then
1817 __log_test_fail_status_code $1 $status
1818 return 1
1819 fi
1820 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001821 return 0
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001822}
1823
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001824###########################################
1825######### Info data consumer API ##########
1826###########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001827#Function prefix: ics_api_idc
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001828
1829
1830# API Test function: GET /data-consumer/v1/info-types
1831# args: <response-code> [ (EMPTY | [<type-id>]+) ]
1832# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001833ics_api_idc_get_type_ids() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001834 __log_test_start $@
1835
1836 if [ $# -lt 1 ]; then
1837 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
1838 return 1
1839 fi
1840
1841 query="/data-consumer/v1/info-types"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001842 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001843 status=${res:${#res}-3}
1844
1845 if [ $status -ne $1 ]; then
1846 __log_test_fail_status_code $1 $status
1847 return 1
1848 fi
1849 if [ $# -gt 1 ]; then
1850 body=${res:0:${#res}-3}
1851 targetJson="["
1852 if [ $2 != "EMPTY" ]; then
1853 for pid in ${@:2} ; do
1854 if [ "$targetJson" != "[" ]; then
1855 targetJson=$targetJson","
1856 fi
1857 targetJson=$targetJson"\"$pid\""
1858 done
1859 fi
1860 targetJson=$targetJson"]"
1861 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1862 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1863
1864 if [ $res -ne 0 ]; then
1865 __log_test_fail_body
1866 return 1
1867 fi
1868 fi
1869
1870 __log_test_pass
1871 return 0
1872}
1873
1874# API Test function: GET /data-consumer/v1/info-jobs
1875# args: <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
1876# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001877ics_api_idc_get_job_ids() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001878 __log_test_start $@
1879
1880 # Valid number of parameters 4,5,6 etc
1881 if [ $# -lt 3 ]; then
1882 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
1883 return 1
1884 fi
1885 search=""
1886 if [ $3 != "NOWNER" ]; then
1887 search="?owner="$3
1888 fi
1889
1890 if [ $2 != "NOTYPE" ]; then
1891 if [ -z "$search" ]; then
1892 search="?infoTypeId="$2
1893 else
1894 search=$search"&infoTypeId="$2
1895 fi
1896 fi
1897 query="/data-consumer/v1/info-jobs$search"
1898
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001899 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001900 status=${res:${#res}-3}
1901
1902 if [ $status -ne $1 ]; then
1903 __log_test_fail_status_code $1 $status
1904 return 1
1905 fi
1906
1907 if [ $# -gt 3 ]; then
1908 body=${res:0:${#res}-3}
1909 targetJson="["
1910
1911 for pid in ${@:4} ; do
1912 if [ "$targetJson" != "[" ]; then
1913 targetJson=$targetJson","
1914 fi
1915 if [ $pid != "EMPTY" ]; then
1916 targetJson=$targetJson"\"$pid\""
1917 fi
1918 done
1919
1920 targetJson=$targetJson"]"
1921 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1922 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1923
1924 if [ $res -ne 0 ]; then
1925 __log_test_fail_body
1926 return 1
1927 fi
1928 fi
1929
1930 __log_test_pass
1931 return 0
1932}
1933
1934# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}
1935# args: <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
1936# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001937ics_api_idc_get_job() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001938 __log_test_start $@
1939
1940 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
1941 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
1942 return 1
1943 fi
1944 query="/data-consumer/v1/info-jobs/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001945 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001946 status=${res:${#res}-3}
1947
1948 if [ $status -ne $1 ]; then
1949 __log_test_fail_status_code $1 $status
1950 return 1
1951 fi
1952
1953 if [ $# -eq 7 ]; then
1954 body=${res:0:${#res}-3}
1955
1956 if [ -f $7 ]; then
1957 jobfile=$(cat $7)
1958 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1959 else
1960 __log_test_fail_general "Job template file "$6", does not exist"
1961 return 1
1962 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001963 targetJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001964 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1965 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1966
1967 if [ $res -ne 0 ]; then
1968 __log_test_fail_body
1969 return 1
1970 fi
1971 fi
1972
1973 __log_test_pass
1974 return 0
1975}
1976
1977
1978# API Test function: PUT ​/data-consumer/v1/info-jobs/{infoJobId}
1979# args: <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]
1980# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001981ics_api_idc_put_job() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001982 __log_test_start $@
1983
1984 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1985 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]" $@
1986 return 1
1987 fi
1988 if [ -f $7 ]; then
1989 jobfile=$(cat $7)
1990 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1991 else
1992 __log_test_fail_general "Job template file "$7", does not exist"
1993 return 1
1994 fi
1995
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001996 inputJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001997 file="./tmp/.p.json"
1998 echo "$inputJson" > $file
1999
2000 query="/data-consumer/v1/info-jobs/$2"
2001
2002 if [ $# -eq 8 ]; then
2003 if [ $8 == "VALIDATE" ]; then
2004 query=$query"?typeCheck=true"
2005 fi
2006 fi
2007
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002008 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002009 status=${res:${#res}-3}
2010
2011 if [ $status -ne $1 ]; then
2012 __log_test_fail_status_code $1 $status
2013 return 1
2014 fi
2015
2016 __log_test_pass
2017 return 0
2018}
2019
2020# API Test function: DELETE ​/data-consumer/v1/info-jobs/{infoJobId}
2021# args: <response-code> <job-id>
2022# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002023ics_api_idc_delete_job() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002024 __log_test_start $@
2025
2026 if [ $# -ne 2 ]; then
2027 __print_err "<response-code> <job-id>" $@
2028 return 1
2029 fi
2030 query="/data-consumer/v1/info-jobs/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002031 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002032 status=${res:${#res}-3}
2033
2034 if [ $status -ne $1 ]; then
2035 __log_test_fail_status_code $1 $status
2036 return 1
2037 fi
2038
2039 __log_test_pass
2040 return 0
2041}
2042
2043# API Test function: GET ​/data-consumer/v1/info-types/{infoTypeId}
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002044# args: <response-code> <type-id> [<schema-file> [<type-status> <producers-count]]
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002045# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002046ics_api_idc_get_type() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002047 __log_test_start $@
2048
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002049 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
2050 __print_err "<response-code> <type-id> [<schema-file> [<type-status> <producers-count]]" $@
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002051 return 1
2052 fi
2053
2054 query="/data-consumer/v1/info-types/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002055 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002056 status=${res:${#res}-3}
2057
2058 if [ $status -ne $1 ]; then
2059 __log_test_fail_status_code $1 $status
2060 return 1
2061 fi
2062
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002063 if [ $# -gt 2 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002064 body=${res:0:${#res}-3}
2065 if [ -f $3 ]; then
2066 schema=$(cat $3)
2067 else
2068 __log_test_fail_general "Schema file "$3", does not exist"
2069 return 1
2070 fi
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002071 if [ $# -eq 5 ]; then
2072 targetJson="{\"job_data_schema\":$schema, \"type_status\":\"$4\", \"no_of_producers\":$5}"
2073 else
2074 targetJson="{\"job_data_schema\":$schema}"
2075 fi
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002076 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2077 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2078
2079 if [ $res -ne 0 ]; then
2080 __log_test_fail_body
2081 return 1
2082 fi
2083 fi
2084
2085 __log_test_pass
2086 return 0
2087}
2088
2089# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002090# This test only status during an optional timeout. No test of the list of producers
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002091# args: <response-code> <job-id> [<status> [<timeout>]]
2092# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002093ics_api_idc_get_job_status() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002094 __log_test_start $@
2095
2096 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
2097 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
2098 return 1
2099 fi
2100
2101 query="/data-consumer/v1/info-jobs/$2/status"
2102
2103 start=$SECONDS
2104 for (( ; ; )); do
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002105 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002106 status=${res:${#res}-3}
2107
2108 if [ $# -eq 4 ]; then
2109 duration=$((SECONDS-start))
2110 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2111 if [ $duration -gt $4 ]; then
2112 echo ""
2113 duration=-1 #Last iteration
2114 fi
2115 else
2116 duration=-1 #single test, no wait
2117 fi
2118
2119 if [ $status -ne $1 ]; then
2120 if [ $duration -eq -1 ]; then
2121 __log_test_fail_status_code $1 $status
2122 return 1
2123 fi
2124 fi
2125 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
2126 body=${res:0:${#res}-3}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02002127 targetJson="{\"info_job_status\": \"$3\"}"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002128 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2129 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2130
2131 if [ $res -ne 0 ]; then
2132 if [ $duration -eq -1 ]; then
2133 __log_test_fail_body
2134 return 1
2135 fi
2136 else
2137 duration=-1 #Goto pass
2138 fi
2139 fi
2140 if [ $duration -eq -1 ]; then
2141 if [ $# -eq 4 ]; then
2142 echo ""
2143 fi
2144 __log_test_pass
2145 return 0
2146 else
2147 sleep 1
2148 fi
2149 done
2150
2151 __log_test_pass
2152 return 0
2153}
2154
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002155# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
2156# This function test status and the list of producers with and optional timeout
2157# args: <response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]
2158# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002159ics_api_idc_get_job_status2() {
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002160
2161 __log_test_start $@
2162 param_error=0
2163 if [ $# -lt 2 ]; then
2164 param_error=1
2165 fi
2166 args=("$@")
2167 timeout=0
2168 if [ $# -gt 2 ]; then
2169 if [ $# -lt 4 ]; then
2170 param_error=1
2171 fi
2172 targetJson="{\"info_job_status\": \"$3\""
2173 if [ "$4" == "EMPTYPROD" ]; then
2174 targetJson=$targetJson",\"producers\": []}"
2175 if [ $# -gt 4 ]; then
2176 timeout=$5
2177 fi
2178 else
2179 targetJson=$targetJson",\"producers\": ["
2180 if [ $# -eq $(($4+5)) ]; then
2181 idx=$(($4+4))
2182 timeout=${args[$idx]}
2183 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002184 for ((ics_i = 0 ; ics_i < $4 ; ics_i++)); do
2185 idx=$(($ics_i+4))
2186 if [ $ics_i -gt 0 ]; then
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002187 targetJson=$targetJson","
2188 fi
2189 targetJson=$targetJson"\""${args[$idx]}"\""
2190 done
2191 targetJson=$targetJson"]}"
2192 fi
2193 fi
2194
2195 if [ $param_error -ne 0 ]; then
2196 __print_err "<response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]" $@
2197 return 1
2198 fi
2199
2200 query="/data-consumer/v1/info-jobs/$2/status"
2201
2202 start=$SECONDS
2203 for (( ; ; )); do
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002204 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002205 status=${res:${#res}-3}
2206
2207 if [ $# -gt 2 ]; then
2208 duration=$((SECONDS-start))
2209 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2210 if [ $duration -gt $timeout ]; then
2211 echo ""
2212 duration=-1 #Last iteration
2213 fi
2214 else
2215 duration=-1 #single test, no wait
2216 fi
2217
2218 if [ $status -ne $1 ]; then
2219 if [ $duration -eq -1 ]; then
2220 __log_test_fail_status_code $1 $status
2221 return 1
2222 fi
2223 fi
2224 if [ $# -gt 2 ] && [ $status -eq $1 ]; then
2225 body=${res:0:${#res}-3}
2226 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2227 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2228
2229 if [ $res -ne 0 ]; then
2230 if [ $duration -eq -1 ]; then
2231 __log_test_fail_body
2232 return 1
2233 fi
2234 else
2235 duration=-1 #Goto pass
2236 fi
2237 fi
2238 if [ $duration -eq -1 ]; then
2239 if [ $# -eq 4 ]; then
2240 echo ""
2241 fi
2242 __log_test_pass
2243 return 0
2244 else
2245 sleep 1
2246 fi
2247 done
2248
2249 __log_test_pass
2250 return 0
2251}
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002252
2253##########################################
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002254#### Type subscriptions ####
2255##########################################
2256
2257# API Test function: GET /data-consumer/v1/info-type-subscription
2258# args: <response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]
2259# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002260ics_api_idc_get_subscription_ids() {
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002261 __log_test_start $@
2262
2263 if [ $# -lt 3 ]; then
2264 __print_err "<response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]" $@
2265 return 1
2266 fi
2267
2268 query="/data-consumer/v1/info-type-subscription"
2269 search=""
2270 if [ $2 != "NOOWNER" ]; then
2271 search="?owner="$2
2272 fi
2273
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002274 res="$(__do_curl_to_api ICS GET $query$search)"
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002275 status=${res:${#res}-3}
2276
2277 if [ $status -ne $1 ]; then
2278 __log_test_fail_status_code $1 $status
2279 return 1
2280 fi
2281
2282 if [ $# -gt 2 ]; then
2283 body=${res:0:${#res}-3}
2284 targetJson="["
2285 if [ $3 != "EMPTY" ]; then
2286 for pid in ${@:3} ; do
2287 if [ "$targetJson" != "[" ]; then
2288 targetJson=$targetJson","
2289 fi
2290 targetJson=$targetJson"\"$pid\""
2291 done
2292 fi
2293 targetJson=$targetJson"]"
2294 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2295 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2296
2297 if [ $res -ne 0 ]; then
2298 __log_test_fail_body
2299 return 1
2300 fi
2301 fi
2302
2303 __log_test_pass
2304 return 0
2305}
2306
2307# API Test function: GET /data-consumer/v1/info-type-subscription/{subscriptionId}
2308# args: <response-code> <subscription-id> [ <owner-id> <status-uri> ]
2309# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002310ics_api_idc_get_subscription() {
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002311 __log_test_start $@
2312
2313 if [ $# -ne 2 ] && [ $# -ne 4 ]; then
2314 __print_err "<response-code> <subscription-id> [ <owner-id> <status-uri> ]" $@
2315 return 1
2316 fi
2317
2318 query="/data-consumer/v1/info-type-subscription/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002319 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002320 status=${res:${#res}-3}
2321
2322 if [ $status -ne $1 ]; then
2323 __log_test_fail_status_code $1 $status
2324 return 1
2325 fi
2326
2327 if [ $# -gt 2 ]; then
2328 body=${res:0:${#res}-3}
2329 targetJson="{\"owner\":\"$3\",\"status_result_uri\":\"$4\"}"
2330 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2331 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2332
2333 if [ $res -ne 0 ]; then
2334 __log_test_fail_body
2335 return 1
2336 fi
2337 fi
2338
2339 __log_test_pass
2340 return 0
2341}
2342
2343# API Test function: PUT /data-consumer/v1/info-type-subscription/{subscriptionId}
2344# args: <response-code> <subscription-id> <owner-id> <status-uri>
2345# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002346ics_api_idc_put_subscription() {
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002347 __log_test_start $@
2348
2349 if [ $# -ne 4 ]; then
2350 __print_err "<response-code> <subscription-id> <owner-id> <status-uri>" $@
2351 return 1
2352 fi
2353
2354 inputJson="{\"owner\": \"$3\",\"status_result_uri\": \"$4\"}"
2355 file="./tmp/.p.json"
2356 echo "$inputJson" > $file
2357
2358 query="/data-consumer/v1/info-type-subscription/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002359 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002360 status=${res:${#res}-3}
2361
2362 if [ $status -ne $1 ]; then
2363 __log_test_fail_status_code $1 $status
2364 return 1
2365 fi
2366
2367 __log_test_pass
2368 return 0
2369}
2370
2371# API Test function: DELETE /data-consumer/v1/info-type-subscription/{subscriptionId}
2372# args: <response-code> <subscription-id>
2373# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002374ics_api_idc_delete_subscription() {
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002375 __log_test_start $@
2376
2377 if [ $# -ne 2 ]; then
2378 __print_err "<response-code> <subscription-id> " $@
2379 return 1
2380 fi
2381
2382 query="/data-consumer/v1/info-type-subscription/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002383 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002384 status=${res:${#res}-3}
2385
2386 if [ $status -ne $1 ]; then
2387 __log_test_fail_status_code $1 $status
2388 return 1
2389 fi
2390
2391 __log_test_pass
2392 return 0
2393}
2394
2395##########################################
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002396#### Reset jobs ####
2397##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002398# Function prefix: ics_api_admin
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002399
2400# Admin to remove all jobs
BjornMagnussonXA366e36a2021-01-27 11:48:56 +01002401# args: <response-code> [ <type> ]
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002402# (Function for test scripts)
2403
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002404ics_api_admin_reset() {
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002405 __log_test_start $@
2406
2407 if [ -z "$FLAT_A1_EI" ]; then
2408 query="/A1-EI/v1/eitypes/$2/eijobs"
2409 else
2410 query="/A1-EI/v1/eijobs"
2411 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002412 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002413 status=${res:${#res}-3}
2414
2415 if [ $status -ne 200 ]; then
2416 __log_test_fail_status_code $1 $status
2417 return 1
2418 fi
2419
2420 #Remove brackets and response code
2421 body=${res:1:${#res}-4}
2422 list=$(echo ${body//,/ })
2423 list=$(echo ${list//[/})
2424 list=$(echo ${list//]/})
2425 list=$(echo ${list//\"/})
2426 list=$list" "
2427 for job in $list; do
2428 if [ -z "$FLAT_A1_EI" ]; then
2429 echo "Not supported for non-flat EI api"
2430 else
2431 query="/A1-EI/v1/eijobs/$job"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002432 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002433 status=${res:${#res}-3}
2434 if [ $status -ne 204 ]; then
2435 __log_test_fail_status_code $1 $status
2436 return 1
2437 fi
2438 echo " Deleted job: "$job
2439 fi
2440 done
2441
2442 __log_test_pass
2443 return 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002444}
2445
2446##########################################
2447#### Reset jobs and producers ####
2448##########################################
2449
2450
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002451# Admin reset to remove all data in ics; jobs, producers etc
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002452# NOTE - only works in kubernetes and the pod should not be running
2453# args: -
2454# (Function for test scripts)
2455
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002456ics_kube_pvc_reset() {
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002457 __log_test_start $@
2458
BjornMagnussonXAcb6113e2022-02-17 15:01:28 +01002459 pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep information)
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +02002460 if [ -z "$pvc_name" ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002461 pvc_name=informationservice-pvc
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +02002462 fi
2463 echo " Trying to reset pvc: "$pvc_name
2464
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002465 __kube_clean_pvc $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $ICS_CONTAINER_MNT_DIR
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002466
2467 __log_test_pass
2468 return 0
BjornMagnussonXA145762b2022-03-22 10:35:10 +01002469}
2470
2471# args: <realm> <client-name> <client-secret>
2472ics_configure_sec() {
2473 export ICS_CREDS_GRANT_TYPE="client_credentials"
2474 export ICS_CREDS_CLIENT_SECRET=$3
2475 export ICS_CREDS_CLIENT_ID=$2
2476 export ICS_AUTH_SERVICE_URL=$KEYCLOAK_SERVICE_PATH$KEYCLOAK_TOKEN_URL_PREFIX/$1/protocol/openid-connect/token
2477 export ICS_SIDECAR_MOUNT="/token-cache"
2478 export ICS_SIDECAR_JWT_FILE=$ICS_SIDECAR_MOUNT"/jwt.txt"
2479
2480 export AUTHSIDECAR_APP_NAME
2481 export AUTHSIDECAR_DISPLAY_NAME
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002482}