3 # ============LICENSE_START===============================================
4 # Copyright (C) 2021-2023 Nordix Foundation. All rights reserved.
5 # Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved.
6 # ========================================================================
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 # ============LICENSE_END=================================================
21 # This is a script that contains management and test functions for A1PMS
23 ################ Test engine functions ################
25 # Create the image var used during the test
26 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
27 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
28 __A1PMS_imagesetup() {
29 __check_and_create_image_var A1PMS "A1PMS_IMAGE" "A1PMS_IMAGE_BASE" "A1PMS_IMAGE_TAG" $1 "$A1PMS_DISPLAY_NAME" ""
32 # Pull image from remote repo or use locally built image
33 # arg: <pull-policy-override> <pull-policy-original>
34 # <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
35 # <pull-policy-original> Shall be used for images that does not allow overriding
36 # Both var may contain: 'remote', 'remote-remove' or 'local'
38 __check_and_pull_image $1 "$A1PMS_DISPLAY_NAME" $A1PMS_APP_NAME A1PMS_IMAGE
41 # Build image (only for simulator or interfaces stubs owned by the test environment)
42 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
43 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
44 __A1PMS_imagebuild() {
45 echo -e $RED" Image for app A1PMS shall never be built"$ERED
48 # Generate a string for each included image using the app display name and a docker images format string
49 # If a custom image repo is used then also the source image from the local repo is listed
50 # arg: <docker-images-format-string> <file-to-append>
51 __A1PMS_image_data() {
52 echo -e "$A1PMS_DISPLAY_NAME\t$(docker images --format $1 $A1PMS_IMAGE)" >>$2
53 if [ ! -z "$A1PMS_IMAGE_SOURCE" ]; then
54 echo -e "-- source image --\t$(docker images --format $1 $A1PMS_IMAGE_SOURCE)" >>$2
58 # Scale kubernetes resources to zero
59 # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
60 # This function is called for apps fully managed by the test script
61 __A1PMS_kube_scale_zero() {
62 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS
65 # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
66 # This function is called for pre-started apps not managed by the test script.
67 __A1PMS_kube_scale_zero_and_wait() {
68 __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app "$KUBE_NONRTRIC_NAMESPACE"-policymanagementservice
71 # Delete all kube resources for the app
72 # This function is called for apps managed by the test script.
73 __A1PMS_kube_delete_all() {
74 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS
78 # This function is called for apps managed by the test script.
79 # args: <log-dir> <file-prefix>
80 __A1PMS_store_docker_logs() {
81 if [ $RUNMODE == "KUBE" ]; then
82 kubectl $KUBECONF logs -l "autotest=A1PMS" -n $KUBE_NONRTRIC_NAMESPACE --tail=-1 >$1$2_a1pms.log 2>&1
84 docker logs $A1PMS_APP_NAME >$1$2_a1pms.log 2>&1
88 # Initial setup of protocol, host and ports
89 # This function is called for apps managed by the test script.
91 __A1PMS_initial_setup() {
93 export A1PMS_SIDECAR_JWT_FILE=""
96 # Set app short-name, app name and namespace for logging runtime statistics of kubernetes pods or docker containers
97 # For docker, the namespace shall be excluded
98 # This function is called for apps managed by the test script as well as for pre-started apps.
100 __A1PMS_statistics_setup() {
101 if [ $RUNMODE == "KUBE" ]; then
102 echo "A1PMS $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE"
104 echo "A1PMS $A1PMS_APP_NAME"
108 # Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
110 __A1PMS_test_requirements() {
114 #######################################################
116 ###########################
118 ###########################
120 # Set http as the protocol to use for all communication to the A1PMS
122 # (Function for test scripts)
123 use_a1pms_rest_http() {
124 __a1pms_set_protocoll "http" $A1PMS_INTERNAL_PORT $A1PMS_EXTERNAL_PORT
127 # Set https as the protocol to use for all communication to the A1PMS
129 # (Function for test scripts)
130 use_a1pms_rest_https() {
131 __a1pms_set_protocoll "https" $A1PMS_INTERNAL_SECURE_PORT $A1PMS_EXTERNAL_SECURE_PORT
134 # All calls to the a1pms will be directed to the a1pms dmaap interface over http from now on
136 # (Function for test scripts)
137 use_a1pms_dmaap_http() {
138 echo -e $BOLD"$A1PMS_DISPLAY_NAME dmaap protocol setting"$EBOLD
139 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the a1pms"
140 A1PMS_ADAPTER_TYPE="MR-HTTP"
144 # All calls to the a1pms will be directed to the a1pms dmaap interface over https from now on
146 # (Function for test scripts)
147 use_a1pms_dmaap_https() {
148 echo -e $BOLD"$A1PMS_DISPLAY_NAME dmaap protocol setting"$EBOLD
149 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the a1pms"
150 echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
151 A1PMS_ADAPTER_TYPE="MR-HTTPS"
155 # Setup paths to svc/container for internal and external access
156 # args: <protocol> <internal-port> <external-port>
157 __a1pms_set_protocoll() {
158 echo -e $BOLD"$A1PMS_DISPLAY_NAME protocol setting"$EBOLD
159 echo -e " Using $BOLD $1 $EBOLD towards $A1PMS_DISPLAY_NAME"
161 ## Access to Dmaap adapter
163 A1PMS_SERVICE_PATH=$1"://"$A1PMS_APP_NAME":"$2 # docker access, container->container and script->container via proxy
164 if [ $RUNMODE == "KUBE" ]; then
165 A1PMS_SERVICE_PATH=$1"://"$A1PMS_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
168 # A1PMS_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
169 A1PMS_ADAPTER_TYPE="REST"
170 A1PMS_ADAPTER=$A1PMS_SERVICE_PATH
175 # Make curl retries towards the a1pms for http response codes set in this env var, space separated list of codes
178 #Save first worker node the pod is started on
179 __A1PMS_WORKER_NODE=""
181 # Export env vars for config files, docker compose and kube resources
182 # args: PROXY|NOPROXY
183 __export_a1pms_vars() {
185 export A1PMS_APP_NAME
186 export A1PMS_APP_NAME_ALIAS
187 export A1PMS_DISPLAY_NAME
189 export KUBE_NONRTRIC_NAMESPACE
191 export A1PMS_INTERNAL_PORT
192 export A1PMS_INTERNAL_SECURE_PORT
193 export A1PMS_EXTERNAL_PORT
194 export A1PMS_EXTERNAL_SECURE_PORT
195 export A1PMS_CONFIG_MOUNT_PATH
196 export A1PMS_DATA_MOUNT_PATH
197 export A1PMS_CONFIG_CONFIGMAP_NAME=$A1PMS_APP_NAME"-config"
198 export A1PMS_DATA_CONFIGMAP_NAME=$A1PMS_APP_NAME"-data"
199 export A1PMS_PKG_NAME
200 export A1PMS_CONFIG_KEY
201 export DOCKER_SIM_NWNAME
202 export A1PMS_HOST_MNT_DIR
203 export A1PMS_CONFIG_FILE
205 export A1PMS_DATA_PV_NAME=$A1PMS_APP_NAME"-pv"
206 export A1PMS_DATA_PVC_NAME=$A1PMS_APP_NAME"-pvc"
207 ##Create a unique path for the pv each time to prevent a previous volume to be reused
208 export A1PMS_PV_PATH="a1pmsdata-"$(date +%s)
209 export A1PMS_CONTAINER_MNT_DIR
210 export HOST_PATH_BASE_DIR
212 if [ $1 == "PROXY" ]; then
213 export A1PMS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
214 export A1PMS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
215 if [ $A1PMS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$A1PMS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
216 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
218 echo " Configured with http proxy"
221 export A1PMS_HTTP_PROXY_CONFIG_PORT=0
222 export A1PMS_HTTP_PROXY_CONFIG_HOST_NAME=""
223 echo " Configured without http proxy"
228 # args: (docker) PROXY|NOPROXY <config-file>
229 # args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
230 # (Function for test scripts)
232 echo -e $BOLD"Starting $A1PMS_DISPLAY_NAME"$EBOLD
234 if [ $RUNMODE == "KUBE" ]; then
236 # Check if app shall be fully managed by the test script
237 __check_included_image "A1PMS"
240 # Check if app shall only be used by the test script
241 __check_prestarted_image "A1PMS"
244 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
245 echo -e $RED"The $A1PMS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
246 echo -e $RED"The $A1PMS_APP_NAME will not be started"$ERED
249 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
250 echo -e $RED"The $A1PMS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
251 echo -e $RED"The $A1PMS_APP_NAME will not be started"$ERED
255 if [ $retcode_p -eq 0 ]; then
256 echo -e " Using existing $A1PMS_APP_NAME deployment and service"
257 echo " Setting $A1PMS_APP_NAME replicas=1"
258 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
259 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
262 if [ $retcode_i -eq 0 ]; then
264 echo -e " Creating $A1PMS_APP_NAME app and expose service"
266 #Check if nonrtric namespace exists, if not create it
267 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
269 __export_a1pms_vars $1
271 # Create config map for config
272 configfile=$PWD/tmp/$A1PMS_CONFIG_FILE
274 output_yaml=$PWD/tmp/a1pms-cfc.yaml
275 __kube_create_configmap $A1PMS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $configfile $output_yaml
277 # Create config map for data
278 data_json=$PWD/tmp/$A1PMS_DATA_FILE
279 if [ $# -lt 3 ]; then
280 #create empty dummy file
281 echo "{}" >$data_json
285 output_yaml=$PWD/tmp/a1pms-cfd.yaml
286 __kube_create_configmap $A1PMS_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $data_json $output_yaml
289 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"pv.yaml
290 output_yaml=$PWD/tmp/a1pms-pv.yaml
291 __kube_create_instance pv $A1PMS_APP_NAME $input_yaml $output_yaml
294 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"pvc.yaml
295 output_yaml=$PWD/tmp/a1pms-pvc.yaml
296 __kube_create_instance pvc $A1PMS_APP_NAME $input_yaml $output_yaml
299 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"svc.yaml
300 output_yaml=$PWD/tmp/a1pmssvc.yaml
301 __kube_create_instance service $A1PMS_APP_NAME $input_yaml $output_yaml
304 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"app.yaml
305 output_yaml=$PWD/tmp/a1pmsapp.yaml
306 if [ -z "$A1PMS_SIDECAR_JWT_FILE" ]; then
307 cat $input_yaml | sed '/#A1PMS_JWT_START/,/#A1PMS_JWT_STOP/d' >$PWD/tmp/a1pmsapp_tmp.yaml
308 input_yaml=$PWD/tmp/a1pmsapp_tmp.yaml
310 __kube_create_instance app $A1PMS_APP_NAME $input_yaml $output_yaml
314 # 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
315 if [ $retcode_i -eq 0 ]; then
316 __A1PMS_WORKER_NODE=$(kubectl $KUBECONF get pod -l "autotest=A1PMS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
317 if [ -z "$__A1PMS_WORKER_NODE" ]; then
318 echo -e $YELLOW" Cannot find worker node for pod for $A1PMS_APP_NAME, persistency may not work"$EYELLOW
321 echo -e $YELLOW" Persistency may not work for app $A1PMS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
324 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
327 __check_included_image 'A1PMS'
328 if [ $? -eq 1 ]; then
329 echo -e $RED"The A1PMS app is not included in this test script"$ERED
330 echo -e $RED"The A1PMS will not be started"$ERED
337 cd $A1PMS_HOST_MNT_DIR
340 if [ "$(ls -A $DIR)" ]; then
341 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
342 rm -rf db/* &>/dev/null
343 if [ $? -ne 0 ]; then
344 echo -e $RED" Cannot remove database files in: $PWD"$ERED
349 echo " No files in mounted dir or dir does not exists"
354 __export_a1pms_vars $1
356 dest_file=$SIM_GROUP/$A1PMS_COMPOSE_DIR/$A1PMS_HOST_MNT_DIR/application.yaml
358 envsubst <$2 >$dest_file
360 __start_container $A1PMS_COMPOSE_DIR "" NODOCKERARGS 1 $A1PMS_APP_NAME
362 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
365 __collect_endpoint_stats_image_info "A1PMS" $A1PMS_IMAGE
373 # (Function for test scripts)
375 echo -e $BOLD"Stopping $A1PMS_DISPLAY_NAME"$EBOLD
377 if [ $RUNMODE == "KUBE" ]; then
379 __check_prestarted_image "A1PMS"
380 if [ $? -eq 0 ]; then
381 echo -e $YELLOW" Persistency may not work for app $A1PMS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
382 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
383 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
386 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS
387 echo " Deleting the replica set - a new will be started when the app is started"
388 tmp=$(kubectl $KUBECONF delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
389 if [ $? -ne 0 ]; then
390 echo -e $RED" Could not delete replica set "$RED
395 docker stop $A1PMS_APP_NAME &>./tmp/.dockererr
396 if [ $? -ne 0 ]; then
397 __print_err "Could not stop $A1PMS_APP_NAME" $@
403 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
408 # Start a previously stopped a1pms
410 # (Function for test scripts)
411 start_stopped_a1pms() {
412 echo -e $BOLD"Starting (the previously stopped) $A1PMS_DISPLAY_NAME"$EBOLD
414 if [ $RUNMODE == "KUBE" ]; then
416 __check_prestarted_image "A1PMS"
417 if [ $? -eq 0 ]; then
418 echo -e $YELLOW" Persistency may not work for app $A1PMS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
419 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
420 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
421 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
425 # Tie the A1PMS to the same worker node it was initially started on
426 # A PVC of type hostPath is mounted to A1PMS, for persistent storage, so the A1PMS must always be on the node which mounted the volume
427 if [ -z "$__A1PMS_WORKER_NODE" ]; then
428 echo -e $RED" No initial worker node found for pod "$RED
432 echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__A1PMS_WORKER_NODE to deployment for $A1PMS_APP_NAME. Pod will always run on this worker node: $__A1PMS_WORKER_NODE"$BOLD
433 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
434 tmp=$(kubectl $KUBECONF patch deployment $A1PMS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__A1PMS_WORKER_NODE'"}}}}}')
435 if [ $? -ne 0 ]; then
436 echo -e $YELLOW" Cannot set nodeSelector to deployment for $A1PMS_APP_NAME, persistency may not work"$EYELLOW
438 __kube_scale deployment $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
441 docker start $A1PMS_APP_NAME &>./tmp/.dockererr
442 if [ $? -ne 0 ]; then
443 __print_err "Could not start (the stopped) $A1PMS_APP_NAME" $@
449 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
450 if [ $? -ne 0 ]; then
457 # Function to prepare the a1pms configuration according to the current simulator configuration
458 # args: SDNC|NOSDNC <output-file> [ <sim-group> <adapter-class> ]
459 # (Function for test scripts)
460 prepare_a1pms_config() {
461 echo -e $BOLD"Prepare A1PMS config"$EBOLD
463 echo " Writing a1pms config for "$A1PMS_APP_NAME" to file: "$2
465 if [ $# != 2 ] && [ $# != 4 ]; then
467 __print_err "need two or four args, SDNC|NOSDNC <output-file> [ <sim-group> <adapter-class> ]" $@
471 if [ $1 == "SDNC" ]; then
472 echo -e " Config$BOLD including SDNC$EBOLD configuration"
473 elif [ $1 == "NOSDNC" ]; then
474 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
477 __print_err "need three args, SDNC|NOSDNC <output-file> HEADER|NOHEADER" $@
482 if [ $1 == "SDNC" ]; then
483 config_json=$config_json"\n \"controller\": ["
484 config_json=$config_json"\n {"
485 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
486 config_json=$config_json"\n \"baseUrl\": \"$SDNC_SERVICE_PATH\","
487 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
488 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
489 config_json=$config_json"\n }"
490 config_json=$config_json"\n ],"
492 if [[ "$A1PMS_FEATURE_LEVEL" == *"NO-DMAAP"* ]]; then
495 config_json=$config_json"\n \"streams_publishes\": {"
496 config_json=$config_json"\n \"dmaap_publisher\": {"
497 config_json=$config_json"\n \"type\": \"message-router\","
498 config_json=$config_json"\n \"dmaap_info\": {"
499 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_WRITE_URL\""
500 config_json=$config_json"\n }"
501 config_json=$config_json"\n }"
502 config_json=$config_json"\n },"
503 config_json=$config_json"\n \"streams_subscribes\": {"
504 config_json=$config_json"\n \"dmaap_subscriber\": {"
505 config_json=$config_json"\n \"type\": \"message-router\","
506 config_json=$config_json"\n \"dmaap_info\": {"
507 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_READ_URL\""
508 config_json=$config_json"\n }"
509 config_json=$config_json"\n }"
510 config_json=$config_json"\n },"
513 config_json=$config_json"\n \"ric\": ["
515 if [ $RUNMODE == "KUBE" ]; then
516 result=$(kubectl $KUBECONF get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICSIM")].metadata.name}')
519 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
520 for im in $result; do
521 if [[ $im != *"-0" ]]; then
522 ric_subdomain=$(kubectl $KUBECONF get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
523 rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
524 let ric_cntr=ric_cntr+1
528 result=$(kubectl $KUBECONF get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICMEDIATORSIM")].metadata.name}')
530 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
531 for im in $result; do
532 if [[ $im != *"-0" ]]; then
533 ric_subdomain=$(kubectl $KUBECONF get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
534 rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
535 oranrics=$oranrics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
536 let ric_cntr=ric_cntr+1
540 if [ $ric_cntr -eq 0 ]; then
541 echo $YELLOW"Warning: No rics found for the configuration"$EYELLOW
544 rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "label=a1sim" --filter "status=running" --format {{.Names}})
545 oranrics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "label=orana1sim" --filter "status=running" --format {{.Names}})
547 rics="$rics $oranrics"
549 if [ $? -ne 0 ] || [ -z "$rics" ]; then
550 echo -e $RED" FAIL - the names of the running RIC Simulator or ORAN RIC cannot be retrieved." $ERED
557 if [ $cntr -gt 0 ]; then
558 config_json=$config_json"\n ,"
560 config_json=$config_json"\n {"
561 if [ $RUNMODE == "KUBE" ]; then
562 ric_id=${ric%.*.*} #extract pod id from full hosthame
563 ric_id=$(echo "$ric_id" | tr '-' '_')
565 ric_id=$(echo "$ric" | tr '-' '_') #ric var still needs underscore as it is different from the container name
567 echo " Found a1 sim: "$ric
568 config_json=$config_json"\n \"name\": \"$ric_id\","
571 for xric in $oranrics; do
572 if [ $xric == $ric ]; then
576 if [ $xricfound -eq 0 ]; then
577 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
579 config_json=$config_json"\n \"baseUrl\": \"$RICMEDIATOR_SIM_HTTPX://$ric:$RICMEDIATOR_SIM_PORT\","
581 if [ ! -z "$3" ]; then
582 if [[ $ric == "$3"* ]]; then
583 config_json=$config_json"\n \"customAdapterClass\": \"$4\","
586 if [ $1 == "SDNC" ]; then
587 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
589 config_json=$config_json"\n \"managedElementIds\": ["
590 config_json=$config_json"\n \"me1_$ric_id\","
591 config_json=$config_json"\n \"me2_$ric_id\""
592 config_json=$config_json"\n ]"
593 config_json=$config_json"\n }"
597 config_json=$config_json"\n ]"
598 config_json=$config_json"\n}"
600 config_json="{\"config\":"$config_json"}"
602 printf "$config_json" >$2
607 # Load the the appl config for the a1pms into a config map
608 a1pms_load_config() {
609 echo -e $BOLD"A1PMS - load config from "$EBOLD$1
610 data_json=$PWD/tmp/$A1PMS_DATA_FILE
612 output_yaml=$PWD/tmp/a1pms-cfd.yaml
613 __kube_create_configmap $A1PMS_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $data_json $output_yaml
617 # Turn on debug level tracing in the a1pms
619 # (Function for test scripts)
621 echo -e $BOLD"Setting a1pms debug logging"$EBOLD
622 curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
623 result=$(__do_curl "$curlString")
624 if [ $? -ne 0 ]; then
625 __print_err "could not set debug mode" $@
633 # Turn on trace level tracing in the a1pms
635 # (Function for test scripts)
637 echo -e $BOLD"Setting a1pms trace logging"$EBOLD
638 curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
639 result=$(__do_curl "$curlString")
640 if [ $? -ne 0 ]; then
641 __print_err "could not set trace mode" $@
649 # Perform curl retries when making direct call to the a1pms for the specified http response codes
650 # Speace separated list of http response codes
651 # args: [<response-code>]*
652 use_a1pms_retries() {
653 echo -e $BOLD"Do curl retries to the a1pms REST inteface for these response codes:$@"$EBOLD
659 # Check the a1pms logs for WARNINGs and ERRORs
661 # (Function for test scripts)
663 __check_container_logs "A1PMS" $A1PMS_APP_NAME $A1PMS_LOGPATH WARN ERR
666 #########################################################
667 #### Test case functions A1 Policy management service
668 #########################################################
670 # This function compare the size, towards a target value, of a json array returned from <url> of the A1PMS.
671 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
672 # args: json:<url> <target-value> [<timeout-in-seconds]
673 # (Function for test scripts)
675 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >>$HTTPLOG
676 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
677 if [[ $1 == "json:"* ]]; then
678 if [ "$A1PMS_VERSION" == "V2" ]; then
679 __var_test "A1PMS" $A1PMS_SERVICE_PATH$A1PMS_API_PREFIX"/v2/" $1 "=" $2 $3
680 elif [ "$A1PMS_VERSION" == "V3" ]; then
681 echo "var test execution for V3"
682 __var_test "A1PMS" $A1PMS_SERVICE_PATH$A1PMS_API_PREFIX"/v1/" $1 "=" $2 $3
684 __var_test "A1PMS" $A1PMS_SERVICE_PATH"/" $1 "=" $2 $3
689 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
693 # API Test function: GET /policies and V2 GET /v2/policy-instances
694 # 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>]*]
695 # 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>]*]
696 # (Function for test scripts)
697 a1pms_api_get_policies() {
700 if [ "$A1PMS_VERSION" == "V2" ]; then
702 variableParams=$(($# - 4))
703 if [ $# -lt 4 ]; then
705 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
707 elif [ $# -gt 5 ] && [ $(($variableParams % 7)) -ne 0 ]; then
711 if [ $paramError -ne 0 ]; then
712 __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>]*]" $@
717 variableParams=$(($# - 4))
718 if [ $# -lt 4 ]; then
720 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
722 elif [ $# -gt 5 ] && [ $(($variableParams % 5)) -ne 0 ]; then
726 if [ $paramError -ne 0 ]; then
727 __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>]*]" $@
733 if [ "$A1PMS_VERSION" == "V2" ]; then
734 if [ $2 != "NORIC" ]; then
735 queryparams="?ric_id="$2
737 if [ $3 != "NOSERVICE" ]; then
738 if [ -z $queryparams ]; then
739 queryparams="?service_id="$3
741 queryparams=$queryparams"&service_id="$3
744 if [ $4 != "NOTYPE" ]; then
745 if [ -z $queryparams ]; then
746 queryparams="?policytype_id="$4
748 queryparams=$queryparams"&policytype_id="$4
752 query="/v2/policy-instances"$queryparams
753 res="$(__do_curl_to_api A1PMS GET $query)"
754 status=${res:${#res}-3}
756 if [ $status -ne $1 ]; then
757 __log_test_fail_status_code $1 $status
761 if [ $# -gt 4 ]; then
762 body=${res:0:${#res}-3}
763 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
769 for ((i = 0; i < $(($# - 4)); i = i + 7)); do
771 if [ "$targetJson" != "[" ]; then
772 targetJson=$targetJson","
774 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i + 1]}\",\"service_id\":\"${arr[$i + 2]}\",\"policytype_id\":"
775 if [ "${arr[$i + 3]}" == "EMPTY" ]; then
776 targetJson=$targetJson"\"\","
778 targetJson=$targetJson"\"${arr[$i + 3]}\","
780 targetJson=$targetJson"\"transient\":${arr[$i + 4]},\"status_notification_uri\":\"${arr[$i + 5]}\","
782 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i + 6]} >$file
784 targetJson=$targetJson"\"policy_data\":"$json"}"
788 targetJson=$targetJson"]"
789 targetJson="{\"policies\": $targetJson}"
790 echo "TARGET JSON: $targetJson" >>$HTTPLOG
791 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
793 if [ $res -ne 0 ]; then
799 if [ $2 != "NORIC" ]; then
800 queryparams="?ric="$2
802 if [ $3 != "NOSERVICE" ]; then
803 if [ -z $queryparams ]; then
804 queryparams="?service="$3
806 queryparams=$queryparams"&service="$3
809 if [ $4 != "NOTYPE" ]; then
810 if [ -z $queryparams ]; then
811 queryparams="?type="$4
813 queryparams=$queryparams"&type="$4
817 query="/policies"$queryparams
818 res="$(__do_curl_to_api A1PMS GET $query)"
819 status=${res:${#res}-3}
821 if [ $status -ne $1 ]; then
822 __log_test_fail_status_code $1 $status
826 if [ $# -gt 4 ]; then
827 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
830 body=${res:0:${#res}-3}
834 for ((i = 0; i < $(($# - 4)); i = i + 5)); do
836 if [ "$targetJson" != "[" ]; then
837 targetJson=$targetJson","
839 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i + 1]}\",\"service\":\"${arr[$i + 2]}\",\"type\":"
840 if [ "${arr[$i + 3]}" == "EMPTY" ]; then
841 targetJson=$targetJson"\"\","
843 targetJson=$targetJson"\"${arr[$i + 3]}\","
846 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i + 4]} >$file
848 targetJson=$targetJson"\"json\":"$json"}"
852 targetJson=$targetJson"]"
853 echo "TARGET JSON: $targetJson" >>$HTTPLOG
854 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
856 if [ $res -ne 0 ]; then
862 __collect_endpoint_stats "A1PMS" 00 "GET" $A1PMS_API_PREFIX"/v2/policy-instances" $status
868 # API Test function: GET /policy, V2 GET /v2/policies/{policy_id} and V3 GET a1policymanagement/v1/policies/{policy_id}
869 # args: <response-code> <policy-id> [<template-file>]
870 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
871 # (Function for test scripts)
872 a1pms_api_get_policy() {
875 if [ "$A1PMS_VERSION" == "V2" ]; then
876 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
877 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
880 query="/v2/policies/$UUID$2"
881 elif [ "$A1PMS_VERSION" == "V3" ]; then
882 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
883 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
886 query="/v1/policies/$UUID$2"
888 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
889 __print_err "<response-code> <policy-id> [<template-file>] " $@
892 query="/policy?id=$UUID$2"
894 res="$(__do_curl_to_api A1PMS GET $query)"
895 status=${res:${#res}-3}
897 if [ $status -ne $1 ]; then
898 __log_test_fail_status_code $1 $status
902 if [ "$A1PMS_VERSION" == "V2" ]; then
903 if [ $# -eq 8 ]; then
905 #Create a policy json to compare with
906 body=${res:0:${#res}-3}
908 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
909 if [ $7 != "NOTRANSIENT" ]; then
910 targetJson=$targetJson", \"transient\":$7"
912 if [ $6 != "NOTYPE" ]; then
913 targetJson=$targetJson", \"policytype_id\":\"$6\""
915 targetJson=$targetJson", \"policytype_id\":\"\""
917 if [ $8 != "NOURL" ]; then
918 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
921 data=$(sed 's/XXX/'${2}'/g' $3)
922 targetJson=$targetJson", \"policy_data\":$data"
923 targetJson="{$targetJson}"
925 echo "TARGET JSON: $targetJson" >>$HTTPLOG
926 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
927 if [ $res -ne 0 ]; then
932 elif [ "$A1PMS_VERSION" == "V3" ]; then
933 if [ $# -eq 8 ]; then
934 #Create a policy json to compare with
935 body=${res:0:${#res}-3}
936 data=$(sed 's/XXX/'${2}'/g' $3)
939 echo "TARGET JSON: $targetJson" >>$HTTPLOG
940 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
941 if [ $res -ne 0 ]; then
947 if [ $# -eq 3 ]; then
948 #Create a policy json to compare with
949 body=${res:0:${#res}-3}
951 sed 's/XXX/'${2}'/g' $3 >$file
953 echo "TARGET JSON: $targetJson" >>$HTTPLOG
954 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
955 if [ $res -ne 0 ]; then
961 __collect_endpoint_stats "A1PMS" 01 "GET" ${A1PMS_API_PREFIX}${query} ${status}
966 # API Test function: PUT /policy and V2 PUT /policies
967 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
968 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
969 # (Function for test scripts)
970 a1pms_api_put_policy() {
973 if [ "$A1PMS_VERSION" == "V2" ] || [ "$A1PMS_VERSION" == "V3" ]; then
974 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
975 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
979 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
980 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
993 if [ "$A1PMS_VERSION" == "V2" ]; then
996 if [ $# -eq 9 ]; then
1001 if [ $# -eq 8 ]; then
1006 while [ $count -lt $max ]; do
1007 if [ "$A1PMS_VERSION" == "V2" ]; then
1009 query="/v2/policies"
1011 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1012 if [ $trans != "NOTRANSIENT" ]; then
1013 inputJson=$inputJson", \"transient\":$trans"
1015 if [ $pt != "NOTYPE" ]; then
1016 inputJson=$inputJson", \"policytype_id\":\"$pt\""
1018 inputJson=$inputJson", \"policytype_id\":\"\""
1020 if [ $noti != "NOURL" ]; then
1021 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1023 file="./tmp/.p.json"
1024 data=$(sed 's/XXX/'${pid}'/g' $temp)
1025 inputJson=$inputJson", \"policy_data\":$data"
1026 inputJson="{$inputJson}"
1027 echo $inputJson >$file
1029 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
1031 if [ $pt != "NOTYPE" ]; then
1032 query=$query"&type=$pt"
1035 if [ $trans != NOTRANSIENT ]; then
1036 query=$query"&transient=$trans"
1039 file="./tmp/.p.json"
1040 sed 's/XXX/'${pid}'/g' $temp >$file
1042 res="$(__do_curl_to_api A1PMS PUT $query $file)"
1043 status=${res:${#res}-3}
1044 echo -ne " Executing "$count"("$max")${SAMELINE}"
1045 if [ $status -ne $1 ]; then
1046 echo " Executed "$count"?("$max")"
1047 __log_test_fail_status_code $1 $status
1052 echo -ne " Executed "$count"("$max")${SAMELINE}"
1054 __collect_endpoint_stats "A1PMS" 02 "PUT" ${A1PMS_API_PREFIX}${query} ${status} ${max}
1061 # API Test function: V3 PUT a1policymanagement/v1/policies
1062 # args: <response-code> <policy-id> <template-file> [<count>]
1063 # args(V2): <response-code> <policy-id> <template-file> [<count>]
1064 # (Function for test scripts)
1065 a1pms_api_put_policy_v3() {
1068 if [ $# -lt 3 ] || [ $# -gt 4 ]; then
1069 __print_err "<response-code> <policy-id> <template-file> [<count>]" $@
1078 if [ $# -eq 4 ]; then
1082 while [ $count -lt $max ]; do
1083 query="/v1/policies/$UUID$pid"
1084 file="./tmp/.p_v3.json"
1085 let update_value=$pid+300
1086 data=$(sed 's/XXX/'${update_value}'/g' $temp)
1088 echo $inputJson >$file
1089 res="$(__do_curl_to_api A1PMS PUT $query $file)"
1090 status=${res:${#res}-3}
1091 echo -ne " Executing "$count"("$max")${SAMELINE}"
1092 if [ $status -ne $1 ]; then
1093 echo " Executed "$count"?("$max")"
1094 __log_test_fail_status_code $1 $status
1099 echo -ne " Executed "$count"("$max")${SAMELINE}"
1101 __collect_endpoint_stats "A1PMS" 02 "PUT" ${A1PMS_API_PREFIX}${query} ${status} ${max}
1108 # API Test function: V£ POST a1policymanagement/v1/policies
1109 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
1110 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
1111 # (Function for test scripts)
1112 a1pms_api_post_policy_v3() {
1115 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1116 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
1129 if [ $# -eq 9 ]; then
1133 while [ $count -lt $max ]; do
1134 query="/v1/policies"
1136 inputJson="\"nearRtRicId\":\"$ric\""
1137 if [ $pt != "NOTYPE" ]; then
1138 inputJson=$inputJson", \"policyTypeId\":\"$pt\""
1140 inputJson=$inputJson", \"policyTypeId\":\"\""
1142 if [ $serv != "NOSERVICE" ]; then
1143 inputJson=$inputJson", \"serviceId\":\"$serv\""
1145 if [ $noti != "NONOTIFYURL" ]; then
1146 inputJson=$inputJson", \"statusNotificationUri\":\"$noti\""
1148 if [ $trans != "NOTRANSIENT" ]; then
1149 inputJson=$inputJson", \"transient\":\"$trans\""
1151 file="./tmp/.p.json"
1152 data=$(sed 's/XXX/'${pid}'/g' $temp)
1153 inputJson=$inputJson", \"policyObject\":$data"
1154 inputJson=$inputJson", \"policyId\":\"$UUID$pid\""
1155 inputJson="{$inputJson}"
1156 echo $inputJson >$file
1157 res="$(__do_curl_to_api A1PMS POST $query $file)"
1158 status=${res:${#res}-3}
1159 echo -ne " Executing "$count"("$max")${SAMELINE}"
1160 if [ $status -ne $1 ]; then
1161 echo " Executed "$count"?("$max")"
1162 __log_test_fail_status_code $1 $status
1167 echo -ne " Executed "$count"("$max")${SAMELINE}"
1169 __collect_endpoint_stats "A1PMS" 02 "PUT" ${A1PMS_API_PREFIX}${A1PMS_VERSION} ${status} ${max}
1176 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
1177 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
1178 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
1179 # (Function for test scripts)
1181 a1pms_api_put_policy_batch() {
1184 if [ "$A1PMS_VERSION" == "V2" ]; then
1185 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1186 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
1190 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1191 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
1203 if [ "$A1PMS_VERSION" == "V2" ]; then
1206 if [ $# -eq 9 ]; then
1211 if [ $# -eq 8 ]; then
1217 while [ $count -lt $max ]; do
1218 if [ "$A1PMS_VERSION" == "V2" ]; then
1219 query="/v2/policies"
1221 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1222 if [ $trans != "NOTRANSIENT" ]; then
1223 inputJson=$inputJson", \"transient\":$trans"
1225 if [ $pt != "NOTYPE" ]; then
1226 inputJson=$inputJson", \"policytype_id\":\"$pt\""
1228 inputJson=$inputJson", \"policytype_id\":\"\""
1230 if [ $noti != "NOURL" ]; then
1231 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1233 file="./tmp/.p.json"
1234 data=$(sed 's/XXX/'${pid}'/g' $temp)
1235 inputJson=$inputJson", \"policy_data\":$data"
1236 inputJson="{$inputJson}"
1237 echo $inputJson >$file
1239 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
1241 if [ $pt != "NOTYPE" ]; then
1242 query=$query"&type=$pt"
1245 if [ $trans != NOTRANSIENT ]; then
1246 query=$query"&transient=$trans"
1248 file="./tmp/.p.json"
1249 sed 's/XXX/'${pid}'/g' $temp >$file
1251 res="$(__do_curl_to_api A1PMS PUT_BATCH $query $file)"
1252 status=${res:${#res}-3}
1253 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1255 if [ $status -ne 200 ]; then
1256 echo " Requested(batch) "$count"?("$max")"
1257 __log_test_fail_status_code 200 $status
1260 cid=${res:0:${#res}-3}
1264 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1271 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1272 status=${res:${#res}-3}
1273 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
1275 if [ $status -ne $1 ]; then
1276 echo " Accepted(batch) "$count"?("$max")"
1277 __log_test_fail_status_code $1 $status
1282 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
1284 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $1 $max
1292 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
1293 # 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>
1294 # 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>
1295 # (Function for test scripts)
1296 a1pms_api_put_policy_parallel() {
1299 if [ "$A1PMS_VERSION" == "V2" ]; then
1300 if [ $# -ne 11 ]; then
1301 __print_err "These all arguments needed <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>" $@
1320 if [ "$A1PMS_VERSION" == "V2" ]; then
1333 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1334 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1335 echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1336 echo " Info - will execute over a1pms REST"
1338 if [ "$A1PMS_VERSION" == "V2" ]; then
1339 if [ $serv == "NOSERVICE" ]; then
1342 query="$A1PMS_API_PREFIX/v2/policies"
1344 if [ $serv == "NOSERVICE" ]; then
1347 query="/policy?service=$serv"
1349 if [ $type != "NOTYPE" ]; then
1350 query=$query"&type=$type"
1353 if [ $transient != NOTRANSIENT ]; then
1354 query=$query"&transient=$transient"
1358 urlbase=${A1PMS_ADAPTER}${query}
1361 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1362 httpproxy=$KUBE_PROXY_PATH
1365 for ((i = 1; i <= $pids; i++)); do
1367 if [ -z "$uuid" ]; then
1370 echo "" >"./tmp/.pid${i}.res.txt"
1371 if [ "$A1PMS_VERSION" == "V2" ]; then
1372 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy >"./tmp/.pid${i}.txt"
1374 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy >"./tmp/.pid${i}.txt"
1377 done | xargs -n 1 -I{} -P $pids bash -c '{
1379 echo " Parallel process $arg started"
1380 tmp=$(< "./tmp/.pid${arg}.txt")
1381 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1384 for ((i = 1; i <= $pids; i++)); do
1385 file="./tmp/.pid${i}.res.txt"
1387 if [ -z "$tmp" ]; then
1388 echo " Process $i : unknown result (result file empty"
1392 if [ $res == "0" ]; then
1393 echo " Process $i : OK - "${tmp:1}
1395 echo " Process $i : failed - "${tmp:1}
1400 if [ -z $msg ]; then
1401 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $resp_code $(($count * $num_rics))
1402 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1405 __log_test_fail_general "One of more processes failed to execute"
1409 # API Test function: V3 POST /policies, to run in i parallel for a number of rics
1410 # 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>
1411 # args(V3): <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>
1412 # (Function for test scripts)
1413 a1pms_api_post_policy_parallel() {
1416 if [ $# -ne 11 ]; then
1417 __print_err "These all arguments needed <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>" $@
1444 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1445 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1446 echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1447 echo " Info - will execute over a1pms REST"
1450 if [ $serv == "NOSERVICE" ]; then
1453 query="$A1PMS_API_PREFIX/v1/policies"
1455 urlbase=${A1PMS_ADAPTER}${query}
1458 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1459 httpproxy=$KUBE_PROXY_PATH
1462 for ((i = 1; i <= $pids; i++)); do
1464 if [ -z "$uuid" ]; then
1467 echo "" >"./tmp/.pid${i}.res.txt"
1468 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy >"./tmp/.pid${i}.txt"
1470 done | xargs -n 1 -I{} -P $pids bash -c '{
1472 echo " Parallel process $arg started"
1473 tmp=$(< "./tmp/.pid${arg}.txt")
1474 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1477 for ((i = 1; i <= $pids; i++)); do
1478 file="./tmp/.pid${i}.res.txt"
1480 if [ -z "$tmp" ]; then
1481 echo " Process $i : unknown result (result file empty"
1485 if [ $res == "0" ]; then
1486 echo " Process $i : OK - "${tmp:1}
1488 echo " Process $i : failed - "${tmp:1}
1493 if [ -z $msg ]; then
1494 __collect_endpoint_stats "A1PMS" 02 "POST" $A1PMS_API_PREFIX"/v1/policies" $resp_code $(($count * $num_rics))
1495 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1498 __log_test_fail_general "One of more processes failed to execute"
1502 # API Test function: V3 PUT /policies, to run in i parallel for a number of rics
1503 # 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> <policy-ids-file-path>
1504 # args(V3): <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> <policy-ids-file-path>
1505 # (Function for test scripts)
1506 a1pms_api_update_policy_parallel() {
1509 if [ $# -ne 12 ]; then
1510 __print_err "These all arguments needed <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> <policy-ids-file-path>" $@
1536 policy_ids_file_path=$1
1539 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1540 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1541 echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1542 echo " Info - will execute over a1pms REST"
1545 if [ $serv == "NOSERVICE" ]; then
1548 query="$A1PMS_API_PREFIX/v1/policies"
1550 urlbase=${A1PMS_ADAPTER}${query}
1553 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1554 httpproxy=$KUBE_PROXY_PATH
1557 for ((i = 1; i <= $pids; i++)); do
1559 if [ -z "$uuid" ]; then
1562 echo "" >"./tmp/.pid${i}.res.txt"
1563 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy $policy_ids_file_path >"./tmp/.pid${i}.txt"
1565 done | xargs -n 1 -I{} -P $pids bash -c '{
1567 echo " Parallel process $arg started"
1568 tmp=$(< "./tmp/.pid${arg}.txt")
1569 python3 ../common/update_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1572 for ((i = 1; i <= $pids; i++)); do
1573 file="./tmp/.pid${i}.res.txt"
1575 if [ -z "$tmp" ]; then
1576 echo " Process $i : unknown result (result file empty"
1580 if [ $res == "0" ]; then
1581 echo " Process $i : OK - "${tmp:1}
1583 echo " Process $i : failed - "${tmp:1}
1588 if [ -z $msg ]; then
1589 __collect_endpoint_stats "A1PMS" 02 "POST" $A1PMS_API_PREFIX"/v1/policies" $resp_code $(($count * $num_rics))
1590 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1593 __log_test_fail_general "One of more processes failed to execute"
1597 # API Test function: DELETE /policy, V2 DELETE /v2/policies/{policy_id} and V3 DELETE a1policymanagement/v1/policies/{policy_id}
1598 # args: <response-code> <policy-id> [count]
1599 # (Function for test scripts)
1600 a1pms_api_delete_policy() {
1603 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1604 __print_err "<response-code> <policy-id> [count]" $@
1611 if [ $# -eq 3 ]; then
1617 while [ $count -lt $max ]; do
1618 if [ "$A1PMS_VERSION" == "V2" ]; then
1619 query="/v2/policies/"$UUID$pid
1620 elif [ "$A1PMS_VERSION" == "V3" ]; then
1621 query="/v1/policies/"$UUID$pid
1623 query="/policy?id="$UUID$pid
1625 res="$(__do_curl_to_api A1PMS DELETE $query)"
1626 status=${res:${#res}-3}
1627 echo -ne " Executing "${count}"("${max}")${SAMELINE}"
1629 if [ $status -ne $1 ]; then
1630 echo " Executed "${count}"?("${max}")"
1631 __log_test_fail_status_code $1 $status
1637 echo -ne " Executed "${count}"("${max}")${SAMELINE}"
1639 __collect_endpoint_stats "A1PMS" 03 "DELETE" ${A1PMS_API_PREFIX}${query} ${status} ${max}
1646 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
1647 # args: <response-code> <policy-id> [count]
1648 # (Function for test scripts)
1649 a1pms_api_delete_policy_batch() {
1652 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1653 __print_err "<response-code> <policy-id> [count]" $@
1660 if [ $# -eq 3 ]; then
1666 while [ $count -lt $max ]; do
1667 if [ "$A1PMS_VERSION" == "V2" ]; then
1668 query="/v2/policies/"$UUID$pid
1670 query="/policy?id="$UUID$pid
1672 res="$(__do_curl_to_api A1PMS DELETE_BATCH $query)"
1673 status=${res:${#res}-3}
1674 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1676 if [ $status -ne 200 ]; then
1677 echo " Requested(batch) "$count"?("$max")"
1678 __log_test_fail_status_code 200 $status
1681 cid=${res:0:${#res}-3}
1685 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1693 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1694 status=${res:${#res}-3}
1695 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1697 if [ $status -ne $1 ]; then
1698 echo " Deleted(batch) "$count"?("$max")"
1699 __log_test_fail_status_code $1 $status
1704 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1706 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $1 $max
1714 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1715 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1716 # (Function for test scripts)
1717 a1pms_api_delete_policy_parallel() {
1720 if [ $# -ne 5 ]; then
1721 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1735 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1736 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1737 echo " Info - a1pms_api_delete_policy_parallel uses only the a1pms REST interface - delete over dmaap in parallel is not supported"
1738 echo " Info - will execute over a1pms REST"
1741 if [ "$A1PMS_VERSION" == "V2" ]; then
1742 query="$A1PMS_API_PREFIX/v2/policies/"
1747 urlbase=${A1PMS_ADAPTER}${query}
1750 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1751 httpproxy=$KUBE_PROXY_PATH
1754 for ((i = 1; i <= $pids; i++)); do
1756 if [ -z "$uuid" ]; then
1759 echo "" >"./tmp/.pid${i}.del.res.txt"
1760 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy >"./tmp/.pid${i}.del.txt"
1762 done | xargs -n 1 -I{} -P $pids bash -c '{
1764 echo " Parallel process $arg started"
1765 tmp=$(< "./tmp/.pid${arg}.del.txt")
1766 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1769 for ((i = 1; i <= $pids; i++)); do
1770 file="./tmp/.pid${i}.del.res.txt"
1772 if [ -z "$tmp" ]; then
1773 echo " Process $i : unknown result (result file empty"
1777 if [ $res == "0" ]; then
1778 echo " Process $i : OK - "${tmp:1}
1780 echo " Process $i : failed - "${tmp:1}
1785 if [ -z $msg ]; then
1786 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count * $num_rics))
1787 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1791 __log_test_fail_general "One of more processes failed to execute"
1795 # API Test function: V3 DELETE a1policymanagement/v1/policies/{policy_id}, to run in i parallel for a number of rics
1796 # args: <responseCode> <numberOfRics> <PolicyIdsFilePath> <countPerRic> <numberOfThreads>
1797 # (Function for test scripts)
1798 a1pms_api_delete_policy_parallel_v3() {
1801 if [ $# -ne 6 ]; then
1802 __print_err " <responseCode> <numberOfRics> <PolicyIdsFilePath> <StartID> <countPerRic> <numberOfThreads>" $@
1809 policy_ids_file_path=$1
1818 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1819 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1820 echo " Info - a1pms_api_delete_policy_parallel uses only the a1pms REST interface - delete over dmaap in parallel is not supported"
1821 echo " Info - will execute over a1pms REST"
1824 query="$A1PMS_API_PREFIX/v1/policies/"
1825 urlbase=${A1PMS_ADAPTER}${query}
1827 urlbase=${A1PMS_ADAPTER}${query}
1830 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1831 httpproxy=$KUBE_PROXY_PATH
1834 for ((i = 1; i <= $pids; i++)); do
1835 echo "" >"./tmp/.pid${i}.del.res.txt"
1836 echo $resp_code $urlbase $policy_ids_file_path $start_id $pids $i $httpproxy >"./tmp/.pid${i}.del.txt"
1838 done | xargs -n 1 -I{} -P $pids bash -c '{
1840 echo " Parallel process $arg started"
1841 tmp=$(< "./tmp/.pid${arg}.del.txt")
1842 python3 ../common/delete_policies_process_v3.py $tmp > ./tmp/.pid${arg}.del.res.txt
1845 for ((i = 1; i <= $pids; i++)); do
1846 file="./tmp/.pid${i}.del.res.txt"
1848 if [ -z "$tmp" ]; then
1849 echo " Process $i : unknown result (result file empty"
1853 if [ $res == "0" ]; then
1854 echo " Process $i : OK - "${tmp:1}
1856 echo " Process $i : failed - "${tmp:1}
1861 if [ -z $msg ]; then
1862 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v1/policies/{policy_id}" $resp_code $(($count * $num_rics))
1863 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1867 __log_test_fail_general "One of more processes failed to execute"
1871 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}, to run in i parallel for a number of rics
1872 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1873 # (Function for test scripts)
1874 a1pms_api_get_policy_parallel() {
1877 if [ $# -ne 5 ]; then
1878 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1892 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1893 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1894 echo " Info - a1pms_api_get_policy_parallel uses only the a1pms REST interface - GET over dmaap in parallel is not supported"
1895 echo " Info - will execute over a1pms REST"
1898 if [ "$A1PMS_VERSION" == "V2" ]; then
1899 query="$A1PMS_API_PREFIX/v2/policies/"
1904 urlbase=${A1PMS_ADAPTER}${query}
1907 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1908 httpproxy=$KUBE_PROXY_PATH
1911 for ((i = 1; i <= $pids; i++)); do
1913 if [ -z "$uuid" ]; then
1916 echo "" >"./tmp/.pid${i}.get.res.txt"
1917 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy >"./tmp/.pid${i}.get.txt"
1919 done | xargs -n 1 -I{} -P $pids bash -c '{
1921 echo " Parallel process $arg started"
1922 tmp=$(< "./tmp/.pid${arg}.get.txt")
1923 python3 ../common/get_policies_process.py $tmp > ./tmp/.pid${arg}.get.res.txt
1926 for ((i = 1; i <= $pids; i++)); do
1927 file="./tmp/.pid${i}.get.res.txt"
1929 if [ -z "$tmp" ]; then
1930 echo " Process $i : unknown result (result file empty"
1934 if [ $res == "0" ]; then
1935 echo " Process $i : OK - "${tmp:1}
1937 echo " Process $i : failed - "${tmp:1}
1942 if [ -z $msg ]; then
1943 __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count * $num_rics))
1944 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1948 __log_test_fail_general "One of more processes failed to execute"
1952 # API Test function: V3 GET a1policymanagement/v1/policies/{policy_id}, to run in i parallel for a number of rics
1953 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1954 # (Function for test scripts)
1955 a1pms_api_get_policy_parallel_v3() {
1958 if [ $# -ne 6 ]; then
1959 __print_err " <responseCode> <numberOfRics> <PolicyIdsFilePath> <startID> <countPerRic> <numberOfThreads>" $@
1966 policy_ids_file_path=$1
1975 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1976 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1977 echo " Info - a1pms_api_get_policy_parallel uses only the a1pms REST interface - GET over dmaap in parallel is not supported"
1978 echo " Info - will execute over a1pms REST"
1981 query="$A1PMS_API_PREFIX/v1/policies/"
1982 urlbase=${A1PMS_ADAPTER}${query}
1985 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1986 httpproxy=$KUBE_PROXY_PATH
1989 for ((i = 1; i <= $pids; i++)); do
1990 echo "" >"./tmp/.pid${i}.get.res.txt"
1991 echo $resp_code $urlbase $policy_ids_file_path $start_id $pids $i $httpproxy >"./tmp/.pid${i}.get.txt"
1993 done | xargs -n 1 -I{} -P $pids bash -c '{
1995 echo " Parallel process $arg started"
1996 tmp=$(< "./tmp/.pid${arg}.get.txt")
1997 python3 ../common/get_policies_process_v3.py $tmp > ./tmp/.pid${arg}.get.res.txt
2000 for ((i = 1; i <= $pids; i++)); do
2001 file="./tmp/.pid${i}.get.res.txt"
2003 if [ -z "$tmp" ]; then
2004 echo " Process $i : unknown result (result file empty"
2008 if [ $res == "0" ]; then
2009 echo " Process $i : OK - "${tmp:1}
2011 echo " Process $i : failed - "${tmp:1}
2016 if [ -z $msg ]; then
2017 __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v1/policies/{policyId}" $resp_code $(($count * $num_rics))
2018 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
2022 __log_test_fail_general "One of more processes failed to execute"
2026 # API Test function: GET /policy_ids and V2 GET /v2/policies
2027 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
2028 # (Function for test scripts)
2029 a1pms_api_get_policy_ids() {
2032 if [ $# -lt 4 ]; then
2033 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
2039 if [ "$A1PMS_VERSION" == "V2" ]; then
2040 if [ $2 != "NORIC" ]; then
2041 queryparams="?ric_id="$2
2044 if [ $3 != "NOSERVICE" ]; then
2045 if [ -z $queryparams ]; then
2046 queryparams="?service_id="$3
2048 queryparams=$queryparams"&service_id="$3
2051 if [ $4 != "NOTYPE" ]; then
2052 if [ -z $queryparams ]; then
2053 queryparams="?policytype_id="$4
2055 queryparams=$queryparams"&policytype_id="$4
2059 query="/v2/policies"$queryparams
2061 if [ $2 != "NORIC" ]; then
2062 queryparams="?ric="$2
2065 if [ $3 != "NOSERVICE" ]; then
2066 if [ -z $queryparams ]; then
2067 queryparams="?service="$3
2069 queryparams=$queryparams"&service="$3
2072 if [ $4 != "NOTYPE" ]; then
2073 if [ -z $queryparams ]; then
2074 queryparams="?type="$4
2076 queryparams=$queryparams"&type="$4
2080 query="/policy_ids"$queryparams
2083 res="$(__do_curl_to_api A1PMS GET $query)"
2084 status=${res:${#res}-3}
2086 if [ $status -ne $1 ]; then
2087 __log_test_fail_status_code $1 $status
2091 if [ $# -gt 4 ]; then
2092 body=${res:0:${#res}-3}
2095 for pid in ${@:5}; do
2096 if [ "$targetJson" != "[" ]; then
2097 targetJson=$targetJson","
2099 if [ $pid != "NOID" ]; then
2100 targetJson=$targetJson"\"$UUID$pid\""
2104 targetJson=$targetJson"]"
2105 if [ "$A1PMS_VERSION" == "V2" ]; then
2106 targetJson="{\"policy_ids\": $targetJson}"
2108 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2109 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2111 if [ $res -ne 0 ]; then
2112 __log_test_fail_body
2117 __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v2/policies" $status
2122 # API Test function: V3 GET a1policymanagement/v1/policies
2123 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
2124 # (Function for test scripts)
2125 a1pms_api_get_all_policies_v3() {
2128 if [ $# -lt 4 ]; then
2129 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
2135 if [ $2 != "NORIC" ]; then
2136 queryparams="?nearRtRicId="$2
2139 if [ $3 != "NOSERVICE" ]; then
2140 if [ -z $queryparams ]; then
2141 queryparams="?serviceId="$3
2143 queryparams=$queryparams"&serviceId="$3
2146 if [ $4 != "NOTYPE" ]; then
2147 if [ -z $queryparams ]; then
2148 queryparams="?policyTypeId="$4
2150 queryparams=$queryparams"&policyTypeId="$4
2154 query="/v1/policies"$queryparams
2156 res="$(__do_curl_to_api A1PMS GET $query)"
2157 status=${res:${#res}-3}
2159 if [ $status -ne $1 ]; then
2160 __log_test_fail_status_code $1 $status
2164 if [ $# -gt 4 ]; then
2165 body=${res:0:${#res}-3}
2168 for pid in ${@:5}; do
2169 if [ "$targetJson" != "[" ]; then
2170 targetJson=$targetJson","
2172 IFS=':' read -r policy_id ric_id <<<"$pid"
2173 if [ $policy_id != "NOID" ]; then
2174 targetJson=$targetJson"{ \"policyId\": \"${UUID}${policy_id}\", \"nearRtRicId\": \"$ric_id\" }"
2178 targetJson=$targetJson"]"
2179 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2180 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2182 if [ $res -ne 0 ]; then
2183 __log_test_fail_body
2188 __collect_endpoint_stats "A1PMS" 04 "GET" ${A1PMS_API_PREFIX}${query} ${status}
2193 # API Test function: V2 GET a1-policy/v2/policy-types/{policyTypeId} and V3 GET a1policymanagement/v1/policytypes/{policyTypeId}
2194 # args(V2): <response-code> <policy-type-id> [<schema-file>]
2195 # (Function for test scripts)
2196 a1pms_api_get_policy_type() {
2199 if [ "$A1PMS_VERSION" != "V2" ] && [ "$A1PMS_VERSION" != "V3" ]; then
2200 __log_test_fail_not_supported
2204 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
2205 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
2208 if [ "$A1PMS_VERSION" == "V2" ]; then
2209 query="/v2/policy-types/$2"
2211 if [ "$A1PMS_VERSION" == "V3" ]; then
2212 query="/v1/policytypes/$2"
2215 res="$(__do_curl_to_api A1PMS GET $query)"
2216 status=${res:${#res}-3}
2218 if [ $status -ne $1 ]; then
2219 __log_test_fail_status_code $1 $status
2223 if [ $# -eq 3 ]; then
2225 body=${res:0:${#res}-3}
2228 if [ "$A1PMS_VERSION" == "V2" ]; then
2229 targetJson="{\"policy_schema\":$targetJson}"
2230 elif [ "$A1PMS_VERSION" == "V3" ]; then
2231 targetJson="$targetJson"
2233 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2234 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2236 if [ $res -ne 0 ]; then
2237 __log_test_fail_body
2242 __collect_endpoint_stats "A1PMS" 05 "GET" ${A1PMS_API_PREFIX}${query} ${status}
2247 # API Test function: GET /policy_schema
2248 # args: <response-code> <policy-type-id> [<schema-file>]
2249 # (Function for test scripts)
2250 a1pms_api_get_policy_schema() {
2253 if [ "$A1PMS_VERSION" == "V2" ]; then
2254 __log_test_fail_not_supported
2258 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
2259 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
2262 query="/policy_schema?id=$2"
2263 res="$(__do_curl_to_api A1PMS GET $query)"
2264 status=${res:${#res}-3}
2266 if [ $status -ne $1 ]; then
2267 __log_test_fail_status_code $1 $status
2271 if [ $# -eq 3 ]; then
2273 body=${res:0:${#res}-3}
2277 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2278 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2280 if [ $res -ne 0 ]; then
2281 __log_test_fail_body
2286 __collect_endpoint_stats "A1PMS" 06 "GET" $A1PMS_API_PREFIX"/v2/policy_schema" $status
2291 # API Test function: GET /policy_schemas
2292 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
2293 # args(V2): <response-code>
2294 # (Function for test scripts)
2295 a1pms_api_get_policy_schemas() {
2298 if [ "$A1PMS_VERSION" == "V2" ]; then
2299 if [ $# -ne 1 ]; then
2300 __print_err "<response-code>" $@
2304 if [ $# -lt 2 ]; then
2305 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
2309 if [ "$A1PMS_VERSION" == "V2" ]; then
2310 query="/v2/policy-schemas"
2312 query="/policy_schemas"
2313 if [ $2 != "NORIC" ]; then
2314 query=$query"?ric="$2
2318 res="$(__do_curl_to_api A1PMS GET $query)"
2319 status=${res:${#res}-3}
2321 if [ $status -ne $1 ]; then
2322 __log_test_fail_status_code $1 $status
2326 if [ $# -gt 2 ]; then
2327 body=${res:0:${#res}-3}
2330 for file in ${@:3}; do
2331 if [ "$targetJson" != "[" ]; then
2332 targetJson=$targetJson","
2334 if [ $file == "NOFILE" ]; then
2335 targetJson=$targetJson"{}"
2337 targetJson=$targetJson$(<$file)
2341 targetJson=$targetJson"]"
2342 if [ "$A1PMS_VERSION" == "V2" ]; then
2343 targetJson="{\"policy_schemas\": $targetJson }"
2345 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2346 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2348 if [ $res -ne 0 ]; then
2349 __log_test_fail_body
2354 __collect_endpoint_stats "A1PMS" 07 "GET" $A1PMS_API_PREFIX"/v2/policy-schemas" $status
2359 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
2360 # arg: <response-code> <policy-id> [ (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>) ]
2361 # (Function for test scripts)
2362 a1pms_api_get_policy_status() {
2365 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
2366 __print_err "<response-code> <policy-id> [(STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)]" $@
2371 if [ $# -eq 2 ]; then
2373 elif [ "$3" == "STD" ]; then
2374 targetJson="{\"enforceStatus\":\"$4\""
2375 if [ $# -eq 5 ]; then
2376 targetJson=$targetJson",\"reason\":\"$5\""
2378 targetJson=$targetJson"}"
2379 elif [ "$3" == "STD2" ]; then
2380 if [ $4 == "EMPTY" ]; then
2381 targetJson="{\"enforceStatus\":\"\""
2383 targetJson="{\"enforceStatus\":\"$4\""
2385 if [ $# -eq 5 ]; then
2386 if [ $5 == "EMPTY" ]; then
2387 targetJson=$targetJson",\"enforceReason\":\"\""
2389 targetJson=$targetJson",\"enforceReason\":\"$5\""
2392 targetJson=$targetJson"}"
2393 elif [ "$3" == "OSC" ]; then
2394 if [[ $TEST_ENV_PROFILE =~ ^ORAN-[A-H] ]] || [[ $TEST_ENV_PROFILE =~ ^ONAP-[A-L] ]]; then
2395 targetJson="{\"instance_status\":\"$4\""
2396 if [ $# -eq 5 ]; then
2397 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
2399 targetJson=$targetJson",\"created_at\":\"????\"}"
2401 targetJson="{\"enforceStatus\":\"$4\""
2402 if [ $# -eq 5 ]; then
2403 targetJson=$targetJson",\"enforceReason\":\"$5\"}"
2407 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
2411 if [ "$A1PMS_VERSION" == "V2" ]; then
2412 query="/v2/policies/$UUID$2/status"
2413 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
2415 query="/policy_status?id="$UUID$2
2418 res="$(__do_curl_to_api A1PMS GET $query)"
2419 status=${res:${#res}-3}
2421 if [ $status -ne $1 ]; then
2422 __log_test_fail_status_code $1 $status
2425 if [ $# -gt 2 ]; then
2426 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2427 body=${res:0:${#res}-3}
2428 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2430 if [ $res -ne 0 ]; then
2431 __log_test_fail_body
2435 __collect_endpoint_stats "A1PMS" 08 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}/status" $status
2440 # API Test function: GET /policy_types and V2 GET /v2/policy-types
2441 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
2442 # (Function for test scripts)
2443 a1pms_api_get_policy_types() {
2446 if [ $# -lt 1 ]; then
2447 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
2451 if [ "$A1PMS_VERSION" == "V2" ]; then
2452 if [ $# -eq 1 ]; then
2453 query="/v2/policy-types"
2454 elif [ $2 == "NORIC" ]; then
2455 query="/v2/policy-types"
2457 query="/v2/policy-types?ric_id=$2"
2460 if [ $# -eq 1 ]; then
2461 query="/policy_types"
2462 elif [ $2 == "NORIC" ]; then
2463 query="/policy_types"
2465 query="/policy_types?ric=$2"
2469 res="$(__do_curl_to_api A1PMS GET $query)"
2470 status=${res:${#res}-3}
2472 if [ $status -ne $1 ]; then
2473 __log_test_fail_status_code $1 $status
2477 if [ $# -gt 2 ]; then
2478 body=${res:0:${#res}-3}
2481 for pid in ${@:3}; do
2482 if [ "$targetJson" != "[" ]; then
2483 targetJson=$targetJson","
2485 if [ $pid == "EMPTY" ]; then
2488 targetJson=$targetJson"\"$pid\""
2491 targetJson=$targetJson"]"
2492 if [ "$A1PMS_VERSION" == "V2" ]; then
2493 targetJson="{\"policytype_ids\": $targetJson }"
2495 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2496 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2498 if [ $res -ne 0 ]; then
2499 __log_test_fail_body
2504 __collect_endpoint_stats "A1PMS" 09 "GET" $A1PMS_API_PREFIX"/v2/policy-types" $status
2509 # API Test function: V3 GET a1policymanagement/v1/policytypes
2510 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
2511 # (Function for test scripts)
2512 a1pms_api_get_policy_types_v3() {
2515 if [ $# -lt 1 ]; then
2516 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
2520 if [ $# -eq 1 ]; then
2521 query="/v1/policytypes"
2522 elif [ $2 == "NORIC" ]; then
2523 query="/v1/policytypes"
2525 query="/v1/policytypes?nearRtRicId=$2"
2527 res="$(__do_curl_to_api A1PMS GET $query)"
2528 status=${res:${#res}-3}
2530 if [ $status -ne $1 ]; then
2531 __log_test_fail_status_code $1 $status
2535 if [ $# -gt 2 ]; then
2536 body=${res:0:${#res}-3}
2539 for pid in ${@:3}; do
2540 if [ "$targetJson" != "[" ]; then
2541 targetJson=$targetJson","
2543 IFS=':' read -r policy_type_id ric_id <<<"$pid"
2544 # if [ -n "$policy_type_id" ] && [ -n "$ric_id" ]; then
2545 if [ $policy_type_id == "EMPTY" ]; then
2548 targetJson=$targetJson"{ \"policyTypeId\": \"$policy_type_id\", \"nearRtRicId\": \"$ric_id\" }"
2552 targetJson=$targetJson"]"
2554 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2555 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2557 if [ $res -ne 0 ]; then
2558 __log_test_fail_body
2563 __collect_endpoint_stats "A1PMS" 09 "GET" ${A1PMS_API_PREFIX}${query} ${status}
2568 #########################################################
2569 #### Test case functions Health check
2570 #########################################################
2572 # API Test function: GET /status and V2 GET /status or (v1/status for a1pmsV3)
2573 # args: <response-code>
2574 # (Function for test scripts)
2575 a1pms_api_get_status() {
2577 if [ $# -ne 1 ]; then
2578 __print_err "<response-code>" $@
2582 if [ "$A1PMS_VERSION" == "V2" ]; then
2584 elif [ "$A1PMS_VERSION" == "V3" ]; then
2590 res="$(__do_curl_to_api A1PMS GET $query)"
2591 status=${res:${#res}-3}
2593 if [ $status -ne $1 ]; then
2594 __log_test_fail_status_code $1 $status
2598 __collect_endpoint_stats "A1PMS" 10 "GET" $A1PMS_API_PREFIX$query $status
2603 # API Test function: GET /status (root) without api prefix
2604 # args: <response-code>
2605 # (Function for test scripts)
2606 a1pms_api_get_status_root() {
2608 if [ $# -ne 1 ]; then
2609 __print_err "<response-code>" $@
2613 TMP_PREFIX=$A1PMS_API_PREFIX
2615 res="$(__do_curl_to_api A1PMS GET $query)"
2616 A1PMS_API_PREFIX=$TMP_PREFIX
2617 status=${res:${#res}-3}
2619 if [ $status -ne $1 ]; then
2620 __log_test_fail_status_code $1 $status
2624 __collect_endpoint_stats "A1PMS" 19 "GET" "/status" $status
2629 #########################################################
2630 #### Test case functions RIC Repository
2631 #########################################################
2633 # API Test function: GET /ric, V2 GET /v2/rics/ric, and V3 GET a1policymanagement/v1/rics/ric
2634 # args: <reponse-code> <management-element-id> [<ric-id>]
2635 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
2636 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
2637 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
2639 # (Function for test scripts)
2640 a1pms_api_get_ric() {
2643 if [ "$A1PMS_VERSION" == "V2" ]; then
2644 if [ $# -lt 3 ]; then
2645 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
2649 if [ $2 != "NOME" ]; then
2650 search="?managed_element_id="$2
2652 if [ $3 != "NORIC" ]; then
2653 if [ -z $search ]; then
2656 search=$search"&ric_id="$3
2659 query="/v2/rics/ric"$search
2661 res="$(__do_curl_to_api A1PMS GET $query)"
2662 status=${res:${#res}-3}
2664 if [ $status -ne $1 ]; then
2665 __log_test_fail_status_code $1 $status
2669 if [ $# -gt 3 ]; then
2670 body=${res:0:${#res}-3}
2671 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4")
2672 if [ $res -ne 0 ]; then
2673 __log_test_fail_general "Could not create target ric info json"
2677 targetJson=$(<./tmp/.tmp_rics.json)
2678 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
2679 echo " TARGET JSON: $targetJson" >>$HTTPLOG
2680 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2681 if [ $res -ne 0 ]; then
2682 __log_test_fail_body
2686 elif [ "$A1PMS_VERSION" == "V3" ]; then
2687 if [ $# -lt 3 ]; then
2688 __print_err "<reponseCode> <managementElementId>|NOME <ricId>|<NORIC> [stringOfRicInfo>]" $@
2692 if [ $2 != "NOME" ]; then
2693 search="?managedElementId="$2
2695 if [ $3 != "NORIC" ]; then
2696 if [ -z $search ]; then
2699 search=$search"&ricId="$3
2702 query="/v1/rics/ric"$search
2704 res="$(__do_curl_to_api A1PMS GET $query)"
2705 status=${res:${#res}-3}
2707 if [ $status -ne $1 ]; then
2708 __log_test_fail_status_code $1 $status
2712 if [ $# -gt 3 ]; then
2713 body=${res:0:${#res}-3}
2714 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "${A1PMS_VERSION}" "$4")
2715 if [ $res -ne 0 ]; then
2716 __log_test_fail_general "Could not create target ric info json"
2720 targetJson=$(<./tmp/.tmp_rics.json)
2721 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
2722 echo " TARGET JSON: $targetJson" >>$HTTPLOG
2723 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2724 if [ $res -ne 0 ]; then
2725 __log_test_fail_body
2730 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
2731 __print_err "<reponseCode> <managedElementIds> [<ricId>]" $@
2735 query="/ric?managedElementId="$2
2737 res="$(__do_curl_to_api A1PMS GET $query)"
2738 status=${res:${#res}-3}
2740 if [ $status -ne $1 ]; then
2741 __log_test_fail_status_code $1 $status
2745 if [ $# -eq 3 ]; then
2746 body=${res:0:${#res}-3}
2747 if [ "$body" != "$3" ]; then
2748 __log_test_fail_body
2754 __collect_endpoint_stats "A1PMS" 11 "GET" ${A1PMS_API_PREFIX}${query} ${status}
2759 # API test function: GET /rics, V2 GET /v2/rics, and V3 GET /a1policymanagement/v1/rics
2760 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
2761 # 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_........."
2762 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
2763 # (Function for test scripts)
2764 a1pms_api_get_rics() {
2767 if [ $# -lt 2 ]; then
2768 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
2772 if [ "$A1PMS_VERSION" == "V2" ]; then
2774 if [ $2 != "NOTYPE" ]; then
2775 query="/v2/rics?policytype_id="$2
2777 elif [ "$A1PMS_VERSION" == "V3" ]; then
2779 if [ $2 != "NOTYPE" ]; then
2780 query=${query}"?policyTypeId="$2
2784 if [ $2 != "NOTYPE" ]; then
2785 query="/rics?policyType="$2
2789 res="$(__do_curl_to_api A1PMS GET $query)"
2790 status=${res:${#res}-3}
2792 if [ $status -ne $1 ]; then
2793 __log_test_fail_status_code $1 $status
2797 if [ $# -gt 2 ]; then
2798 body=${res:0:${#res}-3}
2799 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "${A1PMS_VERSION}" "$3")
2800 if [ $res -ne 0 ]; then
2801 __log_test_fail_general "Could not create target ric info json"
2805 targetJson=$(<./tmp/.tmp_rics.json)
2806 if [ "$A1PMS_VERSION" == "V2" ] || [ "$A1PMS_VERSION" == "V3" ]; then
2807 targetJson="{\"rics\": $targetJson }"
2809 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2810 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2811 if [ $res -ne 0 ]; then
2812 __log_test_fail_body
2817 __collect_endpoint_stats "A1PMS" 12 "GET" ${A1PMS_API_PREFIX}${query} ${status}
2822 ##################################################################
2823 #### API Test case functions Service registry and supervision ####
2824 ##################################################################
2826 # API test function: PUT /service, V2 PUT /service and V3 PUT a1policymanagement/v1/services
2827 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
2828 # (Function for test scripts)
2829 a1pms_api_put_service() {
2831 if [ $# -ne 4 ]; then
2832 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
2836 if [ "$A1PMS_VERSION" == "V2" ]; then
2837 query="/v2/services"
2838 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
2839 elif [ "$A1PMS_VERSION" == "V3" ]; then
2840 query="/v1/services"
2841 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceId\": \""$2"\"}"
2844 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
2846 file="./tmp/.tmp.json"
2849 res="$(__do_curl_to_api A1PMS PUT $query $file)"
2850 status=${res:${#res}-3}
2852 if [ $status -ne $1 ]; then
2853 __log_test_fail_status_code $1 $status
2857 __collect_endpoint_stats "A1PMS" 13 "PUT" $A1PMS_API_PREFIX$query $status
2862 # API test function: GET /services, V2 GET /v2/services and V3 /a1policymanagement/v1/services
2863 #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>]* )]
2864 # (Function for test scripts)
2865 a1pms_api_get_services() {
2867 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
2869 if [ $# -eq 1 ]; then
2871 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
2873 elif [ $# -eq 5 ]; then
2875 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
2877 if [ $(($argLen % 3)) -eq 0 ]; then
2882 if [ $paramError -ne 0 ]; then
2883 __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>]* )]" $@
2887 if [ "$A1PMS_VERSION" == "V2" ]; then
2888 query="/v2/services"
2889 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2890 query="/v2/services?service_id="$2
2892 elif [ "$A1PMS_VERSION" == "V3" ]; then
2893 query="/v1/services"
2894 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2895 query="/v1/services?serviceId="$2
2900 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2901 query="/services?name="$2
2904 res="$(__do_curl_to_api A1PMS GET $query)"
2905 status=${res:${#res}-3}
2907 if [ $status -ne $1 ]; then
2908 __log_test_fail_status_code $1 $status
2912 if [ $# -gt 2 ]; then
2913 variableArgCount=$(($# - 2))
2914 body=${res:0:${#res}-3}
2919 while [ $cntr -lt $variableArgCount ]; do
2926 if [ $cntr -gt 0 ]; then
2927 targetJson=$targetJson","
2929 # timeSinceLastActivitySeconds value cannot be checked since value varies
2930 if [ "$A1PMS_VERSION" == "V2" ]; then
2931 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
2932 elif [ "$A1PMS_VERSION" == "V3" ]; then
2933 targetJson=$targetJson"{\"serviceId\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2935 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2939 targetJson=$targetJson"]"
2940 if [ "$A1PMS_VERSION" == "V2" ]; then
2941 targetJson="{\"service_list\": $targetJson }"
2942 URL_for_Collect_End_Point="/v2/services"
2943 elif [ "$A1PMS_VERSION" == "V3" ]; then
2944 targetJson="{\"serviceList\": $targetJson }"
2945 URL_for_Collect_End_Point="/v1/services"
2947 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2948 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2949 if [ $res -ne 0 ]; then
2950 __log_test_fail_body
2955 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX$URL_for_Collect_End_Point $status
2960 # API test function: GET /services, V2 GET /v2/services and V3 /a1policymanagement/v1/services - (only checking service names)
2961 # args: <response-code> [<service-name>]*"
2962 # (Function for test scripts)
2963 a1pms_api_get_service_ids() {
2966 if [ $# -lt 1 ]; then
2967 __print_err "<response-code> [<service-name>]*" $@
2971 if [ "$A1PMS_VERSION" == "V2" ]; then
2972 query="/v2/services"
2973 elif [ "$A1PMS_VERSION" == "V3" ]; then
2974 query="/v1/services"
2978 res="$(__do_curl_to_api A1PMS GET $query)"
2979 status=${res:${#res}-3}
2981 if [ $status -ne $1 ]; then
2982 __log_test_fail_status_code $1 $status
2986 body=${res:0:${#res}-3}
2988 for rapp in ${@:2}; do
2989 if [ "$targetJson" != "[" ]; then
2990 targetJson=$targetJson","
2992 if [ "$A1PMS_VERSION" == "V2" ]; then
2993 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2994 elif [ "$A1PMS_VERSION" == "V3" ]; then
2995 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceId\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2997 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
3001 targetJson=$targetJson"]"
3002 if [ "$A1PMS_VERSION" == "V2" ]; then
3003 targetJson="{\"service_list\": $targetJson }"
3004 URL_for_Collect_End_Point="/v2/services"
3005 elif [ "$A1PMS_VERSION" == "V3" ]; then
3006 targetJson="{\"serviceList\": $targetJson }"
3007 URL_for_Collect_End_Point="/v1/services"
3009 echo "TARGET JSON: $targetJson" >>$HTTPLOG
3010 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
3012 if [ $res -ne 0 ]; then
3013 __log_test_fail_body
3017 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX$URL_for_Collect_End_Point $status
3022 # API test function: DELETE /services, V2 DELETE /v2/services/{serviceId} and V3 DELETE a1policymanagement/v1/services/{serviceId}
3023 # args: <response-code> <service-name>
3024 # (Function for test scripts)
3025 a1pms_api_delete_services() {
3028 if [ $# -ne 2 ]; then
3029 __print_err "<response-code> <service-name>" $@
3032 if [ "$A1PMS_VERSION" == "V2" ]; then
3033 url_part="/v2/services/"
3034 query=${url_part}${2}
3035 elif [ "$A1PMS_VERSION" == "V3" ]; then
3036 url_part="/v1/services/"
3037 query=${url_part}${2}
3039 query="/services?name="$2
3041 res="$(__do_curl_to_api A1PMS DELETE $query)"
3042 status=${res:${#res}-3}
3044 if [ $status -ne $1 ]; then
3045 __log_test_fail_status_code $1 $status
3049 __collect_endpoint_stats "A1PMS" 15 "DELETE" ${A1PMS_API_PREFIX}${url_part}"{serviceId}" $status
3054 # API test function: PUT /services/keepalive, V2 PUT /v2/services/{service_id}/keepalive and V3 DELETE a1policymanagement/v1/services/{serviceId}
3055 # args: <response-code> <service-name>
3056 # (Function for test scripts)
3057 a1pms_api_put_services_keepalive() {
3060 if [ $# -ne 2 ]; then
3061 __print_err "<response-code> <service-name>" $@
3064 if [ "$A1PMS_VERSION" == "V2" ]; then
3065 query="/v2/services/$2/keepalive"
3066 elif [ "$A1PMS_VERSION" == "V3" ]; then
3067 query="/v1/services/$2/keepalive"
3069 query="/services/keepalive?name="$2
3072 if [ "$A1PMS_VERSION" == "V3" ]; then
3074 res="$(__do_curl_to_api A1PMS PUT ${query} ${empty_json_body})"
3076 res="$(__do_curl_to_api A1PMS PUT ${query})"
3078 status=${res:${#res}-3}
3080 if [ $status -ne $1 ]; then
3081 __log_test_fail_status_code ${1} ${status}
3085 __collect_endpoint_stats "A1PMS" 16 "PUT" ${A1PMS_API_PREFIX}${query} ${status}
3090 ##################################################################
3091 #### API Test case functions Configuration ####
3092 ##################################################################
3094 # API Test function: PUT "/v2/configuration" or V3 PUT "a1policymanagement/v1/configuration"
3095 # args: <response-code> <config-file>
3096 # (Function for test scripts)
3097 a1pms_api_put_configuration() {
3100 if [ "$A1PMS_VERSION" != "V2" ] && [ "$A1PMS_VERSION" != "V3" ]; then
3101 __log_test_fail_not_supported
3105 if [ $# -ne 2 ]; then
3106 __print_err "<response-code> <config-file>" $@
3109 if [ ! -f $2 ]; then
3110 __log_test_fail_general "Config file "$2", does not exist"
3114 # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
3115 # inputJson="{\"config\":"$inputJson"}"
3117 file="./tmp/.config.json"
3118 echo $inputJson >$file
3119 if [ "$A1PMS_VERSION" == "V2" ]; then
3120 query="/v2/configuration"
3121 elif [ "$A1PMS_VERSION" == "V3" ]; then
3122 #V3 has baseurl changes 'a1-policy/v2' to 'a1policymanagement/v1'
3123 query="/v1/configuration"
3125 res="$(__do_curl_to_api A1PMS PUT $query $file)"
3126 status=${res:${#res}-3}
3128 if [ $status -ne $1 ]; then
3129 __log_test_fail_status_code $1 $status
3133 __collect_endpoint_stats "A1PMS" 17 "PUT" $A1PMS_API_PREFIX$query $status
3138 # API Test function: GET /v2/configuration and V3 GET a1policymanagement/v1/configuration
3139 # args: <response-code> [<config-file>]
3140 # (Function for test scripts)
3141 a1pms_api_get_configuration() {
3144 if [ "$A1PMS_VERSION" != "V2" ] && [ "$A1PMS_VERSION" != "V3" ]; then
3145 __log_test_fail_not_supported
3149 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
3150 __print_err "<response-code> [<config-file>]" $@
3153 if [ ! -f $2 ]; then
3154 __log_test_fail_general "Config file "$2" for comparison, does not exist"
3158 if [ "$A1PMS_VERSION" == "V3" ]; then
3159 #The V3 of a1-pms URL is a1policymanagement/v1 and the v2 is a1-policy/v2
3160 query="/v1/configuration"
3162 query="/v2/configuration"
3164 res="$(__do_curl_to_api A1PMS GET $query)"
3165 status=${res:${#res}-3}
3167 if [ $status -ne $1 ]; then
3168 __log_test_fail_status_code $1 $status
3172 if [ $# -eq 2 ]; then
3174 body=${res:0:${#res}-3}
3177 # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
3178 # inputJson="{\"config\":"$inputJson"}"
3180 echo "TARGET JSON: $targetJson" >>$HTTPLOG
3181 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
3183 if [ $res -ne 0 ]; then
3184 __log_test_fail_body
3189 if [ "$A1PMS_VERSION" == "V3" ]; then
3190 __collect_endpoint_stats "A1PMS" 18 "GET" $A1PMS_API_PREFIX"/v1/configuration" $status
3192 __collect_endpoint_stats "A1PMS" 18 "GET" $A1PMS_API_PREFIX"/v2/configuration" $status
3198 ##########################################
3199 #### Reset types and instances ####
3200 ##########################################
3202 # Admin reset to remove all policies and services
3203 # All types and instances etc are removed - types and instances in a1 sims need to be removed separately
3204 # NOTE - only works in kubernetes and the pod should not be running
3206 # (Function for test scripts)
3208 a1pms_kube_pvc_reset() {
3211 pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
3212 if [ -z "$pvc_name" ]; then
3213 pvc_name=policymanagementservice-vardata-pvc
3215 echo " Trying to reset pvc: "$pvc_name
3216 __kube_clean_pvc $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $A1PMS_CONTAINER_MNT_DIR
3222 # args: <realm> <client-name> <client-secret>
3223 a1pms_configure_sec() {
3224 export A1PMS_CREDS_GRANT_TYPE="client_credentials"
3225 export A1PMS_CREDS_CLIENT_SECRET=$3
3226 export A1PMS_CREDS_CLIENT_ID=$2
3227 export A1PMS_AUTH_SERVICE_URL=$KEYCLOAK_SERVICE_PATH$KEYCLOAK_TOKEN_URL_PREFIX/$1/protocol/openid-connect/token
3228 export A1PMS_SIDECAR_MOUNT="/token-cache"
3229 export A1PMS_SIDECAR_JWT_FILE=$A1PMS_SIDECAR_MOUNT"/jwt.txt"
3231 export AUTHSIDECAR_APP_NAME
3232 export AUTHSIDECAR_DISPLAY_NAME