blob: a5a51c062e370f8f41ca9da0036586fedfde172b [file] [log] [blame]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001#!/bin/bash
2
3# ============LICENSE_START===============================================
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01004# Copyright (C) 2021 Nordix Foundation. All rights reserved.
BjornMagnussonXA80a92002020-03-19 14:31:06 +01005# ========================================================================
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17# ============LICENSE_END=================================================
18#
19
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +010020# This is a script that contains management and test functions for Policy Agent
BjornMagnussonXA80a92002020-03-19 14:31:06 +010021
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010022################ Test engine functions ################
23
24# Create the image var used during the test
25# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
26# <image-tag-suffix> is present only for images with staging, snapshot,release tags
27__PA_imagesetup() {
28 __check_and_create_image_var PA "POLICY_AGENT_IMAGE" "POLICY_AGENT_IMAGE_BASE" "POLICY_AGENT_IMAGE_TAG" $1 "$POLICY_AGENT_DISPLAY_NAME"
29}
30
31# Pull image from remote repo or use locally built image
32# arg: <pull-policy-override> <pull-policy-original>
33# <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
34# <pull-policy-original> Shall be used for images that does not allow overriding
35# Both var may contain: 'remote', 'remote-remove' or 'local'
36__PA_imagepull() {
BjornMagnussonXA483ee332021-04-08 01:35:24 +020037 __check_and_pull_image $1 "$POLICY_AGENT_DISPLAY_NAME" $POLICY_AGENT_APP_NAME POLICY_AGENT_IMAGE
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010038}
39
40# Build image (only for simulator or interfaces stubs owned by the test environment)
41# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
42# <image-tag-suffix> is present only for images with staging, snapshot,release tags
43__PA_imagebuild() {
44 echo -e $RED" Image for app PA shall never be built"$ERED
45}
46
47# Generate a string for each included image using the app display name and a docker images format string
BjornMagnussonXA483ee332021-04-08 01:35:24 +020048# If a custom image repo is used then also the source image from the local repo is listed
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010049# arg: <docker-images-format-string> <file-to-append>
50__PA_image_data() {
51 echo -e "$POLICY_AGENT_DISPLAY_NAME\t$(docker images --format $1 $POLICY_AGENT_IMAGE)" >> $2
BjornMagnussonXA483ee332021-04-08 01:35:24 +020052 if [ ! -z "$POLICY_AGENT_IMAGE_SOURCE" ]; then
53 echo -e "-- source image --\t$(docker images --format $1 $POLICY_AGENT_IMAGE_SOURCE)" >> $2
54 fi
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010055}
56
57# Scale kubernetes resources to zero
58# All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
59# This function is called for apps fully managed by the test script
60__PA_kube_scale_zero() {
61 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
62}
63
64# Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
65# This function is called for prestarted apps not managed by the test script.
66__PA_kube_scale_zero_and_wait() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +010067 __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app "$KUBE_NONRTRIC_NAMESPACE"-policymanagementservice
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010068}
69
70# Delete all kube resouces for the app
71# This function is called for apps managed by the test script.
72__PA_kube_delete_all() {
73 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
74}
75
76# Store docker logs
77# This function is called for apps managed by the test script.
78# args: <log-dir> <file-prexix>
79__PA_store_docker_logs() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +010080 if [ $RUNMODE == "KUBE" ]; then
81 kubectl logs -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE --tail=-1 > $1$2_policy-agent.log 2>&1
82 else
83 docker logs $POLICY_AGENT_APP_NAME > $1$2_policy-agent.log 2>&1
84 fi
85}
86
87# Initial setup of protocol, host and ports
88# This function is called for apps managed by the test script.
89# args: -
90__PA_initial_setup() {
91 use_agent_rest_http
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010092}
93
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +010094# Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers
95# For docker, the namespace shall be excluded
96# This function is called for apps managed by the test script as well as for prestarted apps.
97# args: -
98__PA_statisics_setup() {
99 if [ $RUNMODE == "KUBE" ]; then
100 echo "PA $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE"
101 else
102 echo "PA $POLICY_AGENT_APP_NAME"
103 fi
104}
105
BjornMagnussonXAe60d04e2021-12-27 13:38:01 +0100106# Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
107# args: -
108__PA_test_requirements() {
109 :
110}
111
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100112
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100113#######################################################
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100114
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100115###########################
116### Policy Agents functions
117###########################
118
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100119# Set http as the protocol to use for all communication to the Policy Agent
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100120# args: -
121# (Function for test scripts)
122use_agent_rest_http() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100123 __agent_set_protocoll "http" $POLICY_AGENT_INTERNAL_PORT $POLICY_AGENT_EXTERNAL_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100124}
125
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100126# Set https as the protocol to use for all communication to the Policy Agent
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100127# args: -
128# (Function for test scripts)
129use_agent_rest_https() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100130 __agent_set_protocoll "https" $POLICY_AGENT_INTERNAL_SECURE_PORT $POLICY_AGENT_EXTERNAL_SECURE_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100131}
132
133# All calls to the agent will be directed to the agent dmaap interface over http from now on
134# args: -
135# (Function for test scripts)
136use_agent_dmaap_http() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100137 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME dmaap protocol setting"$EBOLD
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100138 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
139 PA_ADAPTER_TYPE="MR-HTTP"
140 echo ""
141}
142
143# All calls to the agent will be directed to the agent dmaap interface over https from now on
144# args: -
145# (Function for test scripts)
146use_agent_dmaap_https() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100147 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME dmaap protocol setting"$EBOLD
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100148 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
149 echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
150 PA_ADAPTER_TYPE="MR-HTTPS"
151 echo ""
152}
153
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100154# Setup paths to svc/container for internal and external access
155# args: <protocol> <internal-port> <external-port>
156__agent_set_protocoll() {
157 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME protocol setting"$EBOLD
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100158 echo -e " Using $BOLD $1 $EBOLD towards $POLICY_AGENT_DISPLAY_NAME"
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100159
160 ## Access to Dmaap adapter
161
162 PA_SERVICE_PATH=$1"://"$POLICY_AGENT_APP_NAME":"$2 # docker access, container->container and script->container via proxy
163 if [ $RUNMODE == "KUBE" ]; then
164 PA_SERVICE_PATH=$1"://"$POLICY_AGENT_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
165 fi
166
167 # PA_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
168 PA_ADAPTER_TYPE="REST"
169 PA_ADAPTER=$PA_SERVICE_PATH
170
171 echo ""
172}
173
174# Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
175AGENT_RETRY_CODES=""
176
177#Save first worker node the pod is started on
178__PA_WORKER_NODE=""
179
180# Export env vars for config files, docker compose and kube resources
181# args: PROXY|NOPROXY
182__export_agent_vars() {
183
184 export POLICY_AGENT_APP_NAME
185 export POLICY_AGENT_APP_NAME_ALIAS
186 export POLICY_AGENT_DISPLAY_NAME
187
188 export KUBE_NONRTRIC_NAMESPACE
189 export POLICY_AGENT_IMAGE
190 export POLICY_AGENT_INTERNAL_PORT
191 export POLICY_AGENT_INTERNAL_SECURE_PORT
192 export POLICY_AGENT_EXTERNAL_PORT
193 export POLICY_AGENT_EXTERNAL_SECURE_PORT
194 export POLICY_AGENT_CONFIG_MOUNT_PATH
195 export POLICY_AGENT_DATA_MOUNT_PATH
196 export POLICY_AGENT_CONFIG_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-config"
197 export POLICY_AGENT_DATA_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-data"
198 export POLICY_AGENT_PKG_NAME
199 export CONSUL_HOST
200 export CONSUL_INTERNAL_PORT
201 export CONFIG_BINDING_SERVICE
202 export POLICY_AGENT_CONFIG_KEY
203 export DOCKER_SIM_NWNAME
204 export POLICY_AGENT_HOST_MNT_DIR
205 export POLICY_AGENT_CONFIG_FILE
206
207 export POLICY_AGENT_DATA_PV_NAME=$POLICY_AGENT_APP_NAME"-pv"
208 export POLICY_AGENT_DATA_PVC_NAME=$POLICY_AGENT_APP_NAME"-pvc"
209 ##Create a unique path for the pv each time to prevent a previous volume to be reused
210 export POLICY_AGENT_PV_PATH="padata-"$(date +%s)
211 export POLICY_AGENT_CONTAINER_MNT_DIR
212
213 if [ $1 == "PROXY" ]; then
214 export AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
215 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
216 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
217 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
218 else
219 echo " Configured with http proxy"
220 fi
221 else
222 export AGENT_HTTP_PROXY_CONFIG_PORT=0
223 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
224 echo " Configured without http proxy"
225 fi
226}
227
228
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100229# Start the policy agent
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100230# args: (docker) PROXY|NOPROXY <config-file>
231# args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100232# (Function for test scripts)
233start_policy_agent() {
234 echo -e $BOLD"Starting $POLICY_AGENT_DISPLAY_NAME"$EBOLD
235
236 if [ $RUNMODE == "KUBE" ]; then
237
238 # Check if app shall be fully managed by the test script
239 __check_included_image "PA"
240 retcode_i=$?
241
242 # Check if app shall only be used by the testscipt
243 __check_prestarted_image "PA"
244 retcode_p=$?
245
246 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
247 echo -e $RED"The $POLICY_AGENT_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
248 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
249 exit
250 fi
251 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
252 echo -e $RED"The $POLICY_AGENT_APP_NAME app is included both as managed and prestarted in this test script"$ERED
253 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
254 exit
255 fi
256
257 if [ $retcode_p -eq 0 ]; then
258 echo -e " Using existing $POLICY_AGENT_APP_NAME deployment and service"
259 echo " Setting $POLICY_AGENT_APP_NAME replicas=1"
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +0200260 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
261 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100262 fi
263
264 if [ $retcode_i -eq 0 ]; then
265
266 echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
267
268 #Check if nonrtric namespace exists, if not create it
269 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
270
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100271 __export_agent_vars $1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100272
273 # Create config map for config
274 configfile=$PWD/tmp/$POLICY_AGENT_CONFIG_FILE
275 cp $2 $configfile
276 output_yaml=$PWD/tmp/pa_cfc.yaml
277 __kube_create_configmap $POLICY_AGENT_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $configfile $output_yaml
278
279 # Create config map for data
280 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
281 if [ $# -lt 3 ]; then
282 #create empty dummy file
283 echo "{}" > $data_json
284 else
285 cp $3 $data_json
286 fi
287 output_yaml=$PWD/tmp/pa_cfd.yaml
288 __kube_create_configmap $POLICY_AGENT_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
289
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200290 ## Create pv
291 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pv.yaml
292 output_yaml=$PWD/tmp/pa_pv.yaml
293 __kube_create_instance pv $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
294
295 ## Create pvc
296 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pvc.yaml
297 output_yaml=$PWD/tmp/pa_pvc.yaml
298 __kube_create_instance pvc $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
299
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100300 # Create service
301 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"svc.yaml
302 output_yaml=$PWD/tmp/pa_svc.yaml
303 __kube_create_instance service $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
304
305 # Create app
306 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"app.yaml
307 output_yaml=$PWD/tmp/pa_app.yaml
308 __kube_create_instance app $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
309
310 fi
311
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200312 # 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 +0200313 if [ $retcode_i -eq 0 ]; then
314 __PA_WORKER_NODE=$(kubectl get pod -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
315 if [ -z "$__PA_WORKER_NODE" ]; then
316 echo -e $YELLOW" Cannot find worker node for pod for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
317 fi
318 else
319 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 +0200320 fi
321
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100322 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100323
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100324 else
325 __check_included_image 'PA'
326 if [ $? -eq 1 ]; then
327 echo -e $RED"The Policy Agent app is not included in this test script"$ERED
328 echo -e $RED"The Policy Agent will not be started"$ERED
329 exit
330 fi
331
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200332 curdir=$PWD
333 cd $SIM_GROUP
334 cd policy_agent
335 cd $POLICY_AGENT_HOST_MNT_DIR
336 #cd ..
337 if [ -d db ]; then
338 if [ "$(ls -A $DIR)" ]; then
339 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
340 rm -rf db/* &> /dev/null
341 if [ $? -ne 0 ]; then
342 echo -e $RED" Cannot remove database files in: $PWD"$ERED
343 exit 1
344 fi
345 fi
346 else
347 echo " No files in mounted dir or dir does not exists"
348 fi
349 cd $curdir
350
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100351 __export_agent_vars $1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100352
353 dest_file=$SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_HOST_MNT_DIR/application.yaml
354
355 envsubst < $2 > $dest_file
356
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100357 __start_container $POLICY_AGENT_COMPOSE_DIR "" NODOCKERARGS 1 $POLICY_AGENT_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100358
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100359 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100360 fi
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +0100361
362 __collect_endpoint_stats_image_info "PMS" $POLICY_AGENT_IMAGE
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100363 echo ""
364 return 0
365}
366
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200367# Stop the policy agent
368# args: -
369# args: -
370# (Function for test scripts)
371stop_policy_agent() {
372 echo -e $BOLD"Stopping $POLICY_AGENT_DISPLAY_NAME"$EBOLD
373
374 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200375
376 __check_prestarted_image "PA"
377 if [ $? -eq 0 ]; then
378 echo -e $YELLOW" Persistency may not work for app $POLICY_AGENT_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +0200379 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
380 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200381 return 0
382 fi
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200383 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
384 echo " Deleting the replica set - a new will be started when the app is started"
385 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
386 if [ $? -ne 0 ]; then
387 echo -e $RED" Could not delete replica set "$RED
388 ((RES_CONF_FAIL++))
389 return 1
390 fi
391 else
392 docker stop $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
393 if [ $? -ne 0 ]; then
394 __print_err "Could not stop $POLICY_AGENT_APP_NAME" $@
395 cat ./tmp/.dockererr
396 ((RES_CONF_FAIL++))
397 return 1
398 fi
399 fi
400 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
401 echo ""
402 return 0
403}
404
405# Start a previously stopped policy agent
406# args: -
407# (Function for test scripts)
408start_stopped_policy_agent() {
409 echo -e $BOLD"Starting (the previously stopped) $POLICY_AGENT_DISPLAY_NAME"$EBOLD
410
411 if [ $RUNMODE == "KUBE" ]; then
412
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200413 __check_prestarted_image "PA"
414 if [ $? -eq 0 ]; then
415 echo -e $YELLOW" Persistency may not work for app $POLICY_AGENT_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +0200416 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
417 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100418 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200419 return 0
420 fi
421
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200422 # Tie the PMS to the same worker node it was initially started on
423 # 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
424 if [ -z "$__PA_WORKER_NODE" ]; then
425 echo -e $RED" No initial worker node found for pod "$RED
426 ((RES_CONF_FAIL++))
427 return 1
428 else
429 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
430 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
431 tmp=$(kubectl patch deployment $POLICY_AGENT_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__PA_WORKER_NODE'"}}}}}')
432 if [ $? -ne 0 ]; then
433 echo -e $YELLOW" Cannot set nodeSelector to deployment for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
434 fi
435 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
436 fi
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200437 else
438 docker start $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
439 if [ $? -ne 0 ]; then
440 __print_err "Could not start (the stopped) $POLICY_AGENT_APP_NAME" $@
441 cat ./tmp/.dockererr
442 ((RES_CONF_FAIL++))
443 return 1
444 fi
445 fi
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100446 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200447 if [ $? -ne 0 ]; then
448 return 1
449 fi
450 echo ""
451 return 0
452}
453
454
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100455# Function to perpare the consul configuration according to the current simulator configuration
456# args: SDNC|NOSDNC <output-file>
457# (Function for test scripts)
458prepare_consul_config() {
459 echo -e $BOLD"Prepare Consul config"$EBOLD
460
461 echo " Writing consul config for "$POLICY_AGENT_APP_NAME" to file: "$2
462
463 if [ $# != 2 ]; then
464 ((RES_CONF_FAIL++))
465 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
466 exit 1
467 fi
468
469 if [ $1 == "SDNC" ]; then
470 echo -e " Config$BOLD including SDNC$EBOLD configuration"
471 elif [ $1 == "NOSDNC" ]; then
472 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
473 else
474 ((RES_CONF_FAIL++))
475 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
476 exit 1
477 fi
478
479 config_json="\n {"
480 if [ $1 == "SDNC" ]; then
481 config_json=$config_json"\n \"controller\": ["
482 config_json=$config_json"\n {"
483 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
484 config_json=$config_json"\n \"baseUrl\": \"$SDNC_SERVICE_PATH\","
485 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
486 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
487 config_json=$config_json"\n }"
488 config_json=$config_json"\n ],"
489 fi
490
491 config_json=$config_json"\n \"streams_publishes\": {"
492 config_json=$config_json"\n \"dmaap_publisher\": {"
493 config_json=$config_json"\n \"type\": \"message-router\","
494 config_json=$config_json"\n \"dmaap_info\": {"
495 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_WRITE_URL\""
496 config_json=$config_json"\n }"
497 config_json=$config_json"\n }"
498 config_json=$config_json"\n },"
499 config_json=$config_json"\n \"streams_subscribes\": {"
500 config_json=$config_json"\n \"dmaap_subscriber\": {"
501 config_json=$config_json"\n \"type\": \"message-router\","
502 config_json=$config_json"\n \"dmaap_info\": {"
503 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_READ_URL\""
504 config_json=$config_json"\n }"
505 config_json=$config_json"\n }"
506 config_json=$config_json"\n },"
507
508 config_json=$config_json"\n \"ric\": ["
509
510 if [ $RUNMODE == "KUBE" ]; then
511 result=$(kubectl get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICSIM")].metadata.name}')
512 rics=""
513 ric_cntr=0
514 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
515 for im in $result; do
516 if [[ $im != *"-0" ]]; then
517 ric_subdomain=$(kubectl get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
518 rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
519 let ric_cntr=ric_cntr+1
520 fi
521 done
522 fi
523 if [ $ric_cntr -eq 0 ]; then
524 echo $YELLOW"Warning: No rics found for the configuration"$EYELLOW
525 fi
526 else
527 rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "status=running" --format {{.Names}})
528 if [ $? -ne 0 ] || [ -z "$rics" ]; then
529 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
530 ((RES_CONF_FAIL++))
531 return 1
532 fi
533 fi
534 cntr=0
535 for ric in $rics; do
536 if [ $cntr -gt 0 ]; then
537 config_json=$config_json"\n ,"
538 fi
539 config_json=$config_json"\n {"
540 if [ $RUNMODE == "KUBE" ]; then
541 ric_id=${ric%.*.*} #extract pod id from full hosthame
542 ric_id=$(echo "$ric_id" | tr '-' '_')
543 else
BjornMagnussonXA51f04f02021-11-23 09:22:35 +0100544 if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
545 ric_id=$ric
546 else
547 ric_id=$(echo "$ric" | tr '-' '_') #ric id still needs underscore as it is different from the container name
548 fi
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100549 fi
550 echo " Found a1 sim: "$ric_id
551 config_json=$config_json"\n \"name\": \"$ric_id\","
552 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
553 if [ $1 == "SDNC" ]; then
554 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
555 fi
556 config_json=$config_json"\n \"managedElementIds\": ["
557 config_json=$config_json"\n \"me1_$ric_id\","
558 config_json=$config_json"\n \"me2_$ric_id\""
559 config_json=$config_json"\n ]"
560 config_json=$config_json"\n }"
561 let cntr=cntr+1
562 done
563
564 config_json=$config_json"\n ]"
565 config_json=$config_json"\n}"
566
567 if [ $RUNMODE == "KUBE" ]; then
568 config_json="{\"config\":"$config_json"}"
569 fi
570
571 printf "$config_json">$2
572
573 echo ""
574}
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200575
BjornMagnussonXA366e36a2021-01-27 11:48:56 +0100576# Load the the appl config for the agent into a config map
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100577agent_load_config() {
578 echo -e $BOLD"Agent - load config from "$EBOLD$1
579 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
580 cp $1 $data_json
581 output_yaml=$PWD/tmp/pa_cfd.yaml
582 __kube_create_configmap $POLICY_AGENT_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100583 echo ""
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100584}
585
586
587# Turn on debug level tracing in the agent
588# args: -
589# (Function for test scripts)
590set_agent_debug() {
591 echo -e $BOLD"Setting agent debug logging"$EBOLD
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100592 curlString="$PA_SERVICE_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100593 result=$(__do_curl "$curlString")
594 if [ $? -ne 0 ]; then
595 __print_err "could not set debug mode" $@
596 ((RES_CONF_FAIL++))
597 return 1
598 fi
599 echo ""
600 return 0
601}
602
603# Turn on trace level tracing in the agent
604# args: -
605# (Function for test scripts)
606set_agent_trace() {
607 echo -e $BOLD"Setting agent trace logging"$EBOLD
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100608 curlString="$PA_SERVICE_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100609 result=$(__do_curl "$curlString")
610 if [ $? -ne 0 ]; then
611 __print_err "could not set trace mode" $@
612 ((RES_CONF_FAIL++))
613 return 1
614 fi
615 echo ""
616 return 0
617}
618
619# Perform curl retries when making direct call to the agent for the specified http response codes
620# Speace separated list of http response codes
621# args: [<response-code>]*
622use_agent_retries() {
623 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
624 AGENT_RETRY_CODES=$@
625 echo ""
626 return
627}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100628
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100629# Check the agent logs for WARNINGs and ERRORs
630# args: -
631# (Function for test scripts)
632check_policy_agent_logs() {
633 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
634}
635
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100636#########################################################
637#### Test case functions A1 Policy management service
638#########################################################
639
640# This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
641# This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
642# args: json:<url> <target-value> [<timeout-in-seconds]
643# (Function for test scripts)
644api_equal() {
645 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
646 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
647 if [[ $1 == "json:"* ]]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100648 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100649 __var_test "Policy Agent" $PA_SERVICE_PATH$PMS_API_PREFIX"/v2/" $1 "=" $2 $3
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100650 else
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100651 __var_test "Policy Agent" $PA_SERVICE_PATH"/" $1 "=" $2 $3
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100652 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100653 return 0
654 fi
655 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100656 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
657 return 1
658}
659
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100660# API Test function: GET /policies and V2 GET /v2/policy-instances
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100661# 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>]*]
662# 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 +0100663# (Function for test scripts)
664api_get_policies() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100665 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100666
667 if [ "$PMS_VERSION" == "V2" ]; then
668 paramError=0
669 variableParams=$(($#-4))
670 if [ $# -lt 4 ]; then
671 paramError=1
672 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
673 paramError=1
674 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
675 paramError=1
676 fi
677
678 if [ $paramError -ne 0 ]; then
679 __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>]*]" $@
680 return 1
681 fi
682 else
683 paramError=0
684 variableParams=$(($#-4))
685 if [ $# -lt 4 ]; then
686 paramError=1
687 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
688 paramError=1
689 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
690 paramError=1
691 fi
692
693 if [ $paramError -ne 0 ]; then
694 __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>]*]" $@
695 return 1
696 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100697 fi
698
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100699 queryparams=""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100700 if [ "$PMS_VERSION" == "V2" ]; then
701 if [ $2 != "NORIC" ]; then
702 queryparams="?ric_id="$2
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100703 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100704 if [ $3 != "NOSERVICE" ]; then
705 if [ -z $queryparams ]; then
706 queryparams="?service_id="$3
707 else
708 queryparams=$queryparams"&service_id="$3
709 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100710 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100711 if [ $4 != "NOTYPE" ]; then
712 if [ -z $queryparams ]; then
713 queryparams="?policytype_id="$4
714 else
715 queryparams=$queryparams"&policytype_id="$4
716 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100717 fi
718
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100719 query="/v2/policy-instances"$queryparams
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100720 res="$(__do_curl_to_api PA GET $query)"
721 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100722
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100723 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100724 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100725 return 1
726 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100727
728 if [ $# -gt 4 ]; then
729 body=${res:0:${#res}-3}
730 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
731 targetJson="["
732 else
733 targetJson="["
734 arr=(${@:5})
735
736 for ((i=0; i<$(($#-4)); i=i+7)); do
737
738 if [ "$targetJson" != "[" ]; then
739 targetJson=$targetJson","
740 fi
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100741 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 +0100742 if [ "${arr[$i+3]}" == "EMPTY" ]; then
743 targetJson=$targetJson"\"\","
744 else
745 targetJson=$targetJson"\"${arr[$i+3]}\","
746 fi
747 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
748 file="./tmp/.p.json"
749 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
750 json=$(cat $file)
751 targetJson=$targetJson"\"policy_data\":"$json"}"
752 done
753 fi
754
755 targetJson=$targetJson"]"
756 targetJson="{\"policies\": $targetJson}"
757 echo "TARGET JSON: $targetJson" >> $HTTPLOG
758 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
759
760 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100761 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100762 return 1
763 fi
764 fi
765 else
766 if [ $2 != "NORIC" ]; then
767 queryparams="?ric="$2
768 fi
769 if [ $3 != "NOSERVICE" ]; then
770 if [ -z $queryparams ]; then
771 queryparams="?service="$3
772 else
773 queryparams=$queryparams"&service="$3
774 fi
775 fi
776 if [ $4 != "NOTYPE" ]; then
777 if [ -z $queryparams ]; then
778 queryparams="?type="$4
779 else
780 queryparams=$queryparams"&type="$4
781 fi
782 fi
783
784 query="/policies"$queryparams
785 res="$(__do_curl_to_api PA GET $query)"
786 status=${res:${#res}-3}
787
788 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100789 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100790 return 1
791 fi
792
793 if [ $# -gt 4 ]; then
794 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
795 targetJson="["
796 else
797 body=${res:0:${#res}-3}
798 targetJson="["
799 arr=(${@:5})
800
801 for ((i=0; i<$(($#-4)); i=i+5)); do
802
803 if [ "$targetJson" != "[" ]; then
804 targetJson=$targetJson","
805 fi
806 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
807 if [ "${arr[$i+3]}" == "EMPTY" ]; then
808 targetJson=$targetJson"\"\","
809 else
810 targetJson=$targetJson"\"${arr[$i+3]}\","
811 fi
812 file="./tmp/.p.json"
813 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
814 json=$(cat $file)
815 targetJson=$targetJson"\"json\":"$json"}"
816 done
817 fi
818
819 targetJson=$targetJson"]"
820 echo "TARGET JSON: $targetJson" >> $HTTPLOG
821 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
822
823 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100824 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100825 return 1
826 fi
827 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100828 fi
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +0100829 __collect_endpoint_stats "PMS" 00 "GET" $PMS_API_PREFIX"/v2/policy-instances" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100830 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100831 return 0
832
833}
834
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100835
836# API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
837# args: <response-code> <policy-id> [<template-file>]
838# args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
839
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100840# (Function for test scripts)
841api_get_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100842 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100843
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100844
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100845 if [ "$PMS_VERSION" == "V2" ]; then
846 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
847 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
848 return 1
849 fi
850 query="/v2/policies/$UUID$2"
851 else
852 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
853 __print_err "<response-code> <policy-id> [<template-file>] " $@
854 return 1
855 fi
856 query="/policy?id=$UUID$2"
857 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200858 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100859 status=${res:${#res}-3}
860
861 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100862 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100863 return 1
864 fi
865
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100866 if [ "$PMS_VERSION" == "V2" ]; then
867 if [ $# -eq 8 ]; then
868
869 #Create a policy json to compare with
870 body=${res:0:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100871
872 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
873 if [ $7 != "NOTRANSIENT" ]; then
874 targetJson=$targetJson", \"transient\":$7"
875 fi
876 if [ $6 != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100877 targetJson=$targetJson", \"policytype_id\":\"$6\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100878 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100879 targetJson=$targetJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100880 fi
881 if [ $8 != "NOURL" ]; then
882 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
883 fi
884
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100885 data=$(sed 's/XXX/'${2}'/g' $3)
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100886 targetJson=$targetJson", \"policy_data\":$data"
887 targetJson="{$targetJson}"
888
889 echo "TARGET JSON: $targetJson" >> $HTTPLOG
890 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
891 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100892 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100893 return 1
894 fi
895 fi
896 else
897 if [ $# -eq 3 ]; then
898 #Create a policy json to compare with
899 body=${res:0:${#res}-3}
900 file="./tmp/.p.json"
901 sed 's/XXX/'${2}'/g' $3 > $file
902 targetJson=$(< $file)
903 echo "TARGET JSON: $targetJson" >> $HTTPLOG
904 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
905 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100906 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100907 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100908 fi
909 fi
910
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +0100911 __collect_endpoint_stats "PMS" 01 "GET" $PMS_API_PREFIX"/v2/policies/{policy_id}" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100912 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100913 return 0
914}
915
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100916# API Test function: PUT /policy and V2 PUT /policies
917# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
918# 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 +0100919# (Function for test scripts)
920api_put_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100921 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100922
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100923 if [ "$PMS_VERSION" == "V2" ]; then
924 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
925 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
926 return 1
927 fi
928 else
929 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
930 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
931 return 1
932 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100933 fi
934
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100935 count=0
936 max=1
937 serv=$2
938 ric=$3
939 pt=$4
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100940 pid=$5
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100941 trans=$6
942
943 if [ "$PMS_VERSION" == "V2" ]; then
944 noti=$7
945 temp=$8
946 if [ $# -eq 9 ]; then
947 max=$9
948 fi
949 else
950 temp=$7
951 if [ $# -eq 8 ]; then
952 max=$8
953 fi
954 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100955
956 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100957 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100958
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100959 query="/v2/policies"
960
961 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
962 if [ $trans != "NOTRANSIENT" ]; then
963 inputJson=$inputJson", \"transient\":$trans"
964 fi
965 if [ $pt != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100966 inputJson=$inputJson", \"policytype_id\":\"$pt\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100967 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100968 inputJson=$inputJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100969 fi
970 if [ $noti != "NOURL" ]; then
971 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
972 fi
973 file="./tmp/.p.json"
974 data=$(sed 's/XXX/'${pid}'/g' $temp)
975 inputJson=$inputJson", \"policy_data\":$data"
976 inputJson="{$inputJson}"
977 echo $inputJson > $file
978 else
979 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
980
981 if [ $pt != "NOTYPE" ]; then
982 query=$query"&type=$pt"
983 fi
984
985 if [ $trans != NOTRANSIENT ]; then
986 query=$query"&transient=$trans"
987 fi
988
989 file="./tmp/.p.json"
990 sed 's/XXX/'${pid}'/g' $temp > $file
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200991 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200992 res="$(__do_curl_to_api PA PUT $query $file)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100993 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200994 echo -ne " Executing "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100995 if [ $status -ne $1 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200996 echo " Executed "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100997 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100998 return 1
999 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001000 let pid=$pid+1
1001 let count=$count+1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001002 echo -ne " Executed "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001003 done
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001004 __collect_endpoint_stats "PMS" 02 "PUT" $PMS_API_PREFIX"/v2/policies" $status $max
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001005 echo ""
1006
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001007 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001008 return 0
1009}
1010
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001011# API Test function: PUT /policy and V2 PUT /policies, to run in batch
1012# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
1013# 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 +02001014# (Function for test scripts)
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001015
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001016api_put_policy_batch() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001017 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001018
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001019 if [ "$PMS_VERSION" == "V2" ]; then
1020 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1021 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
1022 return 1
1023 fi
1024 else
1025 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1026 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
1027 return 1
1028 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001029 fi
1030
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001031 count=0
1032 max=1
1033 serv=$2
1034 ric=$3
1035 pt=$4
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001036 pid=$5
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001037 trans=$6
1038 if [ "$PMS_VERSION" == "V2" ]; then
1039 noti=$7
1040 temp=$8
1041 if [ $# -eq 9 ]; then
1042 max=$9
1043 fi
1044 else
1045 temp=$7
1046 if [ $# -eq 8 ]; then
1047 max=$8
1048 fi
1049 fi
1050
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001051 ARR=""
1052 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001053 if [ "$PMS_VERSION" == "V2" ]; then
1054 query="/v2/policies"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001055
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001056 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1057 if [ $trans != "NOTRANSIENT" ]; then
1058 inputJson=$inputJson", \"transient\":$trans"
1059 fi
1060 if [ $pt != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001061 inputJson=$inputJson", \"policytype_id\":\"$pt\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001062 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001063 inputJson=$inputJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001064 fi
1065 if [ $noti != "NOURL" ]; then
1066 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1067 fi
1068 file="./tmp/.p.json"
1069 data=$(sed 's/XXX/'${pid}'/g' $temp)
1070 inputJson=$inputJson", \"policy_data\":$data"
1071 inputJson="{$inputJson}"
1072 echo $inputJson > $file
1073 else
1074 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
1075
1076 if [ $pt != "NOTYPE" ]; then
1077 query=$query"&type=$pt"
1078 fi
1079
1080 if [ $trans != NOTRANSIENT ]; then
1081 query=$query"&transient=$trans"
1082 fi
1083 file="./tmp/.p.json"
1084 sed 's/XXX/'${pid}'/g' $temp > $file
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001085 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001086 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001087 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001088 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001089
1090 if [ $status -ne 200 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001091 echo " Requested(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001092 __log_test_fail_status_code 200 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001093 return 1
1094 fi
1095 cid=${res:0:${#res}-3}
1096 ARR=$ARR" "$cid
1097 let pid=$pid+1
1098 let count=$count+1
1099 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1100 done
1101
1102 echo ""
1103 count=0
1104 for cid in $ARR; do
1105
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001106 res="$(__do_curl_to_api PA RESPONSE $cid)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001107 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001108 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001109
1110 if [ $status -ne $1 ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001111 echo " Accepted(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001112 __log_test_fail_status_code $1 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001113 return 1
1114 fi
1115
1116 let count=$count+1
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001117 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001118 done
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001119 __collect_endpoint_stats "PMS" 02 "PUT" $PMS_API_PREFIX"/v2/policies" $1 $max
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001120
1121 echo ""
1122
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001123 __log_test_pass
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001124 return 0
1125}
1126
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001127# 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 +02001128# 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 +01001129# 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 +02001130# (Function for test scripts)
1131api_put_policy_parallel() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001132 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001133
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001134 if [ "$PMS_VERSION" == "V2" ]; then
1135 if [ $# -ne 11 ]; then
1136 __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>" $@
1137 return 1
1138 fi
1139 else
1140 if [ $# -ne 10 ]; then
1141 __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>" $@
1142 return 1
1143 fi
1144 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001145 resp_code=$1; shift;
1146 serv=$1; shift
1147 ric_base=$1; shift;
1148 num_rics=$1; shift;
1149 type=$1; shift;
1150 start_id=$1; shift;
1151 transient=$1; shift;
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001152 if [ "$PMS_VERSION" == "V2" ]; then
1153 noti=$1; shift;
1154 else
1155 noti=""
1156 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001157 template=$1; shift;
1158 count=$1; shift;
1159 pids=$1; shift;
1160
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001161 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001162 if [ $PA_ADAPTER_TYPE != "REST" ]; then
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001163 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1164 echo " Info - will execute over agent REST"
1165 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001166 if [ "$PMS_VERSION" == "V2" ]; then
1167 if [ $serv == "NOSERVICE" ]; then
1168 serv=""
1169 fi
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001170 query="$PMS_API_PREFIX/v2/policies"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001171 else
1172 if [ $serv == "NOSERVICE" ]; then
1173 serv=""
1174 fi
1175 query="/policy?service=$serv"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001176
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001177 if [ $type != "NOTYPE" ]; then
1178 query=$query"&type=$type"
1179 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001180
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001181 if [ $transient != NOTRANSIENT ]; then
1182 query=$query"&transient=$transient"
1183 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001184 fi
1185
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001186 urlbase=${PA_ADAPTER}${query}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001187
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001188 httpproxy="NOPROXY"
BjornMagnussonXA663566c2021-11-08 10:25:07 +01001189 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1190 httpproxy=$KUBE_PROXY_PATH
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001191 fi
1192
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001193 for ((i=1; i<=$pids; i++))
1194 do
BjornMagnussonXAad047782020-06-08 15:54:11 +02001195 uuid=$UUID
1196 if [ -z "$uuid" ]; then
1197 uuid="NOUUID"
1198 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001199 echo "" > "./tmp/.pid${i}.res.txt"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001200 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001201 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 +01001202 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001203 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 +01001204 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001205 echo $i
1206 done | xargs -n 1 -I{} -P $pids bash -c '{
1207 arg=$(echo {})
1208 echo " Parallel process $arg started"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001209 tmp=$(< "./tmp/.pid${arg}.txt")
1210 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001211 }'
1212 msg=""
1213 for ((i=1; i<=$pids; i++))
1214 do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001215 file="./tmp/.pid${i}.res.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001216 tmp=$(< $file)
1217 if [ -z "$tmp" ]; then
1218 echo " Process $i : unknown result (result file empty"
1219 msg="failed"
1220 else
1221 res=${tmp:0:1}
1222 if [ $res == "0" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001223 echo " Process $i : OK - "${tmp:1}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001224 else
1225 echo " Process $i : failed - "${tmp:1}
1226 msg="failed"
1227 fi
1228 fi
1229 done
1230 if [ -z $msg ]; then
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001231 __collect_endpoint_stats "PMS" 02 "PUT" $PMS_API_PREFIX"/v2/policies" $resp_code $(($count*$num_rics))
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001232 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001233 return 0
1234 fi
1235
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001236 __log_test_fail_general "One of more processes failed to execute"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001237 return 1
1238}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001239
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001240# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001241# args: <response-code> <policy-id> [count]
1242# (Function for test scripts)
1243api_delete_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001244 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001245
1246 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1247 __print_err "<response-code> <policy-id> [count]" $@
1248 return 1
1249 fi
1250
1251 count=0
1252 max=1
1253
1254 if [ $# -eq 3 ]; then
1255 max=$3
1256 fi
1257
1258 pid=$2
1259
1260 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001261 if [ "$PMS_VERSION" == "V2" ]; then
1262 query="/v2/policies/"$UUID$pid
1263 else
1264 query="/policy?id="$UUID$pid
1265 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001266 res="$(__do_curl_to_api PA DELETE $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001267 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001268 echo -ne " Executing "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001269
1270 if [ $status -ne $1 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001271 echo " Executed "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001272 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001273 return 1
1274 fi
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001275
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001276 let pid=$pid+1
1277 let count=$count+1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001278 echo -ne " Executed "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001279 done
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001280 __collect_endpoint_stats "PMS" 03 "DELETE" $PMS_API_PREFIX"/v2/policies/{policy_id}" $status $max
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001281 echo ""
1282
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001283 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001284 return 0
1285}
1286
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001287# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001288# args: <response-code> <policy-id> [count]
1289# (Function for test scripts)
1290api_delete_policy_batch() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001291 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001292
1293 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1294 __print_err "<response-code> <policy-id> [count]" $@
1295 return 1
1296 fi
1297
1298 count=0
1299 max=1
1300
1301 if [ $# -eq 3 ]; then
1302 max=$3
1303 fi
1304
1305 pid=$2
1306 ARR=""
1307 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001308 if [ "$PMS_VERSION" == "V2" ]; then
1309 query="/v2/policies/"$UUID$pid
1310 else
1311 query="/policy?id="$UUID$pid
1312 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001313 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001314 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001315 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001316
1317 if [ $status -ne 200 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001318 echo " Requested(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001319 __log_test_fail_status_code 200 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001320 return 1
1321 fi
1322 cid=${res:0:${#res}-3}
1323 ARR=$ARR" "$cid
1324 let pid=$pid+1
1325 let count=$count+1
1326 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1327 done
1328
1329 echo ""
1330
1331 count=0
1332 for cid in $ARR; do
1333
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001334 res="$(__do_curl_to_api PA RESPONSE $cid)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001335 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001336 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001337
1338 if [ $status -ne $1 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001339 echo " Deleted(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001340 __log_test_fail_status_code $1 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001341 return 1
1342 fi
1343
1344 let count=$count+1
1345 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1346 done
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001347 __collect_endpoint_stats "PMS" 03 "DELETE" $PMS_API_PREFIX"/v2/policies/{policy_id}" $1 $max
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001348
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001349 echo ""
1350
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001351 __log_test_pass
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001352 return 0
1353}
1354
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001355# 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 +02001356# args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1357# (Function for test scripts)
1358api_delete_policy_parallel() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001359 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001360
1361 if [ $# -ne 5 ]; then
1362 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1363 return 1
1364 fi
1365 resp_code=$1; shift;
1366 num_rics=$1; shift;
1367 start_id=$1; shift;
1368 count=$1; shift;
1369 pids=$1; shift;
1370
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001371 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001372 if [ $PA_ADAPTER_TYPE != "REST" ]; then
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001373 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1374 echo " Info - will execute over agent REST"
1375 fi
1376
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001377 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001378 query="$PMS_API_PREFIX/v2/policies/"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001379 else
1380 query="/policy"
1381 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001382
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001383 urlbase=${PA_ADAPTER}${query}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001384
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001385 httpproxy="NOPROXY"
BjornMagnussonXA663566c2021-11-08 10:25:07 +01001386 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1387 httpproxy=$KUBE_PROXY_PATH
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001388 fi
1389
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001390 for ((i=1; i<=$pids; i++))
1391 do
BjornMagnussonXAad047782020-06-08 15:54:11 +02001392 uuid=$UUID
1393 if [ -z "$uuid" ]; then
1394 uuid="NOUUID"
1395 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001396 echo "" > "./tmp/.pid${i}.del.res.txt"
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001397 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001398 echo $i
1399 done | xargs -n 1 -I{} -P $pids bash -c '{
1400 arg=$(echo {})
1401 echo " Parallel process $arg started"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001402 tmp=$(< "./tmp/.pid${arg}.del.txt")
1403 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001404 }'
1405 msg=""
1406 for ((i=1; i<=$pids; i++))
1407 do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001408 file="./tmp/.pid${i}.del.res.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001409 tmp=$(< $file)
1410 if [ -z "$tmp" ]; then
1411 echo " Process $i : unknown result (result file empty"
1412 msg="failed"
1413 else
1414 res=${tmp:0:1}
1415 if [ $res == "0" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001416 echo " Process $i : OK - "${tmp:1}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001417 else
1418 echo " Process $i : failed - "${tmp:1}
1419 msg="failed"
1420 fi
1421 fi
1422 done
1423 if [ -z $msg ]; then
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001424 __collect_endpoint_stats "PMS" 03 "DELETE" $PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count*$num_rics))
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001425 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001426 return 0
1427 fi
1428
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001429 __log_test_fail_general "One of more processes failed to execute"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001430 return 1
1431}
1432
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001433# API Test function: GET /policy_ids and V2 GET /v2/policies
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001434# args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1435# (Function for test scripts)
1436api_get_policy_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001437 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001438
1439 if [ $# -lt 4 ]; then
1440 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1441 return 1
1442 fi
1443
1444 queryparams=""
1445
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001446 if [ "$PMS_VERSION" == "V2" ]; then
1447 if [ $2 != "NORIC" ]; then
1448 queryparams="?ric_id="$2
1449 fi
1450
1451 if [ $3 != "NOSERVICE" ]; then
1452 if [ -z $queryparams ]; then
1453 queryparams="?service_id="$3
1454 else
1455 queryparams=$queryparams"&service_id="$3
1456 fi
1457 fi
1458 if [ $4 != "NOTYPE" ]; then
1459 if [ -z $queryparams ]; then
1460 queryparams="?policytype_id="$4
1461 else
1462 queryparams=$queryparams"&policytype_id="$4
1463 fi
1464 fi
1465
1466 query="/v2/policies"$queryparams
1467 else
1468 if [ $2 != "NORIC" ]; then
1469 queryparams="?ric="$2
1470 fi
1471
1472 if [ $3 != "NOSERVICE" ]; then
1473 if [ -z $queryparams ]; then
1474 queryparams="?service="$3
1475 else
1476 queryparams=$queryparams"&service="$3
1477 fi
1478 fi
1479 if [ $4 != "NOTYPE" ]; then
1480 if [ -z $queryparams ]; then
1481 queryparams="?type="$4
1482 else
1483 queryparams=$queryparams"&type="$4
1484 fi
1485 fi
1486
1487 query="/policy_ids"$queryparams
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001488 fi
1489
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001490 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001491 status=${res:${#res}-3}
1492
1493 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001494 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001495 return 1
1496 fi
1497
1498 if [ $# -gt 4 ]; then
1499 body=${res:0:${#res}-3}
1500 targetJson="["
1501
1502 for pid in ${@:5} ; do
1503 if [ "$targetJson" != "[" ]; then
1504 targetJson=$targetJson","
1505 fi
1506 if [ $pid != "NOID" ]; then
BjornMagnussonXAad047782020-06-08 15:54:11 +02001507 targetJson=$targetJson"\"$UUID$pid\""
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001508 fi
1509 done
1510
1511 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001512 if [ "$PMS_VERSION" == "V2" ]; then
1513 targetJson="{\"policy_ids\": $targetJson}"
1514 fi
1515 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1516 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1517
1518 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001519 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001520 return 1
1521 fi
1522 fi
1523
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001524 __collect_endpoint_stats "PMS" 04 "GET" $PMS_API_PREFIX"/v2/policies" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001525 __log_test_pass
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001526 return 0
1527}
1528
1529# API Test function: V2 GET /v2/policy-types/{policyTypeId}
1530# args(V2): <response-code> <policy-type-id> [<schema-file>]
1531# (Function for test scripts)
1532api_get_policy_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001533 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001534
1535 if [ "$PMS_VERSION" != "V2" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001536 __log_test_fail_not_supported
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001537 return 1
1538 fi
1539
1540 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1541 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1542 return 1
1543 fi
1544 query="/v2/policy-types/$2"
1545
1546 res="$(__do_curl_to_api PA GET $query)"
1547 status=${res:${#res}-3}
1548
1549 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001550 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001551 return 1
1552 fi
1553
1554 if [ $# -eq 3 ]; then
1555
1556 body=${res:0:${#res}-3}
1557
1558 targetJson=$(< $3)
1559 targetJson="{\"policy_schema\":$targetJson}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001560 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001561 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001562
1563 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001564 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001565 return 1
1566 fi
1567 fi
1568
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001569 __collect_endpoint_stats "PMS" 05 "GET" $PMS_API_PREFIX"/v2/policy-types/{policyTypeId}" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001570 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001571 return 0
1572}
1573
1574# API Test function: GET /policy_schema
1575# args: <response-code> <policy-type-id> [<schema-file>]
1576# (Function for test scripts)
1577api_get_policy_schema() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001578 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001579
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001580 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001581 __log_test_fail_not_supported
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001582 return 1
1583 fi
1584
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001585 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1586 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1587 return 1
1588 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001589 query="/policy_schema?id=$2"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001590 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001591 status=${res:${#res}-3}
1592
1593 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001594 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001595 return 1
1596 fi
1597
1598 if [ $# -eq 3 ]; then
1599
1600 body=${res:0:${#res}-3}
1601
1602 targetJson=$(< $3)
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001603
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001604 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001605 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001606
1607 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001608 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001609 return 1
1610 fi
1611 fi
1612
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001613 __collect_endpoint_stats "PMS" 06 "GET" $PMS_API_PREFIX"/v2/policy_schema" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001614 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001615 return 0
1616}
1617
1618# API Test function: GET /policy_schemas
1619# args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001620# args(V2): <response-code>
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001621# (Function for test scripts)
1622api_get_policy_schemas() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001623 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001624
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001625 if [ "$PMS_VERSION" == "V2" ]; then
1626 if [ $# -ne 1 ]; then
1627 __print_err "<response-code>" $@
1628 return 1
1629 fi
1630 else
1631 if [ $# -lt 2 ]; then
1632 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1633 return 1
1634 fi
1635 fi
1636 if [ "$PMS_VERSION" == "V2" ]; then
1637 query="/v2/policy-schemas"
1638 else
1639 query="/policy_schemas"
1640 if [ $2 != "NORIC" ]; then
1641 query=$query"?ric="$2
1642 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001643 fi
1644
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001645 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001646 status=${res:${#res}-3}
1647
1648 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001649 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001650 return 1
1651 fi
1652
1653 if [ $# -gt 2 ]; then
1654 body=${res:0:${#res}-3}
1655 targetJson="["
1656
1657 for file in ${@:3} ; do
1658 if [ "$targetJson" != "[" ]; then
1659 targetJson=$targetJson","
1660 fi
1661 if [ $file == "NOFILE" ]; then
1662 targetJson=$targetJson"{}"
1663 else
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001664 targetJson=$targetJson$(< $file)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001665 fi
1666 done
1667
1668 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001669 if [ "$PMS_VERSION" == "V2" ]; then
1670 targetJson="{\"policy_schemas\": $targetJson }"
1671 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001672 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001673 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001674
1675 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001676 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001677 return 1
1678 fi
1679 fi
1680
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001681 __collect_endpoint_stats "PMS" 07 "GET" $PMS_API_PREFIX"/v2/policy-schemas" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001682 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001683 return 0
1684}
1685
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001686# API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001687# arg: <response-code> <policy-id> [ (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>) ]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001688# (Function for test scripts)
1689api_get_policy_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001690 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001691
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001692 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
1693 __print_err "<response-code> <policy-id> [(STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)]" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001694 return 1
1695 fi
1696
1697 targetJson=""
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001698 if [ $# -eq 2 ]; then
1699 :
1700 elif [ "$3" == "STD" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001701 targetJson="{\"enforceStatus\":\"$4\""
1702 if [ $# -eq 5 ]; then
1703 targetJson=$targetJson",\"reason\":\"$5\""
1704 fi
1705 targetJson=$targetJson"}"
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001706 elif [ "$3" == "STD2" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001707 if [ $4 == "EMPTY" ]; then
1708 targetJson="{\"enforceStatus\":\"\""
1709 else
1710 targetJson="{\"enforceStatus\":\"$4\""
1711 fi
1712 if [ $# -eq 5 ]; then
1713 if [ $5 == "EMPTY" ]; then
1714 targetJson=$targetJson",\"enforceReason\":\"\""
1715 else
1716 targetJson=$targetJson",\"enforceReason\":\"$5\""
1717 fi
1718 fi
1719 targetJson=$targetJson"}"
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001720 elif [ "$3" == "OSC" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001721 targetJson="{\"instance_status\":\"$4\""
1722 if [ $# -eq 5 ]; then
1723 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1724 fi
1725 targetJson=$targetJson",\"created_at\":\"????\"}"
1726 else
1727 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1728 return 1
1729 fi
1730
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001731 if [ "$PMS_VERSION" == "V2" ]; then
1732 query="/v2/policies/$UUID$2/status"
1733 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1734 else
1735 query="/policy_status?id="$UUID$2
1736 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001737
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001738 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001739 status=${res:${#res}-3}
1740
1741 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001742 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001743 return 1
1744 fi
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001745 if [ $# -gt 2 ]; then
1746 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1747 body=${res:0:${#res}-3}
1748 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001749
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001750 if [ $res -ne 0 ]; then
1751 __log_test_fail_body
1752 return 1
1753 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001754 fi
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001755 __collect_endpoint_stats "PMS" 08 "GET" $PMS_API_PREFIX"/policies/{policy_id}/status" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001756 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001757 return 0
1758}
1759
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001760# API Test function: GET /policy_types and V2 GET /v2/policy-types
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001761# args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1762# (Function for test scripts)
1763api_get_policy_types() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001764 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001765
1766 if [ $# -lt 1 ]; then
1767 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1768 return 1
1769 fi
1770
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001771 if [ "$PMS_VERSION" == "V2" ]; then
1772 if [ $# -eq 1 ]; then
1773 query="/v2/policy-types"
1774 elif [ $2 == "NORIC" ]; then
1775 query="/v2/policy-types"
1776 else
1777 query="/v2/policy-types?ric_id=$2"
1778 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001779 else
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001780 if [ $# -eq 1 ]; then
1781 query="/policy_types"
1782 elif [ $2 == "NORIC" ]; then
1783 query="/policy_types"
1784 else
1785 query="/policy_types?ric=$2"
1786 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001787 fi
1788
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001789 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001790 status=${res:${#res}-3}
1791
1792 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001793 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001794 return 1
1795 fi
1796
1797 if [ $# -gt 2 ]; then
1798 body=${res:0:${#res}-3}
1799 targetJson="["
1800
1801 for pid in ${@:3} ; do
1802 if [ "$targetJson" != "[" ]; then
1803 targetJson=$targetJson","
1804 fi
1805 if [ $pid == "EMPTY" ]; then
1806 pid=""
1807 fi
1808 targetJson=$targetJson"\"$pid\""
1809 done
1810
1811 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001812 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001813 targetJson="{\"policytype_ids\": $targetJson }"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001814 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001815 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001816 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001817
1818 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001819 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001820 return 1
1821 fi
1822 fi
1823
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001824 __collect_endpoint_stats "PMS" 09 "GET" $PMS_API_PREFIX"/v2/policy-types" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001825 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001826 return 0
1827}
1828
1829#########################################################
1830#### Test case functions Health check
1831#########################################################
1832
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001833# API Test function: GET /status and V2 GET /status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001834# args: <response-code>
1835# (Function for test scripts)
1836api_get_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001837 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001838 if [ $# -ne 1 ]; then
1839 __print_err "<response-code>" $@
1840 return 1
1841 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001842 if [ "$PMS_VERSION" == "V2" ]; then
1843 query="/v2/status"
1844 else
1845 query="/status"
1846 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001847 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001848 status=${res:${#res}-3}
1849
1850 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001851 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001852 return 1
1853 fi
1854
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001855 __collect_endpoint_stats "PMS" 10 "GET" $PMS_API_PREFIX"/v2/status" $status
1856 __log_test_pass
1857 return 0
1858}
1859
1860# API Test function: GET /status (root) without api prefix
1861# args: <response-code>
1862# (Function for test scripts)
1863api_get_status_root() {
1864 __log_test_start $@
1865 if [ $# -ne 1 ]; then
1866 __print_err "<response-code>" $@
1867 return 1
1868 fi
1869 query="/status"
1870 TMP_PREFIX=$PMS_API_PREFIX
1871 PMS_API_PREFIX=""
1872 res="$(__do_curl_to_api PA GET $query)"
1873 PMS_API_PREFIX=$TMP_PREFIX
1874 status=${res:${#res}-3}
1875
1876 if [ $status -ne $1 ]; then
1877 __log_test_fail_status_code $1 $status
1878 return 1
1879 fi
1880
1881 __collect_endpoint_stats "PMS" 19 "GET" "/status" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001882 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001883 return 0
1884}
1885
1886#########################################################
1887#### Test case functions RIC Repository
1888#########################################################
1889
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001890# API Test function: GET /ric and V2 GET /v2/rics/ric
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001891# args: <reponse-code> <management-element-id> [<ric-id>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001892# (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1893# (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1894# (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1895
1896
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001897# (Function for test scripts)
1898api_get_ric() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001899 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001900
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001901 if [ "$PMS_VERSION" == "V2" ]; then
1902 if [ $# -lt 3 ]; then
1903 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1904 return 1
1905 fi
1906 search=""
1907 if [ $2 != "NOME" ]; then
1908 search="?managed_element_id="$2
1909 fi
1910 if [ $3 != "NORIC" ]; then
1911 if [ -z $search ]; then
1912 search="?ric_id="$3
1913 else
1914 search=$search"&ric_id="$3
1915 fi
1916 fi
1917 query="/v2/rics/ric"$search
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001918
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001919 res="$(__do_curl_to_api PA GET $query)"
1920 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001921
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001922 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001923 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001924 return 1
1925 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001926
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001927 if [ $# -gt 3 ]; then
1928 body=${res:0:${#res}-3}
1929 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1930 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001931 __log_test_fail_general "Could not create target ric info json"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001932 return 1
1933 fi
1934
1935 targetJson=$(<./tmp/.tmp_rics.json)
1936 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1937 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1938 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1939 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001940 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001941 return 1
1942 fi
1943 fi
1944 else
1945 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1946 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1947 return 1
1948 fi
1949
1950 query="/ric?managedElementId="$2
1951
1952 res="$(__do_curl_to_api PA GET $query)"
1953 status=${res:${#res}-3}
1954
1955 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001956 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001957 return 1
1958 fi
1959
1960 if [ $# -eq 3 ]; then
1961 body=${res:0:${#res}-3}
1962 if [ "$body" != "$3" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001963 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001964 return 1
1965 fi
1966 fi
1967 fi
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001968
1969 __collect_endpoint_stats "PMS" 11 "GET" $PMS_API_PREFIX"/v2/rics/ric" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001970 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001971 return 0
1972}
1973
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001974# API test function: GET /rics and V2 GET /v2/rics
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001975# args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1976# 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_........."
1977# format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1978# (Function for test scripts)
1979api_get_rics() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001980 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001981
1982 if [ $# -lt 2 ]; then
1983 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1984 return 1
1985 fi
1986
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001987 if [ "$PMS_VERSION" == "V2" ]; then
1988 query="/v2/rics"
1989 if [ $2 != "NOTYPE" ]; then
1990 query="/v2/rics?policytype_id="$2
1991 fi
1992 else
1993 query="/rics"
1994 if [ $2 != "NOTYPE" ]; then
1995 query="/rics?policyType="$2
1996 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001997 fi
1998
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001999 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002000 status=${res:${#res}-3}
2001
2002 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002003 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002004 return 1
2005 fi
2006
2007 if [ $# -gt 2 ]; then
2008 body=${res:0:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002009 if [ "$PMS_VERSION" == "V2" ]; then
2010 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
2011 else
2012 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
2013 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002014 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002015 __log_test_fail_general "Could not create target ric info json"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002016 return 1
2017 fi
2018
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002019 targetJson=$(<./tmp/.tmp_rics.json)
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002020 if [ "$PMS_VERSION" == "V2" ]; then
2021 targetJson="{\"rics\": $targetJson }"
2022 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002023 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002024 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002025 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002026 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002027 return 1
2028 fi
2029 fi
2030
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002031 __collect_endpoint_stats "PMS" 12 "GET" $PMS_API_PREFIX"/v2/rics" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002032 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002033 return 0
2034}
2035
2036##################################################################
2037#### API Test case functions Service registry and supervision ####
2038##################################################################
2039
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002040# API test function: PUT /service and V2 PUT /service
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002041# args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
2042# (Function for test scripts)
2043api_put_service() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002044 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002045 if [ $# -ne 4 ]; then
2046 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
2047 return 1
2048 fi
2049
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002050 if [ "$PMS_VERSION" == "V2" ]; then
2051 query="/v2/services"
2052 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
2053 else
2054 query="/service"
2055 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
2056 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002057 file="./tmp/.tmp.json"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002058 echo "$json" > $file
2059
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002060 res="$(__do_curl_to_api PA PUT $query $file)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002061 status=${res:${#res}-3}
2062
2063 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002064 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002065 return 1
2066 fi
2067
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002068 __collect_endpoint_stats "PMS" 13 "PUT" $PMS_API_PREFIX"/v2/service" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002069 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002070 return 0
2071}
2072
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002073# API test function: GET /services and V2 GET /v2/services
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002074#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>]* )]
2075# (Function for test scripts)
2076api_get_services() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002077 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002078 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
2079 paramError=1
2080 if [ $# -eq 1 ]; then
2081 paramError=0
2082 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
2083 paramError=0
2084 elif [ $# -eq 5 ]; then
2085 paramError=0
2086 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
2087 argLen=$(($#-2))
2088 if [ $(($argLen%3)) -eq 0 ]; then
2089 paramError=0
2090 fi
2091 fi
2092
2093 if [ $paramError -ne 0 ]; then
2094 __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>]* )]" $@
2095 return 1
2096 fi
2097
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002098 if [ "$PMS_VERSION" == "V2" ]; then
2099 query="/v2/services"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002100
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002101 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2102 query="/v2/services?service_id="$2
2103 fi
2104 else
2105 query="/services"
2106
2107 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2108 query="/services?name="$2
2109 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002110 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002111 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002112 status=${res:${#res}-3}
2113
2114 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002115 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002116 return 1
2117 fi
2118
2119 if [ $# -gt 2 ]; then
2120 variableArgCount=$(($#-2))
2121 body=${res:0:${#res}-3}
2122 targetJson="["
2123 shift; shift;
2124 cntr=0
2125 while [ $cntr -lt $variableArgCount ]; do
2126 servicename=$1; shift;
2127 timeout=$1; shift;
2128 callback=$1; shift;
2129 if [ $cntr -gt 0 ]; then
2130 targetJson=$targetJson","
2131 fi
2132 # timeSinceLastActivitySeconds value cannot be checked since value varies
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002133 if [ "$PMS_VERSION" == "V2" ]; then
2134 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
2135 else
2136 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2137 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002138 let cntr=cntr+3
2139 done
2140 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002141 if [ "$PMS_VERSION" == "V2" ]; then
2142 targetJson="{\"service_list\": $targetJson }"
2143 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002144 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002145 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002146 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002147 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002148 return 1
2149 fi
2150 fi
2151
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002152 __collect_endpoint_stats "PMS" 14 "GET" $PMS_API_PREFIX"/v2/services" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002153 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002154 return 0
2155}
2156
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002157# API test function: GET /services V2 GET /v2/services - (only checking service names)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002158# args: <response-code> [<service-name>]*"
2159# (Function for test scripts)
2160api_get_service_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002161 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002162
2163 if [ $# -lt 1 ]; then
2164 __print_err "<response-code> [<service-name>]*" $@
2165 return 1
2166 fi
2167
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002168 if [ "$PMS_VERSION" == "V2" ]; then
2169 query="/v2/services"
2170 else
2171 query="/services"
2172 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002173 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002174 status=${res:${#res}-3}
2175
2176 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002177 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002178 return 1
2179 fi
2180
2181 body=${res:0:${#res}-3}
2182 targetJson="["
2183 for rapp in ${@:2} ; do
2184 if [ "$targetJson" != "[" ]; then
2185 targetJson=$targetJson","
2186 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002187 if [ "$PMS_VERSION" == "V2" ]; then
2188 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2189 else
2190 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2191 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002192 done
2193
2194 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002195 if [ "$PMS_VERSION" == "V2" ]; then
2196 targetJson="{\"service_list\": $targetJson }"
2197 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002198 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002199 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002200
2201 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002202 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002203 return 1
2204 fi
2205
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002206 __collect_endpoint_stats "PMS" 14 "GET" $PMS_API_PREFIX"/v2/services" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002207 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002208 return 0
2209}
2210
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002211# API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002212# args: <response-code> <service-name>
2213# (Function for test scripts)
2214api_delete_services() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002215 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002216
2217 if [ $# -ne 2 ]; then
2218 __print_err "<response-code> <service-name>" $@
2219 return 1
2220 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002221 if [ "$PMS_VERSION" == "V2" ]; then
2222 query="/v2/services/"$2
2223 else
2224 query="/services?name="$2
2225 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002226 res="$(__do_curl_to_api PA DELETE $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002227 status=${res:${#res}-3}
2228
2229 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002230 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002231 return 1
2232 fi
2233
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002234 __collect_endpoint_stats "PMS" 15 "DELETE" $PMS_API_PREFIX"/v2/services/{serviceId}" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002235 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002236 return 0
2237}
2238
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002239# API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002240# args: <response-code> <service-name>
2241# (Function for test scripts)
2242api_put_services_keepalive() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002243 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002244
2245 if [ $# -ne 2 ]; then
2246 __print_err "<response-code> <service-name>" $@
2247 return 1
2248 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002249 if [ "$PMS_VERSION" == "V2" ]; then
2250 query="/v2/services/$2/keepalive"
2251 else
2252 query="/services/keepalive?name="$2
2253 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002254
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002255 res="$(__do_curl_to_api PA PUT $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002256 status=${res:${#res}-3}
2257
2258 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002259 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002260 return 1
2261 fi
2262
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002263 __collect_endpoint_stats "PMS" 16 "PUT" $PMS_API_PREFIX"/v2/services/{service_id}/keepalive" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002264 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002265 return 0
2266}
2267
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002268##################################################################
2269#### API Test case functions Configuration ####
2270##################################################################
2271
2272# API Test function: PUT /v2/configuration
2273# args: <response-code> <config-file>
2274# (Function for test scripts)
2275api_put_configuration() {
2276 __log_test_start $@
2277
2278 if [ "$PMS_VERSION" != "V2" ]; then
2279 __log_test_fail_not_supported
2280 return 1
2281 fi
2282
2283 if [ $# -ne 2 ]; then
2284 __print_err "<response-code> <config-file>" $@
2285 return 1
2286 fi
2287 if [ ! -f $2 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002288 __log_test_fail_general "Config file "$2", does not exist"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002289 return 1
2290 fi
2291 inputJson=$(< $2)
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002292 if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
2293 inputJson="{\"config\":"$inputJson"}"
2294 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002295 file="./tmp/.config.json"
2296 echo $inputJson > $file
2297 query="/v2/configuration"
2298 res="$(__do_curl_to_api PA PUT $query $file)"
2299 status=${res:${#res}-3}
2300
2301 if [ $status -ne $1 ]; then
2302 __log_test_fail_status_code $1 $status
2303 return 1
2304 fi
2305
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002306 __collect_endpoint_stats "PMS" 17 "PUT" $PMS_API_PREFIX"/v2/configuration" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002307 __log_test_pass
2308 return 0
2309}
2310
2311# API Test function: GET /v2/configuration
2312# args: <response-code> [<config-file>]
2313# (Function for test scripts)
2314api_get_configuration() {
2315 __log_test_start $@
2316
2317 if [ "$PMS_VERSION" != "V2" ]; then
2318 __log_test_fail_not_supported
2319 return 1
2320 fi
2321
2322 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2323 __print_err "<response-code> [<config-file>]" $@
2324 return 1
2325 fi
2326 if [ ! -f $2 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002327 __log_test_fail_general "Config file "$2" for comparison, does not exist"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002328 return 1
2329 fi
2330
2331 query="/v2/configuration"
2332 res="$(__do_curl_to_api PA GET $query)"
2333 status=${res:${#res}-3}
2334
2335 if [ $status -ne $1 ]; then
2336 __log_test_fail_status_code $1 $status
2337 return 1
2338 fi
2339
2340 if [ $# -eq 2 ]; then
2341
2342 body=${res:0:${#res}-3}
2343
2344 targetJson=$(< $2)
2345 targetJson="{\"config\":"$targetJson"}"
2346 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2347 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2348
2349 if [ $res -ne 0 ]; then
2350 __log_test_fail_body
2351 return 1
2352 fi
2353 fi
2354
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002355 __collect_endpoint_stats "PMS" 18 "GET" $PMS_API_PREFIX"/v2/configuration" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002356 __log_test_pass
2357 return 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002358}
2359
2360##########################################
2361#### Reset types and instances ####
2362##########################################
2363
2364# Admin reset to remove all policies and services
2365# All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2366# NOTE - only works in kubernetes and the pod should not be running
2367# args: -
2368# (Function for test scripts)
2369
2370pms_kube_pvc_reset() {
2371 __log_test_start $@
2372
BjornMagnussonXA663566c2021-11-08 10:25:07 +01002373 pvc_name=$(kubectl get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +02002374 if [ -z "$pvc_name" ]; then
2375 pvc_name=policymanagementservice-vardata-pvc
2376 fi
2377 echo " Trying to reset pvc: "$pvc_name
BjornMagnussonXA663566c2021-11-08 10:25:07 +01002378 __kube_clean_pvc $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $POLICY_AGENT_CONTAINER_MNT_DIR
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002379
2380 __log_test_pass
2381 return 0
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002382}