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() {
115 #######################################################
117 ###########################
119 ###########################
121 # Set http as the protocol to use for all communication to the A1PMS
123 # (Function for test scripts)
124 use_a1pms_rest_http() {
125 __a1pms_set_protocoll "http" $A1PMS_INTERNAL_PORT $A1PMS_EXTERNAL_PORT
128 # Set https as the protocol to use for all communication to the A1PMS
130 # (Function for test scripts)
131 use_a1pms_rest_https() {
132 __a1pms_set_protocoll "https" $A1PMS_INTERNAL_SECURE_PORT $A1PMS_EXTERNAL_SECURE_PORT
135 # All calls to the a1pms will be directed to the a1pms dmaap interface over http from now on
137 # (Function for test scripts)
138 use_a1pms_dmaap_http() {
139 echo -e $BOLD"$A1PMS_DISPLAY_NAME dmaap protocol setting"$EBOLD
140 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the a1pms"
141 A1PMS_ADAPTER_TYPE="MR-HTTP"
145 # All calls to the a1pms will be directed to the a1pms dmaap interface over https from now on
147 # (Function for test scripts)
148 use_a1pms_dmaap_https() {
149 echo -e $BOLD"$A1PMS_DISPLAY_NAME dmaap protocol setting"$EBOLD
150 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the a1pms"
151 echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
152 A1PMS_ADAPTER_TYPE="MR-HTTPS"
156 # Setup paths to svc/container for internal and external access
157 # args: <protocol> <internal-port> <external-port>
158 __a1pms_set_protocoll() {
159 echo -e $BOLD"$A1PMS_DISPLAY_NAME protocol setting"$EBOLD
160 echo -e " Using $BOLD $1 $EBOLD towards $A1PMS_DISPLAY_NAME"
162 ## Access to Dmaap adapter
164 A1PMS_SERVICE_PATH=$1"://"$A1PMS_APP_NAME":"$2 # docker access, container->container and script->container via proxy
165 if [ $RUNMODE == "KUBE" ]; then
166 A1PMS_SERVICE_PATH=$1"://"$A1PMS_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
169 # A1PMS_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
170 A1PMS_ADAPTER_TYPE="REST"
171 A1PMS_ADAPTER=$A1PMS_SERVICE_PATH
176 # Make curl retries towards the a1pms for http response codes set in this env var, space separated list of codes
179 #Save first worker node the pod is started on
180 __A1PMS_WORKER_NODE=""
182 # Export env vars for config files, docker compose and kube resources
183 # args: PROXY|NOPROXY
184 __export_a1pms_vars() {
186 export A1PMS_APP_NAME
187 export A1PMS_APP_NAME_ALIAS
188 export A1PMS_DISPLAY_NAME
190 export KUBE_NONRTRIC_NAMESPACE
192 export A1PMS_INTERNAL_PORT
193 export A1PMS_INTERNAL_SECURE_PORT
194 export A1PMS_EXTERNAL_PORT
195 export A1PMS_EXTERNAL_SECURE_PORT
196 export A1PMS_CONFIG_MOUNT_PATH
197 export A1PMS_DATA_MOUNT_PATH
198 export A1PMS_CONFIG_CONFIGMAP_NAME=$A1PMS_APP_NAME"-config"
199 export A1PMS_DATA_CONFIGMAP_NAME=$A1PMS_APP_NAME"-data"
200 export A1PMS_PKG_NAME
201 export A1PMS_CONFIG_KEY
202 export DOCKER_SIM_NWNAME
203 export A1PMS_HOST_MNT_DIR
204 export A1PMS_CONFIG_FILE
206 export A1PMS_DATA_PV_NAME=$A1PMS_APP_NAME"-pv"
207 export A1PMS_DATA_PVC_NAME=$A1PMS_APP_NAME"-pvc"
208 ##Create a unique path for the pv each time to prevent a previous volume to be reused
209 export A1PMS_PV_PATH="a1pmsdata-"$(date +%s)
210 export A1PMS_CONTAINER_MNT_DIR
211 export HOST_PATH_BASE_DIR
213 if [ $1 == "PROXY" ]; then
214 export A1PMS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
215 export A1PMS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
216 if [ $A1PMS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$A1PMS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
217 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
219 echo " Configured with http proxy"
222 export A1PMS_HTTP_PROXY_CONFIG_PORT=0
223 export A1PMS_HTTP_PROXY_CONFIG_HOST_NAME=""
224 echo " Configured without http proxy"
230 # args: (docker) PROXY|NOPROXY <config-file>
231 # args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
232 # (Function for test scripts)
234 echo -e $BOLD"Starting $A1PMS_DISPLAY_NAME"$EBOLD
236 if [ $RUNMODE == "KUBE" ]; then
238 # Check if app shall be fully managed by the test script
239 __check_included_image "A1PMS"
242 # Check if app shall only be used by the test script
243 __check_prestarted_image "A1PMS"
246 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
247 echo -e $RED"The $A1PMS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
248 echo -e $RED"The $A1PMS_APP_NAME will not be started"$ERED
251 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
252 echo -e $RED"The $A1PMS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
253 echo -e $RED"The $A1PMS_APP_NAME will not be started"$ERED
257 if [ $retcode_p -eq 0 ]; then
258 echo -e " Using existing $A1PMS_APP_NAME deployment and service"
259 echo " Setting $A1PMS_APP_NAME replicas=1"
260 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
261 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
264 if [ $retcode_i -eq 0 ]; then
266 echo -e " Creating $A1PMS_APP_NAME app and expose service"
268 #Check if nonrtric namespace exists, if not create it
269 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
271 __export_a1pms_vars $1
273 # Create config map for config
274 configfile=$PWD/tmp/$A1PMS_CONFIG_FILE
276 output_yaml=$PWD/tmp/a1pms-cfc.yaml
277 __kube_create_configmap $A1PMS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $configfile $output_yaml
279 # Create config map for data
280 data_json=$PWD/tmp/$A1PMS_DATA_FILE
281 if [ $# -lt 3 ]; then
282 #create empty dummy file
283 echo "{}" > $data_json
287 output_yaml=$PWD/tmp/a1pms-cfd.yaml
288 __kube_create_configmap $A1PMS_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $data_json $output_yaml
291 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"pv.yaml
292 output_yaml=$PWD/tmp/a1pms-pv.yaml
293 __kube_create_instance pv $A1PMS_APP_NAME $input_yaml $output_yaml
296 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"pvc.yaml
297 output_yaml=$PWD/tmp/a1pms-pvc.yaml
298 __kube_create_instance pvc $A1PMS_APP_NAME $input_yaml $output_yaml
301 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"svc.yaml
302 output_yaml=$PWD/tmp/a1pmssvc.yaml
303 __kube_create_instance service $A1PMS_APP_NAME $input_yaml $output_yaml
306 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"app.yaml
307 output_yaml=$PWD/tmp/a1pmsapp.yaml
308 if [ -z "$A1PMS_SIDECAR_JWT_FILE" ]; then
309 cat $input_yaml | sed '/#A1PMS_JWT_START/,/#A1PMS_JWT_STOP/d' > $PWD/tmp/a1pmsapp_tmp.yaml
310 input_yaml=$PWD/tmp/a1pmsapp_tmp.yaml
312 __kube_create_instance app $A1PMS_APP_NAME $input_yaml $output_yaml
316 # 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
317 if [ $retcode_i -eq 0 ]; then
318 __A1PMS_WORKER_NODE=$(kubectl $KUBECONF get pod -l "autotest=A1PMS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
319 if [ -z "$__A1PMS_WORKER_NODE" ]; then
320 echo -e $YELLOW" Cannot find worker node for pod for $A1PMS_APP_NAME, persistency may not work"$EYELLOW
323 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
326 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
329 __check_included_image 'A1PMS'
330 if [ $? -eq 1 ]; then
331 echo -e $RED"The A1PMS app is not included in this test script"$ERED
332 echo -e $RED"The A1PMS will not be started"$ERED
339 cd $A1PMS_HOST_MNT_DIR
342 if [ "$(ls -A $DIR)" ]; then
343 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
344 rm -rf db/* &> /dev/null
345 if [ $? -ne 0 ]; then
346 echo -e $RED" Cannot remove database files in: $PWD"$ERED
351 echo " No files in mounted dir or dir does not exists"
356 __export_a1pms_vars $1
358 dest_file=$SIM_GROUP/$A1PMS_COMPOSE_DIR/$A1PMS_HOST_MNT_DIR/application.yaml
360 envsubst < $2 > $dest_file
362 __start_container $A1PMS_COMPOSE_DIR "" NODOCKERARGS 1 $A1PMS_APP_NAME
364 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
367 __collect_endpoint_stats_image_info "A1PMS" $A1PMS_IMAGE
375 # (Function for test scripts)
377 echo -e $BOLD"Stopping $A1PMS_DISPLAY_NAME"$EBOLD
379 if [ $RUNMODE == "KUBE" ]; then
381 __check_prestarted_image "A1PMS"
382 if [ $? -eq 0 ]; then
383 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
384 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
385 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
388 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS
389 echo " Deleting the replica set - a new will be started when the app is started"
390 tmp=$(kubectl $KUBECONF delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
391 if [ $? -ne 0 ]; then
392 echo -e $RED" Could not delete replica set "$RED
397 docker stop $A1PMS_APP_NAME &> ./tmp/.dockererr
398 if [ $? -ne 0 ]; then
399 __print_err "Could not stop $A1PMS_APP_NAME" $@
405 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
410 # Start a previously stopped a1pms
412 # (Function for test scripts)
413 start_stopped_a1pms() {
414 echo -e $BOLD"Starting (the previously stopped) $A1PMS_DISPLAY_NAME"$EBOLD
416 if [ $RUNMODE == "KUBE" ]; then
418 __check_prestarted_image "A1PMS"
419 if [ $? -eq 0 ]; then
420 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
421 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
422 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
423 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
427 # Tie the A1PMS to the same worker node it was initially started on
428 # 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
429 if [ -z "$__A1PMS_WORKER_NODE" ]; then
430 echo -e $RED" No initial worker node found for pod "$RED
434 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
435 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
436 tmp=$(kubectl $KUBECONF patch deployment $A1PMS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__A1PMS_WORKER_NODE'"}}}}}')
437 if [ $? -ne 0 ]; then
438 echo -e $YELLOW" Cannot set nodeSelector to deployment for $A1PMS_APP_NAME, persistency may not work"$EYELLOW
440 __kube_scale deployment $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
443 docker start $A1PMS_APP_NAME &> ./tmp/.dockererr
444 if [ $? -ne 0 ]; then
445 __print_err "Could not start (the stopped) $A1PMS_APP_NAME" $@
451 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
452 if [ $? -ne 0 ]; then
460 # Function to prepare the a1pms configuration according to the current simulator configuration
461 # args: SDNC|NOSDNC <output-file> [ <sim-group> <adapter-class> ]
462 # (Function for test scripts)
463 prepare_a1pms_config() {
464 echo -e $BOLD"Prepare A1PMS config"$EBOLD
466 echo " Writing a1pms config for "$A1PMS_APP_NAME" to file: "$2
468 if [ $# != 2 ] && [ $# != 4 ]; then
470 __print_err "need two or four args, SDNC|NOSDNC <output-file> [ <sim-group> <adapter-class> ]" $@
474 if [ $1 == "SDNC" ]; then
475 echo -e " Config$BOLD including SDNC$EBOLD configuration"
476 elif [ $1 == "NOSDNC" ]; then
477 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
480 __print_err "need three args, SDNC|NOSDNC <output-file> HEADER|NOHEADER" $@
485 if [ $1 == "SDNC" ]; then
486 config_json=$config_json"\n \"controller\": ["
487 config_json=$config_json"\n {"
488 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
489 config_json=$config_json"\n \"baseUrl\": \"$SDNC_SERVICE_PATH\","
490 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
491 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
492 config_json=$config_json"\n }"
493 config_json=$config_json"\n ],"
495 if [[ "$A1PMS_FEATURE_LEVEL" == *"NO-DMAAP"* ]]; then
498 config_json=$config_json"\n \"streams_publishes\": {"
499 config_json=$config_json"\n \"dmaap_publisher\": {"
500 config_json=$config_json"\n \"type\": \"message-router\","
501 config_json=$config_json"\n \"dmaap_info\": {"
502 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_WRITE_URL\""
503 config_json=$config_json"\n }"
504 config_json=$config_json"\n }"
505 config_json=$config_json"\n },"
506 config_json=$config_json"\n \"streams_subscribes\": {"
507 config_json=$config_json"\n \"dmaap_subscriber\": {"
508 config_json=$config_json"\n \"type\": \"message-router\","
509 config_json=$config_json"\n \"dmaap_info\": {"
510 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_READ_URL\""
511 config_json=$config_json"\n }"
512 config_json=$config_json"\n }"
513 config_json=$config_json"\n },"
516 config_json=$config_json"\n \"ric\": ["
518 if [ $RUNMODE == "KUBE" ]; then
519 result=$(kubectl $KUBECONF get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICSIM")].metadata.name}')
522 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
523 for im in $result; do
524 if [[ $im != *"-0" ]]; then
525 ric_subdomain=$(kubectl $KUBECONF get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
526 rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
527 let ric_cntr=ric_cntr+1
531 result=$(kubectl $KUBECONF get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICMEDIATORSIM")].metadata.name}')
533 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
534 for im in $result; do
535 if [[ $im != *"-0" ]]; then
536 ric_subdomain=$(kubectl $KUBECONF get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
537 rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
538 oranrics=$oranrics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
539 let ric_cntr=ric_cntr+1
543 if [ $ric_cntr -eq 0 ]; then
544 echo $YELLOW"Warning: No rics found for the configuration"$EYELLOW
547 rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "label=a1sim" --filter "status=running" --format {{.Names}})
548 oranrics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "label=orana1sim" --filter "status=running" --format {{.Names}})
550 rics="$rics $oranrics"
552 if [ $? -ne 0 ] || [ -z "$rics" ]; then
553 echo -e $RED" FAIL - the names of the running RIC Simulator or ORAN RIC cannot be retrieved." $ERED
560 if [ $cntr -gt 0 ]; then
561 config_json=$config_json"\n ,"
563 config_json=$config_json"\n {"
564 if [ $RUNMODE == "KUBE" ]; then
565 ric_id=${ric%.*.*} #extract pod id from full hosthame
566 ric_id=$(echo "$ric_id" | tr '-' '_')
568 ric_id=$(echo "$ric" | tr '-' '_') #ric var still needs underscore as it is different from the container name
570 echo " Found a1 sim: "$ric
571 config_json=$config_json"\n \"name\": \"$ric_id\","
574 for xric in $oranrics; do
575 if [ $xric == $ric ]; then
579 if [ $xricfound -eq 0 ]; then
580 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
582 config_json=$config_json"\n \"baseUrl\": \"$RICMEDIATOR_SIM_HTTPX://$ric:$RICMEDIATOR_SIM_PORT\","
584 if [ ! -z "$3" ]; then
585 if [[ $ric == "$3"* ]]; then
586 config_json=$config_json"\n \"customAdapterClass\": \"$4\","
589 if [ $1 == "SDNC" ]; then
590 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
592 config_json=$config_json"\n \"managedElementIds\": ["
593 config_json=$config_json"\n \"me1_$ric_id\","
594 config_json=$config_json"\n \"me2_$ric_id\""
595 config_json=$config_json"\n ]"
596 config_json=$config_json"\n }"
600 config_json=$config_json"\n ]"
601 config_json=$config_json"\n}"
603 config_json="{\"config\":"$config_json"}"
605 printf "$config_json">$2
610 # Load the the appl config for the a1pms into a config map
611 a1pms_load_config() {
612 echo -e $BOLD"A1PMS - load config from "$EBOLD$1
613 data_json=$PWD/tmp/$A1PMS_DATA_FILE
615 output_yaml=$PWD/tmp/a1pms-cfd.yaml
616 __kube_create_configmap $A1PMS_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $data_json $output_yaml
621 # Turn on debug level tracing in the a1pms
623 # (Function for test scripts)
625 echo -e $BOLD"Setting a1pms debug logging"$EBOLD
626 curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
627 result=$(__do_curl "$curlString")
628 if [ $? -ne 0 ]; then
629 __print_err "could not set debug mode" $@
637 # Turn on trace level tracing in the a1pms
639 # (Function for test scripts)
641 echo -e $BOLD"Setting a1pms trace logging"$EBOLD
642 curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
643 result=$(__do_curl "$curlString")
644 if [ $? -ne 0 ]; then
645 __print_err "could not set trace mode" $@
653 # Perform curl retries when making direct call to the a1pms for the specified http response codes
654 # Speace separated list of http response codes
655 # args: [<response-code>]*
656 use_a1pms_retries() {
657 echo -e $BOLD"Do curl retries to the a1pms REST inteface for these response codes:$@"$EBOLD
663 # Check the a1pms logs for WARNINGs and ERRORs
665 # (Function for test scripts)
667 __check_container_logs "A1PMS" $A1PMS_APP_NAME $A1PMS_LOGPATH WARN ERR
670 #########################################################
671 #### Test case functions A1 Policy management service
672 #########################################################
674 # This function compare the size, towards a target value, of a json array returned from <url> of the A1PMS.
675 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
676 # args: json:<url> <target-value> [<timeout-in-seconds]
677 # (Function for test scripts)
679 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
680 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
681 if [[ $1 == "json:"* ]]; then
682 if [ "$A1PMS_VERSION" == "V2" ]; then
683 __var_test "A1PMS" $A1PMS_SERVICE_PATH$A1PMS_API_PREFIX"/v2/" $1 "=" $2 $3
685 __var_test "A1PMS" $A1PMS_SERVICE_PATH"/" $1 "=" $2 $3
690 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
694 # API Test function: GET /policies and V2 GET /v2/policy-instances
695 # 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>]*]
696 # 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>]*]
697 # (Function for test scripts)
698 a1pms_api_get_policies() {
701 if [ "$A1PMS_VERSION" == "V2" ]; then
703 variableParams=$(($#-4))
704 if [ $# -lt 4 ]; then
706 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
708 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
712 if [ $paramError -ne 0 ]; then
713 __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>]*]" $@
718 variableParams=$(($#-4))
719 if [ $# -lt 4 ]; then
721 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
723 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
727 if [ $paramError -ne 0 ]; then
728 __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>]*]" $@
734 if [ "$A1PMS_VERSION" == "V2" ]; then
735 if [ $2 != "NORIC" ]; then
736 queryparams="?ric_id="$2
738 if [ $3 != "NOSERVICE" ]; then
739 if [ -z $queryparams ]; then
740 queryparams="?service_id="$3
742 queryparams=$queryparams"&service_id="$3
745 if [ $4 != "NOTYPE" ]; then
746 if [ -z $queryparams ]; then
747 queryparams="?policytype_id="$4
749 queryparams=$queryparams"&policytype_id="$4
753 query="/v2/policy-instances"$queryparams
754 res="$(__do_curl_to_api A1PMS GET $query)"
755 status=${res:${#res}-3}
757 if [ $status -ne $1 ]; then
758 __log_test_fail_status_code $1 $status
762 if [ $# -gt 4 ]; then
763 body=${res:0:${#res}-3}
764 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
770 for ((i=0; i<$(($#-4)); i=i+7)); do
772 if [ "$targetJson" != "[" ]; then
773 targetJson=$targetJson","
775 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
776 if [ "${arr[$i+3]}" == "EMPTY" ]; then
777 targetJson=$targetJson"\"\","
779 targetJson=$targetJson"\"${arr[$i+3]}\","
781 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
783 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
785 targetJson=$targetJson"\"policy_data\":"$json"}"
789 targetJson=$targetJson"]"
790 targetJson="{\"policies\": $targetJson}"
791 echo "TARGET JSON: $targetJson" >> $HTTPLOG
792 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
794 if [ $res -ne 0 ]; then
800 if [ $2 != "NORIC" ]; then
801 queryparams="?ric="$2
803 if [ $3 != "NOSERVICE" ]; then
804 if [ -z $queryparams ]; then
805 queryparams="?service="$3
807 queryparams=$queryparams"&service="$3
810 if [ $4 != "NOTYPE" ]; then
811 if [ -z $queryparams ]; then
812 queryparams="?type="$4
814 queryparams=$queryparams"&type="$4
818 query="/policies"$queryparams
819 res="$(__do_curl_to_api A1PMS GET $query)"
820 status=${res:${#res}-3}
822 if [ $status -ne $1 ]; then
823 __log_test_fail_status_code $1 $status
827 if [ $# -gt 4 ]; then
828 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
831 body=${res:0:${#res}-3}
835 for ((i=0; i<$(($#-4)); i=i+5)); do
837 if [ "$targetJson" != "[" ]; then
838 targetJson=$targetJson","
840 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
841 if [ "${arr[$i+3]}" == "EMPTY" ]; then
842 targetJson=$targetJson"\"\","
844 targetJson=$targetJson"\"${arr[$i+3]}\","
847 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
849 targetJson=$targetJson"\"json\":"$json"}"
853 targetJson=$targetJson"]"
854 echo "TARGET JSON: $targetJson" >> $HTTPLOG
855 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
857 if [ $res -ne 0 ]; then
863 __collect_endpoint_stats "A1PMS" 00 "GET" $A1PMS_API_PREFIX"/v2/policy-instances" $status
870 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
871 # args: <response-code> <policy-id> [<template-file>]
872 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
874 # (Function for test scripts)
875 a1pms_api_get_policy() {
879 if [ "$A1PMS_VERSION" == "V2" ]; then
880 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
881 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
884 query="/v2/policies/$UUID$2"
886 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
887 __print_err "<response-code> <policy-id> [<template-file>] " $@
890 query="/policy?id=$UUID$2"
892 res="$(__do_curl_to_api A1PMS GET $query)"
893 status=${res:${#res}-3}
895 if [ $status -ne $1 ]; then
896 __log_test_fail_status_code $1 $status
900 if [ "$A1PMS_VERSION" == "V2" ]; then
901 if [ $# -eq 8 ]; then
903 #Create a policy json to compare with
904 body=${res:0:${#res}-3}
906 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
907 if [ $7 != "NOTRANSIENT" ]; then
908 targetJson=$targetJson", \"transient\":$7"
910 if [ $6 != "NOTYPE" ]; then
911 targetJson=$targetJson", \"policytype_id\":\"$6\""
913 targetJson=$targetJson", \"policytype_id\":\"\""
915 if [ $8 != "NOURL" ]; then
916 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
919 data=$(sed 's/XXX/'${2}'/g' $3)
920 targetJson=$targetJson", \"policy_data\":$data"
921 targetJson="{$targetJson}"
923 echo "TARGET JSON: $targetJson" >> $HTTPLOG
924 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
925 if [ $res -ne 0 ]; then
931 if [ $# -eq 3 ]; then
932 #Create a policy json to compare with
933 body=${res:0:${#res}-3}
935 sed 's/XXX/'${2}'/g' $3 > $file
936 targetJson=$(< $file)
937 echo "TARGET JSON: $targetJson" >> $HTTPLOG
938 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
939 if [ $res -ne 0 ]; then
945 __collect_endpoint_stats "A1PMS" 01 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $status
950 # API Test function: PUT /policy and V2 PUT /policies
951 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
952 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
953 # (Function for test scripts)
954 a1pms_api_put_policy() {
957 if [ "$A1PMS_VERSION" == "V2" ]; then
958 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
959 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
963 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
964 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
977 if [ "$A1PMS_VERSION" == "V2" ]; then
980 if [ $# -eq 9 ]; then
985 if [ $# -eq 8 ]; then
990 while [ $count -lt $max ]; do
991 if [ "$A1PMS_VERSION" == "V2" ]; then
995 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
996 if [ $trans != "NOTRANSIENT" ]; then
997 inputJson=$inputJson", \"transient\":$trans"
999 if [ $pt != "NOTYPE" ]; then
1000 inputJson=$inputJson", \"policytype_id\":\"$pt\""
1002 inputJson=$inputJson", \"policytype_id\":\"\""
1004 if [ $noti != "NOURL" ]; then
1005 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1007 file="./tmp/.p.json"
1008 data=$(sed 's/XXX/'${pid}'/g' $temp)
1009 inputJson=$inputJson", \"policy_data\":$data"
1010 inputJson="{$inputJson}"
1011 echo $inputJson > $file
1013 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
1015 if [ $pt != "NOTYPE" ]; then
1016 query=$query"&type=$pt"
1019 if [ $trans != NOTRANSIENT ]; then
1020 query=$query"&transient=$trans"
1023 file="./tmp/.p.json"
1024 sed 's/XXX/'${pid}'/g' $temp > $file
1026 res="$(__do_curl_to_api A1PMS PUT $query $file)"
1027 status=${res:${#res}-3}
1028 echo -ne " Executing "$count"("$max")${SAMELINE}"
1029 if [ $status -ne $1 ]; then
1030 echo " Executed "$count"?("$max")"
1031 __log_test_fail_status_code $1 $status
1036 echo -ne " Executed "$count"("$max")${SAMELINE}"
1038 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $status $max
1045 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
1046 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
1047 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
1048 # (Function for test scripts)
1050 a1pms_api_put_policy_batch() {
1053 if [ "$A1PMS_VERSION" == "V2" ]; then
1054 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1055 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
1059 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1060 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
1072 if [ "$A1PMS_VERSION" == "V2" ]; then
1075 if [ $# -eq 9 ]; then
1080 if [ $# -eq 8 ]; then
1086 while [ $count -lt $max ]; do
1087 if [ "$A1PMS_VERSION" == "V2" ]; then
1088 query="/v2/policies"
1090 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1091 if [ $trans != "NOTRANSIENT" ]; then
1092 inputJson=$inputJson", \"transient\":$trans"
1094 if [ $pt != "NOTYPE" ]; then
1095 inputJson=$inputJson", \"policytype_id\":\"$pt\""
1097 inputJson=$inputJson", \"policytype_id\":\"\""
1099 if [ $noti != "NOURL" ]; then
1100 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1102 file="./tmp/.p.json"
1103 data=$(sed 's/XXX/'${pid}'/g' $temp)
1104 inputJson=$inputJson", \"policy_data\":$data"
1105 inputJson="{$inputJson}"
1106 echo $inputJson > $file
1108 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
1110 if [ $pt != "NOTYPE" ]; then
1111 query=$query"&type=$pt"
1114 if [ $trans != NOTRANSIENT ]; then
1115 query=$query"&transient=$trans"
1117 file="./tmp/.p.json"
1118 sed 's/XXX/'${pid}'/g' $temp > $file
1120 res="$(__do_curl_to_api A1PMS PUT_BATCH $query $file)"
1121 status=${res:${#res}-3}
1122 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1124 if [ $status -ne 200 ]; then
1125 echo " Requested(batch) "$count"?("$max")"
1126 __log_test_fail_status_code 200 $status
1129 cid=${res:0:${#res}-3}
1133 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1140 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1141 status=${res:${#res}-3}
1142 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
1144 if [ $status -ne $1 ]; then
1145 echo " Accepted(batch) "$count"?("$max")"
1146 __log_test_fail_status_code $1 $status
1151 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
1153 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $1 $max
1161 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
1162 # 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>
1163 # 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>
1164 # (Function for test scripts)
1165 a1pms_api_put_policy_parallel() {
1168 if [ "$A1PMS_VERSION" == "V2" ]; then
1169 if [ $# -ne 11 ]; then
1170 __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>" $@
1174 if [ $# -ne 10 ]; then
1175 __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>" $@
1179 resp_code=$1; shift;
1185 transient=$1; shift;
1186 if [ "$A1PMS_VERSION" == "V2" ]; then
1195 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1196 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1197 echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1198 echo " Info - will execute over a1pms REST"
1200 if [ "$A1PMS_VERSION" == "V2" ]; then
1201 if [ $serv == "NOSERVICE" ]; then
1204 query="$A1PMS_API_PREFIX/v2/policies"
1206 if [ $serv == "NOSERVICE" ]; then
1209 query="/policy?service=$serv"
1211 if [ $type != "NOTYPE" ]; then
1212 query=$query"&type=$type"
1215 if [ $transient != NOTRANSIENT ]; then
1216 query=$query"&transient=$transient"
1220 urlbase=${A1PMS_ADAPTER}${query}
1223 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1224 httpproxy=$KUBE_PROXY_PATH
1227 for ((i=1; i<=$pids; i++))
1230 if [ -z "$uuid" ]; then
1233 echo "" > "./tmp/.pid${i}.res.txt"
1234 if [ "$A1PMS_VERSION" == "V2" ]; then
1235 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1237 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1240 done | xargs -n 1 -I{} -P $pids bash -c '{
1242 echo " Parallel process $arg started"
1243 tmp=$(< "./tmp/.pid${arg}.txt")
1244 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1247 for ((i=1; i<=$pids; i++))
1249 file="./tmp/.pid${i}.res.txt"
1251 if [ -z "$tmp" ]; then
1252 echo " Process $i : unknown result (result file empty"
1256 if [ $res == "0" ]; then
1257 echo " Process $i : OK - "${tmp:1}
1259 echo " Process $i : failed - "${tmp:1}
1264 if [ -z $msg ]; then
1265 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $resp_code $(($count*$num_rics))
1266 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1270 __log_test_fail_general "One of more processes failed to execute"
1274 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
1275 # args: <response-code> <policy-id> [count]
1276 # (Function for test scripts)
1277 a1pms_api_delete_policy() {
1280 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1281 __print_err "<response-code> <policy-id> [count]" $@
1288 if [ $# -eq 3 ]; then
1294 while [ $count -lt $max ]; do
1295 if [ "$A1PMS_VERSION" == "V2" ]; then
1296 query="/v2/policies/"$UUID$pid
1298 query="/policy?id="$UUID$pid
1300 res="$(__do_curl_to_api A1PMS DELETE $query)"
1301 status=${res:${#res}-3}
1302 echo -ne " Executing "$count"("$max")${SAMELINE}"
1304 if [ $status -ne $1 ]; then
1305 echo " Executed "$count"?("$max")"
1306 __log_test_fail_status_code $1 $status
1312 echo -ne " Executed "$count"("$max")${SAMELINE}"
1314 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $status $max
1321 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
1322 # args: <response-code> <policy-id> [count]
1323 # (Function for test scripts)
1324 a1pms_api_delete_policy_batch() {
1327 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1328 __print_err "<response-code> <policy-id> [count]" $@
1335 if [ $# -eq 3 ]; then
1341 while [ $count -lt $max ]; do
1342 if [ "$A1PMS_VERSION" == "V2" ]; then
1343 query="/v2/policies/"$UUID$pid
1345 query="/policy?id="$UUID$pid
1347 res="$(__do_curl_to_api A1PMS DELETE_BATCH $query)"
1348 status=${res:${#res}-3}
1349 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1351 if [ $status -ne 200 ]; then
1352 echo " Requested(batch) "$count"?("$max")"
1353 __log_test_fail_status_code 200 $status
1356 cid=${res:0:${#res}-3}
1360 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1368 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1369 status=${res:${#res}-3}
1370 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1372 if [ $status -ne $1 ]; then
1373 echo " Deleted(batch) "$count"?("$max")"
1374 __log_test_fail_status_code $1 $status
1379 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1381 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $1 $max
1389 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1390 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1391 # (Function for test scripts)
1392 a1pms_api_delete_policy_parallel() {
1395 if [ $# -ne 5 ]; then
1396 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1399 resp_code=$1; shift;
1405 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1406 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1407 echo " Info - a1pms_api_delete_policy_parallel uses only the a1pms REST interface - delete over dmaap in parallel is not supported"
1408 echo " Info - will execute over a1pms REST"
1411 if [ "$A1PMS_VERSION" == "V2" ]; then
1412 query="$A1PMS_API_PREFIX/v2/policies/"
1417 urlbase=${A1PMS_ADAPTER}${query}
1420 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1421 httpproxy=$KUBE_PROXY_PATH
1424 for ((i=1; i<=$pids; i++))
1427 if [ -z "$uuid" ]; then
1430 echo "" > "./tmp/.pid${i}.del.res.txt"
1431 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
1433 done | xargs -n 1 -I{} -P $pids bash -c '{
1435 echo " Parallel process $arg started"
1436 tmp=$(< "./tmp/.pid${arg}.del.txt")
1437 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1440 for ((i=1; i<=$pids; i++))
1442 file="./tmp/.pid${i}.del.res.txt"
1444 if [ -z "$tmp" ]; then
1445 echo " Process $i : unknown result (result file empty"
1449 if [ $res == "0" ]; then
1450 echo " Process $i : OK - "${tmp:1}
1452 echo " Process $i : failed - "${tmp:1}
1457 if [ -z $msg ]; then
1458 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count*$num_rics))
1459 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1463 __log_test_fail_general "One of more processes failed to execute"
1467 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}, to run in i parallel for a number of rics
1468 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1469 # (Function for test scripts)
1470 a1pms_api_get_policy_parallel() {
1473 if [ $# -ne 5 ]; then
1474 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1477 resp_code=$1; shift;
1483 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1484 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1485 echo " Info - a1pms_api_get_policy_parallel uses only the a1pms REST interface - GET over dmaap in parallel is not supported"
1486 echo " Info - will execute over a1pms REST"
1489 if [ "$A1PMS_VERSION" == "V2" ]; then
1490 query="$A1PMS_API_PREFIX/v2/policies/"
1495 urlbase=${A1PMS_ADAPTER}${query}
1498 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1499 httpproxy=$KUBE_PROXY_PATH
1502 for ((i=1; i<=$pids; i++))
1505 if [ -z "$uuid" ]; then
1508 echo "" > "./tmp/.pid${i}.get.res.txt"
1509 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.get.txt"
1511 done | xargs -n 1 -I{} -P $pids bash -c '{
1513 echo " Parallel process $arg started"
1514 tmp=$(< "./tmp/.pid${arg}.get.txt")
1515 python3 ../common/get_policies_process.py $tmp > ./tmp/.pid${arg}.get.res.txt
1518 for ((i=1; i<=$pids; i++))
1520 file="./tmp/.pid${i}.get.res.txt"
1522 if [ -z "$tmp" ]; then
1523 echo " Process $i : unknown result (result file empty"
1527 if [ $res == "0" ]; then
1528 echo " Process $i : OK - "${tmp:1}
1530 echo " Process $i : failed - "${tmp:1}
1535 if [ -z $msg ]; then
1536 __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count*$num_rics))
1537 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1541 __log_test_fail_general "One of more processes failed to execute"
1545 # API Test function: GET /policy_ids and V2 GET /v2/policies
1546 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1547 # (Function for test scripts)
1548 a1pms_api_get_policy_ids() {
1551 if [ $# -lt 4 ]; then
1552 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1558 if [ "$A1PMS_VERSION" == "V2" ]; then
1559 if [ $2 != "NORIC" ]; then
1560 queryparams="?ric_id="$2
1563 if [ $3 != "NOSERVICE" ]; then
1564 if [ -z $queryparams ]; then
1565 queryparams="?service_id="$3
1567 queryparams=$queryparams"&service_id="$3
1570 if [ $4 != "NOTYPE" ]; then
1571 if [ -z $queryparams ]; then
1572 queryparams="?policytype_id="$4
1574 queryparams=$queryparams"&policytype_id="$4
1578 query="/v2/policies"$queryparams
1580 if [ $2 != "NORIC" ]; then
1581 queryparams="?ric="$2
1584 if [ $3 != "NOSERVICE" ]; then
1585 if [ -z $queryparams ]; then
1586 queryparams="?service="$3
1588 queryparams=$queryparams"&service="$3
1591 if [ $4 != "NOTYPE" ]; then
1592 if [ -z $queryparams ]; then
1593 queryparams="?type="$4
1595 queryparams=$queryparams"&type="$4
1599 query="/policy_ids"$queryparams
1602 res="$(__do_curl_to_api A1PMS GET $query)"
1603 status=${res:${#res}-3}
1605 if [ $status -ne $1 ]; then
1606 __log_test_fail_status_code $1 $status
1610 if [ $# -gt 4 ]; then
1611 body=${res:0:${#res}-3}
1614 for pid in ${@:5} ; do
1615 if [ "$targetJson" != "[" ]; then
1616 targetJson=$targetJson","
1618 if [ $pid != "NOID" ]; then
1619 targetJson=$targetJson"\"$UUID$pid\""
1623 targetJson=$targetJson"]"
1624 if [ "$A1PMS_VERSION" == "V2" ]; then
1625 targetJson="{\"policy_ids\": $targetJson}"
1627 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1628 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1630 if [ $res -ne 0 ]; then
1631 __log_test_fail_body
1636 __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v2/policies" $status
1641 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
1642 # args(V2): <response-code> <policy-type-id> [<schema-file>]
1643 # (Function for test scripts)
1644 a1pms_api_get_policy_type() {
1647 if [ "$A1PMS_VERSION" != "V2" ]; then
1648 __log_test_fail_not_supported
1652 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1653 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1656 query="/v2/policy-types/$2"
1658 res="$(__do_curl_to_api A1PMS GET $query)"
1659 status=${res:${#res}-3}
1661 if [ $status -ne $1 ]; then
1662 __log_test_fail_status_code $1 $status
1666 if [ $# -eq 3 ]; then
1668 body=${res:0:${#res}-3}
1671 targetJson="{\"policy_schema\":$targetJson}"
1672 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1673 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1675 if [ $res -ne 0 ]; then
1676 __log_test_fail_body
1681 __collect_endpoint_stats "A1PMS" 05 "GET" $A1PMS_API_PREFIX"/v2/policy-types/{policyTypeId}" $status
1686 # API Test function: GET /policy_schema
1687 # args: <response-code> <policy-type-id> [<schema-file>]
1688 # (Function for test scripts)
1689 a1pms_api_get_policy_schema() {
1692 if [ "$A1PMS_VERSION" == "V2" ]; then
1693 __log_test_fail_not_supported
1697 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1698 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1701 query="/policy_schema?id=$2"
1702 res="$(__do_curl_to_api A1PMS GET $query)"
1703 status=${res:${#res}-3}
1705 if [ $status -ne $1 ]; then
1706 __log_test_fail_status_code $1 $status
1710 if [ $# -eq 3 ]; then
1712 body=${res:0:${#res}-3}
1716 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1717 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1719 if [ $res -ne 0 ]; then
1720 __log_test_fail_body
1725 __collect_endpoint_stats "A1PMS" 06 "GET" $A1PMS_API_PREFIX"/v2/policy_schema" $status
1730 # API Test function: GET /policy_schemas
1731 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
1732 # args(V2): <response-code>
1733 # (Function for test scripts)
1734 a1pms_api_get_policy_schemas() {
1737 if [ "$A1PMS_VERSION" == "V2" ]; then
1738 if [ $# -ne 1 ]; then
1739 __print_err "<response-code>" $@
1743 if [ $# -lt 2 ]; then
1744 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1748 if [ "$A1PMS_VERSION" == "V2" ]; then
1749 query="/v2/policy-schemas"
1751 query="/policy_schemas"
1752 if [ $2 != "NORIC" ]; then
1753 query=$query"?ric="$2
1757 res="$(__do_curl_to_api A1PMS GET $query)"
1758 status=${res:${#res}-3}
1760 if [ $status -ne $1 ]; then
1761 __log_test_fail_status_code $1 $status
1765 if [ $# -gt 2 ]; then
1766 body=${res:0:${#res}-3}
1769 for file in ${@:3} ; do
1770 if [ "$targetJson" != "[" ]; then
1771 targetJson=$targetJson","
1773 if [ $file == "NOFILE" ]; then
1774 targetJson=$targetJson"{}"
1776 targetJson=$targetJson$(< $file)
1780 targetJson=$targetJson"]"
1781 if [ "$A1PMS_VERSION" == "V2" ]; then
1782 targetJson="{\"policy_schemas\": $targetJson }"
1784 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1785 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1787 if [ $res -ne 0 ]; then
1788 __log_test_fail_body
1793 __collect_endpoint_stats "A1PMS" 07 "GET" $A1PMS_API_PREFIX"/v2/policy-schemas" $status
1798 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1799 # arg: <response-code> <policy-id> [ (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>) ]
1800 # (Function for test scripts)
1801 a1pms_api_get_policy_status() {
1804 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
1805 __print_err "<response-code> <policy-id> [(STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)]" $@
1810 if [ $# -eq 2 ]; then
1812 elif [ "$3" == "STD" ]; then
1813 targetJson="{\"enforceStatus\":\"$4\""
1814 if [ $# -eq 5 ]; then
1815 targetJson=$targetJson",\"reason\":\"$5\""
1817 targetJson=$targetJson"}"
1818 elif [ "$3" == "STD2" ]; then
1819 if [ $4 == "EMPTY" ]; then
1820 targetJson="{\"enforceStatus\":\"\""
1822 targetJson="{\"enforceStatus\":\"$4\""
1824 if [ $# -eq 5 ]; then
1825 if [ $5 == "EMPTY" ]; then
1826 targetJson=$targetJson",\"enforceReason\":\"\""
1828 targetJson=$targetJson",\"enforceReason\":\"$5\""
1831 targetJson=$targetJson"}"
1832 elif [ "$3" == "OSC" ]; then
1833 if [[ $TEST_ENV_PROFILE =~ ^ORAN-[A-H] ]] || [[ $TEST_ENV_PROFILE =~ ^ONAP-[A-L] ]]; then
1834 targetJson="{\"instance_status\":\"$4\""
1835 if [ $# -eq 5 ]; then
1836 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1838 targetJson=$targetJson",\"created_at\":\"????\"}"
1840 targetJson="{\"enforceStatus\":\"$4\""
1841 if [ $# -eq 5 ]; then
1842 targetJson=$targetJson",\"enforceReason\":\"$5\"}"
1846 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1850 if [ "$A1PMS_VERSION" == "V2" ]; then
1851 query="/v2/policies/$UUID$2/status"
1852 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1854 query="/policy_status?id="$UUID$2
1857 res="$(__do_curl_to_api A1PMS GET $query)"
1858 status=${res:${#res}-3}
1860 if [ $status -ne $1 ]; then
1861 __log_test_fail_status_code $1 $status
1864 if [ $# -gt 2 ]; then
1865 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1866 body=${res:0:${#res}-3}
1867 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1869 if [ $res -ne 0 ]; then
1870 __log_test_fail_body
1874 __collect_endpoint_stats "A1PMS" 08 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}/status" $status
1879 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1880 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1881 # (Function for test scripts)
1882 a1pms_api_get_policy_types() {
1885 if [ $# -lt 1 ]; then
1886 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1890 if [ "$A1PMS_VERSION" == "V2" ]; then
1891 if [ $# -eq 1 ]; then
1892 query="/v2/policy-types"
1893 elif [ $2 == "NORIC" ]; then
1894 query="/v2/policy-types"
1896 query="/v2/policy-types?ric_id=$2"
1899 if [ $# -eq 1 ]; then
1900 query="/policy_types"
1901 elif [ $2 == "NORIC" ]; then
1902 query="/policy_types"
1904 query="/policy_types?ric=$2"
1908 res="$(__do_curl_to_api A1PMS GET $query)"
1909 status=${res:${#res}-3}
1911 if [ $status -ne $1 ]; then
1912 __log_test_fail_status_code $1 $status
1916 if [ $# -gt 2 ]; then
1917 body=${res:0:${#res}-3}
1920 for pid in ${@:3} ; do
1921 if [ "$targetJson" != "[" ]; then
1922 targetJson=$targetJson","
1924 if [ $pid == "EMPTY" ]; then
1927 targetJson=$targetJson"\"$pid\""
1930 targetJson=$targetJson"]"
1931 if [ "$A1PMS_VERSION" == "V2" ]; then
1932 targetJson="{\"policytype_ids\": $targetJson }"
1934 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1935 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1937 if [ $res -ne 0 ]; then
1938 __log_test_fail_body
1943 __collect_endpoint_stats "A1PMS" 09 "GET" $A1PMS_API_PREFIX"/v2/policy-types" $status
1948 #########################################################
1949 #### Test case functions Health check
1950 #########################################################
1952 # API Test function: GET /status and V2 GET /status
1953 # args: <response-code>
1954 # (Function for test scripts)
1955 a1pms_api_get_status() {
1957 if [ $# -ne 1 ]; then
1958 __print_err "<response-code>" $@
1961 if [ "$A1PMS_VERSION" == "V2" ]; then
1966 res="$(__do_curl_to_api A1PMS GET $query)"
1967 status=${res:${#res}-3}
1969 if [ $status -ne $1 ]; then
1970 __log_test_fail_status_code $1 $status
1974 __collect_endpoint_stats "A1PMS" 10 "GET" $A1PMS_API_PREFIX"/v2/status" $status
1979 # API Test function: GET /status (root) without api prefix
1980 # args: <response-code>
1981 # (Function for test scripts)
1982 a1pms_api_get_status_root() {
1984 if [ $# -ne 1 ]; then
1985 __print_err "<response-code>" $@
1989 TMP_PREFIX=$A1PMS_API_PREFIX
1991 res="$(__do_curl_to_api A1PMS GET $query)"
1992 A1PMS_API_PREFIX=$TMP_PREFIX
1993 status=${res:${#res}-3}
1995 if [ $status -ne $1 ]; then
1996 __log_test_fail_status_code $1 $status
2000 __collect_endpoint_stats "A1PMS" 19 "GET" "/status" $status
2005 #########################################################
2006 #### Test case functions RIC Repository
2007 #########################################################
2009 # API Test function: GET /ric and V2 GET /v2/rics/ric
2010 # args: <reponse-code> <management-element-id> [<ric-id>]
2011 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
2012 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
2013 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
2016 # (Function for test scripts)
2017 a1pms_api_get_ric() {
2020 if [ "$A1PMS_VERSION" == "V2" ]; then
2021 if [ $# -lt 3 ]; then
2022 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
2026 if [ $2 != "NOME" ]; then
2027 search="?managed_element_id="$2
2029 if [ $3 != "NORIC" ]; then
2030 if [ -z $search ]; then
2033 search=$search"&ric_id="$3
2036 query="/v2/rics/ric"$search
2038 res="$(__do_curl_to_api A1PMS GET $query)"
2039 status=${res:${#res}-3}
2041 if [ $status -ne $1 ]; then
2042 __log_test_fail_status_code $1 $status
2046 if [ $# -gt 3 ]; then
2047 body=${res:0:${#res}-3}
2048 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
2049 if [ $res -ne 0 ]; then
2050 __log_test_fail_general "Could not create target ric info json"
2054 targetJson=$(<./tmp/.tmp_rics.json)
2055 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
2056 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2057 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2058 if [ $res -ne 0 ]; then
2059 __log_test_fail_body
2064 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
2065 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
2069 query="/ric?managedElementId="$2
2071 res="$(__do_curl_to_api A1PMS GET $query)"
2072 status=${res:${#res}-3}
2074 if [ $status -ne $1 ]; then
2075 __log_test_fail_status_code $1 $status
2079 if [ $# -eq 3 ]; then
2080 body=${res:0:${#res}-3}
2081 if [ "$body" != "$3" ]; then
2082 __log_test_fail_body
2088 __collect_endpoint_stats "A1PMS" 11 "GET" $A1PMS_API_PREFIX"/v2/rics/ric" $status
2093 # API test function: GET /rics and V2 GET /v2/rics
2094 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
2095 # 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_........."
2096 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
2097 # (Function for test scripts)
2098 a1pms_api_get_rics() {
2101 if [ $# -lt 2 ]; then
2102 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
2106 if [ "$A1PMS_VERSION" == "V2" ]; then
2108 if [ $2 != "NOTYPE" ]; then
2109 query="/v2/rics?policytype_id="$2
2113 if [ $2 != "NOTYPE" ]; then
2114 query="/rics?policyType="$2
2118 res="$(__do_curl_to_api A1PMS GET $query)"
2119 status=${res:${#res}-3}
2121 if [ $status -ne $1 ]; then
2122 __log_test_fail_status_code $1 $status
2126 if [ $# -gt 2 ]; then
2127 body=${res:0:${#res}-3}
2128 if [ "$A1PMS_VERSION" == "V2" ]; then
2129 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
2131 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
2133 if [ $res -ne 0 ]; then
2134 __log_test_fail_general "Could not create target ric info json"
2138 targetJson=$(<./tmp/.tmp_rics.json)
2139 if [ "$A1PMS_VERSION" == "V2" ]; then
2140 targetJson="{\"rics\": $targetJson }"
2142 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2143 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2144 if [ $res -ne 0 ]; then
2145 __log_test_fail_body
2150 __collect_endpoint_stats "A1PMS" 12 "GET" $A1PMS_API_PREFIX"/v2/rics" $status
2155 ##################################################################
2156 #### API Test case functions Service registry and supervision ####
2157 ##################################################################
2159 # API test function: PUT /service and V2 PUT /service
2160 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
2161 # (Function for test scripts)
2162 a1pms_api_put_service() {
2164 if [ $# -ne 4 ]; then
2165 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
2169 if [ "$A1PMS_VERSION" == "V2" ]; then
2170 query="/v2/services"
2171 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
2174 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
2176 file="./tmp/.tmp.json"
2177 echo "$json" > $file
2179 res="$(__do_curl_to_api A1PMS PUT $query $file)"
2180 status=${res:${#res}-3}
2182 if [ $status -ne $1 ]; then
2183 __log_test_fail_status_code $1 $status
2187 __collect_endpoint_stats "A1PMS" 13 "PUT" $A1PMS_API_PREFIX"/v2/service" $status
2192 # API test function: GET /services and V2 GET /v2/services
2193 #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>]* )]
2194 # (Function for test scripts)
2195 a1pms_api_get_services() {
2197 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
2199 if [ $# -eq 1 ]; then
2201 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
2203 elif [ $# -eq 5 ]; then
2205 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
2207 if [ $(($argLen%3)) -eq 0 ]; then
2212 if [ $paramError -ne 0 ]; then
2213 __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>]* )]" $@
2217 if [ "$A1PMS_VERSION" == "V2" ]; then
2218 query="/v2/services"
2220 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2221 query="/v2/services?service_id="$2
2226 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2227 query="/services?name="$2
2230 res="$(__do_curl_to_api A1PMS GET $query)"
2231 status=${res:${#res}-3}
2233 if [ $status -ne $1 ]; then
2234 __log_test_fail_status_code $1 $status
2238 if [ $# -gt 2 ]; then
2239 variableArgCount=$(($#-2))
2240 body=${res:0:${#res}-3}
2244 while [ $cntr -lt $variableArgCount ]; do
2245 servicename=$1; shift;
2248 if [ $cntr -gt 0 ]; then
2249 targetJson=$targetJson","
2251 # timeSinceLastActivitySeconds value cannot be checked since value varies
2252 if [ "$A1PMS_VERSION" == "V2" ]; then
2253 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
2255 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2259 targetJson=$targetJson"]"
2260 if [ "$A1PMS_VERSION" == "V2" ]; then
2261 targetJson="{\"service_list\": $targetJson }"
2263 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2264 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2265 if [ $res -ne 0 ]; then
2266 __log_test_fail_body
2271 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX"/v2/services" $status
2276 # API test function: GET /services V2 GET /v2/services - (only checking service names)
2277 # args: <response-code> [<service-name>]*"
2278 # (Function for test scripts)
2279 a1pms_api_get_service_ids() {
2282 if [ $# -lt 1 ]; then
2283 __print_err "<response-code> [<service-name>]*" $@
2287 if [ "$A1PMS_VERSION" == "V2" ]; then
2288 query="/v2/services"
2292 res="$(__do_curl_to_api A1PMS GET $query)"
2293 status=${res:${#res}-3}
2295 if [ $status -ne $1 ]; then
2296 __log_test_fail_status_code $1 $status
2300 body=${res:0:${#res}-3}
2302 for rapp in ${@:2} ; do
2303 if [ "$targetJson" != "[" ]; then
2304 targetJson=$targetJson","
2306 if [ "$A1PMS_VERSION" == "V2" ]; then
2307 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2309 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2313 targetJson=$targetJson"]"
2314 if [ "$A1PMS_VERSION" == "V2" ]; then
2315 targetJson="{\"service_list\": $targetJson }"
2317 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2318 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2320 if [ $res -ne 0 ]; then
2321 __log_test_fail_body
2325 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX"/v2/services" $status
2330 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
2331 # args: <response-code> <service-name>
2332 # (Function for test scripts)
2333 a1pms_api_delete_services() {
2336 if [ $# -ne 2 ]; then
2337 __print_err "<response-code> <service-name>" $@
2340 if [ "$A1PMS_VERSION" == "V2" ]; then
2341 query="/v2/services/"$2
2343 query="/services?name="$2
2345 res="$(__do_curl_to_api A1PMS DELETE $query)"
2346 status=${res:${#res}-3}
2348 if [ $status -ne $1 ]; then
2349 __log_test_fail_status_code $1 $status
2353 __collect_endpoint_stats "A1PMS" 15 "DELETE" $A1PMS_API_PREFIX"/v2/services/{serviceId}" $status
2358 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
2359 # args: <response-code> <service-name>
2360 # (Function for test scripts)
2361 a1pms_api_put_services_keepalive() {
2364 if [ $# -ne 2 ]; then
2365 __print_err "<response-code> <service-name>" $@
2368 if [ "$A1PMS_VERSION" == "V2" ]; then
2369 query="/v2/services/$2/keepalive"
2371 query="/services/keepalive?name="$2
2374 res="$(__do_curl_to_api A1PMS PUT $query)"
2375 status=${res:${#res}-3}
2377 if [ $status -ne $1 ]; then
2378 __log_test_fail_status_code $1 $status
2382 __collect_endpoint_stats "A1PMS" 16 "PUT" $A1PMS_API_PREFIX"/v2/services/{service_id}/keepalive" $status
2387 ##################################################################
2388 #### API Test case functions Configuration ####
2389 ##################################################################
2391 # API Test function: PUT /v2/configuration
2392 # args: <response-code> <config-file>
2393 # (Function for test scripts)
2394 a1pms_api_put_configuration() {
2397 if [ "$A1PMS_VERSION" != "V2" ]; then
2398 __log_test_fail_not_supported
2402 if [ $# -ne 2 ]; then
2403 __print_err "<response-code> <config-file>" $@
2406 if [ ! -f $2 ]; then
2407 __log_test_fail_general "Config file "$2", does not exist"
2411 # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
2412 # inputJson="{\"config\":"$inputJson"}"
2414 file="./tmp/.config.json"
2415 echo $inputJson > $file
2416 query="/v2/configuration"
2417 res="$(__do_curl_to_api A1PMS PUT $query $file)"
2418 status=${res:${#res}-3}
2420 if [ $status -ne $1 ]; then
2421 __log_test_fail_status_code $1 $status
2425 __collect_endpoint_stats "A1PMS" 17 "PUT" $A1PMS_API_PREFIX"/v2/configuration" $status
2430 # API Test function: GET /v2/configuration
2431 # args: <response-code> [<config-file>]
2432 # (Function for test scripts)
2433 a1pms_api_get_configuration() {
2436 if [ "$A1PMS_VERSION" != "V2" ]; then
2437 __log_test_fail_not_supported
2441 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2442 __print_err "<response-code> [<config-file>]" $@
2445 if [ ! -f $2 ]; then
2446 __log_test_fail_general "Config file "$2" for comparison, does not exist"
2450 query="/v2/configuration"
2451 res="$(__do_curl_to_api A1PMS GET $query)"
2452 status=${res:${#res}-3}
2454 if [ $status -ne $1 ]; then
2455 __log_test_fail_status_code $1 $status
2459 if [ $# -eq 2 ]; then
2461 body=${res:0:${#res}-3}
2464 # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
2465 # inputJson="{\"config\":"$inputJson"}"
2467 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2468 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2470 if [ $res -ne 0 ]; then
2471 __log_test_fail_body
2476 __collect_endpoint_stats "A1PMS" 18 "GET" $A1PMS_API_PREFIX"/v2/configuration" $status
2481 ##########################################
2482 #### Reset types and instances ####
2483 ##########################################
2485 # Admin reset to remove all policies and services
2486 # All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2487 # NOTE - only works in kubernetes and the pod should not be running
2489 # (Function for test scripts)
2491 a1pms_kube_pvc_reset() {
2494 pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
2495 if [ -z "$pvc_name" ]; then
2496 pvc_name=policymanagementservice-vardata-pvc
2498 echo " Trying to reset pvc: "$pvc_name
2499 __kube_clean_pvc $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $A1PMS_CONTAINER_MNT_DIR
2505 # args: <realm> <client-name> <client-secret>
2506 a1pms_configure_sec() {
2507 export A1PMS_CREDS_GRANT_TYPE="client_credentials"
2508 export A1PMS_CREDS_CLIENT_SECRET=$3
2509 export A1PMS_CREDS_CLIENT_ID=$2
2510 export A1PMS_AUTH_SERVICE_URL=$KEYCLOAK_SERVICE_PATH$KEYCLOAK_TOKEN_URL_PREFIX/$1/protocol/openid-connect/token
2511 export A1PMS_SIDECAR_MOUNT="/token-cache"
2512 export A1PMS_SIDECAR_JWT_FILE=$A1PMS_SIDECAR_MOUNT"/jwt.txt"
2514 export AUTHSIDECAR_APP_NAME
2515 export AUTHSIDECAR_DISPLAY_NAME