blob: a1fd657712a7c31cace9bce73ca86576330f98a6 [file] [log] [blame]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001#!/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
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +010020# This is a script that contains management and test functions for Policy Agent
BjornMagnussonXA80a92002020-03-19 14:31:06 +010021
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
27__PA_imagesetup() {
28 __check_and_create_image_var PA "POLICY_AGENT_IMAGE" "POLICY_AGENT_IMAGE_BASE" "POLICY_AGENT_IMAGE_TAG" $1 "$POLICY_AGENT_DISPLAY_NAME"
29}
30
31# Pull image from remote repo or use locally built image
32# arg: <pull-policy-override> <pull-policy-original>
33# <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
34# <pull-policy-original> Shall be used for images that does not allow overriding
35# Both var may contain: 'remote', 'remote-remove' or 'local'
36__PA_imagepull() {
BjornMagnussonXA483ee332021-04-08 01:35:24 +020037 __check_and_pull_image $1 "$POLICY_AGENT_DISPLAY_NAME" $POLICY_AGENT_APP_NAME POLICY_AGENT_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
43__PA_imagebuild() {
44 echo -e $RED" Image for app PA shall never be built"$ERED
45}
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>
50__PA_image_data() {
51 echo -e "$POLICY_AGENT_DISPLAY_NAME\t$(docker images --format $1 $POLICY_AGENT_IMAGE)" >> $2
BjornMagnussonXA483ee332021-04-08 01:35:24 +020052 if [ ! -z "$POLICY_AGENT_IMAGE_SOURCE" ]; then
53 echo -e "-- source image --\t$(docker images --format $1 $POLICY_AGENT_IMAGE_SOURCE)" >> $2
54 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
60__PA_kube_scale_zero() {
61 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
62}
63
64# Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
65# This function is called for prestarted apps not managed by the test script.
66__PA_kube_scale_zero_and_wait() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +010067 __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app "$KUBE_NONRTRIC_NAMESPACE"-policymanagementservice
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.
72__PA_kube_delete_all() {
73 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
74}
75
76# Store docker logs
77# This function is called for apps managed by the test script.
78# args: <log-dir> <file-prexix>
79__PA_store_docker_logs() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +010080 if [ $RUNMODE == "KUBE" ]; then
81 kubectl logs -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE --tail=-1 > $1$2_policy-agent.log 2>&1
82 else
83 docker logs $POLICY_AGENT_APP_NAME > $1$2_policy-agent.log 2>&1
84 fi
85}
86
87# Initial setup of protocol, host and ports
88# This function is called for apps managed by the test script.
89# args: -
90__PA_initial_setup() {
91 use_agent_rest_http
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010092}
93
94#######################################################
BjornMagnussonXA80a92002020-03-19 14:31:06 +010095
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +010096###########################
97### Policy Agents functions
98###########################
99
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100100# Set http as the protocol to use for all communication to the Policy Agent
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100101# args: -
102# (Function for test scripts)
103use_agent_rest_http() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100104 __agent_set_protocoll "http" $POLICY_AGENT_INTERNAL_PORT $POLICY_AGENT_EXTERNAL_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100105}
106
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100107# Set https as the protocol to use for all communication to the Policy Agent
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100108# args: -
109# (Function for test scripts)
110use_agent_rest_https() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100111 __agent_set_protocoll "https" $POLICY_AGENT_INTERNAL_SECURE_PORT $POLICY_AGENT_EXTERNAL_SECURE_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100112}
113
114# All calls to the agent will be directed to the agent dmaap interface over http from now on
115# args: -
116# (Function for test scripts)
117use_agent_dmaap_http() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100118 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME dmaap protocol setting"$EBOLD
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100119 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
120 PA_ADAPTER_TYPE="MR-HTTP"
121 echo ""
122}
123
124# All calls to the agent will be directed to the agent dmaap interface over https from now on
125# args: -
126# (Function for test scripts)
127use_agent_dmaap_https() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100128 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME dmaap protocol setting"$EBOLD
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100129 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
130 echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
131 PA_ADAPTER_TYPE="MR-HTTPS"
132 echo ""
133}
134
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100135# Setup paths to svc/container for internal and external access
136# args: <protocol> <internal-port> <external-port>
137__agent_set_protocoll() {
138 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME protocol setting"$EBOLD
139 echo -e " Using $BOLD http $EBOLD towards $POLICY_AGENT_DISPLAY_NAME"
140
141 ## Access to Dmaap adapter
142
143 PA_SERVICE_PATH=$1"://"$POLICY_AGENT_APP_NAME":"$2 # docker access, container->container and script->container via proxy
144 if [ $RUNMODE == "KUBE" ]; then
145 PA_SERVICE_PATH=$1"://"$POLICY_AGENT_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
146 fi
147
148 # PA_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
149 PA_ADAPTER_TYPE="REST"
150 PA_ADAPTER=$PA_SERVICE_PATH
151
152 echo ""
153}
154
155# Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
156AGENT_RETRY_CODES=""
157
158#Save first worker node the pod is started on
159__PA_WORKER_NODE=""
160
161# Export env vars for config files, docker compose and kube resources
162# args: PROXY|NOPROXY
163__export_agent_vars() {
164
165 export POLICY_AGENT_APP_NAME
166 export POLICY_AGENT_APP_NAME_ALIAS
167 export POLICY_AGENT_DISPLAY_NAME
168
169 export KUBE_NONRTRIC_NAMESPACE
170 export POLICY_AGENT_IMAGE
171 export POLICY_AGENT_INTERNAL_PORT
172 export POLICY_AGENT_INTERNAL_SECURE_PORT
173 export POLICY_AGENT_EXTERNAL_PORT
174 export POLICY_AGENT_EXTERNAL_SECURE_PORT
175 export POLICY_AGENT_CONFIG_MOUNT_PATH
176 export POLICY_AGENT_DATA_MOUNT_PATH
177 export POLICY_AGENT_CONFIG_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-config"
178 export POLICY_AGENT_DATA_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-data"
179 export POLICY_AGENT_PKG_NAME
180 export CONSUL_HOST
181 export CONSUL_INTERNAL_PORT
182 export CONFIG_BINDING_SERVICE
183 export POLICY_AGENT_CONFIG_KEY
184 export DOCKER_SIM_NWNAME
185 export POLICY_AGENT_HOST_MNT_DIR
186 export POLICY_AGENT_CONFIG_FILE
187
188 export POLICY_AGENT_DATA_PV_NAME=$POLICY_AGENT_APP_NAME"-pv"
189 export POLICY_AGENT_DATA_PVC_NAME=$POLICY_AGENT_APP_NAME"-pvc"
190 ##Create a unique path for the pv each time to prevent a previous volume to be reused
191 export POLICY_AGENT_PV_PATH="padata-"$(date +%s)
192 export POLICY_AGENT_CONTAINER_MNT_DIR
193
194 if [ $1 == "PROXY" ]; then
195 export AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
196 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
197 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
198 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
199 else
200 echo " Configured with http proxy"
201 fi
202 else
203 export AGENT_HTTP_PROXY_CONFIG_PORT=0
204 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
205 echo " Configured without http proxy"
206 fi
207}
208
209
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100210# Start the policy agent
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100211# args: (docker) PROXY|NOPROXY <config-file>
212# args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100213# (Function for test scripts)
214start_policy_agent() {
215 echo -e $BOLD"Starting $POLICY_AGENT_DISPLAY_NAME"$EBOLD
216
217 if [ $RUNMODE == "KUBE" ]; then
218
219 # Check if app shall be fully managed by the test script
220 __check_included_image "PA"
221 retcode_i=$?
222
223 # Check if app shall only be used by the testscipt
224 __check_prestarted_image "PA"
225 retcode_p=$?
226
227 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
228 echo -e $RED"The $POLICY_AGENT_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
229 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
230 exit
231 fi
232 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
233 echo -e $RED"The $POLICY_AGENT_APP_NAME app is included both as managed and prestarted in this test script"$ERED
234 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
235 exit
236 fi
237
238 if [ $retcode_p -eq 0 ]; then
239 echo -e " Using existing $POLICY_AGENT_APP_NAME deployment and service"
240 echo " Setting $POLICY_AGENT_APP_NAME replicas=1"
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +0200241 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
242 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100243 fi
244
245 if [ $retcode_i -eq 0 ]; then
246
247 echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
248
249 #Check if nonrtric namespace exists, if not create it
250 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
251
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100252 __export_agent_vars $1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100253
254 # Create config map for config
255 configfile=$PWD/tmp/$POLICY_AGENT_CONFIG_FILE
256 cp $2 $configfile
257 output_yaml=$PWD/tmp/pa_cfc.yaml
258 __kube_create_configmap $POLICY_AGENT_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $configfile $output_yaml
259
260 # Create config map for data
261 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
262 if [ $# -lt 3 ]; then
263 #create empty dummy file
264 echo "{}" > $data_json
265 else
266 cp $3 $data_json
267 fi
268 output_yaml=$PWD/tmp/pa_cfd.yaml
269 __kube_create_configmap $POLICY_AGENT_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
270
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200271 ## Create pv
272 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pv.yaml
273 output_yaml=$PWD/tmp/pa_pv.yaml
274 __kube_create_instance pv $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
275
276 ## Create pvc
277 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pvc.yaml
278 output_yaml=$PWD/tmp/pa_pvc.yaml
279 __kube_create_instance pvc $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
280
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100281 # Create service
282 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"svc.yaml
283 output_yaml=$PWD/tmp/pa_svc.yaml
284 __kube_create_instance service $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
285
286 # Create app
287 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"app.yaml
288 output_yaml=$PWD/tmp/pa_app.yaml
289 __kube_create_instance app $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
290
291 fi
292
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200293 # 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 +0200294 if [ $retcode_i -eq 0 ]; then
295 __PA_WORKER_NODE=$(kubectl get pod -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
296 if [ -z "$__PA_WORKER_NODE" ]; then
297 echo -e $YELLOW" Cannot find worker node for pod for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
298 fi
299 else
300 echo -e $YELLOW" Persistency may not work for app $POLICY_AGENT_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200301 fi
302
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100303 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100304
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100305 else
306 __check_included_image 'PA'
307 if [ $? -eq 1 ]; then
308 echo -e $RED"The Policy Agent app is not included in this test script"$ERED
309 echo -e $RED"The Policy Agent will not be started"$ERED
310 exit
311 fi
312
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200313 curdir=$PWD
314 cd $SIM_GROUP
315 cd policy_agent
316 cd $POLICY_AGENT_HOST_MNT_DIR
317 #cd ..
318 if [ -d db ]; then
319 if [ "$(ls -A $DIR)" ]; then
320 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
321 rm -rf db/* &> /dev/null
322 if [ $? -ne 0 ]; then
323 echo -e $RED" Cannot remove database files in: $PWD"$ERED
324 exit 1
325 fi
326 fi
327 else
328 echo " No files in mounted dir or dir does not exists"
329 fi
330 cd $curdir
331
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100332 __export_agent_vars $1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100333
334 dest_file=$SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_HOST_MNT_DIR/application.yaml
335
336 envsubst < $2 > $dest_file
337
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100338 __start_container $POLICY_AGENT_COMPOSE_DIR "" NODOCKERARGS 1 $POLICY_AGENT_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100339
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100340 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100341 fi
342 echo ""
343 return 0
344}
345
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200346# Stop the policy agent
347# args: -
348# args: -
349# (Function for test scripts)
350stop_policy_agent() {
351 echo -e $BOLD"Stopping $POLICY_AGENT_DISPLAY_NAME"$EBOLD
352
353 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200354
355 __check_prestarted_image "PA"
356 if [ $? -eq 0 ]; then
357 echo -e $YELLOW" Persistency may not work for app $POLICY_AGENT_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +0200358 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
359 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200360 return 0
361 fi
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200362 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
363 echo " Deleting the replica set - a new will be started when the app is started"
364 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
365 if [ $? -ne 0 ]; then
366 echo -e $RED" Could not delete replica set "$RED
367 ((RES_CONF_FAIL++))
368 return 1
369 fi
370 else
371 docker stop $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
372 if [ $? -ne 0 ]; then
373 __print_err "Could not stop $POLICY_AGENT_APP_NAME" $@
374 cat ./tmp/.dockererr
375 ((RES_CONF_FAIL++))
376 return 1
377 fi
378 fi
379 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
380 echo ""
381 return 0
382}
383
384# Start a previously stopped policy agent
385# args: -
386# (Function for test scripts)
387start_stopped_policy_agent() {
388 echo -e $BOLD"Starting (the previously stopped) $POLICY_AGENT_DISPLAY_NAME"$EBOLD
389
390 if [ $RUNMODE == "KUBE" ]; then
391
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200392 __check_prestarted_image "PA"
393 if [ $? -eq 0 ]; then
394 echo -e $YELLOW" Persistency may not work for app $POLICY_AGENT_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +0200395 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
396 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100397 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200398 return 0
399 fi
400
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200401 # Tie the PMS to the same worker node it was initially started on
402 # A PVC of type hostPath is mounted to PMS, for persistent storage, so the PMS must always be on the node which mounted the volume
403 if [ -z "$__PA_WORKER_NODE" ]; then
404 echo -e $RED" No initial worker node found for pod "$RED
405 ((RES_CONF_FAIL++))
406 return 1
407 else
408 echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__PA_WORKER_NODE to deployment for $POLICY_AGENT_APP_NAME. Pod will always run on this worker node: $__PA_WORKER_NODE"$BOLD
409 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
410 tmp=$(kubectl patch deployment $POLICY_AGENT_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__PA_WORKER_NODE'"}}}}}')
411 if [ $? -ne 0 ]; then
412 echo -e $YELLOW" Cannot set nodeSelector to deployment for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
413 fi
414 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
415 fi
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200416 else
417 docker start $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
418 if [ $? -ne 0 ]; then
419 __print_err "Could not start (the stopped) $POLICY_AGENT_APP_NAME" $@
420 cat ./tmp/.dockererr
421 ((RES_CONF_FAIL++))
422 return 1
423 fi
424 fi
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100425 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200426 if [ $? -ne 0 ]; then
427 return 1
428 fi
429 echo ""
430 return 0
431}
432
433
434
BjornMagnussonXA366e36a2021-01-27 11:48:56 +0100435# Load the the appl config for the agent into a config map
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100436agent_load_config() {
437 echo -e $BOLD"Agent - load config from "$EBOLD$1
438 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
439 cp $1 $data_json
440 output_yaml=$PWD/tmp/pa_cfd.yaml
441 __kube_create_configmap $POLICY_AGENT_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100442 echo ""
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100443}
444
445
446# Turn on debug level tracing in the agent
447# args: -
448# (Function for test scripts)
449set_agent_debug() {
450 echo -e $BOLD"Setting agent debug logging"$EBOLD
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100451 curlString="$PA_SERVICE_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100452 result=$(__do_curl "$curlString")
453 if [ $? -ne 0 ]; then
454 __print_err "could not set debug mode" $@
455 ((RES_CONF_FAIL++))
456 return 1
457 fi
458 echo ""
459 return 0
460}
461
462# Turn on trace level tracing in the agent
463# args: -
464# (Function for test scripts)
465set_agent_trace() {
466 echo -e $BOLD"Setting agent trace logging"$EBOLD
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100467 curlString="$PA_SERVICE_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100468 result=$(__do_curl "$curlString")
469 if [ $? -ne 0 ]; then
470 __print_err "could not set trace mode" $@
471 ((RES_CONF_FAIL++))
472 return 1
473 fi
474 echo ""
475 return 0
476}
477
478# Perform curl retries when making direct call to the agent for the specified http response codes
479# Speace separated list of http response codes
480# args: [<response-code>]*
481use_agent_retries() {
482 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
483 AGENT_RETRY_CODES=$@
484 echo ""
485 return
486}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100487
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100488# Check the agent logs for WARNINGs and ERRORs
489# args: -
490# (Function for test scripts)
491check_policy_agent_logs() {
492 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
493}
494
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100495#########################################################
496#### Test case functions A1 Policy management service
497#########################################################
498
499# This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
500# This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
501# args: json:<url> <target-value> [<timeout-in-seconds]
502# (Function for test scripts)
503api_equal() {
504 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
505 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
506 if [[ $1 == "json:"* ]]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100507 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100508 __var_test "Policy Agent" $PA_SERVICE_PATH$PMS_API_PREFIX"/v2/" $1 "=" $2 $3
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100509 else
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100510 __var_test "Policy Agent" $PA_SERVICE_PATH"/" $1 "=" $2 $3
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100511 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100512 return 0
513 fi
514 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100515 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
516 return 1
517}
518
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100519# API Test function: GET /policies and V2 GET /v2/policy-instances
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100520# args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <template-file>]*]
521# args(V2): <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <transient> <notification-url> <template-file>]*]
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100522# (Function for test scripts)
523api_get_policies() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100524 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100525
526 if [ "$PMS_VERSION" == "V2" ]; then
527 paramError=0
528 variableParams=$(($#-4))
529 if [ $# -lt 4 ]; then
530 paramError=1
531 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
532 paramError=1
533 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
534 paramError=1
535 fi
536
537 if [ $paramError -ne 0 ]; then
538 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <transient> <notification-url> <template-file>]*]" $@
539 return 1
540 fi
541 else
542 paramError=0
543 variableParams=$(($#-4))
544 if [ $# -lt 4 ]; then
545 paramError=1
546 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
547 paramError=1
548 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
549 paramError=1
550 fi
551
552 if [ $paramError -ne 0 ]; then
553 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <template-file>]*]" $@
554 return 1
555 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100556 fi
557
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100558 queryparams=""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100559 if [ "$PMS_VERSION" == "V2" ]; then
560 if [ $2 != "NORIC" ]; then
561 queryparams="?ric_id="$2
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100562 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100563 if [ $3 != "NOSERVICE" ]; then
564 if [ -z $queryparams ]; then
565 queryparams="?service_id="$3
566 else
567 queryparams=$queryparams"&service_id="$3
568 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100569 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100570 if [ $4 != "NOTYPE" ]; then
571 if [ -z $queryparams ]; then
572 queryparams="?policytype_id="$4
573 else
574 queryparams=$queryparams"&policytype_id="$4
575 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100576 fi
577
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100578 query="/v2/policy-instances"$queryparams
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100579 res="$(__do_curl_to_api PA GET $query)"
580 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100581
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100582 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100583 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100584 return 1
585 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100586
587 if [ $# -gt 4 ]; then
588 body=${res:0:${#res}-3}
589 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
590 targetJson="["
591 else
592 targetJson="["
593 arr=(${@:5})
594
595 for ((i=0; i<$(($#-4)); i=i+7)); do
596
597 if [ "$targetJson" != "[" ]; then
598 targetJson=$targetJson","
599 fi
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100600 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100601 if [ "${arr[$i+3]}" == "EMPTY" ]; then
602 targetJson=$targetJson"\"\","
603 else
604 targetJson=$targetJson"\"${arr[$i+3]}\","
605 fi
606 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
607 file="./tmp/.p.json"
608 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
609 json=$(cat $file)
610 targetJson=$targetJson"\"policy_data\":"$json"}"
611 done
612 fi
613
614 targetJson=$targetJson"]"
615 targetJson="{\"policies\": $targetJson}"
616 echo "TARGET JSON: $targetJson" >> $HTTPLOG
617 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
618
619 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100620 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100621 return 1
622 fi
623 fi
624 else
625 if [ $2 != "NORIC" ]; then
626 queryparams="?ric="$2
627 fi
628 if [ $3 != "NOSERVICE" ]; then
629 if [ -z $queryparams ]; then
630 queryparams="?service="$3
631 else
632 queryparams=$queryparams"&service="$3
633 fi
634 fi
635 if [ $4 != "NOTYPE" ]; then
636 if [ -z $queryparams ]; then
637 queryparams="?type="$4
638 else
639 queryparams=$queryparams"&type="$4
640 fi
641 fi
642
643 query="/policies"$queryparams
644 res="$(__do_curl_to_api PA GET $query)"
645 status=${res:${#res}-3}
646
647 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100648 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100649 return 1
650 fi
651
652 if [ $# -gt 4 ]; then
653 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
654 targetJson="["
655 else
656 body=${res:0:${#res}-3}
657 targetJson="["
658 arr=(${@:5})
659
660 for ((i=0; i<$(($#-4)); i=i+5)); do
661
662 if [ "$targetJson" != "[" ]; then
663 targetJson=$targetJson","
664 fi
665 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
666 if [ "${arr[$i+3]}" == "EMPTY" ]; then
667 targetJson=$targetJson"\"\","
668 else
669 targetJson=$targetJson"\"${arr[$i+3]}\","
670 fi
671 file="./tmp/.p.json"
672 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
673 json=$(cat $file)
674 targetJson=$targetJson"\"json\":"$json"}"
675 done
676 fi
677
678 targetJson=$targetJson"]"
679 echo "TARGET JSON: $targetJson" >> $HTTPLOG
680 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
681
682 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100683 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100684 return 1
685 fi
686 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100687 fi
688
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100689 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100690 return 0
691
692}
693
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100694
695# API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
696# args: <response-code> <policy-id> [<template-file>]
697# args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
698
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100699# (Function for test scripts)
700api_get_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100701 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100702
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100703
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100704 if [ "$PMS_VERSION" == "V2" ]; then
705 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
706 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
707 return 1
708 fi
709 query="/v2/policies/$UUID$2"
710 else
711 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
712 __print_err "<response-code> <policy-id> [<template-file>] " $@
713 return 1
714 fi
715 query="/policy?id=$UUID$2"
716 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200717 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100718 status=${res:${#res}-3}
719
720 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100721 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100722 return 1
723 fi
724
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100725 if [ "$PMS_VERSION" == "V2" ]; then
726 if [ $# -eq 8 ]; then
727
728 #Create a policy json to compare with
729 body=${res:0:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100730
731 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
732 if [ $7 != "NOTRANSIENT" ]; then
733 targetJson=$targetJson", \"transient\":$7"
734 fi
735 if [ $6 != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100736 targetJson=$targetJson", \"policytype_id\":\"$6\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100737 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100738 targetJson=$targetJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100739 fi
740 if [ $8 != "NOURL" ]; then
741 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
742 fi
743
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100744 data=$(sed 's/XXX/'${2}'/g' $3)
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100745 targetJson=$targetJson", \"policy_data\":$data"
746 targetJson="{$targetJson}"
747
748 echo "TARGET JSON: $targetJson" >> $HTTPLOG
749 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
750 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100751 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100752 return 1
753 fi
754 fi
755 else
756 if [ $# -eq 3 ]; then
757 #Create a policy json to compare with
758 body=${res:0:${#res}-3}
759 file="./tmp/.p.json"
760 sed 's/XXX/'${2}'/g' $3 > $file
761 targetJson=$(< $file)
762 echo "TARGET JSON: $targetJson" >> $HTTPLOG
763 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
764 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100765 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100766 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100767 fi
768 fi
769
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100770 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100771 return 0
772}
773
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100774# API Test function: PUT /policy and V2 PUT /policies
775# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
776# args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100777# (Function for test scripts)
778api_put_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100779 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100780
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100781 if [ "$PMS_VERSION" == "V2" ]; then
782 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
783 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
784 return 1
785 fi
786 else
787 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
788 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
789 return 1
790 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100791 fi
792
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100793 count=0
794 max=1
795 serv=$2
796 ric=$3
797 pt=$4
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100798 pid=$5
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100799 trans=$6
800
801 if [ "$PMS_VERSION" == "V2" ]; then
802 noti=$7
803 temp=$8
804 if [ $# -eq 9 ]; then
805 max=$9
806 fi
807 else
808 temp=$7
809 if [ $# -eq 8 ]; then
810 max=$8
811 fi
812 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100813
814 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100815 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100816
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100817 query="/v2/policies"
818
819 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
820 if [ $trans != "NOTRANSIENT" ]; then
821 inputJson=$inputJson", \"transient\":$trans"
822 fi
823 if [ $pt != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100824 inputJson=$inputJson", \"policytype_id\":\"$pt\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100825 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100826 inputJson=$inputJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100827 fi
828 if [ $noti != "NOURL" ]; then
829 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
830 fi
831 file="./tmp/.p.json"
832 data=$(sed 's/XXX/'${pid}'/g' $temp)
833 inputJson=$inputJson", \"policy_data\":$data"
834 inputJson="{$inputJson}"
835 echo $inputJson > $file
836 else
837 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
838
839 if [ $pt != "NOTYPE" ]; then
840 query=$query"&type=$pt"
841 fi
842
843 if [ $trans != NOTRANSIENT ]; then
844 query=$query"&transient=$trans"
845 fi
846
847 file="./tmp/.p.json"
848 sed 's/XXX/'${pid}'/g' $temp > $file
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200849 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200850 res="$(__do_curl_to_api PA PUT $query $file)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100851 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200852 echo -ne " Executing "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100853 if [ $status -ne $1 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200854 echo " Executed "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100855 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100856 return 1
857 fi
858
859 let pid=$pid+1
860 let count=$count+1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200861 echo -ne " Executed "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100862 done
863 echo ""
864
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100865 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100866 return 0
867}
868
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100869# API Test function: PUT /policy and V2 PUT /policies, to run in batch
870# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
871# args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200872# (Function for test scripts)
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100873
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200874api_put_policy_batch() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100875 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200876
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100877 if [ "$PMS_VERSION" == "V2" ]; then
878 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
879 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
880 return 1
881 fi
882 else
883 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
884 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
885 return 1
886 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200887 fi
888
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100889 count=0
890 max=1
891 serv=$2
892 ric=$3
893 pt=$4
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200894 pid=$5
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100895 trans=$6
896 if [ "$PMS_VERSION" == "V2" ]; then
897 noti=$7
898 temp=$8
899 if [ $# -eq 9 ]; then
900 max=$9
901 fi
902 else
903 temp=$7
904 if [ $# -eq 8 ]; then
905 max=$8
906 fi
907 fi
908
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200909 ARR=""
910 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100911 if [ "$PMS_VERSION" == "V2" ]; then
912 query="/v2/policies"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200913
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100914 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
915 if [ $trans != "NOTRANSIENT" ]; then
916 inputJson=$inputJson", \"transient\":$trans"
917 fi
918 if [ $pt != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100919 inputJson=$inputJson", \"policytype_id\":\"$pt\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100920 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100921 inputJson=$inputJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100922 fi
923 if [ $noti != "NOURL" ]; then
924 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
925 fi
926 file="./tmp/.p.json"
927 data=$(sed 's/XXX/'${pid}'/g' $temp)
928 inputJson=$inputJson", \"policy_data\":$data"
929 inputJson="{$inputJson}"
930 echo $inputJson > $file
931 else
932 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
933
934 if [ $pt != "NOTYPE" ]; then
935 query=$query"&type=$pt"
936 fi
937
938 if [ $trans != NOTRANSIENT ]; then
939 query=$query"&transient=$trans"
940 fi
941 file="./tmp/.p.json"
942 sed 's/XXX/'${pid}'/g' $temp > $file
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200943 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200944 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200945 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200946 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200947
948 if [ $status -ne 200 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200949 echo " Requested(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100950 __log_test_fail_status_code 200 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200951 return 1
952 fi
953 cid=${res:0:${#res}-3}
954 ARR=$ARR" "$cid
955 let pid=$pid+1
956 let count=$count+1
957 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
958 done
959
960 echo ""
961 count=0
962 for cid in $ARR; do
963
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200964 res="$(__do_curl_to_api PA RESPONSE $cid)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200965 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100966 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200967
968 if [ $status -ne $1 ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100969 echo " Accepted(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100970 __log_test_fail_status_code $1 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200971 return 1
972 fi
973
974 let count=$count+1
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100975 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200976 done
977
978 echo ""
979
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100980 __log_test_pass
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200981 return 0
982}
983
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100984# API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200985# args: <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <template-file> <count-per-ric> <number-of-threads>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100986# args(V2): <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <notification-url>|NOURL <template-file> <count-per-ric> <number-of-threads>
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200987# (Function for test scripts)
988api_put_policy_parallel() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100989 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200990
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100991 if [ "$PMS_VERSION" == "V2" ]; then
992 if [ $# -ne 11 ]; then
993 __print_err "<response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <notification-url>|NOURL <template-file> <count-per-ric> <number-of-threads>" $@
994 return 1
995 fi
996 else
997 if [ $# -ne 10 ]; then
998 __print_err " <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <template-file> <count-per-ric> <number-of-threads>" $@
999 return 1
1000 fi
1001 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001002 resp_code=$1; shift;
1003 serv=$1; shift
1004 ric_base=$1; shift;
1005 num_rics=$1; shift;
1006 type=$1; shift;
1007 start_id=$1; shift;
1008 transient=$1; shift;
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001009 if [ "$PMS_VERSION" == "V2" ]; then
1010 noti=$1; shift;
1011 else
1012 noti=""
1013 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001014 template=$1; shift;
1015 count=$1; shift;
1016 pids=$1; shift;
1017
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001018 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001019 if [ $PA_ADAPTER_TYPE != "REST" ]; then
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001020 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1021 echo " Info - will execute over agent REST"
1022 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001023 if [ "$PMS_VERSION" == "V2" ]; then
1024 if [ $serv == "NOSERVICE" ]; then
1025 serv=""
1026 fi
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001027 query="$PMS_API_PREFIX/v2/policies"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001028 else
1029 if [ $serv == "NOSERVICE" ]; then
1030 serv=""
1031 fi
1032 query="/policy?service=$serv"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001033
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001034 if [ $type != "NOTYPE" ]; then
1035 query=$query"&type=$type"
1036 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001037
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001038 if [ $transient != NOTRANSIENT ]; then
1039 query=$query"&transient=$transient"
1040 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001041 fi
1042
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001043 urlbase=${PA_ADAPTER}${query}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001044
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001045 httpproxy="NOPROXY"
BjornMagnussonXA663566c2021-11-08 10:25:07 +01001046 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1047 httpproxy=$KUBE_PROXY_PATH
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001048 fi
1049
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001050 for ((i=1; i<=$pids; i++))
1051 do
BjornMagnussonXAad047782020-06-08 15:54:11 +02001052 uuid=$UUID
1053 if [ -z "$uuid" ]; then
1054 uuid="NOUUID"
1055 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001056 echo "" > "./tmp/.pid${i}.res.txt"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001057 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001058 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001059 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001060 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001061 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001062 echo $i
1063 done | xargs -n 1 -I{} -P $pids bash -c '{
1064 arg=$(echo {})
1065 echo " Parallel process $arg started"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001066 tmp=$(< "./tmp/.pid${arg}.txt")
1067 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001068 }'
1069 msg=""
1070 for ((i=1; i<=$pids; i++))
1071 do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001072 file="./tmp/.pid${i}.res.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001073 tmp=$(< $file)
1074 if [ -z "$tmp" ]; then
1075 echo " Process $i : unknown result (result file empty"
1076 msg="failed"
1077 else
1078 res=${tmp:0:1}
1079 if [ $res == "0" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001080 echo " Process $i : OK - "${tmp:1}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001081 else
1082 echo " Process $i : failed - "${tmp:1}
1083 msg="failed"
1084 fi
1085 fi
1086 done
1087 if [ -z $msg ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001088 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001089 return 0
1090 fi
1091
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001092 __log_test_fail_general "One of more processes failed to execute"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001093 return 1
1094}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001095
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001096# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001097# args: <response-code> <policy-id> [count]
1098# (Function for test scripts)
1099api_delete_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001100 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001101
1102 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1103 __print_err "<response-code> <policy-id> [count]" $@
1104 return 1
1105 fi
1106
1107 count=0
1108 max=1
1109
1110 if [ $# -eq 3 ]; then
1111 max=$3
1112 fi
1113
1114 pid=$2
1115
1116 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001117 if [ "$PMS_VERSION" == "V2" ]; then
1118 query="/v2/policies/"$UUID$pid
1119 else
1120 query="/policy?id="$UUID$pid
1121 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001122 res="$(__do_curl_to_api PA DELETE $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001123 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001124 echo -ne " Executing "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001125
1126 if [ $status -ne $1 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001127 echo " Executed "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001128 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001129 return 1
1130 fi
1131 let pid=$pid+1
1132 let count=$count+1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001133 echo -ne " Executed "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001134 done
1135 echo ""
1136
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001137 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001138 return 0
1139}
1140
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001141# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001142# args: <response-code> <policy-id> [count]
1143# (Function for test scripts)
1144api_delete_policy_batch() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001145 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001146
1147 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1148 __print_err "<response-code> <policy-id> [count]" $@
1149 return 1
1150 fi
1151
1152 count=0
1153 max=1
1154
1155 if [ $# -eq 3 ]; then
1156 max=$3
1157 fi
1158
1159 pid=$2
1160 ARR=""
1161 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001162 if [ "$PMS_VERSION" == "V2" ]; then
1163 query="/v2/policies/"$UUID$pid
1164 else
1165 query="/policy?id="$UUID$pid
1166 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001167 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001168 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001169 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001170
1171 if [ $status -ne 200 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001172 echo " Requested(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001173 __log_test_fail_status_code 200 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001174 return 1
1175 fi
1176 cid=${res:0:${#res}-3}
1177 ARR=$ARR" "$cid
1178 let pid=$pid+1
1179 let count=$count+1
1180 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1181 done
1182
1183 echo ""
1184
1185 count=0
1186 for cid in $ARR; do
1187
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001188 res="$(__do_curl_to_api PA RESPONSE $cid)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001189 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001190 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001191
1192 if [ $status -ne $1 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001193 echo " Deleted(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001194 __log_test_fail_status_code $1 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001195 return 1
1196 fi
1197
1198 let count=$count+1
1199 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1200 done
1201
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001202 echo ""
1203
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001204 __log_test_pass
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001205 return 0
1206}
1207
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001208# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001209# args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1210# (Function for test scripts)
1211api_delete_policy_parallel() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001212 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001213
1214 if [ $# -ne 5 ]; then
1215 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1216 return 1
1217 fi
1218 resp_code=$1; shift;
1219 num_rics=$1; shift;
1220 start_id=$1; shift;
1221 count=$1; shift;
1222 pids=$1; shift;
1223
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001224 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001225 if [ $PA_ADAPTER_TYPE != "REST" ]; then
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001226 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1227 echo " Info - will execute over agent REST"
1228 fi
1229
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001230 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001231 query="$PMS_API_PREFIX/v2/policies/"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001232 else
1233 query="/policy"
1234 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001235
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001236 urlbase=${PA_ADAPTER}${query}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001237
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001238 httpproxy="NOPROXY"
BjornMagnussonXA663566c2021-11-08 10:25:07 +01001239 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1240 httpproxy=$KUBE_PROXY_PATH
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001241 fi
1242
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001243 for ((i=1; i<=$pids; i++))
1244 do
BjornMagnussonXAad047782020-06-08 15:54:11 +02001245 uuid=$UUID
1246 if [ -z "$uuid" ]; then
1247 uuid="NOUUID"
1248 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001249 echo "" > "./tmp/.pid${i}.del.res.txt"
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001250 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001251 echo $i
1252 done | xargs -n 1 -I{} -P $pids bash -c '{
1253 arg=$(echo {})
1254 echo " Parallel process $arg started"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001255 tmp=$(< "./tmp/.pid${arg}.del.txt")
1256 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001257 }'
1258 msg=""
1259 for ((i=1; i<=$pids; i++))
1260 do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001261 file="./tmp/.pid${i}.del.res.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001262 tmp=$(< $file)
1263 if [ -z "$tmp" ]; then
1264 echo " Process $i : unknown result (result file empty"
1265 msg="failed"
1266 else
1267 res=${tmp:0:1}
1268 if [ $res == "0" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001269 echo " Process $i : OK - "${tmp:1}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001270 else
1271 echo " Process $i : failed - "${tmp:1}
1272 msg="failed"
1273 fi
1274 fi
1275 done
1276 if [ -z $msg ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001277 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001278 return 0
1279 fi
1280
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001281 __log_test_fail_general "One of more processes failed to execute"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001282 return 1
1283}
1284
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001285# API Test function: GET /policy_ids and V2 GET /v2/policies
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001286# args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1287# (Function for test scripts)
1288api_get_policy_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001289 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001290
1291 if [ $# -lt 4 ]; then
1292 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1293 return 1
1294 fi
1295
1296 queryparams=""
1297
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001298 if [ "$PMS_VERSION" == "V2" ]; then
1299 if [ $2 != "NORIC" ]; then
1300 queryparams="?ric_id="$2
1301 fi
1302
1303 if [ $3 != "NOSERVICE" ]; then
1304 if [ -z $queryparams ]; then
1305 queryparams="?service_id="$3
1306 else
1307 queryparams=$queryparams"&service_id="$3
1308 fi
1309 fi
1310 if [ $4 != "NOTYPE" ]; then
1311 if [ -z $queryparams ]; then
1312 queryparams="?policytype_id="$4
1313 else
1314 queryparams=$queryparams"&policytype_id="$4
1315 fi
1316 fi
1317
1318 query="/v2/policies"$queryparams
1319 else
1320 if [ $2 != "NORIC" ]; then
1321 queryparams="?ric="$2
1322 fi
1323
1324 if [ $3 != "NOSERVICE" ]; then
1325 if [ -z $queryparams ]; then
1326 queryparams="?service="$3
1327 else
1328 queryparams=$queryparams"&service="$3
1329 fi
1330 fi
1331 if [ $4 != "NOTYPE" ]; then
1332 if [ -z $queryparams ]; then
1333 queryparams="?type="$4
1334 else
1335 queryparams=$queryparams"&type="$4
1336 fi
1337 fi
1338
1339 query="/policy_ids"$queryparams
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001340 fi
1341
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001342 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001343 status=${res:${#res}-3}
1344
1345 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001346 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001347 return 1
1348 fi
1349
1350 if [ $# -gt 4 ]; then
1351 body=${res:0:${#res}-3}
1352 targetJson="["
1353
1354 for pid in ${@:5} ; do
1355 if [ "$targetJson" != "[" ]; then
1356 targetJson=$targetJson","
1357 fi
1358 if [ $pid != "NOID" ]; then
BjornMagnussonXAad047782020-06-08 15:54:11 +02001359 targetJson=$targetJson"\"$UUID$pid\""
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001360 fi
1361 done
1362
1363 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001364 if [ "$PMS_VERSION" == "V2" ]; then
1365 targetJson="{\"policy_ids\": $targetJson}"
1366 fi
1367 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1368 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1369
1370 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001371 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001372 return 1
1373 fi
1374 fi
1375
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001376 __log_test_pass
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001377 return 0
1378}
1379
1380# API Test function: V2 GET /v2/policy-types/{policyTypeId}
1381# args(V2): <response-code> <policy-type-id> [<schema-file>]
1382# (Function for test scripts)
1383api_get_policy_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001384 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001385
1386 if [ "$PMS_VERSION" != "V2" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001387 __log_test_fail_not_supported
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001388 return 1
1389 fi
1390
1391 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1392 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1393 return 1
1394 fi
1395 query="/v2/policy-types/$2"
1396
1397 res="$(__do_curl_to_api PA GET $query)"
1398 status=${res:${#res}-3}
1399
1400 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001401 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001402 return 1
1403 fi
1404
1405 if [ $# -eq 3 ]; then
1406
1407 body=${res:0:${#res}-3}
1408
1409 targetJson=$(< $3)
1410 targetJson="{\"policy_schema\":$targetJson}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001411 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001412 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001413
1414 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001415 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001416 return 1
1417 fi
1418 fi
1419
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001420 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001421 return 0
1422}
1423
1424# API Test function: GET /policy_schema
1425# args: <response-code> <policy-type-id> [<schema-file>]
1426# (Function for test scripts)
1427api_get_policy_schema() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001428 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001429
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001430 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001431 __log_test_fail_not_supported
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001432 return 1
1433 fi
1434
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001435 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1436 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1437 return 1
1438 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001439 query="/policy_schema?id=$2"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001440 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001441 status=${res:${#res}-3}
1442
1443 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001444 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001445 return 1
1446 fi
1447
1448 if [ $# -eq 3 ]; then
1449
1450 body=${res:0:${#res}-3}
1451
1452 targetJson=$(< $3)
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001453
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001454 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001455 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001456
1457 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001458 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001459 return 1
1460 fi
1461 fi
1462
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001463 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001464 return 0
1465}
1466
1467# API Test function: GET /policy_schemas
1468# args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001469# args(V2): <response-code>
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001470# (Function for test scripts)
1471api_get_policy_schemas() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001472 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001473
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001474 if [ "$PMS_VERSION" == "V2" ]; then
1475 if [ $# -ne 1 ]; then
1476 __print_err "<response-code>" $@
1477 return 1
1478 fi
1479 else
1480 if [ $# -lt 2 ]; then
1481 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1482 return 1
1483 fi
1484 fi
1485 if [ "$PMS_VERSION" == "V2" ]; then
1486 query="/v2/policy-schemas"
1487 else
1488 query="/policy_schemas"
1489 if [ $2 != "NORIC" ]; then
1490 query=$query"?ric="$2
1491 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001492 fi
1493
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001494 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001495 status=${res:${#res}-3}
1496
1497 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001498 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001499 return 1
1500 fi
1501
1502 if [ $# -gt 2 ]; then
1503 body=${res:0:${#res}-3}
1504 targetJson="["
1505
1506 for file in ${@:3} ; do
1507 if [ "$targetJson" != "[" ]; then
1508 targetJson=$targetJson","
1509 fi
1510 if [ $file == "NOFILE" ]; then
1511 targetJson=$targetJson"{}"
1512 else
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001513 targetJson=$targetJson$(< $file)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001514 fi
1515 done
1516
1517 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001518 if [ "$PMS_VERSION" == "V2" ]; then
1519 targetJson="{\"policy_schemas\": $targetJson }"
1520 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001521 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001522 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001523
1524 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001525 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001526 return 1
1527 fi
1528 fi
1529
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001530 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001531 return 0
1532}
1533
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001534# API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001535# arg: <response-code> <policy-id> (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001536# (Function for test scripts)
1537api_get_policy_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001538 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001539
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001540 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001541 __print_err "<response-code> <policy-id> (STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001542 return 1
1543 fi
1544
1545 targetJson=""
1546
1547 if [ $3 == "STD" ]; then
1548 targetJson="{\"enforceStatus\":\"$4\""
1549 if [ $# -eq 5 ]; then
1550 targetJson=$targetJson",\"reason\":\"$5\""
1551 fi
1552 targetJson=$targetJson"}"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001553 elif [ $3 == "STD2" ]; then
1554 if [ $4 == "EMPTY" ]; then
1555 targetJson="{\"enforceStatus\":\"\""
1556 else
1557 targetJson="{\"enforceStatus\":\"$4\""
1558 fi
1559 if [ $# -eq 5 ]; then
1560 if [ $5 == "EMPTY" ]; then
1561 targetJson=$targetJson",\"enforceReason\":\"\""
1562 else
1563 targetJson=$targetJson",\"enforceReason\":\"$5\""
1564 fi
1565 fi
1566 targetJson=$targetJson"}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001567 elif [ $3 == "OSC" ]; then
1568 targetJson="{\"instance_status\":\"$4\""
1569 if [ $# -eq 5 ]; then
1570 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1571 fi
1572 targetJson=$targetJson",\"created_at\":\"????\"}"
1573 else
1574 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1575 return 1
1576 fi
1577
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001578 if [ "$PMS_VERSION" == "V2" ]; then
1579 query="/v2/policies/$UUID$2/status"
1580 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1581 else
1582 query="/policy_status?id="$UUID$2
1583 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001584
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001585 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001586 status=${res:${#res}-3}
1587
1588 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001589 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001590 return 1
1591 fi
1592
1593 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1594 body=${res:0:${#res}-3}
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001595 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001596
1597 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001598 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001599 return 1
1600 fi
1601
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001602 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001603 return 0
1604}
1605
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001606# API Test function: GET /policy_types and V2 GET /v2/policy-types
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001607# args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1608# (Function for test scripts)
1609api_get_policy_types() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001610 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001611
1612 if [ $# -lt 1 ]; then
1613 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1614 return 1
1615 fi
1616
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001617 if [ "$PMS_VERSION" == "V2" ]; then
1618 if [ $# -eq 1 ]; then
1619 query="/v2/policy-types"
1620 elif [ $2 == "NORIC" ]; then
1621 query="/v2/policy-types"
1622 else
1623 query="/v2/policy-types?ric_id=$2"
1624 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001625 else
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001626 if [ $# -eq 1 ]; then
1627 query="/policy_types"
1628 elif [ $2 == "NORIC" ]; then
1629 query="/policy_types"
1630 else
1631 query="/policy_types?ric=$2"
1632 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001633 fi
1634
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001635 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001636 status=${res:${#res}-3}
1637
1638 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001639 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001640 return 1
1641 fi
1642
1643 if [ $# -gt 2 ]; then
1644 body=${res:0:${#res}-3}
1645 targetJson="["
1646
1647 for pid in ${@:3} ; do
1648 if [ "$targetJson" != "[" ]; then
1649 targetJson=$targetJson","
1650 fi
1651 if [ $pid == "EMPTY" ]; then
1652 pid=""
1653 fi
1654 targetJson=$targetJson"\"$pid\""
1655 done
1656
1657 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001658 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001659 targetJson="{\"policytype_ids\": $targetJson }"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001660 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001661 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001662 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001663
1664 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001665 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001666 return 1
1667 fi
1668 fi
1669
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001670 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001671 return 0
1672}
1673
1674#########################################################
1675#### Test case functions Health check
1676#########################################################
1677
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001678# API Test function: GET /status and V2 GET /status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001679# args: <response-code>
1680# (Function for test scripts)
1681api_get_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001682 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001683 if [ $# -ne 1 ]; then
1684 __print_err "<response-code>" $@
1685 return 1
1686 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001687 if [ "$PMS_VERSION" == "V2" ]; then
1688 query="/v2/status"
1689 else
1690 query="/status"
1691 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001692 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001693 status=${res:${#res}-3}
1694
1695 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001696 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001697 return 1
1698 fi
1699
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001700 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001701 return 0
1702}
1703
1704#########################################################
1705#### Test case functions RIC Repository
1706#########################################################
1707
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001708# API Test function: GET /ric and V2 GET /v2/rics/ric
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001709# args: <reponse-code> <management-element-id> [<ric-id>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001710# (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1711# (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1712# (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1713
1714
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001715# (Function for test scripts)
1716api_get_ric() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001717 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001718
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001719 if [ "$PMS_VERSION" == "V2" ]; then
1720 if [ $# -lt 3 ]; then
1721 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1722 return 1
1723 fi
1724 search=""
1725 if [ $2 != "NOME" ]; then
1726 search="?managed_element_id="$2
1727 fi
1728 if [ $3 != "NORIC" ]; then
1729 if [ -z $search ]; then
1730 search="?ric_id="$3
1731 else
1732 search=$search"&ric_id="$3
1733 fi
1734 fi
1735 query="/v2/rics/ric"$search
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001736
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001737 res="$(__do_curl_to_api PA GET $query)"
1738 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001739
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001740 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001741 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001742 return 1
1743 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001744
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001745 if [ $# -gt 3 ]; then
1746 body=${res:0:${#res}-3}
1747 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1748 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001749 __log_test_fail_general "Could not create target ric info json"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001750 return 1
1751 fi
1752
1753 targetJson=$(<./tmp/.tmp_rics.json)
1754 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1755 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1756 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1757 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001758 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001759 return 1
1760 fi
1761 fi
1762 else
1763 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1764 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1765 return 1
1766 fi
1767
1768 query="/ric?managedElementId="$2
1769
1770 res="$(__do_curl_to_api PA GET $query)"
1771 status=${res:${#res}-3}
1772
1773 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001774 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001775 return 1
1776 fi
1777
1778 if [ $# -eq 3 ]; then
1779 body=${res:0:${#res}-3}
1780 if [ "$body" != "$3" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001781 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001782 return 1
1783 fi
1784 fi
1785 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001786 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001787 return 0
1788}
1789
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001790# API test function: GET /rics and V2 GET /v2/rics
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001791# args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1792# example of <space-separate-string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4 ricsim_g1_1:me2_........."
1793# format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1794# (Function for test scripts)
1795api_get_rics() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001796 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001797
1798 if [ $# -lt 2 ]; then
1799 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1800 return 1
1801 fi
1802
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001803 if [ "$PMS_VERSION" == "V2" ]; then
1804 query="/v2/rics"
1805 if [ $2 != "NOTYPE" ]; then
1806 query="/v2/rics?policytype_id="$2
1807 fi
1808 else
1809 query="/rics"
1810 if [ $2 != "NOTYPE" ]; then
1811 query="/rics?policyType="$2
1812 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001813 fi
1814
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001815 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001816 status=${res:${#res}-3}
1817
1818 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001819 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001820 return 1
1821 fi
1822
1823 if [ $# -gt 2 ]; then
1824 body=${res:0:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001825 if [ "$PMS_VERSION" == "V2" ]; then
1826 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
1827 else
1828 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
1829 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001830 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001831 __log_test_fail_general "Could not create target ric info json"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001832 return 1
1833 fi
1834
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001835 targetJson=$(<./tmp/.tmp_rics.json)
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001836 if [ "$PMS_VERSION" == "V2" ]; then
1837 targetJson="{\"rics\": $targetJson }"
1838 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001839 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001840 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001841 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001842 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001843 return 1
1844 fi
1845 fi
1846
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001847 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001848 return 0
1849}
1850
1851##################################################################
1852#### API Test case functions Service registry and supervision ####
1853##################################################################
1854
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001855# API test function: PUT /service and V2 PUT /service
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001856# args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1857# (Function for test scripts)
1858api_put_service() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001859 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001860 if [ $# -ne 4 ]; then
1861 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1862 return 1
1863 fi
1864
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001865 if [ "$PMS_VERSION" == "V2" ]; then
1866 query="/v2/services"
1867 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
1868 else
1869 query="/service"
1870 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1871 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001872 file="./tmp/.tmp.json"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001873 echo "$json" > $file
1874
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001875 res="$(__do_curl_to_api PA PUT $query $file)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001876 status=${res:${#res}-3}
1877
1878 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001879 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001880 return 1
1881 fi
1882
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001883 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001884 return 0
1885}
1886
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001887# API test function: GET /services and V2 GET /v2/services
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001888#args: <response-code> [ (<query-service-name> <target-service-name> <keepalive-timeout> <callbackurl>) | (NOSERVICE <target-service-name> <keepalive-timeout> <callbackurl> [<target-service-name> <keepalive-timeout> <callbackurl>]* )]
1889# (Function for test scripts)
1890api_get_services() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001891 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001892 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1893 paramError=1
1894 if [ $# -eq 1 ]; then
1895 paramError=0
1896 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1897 paramError=0
1898 elif [ $# -eq 5 ]; then
1899 paramError=0
1900 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1901 argLen=$(($#-2))
1902 if [ $(($argLen%3)) -eq 0 ]; then
1903 paramError=0
1904 fi
1905 fi
1906
1907 if [ $paramError -ne 0 ]; then
1908 __print_err "<response-code> [ (<query-service-name> <target-service-name> <keepalive-timeout> <callbackurl>) | (NOSERVICE <target-service-name> <keepalive-timeout> <callbackurl> [<target-service-name> <keepalive-timeout> <callbackurl>]* )]" $@
1909 return 1
1910 fi
1911
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001912 if [ "$PMS_VERSION" == "V2" ]; then
1913 query="/v2/services"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001914
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001915 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1916 query="/v2/services?service_id="$2
1917 fi
1918 else
1919 query="/services"
1920
1921 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1922 query="/services?name="$2
1923 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001924 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001925 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001926 status=${res:${#res}-3}
1927
1928 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001929 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001930 return 1
1931 fi
1932
1933 if [ $# -gt 2 ]; then
1934 variableArgCount=$(($#-2))
1935 body=${res:0:${#res}-3}
1936 targetJson="["
1937 shift; shift;
1938 cntr=0
1939 while [ $cntr -lt $variableArgCount ]; do
1940 servicename=$1; shift;
1941 timeout=$1; shift;
1942 callback=$1; shift;
1943 if [ $cntr -gt 0 ]; then
1944 targetJson=$targetJson","
1945 fi
1946 # timeSinceLastActivitySeconds value cannot be checked since value varies
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001947 if [ "$PMS_VERSION" == "V2" ]; then
1948 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
1949 else
1950 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1951 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001952 let cntr=cntr+3
1953 done
1954 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001955 if [ "$PMS_VERSION" == "V2" ]; then
1956 targetJson="{\"service_list\": $targetJson }"
1957 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001958 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001959 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001960 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001961 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001962 return 1
1963 fi
1964 fi
1965
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001966 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001967 return 0
1968}
1969
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001970# API test function: GET /services V2 GET /v2/services - (only checking service names)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001971# args: <response-code> [<service-name>]*"
1972# (Function for test scripts)
1973api_get_service_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001974 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001975
1976 if [ $# -lt 1 ]; then
1977 __print_err "<response-code> [<service-name>]*" $@
1978 return 1
1979 fi
1980
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001981 if [ "$PMS_VERSION" == "V2" ]; then
1982 query="/v2/services"
1983 else
1984 query="/services"
1985 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001986 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001987 status=${res:${#res}-3}
1988
1989 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001990 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001991 return 1
1992 fi
1993
1994 body=${res:0:${#res}-3}
1995 targetJson="["
1996 for rapp in ${@:2} ; do
1997 if [ "$targetJson" != "[" ]; then
1998 targetJson=$targetJson","
1999 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002000 if [ "$PMS_VERSION" == "V2" ]; then
2001 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2002 else
2003 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2004 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002005 done
2006
2007 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002008 if [ "$PMS_VERSION" == "V2" ]; then
2009 targetJson="{\"service_list\": $targetJson }"
2010 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002011 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002012 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002013
2014 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002015 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002016 return 1
2017 fi
2018
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002019 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002020 return 0
2021}
2022
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002023# API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002024# args: <response-code> <service-name>
2025# (Function for test scripts)
2026api_delete_services() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002027 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002028
2029 if [ $# -ne 2 ]; then
2030 __print_err "<response-code> <service-name>" $@
2031 return 1
2032 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002033 if [ "$PMS_VERSION" == "V2" ]; then
2034 query="/v2/services/"$2
2035 else
2036 query="/services?name="$2
2037 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002038 res="$(__do_curl_to_api PA DELETE $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002039 status=${res:${#res}-3}
2040
2041 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002042 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002043 return 1
2044 fi
2045
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002046 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002047 return 0
2048}
2049
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002050# API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002051# args: <response-code> <service-name>
2052# (Function for test scripts)
2053api_put_services_keepalive() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002054 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002055
2056 if [ $# -ne 2 ]; then
2057 __print_err "<response-code> <service-name>" $@
2058 return 1
2059 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002060 if [ "$PMS_VERSION" == "V2" ]; then
2061 query="/v2/services/$2/keepalive"
2062 else
2063 query="/services/keepalive?name="$2
2064 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002065
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002066 res="$(__do_curl_to_api PA PUT $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002067 status=${res:${#res}-3}
2068
2069 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002070 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002071 return 1
2072 fi
2073
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002074 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002075 return 0
2076}
2077
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002078##################################################################
2079#### API Test case functions Configuration ####
2080##################################################################
2081
2082# API Test function: PUT /v2/configuration
2083# args: <response-code> <config-file>
2084# (Function for test scripts)
2085api_put_configuration() {
2086 __log_test_start $@
2087
2088 if [ "$PMS_VERSION" != "V2" ]; then
2089 __log_test_fail_not_supported
2090 return 1
2091 fi
2092
2093 if [ $# -ne 2 ]; then
2094 __print_err "<response-code> <config-file>" $@
2095 return 1
2096 fi
2097 if [ ! -f $2 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002098 __log_test_fail_general "Config file "$2", does not exist"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002099 return 1
2100 fi
2101 inputJson=$(< $2)
2102 inputJson="{\"config\":"$inputJson"}"
2103 file="./tmp/.config.json"
2104 echo $inputJson > $file
2105 query="/v2/configuration"
2106 res="$(__do_curl_to_api PA PUT $query $file)"
2107 status=${res:${#res}-3}
2108
2109 if [ $status -ne $1 ]; then
2110 __log_test_fail_status_code $1 $status
2111 return 1
2112 fi
2113
2114 __log_test_pass
2115 return 0
2116}
2117
2118# API Test function: GET /v2/configuration
2119# args: <response-code> [<config-file>]
2120# (Function for test scripts)
2121api_get_configuration() {
2122 __log_test_start $@
2123
2124 if [ "$PMS_VERSION" != "V2" ]; then
2125 __log_test_fail_not_supported
2126 return 1
2127 fi
2128
2129 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2130 __print_err "<response-code> [<config-file>]" $@
2131 return 1
2132 fi
2133 if [ ! -f $2 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002134 __log_test_fail_general "Config file "$2" for comparison, does not exist"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002135 return 1
2136 fi
2137
2138 query="/v2/configuration"
2139 res="$(__do_curl_to_api PA GET $query)"
2140 status=${res:${#res}-3}
2141
2142 if [ $status -ne $1 ]; then
2143 __log_test_fail_status_code $1 $status
2144 return 1
2145 fi
2146
2147 if [ $# -eq 2 ]; then
2148
2149 body=${res:0:${#res}-3}
2150
2151 targetJson=$(< $2)
2152 targetJson="{\"config\":"$targetJson"}"
2153 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2154 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2155
2156 if [ $res -ne 0 ]; then
2157 __log_test_fail_body
2158 return 1
2159 fi
2160 fi
2161
2162 __log_test_pass
2163 return 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002164}
2165
2166##########################################
2167#### Reset types and instances ####
2168##########################################
2169
2170# Admin reset to remove all policies and services
2171# All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2172# NOTE - only works in kubernetes and the pod should not be running
2173# args: -
2174# (Function for test scripts)
2175
2176pms_kube_pvc_reset() {
2177 __log_test_start $@
2178
BjornMagnussonXA663566c2021-11-08 10:25:07 +01002179 pvc_name=$(kubectl get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +02002180 if [ -z "$pvc_name" ]; then
2181 pvc_name=policymanagementservice-vardata-pvc
2182 fi
2183 echo " Trying to reset pvc: "$pvc_name
BjornMagnussonXA663566c2021-11-08 10:25:07 +01002184 __kube_clean_pvc $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $POLICY_AGENT_CONTAINER_MNT_DIR
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002185
2186 __log_test_pass
2187 return 0
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002188}