blob: 0df2ae41ab0a08bd2afab52519a66f4dd80da8c2 [file] [log] [blame]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001#!/bin/bash
2
3# ============LICENSE_START===============================================
4# Copyright (C) 2020 Nordix Foundation. All rights reserved.
5# ========================================================================
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17# ============LICENSE_END=================================================
18#
19
BjornMagnussonXA007b6452021-11-29 08:03:38 +010020# This is a script that contains container/service management functions and test functions for ICS
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020021
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010022################ Test engine functions ################
23
24# Create the image var used during the test
25# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
26# <image-tag-suffix> is present only for images with staging, snapshot,release tags
BjornMagnussonXA007b6452021-11-29 08:03:38 +010027__ICS_imagesetup() {
28 __check_and_create_image_var ICS "ICS_IMAGE" "ICS_IMAGE_BASE" "ICS_IMAGE_TAG" $1 "$ICS_DISPLAY_NAME"
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010029}
30
31# Pull image from remote repo or use locally built image
32# arg: <pull-policy-override> <pull-policy-original>
33# <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
34# <pull-policy-original> Shall be used for images that does not allow overriding
35# Both var may contain: 'remote', 'remote-remove' or 'local'
BjornMagnussonXA007b6452021-11-29 08:03:38 +010036__ICS_imagepull() {
37 __check_and_pull_image $1 "$ICS_DISPLAY_NAME" $ICS_APP_NAME ICS_IMAGE
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010038}
39
40# Build image (only for simulator or interfaces stubs owned by the test environment)
41# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
42# <image-tag-suffix> is present only for images with staging, snapshot,release tags
BjornMagnussonXA007b6452021-11-29 08:03:38 +010043__ICS_imagebuild() {
44 echo -e $RED" Image for app ICS shall never be built"$ERED
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010045}
46
47# Generate a string for each included image using the app display name and a docker images format string
BjornMagnussonXA483ee332021-04-08 01:35:24 +020048# If a custom image repo is used then also the source image from the local repo is listed
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010049# arg: <docker-images-format-string> <file-to-append>
BjornMagnussonXA007b6452021-11-29 08:03:38 +010050__ICS_image_data() {
51 echo -e "$ICS_DISPLAY_NAME\t$(docker images --format $1 $ICS_IMAGE)" >> $2
52 if [ ! -z "$ICS_IMAGE_SOURCE" ]; then
53 echo -e "-- source image --\t$(docker images --format $1 $ICS_IMAGE_SOURCE)" >> $2
BjornMagnussonXA483ee332021-04-08 01:35:24 +020054 fi
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010055}
56
57# Scale kubernetes resources to zero
58# All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
59# This function is called for apps fully managed by the test script
BjornMagnussonXA007b6452021-11-29 08:03:38 +010060__ICS_kube_scale_zero() {
61 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ICS
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010062}
63
64# Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
65# This function is called for prestarted apps not managed by the test script.
BjornMagnussonXA007b6452021-11-29 08:03:38 +010066__ICS_kube_scale_zero_and_wait() {
67 __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app "$KUBE_NONRTRIC_NAMESPACE"-informationservice
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010068}
69
70# Delete all kube resouces for the app
71# This function is called for apps managed by the test script.
BjornMagnussonXA007b6452021-11-29 08:03:38 +010072__ICS_kube_delete_all() {
73 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ICS
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010074}
75
76# Store docker logs
77# This function is called for apps managed by the test script.
78# args: <log-dir> <file-prexix>
BjornMagnussonXA007b6452021-11-29 08:03:38 +010079__ICS_store_docker_logs() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +010080 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAcb6113e2022-02-17 15:01:28 +010081 kubectl $KUBECONF logs -l "autotest=ICS" -n $KUBE_NONRTRIC_NAMESPACE --tail=-1 > $1$2_ics.log 2>&1
BjornMagnussonXA663566c2021-11-08 10:25:07 +010082 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +010083 docker logs $ICS_APP_NAME > $1$2_ics.log 2>&1
BjornMagnussonXA663566c2021-11-08 10:25:07 +010084 fi
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010085}
BjornMagnussonXA663566c2021-11-08 10:25:07 +010086
87# Initial setup of protocol, host and ports
88# This function is called for apps managed by the test script.
89# args: -
BjornMagnussonXA007b6452021-11-29 08:03:38 +010090__ICS_initial_setup() {
91 use_ics_rest_http
BjornMagnussonXA663566c2021-11-08 10:25:07 +010092}
93
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +010094# Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers
95# For docker, the namespace shall be excluded
96# This function is called for apps managed by the test script as well as for prestarted apps.
97# args: -
BjornMagnussonXA007b6452021-11-29 08:03:38 +010098__ICS_statisics_setup() {
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +010099 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100100 echo "ICS $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE"
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100101 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100102 echo "ICS $ICS_APP_NAME"
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100103 fi
104}
105
BjornMagnussonXAe60d04e2021-12-27 13:38:01 +0100106# Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
107# args: -
108__ICS_test_requirements() {
109 :
110}
111
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100112#######################################################
113
114
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100115# Make curl retries towards ICS for http response codes set in this env var, space separated list of codes
116ICS_RETRY_CODES=""
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100117
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200118#Save first worker node the pod is started on
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100119__ICS_WORKER_NODE=""
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200120
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100121###########################
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100122### ICS functions
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100123###########################
124
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100125# All calls to ICS will be directed to the ICS REST interface from now on
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100126# args: -
127# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100128use_ics_rest_http() {
129 __ics_set_protocoll "http" $ICS_INTERNAL_PORT $ICS_EXTERNAL_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100130}
131
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100132# All calls to ICS will be directed to the ICS REST interface from now on
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100133# args: -
134# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100135use_ics_rest_https() {
136 __ics_set_protocoll "https" $ICS_INTERNAL_SECURE_PORT $ICS_EXTERNAL_SECURE_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100137}
138
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100139# All calls to ICS will be directed to the ICS dmaap interface over http from now on
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100140# args: -
141# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100142use_ics_dmaap_http() {
143 echo -e $BOLD"ICS dmaap protocol setting"$EBOLD
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100144 echo -e $RED" - NOT SUPPORTED - "$ERED
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100145 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ICS"
146 ICS_ADAPTER_TYPE="MR-HTTP"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100147 echo ""
148}
149
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100150# Setup paths to svc/container for internal and external access
151# args: <protocol> <internal-port> <external-port>
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100152__ics_set_protocoll() {
153 echo -e $BOLD"$ICS_DISPLAY_NAME protocol setting"$EBOLD
154 echo -e " Using $BOLD $1 $EBOLD towards $ICS_DISPLAY_NAME"
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100155
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100156 ## Access to ICS
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100157
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100158 ICS_SERVICE_PATH=$1"://"$ICS_APP_NAME":"$2 # docker access, container->container and script->container via proxy
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100159 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100160 ICS_SERVICE_PATH=$1"://"$ICS_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100161 fi
162
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100163 # ICS_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
164 ICS_ADAPTER_TYPE="REST"
165 ICS_ADAPTER=$ICS_SERVICE_PATH
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100166
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100167 echo ""
168}
169
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100170# Export env vars for config files, docker compose and kube resources
171# args: PROXY|NOPROXY
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100172__ics_export_vars() {
173 export ICS_APP_NAME
174 export ICS_APP_NAME_ALIAS
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100175 export KUBE_NONRTRIC_NAMESPACE
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100176 export ICS_IMAGE
177 export ICS_INTERNAL_PORT
178 export ICS_INTERNAL_SECURE_PORT
179 export ICS_EXTERNAL_PORT
180 export ICS_EXTERNAL_SECURE_PORT
181 export ICS_CONFIG_MOUNT_PATH
182 export ICS_CONFIG_CONFIGMAP_NAME=$ICS_APP_NAME"-config"
183 export ICS_DATA_CONFIGMAP_NAME=$ICS_APP_NAME"-data"
184 export ICS_CONTAINER_MNT_DIR
185 export ICS_HOST_MNT_DIR
186 export ICS_CONFIG_FILE
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100187 export DOCKER_SIM_NWNAME
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100188 export ICS_DISPLAY_NAME
BjornMagnussonXA05bfe482021-12-02 08:47:41 +0100189 export ICS_LOGPATH
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100190
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100191 export ICS_DATA_PV_NAME=$ICS_APP_NAME"-pv"
192 export ICS_DATA_PVC_NAME=$ICS_APP_NAME"-pvc"
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100193 #Create a unique path for the pv each time to prevent a previous volume to be reused
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100194 export ICS_PV_PATH="icsdata-"$(date +%s)
BjornMagnussonXAc8f92e92022-02-28 15:16:37 +0100195 export HOST_PATH_BASE_DIR
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100196
197 if [ $1 == "PROXY" ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100198 export ICS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
199 export ICS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
200 if [ $ICS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ICS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100201 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
202 else
203 echo " Configured with http proxy"
204 fi
205 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100206 export ICS_HTTP_PROXY_CONFIG_PORT=0
207 export ICS_HTTP_PROXY_CONFIG_HOST_NAME=""
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100208 echo " Configured without http proxy"
209 fi
210}
211
212
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100213# Start the ICS
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100214# args: PROXY|NOPROXY <config-file>
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100215# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100216start_ics() {
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100217
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100218 echo -e $BOLD"Starting $ICS_DISPLAY_NAME"$EBOLD
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100219
220 if [ $RUNMODE == "KUBE" ]; then
221
222 # Check if app shall be fully managed by the test script
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100223 __check_included_image "ICS"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100224 retcode_i=$?
225
226 # Check if app shall only be used by the testscipt
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100227 __check_prestarted_image "ICS"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100228 retcode_p=$?
229
230 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100231 echo -e $RED"The $ICS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
232 echo -e $RED"The $ICS_APP_NAME will not be started"$ERED
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100233 exit
234 fi
235 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100236 echo -e $RED"The $ICS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
237 echo -e $RED"The $ICS_APP_NAME will not be started"$ERED
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100238 exit
239 fi
240
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100241 if [ $retcode_p -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100242 echo -e " Using existing $ICS_APP_NAME deployment and service"
243 echo " Setting ICS replicas=1"
244 res_type=$(__kube_get_resource_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
245 __kube_scale $res_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100246 fi
247
248 # Check if app shall be fully managed by the test script
249 if [ $retcode_i -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100250 echo -e " Creating $ICS_APP_NAME app and expose service"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100251
252 #Check if nonrtric namespace exists, if not create it
253 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
254
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100255 __ics_export_vars $1
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100256
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100257 # Create config map for config
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100258 datafile=$PWD/tmp/$ICS_CONFIG_FILE
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100259 cp $2 $datafile
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100260 output_yaml=$PWD/tmp/ics_cfc.yaml
261 __kube_create_configmap $ICS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ICS $datafile $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100262
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100263 # Create pv
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100264 input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"pv.yaml
265 output_yaml=$PWD/tmp/ics_pv.yaml
266 __kube_create_instance pv $ICS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100267
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100268 # Create pvc
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100269 input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"pvc.yaml
270 output_yaml=$PWD/tmp/ics_pvc.yaml
271 __kube_create_instance pvc $ICS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100272
273 # Create service
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100274 input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"svc.yaml
275 output_yaml=$PWD/tmp/ics_svc.yaml
276 __kube_create_instance service $ICS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100277
278 # Create app
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100279 input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"app.yaml
280 output_yaml=$PWD/tmp/ics_app.yaml
281 __kube_create_instance app $ICS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100282 fi
283
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100284 # Tie the ICS to a worker node so that ICS will always be scheduled to the same worker node if the ICS pod is restarted
285 # A PVC of type hostPath is mounted to ICS, for persistent storage, so the ICS must always be on the node which mounted the volume
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200286
287 # Keep the initial worker node in case the pod need to be "restarted" - must be made to the same node due to a volume mounted on the host
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200288 if [ $retcode_i -eq 0 ]; then
BjornMagnussonXAc8f92e92022-02-28 15:16:37 +0100289 __ICS_WORKER_NODE=$(kubectl $KUBECONF get pod -l "autotest=ICS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100290 if [ -z "$__ICS_WORKER_NODE" ]; then
291 echo -e $YELLOW" Cannot find worker node for pod for $ICS_APP_NAME, persistency may not work"$EYELLOW
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200292 fi
293 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100294 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 +0200295 fi
296
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100297
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100298 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100299
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100300 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100301 __check_included_image 'ICS'
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100302 if [ $? -eq 1 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100303 echo -e $RED"The ICS app is not included in this test script"$ERED
304 echo -e $RED"ICS will not be started"$ERED
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100305 exit 1
306 fi
307
308 curdir=$PWD
309 cd $SIM_GROUP
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100310 cd ics
311 cd $ICS_HOST_MNT_DIR
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100312 #cd ..
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100313 if [ -d db ]; then
314 if [ "$(ls -A $DIR)" ]; then
315 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
316 rm -rf db/* &> /dev/null
317 if [ $? -ne 0 ]; then
318 echo -e $RED" Cannot remove database files in: $PWD"$ERED
319 exit 1
320 fi
321 fi
322 else
323 echo " No files in mounted dir or dir does not exists"
324 fi
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100325
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100326 cd $curdir
327
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100328 __ics_export_vars $1
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100329
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100330 dest_file=$SIM_GROUP/$ICS_COMPOSE_DIR/$ICS_HOST_MNT_DIR/$ICS_CONFIG_FILE
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100331
332 envsubst < $2 > $dest_file
333
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100334 __start_container $ICS_COMPOSE_DIR "" NODOCKERARGS 1 $ICS_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100335
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100336 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100337 fi
338 echo ""
339 return 0
340}
341
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100342# Stop the ics
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200343# args: -
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100344# args: -
345# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100346stop_ics() {
347 echo -e $BOLD"Stopping $ICS_DISPLAY_NAME"$EBOLD
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200348
349 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200350
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100351 __check_prestarted_image "ICS"
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200352 if [ $? -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100353 echo -e $YELLOW" Persistency may not work for app $ICS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
354 res_type=$(__kube_get_resource_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
355 __kube_scale $res_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200356 return 0
357 fi
358
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100359 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ICS
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200360 echo " Deleting the replica set - a new will be started when the app is started"
BjornMagnussonXAcb6113e2022-02-17 15:01:28 +0100361 tmp=$(kubectl $KUBECONF delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=ICS")
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200362 if [ $? -ne 0 ]; then
363 echo -e $RED" Could not delete replica set "$RED
364 ((RES_CONF_FAIL++))
365 return 1
366 fi
367 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100368 docker stop $ICS_APP_NAME &> ./tmp/.dockererr
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200369 if [ $? -ne 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100370 __print_err "Could not stop $ICS_APP_NAME" $@
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200371 cat ./tmp/.dockererr
372 ((RES_CONF_FAIL++))
373 return 1
374 fi
375 fi
376 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
377 echo ""
378 return 0
379}
380
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100381# Start a previously stopped ics
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200382# args: -
383# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100384start_stopped_ics() {
385 echo -e $BOLD"Starting (the previously stopped) $ICS_DISPLAY_NAME"$EBOLD
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200386
387 if [ $RUNMODE == "KUBE" ]; then
388
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100389 __check_prestarted_image "ICS"
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200390 if [ $? -eq 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100391 echo -e $YELLOW" Persistency may not work for app $ICS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
392 res_type=$(__kube_get_resource_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
393 __kube_scale $res_type $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
394 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200395 return 0
396 fi
397
BjornMagnussonXAc8f92e92022-02-28 15:16:37 +0100398 # Tie the ICS to the same worker node it was initially started on
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100399 # A PVC of type hostPath is mounted to A1PMS, for persistent storage, so the A1PMS must always be on the node which mounted the volume
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100400 if [ -z "$__ICS_WORKER_NODE" ]; then
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200401 echo -e $RED" No initial worker node found for pod "$RED
402 ((RES_CONF_FAIL++))
403 return 1
404 else
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100405 echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__ICS_WORKER_NODE to deployment for $ICS_APP_NAME. Pod will always run on this worker node: $__ICS_WORKER_NODE"$BOLD
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200406 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
BjornMagnussonXAcb6113e2022-02-17 15:01:28 +0100407 tmp=$(kubectl $KUBECONF patch deployment $ICS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__ICS_WORKER_NODE'"}}}}}')
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200408 if [ $? -ne 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100409 echo -e $YELLOW" Cannot set nodeSelector to deployment for $ICS_APP_NAME, persistency may not work"$EYELLOW
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200410 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100411 __kube_scale deployment $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200412 fi
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200413 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100414 docker start $ICS_APP_NAME &> ./tmp/.dockererr
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200415 if [ $? -ne 0 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100416 __print_err "Could not start (the stopped) $ICS_APP_NAME" $@
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200417 cat ./tmp/.dockererr
418 ((RES_CONF_FAIL++))
419 return 1
420 fi
421 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100422 __check_service_start $ICS_APP_NAME $ICS_SERVICE_PATH$ICS_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100423 if [ $? -ne 0 ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100424 return 1
425 fi
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100426 echo ""
427 return 0
428}
429
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100430# Turn on debug level tracing in ICS
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100431# args: -
432# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100433set_ics_debug() {
434 echo -e $BOLD"Setting ics debug logging"$EBOLD
435 curlString="$ICS_SERVICE_PATH$ICS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100436 result=$(__do_curl "$curlString")
437 if [ $? -ne 0 ]; then
438 __print_err "Could not set debug mode" $@
439 ((RES_CONF_FAIL++))
440 return 1
441 fi
442 echo ""
443 return 0
444}
445
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100446# Turn on trace level tracing in ICS
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100447# args: -
448# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100449set_ics_trace() {
450 echo -e $BOLD"Setting ics trace logging"$EBOLD
451 curlString="$ICS_SERVICE_PATH/actuator/loggers/org.oransc.information -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100452 result=$(__do_curl "$curlString")
453 if [ $? -ne 0 ]; then
454 __print_err "Could not set trace mode" $@
455 ((RES_CONF_FAIL++))
456 return 1
457 fi
458 echo ""
459 return 0
460}
461
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100462# Perform curl retries when making direct call to ICS for the specified http response codes
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100463# Speace separated list of http response codes
464# args: [<response-code>]*
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100465use_ics_retries() {
466 echo -e $BOLD"Do curl retries to the ICS REST inteface for these response codes:$@"$EBOLD
467 ICS_RETRY_CODES=$@
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100468 echo ""
469 return 0
470}
471
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100472# Check the ics logs for WARNINGs and ERRORs
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100473# args: -
474# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100475check_ics_logs() {
476 __check_container_logs "ICS" $ICS_APP_NAME $ICS_LOGPATH WARN ERR
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100477}
478
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200479
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100480# Tests if a variable value in the ICS is equal to a target value and and optional timeout.
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100481# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
482# equal to the target or not.
483# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
484# before setting pass or fail depending on if the variable value becomes equal to the target
485# value or not.
486# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100487ics_equal() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100488 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100489 __var_test ICS "$ICS_SERVICE_PATH/" $1 "=" $2 $3
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100490 else
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100491 __print_err "Wrong args to ics_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100492 fi
493}
494
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200495
496##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100497######### A1-E information API ##########
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200498##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100499#Function prefix: ics_api_a1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200500
501# API Test function: GET /A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200502# args: <response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100503# args (flat uri structure): <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200504# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100505ics_api_a1_get_job_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100506 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200507
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100508 if [ -z "$FLAT_A1_EI" ]; then
509 # Valid number of parameters 4,5,6 etc
510 if [ $# -lt 3 ]; then
511 __print_err "<response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
512 return 1
513 fi
514 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100515 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100516 # Valid number of parameters 4,5,6 etc
517 if [ $# -lt 3 ]; then
518 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
519 return 1
520 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200521 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100522 search=""
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200523 if [ $3 != "NOWNER" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100524 search="?owner="$3
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200525 fi
526
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100527 if [ -z "$FLAT_A1_EI" ]; then
528 query="/A1-EI/v1/eitypes/$2/eijobs$search"
529 else
530 if [ $2 != "NOTYPE" ]; then
531 if [ -z "$search" ]; then
532 search="?eiTypeId="$2
533 else
534 search=$search"&eiTypeId="$2
535 fi
536 fi
537 query="/A1-EI/v1/eijobs$search"
538 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100539 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200540 status=${res:${#res}-3}
541
542 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100543 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200544 return 1
545 fi
546
547 if [ $# -gt 3 ]; then
548 body=${res:0:${#res}-3}
549 targetJson="["
550
551 for pid in ${@:4} ; do
552 if [ "$targetJson" != "[" ]; then
553 targetJson=$targetJson","
554 fi
555 if [ $pid != "EMPTY" ]; then
556 targetJson=$targetJson"\"$pid\""
557 fi
558 done
559
560 targetJson=$targetJson"]"
561 echo " TARGET JSON: $targetJson" >> $HTTPLOG
562 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
563
564 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100565 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200566 return 1
567 fi
568 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200569
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100570 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200571 return 0
572}
573
574# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200575# args: <response-code> <type-id> [<schema-file>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200576# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100577ics_api_a1_get_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100578 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200579
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200580 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
581 __print_err "<response-code> <type-id> [<schema-file>]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200582 return 1
583 fi
584
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200585 query="/A1-EI/v1/eitypes/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100586 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200587 status=${res:${#res}-3}
588
589 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100590 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200591 return 1
592 fi
593
594 if [ $# -eq 3 ]; then
595 body=${res:0:${#res}-3}
596 if [ -f $3 ]; then
597 schema=$(cat $3)
598 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100599 __log_test_fail_general "Schema file "$3", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200600 return 1
601 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100602 if [ -z "$FLAT_A1_EI" ]; then
603 targetJson="{\"eiJobParametersSchema\":$schema}"
604 else
605 targetJson=$schema
606 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200607 echo " TARGET JSON: $targetJson" >> $HTTPLOG
608 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
609
610 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100611 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200612 return 1
613 fi
614 fi
615
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100616 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200617 return 0
618}
619
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200620# API Test function: GET /A1-EI/v1/eitypes
621# args: <response-code> [ (EMPTY | [<type-id>]+) ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200622# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100623ics_api_a1_get_type_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100624 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200625
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200626 if [ $# -lt 1 ]; then
627 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200628 return 1
629 fi
630
631 query="/A1-EI/v1/eitypes"
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100632 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200633 status=${res:${#res}-3}
634
635 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100636 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200637 return 1
638 fi
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200639 if [ $# -gt 1 ]; then
640 body=${res:0:${#res}-3}
641 targetJson="["
642 if [ $2 != "EMPTY" ]; then
643 for pid in ${@:2} ; do
644 if [ "$targetJson" != "[" ]; then
645 targetJson=$targetJson","
646 fi
647 targetJson=$targetJson"\"$pid\""
648 done
649 fi
650 targetJson=$targetJson"]"
651 echo " TARGET JSON: $targetJson" >> $HTTPLOG
652 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200653
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200654 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100655 __log_test_fail_body
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200656 return 1
657 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200658 fi
659
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100660 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200661 return 0
662}
663
664# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200665# args: <response-code> <type-id> <job-id> [<status>]
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100666# args (flat uri structure): <response-code> <job-id> [<status> [<timeout>]]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200667# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100668ics_api_a1_get_job_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100669 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200670
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100671 if [ -z "$FLAT_A1_EI" ]; then
672 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
673 __print_err "<response-code> <type-id> <job-id> [<status>]" $@
674 return 1
675 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200676
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100677 query="/A1-EI/v1/eitypes/$2/eijobs/$3/status"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200678
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100679 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100680 status=${res:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200681
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100682 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100683 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200684 return 1
685 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100686 if [ $# -eq 4 ]; then
687 body=${res:0:${#res}-3}
688 targetJson="{\"operationalState\": \"$4\"}"
689 echo " TARGET JSON: $targetJson" >> $HTTPLOG
690 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
691
692 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100693 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100694 return 1
695 fi
696 fi
697 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100698 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100699 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
700 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100701 return 1
702 fi
703
704 query="/A1-EI/v1/eijobs/$2/status"
705
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100706 start=$SECONDS
707 for (( ; ; )); do
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100708 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100709 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100710
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100711 if [ $# -eq 4 ]; then
712 duration=$((SECONDS-start))
713 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
714 if [ $duration -gt $4 ]; then
715 echo ""
716 duration=-1 #Last iteration
717 fi
718 else
719 duration=-1 #single test, no wait
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100720 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100721
722 if [ $status -ne $1 ]; then
723 if [ $duration -eq -1 ]; then
724 __log_test_fail_status_code $1 $status
725 return 1
726 fi
727 fi
728 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
729 body=${res:0:${#res}-3}
730 targetJson="{\"eiJobStatus\": \"$3\"}"
731 echo " TARGET JSON: $targetJson" >> $HTTPLOG
732 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
733
734 if [ $res -ne 0 ]; then
735 if [ $duration -eq -1 ]; then
736 __log_test_fail_body
737 return 1
738 fi
739 else
740 duration=-1 #Goto pass
741 fi
742 fi
743 if [ $duration -eq -1 ]; then
744 if [ $# -eq 4 ]; then
745 echo ""
746 fi
747 __log_test_pass
748 return 0
749 else
750 sleep 1
751 fi
752 done
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200753 fi
754
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100755 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200756 return 0
757}
758
759# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200760# args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100761# args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200762# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100763ics_api_a1_get_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100764 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200765
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100766 if [ -z "$FLAT_A1_EI" ]; then
767 if [ $# -ne 3 ] && [ $# -ne 6 ]; then
768 __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@
769 return 1
770 fi
771 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
772 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100773 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100774 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
775 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
776 return 1
777 fi
778 query="/A1-EI/v1/eijobs/$2"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200779 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100780 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200781 status=${res:${#res}-3}
782
783 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100784 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200785 return 1
786 fi
787
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100788 if [ -z "$FLAT_A1_EI" ]; then
789 if [ $# -eq 6 ]; then
790 body=${res:0:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200791
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100792 if [ -f $6 ]; then
793 jobfile=$(cat $6)
794 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
795 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200796 __log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100797 return 1
798 fi
799 targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
800 echo " TARGET JSON: $targetJson" >> $HTTPLOG
801 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
802
803 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100804 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100805 return 1
806 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200807 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100808 else
809 if [ $# -eq 7 ]; then
810 body=${res:0:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200811
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100812 if [ -f $7 ]; then
813 jobfile=$(cat $7)
814 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
815 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200816 __log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100817 return 1
818 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100819 targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100820 echo " TARGET JSON: $targetJson" >> $HTTPLOG
821 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
822
823 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100824 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100825 return 1
826 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200827 fi
828 fi
829
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100830 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200831 return 0
832}
833
834# API Test function: DELETE ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200835# args: <response-code> <type-id> <job-id>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100836# args (flat uri structure): <response-code> <job-id>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200837# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100838ics_api_a1_delete_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100839 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200840
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100841 if [ -z "$FLAT_A1_EI" ]; then
842 if [ $# -ne 3 ]; then
843 __print_err "<response-code> <type-id> <job-id>" $@
844 return 1
845 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200846
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100847 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
848 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100849 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100850 if [ $# -ne 2 ]; then
851 __print_err "<response-code> <job-id>" $@
852 return 1
853 fi
854 query="/A1-EI/v1/eijobs/$2"
855 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100856 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200857 status=${res:${#res}-3}
858
859 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100860 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200861 return 1
862 fi
863
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100864 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200865 return 0
866}
867
868# API Test function: PUT ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200869# args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100870# 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 +0200871# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100872ics_api_a1_put_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100873 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200874
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100875 if [ -z "$FLAT_A1_EI" ]; then
876 if [ $# -lt 6 ]; then
877 __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@
878 return 1
879 fi
880 if [ -f $6 ]; then
881 jobfile=$(cat $6)
882 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
883 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200884 __log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100885 return 1
886 fi
887
888 inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
889 file="./tmp/.p.json"
890 echo "$inputJson" > $file
891
892 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200893 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100894 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100895 if [ $# -lt 7 ]; then
896 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@
897 return 1
898 fi
899 if [ -f $7 ]; then
900 jobfile=$(cat $7)
901 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
902 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200903 __log_test_fail_general "Job template file "$7", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100904 return 1
905 fi
906
907 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
908 file="./tmp/.p.json"
909 echo "$inputJson" > $file
910
911 query="/A1-EI/v1/eijobs/$2"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200912 fi
913
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100914 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200915 status=${res:${#res}-3}
916
917 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100918 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200919 return 1
920 fi
921
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100922 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200923 return 0
924}
925
926
927##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100928#### information Data Producer API ####
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200929##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100930# Function prefix: ics_api_edp
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200931
932# API Test function: GET /ei-producer/v1/eitypes
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200933# API Test function: GET /data-producer/v1/info-types
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200934# args: <response-code> [ EMPTY | <type-id>+]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200935# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100936ics_api_edp_get_type_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100937 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200938
939 if [ $# -lt 1 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200940 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200941 return 1
942 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100943 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200944 query="/data-producer/v1/info-types"
945 else
946 query="/ei-producer/v1/eitypes"
947 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100948 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200949 status=${res:${#res}-3}
950
951 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100952 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200953 return 1
954 fi
955
956 if [ $# -gt 1 ]; then
957 body=${res:0:${#res}-3}
958 targetJson="["
959 if [ $2 != "EMPTY" ]; then
960 for pid in ${@:2} ; do
961 if [ "$targetJson" != "[" ]; then
962 targetJson=$targetJson","
963 fi
964 targetJson=$targetJson"\"$pid\""
965 done
966 fi
967 targetJson=$targetJson"]"
968 echo " TARGET JSON: $targetJson" >> $HTTPLOG
969 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
970
971 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100972 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200973 return 1
974 fi
975 fi
976
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100977 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200978 return 0
979}
980
981# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200982# API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100983# args: <response-code> <producer-id> [<status> [<timeout>]]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200984# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100985ics_api_edp_get_producer_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100986 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200987
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100988 if [ $# -lt 2 ] || [ $# -gt 4 ]; then
989 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200990 return 1
991 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100992 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200993 query="/data-producer/v1/info-producers/$2/status"
994 else
995 query="/ei-producer/v1/eiproducers/$2/status"
996 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100997 start=$SECONDS
998 for (( ; ; )); do
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100999 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001000 status=${res:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001001
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001002 if [ $# -eq 4 ]; then
1003 duration=$((SECONDS-start))
1004 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
1005 if [ $duration -gt $4 ]; then
1006 echo ""
1007 duration=-1 #Last iteration
1008 fi
1009 else
1010 duration=-1 #single test, no wait
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001011 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001012
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001013 if [ $status -ne $1 ]; then
1014 if [ $duration -eq -1 ]; then
1015 __log_test_fail_status_code $1 $status
1016 return 1
1017 fi
1018 fi
1019 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
1020 body=${res:0:${#res}-3}
1021 targetJson="{\"operational_state\": \"$3\"}"
1022 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1023 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1024
1025 if [ $res -ne 0 ]; then
1026 if [ $duration -eq -1 ]; then
1027 __log_test_fail_body
1028 return 1
1029 fi
1030 else
1031 duration=-1 #Goto pass
1032 fi
1033 fi
1034 if [ $duration -eq -1 ]; then
1035 if [ $# -eq 4 ]; then
1036 echo ""
1037 fi
1038 __log_test_pass
1039 return 0
1040 else
1041 sleep 1
1042 fi
1043 done
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001044}
1045
1046
1047# API Test function: GET /ei-producer/v1/eiproducers
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001048# args (v1_1): <response-code> [ EMPTY | <producer-id>+]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001049# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001050ics_api_edp_get_producer_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001051 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001052
1053 if [ $# -lt 1 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001054 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001055 return 1
1056 fi
1057
1058 query="/ei-producer/v1/eiproducers"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001059 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001060 status=${res:${#res}-3}
1061
1062 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001063 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001064 return 1
1065 fi
1066
1067 if [ $# -gt 1 ]; then
1068 body=${res:0:${#res}-3}
1069 targetJson="["
1070
1071 for pid in ${@:2} ; do
1072 if [ "$targetJson" != "[" ]; then
1073 targetJson=$targetJson","
1074 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001075 if [ $pid != "EMPTY" ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001076 targetJson=$targetJson"\"$pid\""
1077 fi
1078 done
1079
1080 targetJson=$targetJson"]"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001081 echo " TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001082 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1083
1084 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001085 __log_test_fail_body
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001086 return 1
1087 fi
1088 fi
1089
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001090 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001091 return 0
1092}
1093
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001094# API Test function: GET /ei-producer/v1/eiproducers
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001095# API Test function: GET /data-producer/v1/info-producers
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001096# args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]
1097# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001098ics_api_edp_get_producer_ids_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001099 __log_test_start $@
1100
1101 if [ $# -lt 1 ]; then
1102 __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
1103 return 1
1104 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001105 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001106 query="/data-producer/v1/info-producers"
1107 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
BjornMagnussonXAc8f92e92022-02-28 15:16:37 +01001108 query=$query"?info_type_id=$2&infoTypeId=$2" #info_type_id changed to infoTypeId in F-release.
1109 #Remove info_type_id when F-release is no longer supported
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001110 fi
1111 else
1112 query="/ei-producer/v1/eiproducers"
1113 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1114 query=$query"?ei_type_id=$2"
1115 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001116 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001117 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001118 status=${res:${#res}-3}
1119
1120 if [ $status -ne $1 ]; then
1121 __log_test_fail_status_code $1 $status
1122 return 1
1123 fi
1124
1125 if [ $# -gt 2 ]; then
1126 body=${res:0:${#res}-3}
1127 targetJson="["
1128
1129 for pid in ${@:3} ; do
1130 if [ "$targetJson" != "[" ]; then
1131 targetJson=$targetJson","
1132 fi
1133 if [ $pid != "EMPTY" ]; then
1134 targetJson=$targetJson"\"$pid\""
1135 fi
1136 done
1137
1138 targetJson=$targetJson"]"
1139 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1140 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1141
1142 if [ $res -ne 0 ]; then
1143 __log_test_fail_body
1144 return 1
1145 fi
1146 fi
1147
1148 __log_test_pass
1149 return 0
1150}
1151
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001152# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001153# args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001154# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001155ics_api_edp_get_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001156 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001157
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001158 paramError=1
1159 if [ $# -eq 2 ]; then
1160 paramError=0
1161 fi
1162 if [ $# -gt 3 ]; then
1163 paramError=0
1164 fi
1165 if [ $paramError -ne 0 ]; then
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +02001166 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001167 return 1
1168 fi
1169
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001170 query="/ei-producer/v1/eitypes/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001171 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001172 status=${res:${#res}-3}
1173
1174 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001175 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001176 return 1
1177 fi
1178 if [ $# -gt 3 ]; then
1179 body=${res:0:${#res}-3}
1180
1181 if [ -f $3 ]; then
1182 schema=$(cat $3)
1183 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001184 __log_test_fail_general "Job template file "$3", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001185 return 1
1186 fi
1187
1188 targetJson=""
1189 if [ $4 != "EMPTY" ]; then
1190 for pid in ${@:4} ; do
1191 if [ "$targetJson" != "" ]; then
1192 targetJson=$targetJson","
1193 fi
1194 targetJson=$targetJson"\"$pid\""
1195 done
1196 fi
1197 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
1198
1199 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1200 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1201
1202 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001203 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001204 return 1
1205 fi
1206 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001207 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001208 return 0
1209}
1210
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001211# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001212# API Test function: GET /data-producer/v1/info-types/{infoTypeId}
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001213# args: (v1_2) <response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001214# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001215ics_api_edp_get_type_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001216 __log_test_start $@
1217
1218 paramError=1
1219 if [ $# -eq 2 ]; then
1220 paramError=0
1221 fi
1222 if [ $# -eq 3 ]; then
1223 paramError=0
1224 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001225 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001226 if [ $# -eq 4 ]; then
1227 paramError=0
1228 fi
1229 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001230 if [ $paramError -ne 0 ]; then
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001231 __print_err "<response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]" $@
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001232 return 1
1233 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001234 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001235 query="/data-producer/v1/info-types/$2"
1236 else
1237 query="/ei-producer/v1/eitypes/$2"
1238 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001239
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001240 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001241 status=${res:${#res}-3}
1242
1243 if [ $status -ne $1 ]; then
1244 __log_test_fail_status_code $1 $status
1245 return 1
1246 fi
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001247 if [ $# -ge 3 ]; then
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001248 body=${res:0:${#res}-3}
1249
1250 if [ -f $3 ]; then
1251 schema=$(cat $3)
1252 else
1253 __log_test_fail_general "Job template file "$3", does not exist"
1254 return 1
1255 fi
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001256 info_data=""
1257 if [ $# -gt 3 ]; then
1258 if [ -f $4 ]; then
1259 info_data=$(cat $4)
1260 else
1261 __log_test_fail_general "Info-data file "$4", does not exist"
1262 return 1
1263 fi
1264 info_data=",\"info_type_information\":$info_data"
1265 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001266 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001267 targetJson="{\"info_job_data_schema\":$schema $info_data}"
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001268 else
1269 targetJson="{\"ei_job_data_schema\":$schema}"
1270 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001271
1272 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1273 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1274
1275 if [ $res -ne 0 ]; then
1276 __log_test_fail_body
1277 return 1
1278 fi
1279 fi
1280 __log_test_pass
1281 return 0
1282}
1283
1284# API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001285# API Test function: PUT /data-producer/v1/info-types/{infoTypeId}
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001286# args: (v1_2) <response-code> <type-id> <job-schema-file> [ <info-type-info> ]
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001287# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001288ics_api_edp_put_type_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001289 __log_test_start $@
1290
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001291 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001292 if [ $# -lt 3 ] || [ $# -gt 4 ]; then
1293 __print_err "<response-code> <type-id> <job-schema-file> [ <info-type-info> ]" $@
1294 return 1
1295 fi
1296 else
1297 if [ $# -ne 3 ]; then
1298 __print_err "<response-code> <type-id> <job-schema-file>" $@
1299 return 1
1300 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001301 fi
1302
1303 if [ ! -f $3 ]; then
1304 __log_test_fail_general "Job schema file "$3", does not exist"
1305 return 1
1306 fi
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001307
1308 info_data=""
1309 if [ $# -gt 3 ]; then
1310 if [ -f $4 ]; then
1311 info_data=$(cat $4)
1312 else
1313 __log_test_fail_general "Info-data file "$4", does not exist"
1314 return 1
1315 fi
1316 info_data=",\"info_type_information\":$info_data"
1317 fi
1318
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001319 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001320 schema=$(cat $3)
BjornMagnussonXA83a750f2021-09-21 20:39:58 +02001321 input_json="{\"info_job_data_schema\":$schema $info_data}"
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001322 file="./tmp/put_type.json"
1323 echo $input_json > $file
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001324
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001325 query="/data-producer/v1/info-types/$2"
1326 else
1327 schema=$(cat $3)
1328 input_json="{\"ei_job_data_schema\":$schema}"
1329 file="./tmp/put_type.json"
1330 echo $input_json > $file
1331
1332 query="/ei-producer/v1/eitypes/$2"
1333 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001334 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001335 status=${res:${#res}-3}
1336
1337 if [ $status -ne $1 ]; then
1338 __log_test_fail_status_code $1 $status
1339 return 1
1340 fi
1341
1342 __log_test_pass
1343 return 0
1344}
1345
1346# API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001347# API Test function: DELETE /data-producer/v1/info-types/{infoTypeId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001348# args: (v1_2) <response-code> <type-id>
1349# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001350ics_api_edp_delete_type_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001351 __log_test_start $@
1352
1353 if [ $# -ne 2 ]; then
1354 __print_err "<response-code> <type-id>" $@
1355 return 1
1356 fi
1357
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001358 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001359 query="/data-producer/v1/info-types/$2"
1360 else
1361 query="/ei-producer/v1/eitypes/$2"
1362 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001363 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001364 status=${res:${#res}-3}
1365
1366 if [ $status -ne $1 ]; then
1367 __log_test_fail_status_code $1 $status
1368 return 1
1369 fi
1370
1371 __log_test_pass
1372 return 0
1373}
1374
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001375# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001376# args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001377# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001378ics_api_edp_get_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001379 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001380
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001381 #Possible arg count: 2, 5 6, 8, 10 etc
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001382 paramError=1
1383 if [ $# -eq 2 ]; then
1384 paramError=0
1385 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001386 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001387 paramError=0
1388 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001389 variablecount=$(($#-4))
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001390 if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
1391 paramError=0
1392 fi
1393
1394 if [ $paramError -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001395 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001396 return 1
1397 fi
1398
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001399 query="/ei-producer/v1/eiproducers/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001400 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001401 status=${res:${#res}-3}
1402
1403 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001404 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001405 return 1
1406 fi
1407
1408 if [ $# -gt 2 ]; then
1409 body=${res:0:${#res}-3}
1410 targetJson="["
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001411 if [ $# -gt 5 ]; then
1412 arr=(${@:5})
1413 for ((i=0; i<$(($#-5)); i=i+2)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001414 if [ "$targetJson" != "[" ]; then
1415 targetJson=$targetJson","
1416 fi
1417 if [ -f ${arr[$i+1]} ]; then
1418 schema=$(cat ${arr[$i+1]})
1419 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001420 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001421 return 1
1422 fi
1423
1424 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1425 done
1426 fi
1427 targetJson=$targetJson"]"
1428 if [ $# -gt 4 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001429 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001430 fi
1431 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1432 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1433
1434 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001435 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001436 return 1
1437 fi
1438 fi
1439
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001440 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001441 return 0
1442}
1443
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001444# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001445# API Test function: GET /data-producer/v1/info-producers/{infoProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001446# args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]
1447# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001448ics_api_edp_get_producer_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001449 __log_test_start $@
1450
1451 #Possible arg count: 2, 5, 6, 7, 8 etc
1452 paramError=1
1453 if [ $# -eq 2 ]; then
1454 paramError=0
1455 fi
1456 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1457 paramError=0
1458 fi
1459 if [ $# -ge 5 ]; then
1460 paramError=0
1461 fi
1462
1463 if [ $paramError -ne 0 ]; then
1464 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
1465 return 1
1466 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001467 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001468 query="/data-producer/v1/info-producers/$2"
1469 else
1470 query="/ei-producer/v1/eiproducers/$2"
1471 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001472 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001473 status=${res:${#res}-3}
1474
1475 if [ $status -ne $1 ]; then
1476 __log_test_fail_status_code $1 $status
1477 return 1
1478 fi
1479
1480 if [ $# -gt 2 ]; then
1481 body=${res:0:${#res}-3}
1482 targetJson="["
1483 if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
1484 arr=(${@:5})
1485 for ((i=0; i<$(($#-4)); i=i+1)); do
1486 if [ "$targetJson" != "[" ]; then
1487 targetJson=$targetJson","
1488 fi
1489 targetJson=$targetJson"\"${arr[$i]}\""
1490 done
1491 fi
1492 targetJson=$targetJson"]"
1493 if [ $# -gt 4 ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001494 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001495 targetJson="{\"supported_info_types\":$targetJson,\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\"}"
1496 else
1497 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1498 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001499 fi
1500 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1501 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1502
1503 if [ $res -ne 0 ]; then
1504 __log_test_fail_body
1505 return 1
1506 fi
1507 fi
1508
1509 __log_test_pass
1510 return 0
1511}
1512
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001513# API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001514# API Test function: DELETE /data-producer/v1/info-producers/{infoProducerId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001515# args: <response-code> <producer-id>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001516# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001517ics_api_edp_delete_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001518 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001519
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001520 if [ $# -lt 2 ]; then
1521 __print_err "<response-code> <producer-id>" $@
1522 return 1
1523 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001524 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001525 query="/data-producer/v1/info-producers/$2"
1526 else
1527 query="/ei-producer/v1/eiproducers/$2"
1528 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001529 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001530 status=${res:${#res}-3}
1531
1532 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001533 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001534 return 1
1535 fi
1536
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001537 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001538 return 0
1539}
1540
1541# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001542# args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001543# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001544ics_api_edp_put_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001545 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001546
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001547 #Valid number of parametrer 5,6,8,10,
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001548 paramError=1
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001549 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001550 paramError=0
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001551 elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001552 paramError=0
1553 fi
1554 if [ $paramError -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001555 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001556 return 1
1557 fi
1558
1559 inputJson="["
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001560 if [ $# -gt 5 ]; then
1561 arr=(${@:5})
1562 for ((i=0; i<$(($#-5)); i=i+2)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001563 if [ "$inputJson" != "[" ]; then
1564 inputJson=$inputJson","
1565 fi
1566 if [ -f ${arr[$i+1]} ]; then
1567 schema=$(cat ${arr[$i+1]})
1568 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001569 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001570 return 1
1571 fi
1572 inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1573 done
1574 fi
1575 inputJson="\"supported_ei_types\":"$inputJson"]"
1576
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001577 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001578
1579 inputJson="{"$inputJson"}"
1580
1581 file="./tmp/.p.json"
1582 echo "$inputJson" > $file
1583 query="/ei-producer/v1/eiproducers/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001584 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001585 status=${res:${#res}-3}
1586
1587 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001588 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001589 return 1
1590 fi
1591
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001592 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001593 return 0
1594}
1595
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001596# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001597# API Test function: PUT /data-producer/v1/info-producers/{infoProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001598# args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]
1599# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001600ics_api_edp_put_producer_2() {
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001601 __log_test_start $@
1602
1603 #Valid number of parametrer 5,6,8,10,
1604 paramError=1
1605 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1606 paramError=0
1607 elif [ $# -ge 5 ]; then
1608 paramError=0
1609 fi
1610 if [ $paramError -ne 0 ]; then
1611 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
1612 return 1
1613 fi
1614
1615 inputJson="["
1616 if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
1617 arr=(${@:5})
1618 for ((i=0; i<$(($#-4)); i=i+1)); do
1619 if [ "$inputJson" != "[" ]; then
1620 inputJson=$inputJson","
1621 fi
1622 inputJson=$inputJson"\""${arr[$i]}"\""
1623 done
1624 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001625 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001626 inputJson="\"supported_info_types\":"$inputJson"]"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001627
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001628 inputJson=$inputJson",\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\""
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001629
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001630 inputJson="{"$inputJson"}"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001631
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001632 file="./tmp/.p.json"
1633 echo "$inputJson" > $file
1634 query="/data-producer/v1/info-producers/$2"
1635 else
1636 inputJson="\"supported_ei_types\":"$inputJson"]"
1637
1638 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1639
1640 inputJson="{"$inputJson"}"
1641
1642 file="./tmp/.p.json"
1643 echo "$inputJson" > $file
1644 query="/ei-producer/v1/eiproducers/$2"
1645 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001646 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001647 status=${res:${#res}-3}
1648
1649 if [ $status -ne $1 ]; then
1650 __log_test_fail_status_code $1 $status
1651 return 1
1652 fi
1653
1654 __log_test_pass
1655 return 0
1656}
1657
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001658# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001659# 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 +02001660# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001661ics_api_edp_get_producer_jobs() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001662 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001663
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001664 #Valid number of parameter 2,3,7,11
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001665 paramError=1
1666 if [ $# -eq 2 ]; then
1667 paramError=0
1668 fi
1669 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1670 paramError=0
1671 fi
1672 variablecount=$(($#-2))
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001673 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001674 paramError=0
1675 fi
1676 if [ $paramError -eq 1 ]; then
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001677 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001678 return 1
1679 fi
1680
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001681 query="/ei-producer/v1/eiproducers/$2/eijobs"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001682 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001683 status=${res:${#res}-3}
1684 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001685 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001686 return 1
1687 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001688 if [ $# -gt 2 ]; then
1689 body=${res:0:${#res}-3}
1690 targetJson="["
1691 if [ $# -gt 3 ]; then
1692 arr=(${@:3})
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001693 for ((i=0; i<$(($#-3)); i=i+5)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001694 if [ "$targetJson" != "[" ]; then
1695 targetJson=$targetJson","
1696 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001697 if [ -f ${arr[$i+4]} ]; then
1698 jobfile=$(cat ${arr[$i+4]})
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001699 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1700 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001701 __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001702 return 1
1703 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001704 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 +02001705 done
1706 fi
1707 targetJson=$targetJson"]"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001708
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001709 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1710 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001711
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001712 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001713 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001714 return 1
1715 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001716 fi
1717
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001718 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001719 return 0
1720}
1721
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001722# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001723# API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/info-jobs
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001724# args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1725# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001726ics_api_edp_get_producer_jobs_2() {
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001727 __log_test_start $@
1728
1729 #Valid number of parameter 2,3,7,11
1730 paramError=1
1731 if [ $# -eq 2 ]; then
1732 paramError=0
1733 fi
1734 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1735 paramError=0
1736 fi
1737 variablecount=$(($#-2))
1738 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1739 paramError=0
1740 fi
1741 if [ $paramError -eq 1 ]; then
1742 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1743 return 1
1744 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001745 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001746 query="/data-producer/v1/info-producers/$2/info-jobs"
1747 else
1748 query="/ei-producer/v1/eiproducers/$2/eijobs"
1749 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001750 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001751 status=${res:${#res}-3}
1752 if [ $status -ne $1 ]; then
1753 __log_test_fail_status_code $1 $status
1754 return 1
1755 fi
1756 if [ $# -gt 2 ]; then
1757 body=${res:0:${#res}-3}
1758 targetJson="["
1759 if [ $# -gt 3 ]; then
1760 arr=(${@:3})
1761 for ((i=0; i<$(($#-3)); i=i+5)); do
1762 if [ "$targetJson" != "[" ]; then
1763 targetJson=$targetJson","
1764 fi
1765 if [ -f ${arr[$i+4]} ]; then
1766 jobfile=$(cat ${arr[$i+4]})
1767 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1768 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001769 __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001770 return 1
1771 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001772 if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001773 targetJson=$targetJson"{\"info_job_identity\":\"${arr[$i]}\",\"info_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"info_job_data\":$jobfile, \"last_updated\":\"????\"}"
1774 else
1775 targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"ei_job_data\":$jobfile, \"last_updated\":\"????\"}"
1776 fi
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001777 done
1778 fi
1779 targetJson=$targetJson"]"
1780
1781 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1782 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1783
1784 if [ $res -ne 0 ]; then
1785 __log_test_fail_body
1786 return 1
1787 fi
1788 fi
1789
1790 __log_test_pass
1791 return 0
1792}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001793
1794##########################################
1795#### Service status ####
1796##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001797# Function prefix: ics_api_service
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001798
1799# API Test function: GET ​/status
1800# args: <response-code>
1801# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001802ics_api_service_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001803 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001804
1805 if [ $# -lt 1 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001806 __print_err "<response-code>" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001807 return 1
1808 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001809 res="$(__do_curl_to_api ICS GET /status)"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001810 status=${res:${#res}-3}
1811 if [ $status -ne $1 ]; then
1812 __log_test_fail_status_code $1 $status
1813 return 1
1814 fi
1815 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001816 return 0
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001817}
1818
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001819###########################################
1820######### Info data consumer API ##########
1821###########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001822#Function prefix: ics_api_idc
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001823
1824
1825# API Test function: GET /data-consumer/v1/info-types
1826# args: <response-code> [ (EMPTY | [<type-id>]+) ]
1827# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001828ics_api_idc_get_type_ids() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001829 __log_test_start $@
1830
1831 if [ $# -lt 1 ]; then
1832 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
1833 return 1
1834 fi
1835
1836 query="/data-consumer/v1/info-types"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001837 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001838 status=${res:${#res}-3}
1839
1840 if [ $status -ne $1 ]; then
1841 __log_test_fail_status_code $1 $status
1842 return 1
1843 fi
1844 if [ $# -gt 1 ]; then
1845 body=${res:0:${#res}-3}
1846 targetJson="["
1847 if [ $2 != "EMPTY" ]; then
1848 for pid in ${@:2} ; do
1849 if [ "$targetJson" != "[" ]; then
1850 targetJson=$targetJson","
1851 fi
1852 targetJson=$targetJson"\"$pid\""
1853 done
1854 fi
1855 targetJson=$targetJson"]"
1856 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1857 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1858
1859 if [ $res -ne 0 ]; then
1860 __log_test_fail_body
1861 return 1
1862 fi
1863 fi
1864
1865 __log_test_pass
1866 return 0
1867}
1868
1869# API Test function: GET /data-consumer/v1/info-jobs
1870# args: <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
1871# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001872ics_api_idc_get_job_ids() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001873 __log_test_start $@
1874
1875 # Valid number of parameters 4,5,6 etc
1876 if [ $# -lt 3 ]; then
1877 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
1878 return 1
1879 fi
1880 search=""
1881 if [ $3 != "NOWNER" ]; then
1882 search="?owner="$3
1883 fi
1884
1885 if [ $2 != "NOTYPE" ]; then
1886 if [ -z "$search" ]; then
1887 search="?infoTypeId="$2
1888 else
1889 search=$search"&infoTypeId="$2
1890 fi
1891 fi
1892 query="/data-consumer/v1/info-jobs$search"
1893
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001894 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001895 status=${res:${#res}-3}
1896
1897 if [ $status -ne $1 ]; then
1898 __log_test_fail_status_code $1 $status
1899 return 1
1900 fi
1901
1902 if [ $# -gt 3 ]; then
1903 body=${res:0:${#res}-3}
1904 targetJson="["
1905
1906 for pid in ${@:4} ; do
1907 if [ "$targetJson" != "[" ]; then
1908 targetJson=$targetJson","
1909 fi
1910 if [ $pid != "EMPTY" ]; then
1911 targetJson=$targetJson"\"$pid\""
1912 fi
1913 done
1914
1915 targetJson=$targetJson"]"
1916 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1917 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1918
1919 if [ $res -ne 0 ]; then
1920 __log_test_fail_body
1921 return 1
1922 fi
1923 fi
1924
1925 __log_test_pass
1926 return 0
1927}
1928
1929# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}
1930# args: <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
1931# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001932ics_api_idc_get_job() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001933 __log_test_start $@
1934
1935 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
1936 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
1937 return 1
1938 fi
1939 query="/data-consumer/v1/info-jobs/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001940 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001941 status=${res:${#res}-3}
1942
1943 if [ $status -ne $1 ]; then
1944 __log_test_fail_status_code $1 $status
1945 return 1
1946 fi
1947
1948 if [ $# -eq 7 ]; then
1949 body=${res:0:${#res}-3}
1950
1951 if [ -f $7 ]; then
1952 jobfile=$(cat $7)
1953 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1954 else
1955 __log_test_fail_general "Job template file "$6", does not exist"
1956 return 1
1957 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001958 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 +02001959 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1960 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1961
1962 if [ $res -ne 0 ]; then
1963 __log_test_fail_body
1964 return 1
1965 fi
1966 fi
1967
1968 __log_test_pass
1969 return 0
1970}
1971
1972
1973# API Test function: PUT ​/data-consumer/v1/info-jobs/{infoJobId}
1974# args: <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]
1975# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01001976ics_api_idc_put_job() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001977 __log_test_start $@
1978
1979 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1980 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]" $@
1981 return 1
1982 fi
1983 if [ -f $7 ]; then
1984 jobfile=$(cat $7)
1985 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1986 else
1987 __log_test_fail_general "Job template file "$7", does not exist"
1988 return 1
1989 fi
1990
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001991 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 +02001992 file="./tmp/.p.json"
1993 echo "$inputJson" > $file
1994
1995 query="/data-consumer/v1/info-jobs/$2"
1996
1997 if [ $# -eq 8 ]; then
1998 if [ $8 == "VALIDATE" ]; then
1999 query=$query"?typeCheck=true"
2000 fi
2001 fi
2002
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002003 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002004 status=${res:${#res}-3}
2005
2006 if [ $status -ne $1 ]; then
2007 __log_test_fail_status_code $1 $status
2008 return 1
2009 fi
2010
2011 __log_test_pass
2012 return 0
2013}
2014
2015# API Test function: DELETE ​/data-consumer/v1/info-jobs/{infoJobId}
2016# args: <response-code> <job-id>
2017# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002018ics_api_idc_delete_job() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002019 __log_test_start $@
2020
2021 if [ $# -ne 2 ]; then
2022 __print_err "<response-code> <job-id>" $@
2023 return 1
2024 fi
2025 query="/data-consumer/v1/info-jobs/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002026 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002027 status=${res:${#res}-3}
2028
2029 if [ $status -ne $1 ]; then
2030 __log_test_fail_status_code $1 $status
2031 return 1
2032 fi
2033
2034 __log_test_pass
2035 return 0
2036}
2037
2038# API Test function: GET ​/data-consumer/v1/info-types/{infoTypeId}
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002039# args: <response-code> <type-id> [<schema-file> [<type-status> <producers-count]]
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002040# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002041ics_api_idc_get_type() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002042 __log_test_start $@
2043
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002044 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
2045 __print_err "<response-code> <type-id> [<schema-file> [<type-status> <producers-count]]" $@
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002046 return 1
2047 fi
2048
2049 query="/data-consumer/v1/info-types/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002050 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002051 status=${res:${#res}-3}
2052
2053 if [ $status -ne $1 ]; then
2054 __log_test_fail_status_code $1 $status
2055 return 1
2056 fi
2057
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002058 if [ $# -gt 2 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002059 body=${res:0:${#res}-3}
2060 if [ -f $3 ]; then
2061 schema=$(cat $3)
2062 else
2063 __log_test_fail_general "Schema file "$3", does not exist"
2064 return 1
2065 fi
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002066 if [ $# -eq 5 ]; then
2067 targetJson="{\"job_data_schema\":$schema, \"type_status\":\"$4\", \"no_of_producers\":$5}"
2068 else
2069 targetJson="{\"job_data_schema\":$schema}"
2070 fi
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002071 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2072 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2073
2074 if [ $res -ne 0 ]; then
2075 __log_test_fail_body
2076 return 1
2077 fi
2078 fi
2079
2080 __log_test_pass
2081 return 0
2082}
2083
2084# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002085# This test only status during an optional timeout. No test of the list of producers
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002086# args: <response-code> <job-id> [<status> [<timeout>]]
2087# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002088ics_api_idc_get_job_status() {
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002089 __log_test_start $@
2090
2091 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
2092 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
2093 return 1
2094 fi
2095
2096 query="/data-consumer/v1/info-jobs/$2/status"
2097
2098 start=$SECONDS
2099 for (( ; ; )); do
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002100 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002101 status=${res:${#res}-3}
2102
2103 if [ $# -eq 4 ]; then
2104 duration=$((SECONDS-start))
2105 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2106 if [ $duration -gt $4 ]; then
2107 echo ""
2108 duration=-1 #Last iteration
2109 fi
2110 else
2111 duration=-1 #single test, no wait
2112 fi
2113
2114 if [ $status -ne $1 ]; then
2115 if [ $duration -eq -1 ]; then
2116 __log_test_fail_status_code $1 $status
2117 return 1
2118 fi
2119 fi
2120 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
2121 body=${res:0:${#res}-3}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02002122 targetJson="{\"info_job_status\": \"$3\"}"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002123 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2124 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2125
2126 if [ $res -ne 0 ]; then
2127 if [ $duration -eq -1 ]; then
2128 __log_test_fail_body
2129 return 1
2130 fi
2131 else
2132 duration=-1 #Goto pass
2133 fi
2134 fi
2135 if [ $duration -eq -1 ]; then
2136 if [ $# -eq 4 ]; then
2137 echo ""
2138 fi
2139 __log_test_pass
2140 return 0
2141 else
2142 sleep 1
2143 fi
2144 done
2145
2146 __log_test_pass
2147 return 0
2148}
2149
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002150# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
2151# This function test status and the list of producers with and optional timeout
2152# args: <response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]
2153# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002154ics_api_idc_get_job_status2() {
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002155
2156 __log_test_start $@
2157 param_error=0
2158 if [ $# -lt 2 ]; then
2159 param_error=1
2160 fi
2161 args=("$@")
2162 timeout=0
2163 if [ $# -gt 2 ]; then
2164 if [ $# -lt 4 ]; then
2165 param_error=1
2166 fi
2167 targetJson="{\"info_job_status\": \"$3\""
2168 if [ "$4" == "EMPTYPROD" ]; then
2169 targetJson=$targetJson",\"producers\": []}"
2170 if [ $# -gt 4 ]; then
2171 timeout=$5
2172 fi
2173 else
2174 targetJson=$targetJson",\"producers\": ["
2175 if [ $# -eq $(($4+5)) ]; then
2176 idx=$(($4+4))
2177 timeout=${args[$idx]}
2178 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002179 for ((ics_i = 0 ; ics_i < $4 ; ics_i++)); do
2180 idx=$(($ics_i+4))
2181 if [ $ics_i -gt 0 ]; then
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002182 targetJson=$targetJson","
2183 fi
2184 targetJson=$targetJson"\""${args[$idx]}"\""
2185 done
2186 targetJson=$targetJson"]}"
2187 fi
2188 fi
2189
2190 if [ $param_error -ne 0 ]; then
2191 __print_err "<response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]" $@
2192 return 1
2193 fi
2194
2195 query="/data-consumer/v1/info-jobs/$2/status"
2196
2197 start=$SECONDS
2198 for (( ; ; )); do
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002199 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002200 status=${res:${#res}-3}
2201
2202 if [ $# -gt 2 ]; then
2203 duration=$((SECONDS-start))
2204 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2205 if [ $duration -gt $timeout ]; then
2206 echo ""
2207 duration=-1 #Last iteration
2208 fi
2209 else
2210 duration=-1 #single test, no wait
2211 fi
2212
2213 if [ $status -ne $1 ]; then
2214 if [ $duration -eq -1 ]; then
2215 __log_test_fail_status_code $1 $status
2216 return 1
2217 fi
2218 fi
2219 if [ $# -gt 2 ] && [ $status -eq $1 ]; then
2220 body=${res:0:${#res}-3}
2221 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2222 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2223
2224 if [ $res -ne 0 ]; then
2225 if [ $duration -eq -1 ]; then
2226 __log_test_fail_body
2227 return 1
2228 fi
2229 else
2230 duration=-1 #Goto pass
2231 fi
2232 fi
2233 if [ $duration -eq -1 ]; then
2234 if [ $# -eq 4 ]; then
2235 echo ""
2236 fi
2237 __log_test_pass
2238 return 0
2239 else
2240 sleep 1
2241 fi
2242 done
2243
2244 __log_test_pass
2245 return 0
2246}
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002247
2248##########################################
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002249#### Type subscriptions ####
2250##########################################
2251
2252# API Test function: GET /data-consumer/v1/info-type-subscription
2253# args: <response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]
2254# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002255ics_api_idc_get_subscription_ids() {
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002256 __log_test_start $@
2257
2258 if [ $# -lt 3 ]; then
2259 __print_err "<response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]" $@
2260 return 1
2261 fi
2262
2263 query="/data-consumer/v1/info-type-subscription"
2264 search=""
2265 if [ $2 != "NOOWNER" ]; then
2266 search="?owner="$2
2267 fi
2268
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002269 res="$(__do_curl_to_api ICS GET $query$search)"
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002270 status=${res:${#res}-3}
2271
2272 if [ $status -ne $1 ]; then
2273 __log_test_fail_status_code $1 $status
2274 return 1
2275 fi
2276
2277 if [ $# -gt 2 ]; then
2278 body=${res:0:${#res}-3}
2279 targetJson="["
2280 if [ $3 != "EMPTY" ]; then
2281 for pid in ${@:3} ; do
2282 if [ "$targetJson" != "[" ]; then
2283 targetJson=$targetJson","
2284 fi
2285 targetJson=$targetJson"\"$pid\""
2286 done
2287 fi
2288 targetJson=$targetJson"]"
2289 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2290 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2291
2292 if [ $res -ne 0 ]; then
2293 __log_test_fail_body
2294 return 1
2295 fi
2296 fi
2297
2298 __log_test_pass
2299 return 0
2300}
2301
2302# API Test function: GET /data-consumer/v1/info-type-subscription/{subscriptionId}
2303# args: <response-code> <subscription-id> [ <owner-id> <status-uri> ]
2304# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002305ics_api_idc_get_subscription() {
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002306 __log_test_start $@
2307
2308 if [ $# -ne 2 ] && [ $# -ne 4 ]; then
2309 __print_err "<response-code> <subscription-id> [ <owner-id> <status-uri> ]" $@
2310 return 1
2311 fi
2312
2313 query="/data-consumer/v1/info-type-subscription/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002314 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002315 status=${res:${#res}-3}
2316
2317 if [ $status -ne $1 ]; then
2318 __log_test_fail_status_code $1 $status
2319 return 1
2320 fi
2321
2322 if [ $# -gt 2 ]; then
2323 body=${res:0:${#res}-3}
2324 targetJson="{\"owner\":\"$3\",\"status_result_uri\":\"$4\"}"
2325 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2326 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2327
2328 if [ $res -ne 0 ]; then
2329 __log_test_fail_body
2330 return 1
2331 fi
2332 fi
2333
2334 __log_test_pass
2335 return 0
2336}
2337
2338# API Test function: PUT /data-consumer/v1/info-type-subscription/{subscriptionId}
2339# args: <response-code> <subscription-id> <owner-id> <status-uri>
2340# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002341ics_api_idc_put_subscription() {
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002342 __log_test_start $@
2343
2344 if [ $# -ne 4 ]; then
2345 __print_err "<response-code> <subscription-id> <owner-id> <status-uri>" $@
2346 return 1
2347 fi
2348
2349 inputJson="{\"owner\": \"$3\",\"status_result_uri\": \"$4\"}"
2350 file="./tmp/.p.json"
2351 echo "$inputJson" > $file
2352
2353 query="/data-consumer/v1/info-type-subscription/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002354 res="$(__do_curl_to_api ICS PUT $query $file)"
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002355 status=${res:${#res}-3}
2356
2357 if [ $status -ne $1 ]; then
2358 __log_test_fail_status_code $1 $status
2359 return 1
2360 fi
2361
2362 __log_test_pass
2363 return 0
2364}
2365
2366# API Test function: DELETE /data-consumer/v1/info-type-subscription/{subscriptionId}
2367# args: <response-code> <subscription-id>
2368# (Function for test scripts)
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002369ics_api_idc_delete_subscription() {
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002370 __log_test_start $@
2371
2372 if [ $# -ne 2 ]; then
2373 __print_err "<response-code> <subscription-id> " $@
2374 return 1
2375 fi
2376
2377 query="/data-consumer/v1/info-type-subscription/$2"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002378 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXA3cc0b582021-08-30 10:46:41 +02002379 status=${res:${#res}-3}
2380
2381 if [ $status -ne $1 ]; then
2382 __log_test_fail_status_code $1 $status
2383 return 1
2384 fi
2385
2386 __log_test_pass
2387 return 0
2388}
2389
2390##########################################
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002391#### Reset jobs ####
2392##########################################
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002393# Function prefix: ics_api_admin
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002394
2395# Admin to remove all jobs
BjornMagnussonXA366e36a2021-01-27 11:48:56 +01002396# args: <response-code> [ <type> ]
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002397# (Function for test scripts)
2398
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002399ics_api_admin_reset() {
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002400 __log_test_start $@
2401
2402 if [ -z "$FLAT_A1_EI" ]; then
2403 query="/A1-EI/v1/eitypes/$2/eijobs"
2404 else
2405 query="/A1-EI/v1/eijobs"
2406 fi
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002407 res="$(__do_curl_to_api ICS GET $query)"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002408 status=${res:${#res}-3}
2409
2410 if [ $status -ne 200 ]; then
2411 __log_test_fail_status_code $1 $status
2412 return 1
2413 fi
2414
2415 #Remove brackets and response code
2416 body=${res:1:${#res}-4}
2417 list=$(echo ${body//,/ })
2418 list=$(echo ${list//[/})
2419 list=$(echo ${list//]/})
2420 list=$(echo ${list//\"/})
2421 list=$list" "
2422 for job in $list; do
2423 if [ -z "$FLAT_A1_EI" ]; then
2424 echo "Not supported for non-flat EI api"
2425 else
2426 query="/A1-EI/v1/eijobs/$job"
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002427 res="$(__do_curl_to_api ICS DELETE $query)"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002428 status=${res:${#res}-3}
2429 if [ $status -ne 204 ]; then
2430 __log_test_fail_status_code $1 $status
2431 return 1
2432 fi
2433 echo " Deleted job: "$job
2434 fi
2435 done
2436
2437 __log_test_pass
2438 return 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002439}
2440
2441##########################################
2442#### Reset jobs and producers ####
2443##########################################
2444
2445
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002446# Admin reset to remove all data in ics; jobs, producers etc
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002447# NOTE - only works in kubernetes and the pod should not be running
2448# args: -
2449# (Function for test scripts)
2450
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002451ics_kube_pvc_reset() {
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002452 __log_test_start $@
2453
BjornMagnussonXAcb6113e2022-02-17 15:01:28 +01002454 pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep information)
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +02002455 if [ -z "$pvc_name" ]; then
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002456 pvc_name=informationservice-pvc
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +02002457 fi
2458 echo " Trying to reset pvc: "$pvc_name
2459
BjornMagnussonXA007b6452021-11-29 08:03:38 +01002460 __kube_clean_pvc $ICS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $ICS_CONTAINER_MNT_DIR
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002461
2462 __log_test_pass
2463 return 0
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002464}