blob: 82dde44378bef9612f29f10a19e7e769721e1600 [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"
186 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
187 fi
188
189 if [ $retcode_i -eq 0 ]; then
190
191 echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
192
193 #Check if nonrtric namespace exists, if not create it
194 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
195
196 #Export all vars needed for service and deployment
197 export POLICY_AGENT_APP_NAME
198 export KUBE_NONRTRIC_NAMESPACE
199 export POLICY_AGENT_IMAGE
200 export POLICY_AGENT_INTERNAL_PORT
201 export POLICY_AGENT_INTERNAL_SECURE_PORT
202 export POLICY_AGENT_EXTERNAL_PORT
203 export POLICY_AGENT_EXTERNAL_SECURE_PORT
204 export POLICY_AGENT_CONFIG_MOUNT_PATH
205 export POLICY_AGENT_DATA_MOUNT_PATH
206 export POLICY_AGENT_CONFIG_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-config"
207 export POLICY_AGENT_DATA_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-data"
208 export POLICY_AGENT_PKG_NAME
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200209
210 export POLICY_AGENT_DATA_PV_NAME=$POLICY_AGENT_APP_NAME"-pv"
211 export POLICY_AGENT_DATA_PVC_NAME=$POLICY_AGENT_APP_NAME"-pvc"
212 ##Create a unique path for the pv each time to prevent a previous volume to be reused
213 export POLICY_AGENT_PV_PATH="padata-"$(date +%s)
214 export POLICY_AGENT_CONTAINER_MNT_DIR
215
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100216 if [ $1 == "PROXY" ]; then
217 AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
218 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100219 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
220 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
221 else
222 echo " Configured with http proxy"
223 fi
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100224 else
225 AGENT_HTTP_PROXY_CONFIG_PORT=0
226 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100227 echo " Configured without http proxy"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100228 fi
229 export AGENT_HTTP_PROXY_CONFIG_PORT
230 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME
231
232
233 # Create config map for config
234 configfile=$PWD/tmp/$POLICY_AGENT_CONFIG_FILE
235 cp $2 $configfile
236 output_yaml=$PWD/tmp/pa_cfc.yaml
237 __kube_create_configmap $POLICY_AGENT_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $configfile $output_yaml
238
239 # Create config map for data
240 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
241 if [ $# -lt 3 ]; then
242 #create empty dummy file
243 echo "{}" > $data_json
244 else
245 cp $3 $data_json
246 fi
247 output_yaml=$PWD/tmp/pa_cfd.yaml
248 __kube_create_configmap $POLICY_AGENT_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
249
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200250 ## Create pv
251 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pv.yaml
252 output_yaml=$PWD/tmp/pa_pv.yaml
253 __kube_create_instance pv $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
254
255 ## Create pvc
256 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pvc.yaml
257 output_yaml=$PWD/tmp/pa_pvc.yaml
258 __kube_create_instance pvc $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
259
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100260 # Create service
261 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"svc.yaml
262 output_yaml=$PWD/tmp/pa_svc.yaml
263 __kube_create_instance service $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
264
265 # Create app
266 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"app.yaml
267 output_yaml=$PWD/tmp/pa_app.yaml
268 __kube_create_instance app $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
269
270 fi
271
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200272 # 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 +0200273 if [ $retcode_i -eq 0 ]; then
274 __PA_WORKER_NODE=$(kubectl get pod -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
275 if [ -z "$__PA_WORKER_NODE" ]; then
276 echo -e $YELLOW" Cannot find worker node for pod for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
277 fi
278 else
279 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 +0200280 fi
281
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100282 echo " Retrieving host and ports for service..."
283 PA_HOST_NAME=$(__kube_get_service_host $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
284 POLICY_AGENT_EXTERNAL_PORT=$(__kube_get_service_port $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
285 POLICY_AGENT_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
286
287 echo " Host IP, http port, https port: $PA_HOST_NAME $POLICY_AGENT_EXTERNAL_PORT $POLICY_AGENT_EXTERNAL_SECURE_PORT"
288
289 if [ $PA_HTTPX == "http" ]; then
290 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
291 else
292 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_SECURE_PORT
293 fi
294 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
295
296 if [ $PA_ADAPTER_TYPE == "REST" ]; then
297 PA_ADAPTER=$PA_PATH
298 fi
299 else
300 __check_included_image 'PA'
301 if [ $? -eq 1 ]; then
302 echo -e $RED"The Policy Agent app is not included in this test script"$ERED
303 echo -e $RED"The Policy Agent will not be started"$ERED
304 exit
305 fi
306
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200307 curdir=$PWD
308 cd $SIM_GROUP
309 cd policy_agent
310 cd $POLICY_AGENT_HOST_MNT_DIR
311 #cd ..
312 if [ -d db ]; then
313 if [ "$(ls -A $DIR)" ]; then
314 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
315 rm -rf db/* &> /dev/null
316 if [ $? -ne 0 ]; then
317 echo -e $RED" Cannot remove database files in: $PWD"$ERED
318 exit 1
319 fi
320 fi
321 else
322 echo " No files in mounted dir or dir does not exists"
323 fi
324 cd $curdir
325
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100326 #Export all vars needed for docker-compose
327 export POLICY_AGENT_APP_NAME
328 export POLICY_AGENT_APP_NAME_ALIAS
329 export POLICY_AGENT_INTERNAL_PORT
330 export POLICY_AGENT_EXTERNAL_PORT
331 export POLICY_AGENT_INTERNAL_SECURE_PORT
332 export POLICY_AGENT_EXTERNAL_SECURE_PORT
333 export CONSUL_HOST
334 export CONSUL_INTERNAL_PORT
335 export CONFIG_BINDING_SERVICE
336 export POLICY_AGENT_CONFIG_KEY
337 export DOCKER_SIM_NWNAME
338 export POLICY_AGENT_HOST_MNT_DIR
339 export POLICY_AGENT_CONFIG_MOUNT_PATH
340 export POLICY_AGENT_CONFIG_FILE
341 export POLICY_AGENT_PKG_NAME
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100342 export POLICY_AGENT_DISPLAY_NAME
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200343 export POLICY_AGENT_CONTAINER_MNT_DIR
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100344
345 if [ $1 == "PROXY" ]; then
346 AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
347 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100348 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
349 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
350 else
351 echo " Configured with http proxy"
352 fi
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100353 else
354 AGENT_HTTP_PROXY_CONFIG_PORT=0
355 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100356 echo " Configured without http proxy"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100357 fi
358 export AGENT_HTTP_PROXY_CONFIG_PORT
359 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME
360
361 dest_file=$SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_HOST_MNT_DIR/application.yaml
362
363 envsubst < $2 > $dest_file
364
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100365 __start_container $POLICY_AGENT_COMPOSE_DIR "" NODOCKERARGS 1 $POLICY_AGENT_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100366
367 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
368 fi
369 echo ""
370 return 0
371}
372
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200373# Stop the policy agent
374# args: -
375# args: -
376# (Function for test scripts)
377stop_policy_agent() {
378 echo -e $BOLD"Stopping $POLICY_AGENT_DISPLAY_NAME"$EBOLD
379
380 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200381
382 __check_prestarted_image "PA"
383 if [ $? -eq 0 ]; then
384 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
385 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
386 return 0
387 fi
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200388 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
389 echo " Deleting the replica set - a new will be started when the app is started"
390 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
391 if [ $? -ne 0 ]; then
392 echo -e $RED" Could not delete replica set "$RED
393 ((RES_CONF_FAIL++))
394 return 1
395 fi
396 else
397 docker stop $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
398 if [ $? -ne 0 ]; then
399 __print_err "Could not stop $POLICY_AGENT_APP_NAME" $@
400 cat ./tmp/.dockererr
401 ((RES_CONF_FAIL++))
402 return 1
403 fi
404 fi
405 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
406 echo ""
407 return 0
408}
409
410# Start a previously stopped policy agent
411# args: -
412# (Function for test scripts)
413start_stopped_policy_agent() {
414 echo -e $BOLD"Starting (the previously stopped) $POLICY_AGENT_DISPLAY_NAME"$EBOLD
415
416 if [ $RUNMODE == "KUBE" ]; then
417
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200418 __check_prestarted_image "PA"
419 if [ $? -eq 0 ]; then
420 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
421 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
422 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
423 return 0
424 fi
425
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200426 # Tie the PMS to the same worker node it was initially started on
427 # 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
428 if [ -z "$__PA_WORKER_NODE" ]; then
429 echo -e $RED" No initial worker node found for pod "$RED
430 ((RES_CONF_FAIL++))
431 return 1
432 else
433 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
434 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
435 tmp=$(kubectl patch deployment $POLICY_AGENT_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__PA_WORKER_NODE'"}}}}}')
436 if [ $? -ne 0 ]; then
437 echo -e $YELLOW" Cannot set nodeSelector to deployment for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
438 fi
439 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
440 fi
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200441 else
442 docker start $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
443 if [ $? -ne 0 ]; then
444 __print_err "Could not start (the stopped) $POLICY_AGENT_APP_NAME" $@
445 cat ./tmp/.dockererr
446 ((RES_CONF_FAIL++))
447 return 1
448 fi
449 fi
450 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
451 if [ $? -ne 0 ]; then
452 return 1
453 fi
454 echo ""
455 return 0
456}
457
458
459
BjornMagnussonXA366e36a2021-01-27 11:48:56 +0100460# Load the the appl config for the agent into a config map
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100461agent_load_config() {
462 echo -e $BOLD"Agent - load config from "$EBOLD$1
463 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
464 cp $1 $data_json
465 output_yaml=$PWD/tmp/pa_cfd.yaml
466 __kube_create_configmap $POLICY_AGENT_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100467 echo ""
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100468}
469
470
471# Turn on debug level tracing in the agent
472# args: -
473# (Function for test scripts)
474set_agent_debug() {
475 echo -e $BOLD"Setting agent debug logging"$EBOLD
476 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
477 result=$(__do_curl "$curlString")
478 if [ $? -ne 0 ]; then
479 __print_err "could not set debug mode" $@
480 ((RES_CONF_FAIL++))
481 return 1
482 fi
483 echo ""
484 return 0
485}
486
487# Turn on trace level tracing in the agent
488# args: -
489# (Function for test scripts)
490set_agent_trace() {
491 echo -e $BOLD"Setting agent trace logging"$EBOLD
492 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
493 result=$(__do_curl "$curlString")
494 if [ $? -ne 0 ]; then
495 __print_err "could not set trace mode" $@
496 ((RES_CONF_FAIL++))
497 return 1
498 fi
499 echo ""
500 return 0
501}
502
503# Perform curl retries when making direct call to the agent for the specified http response codes
504# Speace separated list of http response codes
505# args: [<response-code>]*
506use_agent_retries() {
507 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
508 AGENT_RETRY_CODES=$@
509 echo ""
510 return
511}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100512
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100513# Check the agent logs for WARNINGs and ERRORs
514# args: -
515# (Function for test scripts)
516check_policy_agent_logs() {
517 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
518}
519
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100520#########################################################
521#### Test case functions A1 Policy management service
522#########################################################
523
524# This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
525# This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
526# args: json:<url> <target-value> [<timeout-in-seconds]
527# (Function for test scripts)
528api_equal() {
529 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
530 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
531 if [[ $1 == "json:"* ]]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100532 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100533 __var_test "Policy Agent" $PA_PATH$PMS_API_PREFIX"/v2/" $1 "=" $2 $3
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100534 else
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100535 __var_test "Policy Agent" $PA_PATH"/" $1 "=" $2 $3
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100536 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100537 return 0
538 fi
539 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100540 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
541 return 1
542}
543
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100544# API Test function: GET /policies and V2 GET /v2/policy-instances
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100545# 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>]*]
546# 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 +0100547# (Function for test scripts)
548api_get_policies() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100549 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100550
551 if [ "$PMS_VERSION" == "V2" ]; then
552 paramError=0
553 variableParams=$(($#-4))
554 if [ $# -lt 4 ]; then
555 paramError=1
556 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
557 paramError=1
558 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
559 paramError=1
560 fi
561
562 if [ $paramError -ne 0 ]; then
563 __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>]*]" $@
564 return 1
565 fi
566 else
567 paramError=0
568 variableParams=$(($#-4))
569 if [ $# -lt 4 ]; then
570 paramError=1
571 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
572 paramError=1
573 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
574 paramError=1
575 fi
576
577 if [ $paramError -ne 0 ]; then
578 __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>]*]" $@
579 return 1
580 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100581 fi
582
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100583 queryparams=""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100584 if [ "$PMS_VERSION" == "V2" ]; then
585 if [ $2 != "NORIC" ]; then
586 queryparams="?ric_id="$2
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100587 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100588 if [ $3 != "NOSERVICE" ]; then
589 if [ -z $queryparams ]; then
590 queryparams="?service_id="$3
591 else
592 queryparams=$queryparams"&service_id="$3
593 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100594 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100595 if [ $4 != "NOTYPE" ]; then
596 if [ -z $queryparams ]; then
597 queryparams="?policytype_id="$4
598 else
599 queryparams=$queryparams"&policytype_id="$4
600 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100601 fi
602
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100603 query="/v2/policy-instances"$queryparams
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100604 res="$(__do_curl_to_api PA GET $query)"
605 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100606
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100607 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100608 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100609 return 1
610 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100611
612 if [ $# -gt 4 ]; then
613 body=${res:0:${#res}-3}
614 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
615 targetJson="["
616 else
617 targetJson="["
618 arr=(${@:5})
619
620 for ((i=0; i<$(($#-4)); i=i+7)); do
621
622 if [ "$targetJson" != "[" ]; then
623 targetJson=$targetJson","
624 fi
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100625 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 +0100626 if [ "${arr[$i+3]}" == "EMPTY" ]; then
627 targetJson=$targetJson"\"\","
628 else
629 targetJson=$targetJson"\"${arr[$i+3]}\","
630 fi
631 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
632 file="./tmp/.p.json"
633 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
634 json=$(cat $file)
635 targetJson=$targetJson"\"policy_data\":"$json"}"
636 done
637 fi
638
639 targetJson=$targetJson"]"
640 targetJson="{\"policies\": $targetJson}"
641 echo "TARGET JSON: $targetJson" >> $HTTPLOG
642 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
643
644 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100645 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100646 return 1
647 fi
648 fi
649 else
650 if [ $2 != "NORIC" ]; then
651 queryparams="?ric="$2
652 fi
653 if [ $3 != "NOSERVICE" ]; then
654 if [ -z $queryparams ]; then
655 queryparams="?service="$3
656 else
657 queryparams=$queryparams"&service="$3
658 fi
659 fi
660 if [ $4 != "NOTYPE" ]; then
661 if [ -z $queryparams ]; then
662 queryparams="?type="$4
663 else
664 queryparams=$queryparams"&type="$4
665 fi
666 fi
667
668 query="/policies"$queryparams
669 res="$(__do_curl_to_api PA GET $query)"
670 status=${res:${#res}-3}
671
672 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100673 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100674 return 1
675 fi
676
677 if [ $# -gt 4 ]; then
678 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
679 targetJson="["
680 else
681 body=${res:0:${#res}-3}
682 targetJson="["
683 arr=(${@:5})
684
685 for ((i=0; i<$(($#-4)); i=i+5)); do
686
687 if [ "$targetJson" != "[" ]; then
688 targetJson=$targetJson","
689 fi
690 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
691 if [ "${arr[$i+3]}" == "EMPTY" ]; then
692 targetJson=$targetJson"\"\","
693 else
694 targetJson=$targetJson"\"${arr[$i+3]}\","
695 fi
696 file="./tmp/.p.json"
697 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
698 json=$(cat $file)
699 targetJson=$targetJson"\"json\":"$json"}"
700 done
701 fi
702
703 targetJson=$targetJson"]"
704 echo "TARGET JSON: $targetJson" >> $HTTPLOG
705 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
706
707 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100708 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100709 return 1
710 fi
711 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100712 fi
713
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100714 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100715 return 0
716
717}
718
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100719
720# API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
721# args: <response-code> <policy-id> [<template-file>]
722# args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
723
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100724# (Function for test scripts)
725api_get_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100726 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100727
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100728
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100729 if [ "$PMS_VERSION" == "V2" ]; then
730 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
731 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
732 return 1
733 fi
734 query="/v2/policies/$UUID$2"
735 else
736 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
737 __print_err "<response-code> <policy-id> [<template-file>] " $@
738 return 1
739 fi
740 query="/policy?id=$UUID$2"
741 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200742 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100743 status=${res:${#res}-3}
744
745 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100746 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100747 return 1
748 fi
749
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100750 if [ "$PMS_VERSION" == "V2" ]; then
751 if [ $# -eq 8 ]; then
752
753 #Create a policy json to compare with
754 body=${res:0:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100755
756 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
757 if [ $7 != "NOTRANSIENT" ]; then
758 targetJson=$targetJson", \"transient\":$7"
759 fi
760 if [ $6 != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100761 targetJson=$targetJson", \"policytype_id\":\"$6\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100762 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100763 targetJson=$targetJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100764 fi
765 if [ $8 != "NOURL" ]; then
766 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
767 fi
768
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100769 data=$(sed 's/XXX/'${2}'/g' $3)
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100770 targetJson=$targetJson", \"policy_data\":$data"
771 targetJson="{$targetJson}"
772
773 echo "TARGET JSON: $targetJson" >> $HTTPLOG
774 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
775 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100776 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100777 return 1
778 fi
779 fi
780 else
781 if [ $# -eq 3 ]; then
782 #Create a policy json to compare with
783 body=${res:0:${#res}-3}
784 file="./tmp/.p.json"
785 sed 's/XXX/'${2}'/g' $3 > $file
786 targetJson=$(< $file)
787 echo "TARGET JSON: $targetJson" >> $HTTPLOG
788 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
789 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100790 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100791 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100792 fi
793 fi
794
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100795 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100796 return 0
797}
798
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100799# API Test function: PUT /policy and V2 PUT /policies
800# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
801# 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 +0100802# (Function for test scripts)
803api_put_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100804 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100805
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100806 if [ "$PMS_VERSION" == "V2" ]; then
807 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
808 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
809 return 1
810 fi
811 else
812 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
813 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
814 return 1
815 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100816 fi
817
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100818 count=0
819 max=1
820 serv=$2
821 ric=$3
822 pt=$4
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100823 pid=$5
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100824 trans=$6
825
826 if [ "$PMS_VERSION" == "V2" ]; then
827 noti=$7
828 temp=$8
829 if [ $# -eq 9 ]; then
830 max=$9
831 fi
832 else
833 temp=$7
834 if [ $# -eq 8 ]; then
835 max=$8
836 fi
837 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100838
839 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100840 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100841
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100842 query="/v2/policies"
843
844 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
845 if [ $trans != "NOTRANSIENT" ]; then
846 inputJson=$inputJson", \"transient\":$trans"
847 fi
848 if [ $pt != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100849 inputJson=$inputJson", \"policytype_id\":\"$pt\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100850 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100851 inputJson=$inputJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100852 fi
853 if [ $noti != "NOURL" ]; then
854 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
855 fi
856 file="./tmp/.p.json"
857 data=$(sed 's/XXX/'${pid}'/g' $temp)
858 inputJson=$inputJson", \"policy_data\":$data"
859 inputJson="{$inputJson}"
860 echo $inputJson > $file
861 else
862 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
863
864 if [ $pt != "NOTYPE" ]; then
865 query=$query"&type=$pt"
866 fi
867
868 if [ $trans != NOTRANSIENT ]; then
869 query=$query"&transient=$trans"
870 fi
871
872 file="./tmp/.p.json"
873 sed 's/XXX/'${pid}'/g' $temp > $file
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200874 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200875 res="$(__do_curl_to_api PA PUT $query $file)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100876 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200877 echo -ne " Executing "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100878 if [ $status -ne $1 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200879 echo " Executed "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100880 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100881 return 1
882 fi
883
884 let pid=$pid+1
885 let count=$count+1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200886 echo -ne " Executed "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100887 done
888 echo ""
889
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100890 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100891 return 0
892}
893
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100894# API Test function: PUT /policy and V2 PUT /policies, to run in batch
895# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
896# 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 +0200897# (Function for test scripts)
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100898
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200899api_put_policy_batch() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100900 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200901
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100902 if [ "$PMS_VERSION" == "V2" ]; then
903 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
904 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
905 return 1
906 fi
907 else
908 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
909 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
910 return 1
911 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200912 fi
913
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100914 count=0
915 max=1
916 serv=$2
917 ric=$3
918 pt=$4
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200919 pid=$5
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100920 trans=$6
921 if [ "$PMS_VERSION" == "V2" ]; then
922 noti=$7
923 temp=$8
924 if [ $# -eq 9 ]; then
925 max=$9
926 fi
927 else
928 temp=$7
929 if [ $# -eq 8 ]; then
930 max=$8
931 fi
932 fi
933
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200934 ARR=""
935 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100936 if [ "$PMS_VERSION" == "V2" ]; then
937 query="/v2/policies"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200938
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100939 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
940 if [ $trans != "NOTRANSIENT" ]; then
941 inputJson=$inputJson", \"transient\":$trans"
942 fi
943 if [ $pt != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100944 inputJson=$inputJson", \"policytype_id\":\"$pt\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100945 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100946 inputJson=$inputJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100947 fi
948 if [ $noti != "NOURL" ]; then
949 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
950 fi
951 file="./tmp/.p.json"
952 data=$(sed 's/XXX/'${pid}'/g' $temp)
953 inputJson=$inputJson", \"policy_data\":$data"
954 inputJson="{$inputJson}"
955 echo $inputJson > $file
956 else
957 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
958
959 if [ $pt != "NOTYPE" ]; then
960 query=$query"&type=$pt"
961 fi
962
963 if [ $trans != NOTRANSIENT ]; then
964 query=$query"&transient=$trans"
965 fi
966 file="./tmp/.p.json"
967 sed 's/XXX/'${pid}'/g' $temp > $file
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200968 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200969 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200970 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200971 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200972
973 if [ $status -ne 200 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200974 echo " Requested(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100975 __log_test_fail_status_code 200 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200976 return 1
977 fi
978 cid=${res:0:${#res}-3}
979 ARR=$ARR" "$cid
980 let pid=$pid+1
981 let count=$count+1
982 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
983 done
984
985 echo ""
986 count=0
987 for cid in $ARR; do
988
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200989 res="$(__do_curl_to_api PA RESPONSE $cid)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200990 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100991 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200992
993 if [ $status -ne $1 ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100994 echo " Accepted(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100995 __log_test_fail_status_code $1 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200996 return 1
997 fi
998
999 let count=$count+1
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001000 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001001 done
1002
1003 echo ""
1004
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001005 __log_test_pass
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001006 return 0
1007}
1008
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001009# 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 +02001010# 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 +01001011# 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 +02001012# (Function for test scripts)
1013api_put_policy_parallel() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001014 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001015
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001016 if [ "$PMS_VERSION" == "V2" ]; then
1017 if [ $# -ne 11 ]; then
1018 __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>" $@
1019 return 1
1020 fi
1021 else
1022 if [ $# -ne 10 ]; then
1023 __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>" $@
1024 return 1
1025 fi
1026 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001027 resp_code=$1; shift;
1028 serv=$1; shift
1029 ric_base=$1; shift;
1030 num_rics=$1; shift;
1031 type=$1; shift;
1032 start_id=$1; shift;
1033 transient=$1; shift;
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001034 if [ "$PMS_VERSION" == "V2" ]; then
1035 noti=$1; shift;
1036 else
1037 noti=""
1038 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001039 template=$1; shift;
1040 count=$1; shift;
1041 pids=$1; shift;
1042
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001043 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001044 if [ $PA_ADAPTER_TYPE != "REST" ]; then
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001045 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1046 echo " Info - will execute over agent REST"
1047 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001048 if [ "$PMS_VERSION" == "V2" ]; then
1049 if [ $serv == "NOSERVICE" ]; then
1050 serv=""
1051 fi
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001052 query="$PMS_API_PREFIX/v2/policies"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001053 else
1054 if [ $serv == "NOSERVICE" ]; then
1055 serv=""
1056 fi
1057 query="/policy?service=$serv"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001058
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001059 if [ $type != "NOTYPE" ]; then
1060 query=$query"&type=$type"
1061 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001062
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001063 if [ $transient != NOTRANSIENT ]; then
1064 query=$query"&transient=$transient"
1065 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001066 fi
1067
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001068 urlbase=${PA_ADAPTER}${query}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001069
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001070 httpproxy="NOPROXY"
1071 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXA483ee332021-04-08 01:35:24 +02001072 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1073 httpproxy=$KUBE_PROXY_PATH
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001074 fi
1075 fi
1076
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001077 for ((i=1; i<=$pids; i++))
1078 do
BjornMagnussonXAad047782020-06-08 15:54:11 +02001079 uuid=$UUID
1080 if [ -z "$uuid" ]; then
1081 uuid="NOUUID"
1082 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001083 echo "" > "./tmp/.pid${i}.res.txt"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001084 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001085 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 +01001086 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001087 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 +01001088 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001089 echo $i
1090 done | xargs -n 1 -I{} -P $pids bash -c '{
1091 arg=$(echo {})
1092 echo " Parallel process $arg started"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001093 tmp=$(< "./tmp/.pid${arg}.txt")
1094 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001095 }'
1096 msg=""
1097 for ((i=1; i<=$pids; i++))
1098 do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001099 file="./tmp/.pid${i}.res.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001100 tmp=$(< $file)
1101 if [ -z "$tmp" ]; then
1102 echo " Process $i : unknown result (result file empty"
1103 msg="failed"
1104 else
1105 res=${tmp:0:1}
1106 if [ $res == "0" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001107 echo " Process $i : OK - "${tmp:1}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001108 else
1109 echo " Process $i : failed - "${tmp:1}
1110 msg="failed"
1111 fi
1112 fi
1113 done
1114 if [ -z $msg ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001115 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001116 return 0
1117 fi
1118
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001119 __log_test_fail_general "One of more processes failed to execute"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001120 return 1
1121}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001122
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001123# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001124# args: <response-code> <policy-id> [count]
1125# (Function for test scripts)
1126api_delete_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001127 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001128
1129 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1130 __print_err "<response-code> <policy-id> [count]" $@
1131 return 1
1132 fi
1133
1134 count=0
1135 max=1
1136
1137 if [ $# -eq 3 ]; then
1138 max=$3
1139 fi
1140
1141 pid=$2
1142
1143 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001144 if [ "$PMS_VERSION" == "V2" ]; then
1145 query="/v2/policies/"$UUID$pid
1146 else
1147 query="/policy?id="$UUID$pid
1148 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001149 res="$(__do_curl_to_api PA DELETE $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001150 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001151 echo -ne " Executing "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001152
1153 if [ $status -ne $1 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001154 echo " Executed "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001155 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001156 return 1
1157 fi
1158 let pid=$pid+1
1159 let count=$count+1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001160 echo -ne " Executed "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001161 done
1162 echo ""
1163
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001164 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001165 return 0
1166}
1167
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001168# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001169# args: <response-code> <policy-id> [count]
1170# (Function for test scripts)
1171api_delete_policy_batch() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001172 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001173
1174 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1175 __print_err "<response-code> <policy-id> [count]" $@
1176 return 1
1177 fi
1178
1179 count=0
1180 max=1
1181
1182 if [ $# -eq 3 ]; then
1183 max=$3
1184 fi
1185
1186 pid=$2
1187 ARR=""
1188 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001189 if [ "$PMS_VERSION" == "V2" ]; then
1190 query="/v2/policies/"$UUID$pid
1191 else
1192 query="/policy?id="$UUID$pid
1193 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001194 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001195 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001196 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001197
1198 if [ $status -ne 200 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001199 echo " Requested(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001200 __log_test_fail_status_code 200 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001201 return 1
1202 fi
1203 cid=${res:0:${#res}-3}
1204 ARR=$ARR" "$cid
1205 let pid=$pid+1
1206 let count=$count+1
1207 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1208 done
1209
1210 echo ""
1211
1212 count=0
1213 for cid in $ARR; do
1214
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001215 res="$(__do_curl_to_api PA RESPONSE $cid)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001216 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001217 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001218
1219 if [ $status -ne $1 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001220 echo " Deleted(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001221 __log_test_fail_status_code $1 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001222 return 1
1223 fi
1224
1225 let count=$count+1
1226 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1227 done
1228
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001229 echo ""
1230
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001231 __log_test_pass
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001232 return 0
1233}
1234
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001235# 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 +02001236# args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1237# (Function for test scripts)
1238api_delete_policy_parallel() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001239 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001240
1241 if [ $# -ne 5 ]; then
1242 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1243 return 1
1244 fi
1245 resp_code=$1; shift;
1246 num_rics=$1; shift;
1247 start_id=$1; shift;
1248 count=$1; shift;
1249 pids=$1; shift;
1250
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001251 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001252 if [ $PA_ADAPTER_TYPE != "REST" ]; then
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001253 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1254 echo " Info - will execute over agent REST"
1255 fi
1256
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001257 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001258 query="$PMS_API_PREFIX/v2/policies/"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001259 else
1260 query="/policy"
1261 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001262
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001263 urlbase=${PA_ADAPTER}${query}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001264
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001265 httpproxy="NOPROXY"
1266 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXA483ee332021-04-08 01:35:24 +02001267 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1268 httpproxy=$KUBE_PROXY_PATH
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001269 fi
1270 fi
1271
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001272 for ((i=1; i<=$pids; i++))
1273 do
BjornMagnussonXAad047782020-06-08 15:54:11 +02001274 uuid=$UUID
1275 if [ -z "$uuid" ]; then
1276 uuid="NOUUID"
1277 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001278 echo "" > "./tmp/.pid${i}.del.res.txt"
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001279 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001280 echo $i
1281 done | xargs -n 1 -I{} -P $pids bash -c '{
1282 arg=$(echo {})
1283 echo " Parallel process $arg started"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001284 tmp=$(< "./tmp/.pid${arg}.del.txt")
1285 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001286 }'
1287 msg=""
1288 for ((i=1; i<=$pids; i++))
1289 do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001290 file="./tmp/.pid${i}.del.res.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001291 tmp=$(< $file)
1292 if [ -z "$tmp" ]; then
1293 echo " Process $i : unknown result (result file empty"
1294 msg="failed"
1295 else
1296 res=${tmp:0:1}
1297 if [ $res == "0" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001298 echo " Process $i : OK - "${tmp:1}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001299 else
1300 echo " Process $i : failed - "${tmp:1}
1301 msg="failed"
1302 fi
1303 fi
1304 done
1305 if [ -z $msg ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001306 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001307 return 0
1308 fi
1309
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001310 __log_test_fail_general "One of more processes failed to execute"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001311 return 1
1312}
1313
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001314# API Test function: GET /policy_ids and V2 GET /v2/policies
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001315# args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1316# (Function for test scripts)
1317api_get_policy_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001318 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001319
1320 if [ $# -lt 4 ]; then
1321 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1322 return 1
1323 fi
1324
1325 queryparams=""
1326
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001327 if [ "$PMS_VERSION" == "V2" ]; then
1328 if [ $2 != "NORIC" ]; then
1329 queryparams="?ric_id="$2
1330 fi
1331
1332 if [ $3 != "NOSERVICE" ]; then
1333 if [ -z $queryparams ]; then
1334 queryparams="?service_id="$3
1335 else
1336 queryparams=$queryparams"&service_id="$3
1337 fi
1338 fi
1339 if [ $4 != "NOTYPE" ]; then
1340 if [ -z $queryparams ]; then
1341 queryparams="?policytype_id="$4
1342 else
1343 queryparams=$queryparams"&policytype_id="$4
1344 fi
1345 fi
1346
1347 query="/v2/policies"$queryparams
1348 else
1349 if [ $2 != "NORIC" ]; then
1350 queryparams="?ric="$2
1351 fi
1352
1353 if [ $3 != "NOSERVICE" ]; then
1354 if [ -z $queryparams ]; then
1355 queryparams="?service="$3
1356 else
1357 queryparams=$queryparams"&service="$3
1358 fi
1359 fi
1360 if [ $4 != "NOTYPE" ]; then
1361 if [ -z $queryparams ]; then
1362 queryparams="?type="$4
1363 else
1364 queryparams=$queryparams"&type="$4
1365 fi
1366 fi
1367
1368 query="/policy_ids"$queryparams
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001369 fi
1370
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001371 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001372 status=${res:${#res}-3}
1373
1374 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001375 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001376 return 1
1377 fi
1378
1379 if [ $# -gt 4 ]; then
1380 body=${res:0:${#res}-3}
1381 targetJson="["
1382
1383 for pid in ${@:5} ; do
1384 if [ "$targetJson" != "[" ]; then
1385 targetJson=$targetJson","
1386 fi
1387 if [ $pid != "NOID" ]; then
BjornMagnussonXAad047782020-06-08 15:54:11 +02001388 targetJson=$targetJson"\"$UUID$pid\""
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001389 fi
1390 done
1391
1392 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001393 if [ "$PMS_VERSION" == "V2" ]; then
1394 targetJson="{\"policy_ids\": $targetJson}"
1395 fi
1396 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1397 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1398
1399 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001400 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001401 return 1
1402 fi
1403 fi
1404
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001405 __log_test_pass
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001406 return 0
1407}
1408
1409# API Test function: V2 GET /v2/policy-types/{policyTypeId}
1410# args(V2): <response-code> <policy-type-id> [<schema-file>]
1411# (Function for test scripts)
1412api_get_policy_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001413 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001414
1415 if [ "$PMS_VERSION" != "V2" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001416 __log_test_fail_not_supported
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001417 return 1
1418 fi
1419
1420 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1421 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1422 return 1
1423 fi
1424 query="/v2/policy-types/$2"
1425
1426 res="$(__do_curl_to_api PA GET $query)"
1427 status=${res:${#res}-3}
1428
1429 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001430 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001431 return 1
1432 fi
1433
1434 if [ $# -eq 3 ]; then
1435
1436 body=${res:0:${#res}-3}
1437
1438 targetJson=$(< $3)
1439 targetJson="{\"policy_schema\":$targetJson}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001440 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001441 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001442
1443 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001444 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001445 return 1
1446 fi
1447 fi
1448
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001449 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001450 return 0
1451}
1452
1453# API Test function: GET /policy_schema
1454# args: <response-code> <policy-type-id> [<schema-file>]
1455# (Function for test scripts)
1456api_get_policy_schema() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001457 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001458
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001459 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001460 __log_test_fail_not_supported
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001461 return 1
1462 fi
1463
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001464 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1465 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1466 return 1
1467 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001468 query="/policy_schema?id=$2"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001469 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001470 status=${res:${#res}-3}
1471
1472 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001473 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001474 return 1
1475 fi
1476
1477 if [ $# -eq 3 ]; then
1478
1479 body=${res:0:${#res}-3}
1480
1481 targetJson=$(< $3)
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001482
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001483 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001484 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001485
1486 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001487 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001488 return 1
1489 fi
1490 fi
1491
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001492 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001493 return 0
1494}
1495
1496# API Test function: GET /policy_schemas
1497# args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001498# args(V2): <response-code>
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001499# (Function for test scripts)
1500api_get_policy_schemas() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001501 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001502
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001503 if [ "$PMS_VERSION" == "V2" ]; then
1504 if [ $# -ne 1 ]; then
1505 __print_err "<response-code>" $@
1506 return 1
1507 fi
1508 else
1509 if [ $# -lt 2 ]; then
1510 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1511 return 1
1512 fi
1513 fi
1514 if [ "$PMS_VERSION" == "V2" ]; then
1515 query="/v2/policy-schemas"
1516 else
1517 query="/policy_schemas"
1518 if [ $2 != "NORIC" ]; then
1519 query=$query"?ric="$2
1520 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001521 fi
1522
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001523 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001524 status=${res:${#res}-3}
1525
1526 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001527 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001528 return 1
1529 fi
1530
1531 if [ $# -gt 2 ]; then
1532 body=${res:0:${#res}-3}
1533 targetJson="["
1534
1535 for file in ${@:3} ; do
1536 if [ "$targetJson" != "[" ]; then
1537 targetJson=$targetJson","
1538 fi
1539 if [ $file == "NOFILE" ]; then
1540 targetJson=$targetJson"{}"
1541 else
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001542 targetJson=$targetJson$(< $file)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001543 fi
1544 done
1545
1546 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001547 if [ "$PMS_VERSION" == "V2" ]; then
1548 targetJson="{\"policy_schemas\": $targetJson }"
1549 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001550 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001551 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001552
1553 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001554 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001555 return 1
1556 fi
1557 fi
1558
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001559 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001560 return 0
1561}
1562
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001563# API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001564# arg: <response-code> <policy-id> (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001565# (Function for test scripts)
1566api_get_policy_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001567 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001568
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001569 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001570 __print_err "<response-code> <policy-id> (STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001571 return 1
1572 fi
1573
1574 targetJson=""
1575
1576 if [ $3 == "STD" ]; then
1577 targetJson="{\"enforceStatus\":\"$4\""
1578 if [ $# -eq 5 ]; then
1579 targetJson=$targetJson",\"reason\":\"$5\""
1580 fi
1581 targetJson=$targetJson"}"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001582 elif [ $3 == "STD2" ]; then
1583 if [ $4 == "EMPTY" ]; then
1584 targetJson="{\"enforceStatus\":\"\""
1585 else
1586 targetJson="{\"enforceStatus\":\"$4\""
1587 fi
1588 if [ $# -eq 5 ]; then
1589 if [ $5 == "EMPTY" ]; then
1590 targetJson=$targetJson",\"enforceReason\":\"\""
1591 else
1592 targetJson=$targetJson",\"enforceReason\":\"$5\""
1593 fi
1594 fi
1595 targetJson=$targetJson"}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001596 elif [ $3 == "OSC" ]; then
1597 targetJson="{\"instance_status\":\"$4\""
1598 if [ $# -eq 5 ]; then
1599 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1600 fi
1601 targetJson=$targetJson",\"created_at\":\"????\"}"
1602 else
1603 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1604 return 1
1605 fi
1606
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001607 if [ "$PMS_VERSION" == "V2" ]; then
1608 query="/v2/policies/$UUID$2/status"
1609 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1610 else
1611 query="/policy_status?id="$UUID$2
1612 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001613
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001614 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001615 status=${res:${#res}-3}
1616
1617 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001618 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001619 return 1
1620 fi
1621
1622 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1623 body=${res:0:${#res}-3}
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001624 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001625
1626 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001627 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001628 return 1
1629 fi
1630
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001631 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001632 return 0
1633}
1634
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001635# API Test function: GET /policy_types and V2 GET /v2/policy-types
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001636# args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1637# (Function for test scripts)
1638api_get_policy_types() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001639 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001640
1641 if [ $# -lt 1 ]; then
1642 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1643 return 1
1644 fi
1645
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001646 if [ "$PMS_VERSION" == "V2" ]; then
1647 if [ $# -eq 1 ]; then
1648 query="/v2/policy-types"
1649 elif [ $2 == "NORIC" ]; then
1650 query="/v2/policy-types"
1651 else
1652 query="/v2/policy-types?ric_id=$2"
1653 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001654 else
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001655 if [ $# -eq 1 ]; then
1656 query="/policy_types"
1657 elif [ $2 == "NORIC" ]; then
1658 query="/policy_types"
1659 else
1660 query="/policy_types?ric=$2"
1661 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001662 fi
1663
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001664 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001665 status=${res:${#res}-3}
1666
1667 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001668 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001669 return 1
1670 fi
1671
1672 if [ $# -gt 2 ]; then
1673 body=${res:0:${#res}-3}
1674 targetJson="["
1675
1676 for pid in ${@:3} ; do
1677 if [ "$targetJson" != "[" ]; then
1678 targetJson=$targetJson","
1679 fi
1680 if [ $pid == "EMPTY" ]; then
1681 pid=""
1682 fi
1683 targetJson=$targetJson"\"$pid\""
1684 done
1685
1686 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001687 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001688 targetJson="{\"policytype_ids\": $targetJson }"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001689 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001690 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001691 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001692
1693 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001694 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001695 return 1
1696 fi
1697 fi
1698
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001699 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001700 return 0
1701}
1702
1703#########################################################
1704#### Test case functions Health check
1705#########################################################
1706
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001707# API Test function: GET /status and V2 GET /status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001708# args: <response-code>
1709# (Function for test scripts)
1710api_get_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001711 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001712 if [ $# -ne 1 ]; then
1713 __print_err "<response-code>" $@
1714 return 1
1715 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001716 if [ "$PMS_VERSION" == "V2" ]; then
1717 query="/v2/status"
1718 else
1719 query="/status"
1720 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001721 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001722 status=${res:${#res}-3}
1723
1724 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001725 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001726 return 1
1727 fi
1728
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001729 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001730 return 0
1731}
1732
1733#########################################################
1734#### Test case functions RIC Repository
1735#########################################################
1736
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001737# API Test function: GET /ric and V2 GET /v2/rics/ric
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001738# args: <reponse-code> <management-element-id> [<ric-id>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001739# (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1740# (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1741# (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1742
1743
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001744# (Function for test scripts)
1745api_get_ric() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001746 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001747
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001748 if [ "$PMS_VERSION" == "V2" ]; then
1749 if [ $# -lt 3 ]; then
1750 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1751 return 1
1752 fi
1753 search=""
1754 if [ $2 != "NOME" ]; then
1755 search="?managed_element_id="$2
1756 fi
1757 if [ $3 != "NORIC" ]; then
1758 if [ -z $search ]; then
1759 search="?ric_id="$3
1760 else
1761 search=$search"&ric_id="$3
1762 fi
1763 fi
1764 query="/v2/rics/ric"$search
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001765
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001766 res="$(__do_curl_to_api PA GET $query)"
1767 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001768
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001769 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001770 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001771 return 1
1772 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001773
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001774 if [ $# -gt 3 ]; then
1775 body=${res:0:${#res}-3}
1776 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1777 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001778 __log_test_fail_general "Could not create target ric info json"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001779 return 1
1780 fi
1781
1782 targetJson=$(<./tmp/.tmp_rics.json)
1783 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1784 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1785 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1786 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001787 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001788 return 1
1789 fi
1790 fi
1791 else
1792 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1793 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1794 return 1
1795 fi
1796
1797 query="/ric?managedElementId="$2
1798
1799 res="$(__do_curl_to_api PA GET $query)"
1800 status=${res:${#res}-3}
1801
1802 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001803 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001804 return 1
1805 fi
1806
1807 if [ $# -eq 3 ]; then
1808 body=${res:0:${#res}-3}
1809 if [ "$body" != "$3" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001810 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001811 return 1
1812 fi
1813 fi
1814 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001815 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001816 return 0
1817}
1818
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001819# API test function: GET /rics and V2 GET /v2/rics
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001820# args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1821# 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_........."
1822# format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1823# (Function for test scripts)
1824api_get_rics() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001825 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001826
1827 if [ $# -lt 2 ]; then
1828 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1829 return 1
1830 fi
1831
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001832 if [ "$PMS_VERSION" == "V2" ]; then
1833 query="/v2/rics"
1834 if [ $2 != "NOTYPE" ]; then
1835 query="/v2/rics?policytype_id="$2
1836 fi
1837 else
1838 query="/rics"
1839 if [ $2 != "NOTYPE" ]; then
1840 query="/rics?policyType="$2
1841 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001842 fi
1843
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001844 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001845 status=${res:${#res}-3}
1846
1847 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001848 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001849 return 1
1850 fi
1851
1852 if [ $# -gt 2 ]; then
1853 body=${res:0:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001854 if [ "$PMS_VERSION" == "V2" ]; then
1855 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
1856 else
1857 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
1858 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001859 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001860 __log_test_fail_general "Could not create target ric info json"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001861 return 1
1862 fi
1863
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001864 targetJson=$(<./tmp/.tmp_rics.json)
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001865 if [ "$PMS_VERSION" == "V2" ]; then
1866 targetJson="{\"rics\": $targetJson }"
1867 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001868 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001869 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001870 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001871 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001872 return 1
1873 fi
1874 fi
1875
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001876 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001877 return 0
1878}
1879
1880##################################################################
1881#### API Test case functions Service registry and supervision ####
1882##################################################################
1883
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001884# API test function: PUT /service and V2 PUT /service
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001885# args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1886# (Function for test scripts)
1887api_put_service() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001888 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001889 if [ $# -ne 4 ]; then
1890 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1891 return 1
1892 fi
1893
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001894 if [ "$PMS_VERSION" == "V2" ]; then
1895 query="/v2/services"
1896 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
1897 else
1898 query="/service"
1899 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1900 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001901 file="./tmp/.tmp.json"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001902 echo "$json" > $file
1903
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001904 res="$(__do_curl_to_api PA PUT $query $file)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001905 status=${res:${#res}-3}
1906
1907 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001908 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001909 return 1
1910 fi
1911
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001912 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001913 return 0
1914}
1915
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001916# API test function: GET /services and V2 GET /v2/services
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001917#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>]* )]
1918# (Function for test scripts)
1919api_get_services() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001920 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001921 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1922 paramError=1
1923 if [ $# -eq 1 ]; then
1924 paramError=0
1925 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1926 paramError=0
1927 elif [ $# -eq 5 ]; then
1928 paramError=0
1929 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1930 argLen=$(($#-2))
1931 if [ $(($argLen%3)) -eq 0 ]; then
1932 paramError=0
1933 fi
1934 fi
1935
1936 if [ $paramError -ne 0 ]; then
1937 __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>]* )]" $@
1938 return 1
1939 fi
1940
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001941 if [ "$PMS_VERSION" == "V2" ]; then
1942 query="/v2/services"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001943
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001944 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1945 query="/v2/services?service_id="$2
1946 fi
1947 else
1948 query="/services"
1949
1950 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1951 query="/services?name="$2
1952 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001953 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001954 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001955 status=${res:${#res}-3}
1956
1957 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001958 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001959 return 1
1960 fi
1961
1962 if [ $# -gt 2 ]; then
1963 variableArgCount=$(($#-2))
1964 body=${res:0:${#res}-3}
1965 targetJson="["
1966 shift; shift;
1967 cntr=0
1968 while [ $cntr -lt $variableArgCount ]; do
1969 servicename=$1; shift;
1970 timeout=$1; shift;
1971 callback=$1; shift;
1972 if [ $cntr -gt 0 ]; then
1973 targetJson=$targetJson","
1974 fi
1975 # timeSinceLastActivitySeconds value cannot be checked since value varies
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001976 if [ "$PMS_VERSION" == "V2" ]; then
1977 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
1978 else
1979 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1980 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001981 let cntr=cntr+3
1982 done
1983 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001984 if [ "$PMS_VERSION" == "V2" ]; then
1985 targetJson="{\"service_list\": $targetJson }"
1986 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001987 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001988 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001989 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001990 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001991 return 1
1992 fi
1993 fi
1994
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001995 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001996 return 0
1997}
1998
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001999# API test function: GET /services V2 GET /v2/services - (only checking service names)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002000# args: <response-code> [<service-name>]*"
2001# (Function for test scripts)
2002api_get_service_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002003 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002004
2005 if [ $# -lt 1 ]; then
2006 __print_err "<response-code> [<service-name>]*" $@
2007 return 1
2008 fi
2009
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002010 if [ "$PMS_VERSION" == "V2" ]; then
2011 query="/v2/services"
2012 else
2013 query="/services"
2014 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002015 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002016 status=${res:${#res}-3}
2017
2018 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002019 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002020 return 1
2021 fi
2022
2023 body=${res:0:${#res}-3}
2024 targetJson="["
2025 for rapp in ${@:2} ; do
2026 if [ "$targetJson" != "[" ]; then
2027 targetJson=$targetJson","
2028 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002029 if [ "$PMS_VERSION" == "V2" ]; then
2030 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2031 else
2032 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2033 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002034 done
2035
2036 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002037 if [ "$PMS_VERSION" == "V2" ]; then
2038 targetJson="{\"service_list\": $targetJson }"
2039 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002040 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002041 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002042
2043 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002044 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002045 return 1
2046 fi
2047
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002048 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002049 return 0
2050}
2051
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002052# API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002053# args: <response-code> <service-name>
2054# (Function for test scripts)
2055api_delete_services() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002056 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002057
2058 if [ $# -ne 2 ]; then
2059 __print_err "<response-code> <service-name>" $@
2060 return 1
2061 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002062 if [ "$PMS_VERSION" == "V2" ]; then
2063 query="/v2/services/"$2
2064 else
2065 query="/services?name="$2
2066 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002067 res="$(__do_curl_to_api PA DELETE $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002068 status=${res:${#res}-3}
2069
2070 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002071 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002072 return 1
2073 fi
2074
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002075 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002076 return 0
2077}
2078
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002079# API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002080# args: <response-code> <service-name>
2081# (Function for test scripts)
2082api_put_services_keepalive() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002083 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002084
2085 if [ $# -ne 2 ]; then
2086 __print_err "<response-code> <service-name>" $@
2087 return 1
2088 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002089 if [ "$PMS_VERSION" == "V2" ]; then
2090 query="/v2/services/$2/keepalive"
2091 else
2092 query="/services/keepalive?name="$2
2093 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002094
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002095 res="$(__do_curl_to_api PA PUT $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002096 status=${res:${#res}-3}
2097
2098 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002099 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002100 return 1
2101 fi
2102
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002103 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002104 return 0
2105}
2106
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002107##################################################################
2108#### API Test case functions Configuration ####
2109##################################################################
2110
2111# API Test function: PUT /v2/configuration
2112# args: <response-code> <config-file>
2113# (Function for test scripts)
2114api_put_configuration() {
2115 __log_test_start $@
2116
2117 if [ "$PMS_VERSION" != "V2" ]; then
2118 __log_test_fail_not_supported
2119 return 1
2120 fi
2121
2122 if [ $# -ne 2 ]; then
2123 __print_err "<response-code> <config-file>" $@
2124 return 1
2125 fi
2126 if [ ! -f $2 ]; then
2127 _log_test_fail_general "Config file "$2", does not exist"
2128 return 1
2129 fi
2130 inputJson=$(< $2)
2131 inputJson="{\"config\":"$inputJson"}"
2132 file="./tmp/.config.json"
2133 echo $inputJson > $file
2134 query="/v2/configuration"
2135 res="$(__do_curl_to_api PA PUT $query $file)"
2136 status=${res:${#res}-3}
2137
2138 if [ $status -ne $1 ]; then
2139 __log_test_fail_status_code $1 $status
2140 return 1
2141 fi
2142
2143 __log_test_pass
2144 return 0
2145}
2146
2147# API Test function: GET /v2/configuration
2148# args: <response-code> [<config-file>]
2149# (Function for test scripts)
2150api_get_configuration() {
2151 __log_test_start $@
2152
2153 if [ "$PMS_VERSION" != "V2" ]; then
2154 __log_test_fail_not_supported
2155 return 1
2156 fi
2157
2158 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2159 __print_err "<response-code> [<config-file>]" $@
2160 return 1
2161 fi
2162 if [ ! -f $2 ]; then
2163 _log_test_fail_general "Config file "$2" for comparison, does not exist"
2164 return 1
2165 fi
2166
2167 query="/v2/configuration"
2168 res="$(__do_curl_to_api PA GET $query)"
2169 status=${res:${#res}-3}
2170
2171 if [ $status -ne $1 ]; then
2172 __log_test_fail_status_code $1 $status
2173 return 1
2174 fi
2175
2176 if [ $# -eq 2 ]; then
2177
2178 body=${res:0:${#res}-3}
2179
2180 targetJson=$(< $2)
2181 targetJson="{\"config\":"$targetJson"}"
2182 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2183 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2184
2185 if [ $res -ne 0 ]; then
2186 __log_test_fail_body
2187 return 1
2188 fi
2189 fi
2190
2191 __log_test_pass
2192 return 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002193}
2194
2195##########################################
2196#### Reset types and instances ####
2197##########################################
2198
2199# Admin reset to remove all policies and services
2200# All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2201# NOTE - only works in kubernetes and the pod should not be running
2202# args: -
2203# (Function for test scripts)
2204
2205pms_kube_pvc_reset() {
2206 __log_test_start $@
2207
2208 __kube_clean_pvc $POLICY_AGENT_APP_NAME nonrtric policymanagementservice-vardata-pvc /var/policy-management-service/database
2209
2210 __log_test_pass
2211 return 0
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002212}