blob: 767abb9a924ba102af1a0de05a5e35f0bb53e627 [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() {
67 __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app nonrtric-policymanagementservice
68}
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() {
80 docker logs $POLICY_AGENT_APP_NAME > $1$2_policy-agent.log 2>&1
81}
82
83#######################################################
BjornMagnussonXA80a92002020-03-19 14:31:06 +010084
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +010085## Access to Policy agent
86# Host name may be changed if app started by kube
87# Direct access from script
88PA_HTTPX="http"
89PA_HOST_NAME=$LOCALHOST_NAME
90PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
91
92# PA_ADAPTER used for switch between REST and DMAAP
93PA_ADAPTER_TYPE="REST"
94PA_ADAPTER=$PA_PATH
95
96# Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
97AGENT_RETRY_CODES=""
98
BjornMagnussonXAa69cd902021-04-22 23:46:10 +020099#Save first worker node the pod is started on
100__PA_WORKER_NODE=""
101
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100102###########################
103### Policy Agents functions
104###########################
105
106# All calls to the agent will be directed to the agent REST interface from now on
107# args: -
108# (Function for test scripts)
109use_agent_rest_http() {
110 echo -e $BOLD"Agent protocol setting"$EBOLD
111 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards the agent"
112 PA_HTTPX="http"
113 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
114
115 PA_ADAPTER_TYPE="REST"
116 PA_ADAPTER=$PA_PATH
117 echo ""
118}
119
120# All calls to the agent will be directed to the agent REST interface from now on
121# args: -
122# (Function for test scripts)
123use_agent_rest_https() {
124 echo -e $BOLD"Agent protocol setting"$EBOLD
125 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent"
126 PA_HTTPX="https"
127 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_SECURE_PORT
128
129 PA_ADAPTER_TYPE="REST"
130 PA_ADAPTER=$PA_PATH
131 echo ""
132}
133
134# All calls to the agent will be directed to the agent dmaap interface over http from now on
135# args: -
136# (Function for test scripts)
137use_agent_dmaap_http() {
138 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
139 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
140 PA_ADAPTER_TYPE="MR-HTTP"
141 echo ""
142}
143
144# All calls to the agent will be directed to the agent dmaap interface over https from now on
145# args: -
146# (Function for test scripts)
147use_agent_dmaap_https() {
148 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
149 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
150 echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
151 PA_ADAPTER_TYPE="MR-HTTPS"
152 echo ""
153}
154
155# Start the policy agent
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100156# args: (docker) PROXY|NOPROXY <config-file>
157# args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100158# (Function for test scripts)
159start_policy_agent() {
160 echo -e $BOLD"Starting $POLICY_AGENT_DISPLAY_NAME"$EBOLD
161
162 if [ $RUNMODE == "KUBE" ]; then
163
164 # Check if app shall be fully managed by the test script
165 __check_included_image "PA"
166 retcode_i=$?
167
168 # Check if app shall only be used by the testscipt
169 __check_prestarted_image "PA"
170 retcode_p=$?
171
172 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
173 echo -e $RED"The $POLICY_AGENT_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
174 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
175 exit
176 fi
177 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
178 echo -e $RED"The $POLICY_AGENT_APP_NAME app is included both as managed and prestarted in this test script"$ERED
179 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
180 exit
181 fi
182
183 if [ $retcode_p -eq 0 ]; then
184 echo -e " Using existing $POLICY_AGENT_APP_NAME deployment and service"
185 echo " Setting $POLICY_AGENT_APP_NAME replicas=1"
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +0200186 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
187 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100188 fi
189
190 if [ $retcode_i -eq 0 ]; then
191
192 echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
193
194 #Check if nonrtric namespace exists, if not create it
195 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
196
197 #Export all vars needed for service and deployment
198 export POLICY_AGENT_APP_NAME
199 export KUBE_NONRTRIC_NAMESPACE
200 export POLICY_AGENT_IMAGE
201 export POLICY_AGENT_INTERNAL_PORT
202 export POLICY_AGENT_INTERNAL_SECURE_PORT
203 export POLICY_AGENT_EXTERNAL_PORT
204 export POLICY_AGENT_EXTERNAL_SECURE_PORT
205 export POLICY_AGENT_CONFIG_MOUNT_PATH
206 export POLICY_AGENT_DATA_MOUNT_PATH
207 export POLICY_AGENT_CONFIG_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-config"
208 export POLICY_AGENT_DATA_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-data"
209 export POLICY_AGENT_PKG_NAME
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200210
211 export POLICY_AGENT_DATA_PV_NAME=$POLICY_AGENT_APP_NAME"-pv"
212 export POLICY_AGENT_DATA_PVC_NAME=$POLICY_AGENT_APP_NAME"-pvc"
213 ##Create a unique path for the pv each time to prevent a previous volume to be reused
214 export POLICY_AGENT_PV_PATH="padata-"$(date +%s)
215 export POLICY_AGENT_CONTAINER_MNT_DIR
216
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100217 if [ $1 == "PROXY" ]; then
218 AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
219 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100220 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
221 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
222 else
223 echo " Configured with http proxy"
224 fi
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100225 else
226 AGENT_HTTP_PROXY_CONFIG_PORT=0
227 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100228 echo " Configured without http proxy"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100229 fi
230 export AGENT_HTTP_PROXY_CONFIG_PORT
231 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME
232
233
234 # Create config map for config
235 configfile=$PWD/tmp/$POLICY_AGENT_CONFIG_FILE
236 cp $2 $configfile
237 output_yaml=$PWD/tmp/pa_cfc.yaml
238 __kube_create_configmap $POLICY_AGENT_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $configfile $output_yaml
239
240 # Create config map for data
241 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
242 if [ $# -lt 3 ]; then
243 #create empty dummy file
244 echo "{}" > $data_json
245 else
246 cp $3 $data_json
247 fi
248 output_yaml=$PWD/tmp/pa_cfd.yaml
249 __kube_create_configmap $POLICY_AGENT_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
250
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200251 ## Create pv
252 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pv.yaml
253 output_yaml=$PWD/tmp/pa_pv.yaml
254 __kube_create_instance pv $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
255
256 ## Create pvc
257 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pvc.yaml
258 output_yaml=$PWD/tmp/pa_pvc.yaml
259 __kube_create_instance pvc $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
260
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100261 # Create service
262 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"svc.yaml
263 output_yaml=$PWD/tmp/pa_svc.yaml
264 __kube_create_instance service $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
265
266 # Create app
267 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"app.yaml
268 output_yaml=$PWD/tmp/pa_app.yaml
269 __kube_create_instance app $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
270
271 fi
272
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200273 # 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 +0200274 if [ $retcode_i -eq 0 ]; then
275 __PA_WORKER_NODE=$(kubectl get pod -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
276 if [ -z "$__PA_WORKER_NODE" ]; then
277 echo -e $YELLOW" Cannot find worker node for pod for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
278 fi
279 else
280 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 +0200281 fi
282
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100283 echo " Retrieving host and ports for service..."
284 PA_HOST_NAME=$(__kube_get_service_host $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
285 POLICY_AGENT_EXTERNAL_PORT=$(__kube_get_service_port $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
286 POLICY_AGENT_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
287
288 echo " Host IP, http port, https port: $PA_HOST_NAME $POLICY_AGENT_EXTERNAL_PORT $POLICY_AGENT_EXTERNAL_SECURE_PORT"
289
290 if [ $PA_HTTPX == "http" ]; then
291 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
292 else
293 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_SECURE_PORT
294 fi
295 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
296
297 if [ $PA_ADAPTER_TYPE == "REST" ]; then
298 PA_ADAPTER=$PA_PATH
299 fi
300 else
301 __check_included_image 'PA'
302 if [ $? -eq 1 ]; then
303 echo -e $RED"The Policy Agent app is not included in this test script"$ERED
304 echo -e $RED"The Policy Agent will not be started"$ERED
305 exit
306 fi
307
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200308 curdir=$PWD
309 cd $SIM_GROUP
310 cd policy_agent
311 cd $POLICY_AGENT_HOST_MNT_DIR
312 #cd ..
313 if [ -d db ]; then
314 if [ "$(ls -A $DIR)" ]; then
315 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
316 rm -rf db/* &> /dev/null
317 if [ $? -ne 0 ]; then
318 echo -e $RED" Cannot remove database files in: $PWD"$ERED
319 exit 1
320 fi
321 fi
322 else
323 echo " No files in mounted dir or dir does not exists"
324 fi
325 cd $curdir
326
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100327 #Export all vars needed for docker-compose
328 export POLICY_AGENT_APP_NAME
329 export POLICY_AGENT_APP_NAME_ALIAS
330 export POLICY_AGENT_INTERNAL_PORT
331 export POLICY_AGENT_EXTERNAL_PORT
332 export POLICY_AGENT_INTERNAL_SECURE_PORT
333 export POLICY_AGENT_EXTERNAL_SECURE_PORT
334 export CONSUL_HOST
335 export CONSUL_INTERNAL_PORT
336 export CONFIG_BINDING_SERVICE
337 export POLICY_AGENT_CONFIG_KEY
338 export DOCKER_SIM_NWNAME
339 export POLICY_AGENT_HOST_MNT_DIR
340 export POLICY_AGENT_CONFIG_MOUNT_PATH
341 export POLICY_AGENT_CONFIG_FILE
342 export POLICY_AGENT_PKG_NAME
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100343 export POLICY_AGENT_DISPLAY_NAME
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200344 export POLICY_AGENT_CONTAINER_MNT_DIR
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100345
346 if [ $1 == "PROXY" ]; then
347 AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
348 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100349 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
350 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
351 else
352 echo " Configured with http proxy"
353 fi
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100354 else
355 AGENT_HTTP_PROXY_CONFIG_PORT=0
356 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100357 echo " Configured without http proxy"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100358 fi
359 export AGENT_HTTP_PROXY_CONFIG_PORT
360 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME
361
362 dest_file=$SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_HOST_MNT_DIR/application.yaml
363
364 envsubst < $2 > $dest_file
365
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100366 __start_container $POLICY_AGENT_COMPOSE_DIR "" NODOCKERARGS 1 $POLICY_AGENT_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100367
368 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
369 fi
370 echo ""
371 return 0
372}
373
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200374# Stop the policy agent
375# args: -
376# args: -
377# (Function for test scripts)
378stop_policy_agent() {
379 echo -e $BOLD"Stopping $POLICY_AGENT_DISPLAY_NAME"$EBOLD
380
381 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200382
383 __check_prestarted_image "PA"
384 if [ $? -eq 0 ]; then
385 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 +0200386 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
387 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200388 return 0
389 fi
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200390 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
391 echo " Deleting the replica set - a new will be started when the app is started"
392 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
393 if [ $? -ne 0 ]; then
394 echo -e $RED" Could not delete replica set "$RED
395 ((RES_CONF_FAIL++))
396 return 1
397 fi
398 else
399 docker stop $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
400 if [ $? -ne 0 ]; then
401 __print_err "Could not stop $POLICY_AGENT_APP_NAME" $@
402 cat ./tmp/.dockererr
403 ((RES_CONF_FAIL++))
404 return 1
405 fi
406 fi
407 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
408 echo ""
409 return 0
410}
411
412# Start a previously stopped policy agent
413# args: -
414# (Function for test scripts)
415start_stopped_policy_agent() {
416 echo -e $BOLD"Starting (the previously stopped) $POLICY_AGENT_DISPLAY_NAME"$EBOLD
417
418 if [ $RUNMODE == "KUBE" ]; then
419
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200420 __check_prestarted_image "PA"
421 if [ $? -eq 0 ]; then
422 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 +0200423 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
424 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200425 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
426 return 0
427 fi
428
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200429 # Tie the PMS to the same worker node it was initially started on
430 # 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
431 if [ -z "$__PA_WORKER_NODE" ]; then
432 echo -e $RED" No initial worker node found for pod "$RED
433 ((RES_CONF_FAIL++))
434 return 1
435 else
436 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
437 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
438 tmp=$(kubectl patch deployment $POLICY_AGENT_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__PA_WORKER_NODE'"}}}}}')
439 if [ $? -ne 0 ]; then
440 echo -e $YELLOW" Cannot set nodeSelector to deployment for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
441 fi
442 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
443 fi
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200444 else
445 docker start $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
446 if [ $? -ne 0 ]; then
447 __print_err "Could not start (the stopped) $POLICY_AGENT_APP_NAME" $@
448 cat ./tmp/.dockererr
449 ((RES_CONF_FAIL++))
450 return 1
451 fi
452 fi
453 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
454 if [ $? -ne 0 ]; then
455 return 1
456 fi
457 echo ""
458 return 0
459}
460
461
462
BjornMagnussonXA366e36a2021-01-27 11:48:56 +0100463# Load the the appl config for the agent into a config map
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100464agent_load_config() {
465 echo -e $BOLD"Agent - load config from "$EBOLD$1
466 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
467 cp $1 $data_json
468 output_yaml=$PWD/tmp/pa_cfd.yaml
469 __kube_create_configmap $POLICY_AGENT_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100470 echo ""
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100471}
472
473
474# Turn on debug level tracing in the agent
475# args: -
476# (Function for test scripts)
477set_agent_debug() {
478 echo -e $BOLD"Setting agent debug logging"$EBOLD
479 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
480 result=$(__do_curl "$curlString")
481 if [ $? -ne 0 ]; then
482 __print_err "could not set debug mode" $@
483 ((RES_CONF_FAIL++))
484 return 1
485 fi
486 echo ""
487 return 0
488}
489
490# Turn on trace level tracing in the agent
491# args: -
492# (Function for test scripts)
493set_agent_trace() {
494 echo -e $BOLD"Setting agent trace logging"$EBOLD
495 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
496 result=$(__do_curl "$curlString")
497 if [ $? -ne 0 ]; then
498 __print_err "could not set trace mode" $@
499 ((RES_CONF_FAIL++))
500 return 1
501 fi
502 echo ""
503 return 0
504}
505
506# Perform curl retries when making direct call to the agent for the specified http response codes
507# Speace separated list of http response codes
508# args: [<response-code>]*
509use_agent_retries() {
510 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
511 AGENT_RETRY_CODES=$@
512 echo ""
513 return
514}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100515
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100516# Check the agent logs for WARNINGs and ERRORs
517# args: -
518# (Function for test scripts)
519check_policy_agent_logs() {
520 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
521}
522
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100523#########################################################
524#### Test case functions A1 Policy management service
525#########################################################
526
527# This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
528# This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
529# args: json:<url> <target-value> [<timeout-in-seconds]
530# (Function for test scripts)
531api_equal() {
532 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
533 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
534 if [[ $1 == "json:"* ]]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100535 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100536 __var_test "Policy Agent" $PA_PATH$PMS_API_PREFIX"/v2/" $1 "=" $2 $3
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100537 else
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100538 __var_test "Policy Agent" $PA_PATH"/" $1 "=" $2 $3
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100539 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100540 return 0
541 fi
542 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100543 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
544 return 1
545}
546
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100547# API Test function: GET /policies and V2 GET /v2/policy-instances
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100548# 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>]*]
549# 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 +0100550# (Function for test scripts)
551api_get_policies() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100552 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100553
554 if [ "$PMS_VERSION" == "V2" ]; then
555 paramError=0
556 variableParams=$(($#-4))
557 if [ $# -lt 4 ]; then
558 paramError=1
559 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
560 paramError=1
561 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
562 paramError=1
563 fi
564
565 if [ $paramError -ne 0 ]; then
566 __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>]*]" $@
567 return 1
568 fi
569 else
570 paramError=0
571 variableParams=$(($#-4))
572 if [ $# -lt 4 ]; then
573 paramError=1
574 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
575 paramError=1
576 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
577 paramError=1
578 fi
579
580 if [ $paramError -ne 0 ]; then
581 __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>]*]" $@
582 return 1
583 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100584 fi
585
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100586 queryparams=""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100587 if [ "$PMS_VERSION" == "V2" ]; then
588 if [ $2 != "NORIC" ]; then
589 queryparams="?ric_id="$2
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100590 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100591 if [ $3 != "NOSERVICE" ]; then
592 if [ -z $queryparams ]; then
593 queryparams="?service_id="$3
594 else
595 queryparams=$queryparams"&service_id="$3
596 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100597 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100598 if [ $4 != "NOTYPE" ]; then
599 if [ -z $queryparams ]; then
600 queryparams="?policytype_id="$4
601 else
602 queryparams=$queryparams"&policytype_id="$4
603 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100604 fi
605
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100606 query="/v2/policy-instances"$queryparams
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100607 res="$(__do_curl_to_api PA GET $query)"
608 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100609
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100610 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100611 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100612 return 1
613 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100614
615 if [ $# -gt 4 ]; then
616 body=${res:0:${#res}-3}
617 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
618 targetJson="["
619 else
620 targetJson="["
621 arr=(${@:5})
622
623 for ((i=0; i<$(($#-4)); i=i+7)); do
624
625 if [ "$targetJson" != "[" ]; then
626 targetJson=$targetJson","
627 fi
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100628 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 +0100629 if [ "${arr[$i+3]}" == "EMPTY" ]; then
630 targetJson=$targetJson"\"\","
631 else
632 targetJson=$targetJson"\"${arr[$i+3]}\","
633 fi
634 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
635 file="./tmp/.p.json"
636 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
637 json=$(cat $file)
638 targetJson=$targetJson"\"policy_data\":"$json"}"
639 done
640 fi
641
642 targetJson=$targetJson"]"
643 targetJson="{\"policies\": $targetJson}"
644 echo "TARGET JSON: $targetJson" >> $HTTPLOG
645 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
646
647 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100648 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100649 return 1
650 fi
651 fi
652 else
653 if [ $2 != "NORIC" ]; then
654 queryparams="?ric="$2
655 fi
656 if [ $3 != "NOSERVICE" ]; then
657 if [ -z $queryparams ]; then
658 queryparams="?service="$3
659 else
660 queryparams=$queryparams"&service="$3
661 fi
662 fi
663 if [ $4 != "NOTYPE" ]; then
664 if [ -z $queryparams ]; then
665 queryparams="?type="$4
666 else
667 queryparams=$queryparams"&type="$4
668 fi
669 fi
670
671 query="/policies"$queryparams
672 res="$(__do_curl_to_api PA GET $query)"
673 status=${res:${#res}-3}
674
675 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100676 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100677 return 1
678 fi
679
680 if [ $# -gt 4 ]; then
681 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
682 targetJson="["
683 else
684 body=${res:0:${#res}-3}
685 targetJson="["
686 arr=(${@:5})
687
688 for ((i=0; i<$(($#-4)); i=i+5)); do
689
690 if [ "$targetJson" != "[" ]; then
691 targetJson=$targetJson","
692 fi
693 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
694 if [ "${arr[$i+3]}" == "EMPTY" ]; then
695 targetJson=$targetJson"\"\","
696 else
697 targetJson=$targetJson"\"${arr[$i+3]}\","
698 fi
699 file="./tmp/.p.json"
700 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
701 json=$(cat $file)
702 targetJson=$targetJson"\"json\":"$json"}"
703 done
704 fi
705
706 targetJson=$targetJson"]"
707 echo "TARGET JSON: $targetJson" >> $HTTPLOG
708 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
709
710 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100711 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100712 return 1
713 fi
714 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100715 fi
716
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100717 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100718 return 0
719
720}
721
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100722
723# API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
724# args: <response-code> <policy-id> [<template-file>]
725# args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
726
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100727# (Function for test scripts)
728api_get_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100729 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100730
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100731
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100732 if [ "$PMS_VERSION" == "V2" ]; then
733 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
734 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
735 return 1
736 fi
737 query="/v2/policies/$UUID$2"
738 else
739 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
740 __print_err "<response-code> <policy-id> [<template-file>] " $@
741 return 1
742 fi
743 query="/policy?id=$UUID$2"
744 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200745 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100746 status=${res:${#res}-3}
747
748 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100749 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100750 return 1
751 fi
752
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100753 if [ "$PMS_VERSION" == "V2" ]; then
754 if [ $# -eq 8 ]; then
755
756 #Create a policy json to compare with
757 body=${res:0:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100758
759 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
760 if [ $7 != "NOTRANSIENT" ]; then
761 targetJson=$targetJson", \"transient\":$7"
762 fi
763 if [ $6 != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100764 targetJson=$targetJson", \"policytype_id\":\"$6\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100765 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100766 targetJson=$targetJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100767 fi
768 if [ $8 != "NOURL" ]; then
769 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
770 fi
771
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100772 data=$(sed 's/XXX/'${2}'/g' $3)
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100773 targetJson=$targetJson", \"policy_data\":$data"
774 targetJson="{$targetJson}"
775
776 echo "TARGET JSON: $targetJson" >> $HTTPLOG
777 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
778 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100779 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100780 return 1
781 fi
782 fi
783 else
784 if [ $# -eq 3 ]; then
785 #Create a policy json to compare with
786 body=${res:0:${#res}-3}
787 file="./tmp/.p.json"
788 sed 's/XXX/'${2}'/g' $3 > $file
789 targetJson=$(< $file)
790 echo "TARGET JSON: $targetJson" >> $HTTPLOG
791 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
792 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100793 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100794 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100795 fi
796 fi
797
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100798 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100799 return 0
800}
801
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100802# API Test function: PUT /policy and V2 PUT /policies
803# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
804# 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 +0100805# (Function for test scripts)
806api_put_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100807 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100808
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100809 if [ "$PMS_VERSION" == "V2" ]; then
810 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
811 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
812 return 1
813 fi
814 else
815 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
816 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
817 return 1
818 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100819 fi
820
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100821 count=0
822 max=1
823 serv=$2
824 ric=$3
825 pt=$4
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100826 pid=$5
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100827 trans=$6
828
829 if [ "$PMS_VERSION" == "V2" ]; then
830 noti=$7
831 temp=$8
832 if [ $# -eq 9 ]; then
833 max=$9
834 fi
835 else
836 temp=$7
837 if [ $# -eq 8 ]; then
838 max=$8
839 fi
840 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100841
842 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100843 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100844
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100845 query="/v2/policies"
846
847 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
848 if [ $trans != "NOTRANSIENT" ]; then
849 inputJson=$inputJson", \"transient\":$trans"
850 fi
851 if [ $pt != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100852 inputJson=$inputJson", \"policytype_id\":\"$pt\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100853 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100854 inputJson=$inputJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100855 fi
856 if [ $noti != "NOURL" ]; then
857 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
858 fi
859 file="./tmp/.p.json"
860 data=$(sed 's/XXX/'${pid}'/g' $temp)
861 inputJson=$inputJson", \"policy_data\":$data"
862 inputJson="{$inputJson}"
863 echo $inputJson > $file
864 else
865 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
866
867 if [ $pt != "NOTYPE" ]; then
868 query=$query"&type=$pt"
869 fi
870
871 if [ $trans != NOTRANSIENT ]; then
872 query=$query"&transient=$trans"
873 fi
874
875 file="./tmp/.p.json"
876 sed 's/XXX/'${pid}'/g' $temp > $file
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200877 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200878 res="$(__do_curl_to_api PA PUT $query $file)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100879 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200880 echo -ne " Executing "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100881 if [ $status -ne $1 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200882 echo " Executed "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100883 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100884 return 1
885 fi
886
887 let pid=$pid+1
888 let count=$count+1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200889 echo -ne " Executed "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100890 done
891 echo ""
892
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100893 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100894 return 0
895}
896
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100897# API Test function: PUT /policy and V2 PUT /policies, to run in batch
898# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
899# 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 +0200900# (Function for test scripts)
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100901
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200902api_put_policy_batch() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100903 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200904
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100905 if [ "$PMS_VERSION" == "V2" ]; then
906 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
907 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
908 return 1
909 fi
910 else
911 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
912 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
913 return 1
914 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200915 fi
916
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100917 count=0
918 max=1
919 serv=$2
920 ric=$3
921 pt=$4
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200922 pid=$5
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100923 trans=$6
924 if [ "$PMS_VERSION" == "V2" ]; then
925 noti=$7
926 temp=$8
927 if [ $# -eq 9 ]; then
928 max=$9
929 fi
930 else
931 temp=$7
932 if [ $# -eq 8 ]; then
933 max=$8
934 fi
935 fi
936
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200937 ARR=""
938 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100939 if [ "$PMS_VERSION" == "V2" ]; then
940 query="/v2/policies"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200941
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100942 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
943 if [ $trans != "NOTRANSIENT" ]; then
944 inputJson=$inputJson", \"transient\":$trans"
945 fi
946 if [ $pt != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100947 inputJson=$inputJson", \"policytype_id\":\"$pt\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100948 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100949 inputJson=$inputJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100950 fi
951 if [ $noti != "NOURL" ]; then
952 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
953 fi
954 file="./tmp/.p.json"
955 data=$(sed 's/XXX/'${pid}'/g' $temp)
956 inputJson=$inputJson", \"policy_data\":$data"
957 inputJson="{$inputJson}"
958 echo $inputJson > $file
959 else
960 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
961
962 if [ $pt != "NOTYPE" ]; then
963 query=$query"&type=$pt"
964 fi
965
966 if [ $trans != NOTRANSIENT ]; then
967 query=$query"&transient=$trans"
968 fi
969 file="./tmp/.p.json"
970 sed 's/XXX/'${pid}'/g' $temp > $file
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200971 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200972 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200973 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200974 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200975
976 if [ $status -ne 200 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200977 echo " Requested(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100978 __log_test_fail_status_code 200 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200979 return 1
980 fi
981 cid=${res:0:${#res}-3}
982 ARR=$ARR" "$cid
983 let pid=$pid+1
984 let count=$count+1
985 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
986 done
987
988 echo ""
989 count=0
990 for cid in $ARR; do
991
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200992 res="$(__do_curl_to_api PA RESPONSE $cid)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200993 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100994 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200995
996 if [ $status -ne $1 ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100997 echo " Accepted(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100998 __log_test_fail_status_code $1 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200999 return 1
1000 fi
1001
1002 let count=$count+1
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001003 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001004 done
1005
1006 echo ""
1007
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001008 __log_test_pass
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001009 return 0
1010}
1011
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001012# 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 +02001013# 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 +01001014# 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 +02001015# (Function for test scripts)
1016api_put_policy_parallel() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001017 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001018
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001019 if [ "$PMS_VERSION" == "V2" ]; then
1020 if [ $# -ne 11 ]; then
1021 __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>" $@
1022 return 1
1023 fi
1024 else
1025 if [ $# -ne 10 ]; then
1026 __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>" $@
1027 return 1
1028 fi
1029 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001030 resp_code=$1; shift;
1031 serv=$1; shift
1032 ric_base=$1; shift;
1033 num_rics=$1; shift;
1034 type=$1; shift;
1035 start_id=$1; shift;
1036 transient=$1; shift;
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001037 if [ "$PMS_VERSION" == "V2" ]; then
1038 noti=$1; shift;
1039 else
1040 noti=""
1041 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001042 template=$1; shift;
1043 count=$1; shift;
1044 pids=$1; shift;
1045
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001046 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001047 if [ $PA_ADAPTER_TYPE != "REST" ]; then
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001048 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1049 echo " Info - will execute over agent REST"
1050 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001051 if [ "$PMS_VERSION" == "V2" ]; then
1052 if [ $serv == "NOSERVICE" ]; then
1053 serv=""
1054 fi
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001055 query="$PMS_API_PREFIX/v2/policies"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001056 else
1057 if [ $serv == "NOSERVICE" ]; then
1058 serv=""
1059 fi
1060 query="/policy?service=$serv"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001061
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001062 if [ $type != "NOTYPE" ]; then
1063 query=$query"&type=$type"
1064 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001065
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001066 if [ $transient != NOTRANSIENT ]; then
1067 query=$query"&transient=$transient"
1068 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001069 fi
1070
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001071 urlbase=${PA_ADAPTER}${query}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001072
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001073 httpproxy="NOPROXY"
1074 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXA483ee332021-04-08 01:35:24 +02001075 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1076 httpproxy=$KUBE_PROXY_PATH
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001077 fi
1078 fi
1079
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001080 for ((i=1; i<=$pids; i++))
1081 do
BjornMagnussonXAad047782020-06-08 15:54:11 +02001082 uuid=$UUID
1083 if [ -z "$uuid" ]; then
1084 uuid="NOUUID"
1085 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001086 echo "" > "./tmp/.pid${i}.res.txt"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001087 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001088 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 +01001089 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001090 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 +01001091 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001092 echo $i
1093 done | xargs -n 1 -I{} -P $pids bash -c '{
1094 arg=$(echo {})
1095 echo " Parallel process $arg started"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001096 tmp=$(< "./tmp/.pid${arg}.txt")
1097 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001098 }'
1099 msg=""
1100 for ((i=1; i<=$pids; i++))
1101 do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001102 file="./tmp/.pid${i}.res.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001103 tmp=$(< $file)
1104 if [ -z "$tmp" ]; then
1105 echo " Process $i : unknown result (result file empty"
1106 msg="failed"
1107 else
1108 res=${tmp:0:1}
1109 if [ $res == "0" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001110 echo " Process $i : OK - "${tmp:1}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001111 else
1112 echo " Process $i : failed - "${tmp:1}
1113 msg="failed"
1114 fi
1115 fi
1116 done
1117 if [ -z $msg ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001118 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001119 return 0
1120 fi
1121
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001122 __log_test_fail_general "One of more processes failed to execute"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001123 return 1
1124}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001125
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001126# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001127# args: <response-code> <policy-id> [count]
1128# (Function for test scripts)
1129api_delete_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001130 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001131
1132 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1133 __print_err "<response-code> <policy-id> [count]" $@
1134 return 1
1135 fi
1136
1137 count=0
1138 max=1
1139
1140 if [ $# -eq 3 ]; then
1141 max=$3
1142 fi
1143
1144 pid=$2
1145
1146 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001147 if [ "$PMS_VERSION" == "V2" ]; then
1148 query="/v2/policies/"$UUID$pid
1149 else
1150 query="/policy?id="$UUID$pid
1151 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001152 res="$(__do_curl_to_api PA DELETE $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001153 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001154 echo -ne " Executing "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001155
1156 if [ $status -ne $1 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001157 echo " Executed "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001158 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001159 return 1
1160 fi
1161 let pid=$pid+1
1162 let count=$count+1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001163 echo -ne " Executed "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001164 done
1165 echo ""
1166
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001167 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001168 return 0
1169}
1170
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001171# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001172# args: <response-code> <policy-id> [count]
1173# (Function for test scripts)
1174api_delete_policy_batch() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001175 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001176
1177 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1178 __print_err "<response-code> <policy-id> [count]" $@
1179 return 1
1180 fi
1181
1182 count=0
1183 max=1
1184
1185 if [ $# -eq 3 ]; then
1186 max=$3
1187 fi
1188
1189 pid=$2
1190 ARR=""
1191 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001192 if [ "$PMS_VERSION" == "V2" ]; then
1193 query="/v2/policies/"$UUID$pid
1194 else
1195 query="/policy?id="$UUID$pid
1196 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001197 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001198 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001199 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001200
1201 if [ $status -ne 200 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001202 echo " Requested(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001203 __log_test_fail_status_code 200 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001204 return 1
1205 fi
1206 cid=${res:0:${#res}-3}
1207 ARR=$ARR" "$cid
1208 let pid=$pid+1
1209 let count=$count+1
1210 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1211 done
1212
1213 echo ""
1214
1215 count=0
1216 for cid in $ARR; do
1217
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001218 res="$(__do_curl_to_api PA RESPONSE $cid)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001219 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001220 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001221
1222 if [ $status -ne $1 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001223 echo " Deleted(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001224 __log_test_fail_status_code $1 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001225 return 1
1226 fi
1227
1228 let count=$count+1
1229 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1230 done
1231
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001232 echo ""
1233
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001234 __log_test_pass
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001235 return 0
1236}
1237
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001238# 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 +02001239# args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1240# (Function for test scripts)
1241api_delete_policy_parallel() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001242 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001243
1244 if [ $# -ne 5 ]; then
1245 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1246 return 1
1247 fi
1248 resp_code=$1; shift;
1249 num_rics=$1; shift;
1250 start_id=$1; shift;
1251 count=$1; shift;
1252 pids=$1; shift;
1253
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001254 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001255 if [ $PA_ADAPTER_TYPE != "REST" ]; then
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001256 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1257 echo " Info - will execute over agent REST"
1258 fi
1259
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001260 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001261 query="$PMS_API_PREFIX/v2/policies/"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001262 else
1263 query="/policy"
1264 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001265
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001266 urlbase=${PA_ADAPTER}${query}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001267
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001268 httpproxy="NOPROXY"
1269 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXA483ee332021-04-08 01:35:24 +02001270 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1271 httpproxy=$KUBE_PROXY_PATH
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001272 fi
1273 fi
1274
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001275 for ((i=1; i<=$pids; i++))
1276 do
BjornMagnussonXAad047782020-06-08 15:54:11 +02001277 uuid=$UUID
1278 if [ -z "$uuid" ]; then
1279 uuid="NOUUID"
1280 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001281 echo "" > "./tmp/.pid${i}.del.res.txt"
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001282 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001283 echo $i
1284 done | xargs -n 1 -I{} -P $pids bash -c '{
1285 arg=$(echo {})
1286 echo " Parallel process $arg started"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001287 tmp=$(< "./tmp/.pid${arg}.del.txt")
1288 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001289 }'
1290 msg=""
1291 for ((i=1; i<=$pids; i++))
1292 do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001293 file="./tmp/.pid${i}.del.res.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001294 tmp=$(< $file)
1295 if [ -z "$tmp" ]; then
1296 echo " Process $i : unknown result (result file empty"
1297 msg="failed"
1298 else
1299 res=${tmp:0:1}
1300 if [ $res == "0" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001301 echo " Process $i : OK - "${tmp:1}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001302 else
1303 echo " Process $i : failed - "${tmp:1}
1304 msg="failed"
1305 fi
1306 fi
1307 done
1308 if [ -z $msg ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001309 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001310 return 0
1311 fi
1312
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001313 __log_test_fail_general "One of more processes failed to execute"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001314 return 1
1315}
1316
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001317# API Test function: GET /policy_ids and V2 GET /v2/policies
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001318# args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1319# (Function for test scripts)
1320api_get_policy_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001321 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001322
1323 if [ $# -lt 4 ]; then
1324 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1325 return 1
1326 fi
1327
1328 queryparams=""
1329
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001330 if [ "$PMS_VERSION" == "V2" ]; then
1331 if [ $2 != "NORIC" ]; then
1332 queryparams="?ric_id="$2
1333 fi
1334
1335 if [ $3 != "NOSERVICE" ]; then
1336 if [ -z $queryparams ]; then
1337 queryparams="?service_id="$3
1338 else
1339 queryparams=$queryparams"&service_id="$3
1340 fi
1341 fi
1342 if [ $4 != "NOTYPE" ]; then
1343 if [ -z $queryparams ]; then
1344 queryparams="?policytype_id="$4
1345 else
1346 queryparams=$queryparams"&policytype_id="$4
1347 fi
1348 fi
1349
1350 query="/v2/policies"$queryparams
1351 else
1352 if [ $2 != "NORIC" ]; then
1353 queryparams="?ric="$2
1354 fi
1355
1356 if [ $3 != "NOSERVICE" ]; then
1357 if [ -z $queryparams ]; then
1358 queryparams="?service="$3
1359 else
1360 queryparams=$queryparams"&service="$3
1361 fi
1362 fi
1363 if [ $4 != "NOTYPE" ]; then
1364 if [ -z $queryparams ]; then
1365 queryparams="?type="$4
1366 else
1367 queryparams=$queryparams"&type="$4
1368 fi
1369 fi
1370
1371 query="/policy_ids"$queryparams
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001372 fi
1373
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001374 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001375 status=${res:${#res}-3}
1376
1377 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001378 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001379 return 1
1380 fi
1381
1382 if [ $# -gt 4 ]; then
1383 body=${res:0:${#res}-3}
1384 targetJson="["
1385
1386 for pid in ${@:5} ; do
1387 if [ "$targetJson" != "[" ]; then
1388 targetJson=$targetJson","
1389 fi
1390 if [ $pid != "NOID" ]; then
BjornMagnussonXAad047782020-06-08 15:54:11 +02001391 targetJson=$targetJson"\"$UUID$pid\""
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001392 fi
1393 done
1394
1395 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001396 if [ "$PMS_VERSION" == "V2" ]; then
1397 targetJson="{\"policy_ids\": $targetJson}"
1398 fi
1399 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1400 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1401
1402 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001403 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001404 return 1
1405 fi
1406 fi
1407
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001408 __log_test_pass
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001409 return 0
1410}
1411
1412# API Test function: V2 GET /v2/policy-types/{policyTypeId}
1413# args(V2): <response-code> <policy-type-id> [<schema-file>]
1414# (Function for test scripts)
1415api_get_policy_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001416 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001417
1418 if [ "$PMS_VERSION" != "V2" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001419 __log_test_fail_not_supported
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001420 return 1
1421 fi
1422
1423 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1424 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1425 return 1
1426 fi
1427 query="/v2/policy-types/$2"
1428
1429 res="$(__do_curl_to_api PA GET $query)"
1430 status=${res:${#res}-3}
1431
1432 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001433 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001434 return 1
1435 fi
1436
1437 if [ $# -eq 3 ]; then
1438
1439 body=${res:0:${#res}-3}
1440
1441 targetJson=$(< $3)
1442 targetJson="{\"policy_schema\":$targetJson}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001443 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001444 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001445
1446 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001447 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001448 return 1
1449 fi
1450 fi
1451
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001452 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001453 return 0
1454}
1455
1456# API Test function: GET /policy_schema
1457# args: <response-code> <policy-type-id> [<schema-file>]
1458# (Function for test scripts)
1459api_get_policy_schema() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001460 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001461
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001462 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001463 __log_test_fail_not_supported
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001464 return 1
1465 fi
1466
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001467 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1468 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1469 return 1
1470 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001471 query="/policy_schema?id=$2"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001472 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001473 status=${res:${#res}-3}
1474
1475 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001476 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001477 return 1
1478 fi
1479
1480 if [ $# -eq 3 ]; then
1481
1482 body=${res:0:${#res}-3}
1483
1484 targetJson=$(< $3)
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001485
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001486 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001487 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001488
1489 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001490 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001491 return 1
1492 fi
1493 fi
1494
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001495 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001496 return 0
1497}
1498
1499# API Test function: GET /policy_schemas
1500# args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001501# args(V2): <response-code>
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001502# (Function for test scripts)
1503api_get_policy_schemas() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001504 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001505
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001506 if [ "$PMS_VERSION" == "V2" ]; then
1507 if [ $# -ne 1 ]; then
1508 __print_err "<response-code>" $@
1509 return 1
1510 fi
1511 else
1512 if [ $# -lt 2 ]; then
1513 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1514 return 1
1515 fi
1516 fi
1517 if [ "$PMS_VERSION" == "V2" ]; then
1518 query="/v2/policy-schemas"
1519 else
1520 query="/policy_schemas"
1521 if [ $2 != "NORIC" ]; then
1522 query=$query"?ric="$2
1523 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001524 fi
1525
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001526 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001527 status=${res:${#res}-3}
1528
1529 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001530 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001531 return 1
1532 fi
1533
1534 if [ $# -gt 2 ]; then
1535 body=${res:0:${#res}-3}
1536 targetJson="["
1537
1538 for file in ${@:3} ; do
1539 if [ "$targetJson" != "[" ]; then
1540 targetJson=$targetJson","
1541 fi
1542 if [ $file == "NOFILE" ]; then
1543 targetJson=$targetJson"{}"
1544 else
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001545 targetJson=$targetJson$(< $file)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001546 fi
1547 done
1548
1549 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001550 if [ "$PMS_VERSION" == "V2" ]; then
1551 targetJson="{\"policy_schemas\": $targetJson }"
1552 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001553 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001554 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001555
1556 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001557 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001558 return 1
1559 fi
1560 fi
1561
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001562 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001563 return 0
1564}
1565
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001566# API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001567# arg: <response-code> <policy-id> (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001568# (Function for test scripts)
1569api_get_policy_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001570 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001571
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001572 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001573 __print_err "<response-code> <policy-id> (STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001574 return 1
1575 fi
1576
1577 targetJson=""
1578
1579 if [ $3 == "STD" ]; then
1580 targetJson="{\"enforceStatus\":\"$4\""
1581 if [ $# -eq 5 ]; then
1582 targetJson=$targetJson",\"reason\":\"$5\""
1583 fi
1584 targetJson=$targetJson"}"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001585 elif [ $3 == "STD2" ]; then
1586 if [ $4 == "EMPTY" ]; then
1587 targetJson="{\"enforceStatus\":\"\""
1588 else
1589 targetJson="{\"enforceStatus\":\"$4\""
1590 fi
1591 if [ $# -eq 5 ]; then
1592 if [ $5 == "EMPTY" ]; then
1593 targetJson=$targetJson",\"enforceReason\":\"\""
1594 else
1595 targetJson=$targetJson",\"enforceReason\":\"$5\""
1596 fi
1597 fi
1598 targetJson=$targetJson"}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001599 elif [ $3 == "OSC" ]; then
1600 targetJson="{\"instance_status\":\"$4\""
1601 if [ $# -eq 5 ]; then
1602 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1603 fi
1604 targetJson=$targetJson",\"created_at\":\"????\"}"
1605 else
1606 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1607 return 1
1608 fi
1609
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001610 if [ "$PMS_VERSION" == "V2" ]; then
1611 query="/v2/policies/$UUID$2/status"
1612 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1613 else
1614 query="/policy_status?id="$UUID$2
1615 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001616
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001617 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001618 status=${res:${#res}-3}
1619
1620 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001621 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001622 return 1
1623 fi
1624
1625 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1626 body=${res:0:${#res}-3}
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001627 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001628
1629 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001630 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001631 return 1
1632 fi
1633
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001634 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001635 return 0
1636}
1637
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001638# API Test function: GET /policy_types and V2 GET /v2/policy-types
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001639# args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1640# (Function for test scripts)
1641api_get_policy_types() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001642 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001643
1644 if [ $# -lt 1 ]; then
1645 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1646 return 1
1647 fi
1648
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001649 if [ "$PMS_VERSION" == "V2" ]; then
1650 if [ $# -eq 1 ]; then
1651 query="/v2/policy-types"
1652 elif [ $2 == "NORIC" ]; then
1653 query="/v2/policy-types"
1654 else
1655 query="/v2/policy-types?ric_id=$2"
1656 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001657 else
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001658 if [ $# -eq 1 ]; then
1659 query="/policy_types"
1660 elif [ $2 == "NORIC" ]; then
1661 query="/policy_types"
1662 else
1663 query="/policy_types?ric=$2"
1664 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001665 fi
1666
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001667 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001668 status=${res:${#res}-3}
1669
1670 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001671 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001672 return 1
1673 fi
1674
1675 if [ $# -gt 2 ]; then
1676 body=${res:0:${#res}-3}
1677 targetJson="["
1678
1679 for pid in ${@:3} ; do
1680 if [ "$targetJson" != "[" ]; then
1681 targetJson=$targetJson","
1682 fi
1683 if [ $pid == "EMPTY" ]; then
1684 pid=""
1685 fi
1686 targetJson=$targetJson"\"$pid\""
1687 done
1688
1689 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001690 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001691 targetJson="{\"policytype_ids\": $targetJson }"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001692 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001693 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001694 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001695
1696 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001697 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001698 return 1
1699 fi
1700 fi
1701
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001702 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001703 return 0
1704}
1705
1706#########################################################
1707#### Test case functions Health check
1708#########################################################
1709
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001710# API Test function: GET /status and V2 GET /status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001711# args: <response-code>
1712# (Function for test scripts)
1713api_get_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001714 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001715 if [ $# -ne 1 ]; then
1716 __print_err "<response-code>" $@
1717 return 1
1718 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001719 if [ "$PMS_VERSION" == "V2" ]; then
1720 query="/v2/status"
1721 else
1722 query="/status"
1723 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001724 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001725 status=${res:${#res}-3}
1726
1727 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001728 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001729 return 1
1730 fi
1731
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001732 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001733 return 0
1734}
1735
1736#########################################################
1737#### Test case functions RIC Repository
1738#########################################################
1739
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001740# API Test function: GET /ric and V2 GET /v2/rics/ric
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001741# args: <reponse-code> <management-element-id> [<ric-id>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001742# (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1743# (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1744# (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1745
1746
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001747# (Function for test scripts)
1748api_get_ric() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001749 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001750
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001751 if [ "$PMS_VERSION" == "V2" ]; then
1752 if [ $# -lt 3 ]; then
1753 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1754 return 1
1755 fi
1756 search=""
1757 if [ $2 != "NOME" ]; then
1758 search="?managed_element_id="$2
1759 fi
1760 if [ $3 != "NORIC" ]; then
1761 if [ -z $search ]; then
1762 search="?ric_id="$3
1763 else
1764 search=$search"&ric_id="$3
1765 fi
1766 fi
1767 query="/v2/rics/ric"$search
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001768
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001769 res="$(__do_curl_to_api PA GET $query)"
1770 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001771
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001772 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001773 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001774 return 1
1775 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001776
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001777 if [ $# -gt 3 ]; then
1778 body=${res:0:${#res}-3}
1779 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1780 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001781 __log_test_fail_general "Could not create target ric info json"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001782 return 1
1783 fi
1784
1785 targetJson=$(<./tmp/.tmp_rics.json)
1786 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1787 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1788 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1789 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001790 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001791 return 1
1792 fi
1793 fi
1794 else
1795 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1796 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1797 return 1
1798 fi
1799
1800 query="/ric?managedElementId="$2
1801
1802 res="$(__do_curl_to_api PA GET $query)"
1803 status=${res:${#res}-3}
1804
1805 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001806 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001807 return 1
1808 fi
1809
1810 if [ $# -eq 3 ]; then
1811 body=${res:0:${#res}-3}
1812 if [ "$body" != "$3" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001813 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001814 return 1
1815 fi
1816 fi
1817 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001818 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001819 return 0
1820}
1821
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001822# API test function: GET /rics and V2 GET /v2/rics
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001823# args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1824# 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_........."
1825# format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1826# (Function for test scripts)
1827api_get_rics() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001828 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001829
1830 if [ $# -lt 2 ]; then
1831 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1832 return 1
1833 fi
1834
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001835 if [ "$PMS_VERSION" == "V2" ]; then
1836 query="/v2/rics"
1837 if [ $2 != "NOTYPE" ]; then
1838 query="/v2/rics?policytype_id="$2
1839 fi
1840 else
1841 query="/rics"
1842 if [ $2 != "NOTYPE" ]; then
1843 query="/rics?policyType="$2
1844 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001845 fi
1846
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001847 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001848 status=${res:${#res}-3}
1849
1850 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001851 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001852 return 1
1853 fi
1854
1855 if [ $# -gt 2 ]; then
1856 body=${res:0:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001857 if [ "$PMS_VERSION" == "V2" ]; then
1858 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
1859 else
1860 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
1861 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001862 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001863 __log_test_fail_general "Could not create target ric info json"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001864 return 1
1865 fi
1866
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001867 targetJson=$(<./tmp/.tmp_rics.json)
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001868 if [ "$PMS_VERSION" == "V2" ]; then
1869 targetJson="{\"rics\": $targetJson }"
1870 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001871 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001872 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001873 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001874 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001875 return 1
1876 fi
1877 fi
1878
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001879 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001880 return 0
1881}
1882
1883##################################################################
1884#### API Test case functions Service registry and supervision ####
1885##################################################################
1886
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001887# API test function: PUT /service and V2 PUT /service
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001888# args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1889# (Function for test scripts)
1890api_put_service() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001891 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001892 if [ $# -ne 4 ]; then
1893 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1894 return 1
1895 fi
1896
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001897 if [ "$PMS_VERSION" == "V2" ]; then
1898 query="/v2/services"
1899 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
1900 else
1901 query="/service"
1902 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1903 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001904 file="./tmp/.tmp.json"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001905 echo "$json" > $file
1906
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001907 res="$(__do_curl_to_api PA PUT $query $file)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001908 status=${res:${#res}-3}
1909
1910 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001911 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001912 return 1
1913 fi
1914
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001915 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001916 return 0
1917}
1918
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001919# API test function: GET /services and V2 GET /v2/services
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001920#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>]* )]
1921# (Function for test scripts)
1922api_get_services() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001923 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001924 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1925 paramError=1
1926 if [ $# -eq 1 ]; then
1927 paramError=0
1928 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1929 paramError=0
1930 elif [ $# -eq 5 ]; then
1931 paramError=0
1932 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1933 argLen=$(($#-2))
1934 if [ $(($argLen%3)) -eq 0 ]; then
1935 paramError=0
1936 fi
1937 fi
1938
1939 if [ $paramError -ne 0 ]; then
1940 __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>]* )]" $@
1941 return 1
1942 fi
1943
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001944 if [ "$PMS_VERSION" == "V2" ]; then
1945 query="/v2/services"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001946
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001947 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1948 query="/v2/services?service_id="$2
1949 fi
1950 else
1951 query="/services"
1952
1953 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1954 query="/services?name="$2
1955 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001956 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001957 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001958 status=${res:${#res}-3}
1959
1960 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001961 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001962 return 1
1963 fi
1964
1965 if [ $# -gt 2 ]; then
1966 variableArgCount=$(($#-2))
1967 body=${res:0:${#res}-3}
1968 targetJson="["
1969 shift; shift;
1970 cntr=0
1971 while [ $cntr -lt $variableArgCount ]; do
1972 servicename=$1; shift;
1973 timeout=$1; shift;
1974 callback=$1; shift;
1975 if [ $cntr -gt 0 ]; then
1976 targetJson=$targetJson","
1977 fi
1978 # timeSinceLastActivitySeconds value cannot be checked since value varies
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001979 if [ "$PMS_VERSION" == "V2" ]; then
1980 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
1981 else
1982 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1983 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001984 let cntr=cntr+3
1985 done
1986 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001987 if [ "$PMS_VERSION" == "V2" ]; then
1988 targetJson="{\"service_list\": $targetJson }"
1989 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001990 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001991 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001992 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001993 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001994 return 1
1995 fi
1996 fi
1997
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001998 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001999 return 0
2000}
2001
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002002# API test function: GET /services V2 GET /v2/services - (only checking service names)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002003# args: <response-code> [<service-name>]*"
2004# (Function for test scripts)
2005api_get_service_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002006 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002007
2008 if [ $# -lt 1 ]; then
2009 __print_err "<response-code> [<service-name>]*" $@
2010 return 1
2011 fi
2012
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002013 if [ "$PMS_VERSION" == "V2" ]; then
2014 query="/v2/services"
2015 else
2016 query="/services"
2017 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002018 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002019 status=${res:${#res}-3}
2020
2021 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002022 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002023 return 1
2024 fi
2025
2026 body=${res:0:${#res}-3}
2027 targetJson="["
2028 for rapp in ${@:2} ; do
2029 if [ "$targetJson" != "[" ]; then
2030 targetJson=$targetJson","
2031 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002032 if [ "$PMS_VERSION" == "V2" ]; then
2033 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2034 else
2035 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2036 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002037 done
2038
2039 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002040 if [ "$PMS_VERSION" == "V2" ]; then
2041 targetJson="{\"service_list\": $targetJson }"
2042 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002043 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002044 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002045
2046 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002047 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002048 return 1
2049 fi
2050
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002051 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002052 return 0
2053}
2054
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002055# API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002056# args: <response-code> <service-name>
2057# (Function for test scripts)
2058api_delete_services() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002059 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002060
2061 if [ $# -ne 2 ]; then
2062 __print_err "<response-code> <service-name>" $@
2063 return 1
2064 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002065 if [ "$PMS_VERSION" == "V2" ]; then
2066 query="/v2/services/"$2
2067 else
2068 query="/services?name="$2
2069 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002070 res="$(__do_curl_to_api PA DELETE $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002071 status=${res:${#res}-3}
2072
2073 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002074 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002075 return 1
2076 fi
2077
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002078 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002079 return 0
2080}
2081
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002082# API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002083# args: <response-code> <service-name>
2084# (Function for test scripts)
2085api_put_services_keepalive() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002086 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002087
2088 if [ $# -ne 2 ]; then
2089 __print_err "<response-code> <service-name>" $@
2090 return 1
2091 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002092 if [ "$PMS_VERSION" == "V2" ]; then
2093 query="/v2/services/$2/keepalive"
2094 else
2095 query="/services/keepalive?name="$2
2096 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002097
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002098 res="$(__do_curl_to_api PA PUT $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002099 status=${res:${#res}-3}
2100
2101 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002102 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002103 return 1
2104 fi
2105
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002106 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002107 return 0
2108}
2109
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002110##################################################################
2111#### API Test case functions Configuration ####
2112##################################################################
2113
2114# API Test function: PUT /v2/configuration
2115# args: <response-code> <config-file>
2116# (Function for test scripts)
2117api_put_configuration() {
2118 __log_test_start $@
2119
2120 if [ "$PMS_VERSION" != "V2" ]; then
2121 __log_test_fail_not_supported
2122 return 1
2123 fi
2124
2125 if [ $# -ne 2 ]; then
2126 __print_err "<response-code> <config-file>" $@
2127 return 1
2128 fi
2129 if [ ! -f $2 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002130 __log_test_fail_general "Config file "$2", does not exist"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002131 return 1
2132 fi
2133 inputJson=$(< $2)
2134 inputJson="{\"config\":"$inputJson"}"
2135 file="./tmp/.config.json"
2136 echo $inputJson > $file
2137 query="/v2/configuration"
2138 res="$(__do_curl_to_api PA PUT $query $file)"
2139 status=${res:${#res}-3}
2140
2141 if [ $status -ne $1 ]; then
2142 __log_test_fail_status_code $1 $status
2143 return 1
2144 fi
2145
2146 __log_test_pass
2147 return 0
2148}
2149
2150# API Test function: GET /v2/configuration
2151# args: <response-code> [<config-file>]
2152# (Function for test scripts)
2153api_get_configuration() {
2154 __log_test_start $@
2155
2156 if [ "$PMS_VERSION" != "V2" ]; then
2157 __log_test_fail_not_supported
2158 return 1
2159 fi
2160
2161 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2162 __print_err "<response-code> [<config-file>]" $@
2163 return 1
2164 fi
2165 if [ ! -f $2 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002166 __log_test_fail_general "Config file "$2" for comparison, does not exist"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002167 return 1
2168 fi
2169
2170 query="/v2/configuration"
2171 res="$(__do_curl_to_api PA GET $query)"
2172 status=${res:${#res}-3}
2173
2174 if [ $status -ne $1 ]; then
2175 __log_test_fail_status_code $1 $status
2176 return 1
2177 fi
2178
2179 if [ $# -eq 2 ]; then
2180
2181 body=${res:0:${#res}-3}
2182
2183 targetJson=$(< $2)
2184 targetJson="{\"config\":"$targetJson"}"
2185 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2186 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2187
2188 if [ $res -ne 0 ]; then
2189 __log_test_fail_body
2190 return 1
2191 fi
2192 fi
2193
2194 __log_test_pass
2195 return 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002196}
2197
2198##########################################
2199#### Reset types and instances ####
2200##########################################
2201
2202# Admin reset to remove all policies and services
2203# All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2204# NOTE - only works in kubernetes and the pod should not be running
2205# args: -
2206# (Function for test scripts)
2207
2208pms_kube_pvc_reset() {
2209 __log_test_start $@
2210
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +02002211 pvc_name=$(kubectl get pvc -n nonrtric --no-headers -o custom-columns=":metadata.name" | grep policy)
2212 if [ -z "$pvc_name" ]; then
2213 pvc_name=policymanagementservice-vardata-pvc
2214 fi
2215 echo " Trying to reset pvc: "$pvc_name
2216 __kube_clean_pvc $POLICY_AGENT_APP_NAME nonrtric $pvc_name /var/policy-management-service/database
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002217
2218 __log_test_pass
2219 return 0
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002220}