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 targetJson="{\"instance_status\":\"$4\""
1834 if [ $# -eq 5 ]; then
1835 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1837 targetJson=$targetJson",\"created_at\":\"????\"}"
1839 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1843 if [ "$A1PMS_VERSION" == "V2" ]; then
1844 query="/v2/policies/$UUID$2/status"
1845 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1847 query="/policy_status?id="$UUID$2
1850 res="$(__do_curl_to_api A1PMS GET $query)"
1851 status=${res:${#res}-3}
1853 if [ $status -ne $1 ]; then
1854 __log_test_fail_status_code $1 $status
1857 if [ $# -gt 2 ]; then
1858 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1859 body=${res:0:${#res}-3}
1860 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1862 if [ $res -ne 0 ]; then
1863 __log_test_fail_body
1867 __collect_endpoint_stats "A1PMS" 08 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}/status" $status
1872 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1873 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1874 # (Function for test scripts)
1875 a1pms_api_get_policy_types() {
1878 if [ $# -lt 1 ]; then
1879 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1883 if [ "$A1PMS_VERSION" == "V2" ]; then
1884 if [ $# -eq 1 ]; then
1885 query="/v2/policy-types"
1886 elif [ $2 == "NORIC" ]; then
1887 query="/v2/policy-types"
1889 query="/v2/policy-types?ric_id=$2"
1892 if [ $# -eq 1 ]; then
1893 query="/policy_types"
1894 elif [ $2 == "NORIC" ]; then
1895 query="/policy_types"
1897 query="/policy_types?ric=$2"
1901 res="$(__do_curl_to_api A1PMS GET $query)"
1902 status=${res:${#res}-3}
1904 if [ $status -ne $1 ]; then
1905 __log_test_fail_status_code $1 $status
1909 if [ $# -gt 2 ]; then
1910 body=${res:0:${#res}-3}
1913 for pid in ${@:3} ; do
1914 if [ "$targetJson" != "[" ]; then
1915 targetJson=$targetJson","
1917 if [ $pid == "EMPTY" ]; then
1920 targetJson=$targetJson"\"$pid\""
1923 targetJson=$targetJson"]"
1924 if [ "$A1PMS_VERSION" == "V2" ]; then
1925 targetJson="{\"policytype_ids\": $targetJson }"
1927 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1928 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1930 if [ $res -ne 0 ]; then
1931 __log_test_fail_body
1936 __collect_endpoint_stats "A1PMS" 09 "GET" $A1PMS_API_PREFIX"/v2/policy-types" $status
1941 #########################################################
1942 #### Test case functions Health check
1943 #########################################################
1945 # API Test function: GET /status and V2 GET /status
1946 # args: <response-code>
1947 # (Function for test scripts)
1948 a1pms_api_get_status() {
1950 if [ $# -ne 1 ]; then
1951 __print_err "<response-code>" $@
1954 if [ "$A1PMS_VERSION" == "V2" ]; then
1959 res="$(__do_curl_to_api A1PMS GET $query)"
1960 status=${res:${#res}-3}
1962 if [ $status -ne $1 ]; then
1963 __log_test_fail_status_code $1 $status
1967 __collect_endpoint_stats "A1PMS" 10 "GET" $A1PMS_API_PREFIX"/v2/status" $status
1972 # API Test function: GET /status (root) without api prefix
1973 # args: <response-code>
1974 # (Function for test scripts)
1975 a1pms_api_get_status_root() {
1977 if [ $# -ne 1 ]; then
1978 __print_err "<response-code>" $@
1982 TMP_PREFIX=$A1PMS_API_PREFIX
1984 res="$(__do_curl_to_api A1PMS GET $query)"
1985 A1PMS_API_PREFIX=$TMP_PREFIX
1986 status=${res:${#res}-3}
1988 if [ $status -ne $1 ]; then
1989 __log_test_fail_status_code $1 $status
1993 __collect_endpoint_stats "A1PMS" 19 "GET" "/status" $status
1998 #########################################################
1999 #### Test case functions RIC Repository
2000 #########################################################
2002 # API Test function: GET /ric and V2 GET /v2/rics/ric
2003 # args: <reponse-code> <management-element-id> [<ric-id>]
2004 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
2005 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
2006 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
2009 # (Function for test scripts)
2010 a1pms_api_get_ric() {
2013 if [ "$A1PMS_VERSION" == "V2" ]; then
2014 if [ $# -lt 3 ]; then
2015 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
2019 if [ $2 != "NOME" ]; then
2020 search="?managed_element_id="$2
2022 if [ $3 != "NORIC" ]; then
2023 if [ -z $search ]; then
2026 search=$search"&ric_id="$3
2029 query="/v2/rics/ric"$search
2031 res="$(__do_curl_to_api A1PMS GET $query)"
2032 status=${res:${#res}-3}
2034 if [ $status -ne $1 ]; then
2035 __log_test_fail_status_code $1 $status
2039 if [ $# -gt 3 ]; then
2040 body=${res:0:${#res}-3}
2041 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
2042 if [ $res -ne 0 ]; then
2043 __log_test_fail_general "Could not create target ric info json"
2047 targetJson=$(<./tmp/.tmp_rics.json)
2048 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
2049 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2050 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2051 if [ $res -ne 0 ]; then
2052 __log_test_fail_body
2057 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
2058 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
2062 query="/ric?managedElementId="$2
2064 res="$(__do_curl_to_api A1PMS GET $query)"
2065 status=${res:${#res}-3}
2067 if [ $status -ne $1 ]; then
2068 __log_test_fail_status_code $1 $status
2072 if [ $# -eq 3 ]; then
2073 body=${res:0:${#res}-3}
2074 if [ "$body" != "$3" ]; then
2075 __log_test_fail_body
2081 __collect_endpoint_stats "A1PMS" 11 "GET" $A1PMS_API_PREFIX"/v2/rics/ric" $status
2086 # API test function: GET /rics and V2 GET /v2/rics
2087 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
2088 # 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_........."
2089 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
2090 # (Function for test scripts)
2091 a1pms_api_get_rics() {
2094 if [ $# -lt 2 ]; then
2095 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
2099 if [ "$A1PMS_VERSION" == "V2" ]; then
2101 if [ $2 != "NOTYPE" ]; then
2102 query="/v2/rics?policytype_id="$2
2106 if [ $2 != "NOTYPE" ]; then
2107 query="/rics?policyType="$2
2111 res="$(__do_curl_to_api A1PMS GET $query)"
2112 status=${res:${#res}-3}
2114 if [ $status -ne $1 ]; then
2115 __log_test_fail_status_code $1 $status
2119 if [ $# -gt 2 ]; then
2120 body=${res:0:${#res}-3}
2121 if [ "$A1PMS_VERSION" == "V2" ]; then
2122 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
2124 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
2126 if [ $res -ne 0 ]; then
2127 __log_test_fail_general "Could not create target ric info json"
2131 targetJson=$(<./tmp/.tmp_rics.json)
2132 if [ "$A1PMS_VERSION" == "V2" ]; then
2133 targetJson="{\"rics\": $targetJson }"
2135 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2136 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2137 if [ $res -ne 0 ]; then
2138 __log_test_fail_body
2143 __collect_endpoint_stats "A1PMS" 12 "GET" $A1PMS_API_PREFIX"/v2/rics" $status
2148 ##################################################################
2149 #### API Test case functions Service registry and supervision ####
2150 ##################################################################
2152 # API test function: PUT /service and V2 PUT /service
2153 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
2154 # (Function for test scripts)
2155 a1pms_api_put_service() {
2157 if [ $# -ne 4 ]; then
2158 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
2162 if [ "$A1PMS_VERSION" == "V2" ]; then
2163 query="/v2/services"
2164 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
2167 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
2169 file="./tmp/.tmp.json"
2170 echo "$json" > $file
2172 res="$(__do_curl_to_api A1PMS PUT $query $file)"
2173 status=${res:${#res}-3}
2175 if [ $status -ne $1 ]; then
2176 __log_test_fail_status_code $1 $status
2180 __collect_endpoint_stats "A1PMS" 13 "PUT" $A1PMS_API_PREFIX"/v2/service" $status
2185 # API test function: GET /services and V2 GET /v2/services
2186 #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>]* )]
2187 # (Function for test scripts)
2188 a1pms_api_get_services() {
2190 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
2192 if [ $# -eq 1 ]; then
2194 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
2196 elif [ $# -eq 5 ]; then
2198 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
2200 if [ $(($argLen%3)) -eq 0 ]; then
2205 if [ $paramError -ne 0 ]; then
2206 __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>]* )]" $@
2210 if [ "$A1PMS_VERSION" == "V2" ]; then
2211 query="/v2/services"
2213 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2214 query="/v2/services?service_id="$2
2219 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2220 query="/services?name="$2
2223 res="$(__do_curl_to_api A1PMS GET $query)"
2224 status=${res:${#res}-3}
2226 if [ $status -ne $1 ]; then
2227 __log_test_fail_status_code $1 $status
2231 if [ $# -gt 2 ]; then
2232 variableArgCount=$(($#-2))
2233 body=${res:0:${#res}-3}
2237 while [ $cntr -lt $variableArgCount ]; do
2238 servicename=$1; shift;
2241 if [ $cntr -gt 0 ]; then
2242 targetJson=$targetJson","
2244 # timeSinceLastActivitySeconds value cannot be checked since value varies
2245 if [ "$A1PMS_VERSION" == "V2" ]; then
2246 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
2248 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2252 targetJson=$targetJson"]"
2253 if [ "$A1PMS_VERSION" == "V2" ]; then
2254 targetJson="{\"service_list\": $targetJson }"
2256 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2257 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2258 if [ $res -ne 0 ]; then
2259 __log_test_fail_body
2264 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX"/v2/services" $status
2269 # API test function: GET /services V2 GET /v2/services - (only checking service names)
2270 # args: <response-code> [<service-name>]*"
2271 # (Function for test scripts)
2272 a1pms_api_get_service_ids() {
2275 if [ $# -lt 1 ]; then
2276 __print_err "<response-code> [<service-name>]*" $@
2280 if [ "$A1PMS_VERSION" == "V2" ]; then
2281 query="/v2/services"
2285 res="$(__do_curl_to_api A1PMS GET $query)"
2286 status=${res:${#res}-3}
2288 if [ $status -ne $1 ]; then
2289 __log_test_fail_status_code $1 $status
2293 body=${res:0:${#res}-3}
2295 for rapp in ${@:2} ; do
2296 if [ "$targetJson" != "[" ]; then
2297 targetJson=$targetJson","
2299 if [ "$A1PMS_VERSION" == "V2" ]; then
2300 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2302 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2306 targetJson=$targetJson"]"
2307 if [ "$A1PMS_VERSION" == "V2" ]; then
2308 targetJson="{\"service_list\": $targetJson }"
2310 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2311 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2313 if [ $res -ne 0 ]; then
2314 __log_test_fail_body
2318 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX"/v2/services" $status
2323 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
2324 # args: <response-code> <service-name>
2325 # (Function for test scripts)
2326 a1pms_api_delete_services() {
2329 if [ $# -ne 2 ]; then
2330 __print_err "<response-code> <service-name>" $@
2333 if [ "$A1PMS_VERSION" == "V2" ]; then
2334 query="/v2/services/"$2
2336 query="/services?name="$2
2338 res="$(__do_curl_to_api A1PMS DELETE $query)"
2339 status=${res:${#res}-3}
2341 if [ $status -ne $1 ]; then
2342 __log_test_fail_status_code $1 $status
2346 __collect_endpoint_stats "A1PMS" 15 "DELETE" $A1PMS_API_PREFIX"/v2/services/{serviceId}" $status
2351 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
2352 # args: <response-code> <service-name>
2353 # (Function for test scripts)
2354 a1pms_api_put_services_keepalive() {
2357 if [ $# -ne 2 ]; then
2358 __print_err "<response-code> <service-name>" $@
2361 if [ "$A1PMS_VERSION" == "V2" ]; then
2362 query="/v2/services/$2/keepalive"
2364 query="/services/keepalive?name="$2
2367 res="$(__do_curl_to_api A1PMS PUT $query)"
2368 status=${res:${#res}-3}
2370 if [ $status -ne $1 ]; then
2371 __log_test_fail_status_code $1 $status
2375 __collect_endpoint_stats "A1PMS" 16 "PUT" $A1PMS_API_PREFIX"/v2/services/{service_id}/keepalive" $status
2380 ##################################################################
2381 #### API Test case functions Configuration ####
2382 ##################################################################
2384 # API Test function: PUT /v2/configuration
2385 # args: <response-code> <config-file>
2386 # (Function for test scripts)
2387 a1pms_api_put_configuration() {
2390 if [ "$A1PMS_VERSION" != "V2" ]; then
2391 __log_test_fail_not_supported
2395 if [ $# -ne 2 ]; then
2396 __print_err "<response-code> <config-file>" $@
2399 if [ ! -f $2 ]; then
2400 __log_test_fail_general "Config file "$2", does not exist"
2404 # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
2405 # inputJson="{\"config\":"$inputJson"}"
2407 file="./tmp/.config.json"
2408 echo $inputJson > $file
2409 query="/v2/configuration"
2410 res="$(__do_curl_to_api A1PMS PUT $query $file)"
2411 status=${res:${#res}-3}
2413 if [ $status -ne $1 ]; then
2414 __log_test_fail_status_code $1 $status
2418 __collect_endpoint_stats "A1PMS" 17 "PUT" $A1PMS_API_PREFIX"/v2/configuration" $status
2423 # API Test function: GET /v2/configuration
2424 # args: <response-code> [<config-file>]
2425 # (Function for test scripts)
2426 a1pms_api_get_configuration() {
2429 if [ "$A1PMS_VERSION" != "V2" ]; then
2430 __log_test_fail_not_supported
2434 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2435 __print_err "<response-code> [<config-file>]" $@
2438 if [ ! -f $2 ]; then
2439 __log_test_fail_general "Config file "$2" for comparison, does not exist"
2443 query="/v2/configuration"
2444 res="$(__do_curl_to_api A1PMS GET $query)"
2445 status=${res:${#res}-3}
2447 if [ $status -ne $1 ]; then
2448 __log_test_fail_status_code $1 $status
2452 if [ $# -eq 2 ]; then
2454 body=${res:0:${#res}-3}
2457 # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
2458 # inputJson="{\"config\":"$inputJson"}"
2460 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2461 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2463 if [ $res -ne 0 ]; then
2464 __log_test_fail_body
2469 __collect_endpoint_stats "A1PMS" 18 "GET" $A1PMS_API_PREFIX"/v2/configuration" $status
2474 ##########################################
2475 #### Reset types and instances ####
2476 ##########################################
2478 # Admin reset to remove all policies and services
2479 # All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2480 # NOTE - only works in kubernetes and the pod should not be running
2482 # (Function for test scripts)
2484 a1pms_kube_pvc_reset() {
2487 pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
2488 if [ -z "$pvc_name" ]; then
2489 pvc_name=policymanagementservice-vardata-pvc
2491 echo " Trying to reset pvc: "$pvc_name
2492 __kube_clean_pvc $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $A1PMS_CONTAINER_MNT_DIR
2498 # args: <realm> <client-name> <client-secret>
2499 a1pms_configure_sec() {
2500 export A1PMS_CREDS_GRANT_TYPE="client_credentials"
2501 export A1PMS_CREDS_CLIENT_SECRET=$3
2502 export A1PMS_CREDS_CLIENT_ID=$2
2503 export A1PMS_AUTH_SERVICE_URL=$KEYCLOAK_SERVICE_PATH$KEYCLOAK_TOKEN_URL_PREFIX/$1/protocol/openid-connect/token
2504 export A1PMS_SIDECAR_MOUNT="/token-cache"
2505 export A1PMS_SIDECAR_JWT_FILE=$A1PMS_SIDECAR_MOUNT"/jwt.txt"
2507 export AUTHSIDECAR_APP_NAME
2508 export AUTHSIDECAR_DISPLAY_NAME