blob: ea4036dad3cc3b2cb6758efbcb5e0bb1b9fcbfe3 [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
BjornMagnussonXA007b6452021-11-29 08:03:38 +010081 kubectl 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
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100106#######################################################
107
108
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100109# Make curl retries towards ICS for http response codes set in this env var, space separated list of codes
110ICS_RETRY_CODES=""
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100111
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200112#Save first worker node the pod is started on
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100113__ICS_WORKER_NODE=""
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200114
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100115###########################
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100116### ICS functions
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100117###########################
118
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100119# All calls to ICS will be directed to the ICS REST interface from now on
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100120# args: -
121# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100122use_ics_rest_http() {
123 __ics_set_protocoll "http" $ICS_INTERNAL_PORT $ICS_EXTERNAL_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100124}
125
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100126# All calls to ICS will be directed to the ICS REST interface from now on
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100127# args: -
128# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100129use_ics_rest_https() {
130 __ics_set_protocoll "https" $ICS_INTERNAL_SECURE_PORT $ICS_EXTERNAL_SECURE_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100131}
132
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100133# All calls to ICS will be directed to the ICS dmaap interface over http from now on
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100134# args: -
135# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100136use_ics_dmaap_http() {
137 echo -e $BOLD"ICS dmaap protocol setting"$EBOLD
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100138 echo -e $RED" - NOT SUPPORTED - "$ERED
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100139 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ICS"
140 ICS_ADAPTER_TYPE="MR-HTTP"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100141 echo ""
142}
143
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100144# Setup paths to svc/container for internal and external access
145# args: <protocol> <internal-port> <external-port>
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100146__ics_set_protocoll() {
147 echo -e $BOLD"$ICS_DISPLAY_NAME protocol setting"$EBOLD
148 echo -e " Using $BOLD $1 $EBOLD towards $ICS_DISPLAY_NAME"
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100149
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100150 ## Access to ICS
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100151
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100152 ICS_SERVICE_PATH=$1"://"$ICS_APP_NAME":"$2 # docker access, container->container and script->container via proxy
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100153 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100154 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 +0100155 fi
156
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100157 # ICS_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
158 ICS_ADAPTER_TYPE="REST"
159 ICS_ADAPTER=$ICS_SERVICE_PATH
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100160
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100161 echo ""
162}
163
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100164# Export env vars for config files, docker compose and kube resources
165# args: PROXY|NOPROXY
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100166__ics_export_vars() {
167 export ICS_APP_NAME
168 export ICS_APP_NAME_ALIAS
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100169 export KUBE_NONRTRIC_NAMESPACE
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100170 export ICS_IMAGE
171 export ICS_INTERNAL_PORT
172 export ICS_INTERNAL_SECURE_PORT
173 export ICS_EXTERNAL_PORT
174 export ICS_EXTERNAL_SECURE_PORT
175 export ICS_CONFIG_MOUNT_PATH
176 export ICS_CONFIG_CONFIGMAP_NAME=$ICS_APP_NAME"-config"
177 export ICS_DATA_CONFIGMAP_NAME=$ICS_APP_NAME"-data"
178 export ICS_CONTAINER_MNT_DIR
179 export ICS_HOST_MNT_DIR
180 export ICS_CONFIG_FILE
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100181 export DOCKER_SIM_NWNAME
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100182 export ICS_DISPLAY_NAME
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100183
184
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100185 export ICS_DATA_PV_NAME=$ICS_APP_NAME"-pv"
186 export ICS_DATA_PVC_NAME=$ICS_APP_NAME"-pvc"
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100187 #Create a unique path for the pv each time to prevent a previous volume to be reused
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100188 export ICS_PV_PATH="icsdata-"$(date +%s)
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100189
190 if [ $1 == "PROXY" ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100191 export ICS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
192 export ICS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
193 if [ $ICS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ICS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100194 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
195 else
196 echo " Configured with http proxy"
197 fi
198 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100199 export ICS_HTTP_PROXY_CONFIG_PORT=0
200 export ICS_HTTP_PROXY_CONFIG_HOST_NAME=""
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100201 echo " Configured without http proxy"
202 fi
203}
204
205
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100206# Start the ICS
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100207# args: PROXY|NOPROXY <config-file>
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100208# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100209start_ics() {
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100210
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100211 echo -e $BOLD"Starting $ICS_DISPLAY_NAME"$EBOLD
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100212
213 if [ $RUNMODE == "KUBE" ]; then
214
215 # Check if app shall be fully managed by the test script
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100216 __check_included_image "ICS"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100217 retcode_i=$?
218
219 # Check if app shall only be used by the testscipt
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100220 __check_prestarted_image "ICS"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100221 retcode_p=$?
222
223 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100224 echo -e $RED"The $ICS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
225 echo -e $RED"The $ICS_APP_NAME will not be started"$ERED
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100226 exit
227 fi
228 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100229 echo -e $RED"The $ICS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
230 echo -e $RED"The $ICS_APP_NAME will not be started"$ERED
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100231 exit
232 fi
233
234
235 if [ $retcode_p -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100236 echo -e " Using existing $ICS_APP_NAME deployment and service"
237 echo " Setting ICS replicas=1"
238 res_type=$(__kube_get_resource_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
239 __kube_scale $res_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100240 fi
241
242 # Check if app shall be fully managed by the test script
243 if [ $retcode_i -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100244 echo -e " Creating $ICS_APP_NAME app and expose service"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100245
246 #Check if nonrtric namespace exists, if not create it
247 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
248
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100249 __ics_export_vars $1
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100250
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100251 # Create config map for config
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100252 datafile=$PWD/tmp/$ICS_CONFIG_FILE
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100253 cp $2 $datafile
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100254 output_yaml=$PWD/tmp/ics_cfc.yaml
255 __kube_create_configmap $ICS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ICS $datafile $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100256
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100257 # Create pv
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100258 input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"pv.yaml
259 output_yaml=$PWD/tmp/ics_pv.yaml
260 __kube_create_instance pv $ICS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100261
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100262 # Create pvc
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100263 input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"pvc.yaml
264 output_yaml=$PWD/tmp/ics_pvc.yaml
265 __kube_create_instance pvc $ICS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100266
267 # Create service
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100268 input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"svc.yaml
269 output_yaml=$PWD/tmp/ics_svc.yaml
270 __kube_create_instance service $ICS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100271
272 # Create app
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100273 input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"app.yaml
274 output_yaml=$PWD/tmp/ics_app.yaml
275 __kube_create_instance app $ICS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100276 fi
277
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100278 # Tie the ICS to a worker node so that ICS will always be scheduled to the same worker node if the ICS pod is restarted
279 # A PVC of type hostPath is mounted to ICS, for persistent storage, so the ICS must always be on the node which mounted the volume
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200280
281 # Keep the initial worker node in case the pod need to be "restarted" - must be made to the same node due to a volume mounted on the host
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200282 if [ $retcode_i -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100283 __ICS_WORKER_NODE=$(kubectl get pod -l "autotest=ICS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
284 if [ -z "$__ICS_WORKER_NODE" ]; then
285 echo -e $YELLOW" Cannot find worker node for pod for $ICS_APP_NAME, persistency may not work"$EYELLOW
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200286 fi
287 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100288 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 +0200289 fi
290
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100291
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100292 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100293
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100294 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100295 __check_included_image 'ICS'
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100296 if [ $? -eq 1 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100297 echo -e $RED"The ICS app is not included in this test script"$ERED
298 echo -e $RED"ICS will not be started"$ERED
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100299 exit 1
300 fi
301
302 curdir=$PWD
303 cd $SIM_GROUP
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100304 cd ics
305 cd $ICS_HOST_MNT_DIR
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100306 #cd ..
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100307 if [ -d db ]; then
308 if [ "$(ls -A $DIR)" ]; then
309 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
310 rm -rf db/* &> /dev/null
311 if [ $? -ne 0 ]; then
312 echo -e $RED" Cannot remove database files in: $PWD"$ERED
313 exit 1
314 fi
315 fi
316 else
317 echo " No files in mounted dir or dir does not exists"
318 fi
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100319
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100320 cd $curdir
321
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100322 __ics_export_vars $1
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100323
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100324 dest_file=$SIM_GROUP/$ICS_COMPOSE_DIR/$ICS_HOST_MNT_DIR/$ICS_CONFIG_FILE
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100325
326 envsubst < $2 > $dest_file
327
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100328 __start_container $ICS_COMPOSE_DIR "" NODOCKERARGS 1 $ICS_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100329
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100330 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100331 fi
332 echo ""
333 return 0
334}
335
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100336# Stop the ics
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200337# args: -
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100338# args: -
339# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100340stop_ics() {
341 echo -e $BOLD"Stopping $ICS_DISPLAY_NAME"$EBOLD
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200342
343 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200344
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100345 __check_prestarted_image "ICS"
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200346 if [ $? -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100347 echo -e $YELLOW" Persistency may not work for app $ICS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
348 res_type=$(__kube_get_resource_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
349 __kube_scale $res_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200350 return 0
351 fi
352
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100353 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ICS
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200354 echo " Deleting the replica set - a new will be started when the app is started"
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100355 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=ICS")
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200356 if [ $? -ne 0 ]; then
357 echo -e $RED" Could not delete replica set "$RED
358 ((RES_CONF_FAIL++))
359 return 1
360 fi
361 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100362 docker stop $ICS_APP_NAME &> ./tmp/.dockererr
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200363 if [ $? -ne 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100364 __print_err "Could not stop $ICS_APP_NAME" $@
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200365 cat ./tmp/.dockererr
366 ((RES_CONF_FAIL++))
367 return 1
368 fi
369 fi
370 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
371 echo ""
372 return 0
373}
374
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100375# Start a previously stopped ics
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200376# args: -
377# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100378start_stopped_ics() {
379 echo -e $BOLD"Starting (the previously stopped) $ICS_DISPLAY_NAME"$EBOLD
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200380
381 if [ $RUNMODE == "KUBE" ]; then
382
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100383 __check_prestarted_image "ICS"
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200384 if [ $? -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100385 echo -e $YELLOW" Persistency may not work for app $ICS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
386 res_type=$(__kube_get_resource_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
387 __kube_scale $res_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
388 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200389 return 0
390 fi
391
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200392 # Tie the PMS to the same worker node it was initially started on
393 # A PVC of type hostPath is mounted to PMS, for persistent storage, so the PMS must always be on the node which mounted the volume
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100394 if [ -z "$__ICS_WORKER_NODE" ]; then
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200395 echo -e $RED" No initial worker node found for pod "$RED
396 ((RES_CONF_FAIL++))
397 return 1
398 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100399 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 +0200400 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100401 tmp=$(kubectl 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 +0200402 if [ $? -ne 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100403 echo -e $YELLOW" Cannot set nodeSelector to deployment for $ICS_APP_NAME, persistency may not work"$EYELLOW
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200404 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100405 __kube_scale deployment $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200406 fi
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200407 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100408 docker start $ICS_APP_NAME &> ./tmp/.dockererr
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200409 if [ $? -ne 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100410 __print_err "Could not start (the stopped) $ICS_APP_NAME" $@
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200411 cat ./tmp/.dockererr
412 ((RES_CONF_FAIL++))
413 return 1
414 fi
415 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100416 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100417 if [ $? -ne 0 ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100418 return 1
419 fi
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100420 echo ""
421 return 0
422}
423
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100424# Turn on debug level tracing in ICS
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100425# args: -
426# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100427set_ics_debug() {
428 echo -e $BOLD"Setting ics debug logging"$EBOLD
429 curlString="$ICS_SERVICE_PATH$ICS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100430 result=$(__do_curl "$curlString")
431 if [ $? -ne 0 ]; then
432 __print_err "Could not set debug mode" $@
433 ((RES_CONF_FAIL++))
434 return 1
435 fi
436 echo ""
437 return 0
438}
439
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100440# Turn on trace level tracing in ICS
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100441# args: -
442# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100443set_ics_trace() {
444 echo -e $BOLD"Setting ics trace logging"$EBOLD
445 curlString="$ICS_SERVICE_PATH/actuator/loggers/org.oransc.information -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100446 result=$(__do_curl "$curlString")
447 if [ $? -ne 0 ]; then
448 __print_err "Could not set trace mode" $@
449 ((RES_CONF_FAIL++))
450 return 1
451 fi
452 echo ""
453 return 0
454}
455
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100456# Perform curl retries when making direct call to ICS for the specified http response codes
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100457# Speace separated list of http response codes
458# args: [<response-code>]*
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100459use_ics_retries() {
460 echo -e $BOLD"Do curl retries to the ICS REST inteface for these response codes:$@"$EBOLD
461 ICS_RETRY_CODES=$@
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100462 echo ""
463 return 0
464}
465
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100466# Check the ics logs for WARNINGs and ERRORs
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100467# args: -
468# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100469check_ics_logs() {
470 __check_container_logs "ICS" $ICS_APP_NAME $ICS_LOGPATH WARN ERR
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100471}
472
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200473
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100474# Tests if a variable value in the ICS is equal to a target value and and optional timeout.
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100475# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
476# equal to the target or not.
477# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
478# before setting pass or fail depending on if the variable value becomes equal to the target
479# value or not.
480# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100481ics_equal() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100482 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100483 __var_test ICS "$ICS_SERVICE_PATH/" $1 "=" $2 $3
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100484 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100485 __print_err "Wrong args to ics_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100486 fi
487}
488
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200489
490##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100491######### A1-E information API ##########
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200492##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100493#Function prefix: ics_api_a1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200494
495# API Test function: GET /A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200496# args: <response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100497# args (flat uri structure): <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200498# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100499ics_api_a1_get_job_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100500 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200501
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100502 if [ -z "$FLAT_A1_EI" ]; then
503 # Valid number of parameters 4,5,6 etc
504 if [ $# -lt 3 ]; then
505 __print_err "<response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
506 return 1
507 fi
508 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100509 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100510 # Valid number of parameters 4,5,6 etc
511 if [ $# -lt 3 ]; then
512 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
513 return 1
514 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200515 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100516 search=""
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200517 if [ $3 != "NOWNER" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100518 search="?owner="$3
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200519 fi
520
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100521 if [ -z "$FLAT_A1_EI" ]; then
522 query="/A1-EI/v1/eitypes/$2/eijobs$search"
523 else
524 if [ $2 != "NOTYPE" ]; then
525 if [ -z "$search" ]; then
526 search="?eiTypeId="$2
527 else
528 search=$search"&eiTypeId="$2
529 fi
530 fi
531 query="/A1-EI/v1/eijobs$search"
532 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100533 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200534 status=${res:${#res}-3}
535
536 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100537 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200538 return 1
539 fi
540
541 if [ $# -gt 3 ]; then
542 body=${res:0:${#res}-3}
543 targetJson="["
544
545 for pid in ${@:4} ; do
546 if [ "$targetJson" != "[" ]; then
547 targetJson=$targetJson","
548 fi
549 if [ $pid != "EMPTY" ]; then
550 targetJson=$targetJson"\"$pid\""
551 fi
552 done
553
554 targetJson=$targetJson"]"
555 echo " TARGET JSON: $targetJson" >> $HTTPLOG
556 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
557
558 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100559 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200560 return 1
561 fi
562 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200563
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100564 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200565 return 0
566}
567
568# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200569# args: <response-code> <type-id> [<schema-file>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200570# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100571ics_api_a1_get_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100572 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200573
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200574 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
575 __print_err "<response-code> <type-id> [<schema-file>]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200576 return 1
577 fi
578
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200579 query="/A1-EI/v1/eitypes/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100580 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200581 status=${res:${#res}-3}
582
583 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100584 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200585 return 1
586 fi
587
588 if [ $# -eq 3 ]; then
589 body=${res:0:${#res}-3}
590 if [ -f $3 ]; then
591 schema=$(cat $3)
592 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100593 __log_test_fail_general "Schema file "$3", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200594 return 1
595 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100596 if [ -z "$FLAT_A1_EI" ]; then
597 targetJson="{\"eiJobParametersSchema\":$schema}"
598 else
599 targetJson=$schema
600 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200601 echo " TARGET JSON: $targetJson" >> $HTTPLOG
602 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
603
604 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100605 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200606 return 1
607 fi
608 fi
609
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100610 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200611 return 0
612}
613
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200614# API Test function: GET /A1-EI/v1/eitypes
615# args: <response-code> [ (EMPTY | [<type-id>]+) ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200616# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100617ics_api_a1_get_type_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100618 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200619
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200620 if [ $# -lt 1 ]; then
621 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200622 return 1
623 fi
624
625 query="/A1-EI/v1/eitypes"
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100626 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200627 status=${res:${#res}-3}
628
629 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100630 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200631 return 1
632 fi
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200633 if [ $# -gt 1 ]; then
634 body=${res:0:${#res}-3}
635 targetJson="["
636 if [ $2 != "EMPTY" ]; then
637 for pid in ${@:2} ; do
638 if [ "$targetJson" != "[" ]; then
639 targetJson=$targetJson","
640 fi
641 targetJson=$targetJson"\"$pid\""
642 done
643 fi
644 targetJson=$targetJson"]"
645 echo " TARGET JSON: $targetJson" >> $HTTPLOG
646 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200647
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200648 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100649 __log_test_fail_body
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200650 return 1
651 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200652 fi
653
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100654 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200655 return 0
656}
657
658# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200659# args: <response-code> <type-id> <job-id> [<status>]
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100660# args (flat uri structure): <response-code> <job-id> [<status> [<timeout>]]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200661# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100662ics_api_a1_get_job_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100663 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200664
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100665 if [ -z "$FLAT_A1_EI" ]; then
666 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
667 __print_err "<response-code> <type-id> <job-id> [<status>]" $@
668 return 1
669 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200670
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100671 query="/A1-EI/v1/eitypes/$2/eijobs/$3/status"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200672
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100673 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100674 status=${res:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200675
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100676 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100677 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200678 return 1
679 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100680 if [ $# -eq 4 ]; then
681 body=${res:0:${#res}-3}
682 targetJson="{\"operationalState\": \"$4\"}"
683 echo " TARGET JSON: $targetJson" >> $HTTPLOG
684 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
685
686 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100687 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100688 return 1
689 fi
690 fi
691 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100692 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100693 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
694 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100695 return 1
696 fi
697
698 query="/A1-EI/v1/eijobs/$2/status"
699
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100700 start=$SECONDS
701 for (( ; ; )); do
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100702 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100703 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100704
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100705 if [ $# -eq 4 ]; then
706 duration=$((SECONDS-start))
707 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
708 if [ $duration -gt $4 ]; then
709 echo ""
710 duration=-1 #Last iteration
711 fi
712 else
713 duration=-1 #single test, no wait
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100714 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100715
716 if [ $status -ne $1 ]; then
717 if [ $duration -eq -1 ]; then
718 __log_test_fail_status_code $1 $status
719 return 1
720 fi
721 fi
722 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
723 body=${res:0:${#res}-3}
724 targetJson="{\"eiJobStatus\": \"$3\"}"
725 echo " TARGET JSON: $targetJson" >> $HTTPLOG
726 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
727
728 if [ $res -ne 0 ]; then
729 if [ $duration -eq -1 ]; then
730 __log_test_fail_body
731 return 1
732 fi
733 else
734 duration=-1 #Goto pass
735 fi
736 fi
737 if [ $duration -eq -1 ]; then
738 if [ $# -eq 4 ]; then
739 echo ""
740 fi
741 __log_test_pass
742 return 0
743 else
744 sleep 1
745 fi
746 done
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200747 fi
748
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100749 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200750 return 0
751}
752
753# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200754# args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100755# args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200756# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100757ics_api_a1_get_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100758 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200759
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100760 if [ -z "$FLAT_A1_EI" ]; then
761 if [ $# -ne 3 ] && [ $# -ne 6 ]; then
762 __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@
763 return 1
764 fi
765 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
766 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100767 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100768 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
769 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
770 return 1
771 fi
772 query="/A1-EI/v1/eijobs/$2"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200773 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100774 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200775 status=${res:${#res}-3}
776
777 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100778 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200779 return 1
780 fi
781
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100782 if [ -z "$FLAT_A1_EI" ]; then
783 if [ $# -eq 6 ]; then
784 body=${res:0:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200785
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100786 if [ -f $6 ]; then
787 jobfile=$(cat $6)
788 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
789 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200790 __log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100791 return 1
792 fi
793 targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
794 echo " TARGET JSON: $targetJson" >> $HTTPLOG
795 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
796
797 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100798 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100799 return 1
800 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200801 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100802 else
803 if [ $# -eq 7 ]; then
804 body=${res:0:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200805
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100806 if [ -f $7 ]; then
807 jobfile=$(cat $7)
808 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
809 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200810 __log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100811 return 1
812 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100813 targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100814 echo " TARGET JSON: $targetJson" >> $HTTPLOG
815 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
816
817 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100818 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100819 return 1
820 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200821 fi
822 fi
823
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100824 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200825 return 0
826}
827
828# API Test function: DELETE ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200829# args: <response-code> <type-id> <job-id>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100830# args (flat uri structure): <response-code> <job-id>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200831# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100832ics_api_a1_delete_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100833 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200834
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100835 if [ -z "$FLAT_A1_EI" ]; then
836 if [ $# -ne 3 ]; then
837 __print_err "<response-code> <type-id> <job-id>" $@
838 return 1
839 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200840
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100841 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
842 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100843 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100844 if [ $# -ne 2 ]; then
845 __print_err "<response-code> <job-id>" $@
846 return 1
847 fi
848 query="/A1-EI/v1/eijobs/$2"
849 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100850 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200851 status=${res:${#res}-3}
852
853 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100854 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200855 return 1
856 fi
857
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100858 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200859 return 0
860}
861
862# API Test function: PUT ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200863# args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100864# 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 +0200865# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100866ics_api_a1_put_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100867 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200868
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100869 if [ -z "$FLAT_A1_EI" ]; then
870 if [ $# -lt 6 ]; then
871 __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@
872 return 1
873 fi
874 if [ -f $6 ]; then
875 jobfile=$(cat $6)
876 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
877 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200878 __log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100879 return 1
880 fi
881
882 inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
883 file="./tmp/.p.json"
884 echo "$inputJson" > $file
885
886 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200887 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100888 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100889 if [ $# -lt 7 ]; then
890 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@
891 return 1
892 fi
893 if [ -f $7 ]; then
894 jobfile=$(cat $7)
895 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
896 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200897 __log_test_fail_general "Job template file "$7", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100898 return 1
899 fi
900
901 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
902 file="./tmp/.p.json"
903 echo "$inputJson" > $file
904
905 query="/A1-EI/v1/eijobs/$2"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200906 fi
907
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100908 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200909 status=${res:${#res}-3}
910
911 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100912 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200913 return 1
914 fi
915
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100916 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200917 return 0
918}
919
920
921##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100922#### information Data Producer API ####
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200923##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100924# Function prefix: ics_api_edp
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200925
926# API Test function: GET /ei-producer/v1/eitypes
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200927# API Test function: GET /data-producer/v1/info-types
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200928# args: <response-code> [ EMPTY | <type-id>+]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200929# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100930ics_api_edp_get_type_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100931 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200932
933 if [ $# -lt 1 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200934 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200935 return 1
936 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100937 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200938 query="/data-producer/v1/info-types"
939 else
940 query="/ei-producer/v1/eitypes"
941 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100942 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200943 status=${res:${#res}-3}
944
945 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100946 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200947 return 1
948 fi
949
950 if [ $# -gt 1 ]; then
951 body=${res:0:${#res}-3}
952 targetJson="["
953 if [ $2 != "EMPTY" ]; then
954 for pid in ${@:2} ; do
955 if [ "$targetJson" != "[" ]; then
956 targetJson=$targetJson","
957 fi
958 targetJson=$targetJson"\"$pid\""
959 done
960 fi
961 targetJson=$targetJson"]"
962 echo " TARGET JSON: $targetJson" >> $HTTPLOG
963 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
964
965 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100966 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200967 return 1
968 fi
969 fi
970
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100971 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200972 return 0
973}
974
975# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200976# API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100977# args: <response-code> <producer-id> [<status> [<timeout>]]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200978# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100979ics_api_edp_get_producer_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100980 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200981
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100982 if [ $# -lt 2 ] || [ $# -gt 4 ]; then
983 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200984 return 1
985 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100986 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200987 query="/data-producer/v1/info-producers/$2/status"
988 else
989 query="/ei-producer/v1/eiproducers/$2/status"
990 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100991 start=$SECONDS
992 for (( ; ; )); do
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100993 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100994 status=${res:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200995
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100996 if [ $# -eq 4 ]; then
997 duration=$((SECONDS-start))
998 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
999 if [ $duration -gt $4 ]; then
1000 echo ""
1001 duration=-1 #Last iteration
1002 fi
1003 else
1004 duration=-1 #single test, no wait
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001005 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001006
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001007 if [ $status -ne $1 ]; then
1008 if [ $duration -eq -1 ]; then
1009 __log_test_fail_status_code $1 $status
1010 return 1
1011 fi
1012 fi
1013 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
1014 body=${res:0:${#res}-3}
1015 targetJson="{\"operational_state\": \"$3\"}"
1016 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1017 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1018
1019 if [ $res -ne 0 ]; then
1020 if [ $duration -eq -1 ]; then
1021 __log_test_fail_body
1022 return 1
1023 fi
1024 else
1025 duration=-1 #Goto pass
1026 fi
1027 fi
1028 if [ $duration -eq -1 ]; then
1029 if [ $# -eq 4 ]; then
1030 echo ""
1031 fi
1032 __log_test_pass
1033 return 0
1034 else
1035 sleep 1
1036 fi
1037 done
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001038}
1039
1040
1041# API Test function: GET /ei-producer/v1/eiproducers
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001042# args (v1_1): <response-code> [ EMPTY | <producer-id>+]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001043# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001044ics_api_edp_get_producer_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001045 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001046
1047 if [ $# -lt 1 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001048 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001049 return 1
1050 fi
1051
1052 query="/ei-producer/v1/eiproducers"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001053 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001054 status=${res:${#res}-3}
1055
1056 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001057 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001058 return 1
1059 fi
1060
1061 if [ $# -gt 1 ]; then
1062 body=${res:0:${#res}-3}
1063 targetJson="["
1064
1065 for pid in ${@:2} ; do
1066 if [ "$targetJson" != "[" ]; then
1067 targetJson=$targetJson","
1068 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001069 if [ $pid != "EMPTY" ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001070 targetJson=$targetJson"\"$pid\""
1071 fi
1072 done
1073
1074 targetJson=$targetJson"]"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001075 echo " TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001076 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1077
1078 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001079 __log_test_fail_body
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001080 return 1
1081 fi
1082 fi
1083
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001084 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001085 return 0
1086}
1087
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001088# API Test function: GET /ei-producer/v1/eiproducers
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001089# API Test function: GET /data-producer/v1/info-producers
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001090# args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]
1091# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001092ics_api_edp_get_producer_ids_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001093 __log_test_start $@
1094
1095 if [ $# -lt 1 ]; then
1096 __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
1097 return 1
1098 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001099 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001100 query="/data-producer/v1/info-producers"
1101 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1102 query=$query"?info_type_id=$2"
1103 fi
1104 else
1105 query="/ei-producer/v1/eiproducers"
1106 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1107 query=$query"?ei_type_id=$2"
1108 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001109 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001110 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001111 status=${res:${#res}-3}
1112
1113 if [ $status -ne $1 ]; then
1114 __log_test_fail_status_code $1 $status
1115 return 1
1116 fi
1117
1118 if [ $# -gt 2 ]; then
1119 body=${res:0:${#res}-3}
1120 targetJson="["
1121
1122 for pid in ${@:3} ; do
1123 if [ "$targetJson" != "[" ]; then
1124 targetJson=$targetJson","
1125 fi
1126 if [ $pid != "EMPTY" ]; then
1127 targetJson=$targetJson"\"$pid\""
1128 fi
1129 done
1130
1131 targetJson=$targetJson"]"
1132 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1133 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1134
1135 if [ $res -ne 0 ]; then
1136 __log_test_fail_body
1137 return 1
1138 fi
1139 fi
1140
1141 __log_test_pass
1142 return 0
1143}
1144
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001145# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001146# args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001147# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001148ics_api_edp_get_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001149 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001150
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001151 paramError=1
1152 if [ $# -eq 2 ]; then
1153 paramError=0
1154 fi
1155 if [ $# -gt 3 ]; then
1156 paramError=0
1157 fi
1158 if [ $paramError -ne 0 ]; then
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +02001159 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001160 return 1
1161 fi
1162
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001163 query="/ei-producer/v1/eitypes/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001164 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001165 status=${res:${#res}-3}
1166
1167 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001168 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001169 return 1
1170 fi
1171 if [ $# -gt 3 ]; then
1172 body=${res:0:${#res}-3}
1173
1174 if [ -f $3 ]; then
1175 schema=$(cat $3)
1176 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001177 __log_test_fail_general "Job template file "$3", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001178 return 1
1179 fi
1180
1181 targetJson=""
1182 if [ $4 != "EMPTY" ]; then
1183 for pid in ${@:4} ; do
1184 if [ "$targetJson" != "" ]; then
1185 targetJson=$targetJson","
1186 fi
1187 targetJson=$targetJson"\"$pid\""
1188 done
1189 fi
1190 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
1191
1192 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1193 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1194
1195 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001196 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001197 return 1
1198 fi
1199 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001200 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001201 return 0
1202}
1203
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001204# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001205# API Test function: GET /data-producer/v1/info-types/{infoTypeId}
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001206# args: (v1_2) <response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001207# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001208ics_api_edp_get_type_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001209 __log_test_start $@
1210
1211 paramError=1
1212 if [ $# -eq 2 ]; then
1213 paramError=0
1214 fi
1215 if [ $# -eq 3 ]; then
1216 paramError=0
1217 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001218 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001219 if [ $# -eq 4 ]; then
1220 paramError=0
1221 fi
1222 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001223 if [ $paramError -ne 0 ]; then
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001224 __print_err "<response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]" $@
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001225 return 1
1226 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001227 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001228 query="/data-producer/v1/info-types/$2"
1229 else
1230 query="/ei-producer/v1/eitypes/$2"
1231 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001232
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001233 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001234 status=${res:${#res}-3}
1235
1236 if [ $status -ne $1 ]; then
1237 __log_test_fail_status_code $1 $status
1238 return 1
1239 fi
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001240 if [ $# -ge 3 ]; then
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001241 body=${res:0:${#res}-3}
1242
1243 if [ -f $3 ]; then
1244 schema=$(cat $3)
1245 else
1246 __log_test_fail_general "Job template file "$3", does not exist"
1247 return 1
1248 fi
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001249 info_data=""
1250 if [ $# -gt 3 ]; then
1251 if [ -f $4 ]; then
1252 info_data=$(cat $4)
1253 else
1254 __log_test_fail_general "Info-data file "$4", does not exist"
1255 return 1
1256 fi
1257 info_data=",\"info_type_information\":$info_data"
1258 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001259 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001260 targetJson="{\"info_job_data_schema\":$schema $info_data}"
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001261 else
1262 targetJson="{\"ei_job_data_schema\":$schema}"
1263 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001264
1265 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1266 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1267
1268 if [ $res -ne 0 ]; then
1269 __log_test_fail_body
1270 return 1
1271 fi
1272 fi
1273 __log_test_pass
1274 return 0
1275}
1276
1277# API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001278# API Test function: PUT /data-producer/v1/info-types/{infoTypeId}
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001279# args: (v1_2) <response-code> <type-id> <job-schema-file> [ <info-type-info> ]
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001280# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001281ics_api_edp_put_type_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001282 __log_test_start $@
1283
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001284 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001285 if [ $# -lt 3 ] || [ $# -gt 4 ]; then
1286 __print_err "<response-code> <type-id> <job-schema-file> [ <info-type-info> ]" $@
1287 return 1
1288 fi
1289 else
1290 if [ $# -ne 3 ]; then
1291 __print_err "<response-code> <type-id> <job-schema-file>" $@
1292 return 1
1293 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001294 fi
1295
1296 if [ ! -f $3 ]; then
1297 __log_test_fail_general "Job schema file "$3", does not exist"
1298 return 1
1299 fi
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001300
1301 info_data=""
1302 if [ $# -gt 3 ]; then
1303 if [ -f $4 ]; then
1304 info_data=$(cat $4)
1305 else
1306 __log_test_fail_general "Info-data file "$4", does not exist"
1307 return 1
1308 fi
1309 info_data=",\"info_type_information\":$info_data"
1310 fi
1311
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001312 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001313 schema=$(cat $3)
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001314 input_json="{\"info_job_data_schema\":$schema $info_data}"
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001315 file="./tmp/put_type.json"
1316 echo $input_json > $file
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001317
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001318 query="/data-producer/v1/info-types/$2"
1319 else
1320 schema=$(cat $3)
1321 input_json="{\"ei_job_data_schema\":$schema}"
1322 file="./tmp/put_type.json"
1323 echo $input_json > $file
1324
1325 query="/ei-producer/v1/eitypes/$2"
1326 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001327 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001328 status=${res:${#res}-3}
1329
1330 if [ $status -ne $1 ]; then
1331 __log_test_fail_status_code $1 $status
1332 return 1
1333 fi
1334
1335 __log_test_pass
1336 return 0
1337}
1338
1339# API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001340# API Test function: DELETE /data-producer/v1/info-types/{infoTypeId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001341# args: (v1_2) <response-code> <type-id>
1342# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001343ics_api_edp_delete_type_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001344 __log_test_start $@
1345
1346 if [ $# -ne 2 ]; then
1347 __print_err "<response-code> <type-id>" $@
1348 return 1
1349 fi
1350
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001351 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001352 query="/data-producer/v1/info-types/$2"
1353 else
1354 query="/ei-producer/v1/eitypes/$2"
1355 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001356 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001357 status=${res:${#res}-3}
1358
1359 if [ $status -ne $1 ]; then
1360 __log_test_fail_status_code $1 $status
1361 return 1
1362 fi
1363
1364 __log_test_pass
1365 return 0
1366}
1367
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001368# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001369# args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001370# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001371ics_api_edp_get_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001372 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001373
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001374 #Possible arg count: 2, 5 6, 8, 10 etc
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001375 paramError=1
1376 if [ $# -eq 2 ]; then
1377 paramError=0
1378 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001379 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001380 paramError=0
1381 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001382 variablecount=$(($#-4))
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001383 if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
1384 paramError=0
1385 fi
1386
1387 if [ $paramError -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001388 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001389 return 1
1390 fi
1391
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001392 query="/ei-producer/v1/eiproducers/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001393 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001394 status=${res:${#res}-3}
1395
1396 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001397 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001398 return 1
1399 fi
1400
1401 if [ $# -gt 2 ]; then
1402 body=${res:0:${#res}-3}
1403 targetJson="["
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001404 if [ $# -gt 5 ]; then
1405 arr=(${@:5})
1406 for ((i=0; i<$(($#-5)); i=i+2)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001407 if [ "$targetJson" != "[" ]; then
1408 targetJson=$targetJson","
1409 fi
1410 if [ -f ${arr[$i+1]} ]; then
1411 schema=$(cat ${arr[$i+1]})
1412 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001413 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001414 return 1
1415 fi
1416
1417 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1418 done
1419 fi
1420 targetJson=$targetJson"]"
1421 if [ $# -gt 4 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001422 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001423 fi
1424 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1425 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1426
1427 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001428 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001429 return 1
1430 fi
1431 fi
1432
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001433 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001434 return 0
1435}
1436
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001437# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001438# API Test function: GET /data-producer/v1/info-producers/{infoProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001439# args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]
1440# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001441ics_api_edp_get_producer_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001442 __log_test_start $@
1443
1444 #Possible arg count: 2, 5, 6, 7, 8 etc
1445 paramError=1
1446 if [ $# -eq 2 ]; then
1447 paramError=0
1448 fi
1449 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1450 paramError=0
1451 fi
1452 if [ $# -ge 5 ]; then
1453 paramError=0
1454 fi
1455
1456 if [ $paramError -ne 0 ]; then
1457 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
1458 return 1
1459 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001460 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001461 query="/data-producer/v1/info-producers/$2"
1462 else
1463 query="/ei-producer/v1/eiproducers/$2"
1464 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001465 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001466 status=${res:${#res}-3}
1467
1468 if [ $status -ne $1 ]; then
1469 __log_test_fail_status_code $1 $status
1470 return 1
1471 fi
1472
1473 if [ $# -gt 2 ]; then
1474 body=${res:0:${#res}-3}
1475 targetJson="["
1476 if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
1477 arr=(${@:5})
1478 for ((i=0; i<$(($#-4)); i=i+1)); do
1479 if [ "$targetJson" != "[" ]; then
1480 targetJson=$targetJson","
1481 fi
1482 targetJson=$targetJson"\"${arr[$i]}\""
1483 done
1484 fi
1485 targetJson=$targetJson"]"
1486 if [ $# -gt 4 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001487 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001488 targetJson="{\"supported_info_types\":$targetJson,\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\"}"
1489 else
1490 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1491 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001492 fi
1493 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1494 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1495
1496 if [ $res -ne 0 ]; then
1497 __log_test_fail_body
1498 return 1
1499 fi
1500 fi
1501
1502 __log_test_pass
1503 return 0
1504}
1505
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001506# API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001507# API Test function: DELETE /data-producer/v1/info-producers/{infoProducerId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001508# args: <response-code> <producer-id>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001509# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001510ics_api_edp_delete_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001511 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001512
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001513 if [ $# -lt 2 ]; then
1514 __print_err "<response-code> <producer-id>" $@
1515 return 1
1516 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001517 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001518 query="/data-producer/v1/info-producers/$2"
1519 else
1520 query="/ei-producer/v1/eiproducers/$2"
1521 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001522 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001523 status=${res:${#res}-3}
1524
1525 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001526 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001527 return 1
1528 fi
1529
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001530 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001531 return 0
1532}
1533
1534# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001535# args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001536# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001537ics_api_edp_put_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001538 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001539
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001540 #Valid number of parametrer 5,6,8,10,
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001541 paramError=1
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001542 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001543 paramError=0
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001544 elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001545 paramError=0
1546 fi
1547 if [ $paramError -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001548 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001549 return 1
1550 fi
1551
1552 inputJson="["
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001553 if [ $# -gt 5 ]; then
1554 arr=(${@:5})
1555 for ((i=0; i<$(($#-5)); i=i+2)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001556 if [ "$inputJson" != "[" ]; then
1557 inputJson=$inputJson","
1558 fi
1559 if [ -f ${arr[$i+1]} ]; then
1560 schema=$(cat ${arr[$i+1]})
1561 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001562 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001563 return 1
1564 fi
1565 inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1566 done
1567 fi
1568 inputJson="\"supported_ei_types\":"$inputJson"]"
1569
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001570 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001571
1572 inputJson="{"$inputJson"}"
1573
1574 file="./tmp/.p.json"
1575 echo "$inputJson" > $file
1576 query="/ei-producer/v1/eiproducers/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001577 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001578 status=${res:${#res}-3}
1579
1580 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001581 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001582 return 1
1583 fi
1584
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001585 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001586 return 0
1587}
1588
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001589# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001590# API Test function: PUT /data-producer/v1/info-producers/{infoProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001591# args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]
1592# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001593ics_api_edp_put_producer_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001594 __log_test_start $@
1595
1596 #Valid number of parametrer 5,6,8,10,
1597 paramError=1
1598 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1599 paramError=0
1600 elif [ $# -ge 5 ]; then
1601 paramError=0
1602 fi
1603 if [ $paramError -ne 0 ]; then
1604 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
1605 return 1
1606 fi
1607
1608 inputJson="["
1609 if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
1610 arr=(${@:5})
1611 for ((i=0; i<$(($#-4)); i=i+1)); do
1612 if [ "$inputJson" != "[" ]; then
1613 inputJson=$inputJson","
1614 fi
1615 inputJson=$inputJson"\""${arr[$i]}"\""
1616 done
1617 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001618 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001619 inputJson="\"supported_info_types\":"$inputJson"]"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001620
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001621 inputJson=$inputJson",\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\""
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001622
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001623 inputJson="{"$inputJson"}"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001624
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001625 file="./tmp/.p.json"
1626 echo "$inputJson" > $file
1627 query="/data-producer/v1/info-producers/$2"
1628 else
1629 inputJson="\"supported_ei_types\":"$inputJson"]"
1630
1631 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1632
1633 inputJson="{"$inputJson"}"
1634
1635 file="./tmp/.p.json"
1636 echo "$inputJson" > $file
1637 query="/ei-producer/v1/eiproducers/$2"
1638 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001639 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001640 status=${res:${#res}-3}
1641
1642 if [ $status -ne $1 ]; then
1643 __log_test_fail_status_code $1 $status
1644 return 1
1645 fi
1646
1647 __log_test_pass
1648 return 0
1649}
1650
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001651# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001652# 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 +02001653# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001654ics_api_edp_get_producer_jobs() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001655 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001656
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001657 #Valid number of parameter 2,3,7,11
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001658 paramError=1
1659 if [ $# -eq 2 ]; then
1660 paramError=0
1661 fi
1662 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1663 paramError=0
1664 fi
1665 variablecount=$(($#-2))
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001666 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001667 paramError=0
1668 fi
1669 if [ $paramError -eq 1 ]; then
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001670 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001671 return 1
1672 fi
1673
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001674 query="/ei-producer/v1/eiproducers/$2/eijobs"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001675 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001676 status=${res:${#res}-3}
1677 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001678 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001679 return 1
1680 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001681 if [ $# -gt 2 ]; then
1682 body=${res:0:${#res}-3}
1683 targetJson="["
1684 if [ $# -gt 3 ]; then
1685 arr=(${@:3})
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001686 for ((i=0; i<$(($#-3)); i=i+5)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001687 if [ "$targetJson" != "[" ]; then
1688 targetJson=$targetJson","
1689 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001690 if [ -f ${arr[$i+4]} ]; then
1691 jobfile=$(cat ${arr[$i+4]})
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001692 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1693 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001694 __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001695 return 1
1696 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001697 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 +02001698 done
1699 fi
1700 targetJson=$targetJson"]"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001701
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001702 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1703 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001704
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001705 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001706 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001707 return 1
1708 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001709 fi
1710
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001711 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001712 return 0
1713}
1714
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001715# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001716# API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/info-jobs
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001717# args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1718# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001719ics_api_edp_get_producer_jobs_2() {
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001720 __log_test_start $@
1721
1722 #Valid number of parameter 2,3,7,11
1723 paramError=1
1724 if [ $# -eq 2 ]; then
1725 paramError=0
1726 fi
1727 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1728 paramError=0
1729 fi
1730 variablecount=$(($#-2))
1731 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1732 paramError=0
1733 fi
1734 if [ $paramError -eq 1 ]; then
1735 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1736 return 1
1737 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001738 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001739 query="/data-producer/v1/info-producers/$2/info-jobs"
1740 else
1741 query="/ei-producer/v1/eiproducers/$2/eijobs"
1742 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001743 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001744 status=${res:${#res}-3}
1745 if [ $status -ne $1 ]; then
1746 __log_test_fail_status_code $1 $status
1747 return 1
1748 fi
1749 if [ $# -gt 2 ]; then
1750 body=${res:0:${#res}-3}
1751 targetJson="["
1752 if [ $# -gt 3 ]; then
1753 arr=(${@:3})
1754 for ((i=0; i<$(($#-3)); i=i+5)); do
1755 if [ "$targetJson" != "[" ]; then
1756 targetJson=$targetJson","
1757 fi
1758 if [ -f ${arr[$i+4]} ]; then
1759 jobfile=$(cat ${arr[$i+4]})
1760 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1761 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001762 __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001763 return 1
1764 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001765 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001766 targetJson=$targetJson"{\"info_job_identity\":\"${arr[$i]}\",\"info_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"info_job_data\":$jobfile, \"last_updated\":\"????\"}"
1767 else
1768 targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"ei_job_data\":$jobfile, \"last_updated\":\"????\"}"
1769 fi
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001770 done
1771 fi
1772 targetJson=$targetJson"]"
1773
1774 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1775 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1776
1777 if [ $res -ne 0 ]; then
1778 __log_test_fail_body
1779 return 1
1780 fi
1781 fi
1782
1783 __log_test_pass
1784 return 0
1785}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001786
1787##########################################
1788#### Service status ####
1789##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001790# Function prefix: ics_api_service
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001791
1792# API Test function: GET ​/status
1793# args: <response-code>
1794# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001795ics_api_service_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001796 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001797
1798 if [ $# -lt 1 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001799 __print_err "<response-code>" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001800 return 1
1801 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001802 res="$(__do_curl_to_api ICS GET /status)"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001803 status=${res:${#res}-3}
1804 if [ $status -ne $1 ]; then
1805 __log_test_fail_status_code $1 $status
1806 return 1
1807 fi
1808 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001809 return 0
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001810}
1811
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001812###########################################
1813######### Info data consumer API ##########
1814###########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001815#Function prefix: ics_api_idc
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001816
1817
1818# API Test function: GET /data-consumer/v1/info-types
1819# args: <response-code> [ (EMPTY | [<type-id>]+) ]
1820# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001821ics_api_idc_get_type_ids() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001822 __log_test_start $@
1823
1824 if [ $# -lt 1 ]; then
1825 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
1826 return 1
1827 fi
1828
1829 query="/data-consumer/v1/info-types"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001830 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001831 status=${res:${#res}-3}
1832
1833 if [ $status -ne $1 ]; then
1834 __log_test_fail_status_code $1 $status
1835 return 1
1836 fi
1837 if [ $# -gt 1 ]; then
1838 body=${res:0:${#res}-3}
1839 targetJson="["
1840 if [ $2 != "EMPTY" ]; then
1841 for pid in ${@:2} ; do
1842 if [ "$targetJson" != "[" ]; then
1843 targetJson=$targetJson","
1844 fi
1845 targetJson=$targetJson"\"$pid\""
1846 done
1847 fi
1848 targetJson=$targetJson"]"
1849 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1850 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1851
1852 if [ $res -ne 0 ]; then
1853 __log_test_fail_body
1854 return 1
1855 fi
1856 fi
1857
1858 __log_test_pass
1859 return 0
1860}
1861
1862# API Test function: GET /data-consumer/v1/info-jobs
1863# args: <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
1864# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001865ics_api_idc_get_job_ids() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001866 __log_test_start $@
1867
1868 # Valid number of parameters 4,5,6 etc
1869 if [ $# -lt 3 ]; then
1870 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
1871 return 1
1872 fi
1873 search=""
1874 if [ $3 != "NOWNER" ]; then
1875 search="?owner="$3
1876 fi
1877
1878 if [ $2 != "NOTYPE" ]; then
1879 if [ -z "$search" ]; then
1880 search="?infoTypeId="$2
1881 else
1882 search=$search"&infoTypeId="$2
1883 fi
1884 fi
1885 query="/data-consumer/v1/info-jobs$search"
1886
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001887 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001888 status=${res:${#res}-3}
1889
1890 if [ $status -ne $1 ]; then
1891 __log_test_fail_status_code $1 $status
1892 return 1
1893 fi
1894
1895 if [ $# -gt 3 ]; then
1896 body=${res:0:${#res}-3}
1897 targetJson="["
1898
1899 for pid in ${@:4} ; do
1900 if [ "$targetJson" != "[" ]; then
1901 targetJson=$targetJson","
1902 fi
1903 if [ $pid != "EMPTY" ]; then
1904 targetJson=$targetJson"\"$pid\""
1905 fi
1906 done
1907
1908 targetJson=$targetJson"]"
1909 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1910 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1911
1912 if [ $res -ne 0 ]; then
1913 __log_test_fail_body
1914 return 1
1915 fi
1916 fi
1917
1918 __log_test_pass
1919 return 0
1920}
1921
1922# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}
1923# args: <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
1924# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001925ics_api_idc_get_job() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001926 __log_test_start $@
1927
1928 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
1929 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
1930 return 1
1931 fi
1932 query="/data-consumer/v1/info-jobs/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001933 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001934 status=${res:${#res}-3}
1935
1936 if [ $status -ne $1 ]; then
1937 __log_test_fail_status_code $1 $status
1938 return 1
1939 fi
1940
1941 if [ $# -eq 7 ]; then
1942 body=${res:0:${#res}-3}
1943
1944 if [ -f $7 ]; then
1945 jobfile=$(cat $7)
1946 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1947 else
1948 __log_test_fail_general "Job template file "$6", does not exist"
1949 return 1
1950 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001951 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 +02001952 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1953 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1954
1955 if [ $res -ne 0 ]; then
1956 __log_test_fail_body
1957 return 1
1958 fi
1959 fi
1960
1961 __log_test_pass
1962 return 0
1963}
1964
1965
1966# API Test function: PUT ​/data-consumer/v1/info-jobs/{infoJobId}
1967# args: <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]
1968# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001969ics_api_idc_put_job() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001970 __log_test_start $@
1971
1972 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1973 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]" $@
1974 return 1
1975 fi
1976 if [ -f $7 ]; then
1977 jobfile=$(cat $7)
1978 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1979 else
1980 __log_test_fail_general "Job template file "$7", does not exist"
1981 return 1
1982 fi
1983
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001984 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 +02001985 file="./tmp/.p.json"
1986 echo "$inputJson" > $file
1987
1988 query="/data-consumer/v1/info-jobs/$2"
1989
1990 if [ $# -eq 8 ]; then
1991 if [ $8 == "VALIDATE" ]; then
1992 query=$query"?typeCheck=true"
1993 fi
1994 fi
1995
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001996 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001997 status=${res:${#res}-3}
1998
1999 if [ $status -ne $1 ]; then
2000 __log_test_fail_status_code $1 $status
2001 return 1
2002 fi
2003
2004 __log_test_pass
2005 return 0
2006}
2007
2008# API Test function: DELETE ​/data-consumer/v1/info-jobs/{infoJobId}
2009# args: <response-code> <job-id>
2010# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002011ics_api_idc_delete_job() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002012 __log_test_start $@
2013
2014 if [ $# -ne 2 ]; then
2015 __print_err "<response-code> <job-id>" $@
2016 return 1
2017 fi
2018 query="/data-consumer/v1/info-jobs/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002019 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002020 status=${res:${#res}-3}
2021
2022 if [ $status -ne $1 ]; then
2023 __log_test_fail_status_code $1 $status
2024 return 1
2025 fi
2026
2027 __log_test_pass
2028 return 0
2029}
2030
2031# API Test function: GET ​/data-consumer/v1/info-types/{infoTypeId}
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002032# args: <response-code> <type-id> [<schema-file> [<type-status> <producers-count]]
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002033# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002034ics_api_idc_get_type() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002035 __log_test_start $@
2036
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002037 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
2038 __print_err "<response-code> <type-id> [<schema-file> [<type-status> <producers-count]]" $@
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002039 return 1
2040 fi
2041
2042 query="/data-consumer/v1/info-types/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002043 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002044 status=${res:${#res}-3}
2045
2046 if [ $status -ne $1 ]; then
2047 __log_test_fail_status_code $1 $status
2048 return 1
2049 fi
2050
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002051 if [ $# -gt 2 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002052 body=${res:0:${#res}-3}
2053 if [ -f $3 ]; then
2054 schema=$(cat $3)
2055 else
2056 __log_test_fail_general "Schema file "$3", does not exist"
2057 return 1
2058 fi
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002059 if [ $# -eq 5 ]; then
2060 targetJson="{\"job_data_schema\":$schema, \"type_status\":\"$4\", \"no_of_producers\":$5}"
2061 else
2062 targetJson="{\"job_data_schema\":$schema}"
2063 fi
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002064 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2065 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2066
2067 if [ $res -ne 0 ]; then
2068 __log_test_fail_body
2069 return 1
2070 fi
2071 fi
2072
2073 __log_test_pass
2074 return 0
2075}
2076
2077# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002078# This test only status during an optional timeout. No test of the list of producers
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002079# args: <response-code> <job-id> [<status> [<timeout>]]
2080# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002081ics_api_idc_get_job_status() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002082 __log_test_start $@
2083
2084 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
2085 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
2086 return 1
2087 fi
2088
2089 query="/data-consumer/v1/info-jobs/$2/status"
2090
2091 start=$SECONDS
2092 for (( ; ; )); do
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002093 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002094 status=${res:${#res}-3}
2095
2096 if [ $# -eq 4 ]; then
2097 duration=$((SECONDS-start))
2098 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2099 if [ $duration -gt $4 ]; then
2100 echo ""
2101 duration=-1 #Last iteration
2102 fi
2103 else
2104 duration=-1 #single test, no wait
2105 fi
2106
2107 if [ $status -ne $1 ]; then
2108 if [ $duration -eq -1 ]; then
2109 __log_test_fail_status_code $1 $status
2110 return 1
2111 fi
2112 fi
2113 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
2114 body=${res:0:${#res}-3}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02002115 targetJson="{\"info_job_status\": \"$3\"}"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002116 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2117 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2118
2119 if [ $res -ne 0 ]; then
2120 if [ $duration -eq -1 ]; then
2121 __log_test_fail_body
2122 return 1
2123 fi
2124 else
2125 duration=-1 #Goto pass
2126 fi
2127 fi
2128 if [ $duration -eq -1 ]; then
2129 if [ $# -eq 4 ]; then
2130 echo ""
2131 fi
2132 __log_test_pass
2133 return 0
2134 else
2135 sleep 1
2136 fi
2137 done
2138
2139 __log_test_pass
2140 return 0
2141}
2142
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002143# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
2144# This function test status and the list of producers with and optional timeout
2145# args: <response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]
2146# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002147ics_api_idc_get_job_status2() {
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002148
2149 __log_test_start $@
2150 param_error=0
2151 if [ $# -lt 2 ]; then
2152 param_error=1
2153 fi
2154 args=("$@")
2155 timeout=0
2156 if [ $# -gt 2 ]; then
2157 if [ $# -lt 4 ]; then
2158 param_error=1
2159 fi
2160 targetJson="{\"info_job_status\": \"$3\""
2161 if [ "$4" == "EMPTYPROD" ]; then
2162 targetJson=$targetJson",\"producers\": []}"
2163 if [ $# -gt 4 ]; then
2164 timeout=$5
2165 fi
2166 else
2167 targetJson=$targetJson",\"producers\": ["
2168 if [ $# -eq $(($4+5)) ]; then
2169 idx=$(($4+4))
2170 timeout=${args[$idx]}
2171 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002172 for ((ics_i = 0 ; ics_i < $4 ; ics_i++)); do
2173 idx=$(($ics_i+4))
2174 if [ $ics_i -gt 0 ]; then
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002175 targetJson=$targetJson","
2176 fi
2177 targetJson=$targetJson"\""${args[$idx]}"\""
2178 done
2179 targetJson=$targetJson"]}"
2180 fi
2181 fi
2182
2183 if [ $param_error -ne 0 ]; then
2184 __print_err "<response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]" $@
2185 return 1
2186 fi
2187
2188 query="/data-consumer/v1/info-jobs/$2/status"
2189
2190 start=$SECONDS
2191 for (( ; ; )); do
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002192 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002193 status=${res:${#res}-3}
2194
2195 if [ $# -gt 2 ]; then
2196 duration=$((SECONDS-start))
2197 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2198 if [ $duration -gt $timeout ]; then
2199 echo ""
2200 duration=-1 #Last iteration
2201 fi
2202 else
2203 duration=-1 #single test, no wait
2204 fi
2205
2206 if [ $status -ne $1 ]; then
2207 if [ $duration -eq -1 ]; then
2208 __log_test_fail_status_code $1 $status
2209 return 1
2210 fi
2211 fi
2212 if [ $# -gt 2 ] && [ $status -eq $1 ]; then
2213 body=${res:0:${#res}-3}
2214 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2215 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2216
2217 if [ $res -ne 0 ]; then
2218 if [ $duration -eq -1 ]; then
2219 __log_test_fail_body
2220 return 1
2221 fi
2222 else
2223 duration=-1 #Goto pass
2224 fi
2225 fi
2226 if [ $duration -eq -1 ]; then
2227 if [ $# -eq 4 ]; then
2228 echo ""
2229 fi
2230 __log_test_pass
2231 return 0
2232 else
2233 sleep 1
2234 fi
2235 done
2236
2237 __log_test_pass
2238 return 0
2239}
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002240
2241##########################################
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002242#### Type subscriptions ####
2243##########################################
2244
2245# API Test function: GET /data-consumer/v1/info-type-subscription
2246# args: <response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]
2247# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002248ics_api_idc_get_subscription_ids() {
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002249 __log_test_start $@
2250
2251 if [ $# -lt 3 ]; then
2252 __print_err "<response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]" $@
2253 return 1
2254 fi
2255
2256 query="/data-consumer/v1/info-type-subscription"
2257 search=""
2258 if [ $2 != "NOOWNER" ]; then
2259 search="?owner="$2
2260 fi
2261
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002262 res="$(__do_curl_to_api ICS GET $query$search)"
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002263 status=${res:${#res}-3}
2264
2265 if [ $status -ne $1 ]; then
2266 __log_test_fail_status_code $1 $status
2267 return 1
2268 fi
2269
2270 if [ $# -gt 2 ]; then
2271 body=${res:0:${#res}-3}
2272 targetJson="["
2273 if [ $3 != "EMPTY" ]; then
2274 for pid in ${@:3} ; do
2275 if [ "$targetJson" != "[" ]; then
2276 targetJson=$targetJson","
2277 fi
2278 targetJson=$targetJson"\"$pid\""
2279 done
2280 fi
2281 targetJson=$targetJson"]"
2282 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2283 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2284
2285 if [ $res -ne 0 ]; then
2286 __log_test_fail_body
2287 return 1
2288 fi
2289 fi
2290
2291 __log_test_pass
2292 return 0
2293}
2294
2295# API Test function: GET /data-consumer/v1/info-type-subscription/{subscriptionId}
2296# args: <response-code> <subscription-id> [ <owner-id> <status-uri> ]
2297# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002298ics_api_idc_get_subscription() {
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002299 __log_test_start $@
2300
2301 if [ $# -ne 2 ] && [ $# -ne 4 ]; then
2302 __print_err "<response-code> <subscription-id> [ <owner-id> <status-uri> ]" $@
2303 return 1
2304 fi
2305
2306 query="/data-consumer/v1/info-type-subscription/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002307 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002308 status=${res:${#res}-3}
2309
2310 if [ $status -ne $1 ]; then
2311 __log_test_fail_status_code $1 $status
2312 return 1
2313 fi
2314
2315 if [ $# -gt 2 ]; then
2316 body=${res:0:${#res}-3}
2317 targetJson="{\"owner\":\"$3\",\"status_result_uri\":\"$4\"}"
2318 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2319 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2320
2321 if [ $res -ne 0 ]; then
2322 __log_test_fail_body
2323 return 1
2324 fi
2325 fi
2326
2327 __log_test_pass
2328 return 0
2329}
2330
2331# API Test function: PUT /data-consumer/v1/info-type-subscription/{subscriptionId}
2332# args: <response-code> <subscription-id> <owner-id> <status-uri>
2333# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002334ics_api_idc_put_subscription() {
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002335 __log_test_start $@
2336
2337 if [ $# -ne 4 ]; then
2338 __print_err "<response-code> <subscription-id> <owner-id> <status-uri>" $@
2339 return 1
2340 fi
2341
2342 inputJson="{\"owner\": \"$3\",\"status_result_uri\": \"$4\"}"
2343 file="./tmp/.p.json"
2344 echo "$inputJson" > $file
2345
2346 query="/data-consumer/v1/info-type-subscription/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002347 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002348 status=${res:${#res}-3}
2349
2350 if [ $status -ne $1 ]; then
2351 __log_test_fail_status_code $1 $status
2352 return 1
2353 fi
2354
2355 __log_test_pass
2356 return 0
2357}
2358
2359# API Test function: DELETE /data-consumer/v1/info-type-subscription/{subscriptionId}
2360# args: <response-code> <subscription-id>
2361# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002362ics_api_idc_delete_subscription() {
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002363 __log_test_start $@
2364
2365 if [ $# -ne 2 ]; then
2366 __print_err "<response-code> <subscription-id> " $@
2367 return 1
2368 fi
2369
2370 query="/data-consumer/v1/info-type-subscription/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002371 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002372 status=${res:${#res}-3}
2373
2374 if [ $status -ne $1 ]; then
2375 __log_test_fail_status_code $1 $status
2376 return 1
2377 fi
2378
2379 __log_test_pass
2380 return 0
2381}
2382
2383##########################################
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002384#### Reset jobs ####
2385##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002386# Function prefix: ics_api_admin
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002387
2388# Admin to remove all jobs
BjornMagnussonXA366e36a2021-01-27 11:48:56 +01002389# args: <response-code> [ <type> ]
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002390# (Function for test scripts)
2391
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002392ics_api_admin_reset() {
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002393 __log_test_start $@
2394
2395 if [ -z "$FLAT_A1_EI" ]; then
2396 query="/A1-EI/v1/eitypes/$2/eijobs"
2397 else
2398 query="/A1-EI/v1/eijobs"
2399 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002400 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002401 status=${res:${#res}-3}
2402
2403 if [ $status -ne 200 ]; then
2404 __log_test_fail_status_code $1 $status
2405 return 1
2406 fi
2407
2408 #Remove brackets and response code
2409 body=${res:1:${#res}-4}
2410 list=$(echo ${body//,/ })
2411 list=$(echo ${list//[/})
2412 list=$(echo ${list//]/})
2413 list=$(echo ${list//\"/})
2414 list=$list" "
2415 for job in $list; do
2416 if [ -z "$FLAT_A1_EI" ]; then
2417 echo "Not supported for non-flat EI api"
2418 else
2419 query="/A1-EI/v1/eijobs/$job"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002420 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002421 status=${res:${#res}-3}
2422 if [ $status -ne 204 ]; then
2423 __log_test_fail_status_code $1 $status
2424 return 1
2425 fi
2426 echo " Deleted job: "$job
2427 fi
2428 done
2429
2430 __log_test_pass
2431 return 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002432}
2433
2434##########################################
2435#### Reset jobs and producers ####
2436##########################################
2437
2438
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002439# Admin reset to remove all data in ics; jobs, producers etc
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002440# NOTE - only works in kubernetes and the pod should not be running
2441# args: -
2442# (Function for test scripts)
2443
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002444ics_kube_pvc_reset() {
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002445 __log_test_start $@
2446
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002447 pvc_name=$(kubectl get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep information)
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +02002448 if [ -z "$pvc_name" ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002449 pvc_name=informationservice-pvc
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +02002450 fi
2451 echo " Trying to reset pvc: "$pvc_name
2452
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002453 __kube_clean_pvc $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $ICS_CONTAINER_MNT_DIR
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002454
2455 __log_test_pass
2456 return 0
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002457}