3 # ============LICENSE_START===============================================
4 # Copyright (C) 2021-2023 Nordix Foundation. All rights reserved.
5 # ========================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=================================================
20 # This is a script that contains management and test functions for A1PMS
22 ################ Test engine functions ################
24 # Create the image var used during the test
25 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
26 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
27 __A1PMS_imagesetup() {
28 __check_and_create_image_var A1PMS "A1PMS_IMAGE" "A1PMS_IMAGE_BASE" "A1PMS_IMAGE_TAG" $1 "$A1PMS_DISPLAY_NAME" ""
31 # Pull image from remote repo or use locally built image
32 # arg: <pull-policy-override> <pull-policy-original>
33 # <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
34 # <pull-policy-original> Shall be used for images that does not allow overriding
35 # Both var may contain: 'remote', 'remote-remove' or 'local'
37 __check_and_pull_image $1 "$A1PMS_DISPLAY_NAME" $A1PMS_APP_NAME A1PMS_IMAGE
40 # Build image (only for simulator or interfaces stubs owned by the test environment)
41 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
42 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
43 __A1PMS_imagebuild() {
44 echo -e $RED" Image for app A1PMS shall never be built"$ERED
47 # Generate a string for each included image using the app display name and a docker images format string
48 # If a custom image repo is used then also the source image from the local repo is listed
49 # arg: <docker-images-format-string> <file-to-append>
50 __A1PMS_image_data() {
51 echo -e "$A1PMS_DISPLAY_NAME\t$(docker images --format $1 $A1PMS_IMAGE)" >> $2
52 if [ ! -z "$A1PMS_IMAGE_SOURCE" ]; then
53 echo -e "-- source image --\t$(docker images --format $1 $A1PMS_IMAGE_SOURCE)" >> $2
57 # Scale kubernetes resources to zero
58 # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
59 # This function is called for apps fully managed by the test script
60 __A1PMS_kube_scale_zero() {
61 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS
64 # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
65 # This function is called for pre-started apps not managed by the test script.
66 __A1PMS_kube_scale_zero_and_wait() {
67 __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app "$KUBE_NONRTRIC_NAMESPACE"-policymanagementservice
70 # Delete all kube resources for the app
71 # This function is called for apps managed by the test script.
72 __A1PMS_kube_delete_all() {
73 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS
77 # This function is called for apps managed by the test script.
78 # args: <log-dir> <file-prefix>
79 __A1PMS_store_docker_logs() {
80 if [ $RUNMODE == "KUBE" ]; then
81 kubectl $KUBECONF logs -l "autotest=A1PMS" -n $KUBE_NONRTRIC_NAMESPACE --tail=-1 > $1$2_a1pms.log 2>&1
83 docker logs $A1PMS_APP_NAME > $1$2_a1pms.log 2>&1
87 # Initial setup of protocol, host and ports
88 # This function is called for apps managed by the test script.
90 __A1PMS_initial_setup() {
92 export A1PMS_SIDECAR_JWT_FILE=""
95 # Set app short-name, app name and namespace for logging runtime statistics of kubernetes pods or docker containers
96 # For docker, the namespace shall be excluded
97 # This function is called for apps managed by the test script as well as for pre-started apps.
99 __A1PMS_statistics_setup() {
100 if [ $RUNMODE == "KUBE" ]; then
101 echo "A1PMS $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE"
103 echo "A1PMS $A1PMS_APP_NAME"
107 # Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
109 __A1PMS_test_requirements() {
114 #######################################################
116 ###########################
118 ###########################
120 # Set http as the protocol to use for all communication to the A1PMS
122 # (Function for test scripts)
123 use_a1pms_rest_http() {
124 __a1pms_set_protocoll "http" $A1PMS_INTERNAL_PORT $A1PMS_EXTERNAL_PORT
127 # Set https as the protocol to use for all communication to the A1PMS
129 # (Function for test scripts)
130 use_a1pms_rest_https() {
131 __a1pms_set_protocoll "https" $A1PMS_INTERNAL_SECURE_PORT $A1PMS_EXTERNAL_SECURE_PORT
134 # All calls to the a1pms will be directed to the a1pms dmaap interface over http from now on
136 # (Function for test scripts)
137 use_a1pms_dmaap_http() {
138 echo -e $BOLD"$A1PMS_DISPLAY_NAME dmaap protocol setting"$EBOLD
139 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the a1pms"
140 A1PMS_ADAPTER_TYPE="MR-HTTP"
144 # All calls to the a1pms will be directed to the a1pms dmaap interface over https from now on
146 # (Function for test scripts)
147 use_a1pms_dmaap_https() {
148 echo -e $BOLD"$A1PMS_DISPLAY_NAME dmaap protocol setting"$EBOLD
149 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the a1pms"
150 echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
151 A1PMS_ADAPTER_TYPE="MR-HTTPS"
155 # Setup paths to svc/container for internal and external access
156 # args: <protocol> <internal-port> <external-port>
157 __a1pms_set_protocoll() {
158 echo -e $BOLD"$A1PMS_DISPLAY_NAME protocol setting"$EBOLD
159 echo -e " Using $BOLD $1 $EBOLD towards $A1PMS_DISPLAY_NAME"
161 ## Access to Dmaap adapter
163 A1PMS_SERVICE_PATH=$1"://"$A1PMS_APP_NAME":"$2 # docker access, container->container and script->container via proxy
164 if [ $RUNMODE == "KUBE" ]; then
165 A1PMS_SERVICE_PATH=$1"://"$A1PMS_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
168 # A1PMS_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
169 A1PMS_ADAPTER_TYPE="REST"
170 A1PMS_ADAPTER=$A1PMS_SERVICE_PATH
175 # Make curl retries towards the a1pms for http response codes set in this env var, space separated list of codes
178 #Save first worker node the pod is started on
179 __A1PMS_WORKER_NODE=""
181 # Export env vars for config files, docker compose and kube resources
182 # args: PROXY|NOPROXY
183 __export_a1pms_vars() {
185 export A1PMS_APP_NAME
186 export A1PMS_APP_NAME_ALIAS
187 export A1PMS_DISPLAY_NAME
189 export KUBE_NONRTRIC_NAMESPACE
191 export A1PMS_INTERNAL_PORT
192 export A1PMS_INTERNAL_SECURE_PORT
193 export A1PMS_EXTERNAL_PORT
194 export A1PMS_EXTERNAL_SECURE_PORT
195 export A1PMS_CONFIG_MOUNT_PATH
196 export A1PMS_DATA_MOUNT_PATH
197 export A1PMS_CONFIG_CONFIGMAP_NAME=$A1PMS_APP_NAME"-config"
198 export A1PMS_DATA_CONFIGMAP_NAME=$A1PMS_APP_NAME"-data"
199 export A1PMS_PKG_NAME
200 export A1PMS_CONFIG_KEY
201 export DOCKER_SIM_NWNAME
202 export A1PMS_HOST_MNT_DIR
203 export A1PMS_CONFIG_FILE
205 export A1PMS_DATA_PV_NAME=$A1PMS_APP_NAME"-pv"
206 export A1PMS_DATA_PVC_NAME=$A1PMS_APP_NAME"-pvc"
207 ##Create a unique path for the pv each time to prevent a previous volume to be reused
208 export A1PMS_PV_PATH="a1pmsdata-"$(date +%s)
209 export A1PMS_CONTAINER_MNT_DIR
210 export HOST_PATH_BASE_DIR
212 if [ $1 == "PROXY" ]; then
213 export A1PMS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
214 export A1PMS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
215 if [ $A1PMS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$A1PMS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
216 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
218 echo " Configured with http proxy"
221 export A1PMS_HTTP_PROXY_CONFIG_PORT=0
222 export A1PMS_HTTP_PROXY_CONFIG_HOST_NAME=""
223 echo " Configured without http proxy"
229 # args: (docker) PROXY|NOPROXY <config-file>
230 # args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
231 # (Function for test scripts)
233 echo -e $BOLD"Starting $A1PMS_DISPLAY_NAME"$EBOLD
235 if [ $RUNMODE == "KUBE" ]; then
237 # Check if app shall be fully managed by the test script
238 __check_included_image "A1PMS"
241 # Check if app shall only be used by the test script
242 __check_prestarted_image "A1PMS"
245 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
246 echo -e $RED"The $A1PMS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
247 echo -e $RED"The $A1PMS_APP_NAME will not be started"$ERED
250 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
251 echo -e $RED"The $A1PMS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
252 echo -e $RED"The $A1PMS_APP_NAME will not be started"$ERED
256 if [ $retcode_p -eq 0 ]; then
257 echo -e " Using existing $A1PMS_APP_NAME deployment and service"
258 echo " Setting $A1PMS_APP_NAME replicas=1"
259 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
260 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
263 if [ $retcode_i -eq 0 ]; then
265 echo -e " Creating $A1PMS_APP_NAME app and expose service"
267 #Check if nonrtric namespace exists, if not create it
268 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
270 __export_a1pms_vars $1
272 # Create config map for config
273 configfile=$PWD/tmp/$A1PMS_CONFIG_FILE
275 output_yaml=$PWD/tmp/a1pms-cfc.yaml
276 __kube_create_configmap $A1PMS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $configfile $output_yaml
278 # Create config map for data
279 data_json=$PWD/tmp/$A1PMS_DATA_FILE
280 if [ $# -lt 3 ]; then
281 #create empty dummy file
282 echo "{}" > $data_json
286 output_yaml=$PWD/tmp/a1pms-cfd.yaml
287 __kube_create_configmap $A1PMS_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $data_json $output_yaml
290 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"pv.yaml
291 output_yaml=$PWD/tmp/a1pms-pv.yaml
292 __kube_create_instance pv $A1PMS_APP_NAME $input_yaml $output_yaml
295 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"pvc.yaml
296 output_yaml=$PWD/tmp/a1pms-pvc.yaml
297 __kube_create_instance pvc $A1PMS_APP_NAME $input_yaml $output_yaml
300 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"svc.yaml
301 output_yaml=$PWD/tmp/a1pmssvc.yaml
302 __kube_create_instance service $A1PMS_APP_NAME $input_yaml $output_yaml
305 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"app.yaml
306 output_yaml=$PWD/tmp/a1pmsapp.yaml
307 if [ -z "$A1PMS_SIDECAR_JWT_FILE" ]; then
308 cat $input_yaml | sed '/#A1PMS_JWT_START/,/#A1PMS_JWT_STOP/d' > $PWD/tmp/a1pmsapp_tmp.yaml
309 input_yaml=$PWD/tmp/a1pmsapp_tmp.yaml
311 __kube_create_instance app $A1PMS_APP_NAME $input_yaml $output_yaml
315 # 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
316 if [ $retcode_i -eq 0 ]; then
317 __A1PMS_WORKER_NODE=$(kubectl $KUBECONF get pod -l "autotest=A1PMS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
318 if [ -z "$__A1PMS_WORKER_NODE" ]; then
319 echo -e $YELLOW" Cannot find worker node for pod for $A1PMS_APP_NAME, persistency may not work"$EYELLOW
322 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
325 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
328 __check_included_image 'A1PMS'
329 if [ $? -eq 1 ]; then
330 echo -e $RED"The A1PMS app is not included in this test script"$ERED
331 echo -e $RED"The A1PMS will not be started"$ERED
338 cd $A1PMS_HOST_MNT_DIR
341 if [ "$(ls -A $DIR)" ]; then
342 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
343 rm -rf db/* &> /dev/null
344 if [ $? -ne 0 ]; then
345 echo -e $RED" Cannot remove database files in: $PWD"$ERED
350 echo " No files in mounted dir or dir does not exists"
355 __export_a1pms_vars $1
357 dest_file=$SIM_GROUP/$A1PMS_COMPOSE_DIR/$A1PMS_HOST_MNT_DIR/application.yaml
359 envsubst < $2 > $dest_file
361 __start_container $A1PMS_COMPOSE_DIR "" NODOCKERARGS 1 $A1PMS_APP_NAME
363 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
366 __collect_endpoint_stats_image_info "A1PMS" $A1PMS_IMAGE
374 # (Function for test scripts)
376 echo -e $BOLD"Stopping $A1PMS_DISPLAY_NAME"$EBOLD
378 if [ $RUNMODE == "KUBE" ]; then
380 __check_prestarted_image "A1PMS"
381 if [ $? -eq 0 ]; then
382 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
383 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
384 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
387 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS
388 echo " Deleting the replica set - a new will be started when the app is started"
389 tmp=$(kubectl $KUBECONF delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
390 if [ $? -ne 0 ]; then
391 echo -e $RED" Could not delete replica set "$RED
396 docker stop $A1PMS_APP_NAME &> ./tmp/.dockererr
397 if [ $? -ne 0 ]; then
398 __print_err "Could not stop $A1PMS_APP_NAME" $@
404 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
409 # Start a previously stopped a1pms
411 # (Function for test scripts)
412 start_stopped_a1pms() {
413 echo -e $BOLD"Starting (the previously stopped) $A1PMS_DISPLAY_NAME"$EBOLD
415 if [ $RUNMODE == "KUBE" ]; then
417 __check_prestarted_image "A1PMS"
418 if [ $? -eq 0 ]; then
419 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
420 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
421 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
422 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
426 # Tie the A1PMS to the same worker node it was initially started on
427 # 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
428 if [ -z "$__A1PMS_WORKER_NODE" ]; then
429 echo -e $RED" No initial worker node found for pod "$RED
433 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
434 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
435 tmp=$(kubectl $KUBECONF patch deployment $A1PMS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__A1PMS_WORKER_NODE'"}}}}}')
436 if [ $? -ne 0 ]; then
437 echo -e $YELLOW" Cannot set nodeSelector to deployment for $A1PMS_APP_NAME, persistency may not work"$EYELLOW
439 __kube_scale deployment $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
442 docker start $A1PMS_APP_NAME &> ./tmp/.dockererr
443 if [ $? -ne 0 ]; then
444 __print_err "Could not start (the stopped) $A1PMS_APP_NAME" $@
450 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
451 if [ $? -ne 0 ]; then
459 # Function to prepare the a1pms configuration according to the current simulator configuration
460 # args: SDNC|NOSDNC <output-file> [ <sim-group> <adapter-class> ]
461 # (Function for test scripts)
462 prepare_a1pms_config() {
463 echo -e $BOLD"Prepare A1PMS config"$EBOLD
465 echo " Writing a1pms config for "$A1PMS_APP_NAME" to file: "$2
467 if [ $# != 2 ] && [ $# != 4 ]; then
469 __print_err "need two or four args, SDNC|NOSDNC <output-file> [ <sim-group> <adapter-class> ]" $@
473 if [ $1 == "SDNC" ]; then
474 echo -e " Config$BOLD including SDNC$EBOLD configuration"
475 elif [ $1 == "NOSDNC" ]; then
476 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
479 __print_err "need three args, SDNC|NOSDNC <output-file> HEADER|NOHEADER" $@
484 if [ $1 == "SDNC" ]; then
485 config_json=$config_json"\n \"controller\": ["
486 config_json=$config_json"\n {"
487 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
488 config_json=$config_json"\n \"baseUrl\": \"$SDNC_SERVICE_PATH\","
489 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
490 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
491 config_json=$config_json"\n }"
492 config_json=$config_json"\n ],"
494 if [[ "$A1PMS_FEATURE_LEVEL" == *"NO-DMAAP"* ]]; then
497 config_json=$config_json"\n \"streams_publishes\": {"
498 config_json=$config_json"\n \"dmaap_publisher\": {"
499 config_json=$config_json"\n \"type\": \"message-router\","
500 config_json=$config_json"\n \"dmaap_info\": {"
501 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_WRITE_URL\""
502 config_json=$config_json"\n }"
503 config_json=$config_json"\n }"
504 config_json=$config_json"\n },"
505 config_json=$config_json"\n \"streams_subscribes\": {"
506 config_json=$config_json"\n \"dmaap_subscriber\": {"
507 config_json=$config_json"\n \"type\": \"message-router\","
508 config_json=$config_json"\n \"dmaap_info\": {"
509 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_READ_URL\""
510 config_json=$config_json"\n }"
511 config_json=$config_json"\n }"
512 config_json=$config_json"\n },"
515 config_json=$config_json"\n \"ric\": ["
517 if [ $RUNMODE == "KUBE" ]; then
518 result=$(kubectl $KUBECONF get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICSIM")].metadata.name}')
521 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
522 for im in $result; do
523 if [[ $im != *"-0" ]]; then
524 ric_subdomain=$(kubectl $KUBECONF get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
525 rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
526 let ric_cntr=ric_cntr+1
530 result=$(kubectl $KUBECONF get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICMEDIATORSIM")].metadata.name}')
532 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
533 for im in $result; do
534 if [[ $im != *"-0" ]]; then
535 ric_subdomain=$(kubectl $KUBECONF get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
536 rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
537 oranrics=$oranrics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
538 let ric_cntr=ric_cntr+1
542 if [ $ric_cntr -eq 0 ]; then
543 echo $YELLOW"Warning: No rics found for the configuration"$EYELLOW
546 rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "label=a1sim" --filter "status=running" --format {{.Names}})
547 if [ $? -ne 0 ] || [ -z "$rics" ]; then
548 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
552 oranrics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "label=orana1sim" --filter "status=running" --format {{.Names}})
553 if [ $? -ne 0 ] || [ -z "$rics" ]; then
554 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
558 rics="$rics $oranrics"
562 if [ $cntr -gt 0 ]; then
563 config_json=$config_json"\n ,"
565 config_json=$config_json"\n {"
566 if [ $RUNMODE == "KUBE" ]; then
567 ric_id=${ric%.*.*} #extract pod id from full hosthame
568 ric_id=$(echo "$ric_id" | tr '-' '_')
570 ric_id=$(echo "$ric" | tr '-' '_') #ric var still needs underscore as it is different from the container name
572 echo " Found a1 sim: "$ric
573 config_json=$config_json"\n \"name\": \"$ric_id\","
576 for xric in $oranrics; do
577 if [ $xric == $ric ]; then
581 if [ $xricfound -eq 0 ]; then
582 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
584 config_json=$config_json"\n \"baseUrl\": \"$RICMEDIATOR_SIM_HTTPX://$ric:$RICMEDIATOR_SIM_PORT\","
586 if [ ! -z "$3" ]; then
587 if [[ $ric == "$3"* ]]; then
588 config_json=$config_json"\n \"customAdapterClass\": \"$4\","
591 if [ $1 == "SDNC" ]; then
592 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
594 config_json=$config_json"\n \"managedElementIds\": ["
595 config_json=$config_json"\n \"me1_$ric_id\","
596 config_json=$config_json"\n \"me2_$ric_id\""
597 config_json=$config_json"\n ]"
598 config_json=$config_json"\n }"
602 config_json=$config_json"\n ]"
603 config_json=$config_json"\n}"
605 config_json="{\"config\":"$config_json"}"
607 printf "$config_json">$2
612 # Load the the appl config for the a1pms into a config map
613 a1pms_load_config() {
614 echo -e $BOLD"A1PMS - load config from "$EBOLD$1
615 data_json=$PWD/tmp/$A1PMS_DATA_FILE
617 output_yaml=$PWD/tmp/a1pms-cfd.yaml
618 __kube_create_configmap $A1PMS_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $data_json $output_yaml
623 # Turn on debug level tracing in the a1pms
625 # (Function for test scripts)
627 echo -e $BOLD"Setting a1pms debug logging"$EBOLD
628 curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
629 result=$(__do_curl "$curlString")
630 if [ $? -ne 0 ]; then
631 __print_err "could not set debug mode" $@
639 # Turn on trace level tracing in the a1pms
641 # (Function for test scripts)
643 echo -e $BOLD"Setting a1pms trace logging"$EBOLD
644 curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
645 result=$(__do_curl "$curlString")
646 if [ $? -ne 0 ]; then
647 __print_err "could not set trace mode" $@
655 # Perform curl retries when making direct call to the a1pms for the specified http response codes
656 # Speace separated list of http response codes
657 # args: [<response-code>]*
658 use_a1pms_retries() {
659 echo -e $BOLD"Do curl retries to the a1pms REST inteface for these response codes:$@"$EBOLD
665 # Check the a1pms logs for WARNINGs and ERRORs
667 # (Function for test scripts)
669 __check_container_logs "A1PMS" $A1PMS_APP_NAME $A1PMS_LOGPATH WARN ERR
672 #########################################################
673 #### Test case functions A1 Policy management service
674 #########################################################
676 # This function compare the size, towards a target value, of a json array returned from <url> of the A1PMS.
677 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
678 # args: json:<url> <target-value> [<timeout-in-seconds]
679 # (Function for test scripts)
681 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
682 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
683 if [[ $1 == "json:"* ]]; then
684 if [ "$A1PMS_VERSION" == "V2" ]; then
685 __var_test "A1PMS" $A1PMS_SERVICE_PATH$A1PMS_API_PREFIX"/v2/" $1 "=" $2 $3
687 __var_test "A1PMS" $A1PMS_SERVICE_PATH"/" $1 "=" $2 $3
692 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
696 # API Test function: GET /policies and V2 GET /v2/policy-instances
697 # 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>]*]
698 # 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>]*]
699 # (Function for test scripts)
700 a1pms_api_get_policies() {
703 if [ "$A1PMS_VERSION" == "V2" ]; then
705 variableParams=$(($#-4))
706 if [ $# -lt 4 ]; then
708 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
710 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
714 if [ $paramError -ne 0 ]; then
715 __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>]*]" $@
720 variableParams=$(($#-4))
721 if [ $# -lt 4 ]; then
723 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
725 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
729 if [ $paramError -ne 0 ]; then
730 __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>]*]" $@
736 if [ "$A1PMS_VERSION" == "V2" ]; then
737 if [ $2 != "NORIC" ]; then
738 queryparams="?ric_id="$2
740 if [ $3 != "NOSERVICE" ]; then
741 if [ -z $queryparams ]; then
742 queryparams="?service_id="$3
744 queryparams=$queryparams"&service_id="$3
747 if [ $4 != "NOTYPE" ]; then
748 if [ -z $queryparams ]; then
749 queryparams="?policytype_id="$4
751 queryparams=$queryparams"&policytype_id="$4
755 query="/v2/policy-instances"$queryparams
756 res="$(__do_curl_to_api A1PMS GET $query)"
757 status=${res:${#res}-3}
759 if [ $status -ne $1 ]; then
760 __log_test_fail_status_code $1 $status
764 if [ $# -gt 4 ]; then
765 body=${res:0:${#res}-3}
766 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
772 for ((i=0; i<$(($#-4)); i=i+7)); do
774 if [ "$targetJson" != "[" ]; then
775 targetJson=$targetJson","
777 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
778 if [ "${arr[$i+3]}" == "EMPTY" ]; then
779 targetJson=$targetJson"\"\","
781 targetJson=$targetJson"\"${arr[$i+3]}\","
783 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
785 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
787 targetJson=$targetJson"\"policy_data\":"$json"}"
791 targetJson=$targetJson"]"
792 targetJson="{\"policies\": $targetJson}"
793 echo "TARGET JSON: $targetJson" >> $HTTPLOG
794 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
796 if [ $res -ne 0 ]; then
802 if [ $2 != "NORIC" ]; then
803 queryparams="?ric="$2
805 if [ $3 != "NOSERVICE" ]; then
806 if [ -z $queryparams ]; then
807 queryparams="?service="$3
809 queryparams=$queryparams"&service="$3
812 if [ $4 != "NOTYPE" ]; then
813 if [ -z $queryparams ]; then
814 queryparams="?type="$4
816 queryparams=$queryparams"&type="$4
820 query="/policies"$queryparams
821 res="$(__do_curl_to_api A1PMS GET $query)"
822 status=${res:${#res}-3}
824 if [ $status -ne $1 ]; then
825 __log_test_fail_status_code $1 $status
829 if [ $# -gt 4 ]; then
830 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
833 body=${res:0:${#res}-3}
837 for ((i=0; i<$(($#-4)); i=i+5)); do
839 if [ "$targetJson" != "[" ]; then
840 targetJson=$targetJson","
842 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
843 if [ "${arr[$i+3]}" == "EMPTY" ]; then
844 targetJson=$targetJson"\"\","
846 targetJson=$targetJson"\"${arr[$i+3]}\","
849 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
851 targetJson=$targetJson"\"json\":"$json"}"
855 targetJson=$targetJson"]"
856 echo "TARGET JSON: $targetJson" >> $HTTPLOG
857 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
859 if [ $res -ne 0 ]; then
865 __collect_endpoint_stats "A1PMS" 00 "GET" $A1PMS_API_PREFIX"/v2/policy-instances" $status
872 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
873 # args: <response-code> <policy-id> [<template-file>]
874 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
876 # (Function for test scripts)
877 a1pms_api_get_policy() {
881 if [ "$A1PMS_VERSION" == "V2" ]; then
882 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
883 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
886 query="/v2/policies/$UUID$2"
888 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
889 __print_err "<response-code> <policy-id> [<template-file>] " $@
892 query="/policy?id=$UUID$2"
894 res="$(__do_curl_to_api A1PMS GET $query)"
895 status=${res:${#res}-3}
897 if [ $status -ne $1 ]; then
898 __log_test_fail_status_code $1 $status
902 if [ "$A1PMS_VERSION" == "V2" ]; then
903 if [ $# -eq 8 ]; then
905 #Create a policy json to compare with
906 body=${res:0:${#res}-3}
908 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
909 if [ $7 != "NOTRANSIENT" ]; then
910 targetJson=$targetJson", \"transient\":$7"
912 if [ $6 != "NOTYPE" ]; then
913 targetJson=$targetJson", \"policytype_id\":\"$6\""
915 targetJson=$targetJson", \"policytype_id\":\"\""
917 if [ $8 != "NOURL" ]; then
918 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
921 data=$(sed 's/XXX/'${2}'/g' $3)
922 targetJson=$targetJson", \"policy_data\":$data"
923 targetJson="{$targetJson}"
925 echo "TARGET JSON: $targetJson" >> $HTTPLOG
926 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
927 if [ $res -ne 0 ]; then
933 if [ $# -eq 3 ]; then
934 #Create a policy json to compare with
935 body=${res:0:${#res}-3}
937 sed 's/XXX/'${2}'/g' $3 > $file
938 targetJson=$(< $file)
939 echo "TARGET JSON: $targetJson" >> $HTTPLOG
940 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
941 if [ $res -ne 0 ]; then
947 __collect_endpoint_stats "A1PMS" 01 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $status
952 # API Test function: PUT /policy and V2 PUT /policies
953 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
954 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
955 # (Function for test scripts)
956 a1pms_api_put_policy() {
959 if [ "$A1PMS_VERSION" == "V2" ]; then
960 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
961 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
965 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
966 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
979 if [ "$A1PMS_VERSION" == "V2" ]; then
982 if [ $# -eq 9 ]; then
987 if [ $# -eq 8 ]; then
992 while [ $count -lt $max ]; do
993 if [ "$A1PMS_VERSION" == "V2" ]; then
997 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
998 if [ $trans != "NOTRANSIENT" ]; then
999 inputJson=$inputJson", \"transient\":$trans"
1001 if [ $pt != "NOTYPE" ]; then
1002 inputJson=$inputJson", \"policytype_id\":\"$pt\""
1004 inputJson=$inputJson", \"policytype_id\":\"\""
1006 if [ $noti != "NOURL" ]; then
1007 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1009 file="./tmp/.p.json"
1010 data=$(sed 's/XXX/'${pid}'/g' $temp)
1011 inputJson=$inputJson", \"policy_data\":$data"
1012 inputJson="{$inputJson}"
1013 echo $inputJson > $file
1015 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
1017 if [ $pt != "NOTYPE" ]; then
1018 query=$query"&type=$pt"
1021 if [ $trans != NOTRANSIENT ]; then
1022 query=$query"&transient=$trans"
1025 file="./tmp/.p.json"
1026 sed 's/XXX/'${pid}'/g' $temp > $file
1028 res="$(__do_curl_to_api A1PMS PUT $query $file)"
1029 status=${res:${#res}-3}
1030 echo -ne " Executing "$count"("$max")${SAMELINE}"
1031 if [ $status -ne $1 ]; then
1032 echo " Executed "$count"?("$max")"
1033 __log_test_fail_status_code $1 $status
1038 echo -ne " Executed "$count"("$max")${SAMELINE}"
1040 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $status $max
1047 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
1048 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
1049 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
1050 # (Function for test scripts)
1052 a1pms_api_put_policy_batch() {
1055 if [ "$A1PMS_VERSION" == "V2" ]; then
1056 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1057 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
1061 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1062 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
1074 if [ "$A1PMS_VERSION" == "V2" ]; then
1077 if [ $# -eq 9 ]; then
1082 if [ $# -eq 8 ]; then
1088 while [ $count -lt $max ]; do
1089 if [ "$A1PMS_VERSION" == "V2" ]; then
1090 query="/v2/policies"
1092 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1093 if [ $trans != "NOTRANSIENT" ]; then
1094 inputJson=$inputJson", \"transient\":$trans"
1096 if [ $pt != "NOTYPE" ]; then
1097 inputJson=$inputJson", \"policytype_id\":\"$pt\""
1099 inputJson=$inputJson", \"policytype_id\":\"\""
1101 if [ $noti != "NOURL" ]; then
1102 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1104 file="./tmp/.p.json"
1105 data=$(sed 's/XXX/'${pid}'/g' $temp)
1106 inputJson=$inputJson", \"policy_data\":$data"
1107 inputJson="{$inputJson}"
1108 echo $inputJson > $file
1110 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
1112 if [ $pt != "NOTYPE" ]; then
1113 query=$query"&type=$pt"
1116 if [ $trans != NOTRANSIENT ]; then
1117 query=$query"&transient=$trans"
1119 file="./tmp/.p.json"
1120 sed 's/XXX/'${pid}'/g' $temp > $file
1122 res="$(__do_curl_to_api A1PMS PUT_BATCH $query $file)"
1123 status=${res:${#res}-3}
1124 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1126 if [ $status -ne 200 ]; then
1127 echo " Requested(batch) "$count"?("$max")"
1128 __log_test_fail_status_code 200 $status
1131 cid=${res:0:${#res}-3}
1135 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1142 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1143 status=${res:${#res}-3}
1144 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
1146 if [ $status -ne $1 ]; then
1147 echo " Accepted(batch) "$count"?("$max")"
1148 __log_test_fail_status_code $1 $status
1153 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
1155 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $1 $max
1163 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
1164 # 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>
1165 # 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>
1166 # (Function for test scripts)
1167 a1pms_api_put_policy_parallel() {
1170 if [ "$A1PMS_VERSION" == "V2" ]; then
1171 if [ $# -ne 11 ]; then
1172 __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>" $@
1176 if [ $# -ne 10 ]; then
1177 __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>" $@
1181 resp_code=$1; shift;
1187 transient=$1; shift;
1188 if [ "$A1PMS_VERSION" == "V2" ]; then
1197 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1198 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1199 echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1200 echo " Info - will execute over a1pms REST"
1202 if [ "$A1PMS_VERSION" == "V2" ]; then
1203 if [ $serv == "NOSERVICE" ]; then
1206 query="$A1PMS_API_PREFIX/v2/policies"
1208 if [ $serv == "NOSERVICE" ]; then
1211 query="/policy?service=$serv"
1213 if [ $type != "NOTYPE" ]; then
1214 query=$query"&type=$type"
1217 if [ $transient != NOTRANSIENT ]; then
1218 query=$query"&transient=$transient"
1222 urlbase=${A1PMS_ADAPTER}${query}
1225 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1226 httpproxy=$KUBE_PROXY_PATH
1229 for ((i=1; i<=$pids; i++))
1232 if [ -z "$uuid" ]; then
1235 echo "" > "./tmp/.pid${i}.res.txt"
1236 if [ "$A1PMS_VERSION" == "V2" ]; then
1237 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1239 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1242 done | xargs -n 1 -I{} -P $pids bash -c '{
1244 echo " Parallel process $arg started"
1245 tmp=$(< "./tmp/.pid${arg}.txt")
1246 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1249 for ((i=1; i<=$pids; i++))
1251 file="./tmp/.pid${i}.res.txt"
1253 if [ -z "$tmp" ]; then
1254 echo " Process $i : unknown result (result file empty"
1258 if [ $res == "0" ]; then
1259 echo " Process $i : OK - "${tmp:1}
1261 echo " Process $i : failed - "${tmp:1}
1266 if [ -z $msg ]; then
1267 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $resp_code $(($count*$num_rics))
1268 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1272 __log_test_fail_general "One of more processes failed to execute"
1276 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
1277 # args: <response-code> <policy-id> [count]
1278 # (Function for test scripts)
1279 a1pms_api_delete_policy() {
1282 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1283 __print_err "<response-code> <policy-id> [count]" $@
1290 if [ $# -eq 3 ]; then
1296 while [ $count -lt $max ]; do
1297 if [ "$A1PMS_VERSION" == "V2" ]; then
1298 query="/v2/policies/"$UUID$pid
1300 query="/policy?id="$UUID$pid
1302 res="$(__do_curl_to_api A1PMS DELETE $query)"
1303 status=${res:${#res}-3}
1304 echo -ne " Executing "$count"("$max")${SAMELINE}"
1306 if [ $status -ne $1 ]; then
1307 echo " Executed "$count"?("$max")"
1308 __log_test_fail_status_code $1 $status
1314 echo -ne " Executed "$count"("$max")${SAMELINE}"
1316 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $status $max
1323 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
1324 # args: <response-code> <policy-id> [count]
1325 # (Function for test scripts)
1326 a1pms_api_delete_policy_batch() {
1329 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1330 __print_err "<response-code> <policy-id> [count]" $@
1337 if [ $# -eq 3 ]; then
1343 while [ $count -lt $max ]; do
1344 if [ "$A1PMS_VERSION" == "V2" ]; then
1345 query="/v2/policies/"$UUID$pid
1347 query="/policy?id="$UUID$pid
1349 res="$(__do_curl_to_api A1PMS DELETE_BATCH $query)"
1350 status=${res:${#res}-3}
1351 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1353 if [ $status -ne 200 ]; then
1354 echo " Requested(batch) "$count"?("$max")"
1355 __log_test_fail_status_code 200 $status
1358 cid=${res:0:${#res}-3}
1362 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1370 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1371 status=${res:${#res}-3}
1372 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1374 if [ $status -ne $1 ]; then
1375 echo " Deleted(batch) "$count"?("$max")"
1376 __log_test_fail_status_code $1 $status
1381 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1383 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $1 $max
1391 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1392 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1393 # (Function for test scripts)
1394 a1pms_api_delete_policy_parallel() {
1397 if [ $# -ne 5 ]; then
1398 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1401 resp_code=$1; shift;
1407 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1408 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1409 echo " Info - a1pms_api_delete_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1410 echo " Info - will execute over a1pms REST"
1413 if [ "$A1PMS_VERSION" == "V2" ]; then
1414 query="$A1PMS_API_PREFIX/v2/policies/"
1419 urlbase=${A1PMS_ADAPTER}${query}
1422 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1423 httpproxy=$KUBE_PROXY_PATH
1426 for ((i=1; i<=$pids; i++))
1429 if [ -z "$uuid" ]; then
1432 echo "" > "./tmp/.pid${i}.del.res.txt"
1433 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
1435 done | xargs -n 1 -I{} -P $pids bash -c '{
1437 echo " Parallel process $arg started"
1438 tmp=$(< "./tmp/.pid${arg}.del.txt")
1439 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1442 for ((i=1; i<=$pids; i++))
1444 file="./tmp/.pid${i}.del.res.txt"
1446 if [ -z "$tmp" ]; then
1447 echo " Process $i : unknown result (result file empty"
1451 if [ $res == "0" ]; then
1452 echo " Process $i : OK - "${tmp:1}
1454 echo " Process $i : failed - "${tmp:1}
1459 if [ -z $msg ]; then
1460 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count*$num_rics))
1461 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1465 __log_test_fail_general "One of more processes failed to execute"
1469 # API Test function: GET /policy_ids and V2 GET /v2/policies
1470 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1471 # (Function for test scripts)
1472 a1pms_api_get_policy_ids() {
1475 if [ $# -lt 4 ]; then
1476 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1482 if [ "$A1PMS_VERSION" == "V2" ]; then
1483 if [ $2 != "NORIC" ]; then
1484 queryparams="?ric_id="$2
1487 if [ $3 != "NOSERVICE" ]; then
1488 if [ -z $queryparams ]; then
1489 queryparams="?service_id="$3
1491 queryparams=$queryparams"&service_id="$3
1494 if [ $4 != "NOTYPE" ]; then
1495 if [ -z $queryparams ]; then
1496 queryparams="?policytype_id="$4
1498 queryparams=$queryparams"&policytype_id="$4
1502 query="/v2/policies"$queryparams
1504 if [ $2 != "NORIC" ]; then
1505 queryparams="?ric="$2
1508 if [ $3 != "NOSERVICE" ]; then
1509 if [ -z $queryparams ]; then
1510 queryparams="?service="$3
1512 queryparams=$queryparams"&service="$3
1515 if [ $4 != "NOTYPE" ]; then
1516 if [ -z $queryparams ]; then
1517 queryparams="?type="$4
1519 queryparams=$queryparams"&type="$4
1523 query="/policy_ids"$queryparams
1526 res="$(__do_curl_to_api A1PMS GET $query)"
1527 status=${res:${#res}-3}
1529 if [ $status -ne $1 ]; then
1530 __log_test_fail_status_code $1 $status
1534 if [ $# -gt 4 ]; then
1535 body=${res:0:${#res}-3}
1538 for pid in ${@:5} ; do
1539 if [ "$targetJson" != "[" ]; then
1540 targetJson=$targetJson","
1542 if [ $pid != "NOID" ]; then
1543 targetJson=$targetJson"\"$UUID$pid\""
1547 targetJson=$targetJson"]"
1548 if [ "$A1PMS_VERSION" == "V2" ]; then
1549 targetJson="{\"policy_ids\": $targetJson}"
1551 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1552 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1554 if [ $res -ne 0 ]; then
1555 __log_test_fail_body
1560 __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v2/policies" $status
1565 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
1566 # args(V2): <response-code> <policy-type-id> [<schema-file>]
1567 # (Function for test scripts)
1568 a1pms_api_get_policy_type() {
1571 if [ "$A1PMS_VERSION" != "V2" ]; then
1572 __log_test_fail_not_supported
1576 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1577 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1580 query="/v2/policy-types/$2"
1582 res="$(__do_curl_to_api A1PMS GET $query)"
1583 status=${res:${#res}-3}
1585 if [ $status -ne $1 ]; then
1586 __log_test_fail_status_code $1 $status
1590 if [ $# -eq 3 ]; then
1592 body=${res:0:${#res}-3}
1595 targetJson="{\"policy_schema\":$targetJson}"
1596 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1597 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1599 if [ $res -ne 0 ]; then
1600 __log_test_fail_body
1605 __collect_endpoint_stats "A1PMS" 05 "GET" $A1PMS_API_PREFIX"/v2/policy-types/{policyTypeId}" $status
1610 # API Test function: GET /policy_schema
1611 # args: <response-code> <policy-type-id> [<schema-file>]
1612 # (Function for test scripts)
1613 a1pms_api_get_policy_schema() {
1616 if [ "$A1PMS_VERSION" == "V2" ]; then
1617 __log_test_fail_not_supported
1621 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1622 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1625 query="/policy_schema?id=$2"
1626 res="$(__do_curl_to_api A1PMS GET $query)"
1627 status=${res:${#res}-3}
1629 if [ $status -ne $1 ]; then
1630 __log_test_fail_status_code $1 $status
1634 if [ $# -eq 3 ]; then
1636 body=${res:0:${#res}-3}
1640 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1641 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1643 if [ $res -ne 0 ]; then
1644 __log_test_fail_body
1649 __collect_endpoint_stats "A1PMS" 06 "GET" $A1PMS_API_PREFIX"/v2/policy_schema" $status
1654 # API Test function: GET /policy_schemas
1655 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
1656 # args(V2): <response-code>
1657 # (Function for test scripts)
1658 a1pms_api_get_policy_schemas() {
1661 if [ "$A1PMS_VERSION" == "V2" ]; then
1662 if [ $# -ne 1 ]; then
1663 __print_err "<response-code>" $@
1667 if [ $# -lt 2 ]; then
1668 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1672 if [ "$A1PMS_VERSION" == "V2" ]; then
1673 query="/v2/policy-schemas"
1675 query="/policy_schemas"
1676 if [ $2 != "NORIC" ]; then
1677 query=$query"?ric="$2
1681 res="$(__do_curl_to_api A1PMS GET $query)"
1682 status=${res:${#res}-3}
1684 if [ $status -ne $1 ]; then
1685 __log_test_fail_status_code $1 $status
1689 if [ $# -gt 2 ]; then
1690 body=${res:0:${#res}-3}
1693 for file in ${@:3} ; do
1694 if [ "$targetJson" != "[" ]; then
1695 targetJson=$targetJson","
1697 if [ $file == "NOFILE" ]; then
1698 targetJson=$targetJson"{}"
1700 targetJson=$targetJson$(< $file)
1704 targetJson=$targetJson"]"
1705 if [ "$A1PMS_VERSION" == "V2" ]; then
1706 targetJson="{\"policy_schemas\": $targetJson }"
1708 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1709 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1711 if [ $res -ne 0 ]; then
1712 __log_test_fail_body
1717 __collect_endpoint_stats "A1PMS" 07 "GET" $A1PMS_API_PREFIX"/v2/policy-schemas" $status
1722 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1723 # arg: <response-code> <policy-id> [ (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>) ]
1724 # (Function for test scripts)
1725 a1pms_api_get_policy_status() {
1728 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
1729 __print_err "<response-code> <policy-id> [(STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)]" $@
1734 if [ $# -eq 2 ]; then
1736 elif [ "$3" == "STD" ]; then
1737 targetJson="{\"enforceStatus\":\"$4\""
1738 if [ $# -eq 5 ]; then
1739 targetJson=$targetJson",\"reason\":\"$5\""
1741 targetJson=$targetJson"}"
1742 elif [ "$3" == "STD2" ]; then
1743 if [ $4 == "EMPTY" ]; then
1744 targetJson="{\"enforceStatus\":\"\""
1746 targetJson="{\"enforceStatus\":\"$4\""
1748 if [ $# -eq 5 ]; then
1749 if [ $5 == "EMPTY" ]; then
1750 targetJson=$targetJson",\"enforceReason\":\"\""
1752 targetJson=$targetJson",\"enforceReason\":\"$5\""
1755 targetJson=$targetJson"}"
1756 elif [ "$3" == "OSC" ]; then
1757 targetJson="{\"instance_status\":\"$4\""
1758 if [ $# -eq 5 ]; then
1759 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1761 targetJson=$targetJson",\"created_at\":\"????\"}"
1763 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1767 if [ "$A1PMS_VERSION" == "V2" ]; then
1768 query="/v2/policies/$UUID$2/status"
1769 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1771 query="/policy_status?id="$UUID$2
1774 res="$(__do_curl_to_api A1PMS GET $query)"
1775 status=${res:${#res}-3}
1777 if [ $status -ne $1 ]; then
1778 __log_test_fail_status_code $1 $status
1781 if [ $# -gt 2 ]; then
1782 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1783 body=${res:0:${#res}-3}
1784 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1786 if [ $res -ne 0 ]; then
1787 __log_test_fail_body
1791 __collect_endpoint_stats "A1PMS" 08 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}/status" $status
1796 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1797 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1798 # (Function for test scripts)
1799 a1pms_api_get_policy_types() {
1802 if [ $# -lt 1 ]; then
1803 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1807 if [ "$A1PMS_VERSION" == "V2" ]; then
1808 if [ $# -eq 1 ]; then
1809 query="/v2/policy-types"
1810 elif [ $2 == "NORIC" ]; then
1811 query="/v2/policy-types"
1813 query="/v2/policy-types?ric_id=$2"
1816 if [ $# -eq 1 ]; then
1817 query="/policy_types"
1818 elif [ $2 == "NORIC" ]; then
1819 query="/policy_types"
1821 query="/policy_types?ric=$2"
1825 res="$(__do_curl_to_api A1PMS GET $query)"
1826 status=${res:${#res}-3}
1828 if [ $status -ne $1 ]; then
1829 __log_test_fail_status_code $1 $status
1833 if [ $# -gt 2 ]; then
1834 body=${res:0:${#res}-3}
1837 for pid in ${@:3} ; do
1838 if [ "$targetJson" != "[" ]; then
1839 targetJson=$targetJson","
1841 if [ $pid == "EMPTY" ]; then
1844 targetJson=$targetJson"\"$pid\""
1847 targetJson=$targetJson"]"
1848 if [ "$A1PMS_VERSION" == "V2" ]; then
1849 targetJson="{\"policytype_ids\": $targetJson }"
1851 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1852 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1854 if [ $res -ne 0 ]; then
1855 __log_test_fail_body
1860 __collect_endpoint_stats "A1PMS" 09 "GET" $A1PMS_API_PREFIX"/v2/policy-types" $status
1865 #########################################################
1866 #### Test case functions Health check
1867 #########################################################
1869 # API Test function: GET /status and V2 GET /status
1870 # args: <response-code>
1871 # (Function for test scripts)
1872 a1pms_api_get_status() {
1874 if [ $# -ne 1 ]; then
1875 __print_err "<response-code>" $@
1878 if [ "$A1PMS_VERSION" == "V2" ]; then
1883 res="$(__do_curl_to_api A1PMS GET $query)"
1884 status=${res:${#res}-3}
1886 if [ $status -ne $1 ]; then
1887 __log_test_fail_status_code $1 $status
1891 __collect_endpoint_stats "A1PMS" 10 "GET" $A1PMS_API_PREFIX"/v2/status" $status
1896 # API Test function: GET /status (root) without api prefix
1897 # args: <response-code>
1898 # (Function for test scripts)
1899 a1pms_api_get_status_root() {
1901 if [ $# -ne 1 ]; then
1902 __print_err "<response-code>" $@
1906 TMP_PREFIX=$A1PMS_API_PREFIX
1908 res="$(__do_curl_to_api A1PMS GET $query)"
1909 A1PMS_API_PREFIX=$TMP_PREFIX
1910 status=${res:${#res}-3}
1912 if [ $status -ne $1 ]; then
1913 __log_test_fail_status_code $1 $status
1917 __collect_endpoint_stats "A1PMS" 19 "GET" "/status" $status
1922 #########################################################
1923 #### Test case functions RIC Repository
1924 #########################################################
1926 # API Test function: GET /ric and V2 GET /v2/rics/ric
1927 # args: <reponse-code> <management-element-id> [<ric-id>]
1928 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1929 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1930 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1933 # (Function for test scripts)
1934 a1pms_api_get_ric() {
1937 if [ "$A1PMS_VERSION" == "V2" ]; then
1938 if [ $# -lt 3 ]; then
1939 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1943 if [ $2 != "NOME" ]; then
1944 search="?managed_element_id="$2
1946 if [ $3 != "NORIC" ]; then
1947 if [ -z $search ]; then
1950 search=$search"&ric_id="$3
1953 query="/v2/rics/ric"$search
1955 res="$(__do_curl_to_api A1PMS GET $query)"
1956 status=${res:${#res}-3}
1958 if [ $status -ne $1 ]; then
1959 __log_test_fail_status_code $1 $status
1963 if [ $# -gt 3 ]; then
1964 body=${res:0:${#res}-3}
1965 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1966 if [ $res -ne 0 ]; then
1967 __log_test_fail_general "Could not create target ric info json"
1971 targetJson=$(<./tmp/.tmp_rics.json)
1972 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1973 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1974 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1975 if [ $res -ne 0 ]; then
1976 __log_test_fail_body
1981 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1982 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1986 query="/ric?managedElementId="$2
1988 res="$(__do_curl_to_api A1PMS GET $query)"
1989 status=${res:${#res}-3}
1991 if [ $status -ne $1 ]; then
1992 __log_test_fail_status_code $1 $status
1996 if [ $# -eq 3 ]; then
1997 body=${res:0:${#res}-3}
1998 if [ "$body" != "$3" ]; then
1999 __log_test_fail_body
2005 __collect_endpoint_stats "A1PMS" 11 "GET" $A1PMS_API_PREFIX"/v2/rics/ric" $status
2010 # API test function: GET /rics and V2 GET /v2/rics
2011 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
2012 # 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_........."
2013 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
2014 # (Function for test scripts)
2015 a1pms_api_get_rics() {
2018 if [ $# -lt 2 ]; then
2019 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
2023 if [ "$A1PMS_VERSION" == "V2" ]; then
2025 if [ $2 != "NOTYPE" ]; then
2026 query="/v2/rics?policytype_id="$2
2030 if [ $2 != "NOTYPE" ]; then
2031 query="/rics?policyType="$2
2035 res="$(__do_curl_to_api A1PMS GET $query)"
2036 status=${res:${#res}-3}
2038 if [ $status -ne $1 ]; then
2039 __log_test_fail_status_code $1 $status
2043 if [ $# -gt 2 ]; then
2044 body=${res:0:${#res}-3}
2045 if [ "$A1PMS_VERSION" == "V2" ]; then
2046 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
2048 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
2050 if [ $res -ne 0 ]; then
2051 __log_test_fail_general "Could not create target ric info json"
2055 targetJson=$(<./tmp/.tmp_rics.json)
2056 if [ "$A1PMS_VERSION" == "V2" ]; then
2057 targetJson="{\"rics\": $targetJson }"
2059 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2060 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2061 if [ $res -ne 0 ]; then
2062 __log_test_fail_body
2067 __collect_endpoint_stats "A1PMS" 12 "GET" $A1PMS_API_PREFIX"/v2/rics" $status
2072 ##################################################################
2073 #### API Test case functions Service registry and supervision ####
2074 ##################################################################
2076 # API test function: PUT /service and V2 PUT /service
2077 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
2078 # (Function for test scripts)
2079 a1pms_api_put_service() {
2081 if [ $# -ne 4 ]; then
2082 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
2086 if [ "$A1PMS_VERSION" == "V2" ]; then
2087 query="/v2/services"
2088 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
2091 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
2093 file="./tmp/.tmp.json"
2094 echo "$json" > $file
2096 res="$(__do_curl_to_api A1PMS PUT $query $file)"
2097 status=${res:${#res}-3}
2099 if [ $status -ne $1 ]; then
2100 __log_test_fail_status_code $1 $status
2104 __collect_endpoint_stats "A1PMS" 13 "PUT" $A1PMS_API_PREFIX"/v2/service" $status
2109 # API test function: GET /services and V2 GET /v2/services
2110 #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>]* )]
2111 # (Function for test scripts)
2112 a1pms_api_get_services() {
2114 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
2116 if [ $# -eq 1 ]; then
2118 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
2120 elif [ $# -eq 5 ]; then
2122 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
2124 if [ $(($argLen%3)) -eq 0 ]; then
2129 if [ $paramError -ne 0 ]; then
2130 __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>]* )]" $@
2134 if [ "$A1PMS_VERSION" == "V2" ]; then
2135 query="/v2/services"
2137 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2138 query="/v2/services?service_id="$2
2143 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2144 query="/services?name="$2
2147 res="$(__do_curl_to_api A1PMS GET $query)"
2148 status=${res:${#res}-3}
2150 if [ $status -ne $1 ]; then
2151 __log_test_fail_status_code $1 $status
2155 if [ $# -gt 2 ]; then
2156 variableArgCount=$(($#-2))
2157 body=${res:0:${#res}-3}
2161 while [ $cntr -lt $variableArgCount ]; do
2162 servicename=$1; shift;
2165 if [ $cntr -gt 0 ]; then
2166 targetJson=$targetJson","
2168 # timeSinceLastActivitySeconds value cannot be checked since value varies
2169 if [ "$A1PMS_VERSION" == "V2" ]; then
2170 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
2172 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2176 targetJson=$targetJson"]"
2177 if [ "$A1PMS_VERSION" == "V2" ]; then
2178 targetJson="{\"service_list\": $targetJson }"
2180 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2181 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2182 if [ $res -ne 0 ]; then
2183 __log_test_fail_body
2188 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX"/v2/services" $status
2193 # API test function: GET /services V2 GET /v2/services - (only checking service names)
2194 # args: <response-code> [<service-name>]*"
2195 # (Function for test scripts)
2196 a1pms_api_get_service_ids() {
2199 if [ $# -lt 1 ]; then
2200 __print_err "<response-code> [<service-name>]*" $@
2204 if [ "$A1PMS_VERSION" == "V2" ]; then
2205 query="/v2/services"
2209 res="$(__do_curl_to_api A1PMS GET $query)"
2210 status=${res:${#res}-3}
2212 if [ $status -ne $1 ]; then
2213 __log_test_fail_status_code $1 $status
2217 body=${res:0:${#res}-3}
2219 for rapp in ${@:2} ; do
2220 if [ "$targetJson" != "[" ]; then
2221 targetJson=$targetJson","
2223 if [ "$A1PMS_VERSION" == "V2" ]; then
2224 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2226 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2230 targetJson=$targetJson"]"
2231 if [ "$A1PMS_VERSION" == "V2" ]; then
2232 targetJson="{\"service_list\": $targetJson }"
2234 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2235 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2237 if [ $res -ne 0 ]; then
2238 __log_test_fail_body
2242 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX"/v2/services" $status
2247 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
2248 # args: <response-code> <service-name>
2249 # (Function for test scripts)
2250 a1pms_api_delete_services() {
2253 if [ $# -ne 2 ]; then
2254 __print_err "<response-code> <service-name>" $@
2257 if [ "$A1PMS_VERSION" == "V2" ]; then
2258 query="/v2/services/"$2
2260 query="/services?name="$2
2262 res="$(__do_curl_to_api A1PMS DELETE $query)"
2263 status=${res:${#res}-3}
2265 if [ $status -ne $1 ]; then
2266 __log_test_fail_status_code $1 $status
2270 __collect_endpoint_stats "A1PMS" 15 "DELETE" $A1PMS_API_PREFIX"/v2/services/{serviceId}" $status
2275 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
2276 # args: <response-code> <service-name>
2277 # (Function for test scripts)
2278 a1pms_api_put_services_keepalive() {
2281 if [ $# -ne 2 ]; then
2282 __print_err "<response-code> <service-name>" $@
2285 if [ "$A1PMS_VERSION" == "V2" ]; then
2286 query="/v2/services/$2/keepalive"
2288 query="/services/keepalive?name="$2
2291 res="$(__do_curl_to_api A1PMS PUT $query)"
2292 status=${res:${#res}-3}
2294 if [ $status -ne $1 ]; then
2295 __log_test_fail_status_code $1 $status
2299 __collect_endpoint_stats "A1PMS" 16 "PUT" $A1PMS_API_PREFIX"/v2/services/{service_id}/keepalive" $status
2304 ##################################################################
2305 #### API Test case functions Configuration ####
2306 ##################################################################
2308 # API Test function: PUT /v2/configuration
2309 # args: <response-code> <config-file>
2310 # (Function for test scripts)
2311 a1pms_api_put_configuration() {
2314 if [ "$A1PMS_VERSION" != "V2" ]; then
2315 __log_test_fail_not_supported
2319 if [ $# -ne 2 ]; then
2320 __print_err "<response-code> <config-file>" $@
2323 if [ ! -f $2 ]; then
2324 __log_test_fail_general "Config file "$2", does not exist"
2328 # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
2329 # inputJson="{\"config\":"$inputJson"}"
2331 file="./tmp/.config.json"
2332 echo $inputJson > $file
2333 query="/v2/configuration"
2334 res="$(__do_curl_to_api A1PMS PUT $query $file)"
2335 status=${res:${#res}-3}
2337 if [ $status -ne $1 ]; then
2338 __log_test_fail_status_code $1 $status
2342 __collect_endpoint_stats "A1PMS" 17 "PUT" $A1PMS_API_PREFIX"/v2/configuration" $status
2347 # API Test function: GET /v2/configuration
2348 # args: <response-code> [<config-file>]
2349 # (Function for test scripts)
2350 a1pms_api_get_configuration() {
2353 if [ "$A1PMS_VERSION" != "V2" ]; then
2354 __log_test_fail_not_supported
2358 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2359 __print_err "<response-code> [<config-file>]" $@
2362 if [ ! -f $2 ]; then
2363 __log_test_fail_general "Config file "$2" for comparison, does not exist"
2367 query="/v2/configuration"
2368 res="$(__do_curl_to_api A1PMS GET $query)"
2369 status=${res:${#res}-3}
2371 if [ $status -ne $1 ]; then
2372 __log_test_fail_status_code $1 $status
2376 if [ $# -eq 2 ]; then
2378 body=${res:0:${#res}-3}
2381 # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
2382 # inputJson="{\"config\":"$inputJson"}"
2384 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2385 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2387 if [ $res -ne 0 ]; then
2388 __log_test_fail_body
2393 __collect_endpoint_stats "A1PMS" 18 "GET" $A1PMS_API_PREFIX"/v2/configuration" $status
2398 ##########################################
2399 #### Reset types and instances ####
2400 ##########################################
2402 # Admin reset to remove all policies and services
2403 # All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2404 # NOTE - only works in kubernetes and the pod should not be running
2406 # (Function for test scripts)
2408 a1pms_kube_pvc_reset() {
2411 pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
2412 if [ -z "$pvc_name" ]; then
2413 pvc_name=policymanagementservice-vardata-pvc
2415 echo " Trying to reset pvc: "$pvc_name
2416 __kube_clean_pvc $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $A1PMS_CONTAINER_MNT_DIR
2422 # args: <realm> <client-name> <client-secret>
2423 a1pms_configure_sec() {
2424 export A1PMS_CREDS_GRANT_TYPE="client_credentials"
2425 export A1PMS_CREDS_CLIENT_SECRET=$3
2426 export A1PMS_CREDS_CLIENT_ID=$2
2427 export A1PMS_AUTH_SERVICE_URL=$KEYCLOAK_SERVICE_PATH$KEYCLOAK_TOKEN_URL_PREFIX/$1/protocol/openid-connect/token
2428 export A1PMS_SIDECAR_MOUNT="/token-cache"
2429 export A1PMS_SIDECAR_JWT_FILE=$A1PMS_SIDECAR_MOUNT"/jwt.txt"
2431 export AUTHSIDECAR_APP_NAME
2432 export AUTHSIDECAR_DISPLAY_NAME