3 # ============LICENSE_START===============================================
4 # Copyright (C) 2021 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 prestarted 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 resouces 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-prexix>
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 kubernets 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 prestarted apps.
99 __A1PMS_statisics_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 testscipt
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 perpare the consul configuration according to the current simulator configuration
460 # args: SDNC|NOSDNC <output-file>
461 # (Function for test scripts)
462 prepare_a1pms_config() {
463 echo -e $BOLD"Prepare Consul config"$EBOLD
465 echo " Writing consul config for "$A1PMS_APP_NAME" to file: "$2
469 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
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 ],"
495 config_json=$config_json"\n \"streams_publishes\": {"
496 config_json=$config_json"\n \"dmaap_publisher\": {"
497 config_json=$config_json"\n \"type\": \"message-router\","
498 config_json=$config_json"\n \"dmaap_info\": {"
499 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_WRITE_URL\""
500 config_json=$config_json"\n }"
501 config_json=$config_json"\n }"
502 config_json=$config_json"\n },"
503 config_json=$config_json"\n \"streams_subscribes\": {"
504 config_json=$config_json"\n \"dmaap_subscriber\": {"
505 config_json=$config_json"\n \"type\": \"message-router\","
506 config_json=$config_json"\n \"dmaap_info\": {"
507 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_READ_URL\""
508 config_json=$config_json"\n }"
509 config_json=$config_json"\n }"
510 config_json=$config_json"\n },"
512 config_json=$config_json"\n \"ric\": ["
514 if [ $RUNMODE == "KUBE" ]; then
515 result=$(kubectl $KUBECONF get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICSIM")].metadata.name}')
518 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
519 for im in $result; do
520 if [[ $im != *"-0" ]]; then
521 ric_subdomain=$(kubectl $KUBECONF get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
522 rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
523 let ric_cntr=ric_cntr+1
527 if [ $ric_cntr -eq 0 ]; then
528 echo $YELLOW"Warning: No rics found for the configuration"$EYELLOW
531 rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "status=running" --format {{.Names}})
532 if [ $? -ne 0 ] || [ -z "$rics" ]; then
533 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
540 if [ $cntr -gt 0 ]; then
541 config_json=$config_json"\n ,"
543 config_json=$config_json"\n {"
544 if [ $RUNMODE == "KUBE" ]; then
545 ric_id=${ric%.*.*} #extract pod id from full hosthame
546 ric_id=$(echo "$ric_id" | tr '-' '_')
548 if [ $DOCKER_COMPOSE_VERSION == "V1" ]; then
551 ric_id=$(echo "$ric" | tr '-' '_') #ric id still needs underscore as it is different from the container name
554 echo " Found a1 sim: "$ric_id
555 config_json=$config_json"\n \"name\": \"$ric_id\","
556 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
557 if [ $1 == "SDNC" ]; then
558 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
560 config_json=$config_json"\n \"managedElementIds\": ["
561 config_json=$config_json"\n \"me1_$ric_id\","
562 config_json=$config_json"\n \"me2_$ric_id\""
563 config_json=$config_json"\n ]"
564 config_json=$config_json"\n }"
568 config_json=$config_json"\n ]"
569 config_json=$config_json"\n}"
571 config_json="{\"config\":"$config_json"}"
573 printf "$config_json">$2
578 # Load the the appl config for the a1pms into a config map
579 a1pms_load_config() {
580 echo -e $BOLD"A1PMS - load config from "$EBOLD$1
581 data_json=$PWD/tmp/$A1PMS_DATA_FILE
583 output_yaml=$PWD/tmp/a1pms-cfd.yaml
584 __kube_create_configmap $A1PMS_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $data_json $output_yaml
589 # Turn on debug level tracing in the a1pms
591 # (Function for test scripts)
593 echo -e $BOLD"Setting a1pms debug logging"$EBOLD
594 curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
595 result=$(__do_curl "$curlString")
596 if [ $? -ne 0 ]; then
597 __print_err "could not set debug mode" $@
605 # Turn on trace level tracing in the a1pms
607 # (Function for test scripts)
609 echo -e $BOLD"Setting a1pms trace logging"$EBOLD
610 curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
611 result=$(__do_curl "$curlString")
612 if [ $? -ne 0 ]; then
613 __print_err "could not set trace mode" $@
621 # Perform curl retries when making direct call to the a1pms for the specified http response codes
622 # Speace separated list of http response codes
623 # args: [<response-code>]*
624 use_a1pms_retries() {
625 echo -e $BOLD"Do curl retries to the a1pms REST inteface for these response codes:$@"$EBOLD
631 # Check the a1pms logs for WARNINGs and ERRORs
633 # (Function for test scripts)
635 __check_container_logs "A1PMS" $A1PMS_APP_NAME $A1PMS_LOGPATH WARN ERR
638 #########################################################
639 #### Test case functions A1 Policy management service
640 #########################################################
642 # This function compare the size, towards a target value, of a json array returned from <url> of the A1PMS.
643 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
644 # args: json:<url> <target-value> [<timeout-in-seconds]
645 # (Function for test scripts)
647 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
648 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
649 if [[ $1 == "json:"* ]]; then
650 if [ "$A1PMS_VERSION" == "V2" ]; then
651 __var_test "A1PMS" $A1PMS_SERVICE_PATH$A1PMS_API_PREFIX"/v2/" $1 "=" $2 $3
653 __var_test "A1PMS" $A1PMS_SERVICE_PATH"/" $1 "=" $2 $3
658 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
662 # API Test function: GET /policies and V2 GET /v2/policy-instances
663 # 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>]*]
664 # 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>]*]
665 # (Function for test scripts)
666 a1pms_api_get_policies() {
669 if [ "$A1PMS_VERSION" == "V2" ]; then
671 variableParams=$(($#-4))
672 if [ $# -lt 4 ]; then
674 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
676 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
680 if [ $paramError -ne 0 ]; then
681 __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>]*]" $@
686 variableParams=$(($#-4))
687 if [ $# -lt 4 ]; then
689 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
691 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
695 if [ $paramError -ne 0 ]; then
696 __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>]*]" $@
702 if [ "$A1PMS_VERSION" == "V2" ]; then
703 if [ $2 != "NORIC" ]; then
704 queryparams="?ric_id="$2
706 if [ $3 != "NOSERVICE" ]; then
707 if [ -z $queryparams ]; then
708 queryparams="?service_id="$3
710 queryparams=$queryparams"&service_id="$3
713 if [ $4 != "NOTYPE" ]; then
714 if [ -z $queryparams ]; then
715 queryparams="?policytype_id="$4
717 queryparams=$queryparams"&policytype_id="$4
721 query="/v2/policy-instances"$queryparams
722 res="$(__do_curl_to_api A1PMS GET $query)"
723 status=${res:${#res}-3}
725 if [ $status -ne $1 ]; then
726 __log_test_fail_status_code $1 $status
730 if [ $# -gt 4 ]; then
731 body=${res:0:${#res}-3}
732 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
738 for ((i=0; i<$(($#-4)); i=i+7)); do
740 if [ "$targetJson" != "[" ]; then
741 targetJson=$targetJson","
743 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
744 if [ "${arr[$i+3]}" == "EMPTY" ]; then
745 targetJson=$targetJson"\"\","
747 targetJson=$targetJson"\"${arr[$i+3]}\","
749 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
751 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
753 targetJson=$targetJson"\"policy_data\":"$json"}"
757 targetJson=$targetJson"]"
758 targetJson="{\"policies\": $targetJson}"
759 echo "TARGET JSON: $targetJson" >> $HTTPLOG
760 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
762 if [ $res -ne 0 ]; then
768 if [ $2 != "NORIC" ]; then
769 queryparams="?ric="$2
771 if [ $3 != "NOSERVICE" ]; then
772 if [ -z $queryparams ]; then
773 queryparams="?service="$3
775 queryparams=$queryparams"&service="$3
778 if [ $4 != "NOTYPE" ]; then
779 if [ -z $queryparams ]; then
780 queryparams="?type="$4
782 queryparams=$queryparams"&type="$4
786 query="/policies"$queryparams
787 res="$(__do_curl_to_api A1PMS GET $query)"
788 status=${res:${#res}-3}
790 if [ $status -ne $1 ]; then
791 __log_test_fail_status_code $1 $status
795 if [ $# -gt 4 ]; then
796 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
799 body=${res:0:${#res}-3}
803 for ((i=0; i<$(($#-4)); i=i+5)); do
805 if [ "$targetJson" != "[" ]; then
806 targetJson=$targetJson","
808 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
809 if [ "${arr[$i+3]}" == "EMPTY" ]; then
810 targetJson=$targetJson"\"\","
812 targetJson=$targetJson"\"${arr[$i+3]}\","
815 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
817 targetJson=$targetJson"\"json\":"$json"}"
821 targetJson=$targetJson"]"
822 echo "TARGET JSON: $targetJson" >> $HTTPLOG
823 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
825 if [ $res -ne 0 ]; then
831 __collect_endpoint_stats "A1PMS" 00 "GET" $A1PMS_API_PREFIX"/v2/policy-instances" $status
838 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
839 # args: <response-code> <policy-id> [<template-file>]
840 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
842 # (Function for test scripts)
843 a1pms_api_get_policy() {
847 if [ "$A1PMS_VERSION" == "V2" ]; then
848 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
849 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
852 query="/v2/policies/$UUID$2"
854 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
855 __print_err "<response-code> <policy-id> [<template-file>] " $@
858 query="/policy?id=$UUID$2"
860 res="$(__do_curl_to_api A1PMS GET $query)"
861 status=${res:${#res}-3}
863 if [ $status -ne $1 ]; then
864 __log_test_fail_status_code $1 $status
868 if [ "$A1PMS_VERSION" == "V2" ]; then
869 if [ $# -eq 8 ]; then
871 #Create a policy json to compare with
872 body=${res:0:${#res}-3}
874 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
875 if [ $7 != "NOTRANSIENT" ]; then
876 targetJson=$targetJson", \"transient\":$7"
878 if [ $6 != "NOTYPE" ]; then
879 targetJson=$targetJson", \"policytype_id\":\"$6\""
881 targetJson=$targetJson", \"policytype_id\":\"\""
883 if [ $8 != "NOURL" ]; then
884 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
887 data=$(sed 's/XXX/'${2}'/g' $3)
888 targetJson=$targetJson", \"policy_data\":$data"
889 targetJson="{$targetJson}"
891 echo "TARGET JSON: $targetJson" >> $HTTPLOG
892 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
893 if [ $res -ne 0 ]; then
899 if [ $# -eq 3 ]; then
900 #Create a policy json to compare with
901 body=${res:0:${#res}-3}
903 sed 's/XXX/'${2}'/g' $3 > $file
904 targetJson=$(< $file)
905 echo "TARGET JSON: $targetJson" >> $HTTPLOG
906 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
907 if [ $res -ne 0 ]; then
913 __collect_endpoint_stats "A1PMS" 01 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $status
918 # API Test function: PUT /policy and V2 PUT /policies
919 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
920 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
921 # (Function for test scripts)
922 a1pms_api_put_policy() {
925 if [ "$A1PMS_VERSION" == "V2" ]; then
926 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
927 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
931 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
932 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
945 if [ "$A1PMS_VERSION" == "V2" ]; then
948 if [ $# -eq 9 ]; then
953 if [ $# -eq 8 ]; then
958 while [ $count -lt $max ]; do
959 if [ "$A1PMS_VERSION" == "V2" ]; then
963 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
964 if [ $trans != "NOTRANSIENT" ]; then
965 inputJson=$inputJson", \"transient\":$trans"
967 if [ $pt != "NOTYPE" ]; then
968 inputJson=$inputJson", \"policytype_id\":\"$pt\""
970 inputJson=$inputJson", \"policytype_id\":\"\""
972 if [ $noti != "NOURL" ]; then
973 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
976 data=$(sed 's/XXX/'${pid}'/g' $temp)
977 inputJson=$inputJson", \"policy_data\":$data"
978 inputJson="{$inputJson}"
979 echo $inputJson > $file
981 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
983 if [ $pt != "NOTYPE" ]; then
984 query=$query"&type=$pt"
987 if [ $trans != NOTRANSIENT ]; then
988 query=$query"&transient=$trans"
992 sed 's/XXX/'${pid}'/g' $temp > $file
994 res="$(__do_curl_to_api A1PMS PUT $query $file)"
995 status=${res:${#res}-3}
996 echo -ne " Executing "$count"("$max")${SAMELINE}"
997 if [ $status -ne $1 ]; then
998 echo " Executed "$count"?("$max")"
999 __log_test_fail_status_code $1 $status
1004 echo -ne " Executed "$count"("$max")${SAMELINE}"
1006 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $status $max
1013 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
1014 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
1015 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
1016 # (Function for test scripts)
1018 a1pms_api_put_policy_batch() {
1021 if [ "$A1PMS_VERSION" == "V2" ]; then
1022 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1023 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
1027 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1028 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
1040 if [ "$A1PMS_VERSION" == "V2" ]; then
1043 if [ $# -eq 9 ]; then
1048 if [ $# -eq 8 ]; then
1054 while [ $count -lt $max ]; do
1055 if [ "$A1PMS_VERSION" == "V2" ]; then
1056 query="/v2/policies"
1058 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1059 if [ $trans != "NOTRANSIENT" ]; then
1060 inputJson=$inputJson", \"transient\":$trans"
1062 if [ $pt != "NOTYPE" ]; then
1063 inputJson=$inputJson", \"policytype_id\":\"$pt\""
1065 inputJson=$inputJson", \"policytype_id\":\"\""
1067 if [ $noti != "NOURL" ]; then
1068 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1070 file="./tmp/.p.json"
1071 data=$(sed 's/XXX/'${pid}'/g' $temp)
1072 inputJson=$inputJson", \"policy_data\":$data"
1073 inputJson="{$inputJson}"
1074 echo $inputJson > $file
1076 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
1078 if [ $pt != "NOTYPE" ]; then
1079 query=$query"&type=$pt"
1082 if [ $trans != NOTRANSIENT ]; then
1083 query=$query"&transient=$trans"
1085 file="./tmp/.p.json"
1086 sed 's/XXX/'${pid}'/g' $temp > $file
1088 res="$(__do_curl_to_api A1PMS PUT_BATCH $query $file)"
1089 status=${res:${#res}-3}
1090 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1092 if [ $status -ne 200 ]; then
1093 echo " Requested(batch) "$count"?("$max")"
1094 __log_test_fail_status_code 200 $status
1097 cid=${res:0:${#res}-3}
1101 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1108 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1109 status=${res:${#res}-3}
1110 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
1112 if [ $status -ne $1 ]; then
1113 echo " Accepted(batch) "$count"?("$max")"
1114 __log_test_fail_status_code $1 $status
1119 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
1121 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $1 $max
1129 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
1130 # 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>
1131 # 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>
1132 # (Function for test scripts)
1133 a1pms_api_put_policy_parallel() {
1136 if [ "$A1PMS_VERSION" == "V2" ]; then
1137 if [ $# -ne 11 ]; then
1138 __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>" $@
1142 if [ $# -ne 10 ]; then
1143 __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>" $@
1147 resp_code=$1; shift;
1153 transient=$1; shift;
1154 if [ "$A1PMS_VERSION" == "V2" ]; then
1163 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1164 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1165 echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1166 echo " Info - will execute over a1pms REST"
1168 if [ "$A1PMS_VERSION" == "V2" ]; then
1169 if [ $serv == "NOSERVICE" ]; then
1172 query="$A1PMS_API_PREFIX/v2/policies"
1174 if [ $serv == "NOSERVICE" ]; then
1177 query="/policy?service=$serv"
1179 if [ $type != "NOTYPE" ]; then
1180 query=$query"&type=$type"
1183 if [ $transient != NOTRANSIENT ]; then
1184 query=$query"&transient=$transient"
1188 urlbase=${A1PMS_ADAPTER}${query}
1191 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1192 httpproxy=$KUBE_PROXY_PATH
1195 for ((i=1; i<=$pids; i++))
1198 if [ -z "$uuid" ]; then
1201 echo "" > "./tmp/.pid${i}.res.txt"
1202 if [ "$A1PMS_VERSION" == "V2" ]; then
1203 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1205 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1208 done | xargs -n 1 -I{} -P $pids bash -c '{
1210 echo " Parallel process $arg started"
1211 tmp=$(< "./tmp/.pid${arg}.txt")
1212 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1215 for ((i=1; i<=$pids; i++))
1217 file="./tmp/.pid${i}.res.txt"
1219 if [ -z "$tmp" ]; then
1220 echo " Process $i : unknown result (result file empty"
1224 if [ $res == "0" ]; then
1225 echo " Process $i : OK - "${tmp:1}
1227 echo " Process $i : failed - "${tmp:1}
1232 if [ -z $msg ]; then
1233 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $resp_code $(($count*$num_rics))
1234 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1238 __log_test_fail_general "One of more processes failed to execute"
1242 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
1243 # args: <response-code> <policy-id> [count]
1244 # (Function for test scripts)
1245 a1pms_api_delete_policy() {
1248 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1249 __print_err "<response-code> <policy-id> [count]" $@
1256 if [ $# -eq 3 ]; then
1262 while [ $count -lt $max ]; do
1263 if [ "$A1PMS_VERSION" == "V2" ]; then
1264 query="/v2/policies/"$UUID$pid
1266 query="/policy?id="$UUID$pid
1268 res="$(__do_curl_to_api A1PMS DELETE $query)"
1269 status=${res:${#res}-3}
1270 echo -ne " Executing "$count"("$max")${SAMELINE}"
1272 if [ $status -ne $1 ]; then
1273 echo " Executed "$count"?("$max")"
1274 __log_test_fail_status_code $1 $status
1280 echo -ne " Executed "$count"("$max")${SAMELINE}"
1282 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $status $max
1289 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
1290 # args: <response-code> <policy-id> [count]
1291 # (Function for test scripts)
1292 a1pms_api_delete_policy_batch() {
1295 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1296 __print_err "<response-code> <policy-id> [count]" $@
1303 if [ $# -eq 3 ]; then
1309 while [ $count -lt $max ]; do
1310 if [ "$A1PMS_VERSION" == "V2" ]; then
1311 query="/v2/policies/"$UUID$pid
1313 query="/policy?id="$UUID$pid
1315 res="$(__do_curl_to_api A1PMS DELETE_BATCH $query)"
1316 status=${res:${#res}-3}
1317 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1319 if [ $status -ne 200 ]; then
1320 echo " Requested(batch) "$count"?("$max")"
1321 __log_test_fail_status_code 200 $status
1324 cid=${res:0:${#res}-3}
1328 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1336 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1337 status=${res:${#res}-3}
1338 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1340 if [ $status -ne $1 ]; then
1341 echo " Deleted(batch) "$count"?("$max")"
1342 __log_test_fail_status_code $1 $status
1347 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1349 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $1 $max
1357 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1358 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1359 # (Function for test scripts)
1360 a1pms_api_delete_policy_parallel() {
1363 if [ $# -ne 5 ]; then
1364 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1367 resp_code=$1; shift;
1373 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1374 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1375 echo " Info - a1pms_api_delete_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1376 echo " Info - will execute over a1pms REST"
1379 if [ "$A1PMS_VERSION" == "V2" ]; then
1380 query="$A1PMS_API_PREFIX/v2/policies/"
1385 urlbase=${A1PMS_ADAPTER}${query}
1388 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1389 httpproxy=$KUBE_PROXY_PATH
1392 for ((i=1; i<=$pids; i++))
1395 if [ -z "$uuid" ]; then
1398 echo "" > "./tmp/.pid${i}.del.res.txt"
1399 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
1401 done | xargs -n 1 -I{} -P $pids bash -c '{
1403 echo " Parallel process $arg started"
1404 tmp=$(< "./tmp/.pid${arg}.del.txt")
1405 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1408 for ((i=1; i<=$pids; i++))
1410 file="./tmp/.pid${i}.del.res.txt"
1412 if [ -z "$tmp" ]; then
1413 echo " Process $i : unknown result (result file empty"
1417 if [ $res == "0" ]; then
1418 echo " Process $i : OK - "${tmp:1}
1420 echo " Process $i : failed - "${tmp:1}
1425 if [ -z $msg ]; then
1426 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count*$num_rics))
1427 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1431 __log_test_fail_general "One of more processes failed to execute"
1435 # API Test function: GET /policy_ids and V2 GET /v2/policies
1436 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1437 # (Function for test scripts)
1438 a1pms_api_get_policy_ids() {
1441 if [ $# -lt 4 ]; then
1442 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1448 if [ "$A1PMS_VERSION" == "V2" ]; then
1449 if [ $2 != "NORIC" ]; then
1450 queryparams="?ric_id="$2
1453 if [ $3 != "NOSERVICE" ]; then
1454 if [ -z $queryparams ]; then
1455 queryparams="?service_id="$3
1457 queryparams=$queryparams"&service_id="$3
1460 if [ $4 != "NOTYPE" ]; then
1461 if [ -z $queryparams ]; then
1462 queryparams="?policytype_id="$4
1464 queryparams=$queryparams"&policytype_id="$4
1468 query="/v2/policies"$queryparams
1470 if [ $2 != "NORIC" ]; then
1471 queryparams="?ric="$2
1474 if [ $3 != "NOSERVICE" ]; then
1475 if [ -z $queryparams ]; then
1476 queryparams="?service="$3
1478 queryparams=$queryparams"&service="$3
1481 if [ $4 != "NOTYPE" ]; then
1482 if [ -z $queryparams ]; then
1483 queryparams="?type="$4
1485 queryparams=$queryparams"&type="$4
1489 query="/policy_ids"$queryparams
1492 res="$(__do_curl_to_api A1PMS GET $query)"
1493 status=${res:${#res}-3}
1495 if [ $status -ne $1 ]; then
1496 __log_test_fail_status_code $1 $status
1500 if [ $# -gt 4 ]; then
1501 body=${res:0:${#res}-3}
1504 for pid in ${@:5} ; do
1505 if [ "$targetJson" != "[" ]; then
1506 targetJson=$targetJson","
1508 if [ $pid != "NOID" ]; then
1509 targetJson=$targetJson"\"$UUID$pid\""
1513 targetJson=$targetJson"]"
1514 if [ "$A1PMS_VERSION" == "V2" ]; then
1515 targetJson="{\"policy_ids\": $targetJson}"
1517 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1518 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1520 if [ $res -ne 0 ]; then
1521 __log_test_fail_body
1526 __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v2/policies" $status
1531 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
1532 # args(V2): <response-code> <policy-type-id> [<schema-file>]
1533 # (Function for test scripts)
1534 a1pms_api_get_policy_type() {
1537 if [ "$A1PMS_VERSION" != "V2" ]; then
1538 __log_test_fail_not_supported
1542 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1543 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1546 query="/v2/policy-types/$2"
1548 res="$(__do_curl_to_api A1PMS GET $query)"
1549 status=${res:${#res}-3}
1551 if [ $status -ne $1 ]; then
1552 __log_test_fail_status_code $1 $status
1556 if [ $# -eq 3 ]; then
1558 body=${res:0:${#res}-3}
1561 targetJson="{\"policy_schema\":$targetJson}"
1562 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1563 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1565 if [ $res -ne 0 ]; then
1566 __log_test_fail_body
1571 __collect_endpoint_stats "A1PMS" 05 "GET" $A1PMS_API_PREFIX"/v2/policy-types/{policyTypeId}" $status
1576 # API Test function: GET /policy_schema
1577 # args: <response-code> <policy-type-id> [<schema-file>]
1578 # (Function for test scripts)
1579 a1pms_api_get_policy_schema() {
1582 if [ "$A1PMS_VERSION" == "V2" ]; then
1583 __log_test_fail_not_supported
1587 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1588 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1591 query="/policy_schema?id=$2"
1592 res="$(__do_curl_to_api A1PMS GET $query)"
1593 status=${res:${#res}-3}
1595 if [ $status -ne $1 ]; then
1596 __log_test_fail_status_code $1 $status
1600 if [ $# -eq 3 ]; then
1602 body=${res:0:${#res}-3}
1606 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1607 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1609 if [ $res -ne 0 ]; then
1610 __log_test_fail_body
1615 __collect_endpoint_stats "A1PMS" 06 "GET" $A1PMS_API_PREFIX"/v2/policy_schema" $status
1620 # API Test function: GET /policy_schemas
1621 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
1622 # args(V2): <response-code>
1623 # (Function for test scripts)
1624 a1pms_api_get_policy_schemas() {
1627 if [ "$A1PMS_VERSION" == "V2" ]; then
1628 if [ $# -ne 1 ]; then
1629 __print_err "<response-code>" $@
1633 if [ $# -lt 2 ]; then
1634 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1638 if [ "$A1PMS_VERSION" == "V2" ]; then
1639 query="/v2/policy-schemas"
1641 query="/policy_schemas"
1642 if [ $2 != "NORIC" ]; then
1643 query=$query"?ric="$2
1647 res="$(__do_curl_to_api A1PMS GET $query)"
1648 status=${res:${#res}-3}
1650 if [ $status -ne $1 ]; then
1651 __log_test_fail_status_code $1 $status
1655 if [ $# -gt 2 ]; then
1656 body=${res:0:${#res}-3}
1659 for file in ${@:3} ; do
1660 if [ "$targetJson" != "[" ]; then
1661 targetJson=$targetJson","
1663 if [ $file == "NOFILE" ]; then
1664 targetJson=$targetJson"{}"
1666 targetJson=$targetJson$(< $file)
1670 targetJson=$targetJson"]"
1671 if [ "$A1PMS_VERSION" == "V2" ]; then
1672 targetJson="{\"policy_schemas\": $targetJson }"
1674 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1675 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1677 if [ $res -ne 0 ]; then
1678 __log_test_fail_body
1683 __collect_endpoint_stats "A1PMS" 07 "GET" $A1PMS_API_PREFIX"/v2/policy-schemas" $status
1688 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1689 # arg: <response-code> <policy-id> [ (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>) ]
1690 # (Function for test scripts)
1691 a1pms_api_get_policy_status() {
1694 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
1695 __print_err "<response-code> <policy-id> [(STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)]" $@
1700 if [ $# -eq 2 ]; then
1702 elif [ "$3" == "STD" ]; then
1703 targetJson="{\"enforceStatus\":\"$4\""
1704 if [ $# -eq 5 ]; then
1705 targetJson=$targetJson",\"reason\":\"$5\""
1707 targetJson=$targetJson"}"
1708 elif [ "$3" == "STD2" ]; then
1709 if [ $4 == "EMPTY" ]; then
1710 targetJson="{\"enforceStatus\":\"\""
1712 targetJson="{\"enforceStatus\":\"$4\""
1714 if [ $# -eq 5 ]; then
1715 if [ $5 == "EMPTY" ]; then
1716 targetJson=$targetJson",\"enforceReason\":\"\""
1718 targetJson=$targetJson",\"enforceReason\":\"$5\""
1721 targetJson=$targetJson"}"
1722 elif [ "$3" == "OSC" ]; then
1723 targetJson="{\"instance_status\":\"$4\""
1724 if [ $# -eq 5 ]; then
1725 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1727 targetJson=$targetJson",\"created_at\":\"????\"}"
1729 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1733 if [ "$A1PMS_VERSION" == "V2" ]; then
1734 query="/v2/policies/$UUID$2/status"
1735 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1737 query="/policy_status?id="$UUID$2
1740 res="$(__do_curl_to_api A1PMS GET $query)"
1741 status=${res:${#res}-3}
1743 if [ $status -ne $1 ]; then
1744 __log_test_fail_status_code $1 $status
1747 if [ $# -gt 2 ]; then
1748 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1749 body=${res:0:${#res}-3}
1750 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1752 if [ $res -ne 0 ]; then
1753 __log_test_fail_body
1757 __collect_endpoint_stats "A1PMS" 08 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}/status" $status
1762 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1763 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1764 # (Function for test scripts)
1765 a1pms_api_get_policy_types() {
1768 if [ $# -lt 1 ]; then
1769 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1773 if [ "$A1PMS_VERSION" == "V2" ]; then
1774 if [ $# -eq 1 ]; then
1775 query="/v2/policy-types"
1776 elif [ $2 == "NORIC" ]; then
1777 query="/v2/policy-types"
1779 query="/v2/policy-types?ric_id=$2"
1782 if [ $# -eq 1 ]; then
1783 query="/policy_types"
1784 elif [ $2 == "NORIC" ]; then
1785 query="/policy_types"
1787 query="/policy_types?ric=$2"
1791 res="$(__do_curl_to_api A1PMS GET $query)"
1792 status=${res:${#res}-3}
1794 if [ $status -ne $1 ]; then
1795 __log_test_fail_status_code $1 $status
1799 if [ $# -gt 2 ]; then
1800 body=${res:0:${#res}-3}
1803 for pid in ${@:3} ; do
1804 if [ "$targetJson" != "[" ]; then
1805 targetJson=$targetJson","
1807 if [ $pid == "EMPTY" ]; then
1810 targetJson=$targetJson"\"$pid\""
1813 targetJson=$targetJson"]"
1814 if [ "$A1PMS_VERSION" == "V2" ]; then
1815 targetJson="{\"policytype_ids\": $targetJson }"
1817 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1818 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1820 if [ $res -ne 0 ]; then
1821 __log_test_fail_body
1826 __collect_endpoint_stats "A1PMS" 09 "GET" $A1PMS_API_PREFIX"/v2/policy-types" $status
1831 #########################################################
1832 #### Test case functions Health check
1833 #########################################################
1835 # API Test function: GET /status and V2 GET /status
1836 # args: <response-code>
1837 # (Function for test scripts)
1838 a1pms_api_get_status() {
1840 if [ $# -ne 1 ]; then
1841 __print_err "<response-code>" $@
1844 if [ "$A1PMS_VERSION" == "V2" ]; then
1849 res="$(__do_curl_to_api A1PMS GET $query)"
1850 status=${res:${#res}-3}
1852 if [ $status -ne $1 ]; then
1853 __log_test_fail_status_code $1 $status
1857 __collect_endpoint_stats "A1PMS" 10 "GET" $A1PMS_API_PREFIX"/v2/status" $status
1862 # API Test function: GET /status (root) without api prefix
1863 # args: <response-code>
1864 # (Function for test scripts)
1865 a1pms_api_get_status_root() {
1867 if [ $# -ne 1 ]; then
1868 __print_err "<response-code>" $@
1872 TMP_PREFIX=$A1PMS_API_PREFIX
1874 res="$(__do_curl_to_api A1PMS GET $query)"
1875 A1PMS_API_PREFIX=$TMP_PREFIX
1876 status=${res:${#res}-3}
1878 if [ $status -ne $1 ]; then
1879 __log_test_fail_status_code $1 $status
1883 __collect_endpoint_stats "A1PMS" 19 "GET" "/status" $status
1888 #########################################################
1889 #### Test case functions RIC Repository
1890 #########################################################
1892 # API Test function: GET /ric and V2 GET /v2/rics/ric
1893 # args: <reponse-code> <management-element-id> [<ric-id>]
1894 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1895 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1896 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1899 # (Function for test scripts)
1900 a1pms_api_get_ric() {
1903 if [ "$A1PMS_VERSION" == "V2" ]; then
1904 if [ $# -lt 3 ]; then
1905 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1909 if [ $2 != "NOME" ]; then
1910 search="?managed_element_id="$2
1912 if [ $3 != "NORIC" ]; then
1913 if [ -z $search ]; then
1916 search=$search"&ric_id="$3
1919 query="/v2/rics/ric"$search
1921 res="$(__do_curl_to_api A1PMS GET $query)"
1922 status=${res:${#res}-3}
1924 if [ $status -ne $1 ]; then
1925 __log_test_fail_status_code $1 $status
1929 if [ $# -gt 3 ]; then
1930 body=${res:0:${#res}-3}
1931 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1932 if [ $res -ne 0 ]; then
1933 __log_test_fail_general "Could not create target ric info json"
1937 targetJson=$(<./tmp/.tmp_rics.json)
1938 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1939 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1940 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1941 if [ $res -ne 0 ]; then
1942 __log_test_fail_body
1947 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1948 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1952 query="/ric?managedElementId="$2
1954 res="$(__do_curl_to_api A1PMS GET $query)"
1955 status=${res:${#res}-3}
1957 if [ $status -ne $1 ]; then
1958 __log_test_fail_status_code $1 $status
1962 if [ $# -eq 3 ]; then
1963 body=${res:0:${#res}-3}
1964 if [ "$body" != "$3" ]; then
1965 __log_test_fail_body
1971 __collect_endpoint_stats "A1PMS" 11 "GET" $A1PMS_API_PREFIX"/v2/rics/ric" $status
1976 # API test function: GET /rics and V2 GET /v2/rics
1977 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1978 # 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_........."
1979 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1980 # (Function for test scripts)
1981 a1pms_api_get_rics() {
1984 if [ $# -lt 2 ]; then
1985 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1989 if [ "$A1PMS_VERSION" == "V2" ]; then
1991 if [ $2 != "NOTYPE" ]; then
1992 query="/v2/rics?policytype_id="$2
1996 if [ $2 != "NOTYPE" ]; then
1997 query="/rics?policyType="$2
2001 res="$(__do_curl_to_api A1PMS GET $query)"
2002 status=${res:${#res}-3}
2004 if [ $status -ne $1 ]; then
2005 __log_test_fail_status_code $1 $status
2009 if [ $# -gt 2 ]; then
2010 body=${res:0:${#res}-3}
2011 if [ "$A1PMS_VERSION" == "V2" ]; then
2012 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
2014 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
2016 if [ $res -ne 0 ]; then
2017 __log_test_fail_general "Could not create target ric info json"
2021 targetJson=$(<./tmp/.tmp_rics.json)
2022 if [ "$A1PMS_VERSION" == "V2" ]; then
2023 targetJson="{\"rics\": $targetJson }"
2025 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2026 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2027 if [ $res -ne 0 ]; then
2028 __log_test_fail_body
2033 __collect_endpoint_stats "A1PMS" 12 "GET" $A1PMS_API_PREFIX"/v2/rics" $status
2038 ##################################################################
2039 #### API Test case functions Service registry and supervision ####
2040 ##################################################################
2042 # API test function: PUT /service and V2 PUT /service
2043 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
2044 # (Function for test scripts)
2045 a1pms_api_put_service() {
2047 if [ $# -ne 4 ]; then
2048 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
2052 if [ "$A1PMS_VERSION" == "V2" ]; then
2053 query="/v2/services"
2054 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
2057 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
2059 file="./tmp/.tmp.json"
2060 echo "$json" > $file
2062 res="$(__do_curl_to_api A1PMS PUT $query $file)"
2063 status=${res:${#res}-3}
2065 if [ $status -ne $1 ]; then
2066 __log_test_fail_status_code $1 $status
2070 __collect_endpoint_stats "A1PMS" 13 "PUT" $A1PMS_API_PREFIX"/v2/service" $status
2075 # API test function: GET /services and V2 GET /v2/services
2076 #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>]* )]
2077 # (Function for test scripts)
2078 a1pms_api_get_services() {
2080 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
2082 if [ $# -eq 1 ]; then
2084 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
2086 elif [ $# -eq 5 ]; then
2088 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
2090 if [ $(($argLen%3)) -eq 0 ]; then
2095 if [ $paramError -ne 0 ]; then
2096 __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>]* )]" $@
2100 if [ "$A1PMS_VERSION" == "V2" ]; then
2101 query="/v2/services"
2103 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2104 query="/v2/services?service_id="$2
2109 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2110 query="/services?name="$2
2113 res="$(__do_curl_to_api A1PMS GET $query)"
2114 status=${res:${#res}-3}
2116 if [ $status -ne $1 ]; then
2117 __log_test_fail_status_code $1 $status
2121 if [ $# -gt 2 ]; then
2122 variableArgCount=$(($#-2))
2123 body=${res:0:${#res}-3}
2127 while [ $cntr -lt $variableArgCount ]; do
2128 servicename=$1; shift;
2131 if [ $cntr -gt 0 ]; then
2132 targetJson=$targetJson","
2134 # timeSinceLastActivitySeconds value cannot be checked since value varies
2135 if [ "$A1PMS_VERSION" == "V2" ]; then
2136 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
2138 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2142 targetJson=$targetJson"]"
2143 if [ "$A1PMS_VERSION" == "V2" ]; then
2144 targetJson="{\"service_list\": $targetJson }"
2146 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2147 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2148 if [ $res -ne 0 ]; then
2149 __log_test_fail_body
2154 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX"/v2/services" $status
2159 # API test function: GET /services V2 GET /v2/services - (only checking service names)
2160 # args: <response-code> [<service-name>]*"
2161 # (Function for test scripts)
2162 a1pms_api_get_service_ids() {
2165 if [ $# -lt 1 ]; then
2166 __print_err "<response-code> [<service-name>]*" $@
2170 if [ "$A1PMS_VERSION" == "V2" ]; then
2171 query="/v2/services"
2175 res="$(__do_curl_to_api A1PMS GET $query)"
2176 status=${res:${#res}-3}
2178 if [ $status -ne $1 ]; then
2179 __log_test_fail_status_code $1 $status
2183 body=${res:0:${#res}-3}
2185 for rapp in ${@:2} ; do
2186 if [ "$targetJson" != "[" ]; then
2187 targetJson=$targetJson","
2189 if [ "$A1PMS_VERSION" == "V2" ]; then
2190 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2192 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2196 targetJson=$targetJson"]"
2197 if [ "$A1PMS_VERSION" == "V2" ]; then
2198 targetJson="{\"service_list\": $targetJson }"
2200 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2201 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2203 if [ $res -ne 0 ]; then
2204 __log_test_fail_body
2208 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX"/v2/services" $status
2213 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
2214 # args: <response-code> <service-name>
2215 # (Function for test scripts)
2216 a1pms_api_delete_services() {
2219 if [ $# -ne 2 ]; then
2220 __print_err "<response-code> <service-name>" $@
2223 if [ "$A1PMS_VERSION" == "V2" ]; then
2224 query="/v2/services/"$2
2226 query="/services?name="$2
2228 res="$(__do_curl_to_api A1PMS DELETE $query)"
2229 status=${res:${#res}-3}
2231 if [ $status -ne $1 ]; then
2232 __log_test_fail_status_code $1 $status
2236 __collect_endpoint_stats "A1PMS" 15 "DELETE" $A1PMS_API_PREFIX"/v2/services/{serviceId}" $status
2241 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
2242 # args: <response-code> <service-name>
2243 # (Function for test scripts)
2244 a1pms_api_put_services_keepalive() {
2247 if [ $# -ne 2 ]; then
2248 __print_err "<response-code> <service-name>" $@
2251 if [ "$A1PMS_VERSION" == "V2" ]; then
2252 query="/v2/services/$2/keepalive"
2254 query="/services/keepalive?name="$2
2257 res="$(__do_curl_to_api A1PMS PUT $query)"
2258 status=${res:${#res}-3}
2260 if [ $status -ne $1 ]; then
2261 __log_test_fail_status_code $1 $status
2265 __collect_endpoint_stats "A1PMS" 16 "PUT" $A1PMS_API_PREFIX"/v2/services/{service_id}/keepalive" $status
2270 ##################################################################
2271 #### API Test case functions Configuration ####
2272 ##################################################################
2274 # API Test function: PUT /v2/configuration
2275 # args: <response-code> <config-file>
2276 # (Function for test scripts)
2277 a1pms_api_put_configuration() {
2280 if [ "$A1PMS_VERSION" != "V2" ]; then
2281 __log_test_fail_not_supported
2285 if [ $# -ne 2 ]; then
2286 __print_err "<response-code> <config-file>" $@
2289 if [ ! -f $2 ]; then
2290 __log_test_fail_general "Config file "$2", does not exist"
2294 # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
2295 # inputJson="{\"config\":"$inputJson"}"
2297 file="./tmp/.config.json"
2298 echo $inputJson > $file
2299 query="/v2/configuration"
2300 res="$(__do_curl_to_api A1PMS PUT $query $file)"
2301 status=${res:${#res}-3}
2303 if [ $status -ne $1 ]; then
2304 __log_test_fail_status_code $1 $status
2308 __collect_endpoint_stats "A1PMS" 17 "PUT" $A1PMS_API_PREFIX"/v2/configuration" $status
2313 # API Test function: GET /v2/configuration
2314 # args: <response-code> [<config-file>]
2315 # (Function for test scripts)
2316 a1pms_api_get_configuration() {
2319 if [ "$A1PMS_VERSION" != "V2" ]; then
2320 __log_test_fail_not_supported
2324 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2325 __print_err "<response-code> [<config-file>]" $@
2328 if [ ! -f $2 ]; then
2329 __log_test_fail_general "Config file "$2" for comparison, does not exist"
2333 query="/v2/configuration"
2334 res="$(__do_curl_to_api A1PMS GET $query)"
2335 status=${res:${#res}-3}
2337 if [ $status -ne $1 ]; then
2338 __log_test_fail_status_code $1 $status
2342 if [ $# -eq 2 ]; then
2344 body=${res:0:${#res}-3}
2347 # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
2348 # inputJson="{\"config\":"$inputJson"}"
2350 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2351 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2353 if [ $res -ne 0 ]; then
2354 __log_test_fail_body
2359 __collect_endpoint_stats "A1PMS" 18 "GET" $A1PMS_API_PREFIX"/v2/configuration" $status
2364 ##########################################
2365 #### Reset types and instances ####
2366 ##########################################
2368 # Admin reset to remove all policies and services
2369 # All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2370 # NOTE - only works in kubernetes and the pod should not be running
2372 # (Function for test scripts)
2374 a1pms_kube_pvc_reset() {
2377 pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
2378 if [ -z "$pvc_name" ]; then
2379 pvc_name=policymanagementservice-vardata-pvc
2381 echo " Trying to reset pvc: "$pvc_name
2382 __kube_clean_pvc $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $A1PMS_CONTAINER_MNT_DIR
2388 # args: <realm> <client-name> <client-secret>
2389 a1pms_configure_sec() {
2390 export A1PMS_CREDS_GRANT_TYPE="client_credentials"
2391 export A1PMS_CREDS_CLIENT_SECRET=$3
2392 export A1PMS_CREDS_CLIENT_ID=$2
2393 export A1PMS_AUTH_SERVICE_URL=$KEYCLOAK_SERVICE_PATH$KEYCLOAK_TOKEN_URL_PREFIX/$1/protocol/openid-connect/token
2394 export A1PMS_SIDECAR_MOUNT="/token-cache"
2395 export A1PMS_SIDECAR_JWT_FILE=$A1PMS_SIDECAR_MOUNT"/jwt.txt"
2397 export AUTHSIDECAR_APP_NAME
2398 export AUTHSIDECAR_DISPLAY_NAME