blob: 05638af77be0d7703fd9175ad4ff0572bbb6aa3f [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
BjornMagnussonXA663566c2021-11-08 10:25:07 +010092}
93
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +010094# Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers
95# For docker, the namespace shall be excluded
96# This function is called for apps managed by the test script as well as for prestarted apps.
97# args: -
BjornMagnussonXA007b6452021-11-29 08:03:38 +010098__ICS_statisics_setup() {
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +010099 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100100 echo "ICS $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE"
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100101 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100102 echo "ICS $ICS_APP_NAME"
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100103 fi
104}
105
BjornMagnussonXAe60d04e2021-12-27 13:38:01 +0100106# Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
107# args: -
108__ICS_test_requirements() {
109 :
110}
111
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100112#######################################################
113
114
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100115# Make curl retries towards ICS for http response codes set in this env var, space separated list of codes
116ICS_RETRY_CODES=""
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100117
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200118#Save first worker node the pod is started on
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100119__ICS_WORKER_NODE=""
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200120
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100121###########################
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100122### ICS functions
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100123###########################
124
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100125# All calls to ICS will be directed to the ICS REST interface from now on
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100126# args: -
127# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100128use_ics_rest_http() {
129 __ics_set_protocoll "http" $ICS_INTERNAL_PORT $ICS_EXTERNAL_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100130}
131
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100132# All calls to ICS will be directed to the ICS REST interface from now on
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100133# args: -
134# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100135use_ics_rest_https() {
136 __ics_set_protocoll "https" $ICS_INTERNAL_SECURE_PORT $ICS_EXTERNAL_SECURE_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100137}
138
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100139# All calls to ICS will be directed to the ICS dmaap interface over http from now on
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100140# args: -
141# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100142use_ics_dmaap_http() {
143 echo -e $BOLD"ICS dmaap protocol setting"$EBOLD
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100144 echo -e $RED" - NOT SUPPORTED - "$ERED
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100145 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ICS"
146 ICS_ADAPTER_TYPE="MR-HTTP"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100147 echo ""
148}
149
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100150# Setup paths to svc/container for internal and external access
151# args: <protocol> <internal-port> <external-port>
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100152__ics_set_protocoll() {
153 echo -e $BOLD"$ICS_DISPLAY_NAME protocol setting"$EBOLD
154 echo -e " Using $BOLD $1 $EBOLD towards $ICS_DISPLAY_NAME"
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100155
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100156 ## Access to ICS
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100157
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100158 ICS_SERVICE_PATH=$1"://"$ICS_APP_NAME":"$2 # docker access, container->container and script->container via proxy
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100159 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100160 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 +0100161 fi
162
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100163 # ICS_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
164 ICS_ADAPTER_TYPE="REST"
165 ICS_ADAPTER=$ICS_SERVICE_PATH
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100166
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100167 echo ""
168}
169
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100170# Export env vars for config files, docker compose and kube resources
171# args: PROXY|NOPROXY
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100172__ics_export_vars() {
173 export ICS_APP_NAME
174 export ICS_APP_NAME_ALIAS
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100175 export KUBE_NONRTRIC_NAMESPACE
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100176 export ICS_IMAGE
177 export ICS_INTERNAL_PORT
178 export ICS_INTERNAL_SECURE_PORT
179 export ICS_EXTERNAL_PORT
180 export ICS_EXTERNAL_SECURE_PORT
181 export ICS_CONFIG_MOUNT_PATH
182 export ICS_CONFIG_CONFIGMAP_NAME=$ICS_APP_NAME"-config"
183 export ICS_DATA_CONFIGMAP_NAME=$ICS_APP_NAME"-data"
184 export ICS_CONTAINER_MNT_DIR
185 export ICS_HOST_MNT_DIR
186 export ICS_CONFIG_FILE
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100187 export DOCKER_SIM_NWNAME
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100188 export ICS_DISPLAY_NAME
BjornMagnussonXA05bfe482021-12-02 08:47:41 +0100189 export ICS_LOGPATH
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100190
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100191 export ICS_DATA_PV_NAME=$ICS_APP_NAME"-pv"
192 export ICS_DATA_PVC_NAME=$ICS_APP_NAME"-pvc"
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100193 #Create a unique path for the pv each time to prevent a previous volume to be reused
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100194 export ICS_PV_PATH="icsdata-"$(date +%s)
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100195
196 if [ $1 == "PROXY" ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100197 export ICS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
198 export ICS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
199 if [ $ICS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ICS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100200 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
201 else
202 echo " Configured with http proxy"
203 fi
204 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100205 export ICS_HTTP_PROXY_CONFIG_PORT=0
206 export ICS_HTTP_PROXY_CONFIG_HOST_NAME=""
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100207 echo " Configured without http proxy"
208 fi
209}
210
211
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100212# Start the ICS
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100213# args: PROXY|NOPROXY <config-file>
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100214# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100215start_ics() {
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100216
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100217 echo -e $BOLD"Starting $ICS_DISPLAY_NAME"$EBOLD
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100218
219 if [ $RUNMODE == "KUBE" ]; then
220
221 # Check if app shall be fully managed by the test script
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100222 __check_included_image "ICS"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100223 retcode_i=$?
224
225 # Check if app shall only be used by the testscipt
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100226 __check_prestarted_image "ICS"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100227 retcode_p=$?
228
229 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100230 echo -e $RED"The $ICS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
231 echo -e $RED"The $ICS_APP_NAME will not be started"$ERED
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100232 exit
233 fi
234 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100235 echo -e $RED"The $ICS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
236 echo -e $RED"The $ICS_APP_NAME will not be started"$ERED
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100237 exit
238 fi
239
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100240 if [ $retcode_p -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100241 echo -e " Using existing $ICS_APP_NAME deployment and service"
242 echo " Setting ICS replicas=1"
243 res_type=$(__kube_get_resource_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
244 __kube_scale $res_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100245 fi
246
247 # Check if app shall be fully managed by the test script
248 if [ $retcode_i -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100249 echo -e " Creating $ICS_APP_NAME app and expose service"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100250
251 #Check if nonrtric namespace exists, if not create it
252 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
253
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100254 __ics_export_vars $1
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100255
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100256 # Create config map for config
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100257 datafile=$PWD/tmp/$ICS_CONFIG_FILE
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100258 cp $2 $datafile
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100259 output_yaml=$PWD/tmp/ics_cfc.yaml
260 __kube_create_configmap $ICS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ICS $datafile $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100261
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100262 # Create pv
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100263 input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"pv.yaml
264 output_yaml=$PWD/tmp/ics_pv.yaml
265 __kube_create_instance pv $ICS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100266
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100267 # Create pvc
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100268 input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"pvc.yaml
269 output_yaml=$PWD/tmp/ics_pvc.yaml
270 __kube_create_instance pvc $ICS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100271
272 # Create service
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100273 input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"svc.yaml
274 output_yaml=$PWD/tmp/ics_svc.yaml
275 __kube_create_instance service $ICS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100276
277 # Create app
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100278 input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"app.yaml
279 output_yaml=$PWD/tmp/ics_app.yaml
280 __kube_create_instance app $ICS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100281 fi
282
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100283 # Tie the ICS to a worker node so that ICS will always be scheduled to the same worker node if the ICS pod is restarted
284 # A PVC of type hostPath is mounted to ICS, for persistent storage, so the ICS must always be on the node which mounted the volume
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200285
286 # Keep the initial worker node in case the pod need to be "restarted" - must be made to the same node due to a volume mounted on the host
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200287 if [ $retcode_i -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100288 __ICS_WORKER_NODE=$(kubectl get pod -l "autotest=ICS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
289 if [ -z "$__ICS_WORKER_NODE" ]; then
290 echo -e $YELLOW" Cannot find worker node for pod for $ICS_APP_NAME, persistency may not work"$EYELLOW
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200291 fi
292 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100293 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 +0200294 fi
295
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100296
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100297 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100298
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100299 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100300 __check_included_image 'ICS'
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100301 if [ $? -eq 1 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100302 echo -e $RED"The ICS app is not included in this test script"$ERED
303 echo -e $RED"ICS will not be started"$ERED
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100304 exit 1
305 fi
306
307 curdir=$PWD
308 cd $SIM_GROUP
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100309 cd ics
310 cd $ICS_HOST_MNT_DIR
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100311 #cd ..
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100312 if [ -d db ]; then
313 if [ "$(ls -A $DIR)" ]; then
314 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
315 rm -rf db/* &> /dev/null
316 if [ $? -ne 0 ]; then
317 echo -e $RED" Cannot remove database files in: $PWD"$ERED
318 exit 1
319 fi
320 fi
321 else
322 echo " No files in mounted dir or dir does not exists"
323 fi
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100324
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100325 cd $curdir
326
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100327 __ics_export_vars $1
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100328
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100329 dest_file=$SIM_GROUP/$ICS_COMPOSE_DIR/$ICS_HOST_MNT_DIR/$ICS_CONFIG_FILE
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100330
331 envsubst < $2 > $dest_file
332
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100333 __start_container $ICS_COMPOSE_DIR "" NODOCKERARGS 1 $ICS_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100334
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100335 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100336 fi
337 echo ""
338 return 0
339}
340
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100341# Stop the ics
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200342# args: -
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100343# args: -
344# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100345stop_ics() {
346 echo -e $BOLD"Stopping $ICS_DISPLAY_NAME"$EBOLD
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200347
348 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200349
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100350 __check_prestarted_image "ICS"
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200351 if [ $? -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100352 echo -e $YELLOW" Persistency may not work for app $ICS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
353 res_type=$(__kube_get_resource_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
354 __kube_scale $res_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200355 return 0
356 fi
357
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100358 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ICS
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200359 echo " Deleting the replica set - a new will be started when the app is started"
BjornMagnussonXAcb6113e2022-02-17 15:01:28 +0100360 tmp=$(kubectl $KUBECONF delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=ICS")
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200361 if [ $? -ne 0 ]; then
362 echo -e $RED" Could not delete replica set "$RED
363 ((RES_CONF_FAIL++))
364 return 1
365 fi
366 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100367 docker stop $ICS_APP_NAME &> ./tmp/.dockererr
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200368 if [ $? -ne 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100369 __print_err "Could not stop $ICS_APP_NAME" $@
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200370 cat ./tmp/.dockererr
371 ((RES_CONF_FAIL++))
372 return 1
373 fi
374 fi
375 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
376 echo ""
377 return 0
378}
379
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100380# Start a previously stopped ics
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200381# args: -
382# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100383start_stopped_ics() {
384 echo -e $BOLD"Starting (the previously stopped) $ICS_DISPLAY_NAME"$EBOLD
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200385
386 if [ $RUNMODE == "KUBE" ]; then
387
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100388 __check_prestarted_image "ICS"
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200389 if [ $? -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100390 echo -e $YELLOW" Persistency may not work for app $ICS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
391 res_type=$(__kube_get_resource_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
392 __kube_scale $res_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
393 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200394 return 0
395 fi
396
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200397 # Tie the PMS to the same worker node it was initially started on
398 # A PVC of type hostPath is mounted to PMS, for persistent storage, so the PMS must always be on the node which mounted the volume
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100399 if [ -z "$__ICS_WORKER_NODE" ]; then
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200400 echo -e $RED" No initial worker node found for pod "$RED
401 ((RES_CONF_FAIL++))
402 return 1
403 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100404 echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__ICS_WORKER_NODE to deployment for $ICS_APP_NAME. Pod will always run on this worker node: $__PA_WORKER_NODE"$BOLD
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200405 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
BjornMagnussonXAcb6113e2022-02-17 15:01:28 +0100406 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 +0200407 if [ $? -ne 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100408 echo -e $YELLOW" Cannot set nodeSelector to deployment for $ICS_APP_NAME, persistency may not work"$EYELLOW
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200409 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100410 __kube_scale deployment $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200411 fi
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200412 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100413 docker start $ICS_APP_NAME &> ./tmp/.dockererr
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200414 if [ $? -ne 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100415 __print_err "Could not start (the stopped) $ICS_APP_NAME" $@
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200416 cat ./tmp/.dockererr
417 ((RES_CONF_FAIL++))
418 return 1
419 fi
420 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100421 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100422 if [ $? -ne 0 ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100423 return 1
424 fi
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100425 echo ""
426 return 0
427}
428
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100429# Turn on debug level tracing in ICS
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100430# args: -
431# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100432set_ics_debug() {
433 echo -e $BOLD"Setting ics debug logging"$EBOLD
434 curlString="$ICS_SERVICE_PATH$ICS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100435 result=$(__do_curl "$curlString")
436 if [ $? -ne 0 ]; then
437 __print_err "Could not set debug mode" $@
438 ((RES_CONF_FAIL++))
439 return 1
440 fi
441 echo ""
442 return 0
443}
444
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100445# Turn on trace level tracing in ICS
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100446# args: -
447# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100448set_ics_trace() {
449 echo -e $BOLD"Setting ics trace logging"$EBOLD
450 curlString="$ICS_SERVICE_PATH/actuator/loggers/org.oransc.information -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100451 result=$(__do_curl "$curlString")
452 if [ $? -ne 0 ]; then
453 __print_err "Could not set trace mode" $@
454 ((RES_CONF_FAIL++))
455 return 1
456 fi
457 echo ""
458 return 0
459}
460
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100461# Perform curl retries when making direct call to ICS for the specified http response codes
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100462# Speace separated list of http response codes
463# args: [<response-code>]*
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100464use_ics_retries() {
465 echo -e $BOLD"Do curl retries to the ICS REST inteface for these response codes:$@"$EBOLD
466 ICS_RETRY_CODES=$@
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100467 echo ""
468 return 0
469}
470
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100471# Check the ics logs for WARNINGs and ERRORs
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100472# args: -
473# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100474check_ics_logs() {
475 __check_container_logs "ICS" $ICS_APP_NAME $ICS_LOGPATH WARN ERR
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100476}
477
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200478
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100479# Tests if a variable value in the ICS is equal to a target value and and optional timeout.
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100480# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
481# equal to the target or not.
482# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
483# before setting pass or fail depending on if the variable value becomes equal to the target
484# value or not.
485# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100486ics_equal() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100487 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100488 __var_test ICS "$ICS_SERVICE_PATH/" $1 "=" $2 $3
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100489 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100490 __print_err "Wrong args to ics_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100491 fi
492}
493
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200494
495##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100496######### A1-E information API ##########
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200497##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100498#Function prefix: ics_api_a1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200499
500# API Test function: GET /A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200501# args: <response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100502# args (flat uri structure): <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200503# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100504ics_api_a1_get_job_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100505 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200506
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100507 if [ -z "$FLAT_A1_EI" ]; then
508 # Valid number of parameters 4,5,6 etc
509 if [ $# -lt 3 ]; then
510 __print_err "<response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
511 return 1
512 fi
513 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100514 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100515 # Valid number of parameters 4,5,6 etc
516 if [ $# -lt 3 ]; then
517 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
518 return 1
519 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200520 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100521 search=""
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200522 if [ $3 != "NOWNER" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100523 search="?owner="$3
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200524 fi
525
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100526 if [ -z "$FLAT_A1_EI" ]; then
527 query="/A1-EI/v1/eitypes/$2/eijobs$search"
528 else
529 if [ $2 != "NOTYPE" ]; then
530 if [ -z "$search" ]; then
531 search="?eiTypeId="$2
532 else
533 search=$search"&eiTypeId="$2
534 fi
535 fi
536 query="/A1-EI/v1/eijobs$search"
537 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100538 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200539 status=${res:${#res}-3}
540
541 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100542 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200543 return 1
544 fi
545
546 if [ $# -gt 3 ]; then
547 body=${res:0:${#res}-3}
548 targetJson="["
549
550 for pid in ${@:4} ; do
551 if [ "$targetJson" != "[" ]; then
552 targetJson=$targetJson","
553 fi
554 if [ $pid != "EMPTY" ]; then
555 targetJson=$targetJson"\"$pid\""
556 fi
557 done
558
559 targetJson=$targetJson"]"
560 echo " TARGET JSON: $targetJson" >> $HTTPLOG
561 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
562
563 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100564 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200565 return 1
566 fi
567 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200568
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100569 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200570 return 0
571}
572
573# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200574# args: <response-code> <type-id> [<schema-file>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200575# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100576ics_api_a1_get_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100577 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200578
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200579 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
580 __print_err "<response-code> <type-id> [<schema-file>]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200581 return 1
582 fi
583
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200584 query="/A1-EI/v1/eitypes/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100585 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200586 status=${res:${#res}-3}
587
588 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100589 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200590 return 1
591 fi
592
593 if [ $# -eq 3 ]; then
594 body=${res:0:${#res}-3}
595 if [ -f $3 ]; then
596 schema=$(cat $3)
597 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100598 __log_test_fail_general "Schema file "$3", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200599 return 1
600 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100601 if [ -z "$FLAT_A1_EI" ]; then
602 targetJson="{\"eiJobParametersSchema\":$schema}"
603 else
604 targetJson=$schema
605 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200606 echo " TARGET JSON: $targetJson" >> $HTTPLOG
607 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
608
609 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100610 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200611 return 1
612 fi
613 fi
614
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100615 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200616 return 0
617}
618
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200619# API Test function: GET /A1-EI/v1/eitypes
620# args: <response-code> [ (EMPTY | [<type-id>]+) ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200621# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100622ics_api_a1_get_type_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100623 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200624
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200625 if [ $# -lt 1 ]; then
626 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200627 return 1
628 fi
629
630 query="/A1-EI/v1/eitypes"
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100631 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200632 status=${res:${#res}-3}
633
634 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100635 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200636 return 1
637 fi
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200638 if [ $# -gt 1 ]; then
639 body=${res:0:${#res}-3}
640 targetJson="["
641 if [ $2 != "EMPTY" ]; then
642 for pid in ${@:2} ; do
643 if [ "$targetJson" != "[" ]; then
644 targetJson=$targetJson","
645 fi
646 targetJson=$targetJson"\"$pid\""
647 done
648 fi
649 targetJson=$targetJson"]"
650 echo " TARGET JSON: $targetJson" >> $HTTPLOG
651 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200652
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200653 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100654 __log_test_fail_body
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200655 return 1
656 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200657 fi
658
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100659 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200660 return 0
661}
662
663# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200664# args: <response-code> <type-id> <job-id> [<status>]
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100665# args (flat uri structure): <response-code> <job-id> [<status> [<timeout>]]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200666# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100667ics_api_a1_get_job_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100668 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200669
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100670 if [ -z "$FLAT_A1_EI" ]; then
671 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
672 __print_err "<response-code> <type-id> <job-id> [<status>]" $@
673 return 1
674 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200675
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100676 query="/A1-EI/v1/eitypes/$2/eijobs/$3/status"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200677
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100678 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100679 status=${res:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200680
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100681 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100682 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200683 return 1
684 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100685 if [ $# -eq 4 ]; then
686 body=${res:0:${#res}-3}
687 targetJson="{\"operationalState\": \"$4\"}"
688 echo " TARGET JSON: $targetJson" >> $HTTPLOG
689 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
690
691 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100692 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100693 return 1
694 fi
695 fi
696 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100697 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100698 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
699 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100700 return 1
701 fi
702
703 query="/A1-EI/v1/eijobs/$2/status"
704
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100705 start=$SECONDS
706 for (( ; ; )); do
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100707 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100708 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100709
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100710 if [ $# -eq 4 ]; then
711 duration=$((SECONDS-start))
712 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
713 if [ $duration -gt $4 ]; then
714 echo ""
715 duration=-1 #Last iteration
716 fi
717 else
718 duration=-1 #single test, no wait
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100719 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100720
721 if [ $status -ne $1 ]; then
722 if [ $duration -eq -1 ]; then
723 __log_test_fail_status_code $1 $status
724 return 1
725 fi
726 fi
727 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
728 body=${res:0:${#res}-3}
729 targetJson="{\"eiJobStatus\": \"$3\"}"
730 echo " TARGET JSON: $targetJson" >> $HTTPLOG
731 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
732
733 if [ $res -ne 0 ]; then
734 if [ $duration -eq -1 ]; then
735 __log_test_fail_body
736 return 1
737 fi
738 else
739 duration=-1 #Goto pass
740 fi
741 fi
742 if [ $duration -eq -1 ]; then
743 if [ $# -eq 4 ]; then
744 echo ""
745 fi
746 __log_test_pass
747 return 0
748 else
749 sleep 1
750 fi
751 done
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200752 fi
753
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100754 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200755 return 0
756}
757
758# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200759# args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100760# args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200761# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100762ics_api_a1_get_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100763 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200764
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100765 if [ -z "$FLAT_A1_EI" ]; then
766 if [ $# -ne 3 ] && [ $# -ne 6 ]; then
767 __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@
768 return 1
769 fi
770 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
771 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100772 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100773 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
774 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
775 return 1
776 fi
777 query="/A1-EI/v1/eijobs/$2"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200778 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100779 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200780 status=${res:${#res}-3}
781
782 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100783 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200784 return 1
785 fi
786
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100787 if [ -z "$FLAT_A1_EI" ]; then
788 if [ $# -eq 6 ]; then
789 body=${res:0:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200790
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100791 if [ -f $6 ]; then
792 jobfile=$(cat $6)
793 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
794 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200795 __log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100796 return 1
797 fi
798 targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
799 echo " TARGET JSON: $targetJson" >> $HTTPLOG
800 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
801
802 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100803 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100804 return 1
805 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200806 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100807 else
808 if [ $# -eq 7 ]; then
809 body=${res:0:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200810
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100811 if [ -f $7 ]; then
812 jobfile=$(cat $7)
813 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
814 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200815 __log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100816 return 1
817 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100818 targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100819 echo " TARGET JSON: $targetJson" >> $HTTPLOG
820 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
821
822 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100823 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100824 return 1
825 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200826 fi
827 fi
828
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100829 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200830 return 0
831}
832
833# API Test function: DELETE ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200834# args: <response-code> <type-id> <job-id>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100835# args (flat uri structure): <response-code> <job-id>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200836# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100837ics_api_a1_delete_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100838 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200839
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100840 if [ -z "$FLAT_A1_EI" ]; then
841 if [ $# -ne 3 ]; then
842 __print_err "<response-code> <type-id> <job-id>" $@
843 return 1
844 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200845
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100846 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
847 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100848 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100849 if [ $# -ne 2 ]; then
850 __print_err "<response-code> <job-id>" $@
851 return 1
852 fi
853 query="/A1-EI/v1/eijobs/$2"
854 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100855 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200856 status=${res:${#res}-3}
857
858 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100859 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200860 return 1
861 fi
862
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100863 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200864 return 0
865}
866
867# API Test function: PUT ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200868# args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100869# 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 +0200870# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100871ics_api_a1_put_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100872 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200873
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100874 if [ -z "$FLAT_A1_EI" ]; then
875 if [ $# -lt 6 ]; then
876 __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@
877 return 1
878 fi
879 if [ -f $6 ]; then
880 jobfile=$(cat $6)
881 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
882 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200883 __log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100884 return 1
885 fi
886
887 inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
888 file="./tmp/.p.json"
889 echo "$inputJson" > $file
890
891 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200892 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100893 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100894 if [ $# -lt 7 ]; then
895 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@
896 return 1
897 fi
898 if [ -f $7 ]; then
899 jobfile=$(cat $7)
900 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
901 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200902 __log_test_fail_general "Job template file "$7", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100903 return 1
904 fi
905
906 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
907 file="./tmp/.p.json"
908 echo "$inputJson" > $file
909
910 query="/A1-EI/v1/eijobs/$2"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200911 fi
912
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100913 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200914 status=${res:${#res}-3}
915
916 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100917 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200918 return 1
919 fi
920
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100921 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200922 return 0
923}
924
925
926##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100927#### information Data Producer API ####
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200928##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100929# Function prefix: ics_api_edp
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200930
931# API Test function: GET /ei-producer/v1/eitypes
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200932# API Test function: GET /data-producer/v1/info-types
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200933# args: <response-code> [ EMPTY | <type-id>+]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200934# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100935ics_api_edp_get_type_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100936 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200937
938 if [ $# -lt 1 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200939 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200940 return 1
941 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100942 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200943 query="/data-producer/v1/info-types"
944 else
945 query="/ei-producer/v1/eitypes"
946 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100947 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200948 status=${res:${#res}-3}
949
950 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100951 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200952 return 1
953 fi
954
955 if [ $# -gt 1 ]; then
956 body=${res:0:${#res}-3}
957 targetJson="["
958 if [ $2 != "EMPTY" ]; then
959 for pid in ${@:2} ; do
960 if [ "$targetJson" != "[" ]; then
961 targetJson=$targetJson","
962 fi
963 targetJson=$targetJson"\"$pid\""
964 done
965 fi
966 targetJson=$targetJson"]"
967 echo " TARGET JSON: $targetJson" >> $HTTPLOG
968 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
969
970 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100971 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200972 return 1
973 fi
974 fi
975
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100976 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200977 return 0
978}
979
980# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200981# API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100982# args: <response-code> <producer-id> [<status> [<timeout>]]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200983# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100984ics_api_edp_get_producer_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100985 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200986
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100987 if [ $# -lt 2 ] || [ $# -gt 4 ]; then
988 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200989 return 1
990 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100991 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200992 query="/data-producer/v1/info-producers/$2/status"
993 else
994 query="/ei-producer/v1/eiproducers/$2/status"
995 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100996 start=$SECONDS
997 for (( ; ; )); do
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100998 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100999 status=${res:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001000
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001001 if [ $# -eq 4 ]; then
1002 duration=$((SECONDS-start))
1003 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
1004 if [ $duration -gt $4 ]; then
1005 echo ""
1006 duration=-1 #Last iteration
1007 fi
1008 else
1009 duration=-1 #single test, no wait
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001010 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001011
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001012 if [ $status -ne $1 ]; then
1013 if [ $duration -eq -1 ]; then
1014 __log_test_fail_status_code $1 $status
1015 return 1
1016 fi
1017 fi
1018 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
1019 body=${res:0:${#res}-3}
1020 targetJson="{\"operational_state\": \"$3\"}"
1021 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1022 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1023
1024 if [ $res -ne 0 ]; then
1025 if [ $duration -eq -1 ]; then
1026 __log_test_fail_body
1027 return 1
1028 fi
1029 else
1030 duration=-1 #Goto pass
1031 fi
1032 fi
1033 if [ $duration -eq -1 ]; then
1034 if [ $# -eq 4 ]; then
1035 echo ""
1036 fi
1037 __log_test_pass
1038 return 0
1039 else
1040 sleep 1
1041 fi
1042 done
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001043}
1044
1045
1046# API Test function: GET /ei-producer/v1/eiproducers
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001047# args (v1_1): <response-code> [ EMPTY | <producer-id>+]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001048# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001049ics_api_edp_get_producer_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001050 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001051
1052 if [ $# -lt 1 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001053 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001054 return 1
1055 fi
1056
1057 query="/ei-producer/v1/eiproducers"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001058 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001059 status=${res:${#res}-3}
1060
1061 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001062 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001063 return 1
1064 fi
1065
1066 if [ $# -gt 1 ]; then
1067 body=${res:0:${#res}-3}
1068 targetJson="["
1069
1070 for pid in ${@:2} ; do
1071 if [ "$targetJson" != "[" ]; then
1072 targetJson=$targetJson","
1073 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001074 if [ $pid != "EMPTY" ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001075 targetJson=$targetJson"\"$pid\""
1076 fi
1077 done
1078
1079 targetJson=$targetJson"]"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001080 echo " TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001081 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1082
1083 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001084 __log_test_fail_body
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001085 return 1
1086 fi
1087 fi
1088
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001089 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001090 return 0
1091}
1092
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001093# API Test function: GET /ei-producer/v1/eiproducers
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001094# API Test function: GET /data-producer/v1/info-producers
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001095# args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]
1096# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001097ics_api_edp_get_producer_ids_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001098 __log_test_start $@
1099
1100 if [ $# -lt 1 ]; then
1101 __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
1102 return 1
1103 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001104 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001105 query="/data-producer/v1/info-producers"
1106 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1107 query=$query"?info_type_id=$2"
1108 fi
1109 else
1110 query="/ei-producer/v1/eiproducers"
1111 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1112 query=$query"?ei_type_id=$2"
1113 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001114 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001115 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001116 status=${res:${#res}-3}
1117
1118 if [ $status -ne $1 ]; then
1119 __log_test_fail_status_code $1 $status
1120 return 1
1121 fi
1122
1123 if [ $# -gt 2 ]; then
1124 body=${res:0:${#res}-3}
1125 targetJson="["
1126
1127 for pid in ${@:3} ; do
1128 if [ "$targetJson" != "[" ]; then
1129 targetJson=$targetJson","
1130 fi
1131 if [ $pid != "EMPTY" ]; then
1132 targetJson=$targetJson"\"$pid\""
1133 fi
1134 done
1135
1136 targetJson=$targetJson"]"
1137 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1138 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1139
1140 if [ $res -ne 0 ]; then
1141 __log_test_fail_body
1142 return 1
1143 fi
1144 fi
1145
1146 __log_test_pass
1147 return 0
1148}
1149
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001150# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001151# args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001152# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001153ics_api_edp_get_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001154 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001155
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001156 paramError=1
1157 if [ $# -eq 2 ]; then
1158 paramError=0
1159 fi
1160 if [ $# -gt 3 ]; then
1161 paramError=0
1162 fi
1163 if [ $paramError -ne 0 ]; then
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +02001164 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001165 return 1
1166 fi
1167
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001168 query="/ei-producer/v1/eitypes/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001169 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001170 status=${res:${#res}-3}
1171
1172 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001173 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001174 return 1
1175 fi
1176 if [ $# -gt 3 ]; then
1177 body=${res:0:${#res}-3}
1178
1179 if [ -f $3 ]; then
1180 schema=$(cat $3)
1181 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001182 __log_test_fail_general "Job template file "$3", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001183 return 1
1184 fi
1185
1186 targetJson=""
1187 if [ $4 != "EMPTY" ]; then
1188 for pid in ${@:4} ; do
1189 if [ "$targetJson" != "" ]; then
1190 targetJson=$targetJson","
1191 fi
1192 targetJson=$targetJson"\"$pid\""
1193 done
1194 fi
1195 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
1196
1197 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1198 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1199
1200 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001201 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001202 return 1
1203 fi
1204 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001205 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001206 return 0
1207}
1208
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001209# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001210# API Test function: GET /data-producer/v1/info-types/{infoTypeId}
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001211# args: (v1_2) <response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001212# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001213ics_api_edp_get_type_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001214 __log_test_start $@
1215
1216 paramError=1
1217 if [ $# -eq 2 ]; then
1218 paramError=0
1219 fi
1220 if [ $# -eq 3 ]; then
1221 paramError=0
1222 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001223 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001224 if [ $# -eq 4 ]; then
1225 paramError=0
1226 fi
1227 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001228 if [ $paramError -ne 0 ]; then
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001229 __print_err "<response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]" $@
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001230 return 1
1231 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001232 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001233 query="/data-producer/v1/info-types/$2"
1234 else
1235 query="/ei-producer/v1/eitypes/$2"
1236 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001237
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001238 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001239 status=${res:${#res}-3}
1240
1241 if [ $status -ne $1 ]; then
1242 __log_test_fail_status_code $1 $status
1243 return 1
1244 fi
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001245 if [ $# -ge 3 ]; then
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001246 body=${res:0:${#res}-3}
1247
1248 if [ -f $3 ]; then
1249 schema=$(cat $3)
1250 else
1251 __log_test_fail_general "Job template file "$3", does not exist"
1252 return 1
1253 fi
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001254 info_data=""
1255 if [ $# -gt 3 ]; then
1256 if [ -f $4 ]; then
1257 info_data=$(cat $4)
1258 else
1259 __log_test_fail_general "Info-data file "$4", does not exist"
1260 return 1
1261 fi
1262 info_data=",\"info_type_information\":$info_data"
1263 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001264 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001265 targetJson="{\"info_job_data_schema\":$schema $info_data}"
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001266 else
1267 targetJson="{\"ei_job_data_schema\":$schema}"
1268 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001269
1270 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1271 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1272
1273 if [ $res -ne 0 ]; then
1274 __log_test_fail_body
1275 return 1
1276 fi
1277 fi
1278 __log_test_pass
1279 return 0
1280}
1281
1282# API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001283# API Test function: PUT /data-producer/v1/info-types/{infoTypeId}
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001284# args: (v1_2) <response-code> <type-id> <job-schema-file> [ <info-type-info> ]
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001285# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001286ics_api_edp_put_type_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001287 __log_test_start $@
1288
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001289 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001290 if [ $# -lt 3 ] || [ $# -gt 4 ]; then
1291 __print_err "<response-code> <type-id> <job-schema-file> [ <info-type-info> ]" $@
1292 return 1
1293 fi
1294 else
1295 if [ $# -ne 3 ]; then
1296 __print_err "<response-code> <type-id> <job-schema-file>" $@
1297 return 1
1298 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001299 fi
1300
1301 if [ ! -f $3 ]; then
1302 __log_test_fail_general "Job schema file "$3", does not exist"
1303 return 1
1304 fi
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001305
1306 info_data=""
1307 if [ $# -gt 3 ]; then
1308 if [ -f $4 ]; then
1309 info_data=$(cat $4)
1310 else
1311 __log_test_fail_general "Info-data file "$4", does not exist"
1312 return 1
1313 fi
1314 info_data=",\"info_type_information\":$info_data"
1315 fi
1316
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001317 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001318 schema=$(cat $3)
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001319 input_json="{\"info_job_data_schema\":$schema $info_data}"
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001320 file="./tmp/put_type.json"
1321 echo $input_json > $file
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001322
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001323 query="/data-producer/v1/info-types/$2"
1324 else
1325 schema=$(cat $3)
1326 input_json="{\"ei_job_data_schema\":$schema}"
1327 file="./tmp/put_type.json"
1328 echo $input_json > $file
1329
1330 query="/ei-producer/v1/eitypes/$2"
1331 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001332 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001333 status=${res:${#res}-3}
1334
1335 if [ $status -ne $1 ]; then
1336 __log_test_fail_status_code $1 $status
1337 return 1
1338 fi
1339
1340 __log_test_pass
1341 return 0
1342}
1343
1344# API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001345# API Test function: DELETE /data-producer/v1/info-types/{infoTypeId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001346# args: (v1_2) <response-code> <type-id>
1347# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001348ics_api_edp_delete_type_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001349 __log_test_start $@
1350
1351 if [ $# -ne 2 ]; then
1352 __print_err "<response-code> <type-id>" $@
1353 return 1
1354 fi
1355
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001356 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001357 query="/data-producer/v1/info-types/$2"
1358 else
1359 query="/ei-producer/v1/eitypes/$2"
1360 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001361 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001362 status=${res:${#res}-3}
1363
1364 if [ $status -ne $1 ]; then
1365 __log_test_fail_status_code $1 $status
1366 return 1
1367 fi
1368
1369 __log_test_pass
1370 return 0
1371}
1372
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001373# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001374# args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001375# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001376ics_api_edp_get_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001377 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001378
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001379 #Possible arg count: 2, 5 6, 8, 10 etc
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001380 paramError=1
1381 if [ $# -eq 2 ]; then
1382 paramError=0
1383 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001384 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001385 paramError=0
1386 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001387 variablecount=$(($#-4))
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001388 if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
1389 paramError=0
1390 fi
1391
1392 if [ $paramError -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001393 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001394 return 1
1395 fi
1396
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001397 query="/ei-producer/v1/eiproducers/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001398 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001399 status=${res:${#res}-3}
1400
1401 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001402 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001403 return 1
1404 fi
1405
1406 if [ $# -gt 2 ]; then
1407 body=${res:0:${#res}-3}
1408 targetJson="["
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001409 if [ $# -gt 5 ]; then
1410 arr=(${@:5})
1411 for ((i=0; i<$(($#-5)); i=i+2)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001412 if [ "$targetJson" != "[" ]; then
1413 targetJson=$targetJson","
1414 fi
1415 if [ -f ${arr[$i+1]} ]; then
1416 schema=$(cat ${arr[$i+1]})
1417 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001418 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001419 return 1
1420 fi
1421
1422 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1423 done
1424 fi
1425 targetJson=$targetJson"]"
1426 if [ $# -gt 4 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001427 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001428 fi
1429 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1430 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1431
1432 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001433 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001434 return 1
1435 fi
1436 fi
1437
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001438 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001439 return 0
1440}
1441
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001442# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001443# API Test function: GET /data-producer/v1/info-producers/{infoProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001444# args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]
1445# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001446ics_api_edp_get_producer_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001447 __log_test_start $@
1448
1449 #Possible arg count: 2, 5, 6, 7, 8 etc
1450 paramError=1
1451 if [ $# -eq 2 ]; then
1452 paramError=0
1453 fi
1454 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1455 paramError=0
1456 fi
1457 if [ $# -ge 5 ]; then
1458 paramError=0
1459 fi
1460
1461 if [ $paramError -ne 0 ]; then
1462 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
1463 return 1
1464 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001465 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001466 query="/data-producer/v1/info-producers/$2"
1467 else
1468 query="/ei-producer/v1/eiproducers/$2"
1469 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001470 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001471 status=${res:${#res}-3}
1472
1473 if [ $status -ne $1 ]; then
1474 __log_test_fail_status_code $1 $status
1475 return 1
1476 fi
1477
1478 if [ $# -gt 2 ]; then
1479 body=${res:0:${#res}-3}
1480 targetJson="["
1481 if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
1482 arr=(${@:5})
1483 for ((i=0; i<$(($#-4)); i=i+1)); do
1484 if [ "$targetJson" != "[" ]; then
1485 targetJson=$targetJson","
1486 fi
1487 targetJson=$targetJson"\"${arr[$i]}\""
1488 done
1489 fi
1490 targetJson=$targetJson"]"
1491 if [ $# -gt 4 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001492 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001493 targetJson="{\"supported_info_types\":$targetJson,\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\"}"
1494 else
1495 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1496 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001497 fi
1498 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1499 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1500
1501 if [ $res -ne 0 ]; then
1502 __log_test_fail_body
1503 return 1
1504 fi
1505 fi
1506
1507 __log_test_pass
1508 return 0
1509}
1510
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001511# API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001512# API Test function: DELETE /data-producer/v1/info-producers/{infoProducerId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001513# args: <response-code> <producer-id>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001514# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001515ics_api_edp_delete_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001516 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001517
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001518 if [ $# -lt 2 ]; then
1519 __print_err "<response-code> <producer-id>" $@
1520 return 1
1521 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001522 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001523 query="/data-producer/v1/info-producers/$2"
1524 else
1525 query="/ei-producer/v1/eiproducers/$2"
1526 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001527 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001528 status=${res:${#res}-3}
1529
1530 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001531 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001532 return 1
1533 fi
1534
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001535 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001536 return 0
1537}
1538
1539# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001540# args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001541# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001542ics_api_edp_put_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001543 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001544
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001545 #Valid number of parametrer 5,6,8,10,
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001546 paramError=1
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001547 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001548 paramError=0
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001549 elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001550 paramError=0
1551 fi
1552 if [ $paramError -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001553 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001554 return 1
1555 fi
1556
1557 inputJson="["
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001558 if [ $# -gt 5 ]; then
1559 arr=(${@:5})
1560 for ((i=0; i<$(($#-5)); i=i+2)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001561 if [ "$inputJson" != "[" ]; then
1562 inputJson=$inputJson","
1563 fi
1564 if [ -f ${arr[$i+1]} ]; then
1565 schema=$(cat ${arr[$i+1]})
1566 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001567 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001568 return 1
1569 fi
1570 inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1571 done
1572 fi
1573 inputJson="\"supported_ei_types\":"$inputJson"]"
1574
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001575 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001576
1577 inputJson="{"$inputJson"}"
1578
1579 file="./tmp/.p.json"
1580 echo "$inputJson" > $file
1581 query="/ei-producer/v1/eiproducers/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001582 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001583 status=${res:${#res}-3}
1584
1585 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001586 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001587 return 1
1588 fi
1589
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001590 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001591 return 0
1592}
1593
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001594# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001595# API Test function: PUT /data-producer/v1/info-producers/{infoProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001596# args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]
1597# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001598ics_api_edp_put_producer_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001599 __log_test_start $@
1600
1601 #Valid number of parametrer 5,6,8,10,
1602 paramError=1
1603 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1604 paramError=0
1605 elif [ $# -ge 5 ]; then
1606 paramError=0
1607 fi
1608 if [ $paramError -ne 0 ]; then
1609 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
1610 return 1
1611 fi
1612
1613 inputJson="["
1614 if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
1615 arr=(${@:5})
1616 for ((i=0; i<$(($#-4)); i=i+1)); do
1617 if [ "$inputJson" != "[" ]; then
1618 inputJson=$inputJson","
1619 fi
1620 inputJson=$inputJson"\""${arr[$i]}"\""
1621 done
1622 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001623 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001624 inputJson="\"supported_info_types\":"$inputJson"]"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001625
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001626 inputJson=$inputJson",\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\""
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001627
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001628 inputJson="{"$inputJson"}"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001629
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001630 file="./tmp/.p.json"
1631 echo "$inputJson" > $file
1632 query="/data-producer/v1/info-producers/$2"
1633 else
1634 inputJson="\"supported_ei_types\":"$inputJson"]"
1635
1636 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1637
1638 inputJson="{"$inputJson"}"
1639
1640 file="./tmp/.p.json"
1641 echo "$inputJson" > $file
1642 query="/ei-producer/v1/eiproducers/$2"
1643 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001644 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001645 status=${res:${#res}-3}
1646
1647 if [ $status -ne $1 ]; then
1648 __log_test_fail_status_code $1 $status
1649 return 1
1650 fi
1651
1652 __log_test_pass
1653 return 0
1654}
1655
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001656# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001657# 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 +02001658# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001659ics_api_edp_get_producer_jobs() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001660 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001661
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001662 #Valid number of parameter 2,3,7,11
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001663 paramError=1
1664 if [ $# -eq 2 ]; then
1665 paramError=0
1666 fi
1667 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1668 paramError=0
1669 fi
1670 variablecount=$(($#-2))
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001671 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001672 paramError=0
1673 fi
1674 if [ $paramError -eq 1 ]; then
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001675 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001676 return 1
1677 fi
1678
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001679 query="/ei-producer/v1/eiproducers/$2/eijobs"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001680 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001681 status=${res:${#res}-3}
1682 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001683 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001684 return 1
1685 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001686 if [ $# -gt 2 ]; then
1687 body=${res:0:${#res}-3}
1688 targetJson="["
1689 if [ $# -gt 3 ]; then
1690 arr=(${@:3})
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001691 for ((i=0; i<$(($#-3)); i=i+5)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001692 if [ "$targetJson" != "[" ]; then
1693 targetJson=$targetJson","
1694 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001695 if [ -f ${arr[$i+4]} ]; then
1696 jobfile=$(cat ${arr[$i+4]})
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001697 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1698 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001699 __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001700 return 1
1701 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001702 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 +02001703 done
1704 fi
1705 targetJson=$targetJson"]"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001706
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001707 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1708 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001709
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001710 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001711 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001712 return 1
1713 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001714 fi
1715
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001716 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001717 return 0
1718}
1719
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001720# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001721# API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/info-jobs
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001722# args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1723# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001724ics_api_edp_get_producer_jobs_2() {
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001725 __log_test_start $@
1726
1727 #Valid number of parameter 2,3,7,11
1728 paramError=1
1729 if [ $# -eq 2 ]; then
1730 paramError=0
1731 fi
1732 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1733 paramError=0
1734 fi
1735 variablecount=$(($#-2))
1736 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1737 paramError=0
1738 fi
1739 if [ $paramError -eq 1 ]; then
1740 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1741 return 1
1742 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001743 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001744 query="/data-producer/v1/info-producers/$2/info-jobs"
1745 else
1746 query="/ei-producer/v1/eiproducers/$2/eijobs"
1747 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001748 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001749 status=${res:${#res}-3}
1750 if [ $status -ne $1 ]; then
1751 __log_test_fail_status_code $1 $status
1752 return 1
1753 fi
1754 if [ $# -gt 2 ]; then
1755 body=${res:0:${#res}-3}
1756 targetJson="["
1757 if [ $# -gt 3 ]; then
1758 arr=(${@:3})
1759 for ((i=0; i<$(($#-3)); i=i+5)); do
1760 if [ "$targetJson" != "[" ]; then
1761 targetJson=$targetJson","
1762 fi
1763 if [ -f ${arr[$i+4]} ]; then
1764 jobfile=$(cat ${arr[$i+4]})
1765 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1766 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001767 __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001768 return 1
1769 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001770 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001771 targetJson=$targetJson"{\"info_job_identity\":\"${arr[$i]}\",\"info_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"info_job_data\":$jobfile, \"last_updated\":\"????\"}"
1772 else
1773 targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"ei_job_data\":$jobfile, \"last_updated\":\"????\"}"
1774 fi
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001775 done
1776 fi
1777 targetJson=$targetJson"]"
1778
1779 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1780 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1781
1782 if [ $res -ne 0 ]; then
1783 __log_test_fail_body
1784 return 1
1785 fi
1786 fi
1787
1788 __log_test_pass
1789 return 0
1790}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001791
1792##########################################
1793#### Service status ####
1794##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001795# Function prefix: ics_api_service
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001796
1797# API Test function: GET ​/status
1798# args: <response-code>
1799# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001800ics_api_service_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001801 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001802
1803 if [ $# -lt 1 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001804 __print_err "<response-code>" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001805 return 1
1806 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001807 res="$(__do_curl_to_api ICS GET /status)"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001808 status=${res:${#res}-3}
1809 if [ $status -ne $1 ]; then
1810 __log_test_fail_status_code $1 $status
1811 return 1
1812 fi
1813 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001814 return 0
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001815}
1816
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001817###########################################
1818######### Info data consumer API ##########
1819###########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001820#Function prefix: ics_api_idc
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001821
1822
1823# API Test function: GET /data-consumer/v1/info-types
1824# args: <response-code> [ (EMPTY | [<type-id>]+) ]
1825# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001826ics_api_idc_get_type_ids() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001827 __log_test_start $@
1828
1829 if [ $# -lt 1 ]; then
1830 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
1831 return 1
1832 fi
1833
1834 query="/data-consumer/v1/info-types"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001835 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001836 status=${res:${#res}-3}
1837
1838 if [ $status -ne $1 ]; then
1839 __log_test_fail_status_code $1 $status
1840 return 1
1841 fi
1842 if [ $# -gt 1 ]; then
1843 body=${res:0:${#res}-3}
1844 targetJson="["
1845 if [ $2 != "EMPTY" ]; then
1846 for pid in ${@:2} ; do
1847 if [ "$targetJson" != "[" ]; then
1848 targetJson=$targetJson","
1849 fi
1850 targetJson=$targetJson"\"$pid\""
1851 done
1852 fi
1853 targetJson=$targetJson"]"
1854 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1855 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1856
1857 if [ $res -ne 0 ]; then
1858 __log_test_fail_body
1859 return 1
1860 fi
1861 fi
1862
1863 __log_test_pass
1864 return 0
1865}
1866
1867# API Test function: GET /data-consumer/v1/info-jobs
1868# args: <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
1869# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001870ics_api_idc_get_job_ids() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001871 __log_test_start $@
1872
1873 # Valid number of parameters 4,5,6 etc
1874 if [ $# -lt 3 ]; then
1875 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
1876 return 1
1877 fi
1878 search=""
1879 if [ $3 != "NOWNER" ]; then
1880 search="?owner="$3
1881 fi
1882
1883 if [ $2 != "NOTYPE" ]; then
1884 if [ -z "$search" ]; then
1885 search="?infoTypeId="$2
1886 else
1887 search=$search"&infoTypeId="$2
1888 fi
1889 fi
1890 query="/data-consumer/v1/info-jobs$search"
1891
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001892 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001893 status=${res:${#res}-3}
1894
1895 if [ $status -ne $1 ]; then
1896 __log_test_fail_status_code $1 $status
1897 return 1
1898 fi
1899
1900 if [ $# -gt 3 ]; then
1901 body=${res:0:${#res}-3}
1902 targetJson="["
1903
1904 for pid in ${@:4} ; do
1905 if [ "$targetJson" != "[" ]; then
1906 targetJson=$targetJson","
1907 fi
1908 if [ $pid != "EMPTY" ]; then
1909 targetJson=$targetJson"\"$pid\""
1910 fi
1911 done
1912
1913 targetJson=$targetJson"]"
1914 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1915 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1916
1917 if [ $res -ne 0 ]; then
1918 __log_test_fail_body
1919 return 1
1920 fi
1921 fi
1922
1923 __log_test_pass
1924 return 0
1925}
1926
1927# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}
1928# args: <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
1929# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001930ics_api_idc_get_job() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001931 __log_test_start $@
1932
1933 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
1934 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
1935 return 1
1936 fi
1937 query="/data-consumer/v1/info-jobs/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001938 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001939 status=${res:${#res}-3}
1940
1941 if [ $status -ne $1 ]; then
1942 __log_test_fail_status_code $1 $status
1943 return 1
1944 fi
1945
1946 if [ $# -eq 7 ]; then
1947 body=${res:0:${#res}-3}
1948
1949 if [ -f $7 ]; then
1950 jobfile=$(cat $7)
1951 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1952 else
1953 __log_test_fail_general "Job template file "$6", does not exist"
1954 return 1
1955 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001956 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 +02001957 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1958 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1959
1960 if [ $res -ne 0 ]; then
1961 __log_test_fail_body
1962 return 1
1963 fi
1964 fi
1965
1966 __log_test_pass
1967 return 0
1968}
1969
1970
1971# API Test function: PUT ​/data-consumer/v1/info-jobs/{infoJobId}
1972# args: <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]
1973# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001974ics_api_idc_put_job() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001975 __log_test_start $@
1976
1977 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1978 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]" $@
1979 return 1
1980 fi
1981 if [ -f $7 ]; then
1982 jobfile=$(cat $7)
1983 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1984 else
1985 __log_test_fail_general "Job template file "$7", does not exist"
1986 return 1
1987 fi
1988
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001989 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 +02001990 file="./tmp/.p.json"
1991 echo "$inputJson" > $file
1992
1993 query="/data-consumer/v1/info-jobs/$2"
1994
1995 if [ $# -eq 8 ]; then
1996 if [ $8 == "VALIDATE" ]; then
1997 query=$query"?typeCheck=true"
1998 fi
1999 fi
2000
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002001 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002002 status=${res:${#res}-3}
2003
2004 if [ $status -ne $1 ]; then
2005 __log_test_fail_status_code $1 $status
2006 return 1
2007 fi
2008
2009 __log_test_pass
2010 return 0
2011}
2012
2013# API Test function: DELETE ​/data-consumer/v1/info-jobs/{infoJobId}
2014# args: <response-code> <job-id>
2015# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002016ics_api_idc_delete_job() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002017 __log_test_start $@
2018
2019 if [ $# -ne 2 ]; then
2020 __print_err "<response-code> <job-id>" $@
2021 return 1
2022 fi
2023 query="/data-consumer/v1/info-jobs/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002024 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002025 status=${res:${#res}-3}
2026
2027 if [ $status -ne $1 ]; then
2028 __log_test_fail_status_code $1 $status
2029 return 1
2030 fi
2031
2032 __log_test_pass
2033 return 0
2034}
2035
2036# API Test function: GET ​/data-consumer/v1/info-types/{infoTypeId}
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002037# args: <response-code> <type-id> [<schema-file> [<type-status> <producers-count]]
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002038# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002039ics_api_idc_get_type() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002040 __log_test_start $@
2041
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002042 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
2043 __print_err "<response-code> <type-id> [<schema-file> [<type-status> <producers-count]]" $@
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002044 return 1
2045 fi
2046
2047 query="/data-consumer/v1/info-types/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002048 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002049 status=${res:${#res}-3}
2050
2051 if [ $status -ne $1 ]; then
2052 __log_test_fail_status_code $1 $status
2053 return 1
2054 fi
2055
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002056 if [ $# -gt 2 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002057 body=${res:0:${#res}-3}
2058 if [ -f $3 ]; then
2059 schema=$(cat $3)
2060 else
2061 __log_test_fail_general "Schema file "$3", does not exist"
2062 return 1
2063 fi
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002064 if [ $# -eq 5 ]; then
2065 targetJson="{\"job_data_schema\":$schema, \"type_status\":\"$4\", \"no_of_producers\":$5}"
2066 else
2067 targetJson="{\"job_data_schema\":$schema}"
2068 fi
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002069 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2070 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2071
2072 if [ $res -ne 0 ]; then
2073 __log_test_fail_body
2074 return 1
2075 fi
2076 fi
2077
2078 __log_test_pass
2079 return 0
2080}
2081
2082# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002083# This test only status during an optional timeout. No test of the list of producers
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002084# args: <response-code> <job-id> [<status> [<timeout>]]
2085# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002086ics_api_idc_get_job_status() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002087 __log_test_start $@
2088
2089 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
2090 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
2091 return 1
2092 fi
2093
2094 query="/data-consumer/v1/info-jobs/$2/status"
2095
2096 start=$SECONDS
2097 for (( ; ; )); do
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002098 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002099 status=${res:${#res}-3}
2100
2101 if [ $# -eq 4 ]; then
2102 duration=$((SECONDS-start))
2103 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2104 if [ $duration -gt $4 ]; then
2105 echo ""
2106 duration=-1 #Last iteration
2107 fi
2108 else
2109 duration=-1 #single test, no wait
2110 fi
2111
2112 if [ $status -ne $1 ]; then
2113 if [ $duration -eq -1 ]; then
2114 __log_test_fail_status_code $1 $status
2115 return 1
2116 fi
2117 fi
2118 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
2119 body=${res:0:${#res}-3}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02002120 targetJson="{\"info_job_status\": \"$3\"}"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002121 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2122 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2123
2124 if [ $res -ne 0 ]; then
2125 if [ $duration -eq -1 ]; then
2126 __log_test_fail_body
2127 return 1
2128 fi
2129 else
2130 duration=-1 #Goto pass
2131 fi
2132 fi
2133 if [ $duration -eq -1 ]; then
2134 if [ $# -eq 4 ]; then
2135 echo ""
2136 fi
2137 __log_test_pass
2138 return 0
2139 else
2140 sleep 1
2141 fi
2142 done
2143
2144 __log_test_pass
2145 return 0
2146}
2147
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002148# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
2149# This function test status and the list of producers with and optional timeout
2150# args: <response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]
2151# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002152ics_api_idc_get_job_status2() {
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002153
2154 __log_test_start $@
2155 param_error=0
2156 if [ $# -lt 2 ]; then
2157 param_error=1
2158 fi
2159 args=("$@")
2160 timeout=0
2161 if [ $# -gt 2 ]; then
2162 if [ $# -lt 4 ]; then
2163 param_error=1
2164 fi
2165 targetJson="{\"info_job_status\": \"$3\""
2166 if [ "$4" == "EMPTYPROD" ]; then
2167 targetJson=$targetJson",\"producers\": []}"
2168 if [ $# -gt 4 ]; then
2169 timeout=$5
2170 fi
2171 else
2172 targetJson=$targetJson",\"producers\": ["
2173 if [ $# -eq $(($4+5)) ]; then
2174 idx=$(($4+4))
2175 timeout=${args[$idx]}
2176 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002177 for ((ics_i = 0 ; ics_i < $4 ; ics_i++)); do
2178 idx=$(($ics_i+4))
2179 if [ $ics_i -gt 0 ]; then
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002180 targetJson=$targetJson","
2181 fi
2182 targetJson=$targetJson"\""${args[$idx]}"\""
2183 done
2184 targetJson=$targetJson"]}"
2185 fi
2186 fi
2187
2188 if [ $param_error -ne 0 ]; then
2189 __print_err "<response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]" $@
2190 return 1
2191 fi
2192
2193 query="/data-consumer/v1/info-jobs/$2/status"
2194
2195 start=$SECONDS
2196 for (( ; ; )); do
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002197 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002198 status=${res:${#res}-3}
2199
2200 if [ $# -gt 2 ]; then
2201 duration=$((SECONDS-start))
2202 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2203 if [ $duration -gt $timeout ]; then
2204 echo ""
2205 duration=-1 #Last iteration
2206 fi
2207 else
2208 duration=-1 #single test, no wait
2209 fi
2210
2211 if [ $status -ne $1 ]; then
2212 if [ $duration -eq -1 ]; then
2213 __log_test_fail_status_code $1 $status
2214 return 1
2215 fi
2216 fi
2217 if [ $# -gt 2 ] && [ $status -eq $1 ]; then
2218 body=${res:0:${#res}-3}
2219 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2220 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2221
2222 if [ $res -ne 0 ]; then
2223 if [ $duration -eq -1 ]; then
2224 __log_test_fail_body
2225 return 1
2226 fi
2227 else
2228 duration=-1 #Goto pass
2229 fi
2230 fi
2231 if [ $duration -eq -1 ]; then
2232 if [ $# -eq 4 ]; then
2233 echo ""
2234 fi
2235 __log_test_pass
2236 return 0
2237 else
2238 sleep 1
2239 fi
2240 done
2241
2242 __log_test_pass
2243 return 0
2244}
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002245
2246##########################################
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002247#### Type subscriptions ####
2248##########################################
2249
2250# API Test function: GET /data-consumer/v1/info-type-subscription
2251# args: <response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]
2252# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002253ics_api_idc_get_subscription_ids() {
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002254 __log_test_start $@
2255
2256 if [ $# -lt 3 ]; then
2257 __print_err "<response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]" $@
2258 return 1
2259 fi
2260
2261 query="/data-consumer/v1/info-type-subscription"
2262 search=""
2263 if [ $2 != "NOOWNER" ]; then
2264 search="?owner="$2
2265 fi
2266
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002267 res="$(__do_curl_to_api ICS GET $query$search)"
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002268 status=${res:${#res}-3}
2269
2270 if [ $status -ne $1 ]; then
2271 __log_test_fail_status_code $1 $status
2272 return 1
2273 fi
2274
2275 if [ $# -gt 2 ]; then
2276 body=${res:0:${#res}-3}
2277 targetJson="["
2278 if [ $3 != "EMPTY" ]; then
2279 for pid in ${@:3} ; do
2280 if [ "$targetJson" != "[" ]; then
2281 targetJson=$targetJson","
2282 fi
2283 targetJson=$targetJson"\"$pid\""
2284 done
2285 fi
2286 targetJson=$targetJson"]"
2287 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2288 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2289
2290 if [ $res -ne 0 ]; then
2291 __log_test_fail_body
2292 return 1
2293 fi
2294 fi
2295
2296 __log_test_pass
2297 return 0
2298}
2299
2300# API Test function: GET /data-consumer/v1/info-type-subscription/{subscriptionId}
2301# args: <response-code> <subscription-id> [ <owner-id> <status-uri> ]
2302# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002303ics_api_idc_get_subscription() {
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002304 __log_test_start $@
2305
2306 if [ $# -ne 2 ] && [ $# -ne 4 ]; then
2307 __print_err "<response-code> <subscription-id> [ <owner-id> <status-uri> ]" $@
2308 return 1
2309 fi
2310
2311 query="/data-consumer/v1/info-type-subscription/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002312 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002313 status=${res:${#res}-3}
2314
2315 if [ $status -ne $1 ]; then
2316 __log_test_fail_status_code $1 $status
2317 return 1
2318 fi
2319
2320 if [ $# -gt 2 ]; then
2321 body=${res:0:${#res}-3}
2322 targetJson="{\"owner\":\"$3\",\"status_result_uri\":\"$4\"}"
2323 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2324 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2325
2326 if [ $res -ne 0 ]; then
2327 __log_test_fail_body
2328 return 1
2329 fi
2330 fi
2331
2332 __log_test_pass
2333 return 0
2334}
2335
2336# API Test function: PUT /data-consumer/v1/info-type-subscription/{subscriptionId}
2337# args: <response-code> <subscription-id> <owner-id> <status-uri>
2338# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002339ics_api_idc_put_subscription() {
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002340 __log_test_start $@
2341
2342 if [ $# -ne 4 ]; then
2343 __print_err "<response-code> <subscription-id> <owner-id> <status-uri>" $@
2344 return 1
2345 fi
2346
2347 inputJson="{\"owner\": \"$3\",\"status_result_uri\": \"$4\"}"
2348 file="./tmp/.p.json"
2349 echo "$inputJson" > $file
2350
2351 query="/data-consumer/v1/info-type-subscription/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002352 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002353 status=${res:${#res}-3}
2354
2355 if [ $status -ne $1 ]; then
2356 __log_test_fail_status_code $1 $status
2357 return 1
2358 fi
2359
2360 __log_test_pass
2361 return 0
2362}
2363
2364# API Test function: DELETE /data-consumer/v1/info-type-subscription/{subscriptionId}
2365# args: <response-code> <subscription-id>
2366# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002367ics_api_idc_delete_subscription() {
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002368 __log_test_start $@
2369
2370 if [ $# -ne 2 ]; then
2371 __print_err "<response-code> <subscription-id> " $@
2372 return 1
2373 fi
2374
2375 query="/data-consumer/v1/info-type-subscription/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002376 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002377 status=${res:${#res}-3}
2378
2379 if [ $status -ne $1 ]; then
2380 __log_test_fail_status_code $1 $status
2381 return 1
2382 fi
2383
2384 __log_test_pass
2385 return 0
2386}
2387
2388##########################################
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002389#### Reset jobs ####
2390##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002391# Function prefix: ics_api_admin
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002392
2393# Admin to remove all jobs
BjornMagnussonXA366e36a2021-01-27 11:48:56 +01002394# args: <response-code> [ <type> ]
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002395# (Function for test scripts)
2396
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002397ics_api_admin_reset() {
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002398 __log_test_start $@
2399
2400 if [ -z "$FLAT_A1_EI" ]; then
2401 query="/A1-EI/v1/eitypes/$2/eijobs"
2402 else
2403 query="/A1-EI/v1/eijobs"
2404 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002405 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002406 status=${res:${#res}-3}
2407
2408 if [ $status -ne 200 ]; then
2409 __log_test_fail_status_code $1 $status
2410 return 1
2411 fi
2412
2413 #Remove brackets and response code
2414 body=${res:1:${#res}-4}
2415 list=$(echo ${body//,/ })
2416 list=$(echo ${list//[/})
2417 list=$(echo ${list//]/})
2418 list=$(echo ${list//\"/})
2419 list=$list" "
2420 for job in $list; do
2421 if [ -z "$FLAT_A1_EI" ]; then
2422 echo "Not supported for non-flat EI api"
2423 else
2424 query="/A1-EI/v1/eijobs/$job"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002425 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002426 status=${res:${#res}-3}
2427 if [ $status -ne 204 ]; then
2428 __log_test_fail_status_code $1 $status
2429 return 1
2430 fi
2431 echo " Deleted job: "$job
2432 fi
2433 done
2434
2435 __log_test_pass
2436 return 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002437}
2438
2439##########################################
2440#### Reset jobs and producers ####
2441##########################################
2442
2443
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002444# Admin reset to remove all data in ics; jobs, producers etc
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002445# NOTE - only works in kubernetes and the pod should not be running
2446# args: -
2447# (Function for test scripts)
2448
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002449ics_kube_pvc_reset() {
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002450 __log_test_start $@
2451
BjornMagnussonXAcb6113e2022-02-17 15:01:28 +01002452 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 +02002453 if [ -z "$pvc_name" ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002454 pvc_name=informationservice-pvc
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +02002455 fi
2456 echo " Trying to reset pvc: "$pvc_name
2457
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002458 __kube_clean_pvc $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $ICS_CONTAINER_MNT_DIR
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002459
2460 __log_test_pass
2461 return 0
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002462}