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 oranrics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "label=orana1sim" --filter "status=running" --format {{.Names}})
549 rics="$rics $oranrics"
551 if [ $? -ne 0 ] || [ -z "$rics" ]; then
552 echo -e $RED" FAIL - the names of the running RIC Simulator or ORAN RIC cannot be retrieved." $ERED
559 if [ $cntr -gt 0 ]; then
560 config_json=$config_json"\n ,"
562 config_json=$config_json"\n {"
563 if [ $RUNMODE == "KUBE" ]; then
564 ric_id=${ric%.*.*} #extract pod id from full hosthame
565 ric_id=$(echo "$ric_id" | tr '-' '_')
567 ric_id=$(echo "$ric" | tr '-' '_') #ric var still needs underscore as it is different from the container name
569 echo " Found a1 sim: "$ric
570 config_json=$config_json"\n \"name\": \"$ric_id\","
573 for xric in $oranrics; do
574 if [ $xric == $ric ]; then
578 if [ $xricfound -eq 0 ]; then
579 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
581 config_json=$config_json"\n \"baseUrl\": \"$RICMEDIATOR_SIM_HTTPX://$ric:$RICMEDIATOR_SIM_PORT\","
583 if [ ! -z "$3" ]; then
584 if [[ $ric == "$3"* ]]; then
585 config_json=$config_json"\n \"customAdapterClass\": \"$4\","
588 if [ $1 == "SDNC" ]; then
589 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
591 config_json=$config_json"\n \"managedElementIds\": ["
592 config_json=$config_json"\n \"me1_$ric_id\","
593 config_json=$config_json"\n \"me2_$ric_id\""
594 config_json=$config_json"\n ]"
595 config_json=$config_json"\n }"
599 config_json=$config_json"\n ]"
600 config_json=$config_json"\n}"
602 config_json="{\"config\":"$config_json"}"
604 printf "$config_json">$2
609 # Load the the appl config for the a1pms into a config map
610 a1pms_load_config() {
611 echo -e $BOLD"A1PMS - load config from "$EBOLD$1
612 data_json=$PWD/tmp/$A1PMS_DATA_FILE
614 output_yaml=$PWD/tmp/a1pms-cfd.yaml
615 __kube_create_configmap $A1PMS_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $data_json $output_yaml
620 # Turn on debug level tracing in the a1pms
622 # (Function for test scripts)
624 echo -e $BOLD"Setting a1pms debug logging"$EBOLD
625 curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
626 result=$(__do_curl "$curlString")
627 if [ $? -ne 0 ]; then
628 __print_err "could not set debug mode" $@
636 # Turn on trace level tracing in the a1pms
638 # (Function for test scripts)
640 echo -e $BOLD"Setting a1pms trace logging"$EBOLD
641 curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
642 result=$(__do_curl "$curlString")
643 if [ $? -ne 0 ]; then
644 __print_err "could not set trace mode" $@
652 # Perform curl retries when making direct call to the a1pms for the specified http response codes
653 # Speace separated list of http response codes
654 # args: [<response-code>]*
655 use_a1pms_retries() {
656 echo -e $BOLD"Do curl retries to the a1pms REST inteface for these response codes:$@"$EBOLD
662 # Check the a1pms logs for WARNINGs and ERRORs
664 # (Function for test scripts)
666 __check_container_logs "A1PMS" $A1PMS_APP_NAME $A1PMS_LOGPATH WARN ERR
669 #########################################################
670 #### Test case functions A1 Policy management service
671 #########################################################
673 # This function compare the size, towards a target value, of a json array returned from <url> of the A1PMS.
674 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
675 # args: json:<url> <target-value> [<timeout-in-seconds]
676 # (Function for test scripts)
678 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
679 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
680 if [[ $1 == "json:"* ]]; then
681 if [ "$A1PMS_VERSION" == "V2" ]; then
682 __var_test "A1PMS" $A1PMS_SERVICE_PATH$A1PMS_API_PREFIX"/v2/" $1 "=" $2 $3
684 __var_test "A1PMS" $A1PMS_SERVICE_PATH"/" $1 "=" $2 $3
689 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
693 # API Test function: GET /policies and V2 GET /v2/policy-instances
694 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <template-file>]*]
695 # args(V2): <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <transient> <notification-url> <template-file>]*]
696 # (Function for test scripts)
697 a1pms_api_get_policies() {
700 if [ "$A1PMS_VERSION" == "V2" ]; then
702 variableParams=$(($#-4))
703 if [ $# -lt 4 ]; then
705 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
707 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
711 if [ $paramError -ne 0 ]; then
712 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <transient> <notification-url> <template-file>]*]" $@
717 variableParams=$(($#-4))
718 if [ $# -lt 4 ]; then
720 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
722 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
726 if [ $paramError -ne 0 ]; then
727 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <template-file>]*]" $@
733 if [ "$A1PMS_VERSION" == "V2" ]; then
734 if [ $2 != "NORIC" ]; then
735 queryparams="?ric_id="$2
737 if [ $3 != "NOSERVICE" ]; then
738 if [ -z $queryparams ]; then
739 queryparams="?service_id="$3
741 queryparams=$queryparams"&service_id="$3
744 if [ $4 != "NOTYPE" ]; then
745 if [ -z $queryparams ]; then
746 queryparams="?policytype_id="$4
748 queryparams=$queryparams"&policytype_id="$4
752 query="/v2/policy-instances"$queryparams
753 res="$(__do_curl_to_api A1PMS GET $query)"
754 status=${res:${#res}-3}
756 if [ $status -ne $1 ]; then
757 __log_test_fail_status_code $1 $status
761 if [ $# -gt 4 ]; then
762 body=${res:0:${#res}-3}
763 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
769 for ((i=0; i<$(($#-4)); i=i+7)); do
771 if [ "$targetJson" != "[" ]; then
772 targetJson=$targetJson","
774 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
775 if [ "${arr[$i+3]}" == "EMPTY" ]; then
776 targetJson=$targetJson"\"\","
778 targetJson=$targetJson"\"${arr[$i+3]}\","
780 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
782 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
784 targetJson=$targetJson"\"policy_data\":"$json"}"
788 targetJson=$targetJson"]"
789 targetJson="{\"policies\": $targetJson}"
790 echo "TARGET JSON: $targetJson" >> $HTTPLOG
791 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
793 if [ $res -ne 0 ]; then
799 if [ $2 != "NORIC" ]; then
800 queryparams="?ric="$2
802 if [ $3 != "NOSERVICE" ]; then
803 if [ -z $queryparams ]; then
804 queryparams="?service="$3
806 queryparams=$queryparams"&service="$3
809 if [ $4 != "NOTYPE" ]; then
810 if [ -z $queryparams ]; then
811 queryparams="?type="$4
813 queryparams=$queryparams"&type="$4
817 query="/policies"$queryparams
818 res="$(__do_curl_to_api A1PMS GET $query)"
819 status=${res:${#res}-3}
821 if [ $status -ne $1 ]; then
822 __log_test_fail_status_code $1 $status
826 if [ $# -gt 4 ]; then
827 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
830 body=${res:0:${#res}-3}
834 for ((i=0; i<$(($#-4)); i=i+5)); do
836 if [ "$targetJson" != "[" ]; then
837 targetJson=$targetJson","
839 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
840 if [ "${arr[$i+3]}" == "EMPTY" ]; then
841 targetJson=$targetJson"\"\","
843 targetJson=$targetJson"\"${arr[$i+3]}\","
846 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
848 targetJson=$targetJson"\"json\":"$json"}"
852 targetJson=$targetJson"]"
853 echo "TARGET JSON: $targetJson" >> $HTTPLOG
854 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
856 if [ $res -ne 0 ]; then
862 __collect_endpoint_stats "A1PMS" 00 "GET" $A1PMS_API_PREFIX"/v2/policy-instances" $status
869 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
870 # args: <response-code> <policy-id> [<template-file>]
871 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
873 # (Function for test scripts)
874 a1pms_api_get_policy() {
878 if [ "$A1PMS_VERSION" == "V2" ]; then
879 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
880 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
883 query="/v2/policies/$UUID$2"
885 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
886 __print_err "<response-code> <policy-id> [<template-file>] " $@
889 query="/policy?id=$UUID$2"
891 res="$(__do_curl_to_api A1PMS GET $query)"
892 status=${res:${#res}-3}
894 if [ $status -ne $1 ]; then
895 __log_test_fail_status_code $1 $status
899 if [ "$A1PMS_VERSION" == "V2" ]; then
900 if [ $# -eq 8 ]; then
902 #Create a policy json to compare with
903 body=${res:0:${#res}-3}
905 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
906 if [ $7 != "NOTRANSIENT" ]; then
907 targetJson=$targetJson", \"transient\":$7"
909 if [ $6 != "NOTYPE" ]; then
910 targetJson=$targetJson", \"policytype_id\":\"$6\""
912 targetJson=$targetJson", \"policytype_id\":\"\""
914 if [ $8 != "NOURL" ]; then
915 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
918 data=$(sed 's/XXX/'${2}'/g' $3)
919 targetJson=$targetJson", \"policy_data\":$data"
920 targetJson="{$targetJson}"
922 echo "TARGET JSON: $targetJson" >> $HTTPLOG
923 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
924 if [ $res -ne 0 ]; then
930 if [ $# -eq 3 ]; then
931 #Create a policy json to compare with
932 body=${res:0:${#res}-3}
934 sed 's/XXX/'${2}'/g' $3 > $file
935 targetJson=$(< $file)
936 echo "TARGET JSON: $targetJson" >> $HTTPLOG
937 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
938 if [ $res -ne 0 ]; then
944 __collect_endpoint_stats "A1PMS" 01 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $status
949 # API Test function: PUT /policy and V2 PUT /policies
950 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
951 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
952 # (Function for test scripts)
953 a1pms_api_put_policy() {
956 if [ "$A1PMS_VERSION" == "V2" ]; then
957 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
958 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
962 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
963 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
976 if [ "$A1PMS_VERSION" == "V2" ]; then
979 if [ $# -eq 9 ]; then
984 if [ $# -eq 8 ]; then
989 while [ $count -lt $max ]; do
990 if [ "$A1PMS_VERSION" == "V2" ]; then
994 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
995 if [ $trans != "NOTRANSIENT" ]; then
996 inputJson=$inputJson", \"transient\":$trans"
998 if [ $pt != "NOTYPE" ]; then
999 inputJson=$inputJson", \"policytype_id\":\"$pt\""
1001 inputJson=$inputJson", \"policytype_id\":\"\""
1003 if [ $noti != "NOURL" ]; then
1004 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1006 file="./tmp/.p.json"
1007 data=$(sed 's/XXX/'${pid}'/g' $temp)
1008 inputJson=$inputJson", \"policy_data\":$data"
1009 inputJson="{$inputJson}"
1010 echo $inputJson > $file
1012 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
1014 if [ $pt != "NOTYPE" ]; then
1015 query=$query"&type=$pt"
1018 if [ $trans != NOTRANSIENT ]; then
1019 query=$query"&transient=$trans"
1022 file="./tmp/.p.json"
1023 sed 's/XXX/'${pid}'/g' $temp > $file
1025 res="$(__do_curl_to_api A1PMS PUT $query $file)"
1026 status=${res:${#res}-3}
1027 echo -ne " Executing "$count"("$max")${SAMELINE}"
1028 if [ $status -ne $1 ]; then
1029 echo " Executed "$count"?("$max")"
1030 __log_test_fail_status_code $1 $status
1035 echo -ne " Executed "$count"("$max")${SAMELINE}"
1037 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $status $max
1044 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
1045 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
1046 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
1047 # (Function for test scripts)
1049 a1pms_api_put_policy_batch() {
1052 if [ "$A1PMS_VERSION" == "V2" ]; then
1053 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1054 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
1058 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1059 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
1071 if [ "$A1PMS_VERSION" == "V2" ]; then
1074 if [ $# -eq 9 ]; then
1079 if [ $# -eq 8 ]; then
1085 while [ $count -lt $max ]; do
1086 if [ "$A1PMS_VERSION" == "V2" ]; then
1087 query="/v2/policies"
1089 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1090 if [ $trans != "NOTRANSIENT" ]; then
1091 inputJson=$inputJson", \"transient\":$trans"
1093 if [ $pt != "NOTYPE" ]; then
1094 inputJson=$inputJson", \"policytype_id\":\"$pt\""
1096 inputJson=$inputJson", \"policytype_id\":\"\""
1098 if [ $noti != "NOURL" ]; then
1099 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1101 file="./tmp/.p.json"
1102 data=$(sed 's/XXX/'${pid}'/g' $temp)
1103 inputJson=$inputJson", \"policy_data\":$data"
1104 inputJson="{$inputJson}"
1105 echo $inputJson > $file
1107 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
1109 if [ $pt != "NOTYPE" ]; then
1110 query=$query"&type=$pt"
1113 if [ $trans != NOTRANSIENT ]; then
1114 query=$query"&transient=$trans"
1116 file="./tmp/.p.json"
1117 sed 's/XXX/'${pid}'/g' $temp > $file
1119 res="$(__do_curl_to_api A1PMS PUT_BATCH $query $file)"
1120 status=${res:${#res}-3}
1121 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1123 if [ $status -ne 200 ]; then
1124 echo " Requested(batch) "$count"?("$max")"
1125 __log_test_fail_status_code 200 $status
1128 cid=${res:0:${#res}-3}
1132 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1139 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1140 status=${res:${#res}-3}
1141 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
1143 if [ $status -ne $1 ]; then
1144 echo " Accepted(batch) "$count"?("$max")"
1145 __log_test_fail_status_code $1 $status
1150 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
1152 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $1 $max
1160 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
1161 # 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>
1162 # 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>
1163 # (Function for test scripts)
1164 a1pms_api_put_policy_parallel() {
1167 if [ "$A1PMS_VERSION" == "V2" ]; then
1168 if [ $# -ne 11 ]; then
1169 __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>" $@
1173 if [ $# -ne 10 ]; then
1174 __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>" $@
1178 resp_code=$1; shift;
1184 transient=$1; shift;
1185 if [ "$A1PMS_VERSION" == "V2" ]; then
1194 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1195 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1196 echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1197 echo " Info - will execute over a1pms REST"
1199 if [ "$A1PMS_VERSION" == "V2" ]; then
1200 if [ $serv == "NOSERVICE" ]; then
1203 query="$A1PMS_API_PREFIX/v2/policies"
1205 if [ $serv == "NOSERVICE" ]; then
1208 query="/policy?service=$serv"
1210 if [ $type != "NOTYPE" ]; then
1211 query=$query"&type=$type"
1214 if [ $transient != NOTRANSIENT ]; then
1215 query=$query"&transient=$transient"
1219 urlbase=${A1PMS_ADAPTER}${query}
1222 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1223 httpproxy=$KUBE_PROXY_PATH
1226 for ((i=1; i<=$pids; i++))
1229 if [ -z "$uuid" ]; then
1232 echo "" > "./tmp/.pid${i}.res.txt"
1233 if [ "$A1PMS_VERSION" == "V2" ]; then
1234 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1236 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1239 done | xargs -n 1 -I{} -P $pids bash -c '{
1241 echo " Parallel process $arg started"
1242 tmp=$(< "./tmp/.pid${arg}.txt")
1243 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1246 for ((i=1; i<=$pids; i++))
1248 file="./tmp/.pid${i}.res.txt"
1250 if [ -z "$tmp" ]; then
1251 echo " Process $i : unknown result (result file empty"
1255 if [ $res == "0" ]; then
1256 echo " Process $i : OK - "${tmp:1}
1258 echo " Process $i : failed - "${tmp:1}
1263 if [ -z $msg ]; then
1264 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $resp_code $(($count*$num_rics))
1265 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1269 __log_test_fail_general "One of more processes failed to execute"
1273 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
1274 # args: <response-code> <policy-id> [count]
1275 # (Function for test scripts)
1276 a1pms_api_delete_policy() {
1279 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1280 __print_err "<response-code> <policy-id> [count]" $@
1287 if [ $# -eq 3 ]; then
1293 while [ $count -lt $max ]; do
1294 if [ "$A1PMS_VERSION" == "V2" ]; then
1295 query="/v2/policies/"$UUID$pid
1297 query="/policy?id="$UUID$pid
1299 res="$(__do_curl_to_api A1PMS DELETE $query)"
1300 status=${res:${#res}-3}
1301 echo -ne " Executing "$count"("$max")${SAMELINE}"
1303 if [ $status -ne $1 ]; then
1304 echo " Executed "$count"?("$max")"
1305 __log_test_fail_status_code $1 $status
1311 echo -ne " Executed "$count"("$max")${SAMELINE}"
1313 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $status $max
1320 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
1321 # args: <response-code> <policy-id> [count]
1322 # (Function for test scripts)
1323 a1pms_api_delete_policy_batch() {
1326 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1327 __print_err "<response-code> <policy-id> [count]" $@
1334 if [ $# -eq 3 ]; then
1340 while [ $count -lt $max ]; do
1341 if [ "$A1PMS_VERSION" == "V2" ]; then
1342 query="/v2/policies/"$UUID$pid
1344 query="/policy?id="$UUID$pid
1346 res="$(__do_curl_to_api A1PMS DELETE_BATCH $query)"
1347 status=${res:${#res}-3}
1348 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1350 if [ $status -ne 200 ]; then
1351 echo " Requested(batch) "$count"?("$max")"
1352 __log_test_fail_status_code 200 $status
1355 cid=${res:0:${#res}-3}
1359 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1367 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1368 status=${res:${#res}-3}
1369 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1371 if [ $status -ne $1 ]; then
1372 echo " Deleted(batch) "$count"?("$max")"
1373 __log_test_fail_status_code $1 $status
1378 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1380 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $1 $max
1388 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1389 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1390 # (Function for test scripts)
1391 a1pms_api_delete_policy_parallel() {
1394 if [ $# -ne 5 ]; then
1395 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1398 resp_code=$1; shift;
1404 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1405 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1406 echo " Info - a1pms_api_delete_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1407 echo " Info - will execute over a1pms REST"
1410 if [ "$A1PMS_VERSION" == "V2" ]; then
1411 query="$A1PMS_API_PREFIX/v2/policies/"
1416 urlbase=${A1PMS_ADAPTER}${query}
1419 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1420 httpproxy=$KUBE_PROXY_PATH
1423 for ((i=1; i<=$pids; i++))
1426 if [ -z "$uuid" ]; then
1429 echo "" > "./tmp/.pid${i}.del.res.txt"
1430 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
1432 done | xargs -n 1 -I{} -P $pids bash -c '{
1434 echo " Parallel process $arg started"
1435 tmp=$(< "./tmp/.pid${arg}.del.txt")
1436 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1439 for ((i=1; i<=$pids; i++))
1441 file="./tmp/.pid${i}.del.res.txt"
1443 if [ -z "$tmp" ]; then
1444 echo " Process $i : unknown result (result file empty"
1448 if [ $res == "0" ]; then
1449 echo " Process $i : OK - "${tmp:1}
1451 echo " Process $i : failed - "${tmp:1}
1456 if [ -z $msg ]; then
1457 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count*$num_rics))
1458 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1462 __log_test_fail_general "One of more processes failed to execute"
1466 # API Test function: GET /policy_ids and V2 GET /v2/policies
1467 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1468 # (Function for test scripts)
1469 a1pms_api_get_policy_ids() {
1472 if [ $# -lt 4 ]; then
1473 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1479 if [ "$A1PMS_VERSION" == "V2" ]; then
1480 if [ $2 != "NORIC" ]; then
1481 queryparams="?ric_id="$2
1484 if [ $3 != "NOSERVICE" ]; then
1485 if [ -z $queryparams ]; then
1486 queryparams="?service_id="$3
1488 queryparams=$queryparams"&service_id="$3
1491 if [ $4 != "NOTYPE" ]; then
1492 if [ -z $queryparams ]; then
1493 queryparams="?policytype_id="$4
1495 queryparams=$queryparams"&policytype_id="$4
1499 query="/v2/policies"$queryparams
1501 if [ $2 != "NORIC" ]; then
1502 queryparams="?ric="$2
1505 if [ $3 != "NOSERVICE" ]; then
1506 if [ -z $queryparams ]; then
1507 queryparams="?service="$3
1509 queryparams=$queryparams"&service="$3
1512 if [ $4 != "NOTYPE" ]; then
1513 if [ -z $queryparams ]; then
1514 queryparams="?type="$4
1516 queryparams=$queryparams"&type="$4
1520 query="/policy_ids"$queryparams
1523 res="$(__do_curl_to_api A1PMS GET $query)"
1524 status=${res:${#res}-3}
1526 if [ $status -ne $1 ]; then
1527 __log_test_fail_status_code $1 $status
1531 if [ $# -gt 4 ]; then
1532 body=${res:0:${#res}-3}
1535 for pid in ${@:5} ; do
1536 if [ "$targetJson" != "[" ]; then
1537 targetJson=$targetJson","
1539 if [ $pid != "NOID" ]; then
1540 targetJson=$targetJson"\"$UUID$pid\""
1544 targetJson=$targetJson"]"
1545 if [ "$A1PMS_VERSION" == "V2" ]; then
1546 targetJson="{\"policy_ids\": $targetJson}"
1548 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1549 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1551 if [ $res -ne 0 ]; then
1552 __log_test_fail_body
1557 __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v2/policies" $status
1562 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
1563 # args(V2): <response-code> <policy-type-id> [<schema-file>]
1564 # (Function for test scripts)
1565 a1pms_api_get_policy_type() {
1568 if [ "$A1PMS_VERSION" != "V2" ]; then
1569 __log_test_fail_not_supported
1573 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1574 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1577 query="/v2/policy-types/$2"
1579 res="$(__do_curl_to_api A1PMS GET $query)"
1580 status=${res:${#res}-3}
1582 if [ $status -ne $1 ]; then
1583 __log_test_fail_status_code $1 $status
1587 if [ $# -eq 3 ]; then
1589 body=${res:0:${#res}-3}
1592 targetJson="{\"policy_schema\":$targetJson}"
1593 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1594 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1596 if [ $res -ne 0 ]; then
1597 __log_test_fail_body
1602 __collect_endpoint_stats "A1PMS" 05 "GET" $A1PMS_API_PREFIX"/v2/policy-types/{policyTypeId}" $status
1607 # API Test function: GET /policy_schema
1608 # args: <response-code> <policy-type-id> [<schema-file>]
1609 # (Function for test scripts)
1610 a1pms_api_get_policy_schema() {
1613 if [ "$A1PMS_VERSION" == "V2" ]; then
1614 __log_test_fail_not_supported
1618 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1619 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1622 query="/policy_schema?id=$2"
1623 res="$(__do_curl_to_api A1PMS GET $query)"
1624 status=${res:${#res}-3}
1626 if [ $status -ne $1 ]; then
1627 __log_test_fail_status_code $1 $status
1631 if [ $# -eq 3 ]; then
1633 body=${res:0:${#res}-3}
1637 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1638 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1640 if [ $res -ne 0 ]; then
1641 __log_test_fail_body
1646 __collect_endpoint_stats "A1PMS" 06 "GET" $A1PMS_API_PREFIX"/v2/policy_schema" $status
1651 # API Test function: GET /policy_schemas
1652 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
1653 # args(V2): <response-code>
1654 # (Function for test scripts)
1655 a1pms_api_get_policy_schemas() {
1658 if [ "$A1PMS_VERSION" == "V2" ]; then
1659 if [ $# -ne 1 ]; then
1660 __print_err "<response-code>" $@
1664 if [ $# -lt 2 ]; then
1665 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1669 if [ "$A1PMS_VERSION" == "V2" ]; then
1670 query="/v2/policy-schemas"
1672 query="/policy_schemas"
1673 if [ $2 != "NORIC" ]; then
1674 query=$query"?ric="$2
1678 res="$(__do_curl_to_api A1PMS GET $query)"
1679 status=${res:${#res}-3}
1681 if [ $status -ne $1 ]; then
1682 __log_test_fail_status_code $1 $status
1686 if [ $# -gt 2 ]; then
1687 body=${res:0:${#res}-3}
1690 for file in ${@:3} ; do
1691 if [ "$targetJson" != "[" ]; then
1692 targetJson=$targetJson","
1694 if [ $file == "NOFILE" ]; then
1695 targetJson=$targetJson"{}"
1697 targetJson=$targetJson$(< $file)
1701 targetJson=$targetJson"]"
1702 if [ "$A1PMS_VERSION" == "V2" ]; then
1703 targetJson="{\"policy_schemas\": $targetJson }"
1705 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1706 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1708 if [ $res -ne 0 ]; then
1709 __log_test_fail_body
1714 __collect_endpoint_stats "A1PMS" 07 "GET" $A1PMS_API_PREFIX"/v2/policy-schemas" $status
1719 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1720 # arg: <response-code> <policy-id> [ (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>) ]
1721 # (Function for test scripts)
1722 a1pms_api_get_policy_status() {
1725 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
1726 __print_err "<response-code> <policy-id> [(STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)]" $@
1731 if [ $# -eq 2 ]; then
1733 elif [ "$3" == "STD" ]; then
1734 targetJson="{\"enforceStatus\":\"$4\""
1735 if [ $# -eq 5 ]; then
1736 targetJson=$targetJson",\"reason\":\"$5\""
1738 targetJson=$targetJson"}"
1739 elif [ "$3" == "STD2" ]; then
1740 if [ $4 == "EMPTY" ]; then
1741 targetJson="{\"enforceStatus\":\"\""
1743 targetJson="{\"enforceStatus\":\"$4\""
1745 if [ $# -eq 5 ]; then
1746 if [ $5 == "EMPTY" ]; then
1747 targetJson=$targetJson",\"enforceReason\":\"\""
1749 targetJson=$targetJson",\"enforceReason\":\"$5\""
1752 targetJson=$targetJson"}"
1753 elif [ "$3" == "OSC" ]; then
1754 targetJson="{\"instance_status\":\"$4\""
1755 if [ $# -eq 5 ]; then
1756 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1758 targetJson=$targetJson",\"created_at\":\"????\"}"
1760 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1764 if [ "$A1PMS_VERSION" == "V2" ]; then
1765 query="/v2/policies/$UUID$2/status"
1766 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1768 query="/policy_status?id="$UUID$2
1771 res="$(__do_curl_to_api A1PMS GET $query)"
1772 status=${res:${#res}-3}
1774 if [ $status -ne $1 ]; then
1775 __log_test_fail_status_code $1 $status
1778 if [ $# -gt 2 ]; then
1779 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1780 body=${res:0:${#res}-3}
1781 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1783 if [ $res -ne 0 ]; then
1784 __log_test_fail_body
1788 __collect_endpoint_stats "A1PMS" 08 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}/status" $status
1793 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1794 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1795 # (Function for test scripts)
1796 a1pms_api_get_policy_types() {
1799 if [ $# -lt 1 ]; then
1800 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1804 if [ "$A1PMS_VERSION" == "V2" ]; then
1805 if [ $# -eq 1 ]; then
1806 query="/v2/policy-types"
1807 elif [ $2 == "NORIC" ]; then
1808 query="/v2/policy-types"
1810 query="/v2/policy-types?ric_id=$2"
1813 if [ $# -eq 1 ]; then
1814 query="/policy_types"
1815 elif [ $2 == "NORIC" ]; then
1816 query="/policy_types"
1818 query="/policy_types?ric=$2"
1822 res="$(__do_curl_to_api A1PMS GET $query)"
1823 status=${res:${#res}-3}
1825 if [ $status -ne $1 ]; then
1826 __log_test_fail_status_code $1 $status
1830 if [ $# -gt 2 ]; then
1831 body=${res:0:${#res}-3}
1834 for pid in ${@:3} ; do
1835 if [ "$targetJson" != "[" ]; then
1836 targetJson=$targetJson","
1838 if [ $pid == "EMPTY" ]; then
1841 targetJson=$targetJson"\"$pid\""
1844 targetJson=$targetJson"]"
1845 if [ "$A1PMS_VERSION" == "V2" ]; then
1846 targetJson="{\"policytype_ids\": $targetJson }"
1848 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1849 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1851 if [ $res -ne 0 ]; then
1852 __log_test_fail_body
1857 __collect_endpoint_stats "A1PMS" 09 "GET" $A1PMS_API_PREFIX"/v2/policy-types" $status
1862 #########################################################
1863 #### Test case functions Health check
1864 #########################################################
1866 # API Test function: GET /status and V2 GET /status
1867 # args: <response-code>
1868 # (Function for test scripts)
1869 a1pms_api_get_status() {
1871 if [ $# -ne 1 ]; then
1872 __print_err "<response-code>" $@
1875 if [ "$A1PMS_VERSION" == "V2" ]; then
1880 res="$(__do_curl_to_api A1PMS GET $query)"
1881 status=${res:${#res}-3}
1883 if [ $status -ne $1 ]; then
1884 __log_test_fail_status_code $1 $status
1888 __collect_endpoint_stats "A1PMS" 10 "GET" $A1PMS_API_PREFIX"/v2/status" $status
1893 # API Test function: GET /status (root) without api prefix
1894 # args: <response-code>
1895 # (Function for test scripts)
1896 a1pms_api_get_status_root() {
1898 if [ $# -ne 1 ]; then
1899 __print_err "<response-code>" $@
1903 TMP_PREFIX=$A1PMS_API_PREFIX
1905 res="$(__do_curl_to_api A1PMS GET $query)"
1906 A1PMS_API_PREFIX=$TMP_PREFIX
1907 status=${res:${#res}-3}
1909 if [ $status -ne $1 ]; then
1910 __log_test_fail_status_code $1 $status
1914 __collect_endpoint_stats "A1PMS" 19 "GET" "/status" $status
1919 #########################################################
1920 #### Test case functions RIC Repository
1921 #########################################################
1923 # API Test function: GET /ric and V2 GET /v2/rics/ric
1924 # args: <reponse-code> <management-element-id> [<ric-id>]
1925 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1926 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1927 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1930 # (Function for test scripts)
1931 a1pms_api_get_ric() {
1934 if [ "$A1PMS_VERSION" == "V2" ]; then
1935 if [ $# -lt 3 ]; then
1936 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1940 if [ $2 != "NOME" ]; then
1941 search="?managed_element_id="$2
1943 if [ $3 != "NORIC" ]; then
1944 if [ -z $search ]; then
1947 search=$search"&ric_id="$3
1950 query="/v2/rics/ric"$search
1952 res="$(__do_curl_to_api A1PMS GET $query)"
1953 status=${res:${#res}-3}
1955 if [ $status -ne $1 ]; then
1956 __log_test_fail_status_code $1 $status
1960 if [ $# -gt 3 ]; then
1961 body=${res:0:${#res}-3}
1962 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1963 if [ $res -ne 0 ]; then
1964 __log_test_fail_general "Could not create target ric info json"
1968 targetJson=$(<./tmp/.tmp_rics.json)
1969 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1970 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1971 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1972 if [ $res -ne 0 ]; then
1973 __log_test_fail_body
1978 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1979 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1983 query="/ric?managedElementId="$2
1985 res="$(__do_curl_to_api A1PMS GET $query)"
1986 status=${res:${#res}-3}
1988 if [ $status -ne $1 ]; then
1989 __log_test_fail_status_code $1 $status
1993 if [ $# -eq 3 ]; then
1994 body=${res:0:${#res}-3}
1995 if [ "$body" != "$3" ]; then
1996 __log_test_fail_body
2002 __collect_endpoint_stats "A1PMS" 11 "GET" $A1PMS_API_PREFIX"/v2/rics/ric" $status
2007 # API test function: GET /rics and V2 GET /v2/rics
2008 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
2009 # 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_........."
2010 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
2011 # (Function for test scripts)
2012 a1pms_api_get_rics() {
2015 if [ $# -lt 2 ]; then
2016 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
2020 if [ "$A1PMS_VERSION" == "V2" ]; then
2022 if [ $2 != "NOTYPE" ]; then
2023 query="/v2/rics?policytype_id="$2
2027 if [ $2 != "NOTYPE" ]; then
2028 query="/rics?policyType="$2
2032 res="$(__do_curl_to_api A1PMS GET $query)"
2033 status=${res:${#res}-3}
2035 if [ $status -ne $1 ]; then
2036 __log_test_fail_status_code $1 $status
2040 if [ $# -gt 2 ]; then
2041 body=${res:0:${#res}-3}
2042 if [ "$A1PMS_VERSION" == "V2" ]; then
2043 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
2045 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
2047 if [ $res -ne 0 ]; then
2048 __log_test_fail_general "Could not create target ric info json"
2052 targetJson=$(<./tmp/.tmp_rics.json)
2053 if [ "$A1PMS_VERSION" == "V2" ]; then
2054 targetJson="{\"rics\": $targetJson }"
2056 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2057 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2058 if [ $res -ne 0 ]; then
2059 __log_test_fail_body
2064 __collect_endpoint_stats "A1PMS" 12 "GET" $A1PMS_API_PREFIX"/v2/rics" $status
2069 ##################################################################
2070 #### API Test case functions Service registry and supervision ####
2071 ##################################################################
2073 # API test function: PUT /service and V2 PUT /service
2074 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
2075 # (Function for test scripts)
2076 a1pms_api_put_service() {
2078 if [ $# -ne 4 ]; then
2079 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
2083 if [ "$A1PMS_VERSION" == "V2" ]; then
2084 query="/v2/services"
2085 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
2088 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
2090 file="./tmp/.tmp.json"
2091 echo "$json" > $file
2093 res="$(__do_curl_to_api A1PMS PUT $query $file)"
2094 status=${res:${#res}-3}
2096 if [ $status -ne $1 ]; then
2097 __log_test_fail_status_code $1 $status
2101 __collect_endpoint_stats "A1PMS" 13 "PUT" $A1PMS_API_PREFIX"/v2/service" $status
2106 # API test function: GET /services and V2 GET /v2/services
2107 #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>]* )]
2108 # (Function for test scripts)
2109 a1pms_api_get_services() {
2111 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
2113 if [ $# -eq 1 ]; then
2115 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
2117 elif [ $# -eq 5 ]; then
2119 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
2121 if [ $(($argLen%3)) -eq 0 ]; then
2126 if [ $paramError -ne 0 ]; then
2127 __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>]* )]" $@
2131 if [ "$A1PMS_VERSION" == "V2" ]; then
2132 query="/v2/services"
2134 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2135 query="/v2/services?service_id="$2
2140 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2141 query="/services?name="$2
2144 res="$(__do_curl_to_api A1PMS GET $query)"
2145 status=${res:${#res}-3}
2147 if [ $status -ne $1 ]; then
2148 __log_test_fail_status_code $1 $status
2152 if [ $# -gt 2 ]; then
2153 variableArgCount=$(($#-2))
2154 body=${res:0:${#res}-3}
2158 while [ $cntr -lt $variableArgCount ]; do
2159 servicename=$1; shift;
2162 if [ $cntr -gt 0 ]; then
2163 targetJson=$targetJson","
2165 # timeSinceLastActivitySeconds value cannot be checked since value varies
2166 if [ "$A1PMS_VERSION" == "V2" ]; then
2167 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
2169 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2173 targetJson=$targetJson"]"
2174 if [ "$A1PMS_VERSION" == "V2" ]; then
2175 targetJson="{\"service_list\": $targetJson }"
2177 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2178 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2179 if [ $res -ne 0 ]; then
2180 __log_test_fail_body
2185 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX"/v2/services" $status
2190 # API test function: GET /services V2 GET /v2/services - (only checking service names)
2191 # args: <response-code> [<service-name>]*"
2192 # (Function for test scripts)
2193 a1pms_api_get_service_ids() {
2196 if [ $# -lt 1 ]; then
2197 __print_err "<response-code> [<service-name>]*" $@
2201 if [ "$A1PMS_VERSION" == "V2" ]; then
2202 query="/v2/services"
2206 res="$(__do_curl_to_api A1PMS GET $query)"
2207 status=${res:${#res}-3}
2209 if [ $status -ne $1 ]; then
2210 __log_test_fail_status_code $1 $status
2214 body=${res:0:${#res}-3}
2216 for rapp in ${@:2} ; do
2217 if [ "$targetJson" != "[" ]; then
2218 targetJson=$targetJson","
2220 if [ "$A1PMS_VERSION" == "V2" ]; then
2221 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2223 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2227 targetJson=$targetJson"]"
2228 if [ "$A1PMS_VERSION" == "V2" ]; then
2229 targetJson="{\"service_list\": $targetJson }"
2231 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2232 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2234 if [ $res -ne 0 ]; then
2235 __log_test_fail_body
2239 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX"/v2/services" $status
2244 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
2245 # args: <response-code> <service-name>
2246 # (Function for test scripts)
2247 a1pms_api_delete_services() {
2250 if [ $# -ne 2 ]; then
2251 __print_err "<response-code> <service-name>" $@
2254 if [ "$A1PMS_VERSION" == "V2" ]; then
2255 query="/v2/services/"$2
2257 query="/services?name="$2
2259 res="$(__do_curl_to_api A1PMS DELETE $query)"
2260 status=${res:${#res}-3}
2262 if [ $status -ne $1 ]; then
2263 __log_test_fail_status_code $1 $status
2267 __collect_endpoint_stats "A1PMS" 15 "DELETE" $A1PMS_API_PREFIX"/v2/services/{serviceId}" $status
2272 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
2273 # args: <response-code> <service-name>
2274 # (Function for test scripts)
2275 a1pms_api_put_services_keepalive() {
2278 if [ $# -ne 2 ]; then
2279 __print_err "<response-code> <service-name>" $@
2282 if [ "$A1PMS_VERSION" == "V2" ]; then
2283 query="/v2/services/$2/keepalive"
2285 query="/services/keepalive?name="$2
2288 res="$(__do_curl_to_api A1PMS PUT $query)"
2289 status=${res:${#res}-3}
2291 if [ $status -ne $1 ]; then
2292 __log_test_fail_status_code $1 $status
2296 __collect_endpoint_stats "A1PMS" 16 "PUT" $A1PMS_API_PREFIX"/v2/services/{service_id}/keepalive" $status
2301 ##################################################################
2302 #### API Test case functions Configuration ####
2303 ##################################################################
2305 # API Test function: PUT /v2/configuration
2306 # args: <response-code> <config-file>
2307 # (Function for test scripts)
2308 a1pms_api_put_configuration() {
2311 if [ "$A1PMS_VERSION" != "V2" ]; then
2312 __log_test_fail_not_supported
2316 if [ $# -ne 2 ]; then
2317 __print_err "<response-code> <config-file>" $@
2320 if [ ! -f $2 ]; then
2321 __log_test_fail_general "Config file "$2", does not exist"
2325 # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
2326 # inputJson="{\"config\":"$inputJson"}"
2328 file="./tmp/.config.json"
2329 echo $inputJson > $file
2330 query="/v2/configuration"
2331 res="$(__do_curl_to_api A1PMS PUT $query $file)"
2332 status=${res:${#res}-3}
2334 if [ $status -ne $1 ]; then
2335 __log_test_fail_status_code $1 $status
2339 __collect_endpoint_stats "A1PMS" 17 "PUT" $A1PMS_API_PREFIX"/v2/configuration" $status
2344 # API Test function: GET /v2/configuration
2345 # args: <response-code> [<config-file>]
2346 # (Function for test scripts)
2347 a1pms_api_get_configuration() {
2350 if [ "$A1PMS_VERSION" != "V2" ]; then
2351 __log_test_fail_not_supported
2355 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2356 __print_err "<response-code> [<config-file>]" $@
2359 if [ ! -f $2 ]; then
2360 __log_test_fail_general "Config file "$2" for comparison, does not exist"
2364 query="/v2/configuration"
2365 res="$(__do_curl_to_api A1PMS GET $query)"
2366 status=${res:${#res}-3}
2368 if [ $status -ne $1 ]; then
2369 __log_test_fail_status_code $1 $status
2373 if [ $# -eq 2 ]; then
2375 body=${res:0:${#res}-3}
2378 # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
2379 # inputJson="{\"config\":"$inputJson"}"
2381 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2382 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2384 if [ $res -ne 0 ]; then
2385 __log_test_fail_body
2390 __collect_endpoint_stats "A1PMS" 18 "GET" $A1PMS_API_PREFIX"/v2/configuration" $status
2395 ##########################################
2396 #### Reset types and instances ####
2397 ##########################################
2399 # Admin reset to remove all policies and services
2400 # All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2401 # NOTE - only works in kubernetes and the pod should not be running
2403 # (Function for test scripts)
2405 a1pms_kube_pvc_reset() {
2408 pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
2409 if [ -z "$pvc_name" ]; then
2410 pvc_name=policymanagementservice-vardata-pvc
2412 echo " Trying to reset pvc: "$pvc_name
2413 __kube_clean_pvc $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $A1PMS_CONTAINER_MNT_DIR
2419 # args: <realm> <client-name> <client-secret>
2420 a1pms_configure_sec() {
2421 export A1PMS_CREDS_GRANT_TYPE="client_credentials"
2422 export A1PMS_CREDS_CLIENT_SECRET=$3
2423 export A1PMS_CREDS_CLIENT_ID=$2
2424 export A1PMS_AUTH_SERVICE_URL=$KEYCLOAK_SERVICE_PATH$KEYCLOAK_TOKEN_URL_PREFIX/$1/protocol/openid-connect/token
2425 export A1PMS_SIDECAR_MOUNT="/token-cache"
2426 export A1PMS_SIDECAR_JWT_FILE=$A1PMS_SIDECAR_MOUNT"/jwt.txt"
2428 export AUTHSIDECAR_APP_NAME
2429 export AUTHSIDECAR_DISPLAY_NAME