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
201 export CONSUL_INTERNAL_PORT
202 export CONFIG_BINDING_SERVICE
203 export A1PMS_CONFIG_KEY
204 export DOCKER_SIM_NWNAME
205 export A1PMS_HOST_MNT_DIR
206 export A1PMS_CONFIG_FILE
208 export A1PMS_DATA_PV_NAME=$A1PMS_APP_NAME"-pv"
209 export A1PMS_DATA_PVC_NAME=$A1PMS_APP_NAME"-pvc"
210 ##Create a unique path for the pv each time to prevent a previous volume to be reused
211 export A1PMS_PV_PATH="a1pmsdata-"$(date +%s)
212 export A1PMS_CONTAINER_MNT_DIR
213 export HOST_PATH_BASE_DIR
215 if [ $1 == "PROXY" ]; then
216 export A1PMS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
217 export A1PMS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
218 if [ $A1PMS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$A1PMS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
219 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
221 echo " Configured with http proxy"
224 export A1PMS_HTTP_PROXY_CONFIG_PORT=0
225 export A1PMS_HTTP_PROXY_CONFIG_HOST_NAME=""
226 echo " Configured without http proxy"
232 # args: (docker) PROXY|NOPROXY <config-file>
233 # args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
234 # (Function for test scripts)
236 echo -e $BOLD"Starting $A1PMS_DISPLAY_NAME"$EBOLD
238 if [ $RUNMODE == "KUBE" ]; then
240 # Check if app shall be fully managed by the test script
241 __check_included_image "A1PMS"
244 # Check if app shall only be used by the testscipt
245 __check_prestarted_image "A1PMS"
248 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
249 echo -e $RED"The $A1PMS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
250 echo -e $RED"The $A1PMS_APP_NAME will not be started"$ERED
253 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
254 echo -e $RED"The $A1PMS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
255 echo -e $RED"The $A1PMS_APP_NAME will not be started"$ERED
259 if [ $retcode_p -eq 0 ]; then
260 echo -e " Using existing $A1PMS_APP_NAME deployment and service"
261 echo " Setting $A1PMS_APP_NAME replicas=1"
262 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
263 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
266 if [ $retcode_i -eq 0 ]; then
268 echo -e " Creating $A1PMS_APP_NAME app and expose service"
270 #Check if nonrtric namespace exists, if not create it
271 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
273 __export_a1pms_vars $1
275 # Create config map for config
276 configfile=$PWD/tmp/$A1PMS_CONFIG_FILE
278 output_yaml=$PWD/tmp/a1pms-cfc.yaml
279 __kube_create_configmap $A1PMS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $configfile $output_yaml
281 # Create config map for data
282 data_json=$PWD/tmp/$A1PMS_DATA_FILE
283 if [ $# -lt 3 ]; then
284 #create empty dummy file
285 echo "{}" > $data_json
289 output_yaml=$PWD/tmp/a1pms-cfd.yaml
290 __kube_create_configmap $A1PMS_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $data_json $output_yaml
293 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"pv.yaml
294 output_yaml=$PWD/tmp/a1pms-pv.yaml
295 __kube_create_instance pv $A1PMS_APP_NAME $input_yaml $output_yaml
298 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"pvc.yaml
299 output_yaml=$PWD/tmp/a1pms-pvc.yaml
300 __kube_create_instance pvc $A1PMS_APP_NAME $input_yaml $output_yaml
303 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"svc.yaml
304 output_yaml=$PWD/tmp/a1pmssvc.yaml
305 __kube_create_instance service $A1PMS_APP_NAME $input_yaml $output_yaml
308 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"app.yaml
309 output_yaml=$PWD/tmp/a1pmsapp.yaml
310 if [ -z "$A1PMS_SIDECAR_JWT_FILE" ]; then
311 cat $input_yaml | sed '/#A1PMS_JWT_START/,/#A1PMS_JWT_STOP/d' > $PWD/tmp/a1pmsapp_tmp.yaml
312 input_yaml=$PWD/tmp/a1pmsapp_tmp.yaml
314 __kube_create_instance app $A1PMS_APP_NAME $input_yaml $output_yaml
318 # 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
319 if [ $retcode_i -eq 0 ]; then
320 __A1PMS_WORKER_NODE=$(kubectl $KUBECONF get pod -l "autotest=A1PMS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
321 if [ -z "$__A1PMS_WORKER_NODE" ]; then
322 echo -e $YELLOW" Cannot find worker node for pod for $A1PMS_APP_NAME, persistency may not work"$EYELLOW
325 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
328 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
331 __check_included_image 'A1PMS'
332 if [ $? -eq 1 ]; then
333 echo -e $RED"The A1PMS app is not included in this test script"$ERED
334 echo -e $RED"The A1PMS will not be started"$ERED
341 cd $A1PMS_HOST_MNT_DIR
344 if [ "$(ls -A $DIR)" ]; then
345 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
346 rm -rf db/* &> /dev/null
347 if [ $? -ne 0 ]; then
348 echo -e $RED" Cannot remove database files in: $PWD"$ERED
353 echo " No files in mounted dir or dir does not exists"
358 __export_a1pms_vars $1
360 dest_file=$SIM_GROUP/$A1PMS_COMPOSE_DIR/$A1PMS_HOST_MNT_DIR/application.yaml
362 envsubst < $2 > $dest_file
364 __start_container $A1PMS_COMPOSE_DIR "" NODOCKERARGS 1 $A1PMS_APP_NAME
366 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
369 __collect_endpoint_stats_image_info "A1PMS" $A1PMS_IMAGE
377 # (Function for test scripts)
379 echo -e $BOLD"Stopping $A1PMS_DISPLAY_NAME"$EBOLD
381 if [ $RUNMODE == "KUBE" ]; then
383 __check_prestarted_image "A1PMS"
384 if [ $? -eq 0 ]; then
385 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
386 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
387 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
390 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS
391 echo " Deleting the replica set - a new will be started when the app is started"
392 tmp=$(kubectl $KUBECONF delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
393 if [ $? -ne 0 ]; then
394 echo -e $RED" Could not delete replica set "$RED
399 docker stop $A1PMS_APP_NAME &> ./tmp/.dockererr
400 if [ $? -ne 0 ]; then
401 __print_err "Could not stop $A1PMS_APP_NAME" $@
407 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
412 # Start a previously stopped a1pms
414 # (Function for test scripts)
415 start_stopped_a1pms() {
416 echo -e $BOLD"Starting (the previously stopped) $A1PMS_DISPLAY_NAME"$EBOLD
418 if [ $RUNMODE == "KUBE" ]; then
420 __check_prestarted_image "A1PMS"
421 if [ $? -eq 0 ]; then
422 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
423 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
424 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
425 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
429 # Tie the A1PMS to the same worker node it was initially started on
430 # 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
431 if [ -z "$__A1PMS_WORKER_NODE" ]; then
432 echo -e $RED" No initial worker node found for pod "$RED
436 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
437 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
438 tmp=$(kubectl $KUBECONF patch deployment $A1PMS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__A1PMS_WORKER_NODE'"}}}}}')
439 if [ $? -ne 0 ]; then
440 echo -e $YELLOW" Cannot set nodeSelector to deployment for $A1PMS_APP_NAME, persistency may not work"$EYELLOW
442 __kube_scale deployment $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
445 docker start $A1PMS_APP_NAME &> ./tmp/.dockererr
446 if [ $? -ne 0 ]; then
447 __print_err "Could not start (the stopped) $A1PMS_APP_NAME" $@
453 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
454 if [ $? -ne 0 ]; then
462 # Function to perpare the consul configuration according to the current simulator configuration
463 # args: SDNC|NOSDNC <output-file>
464 # (Function for test scripts)
465 prepare_consul_config() {
466 echo -e $BOLD"Prepare Consul config"$EBOLD
468 echo " Writing consul config for "$A1PMS_APP_NAME" to file: "$2
472 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
476 if [ $1 == "SDNC" ]; then
477 echo -e " Config$BOLD including SDNC$EBOLD configuration"
478 elif [ $1 == "NOSDNC" ]; then
479 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
482 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
487 if [ $1 == "SDNC" ]; then
488 config_json=$config_json"\n \"controller\": ["
489 config_json=$config_json"\n {"
490 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
491 config_json=$config_json"\n \"baseUrl\": \"$SDNC_SERVICE_PATH\","
492 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
493 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
494 config_json=$config_json"\n }"
495 config_json=$config_json"\n ],"
498 config_json=$config_json"\n \"streams_publishes\": {"
499 config_json=$config_json"\n \"dmaap_publisher\": {"
500 config_json=$config_json"\n \"type\": \"message-router\","
501 config_json=$config_json"\n \"dmaap_info\": {"
502 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_WRITE_URL\""
503 config_json=$config_json"\n }"
504 config_json=$config_json"\n }"
505 config_json=$config_json"\n },"
506 config_json=$config_json"\n \"streams_subscribes\": {"
507 config_json=$config_json"\n \"dmaap_subscriber\": {"
508 config_json=$config_json"\n \"type\": \"message-router\","
509 config_json=$config_json"\n \"dmaap_info\": {"
510 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_READ_URL\""
511 config_json=$config_json"\n }"
512 config_json=$config_json"\n }"
513 config_json=$config_json"\n },"
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 if [ $ric_cntr -eq 0 ]; then
531 echo $YELLOW"Warning: No rics found for the configuration"$EYELLOW
534 rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "status=running" --format {{.Names}})
535 if [ $? -ne 0 ] || [ -z "$rics" ]; then
536 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
543 if [ $cntr -gt 0 ]; then
544 config_json=$config_json"\n ,"
546 config_json=$config_json"\n {"
547 if [ $RUNMODE == "KUBE" ]; then
548 ric_id=${ric%.*.*} #extract pod id from full hosthame
549 ric_id=$(echo "$ric_id" | tr '-' '_')
551 if [ $DOCKER_COMPOSE_VERSION == "V1" ]; then
554 ric_id=$(echo "$ric" | tr '-' '_') #ric id still needs underscore as it is different from the container name
557 echo " Found a1 sim: "$ric_id
558 config_json=$config_json"\n \"name\": \"$ric_id\","
559 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
560 if [ $1 == "SDNC" ]; then
561 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
563 config_json=$config_json"\n \"managedElementIds\": ["
564 config_json=$config_json"\n \"me1_$ric_id\","
565 config_json=$config_json"\n \"me2_$ric_id\""
566 config_json=$config_json"\n ]"
567 config_json=$config_json"\n }"
571 config_json=$config_json"\n ]"
572 config_json=$config_json"\n}"
574 if [ $RUNMODE == "KUBE" ]; then
575 config_json="{\"config\":"$config_json"}"
578 printf "$config_json">$2
583 # Load the the appl config for the a1pms into a config map
584 a1pms_load_config() {
585 echo -e $BOLD"A1PMS - load config from "$EBOLD$1
586 data_json=$PWD/tmp/$A1PMS_DATA_FILE
588 output_yaml=$PWD/tmp/a1pms-cfd.yaml
589 __kube_create_configmap $A1PMS_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $data_json $output_yaml
594 # Turn on debug level tracing in the a1pms
596 # (Function for test scripts)
598 echo -e $BOLD"Setting a1pms debug logging"$EBOLD
599 curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
600 result=$(__do_curl "$curlString")
601 if [ $? -ne 0 ]; then
602 __print_err "could not set debug mode" $@
610 # Turn on trace level tracing in the a1pms
612 # (Function for test scripts)
614 echo -e $BOLD"Setting a1pms trace logging"$EBOLD
615 curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
616 result=$(__do_curl "$curlString")
617 if [ $? -ne 0 ]; then
618 __print_err "could not set trace mode" $@
626 # Perform curl retries when making direct call to the a1pms for the specified http response codes
627 # Speace separated list of http response codes
628 # args: [<response-code>]*
629 use_a1pms_retries() {
630 echo -e $BOLD"Do curl retries to the a1pms REST inteface for these response codes:$@"$EBOLD
636 # Check the a1pms logs for WARNINGs and ERRORs
638 # (Function for test scripts)
640 __check_container_logs "A1PMS" $A1PMS_APP_NAME $A1PMS_LOGPATH WARN ERR
643 #########################################################
644 #### Test case functions A1 Policy management service
645 #########################################################
647 # This function compare the size, towards a target value, of a json array returned from <url> of the A1PMS.
648 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
649 # args: json:<url> <target-value> [<timeout-in-seconds]
650 # (Function for test scripts)
652 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
653 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
654 if [[ $1 == "json:"* ]]; then
655 if [ "$A1PMS_VERSION" == "V2" ]; then
656 __var_test "A1PMS" $A1PMS_SERVICE_PATH$A1PMS_API_PREFIX"/v2/" $1 "=" $2 $3
658 __var_test "A1PMS" $A1PMS_SERVICE_PATH"/" $1 "=" $2 $3
663 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
667 # API Test function: GET /policies and V2 GET /v2/policy-instances
668 # 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>]*]
669 # 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>]*]
670 # (Function for test scripts)
671 a1pms_api_get_policies() {
674 if [ "$A1PMS_VERSION" == "V2" ]; then
676 variableParams=$(($#-4))
677 if [ $# -lt 4 ]; then
679 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
681 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
685 if [ $paramError -ne 0 ]; then
686 __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>]*]" $@
691 variableParams=$(($#-4))
692 if [ $# -lt 4 ]; then
694 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
696 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
700 if [ $paramError -ne 0 ]; then
701 __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>]*]" $@
707 if [ "$A1PMS_VERSION" == "V2" ]; then
708 if [ $2 != "NORIC" ]; then
709 queryparams="?ric_id="$2
711 if [ $3 != "NOSERVICE" ]; then
712 if [ -z $queryparams ]; then
713 queryparams="?service_id="$3
715 queryparams=$queryparams"&service_id="$3
718 if [ $4 != "NOTYPE" ]; then
719 if [ -z $queryparams ]; then
720 queryparams="?policytype_id="$4
722 queryparams=$queryparams"&policytype_id="$4
726 query="/v2/policy-instances"$queryparams
727 res="$(__do_curl_to_api A1PMS GET $query)"
728 status=${res:${#res}-3}
730 if [ $status -ne $1 ]; then
731 __log_test_fail_status_code $1 $status
735 if [ $# -gt 4 ]; then
736 body=${res:0:${#res}-3}
737 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
743 for ((i=0; i<$(($#-4)); i=i+7)); do
745 if [ "$targetJson" != "[" ]; then
746 targetJson=$targetJson","
748 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
749 if [ "${arr[$i+3]}" == "EMPTY" ]; then
750 targetJson=$targetJson"\"\","
752 targetJson=$targetJson"\"${arr[$i+3]}\","
754 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
756 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
758 targetJson=$targetJson"\"policy_data\":"$json"}"
762 targetJson=$targetJson"]"
763 targetJson="{\"policies\": $targetJson}"
764 echo "TARGET JSON: $targetJson" >> $HTTPLOG
765 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
767 if [ $res -ne 0 ]; then
773 if [ $2 != "NORIC" ]; then
774 queryparams="?ric="$2
776 if [ $3 != "NOSERVICE" ]; then
777 if [ -z $queryparams ]; then
778 queryparams="?service="$3
780 queryparams=$queryparams"&service="$3
783 if [ $4 != "NOTYPE" ]; then
784 if [ -z $queryparams ]; then
785 queryparams="?type="$4
787 queryparams=$queryparams"&type="$4
791 query="/policies"$queryparams
792 res="$(__do_curl_to_api A1PMS GET $query)"
793 status=${res:${#res}-3}
795 if [ $status -ne $1 ]; then
796 __log_test_fail_status_code $1 $status
800 if [ $# -gt 4 ]; then
801 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
804 body=${res:0:${#res}-3}
808 for ((i=0; i<$(($#-4)); i=i+5)); do
810 if [ "$targetJson" != "[" ]; then
811 targetJson=$targetJson","
813 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
814 if [ "${arr[$i+3]}" == "EMPTY" ]; then
815 targetJson=$targetJson"\"\","
817 targetJson=$targetJson"\"${arr[$i+3]}\","
820 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
822 targetJson=$targetJson"\"json\":"$json"}"
826 targetJson=$targetJson"]"
827 echo "TARGET JSON: $targetJson" >> $HTTPLOG
828 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
830 if [ $res -ne 0 ]; then
836 __collect_endpoint_stats "A1PMS" 00 "GET" $A1PMS_API_PREFIX"/v2/policy-instances" $status
843 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
844 # args: <response-code> <policy-id> [<template-file>]
845 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
847 # (Function for test scripts)
848 a1pms_api_get_policy() {
852 if [ "$A1PMS_VERSION" == "V2" ]; then
853 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
854 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
857 query="/v2/policies/$UUID$2"
859 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
860 __print_err "<response-code> <policy-id> [<template-file>] " $@
863 query="/policy?id=$UUID$2"
865 res="$(__do_curl_to_api A1PMS GET $query)"
866 status=${res:${#res}-3}
868 if [ $status -ne $1 ]; then
869 __log_test_fail_status_code $1 $status
873 if [ "$A1PMS_VERSION" == "V2" ]; then
874 if [ $# -eq 8 ]; then
876 #Create a policy json to compare with
877 body=${res:0:${#res}-3}
879 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
880 if [ $7 != "NOTRANSIENT" ]; then
881 targetJson=$targetJson", \"transient\":$7"
883 if [ $6 != "NOTYPE" ]; then
884 targetJson=$targetJson", \"policytype_id\":\"$6\""
886 targetJson=$targetJson", \"policytype_id\":\"\""
888 if [ $8 != "NOURL" ]; then
889 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
892 data=$(sed 's/XXX/'${2}'/g' $3)
893 targetJson=$targetJson", \"policy_data\":$data"
894 targetJson="{$targetJson}"
896 echo "TARGET JSON: $targetJson" >> $HTTPLOG
897 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
898 if [ $res -ne 0 ]; then
904 if [ $# -eq 3 ]; then
905 #Create a policy json to compare with
906 body=${res:0:${#res}-3}
908 sed 's/XXX/'${2}'/g' $3 > $file
909 targetJson=$(< $file)
910 echo "TARGET JSON: $targetJson" >> $HTTPLOG
911 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
912 if [ $res -ne 0 ]; then
918 __collect_endpoint_stats "A1PMS" 01 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $status
923 # API Test function: PUT /policy and V2 PUT /policies
924 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
925 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
926 # (Function for test scripts)
927 a1pms_api_put_policy() {
930 if [ "$A1PMS_VERSION" == "V2" ]; then
931 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
932 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
936 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
937 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
950 if [ "$A1PMS_VERSION" == "V2" ]; then
953 if [ $# -eq 9 ]; then
958 if [ $# -eq 8 ]; then
963 while [ $count -lt $max ]; do
964 if [ "$A1PMS_VERSION" == "V2" ]; then
968 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
969 if [ $trans != "NOTRANSIENT" ]; then
970 inputJson=$inputJson", \"transient\":$trans"
972 if [ $pt != "NOTYPE" ]; then
973 inputJson=$inputJson", \"policytype_id\":\"$pt\""
975 inputJson=$inputJson", \"policytype_id\":\"\""
977 if [ $noti != "NOURL" ]; then
978 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
981 data=$(sed 's/XXX/'${pid}'/g' $temp)
982 inputJson=$inputJson", \"policy_data\":$data"
983 inputJson="{$inputJson}"
984 echo $inputJson > $file
986 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
988 if [ $pt != "NOTYPE" ]; then
989 query=$query"&type=$pt"
992 if [ $trans != NOTRANSIENT ]; then
993 query=$query"&transient=$trans"
997 sed 's/XXX/'${pid}'/g' $temp > $file
999 res="$(__do_curl_to_api A1PMS PUT $query $file)"
1000 status=${res:${#res}-3}
1001 echo -ne " Executing "$count"("$max")${SAMELINE}"
1002 if [ $status -ne $1 ]; then
1003 echo " Executed "$count"?("$max")"
1004 __log_test_fail_status_code $1 $status
1009 echo -ne " Executed "$count"("$max")${SAMELINE}"
1011 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $status $max
1018 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
1019 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
1020 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
1021 # (Function for test scripts)
1023 a1pms_api_put_policy_batch() {
1026 if [ "$A1PMS_VERSION" == "V2" ]; then
1027 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1028 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
1032 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1033 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
1045 if [ "$A1PMS_VERSION" == "V2" ]; then
1048 if [ $# -eq 9 ]; then
1053 if [ $# -eq 8 ]; then
1059 while [ $count -lt $max ]; do
1060 if [ "$A1PMS_VERSION" == "V2" ]; then
1061 query="/v2/policies"
1063 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1064 if [ $trans != "NOTRANSIENT" ]; then
1065 inputJson=$inputJson", \"transient\":$trans"
1067 if [ $pt != "NOTYPE" ]; then
1068 inputJson=$inputJson", \"policytype_id\":\"$pt\""
1070 inputJson=$inputJson", \"policytype_id\":\"\""
1072 if [ $noti != "NOURL" ]; then
1073 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1075 file="./tmp/.p.json"
1076 data=$(sed 's/XXX/'${pid}'/g' $temp)
1077 inputJson=$inputJson", \"policy_data\":$data"
1078 inputJson="{$inputJson}"
1079 echo $inputJson > $file
1081 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
1083 if [ $pt != "NOTYPE" ]; then
1084 query=$query"&type=$pt"
1087 if [ $trans != NOTRANSIENT ]; then
1088 query=$query"&transient=$trans"
1090 file="./tmp/.p.json"
1091 sed 's/XXX/'${pid}'/g' $temp > $file
1093 res="$(__do_curl_to_api A1PMS PUT_BATCH $query $file)"
1094 status=${res:${#res}-3}
1095 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1097 if [ $status -ne 200 ]; then
1098 echo " Requested(batch) "$count"?("$max")"
1099 __log_test_fail_status_code 200 $status
1102 cid=${res:0:${#res}-3}
1106 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1113 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1114 status=${res:${#res}-3}
1115 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
1117 if [ $status -ne $1 ]; then
1118 echo " Accepted(batch) "$count"?("$max")"
1119 __log_test_fail_status_code $1 $status
1124 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
1126 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $1 $max
1134 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
1135 # 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>
1136 # 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>
1137 # (Function for test scripts)
1138 a1pms_api_put_policy_parallel() {
1141 if [ "$A1PMS_VERSION" == "V2" ]; then
1142 if [ $# -ne 11 ]; then
1143 __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>" $@
1147 if [ $# -ne 10 ]; then
1148 __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>" $@
1152 resp_code=$1; shift;
1158 transient=$1; shift;
1159 if [ "$A1PMS_VERSION" == "V2" ]; then
1168 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1169 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1170 echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1171 echo " Info - will execute over a1pms REST"
1173 if [ "$A1PMS_VERSION" == "V2" ]; then
1174 if [ $serv == "NOSERVICE" ]; then
1177 query="$A1PMS_API_PREFIX/v2/policies"
1179 if [ $serv == "NOSERVICE" ]; then
1182 query="/policy?service=$serv"
1184 if [ $type != "NOTYPE" ]; then
1185 query=$query"&type=$type"
1188 if [ $transient != NOTRANSIENT ]; then
1189 query=$query"&transient=$transient"
1193 urlbase=${A1PMS_ADAPTER}${query}
1196 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1197 httpproxy=$KUBE_PROXY_PATH
1200 for ((i=1; i<=$pids; i++))
1203 if [ -z "$uuid" ]; then
1206 echo "" > "./tmp/.pid${i}.res.txt"
1207 if [ "$A1PMS_VERSION" == "V2" ]; then
1208 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1210 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1213 done | xargs -n 1 -I{} -P $pids bash -c '{
1215 echo " Parallel process $arg started"
1216 tmp=$(< "./tmp/.pid${arg}.txt")
1217 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1220 for ((i=1; i<=$pids; i++))
1222 file="./tmp/.pid${i}.res.txt"
1224 if [ -z "$tmp" ]; then
1225 echo " Process $i : unknown result (result file empty"
1229 if [ $res == "0" ]; then
1230 echo " Process $i : OK - "${tmp:1}
1232 echo " Process $i : failed - "${tmp:1}
1237 if [ -z $msg ]; then
1238 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $resp_code $(($count*$num_rics))
1239 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1243 __log_test_fail_general "One of more processes failed to execute"
1247 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
1248 # args: <response-code> <policy-id> [count]
1249 # (Function for test scripts)
1250 a1pms_api_delete_policy() {
1253 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1254 __print_err "<response-code> <policy-id> [count]" $@
1261 if [ $# -eq 3 ]; then
1267 while [ $count -lt $max ]; do
1268 if [ "$A1PMS_VERSION" == "V2" ]; then
1269 query="/v2/policies/"$UUID$pid
1271 query="/policy?id="$UUID$pid
1273 res="$(__do_curl_to_api A1PMS DELETE $query)"
1274 status=${res:${#res}-3}
1275 echo -ne " Executing "$count"("$max")${SAMELINE}"
1277 if [ $status -ne $1 ]; then
1278 echo " Executed "$count"?("$max")"
1279 __log_test_fail_status_code $1 $status
1285 echo -ne " Executed "$count"("$max")${SAMELINE}"
1287 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $status $max
1294 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
1295 # args: <response-code> <policy-id> [count]
1296 # (Function for test scripts)
1297 a1pms_api_delete_policy_batch() {
1300 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1301 __print_err "<response-code> <policy-id> [count]" $@
1308 if [ $# -eq 3 ]; then
1314 while [ $count -lt $max ]; do
1315 if [ "$A1PMS_VERSION" == "V2" ]; then
1316 query="/v2/policies/"$UUID$pid
1318 query="/policy?id="$UUID$pid
1320 res="$(__do_curl_to_api A1PMS DELETE_BATCH $query)"
1321 status=${res:${#res}-3}
1322 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1324 if [ $status -ne 200 ]; then
1325 echo " Requested(batch) "$count"?("$max")"
1326 __log_test_fail_status_code 200 $status
1329 cid=${res:0:${#res}-3}
1333 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1341 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1342 status=${res:${#res}-3}
1343 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1345 if [ $status -ne $1 ]; then
1346 echo " Deleted(batch) "$count"?("$max")"
1347 __log_test_fail_status_code $1 $status
1352 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1354 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $1 $max
1362 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1363 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1364 # (Function for test scripts)
1365 a1pms_api_delete_policy_parallel() {
1368 if [ $# -ne 5 ]; then
1369 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1372 resp_code=$1; shift;
1378 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1379 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1380 echo " Info - a1pms_api_delete_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1381 echo " Info - will execute over a1pms REST"
1384 if [ "$A1PMS_VERSION" == "V2" ]; then
1385 query="$A1PMS_API_PREFIX/v2/policies/"
1390 urlbase=${A1PMS_ADAPTER}${query}
1393 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1394 httpproxy=$KUBE_PROXY_PATH
1397 for ((i=1; i<=$pids; i++))
1400 if [ -z "$uuid" ]; then
1403 echo "" > "./tmp/.pid${i}.del.res.txt"
1404 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
1406 done | xargs -n 1 -I{} -P $pids bash -c '{
1408 echo " Parallel process $arg started"
1409 tmp=$(< "./tmp/.pid${arg}.del.txt")
1410 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1413 for ((i=1; i<=$pids; i++))
1415 file="./tmp/.pid${i}.del.res.txt"
1417 if [ -z "$tmp" ]; then
1418 echo " Process $i : unknown result (result file empty"
1422 if [ $res == "0" ]; then
1423 echo " Process $i : OK - "${tmp:1}
1425 echo " Process $i : failed - "${tmp:1}
1430 if [ -z $msg ]; then
1431 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count*$num_rics))
1432 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1436 __log_test_fail_general "One of more processes failed to execute"
1440 # API Test function: GET /policy_ids and V2 GET /v2/policies
1441 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1442 # (Function for test scripts)
1443 a1pms_api_get_policy_ids() {
1446 if [ $# -lt 4 ]; then
1447 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1453 if [ "$A1PMS_VERSION" == "V2" ]; then
1454 if [ $2 != "NORIC" ]; then
1455 queryparams="?ric_id="$2
1458 if [ $3 != "NOSERVICE" ]; then
1459 if [ -z $queryparams ]; then
1460 queryparams="?service_id="$3
1462 queryparams=$queryparams"&service_id="$3
1465 if [ $4 != "NOTYPE" ]; then
1466 if [ -z $queryparams ]; then
1467 queryparams="?policytype_id="$4
1469 queryparams=$queryparams"&policytype_id="$4
1473 query="/v2/policies"$queryparams
1475 if [ $2 != "NORIC" ]; then
1476 queryparams="?ric="$2
1479 if [ $3 != "NOSERVICE" ]; then
1480 if [ -z $queryparams ]; then
1481 queryparams="?service="$3
1483 queryparams=$queryparams"&service="$3
1486 if [ $4 != "NOTYPE" ]; then
1487 if [ -z $queryparams ]; then
1488 queryparams="?type="$4
1490 queryparams=$queryparams"&type="$4
1494 query="/policy_ids"$queryparams
1497 res="$(__do_curl_to_api A1PMS GET $query)"
1498 status=${res:${#res}-3}
1500 if [ $status -ne $1 ]; then
1501 __log_test_fail_status_code $1 $status
1505 if [ $# -gt 4 ]; then
1506 body=${res:0:${#res}-3}
1509 for pid in ${@:5} ; do
1510 if [ "$targetJson" != "[" ]; then
1511 targetJson=$targetJson","
1513 if [ $pid != "NOID" ]; then
1514 targetJson=$targetJson"\"$UUID$pid\""
1518 targetJson=$targetJson"]"
1519 if [ "$A1PMS_VERSION" == "V2" ]; then
1520 targetJson="{\"policy_ids\": $targetJson}"
1522 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1523 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1525 if [ $res -ne 0 ]; then
1526 __log_test_fail_body
1531 __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v2/policies" $status
1536 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
1537 # args(V2): <response-code> <policy-type-id> [<schema-file>]
1538 # (Function for test scripts)
1539 a1pms_api_get_policy_type() {
1542 if [ "$A1PMS_VERSION" != "V2" ]; then
1543 __log_test_fail_not_supported
1547 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1548 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1551 query="/v2/policy-types/$2"
1553 res="$(__do_curl_to_api A1PMS GET $query)"
1554 status=${res:${#res}-3}
1556 if [ $status -ne $1 ]; then
1557 __log_test_fail_status_code $1 $status
1561 if [ $# -eq 3 ]; then
1563 body=${res:0:${#res}-3}
1566 targetJson="{\"policy_schema\":$targetJson}"
1567 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1568 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1570 if [ $res -ne 0 ]; then
1571 __log_test_fail_body
1576 __collect_endpoint_stats "A1PMS" 05 "GET" $A1PMS_API_PREFIX"/v2/policy-types/{policyTypeId}" $status
1581 # API Test function: GET /policy_schema
1582 # args: <response-code> <policy-type-id> [<schema-file>]
1583 # (Function for test scripts)
1584 a1pms_api_get_policy_schema() {
1587 if [ "$A1PMS_VERSION" == "V2" ]; then
1588 __log_test_fail_not_supported
1592 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1593 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1596 query="/policy_schema?id=$2"
1597 res="$(__do_curl_to_api A1PMS GET $query)"
1598 status=${res:${#res}-3}
1600 if [ $status -ne $1 ]; then
1601 __log_test_fail_status_code $1 $status
1605 if [ $# -eq 3 ]; then
1607 body=${res:0:${#res}-3}
1611 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1612 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1614 if [ $res -ne 0 ]; then
1615 __log_test_fail_body
1620 __collect_endpoint_stats "A1PMS" 06 "GET" $A1PMS_API_PREFIX"/v2/policy_schema" $status
1625 # API Test function: GET /policy_schemas
1626 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
1627 # args(V2): <response-code>
1628 # (Function for test scripts)
1629 a1pms_api_get_policy_schemas() {
1632 if [ "$A1PMS_VERSION" == "V2" ]; then
1633 if [ $# -ne 1 ]; then
1634 __print_err "<response-code>" $@
1638 if [ $# -lt 2 ]; then
1639 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1643 if [ "$A1PMS_VERSION" == "V2" ]; then
1644 query="/v2/policy-schemas"
1646 query="/policy_schemas"
1647 if [ $2 != "NORIC" ]; then
1648 query=$query"?ric="$2
1652 res="$(__do_curl_to_api A1PMS GET $query)"
1653 status=${res:${#res}-3}
1655 if [ $status -ne $1 ]; then
1656 __log_test_fail_status_code $1 $status
1660 if [ $# -gt 2 ]; then
1661 body=${res:0:${#res}-3}
1664 for file in ${@:3} ; do
1665 if [ "$targetJson" != "[" ]; then
1666 targetJson=$targetJson","
1668 if [ $file == "NOFILE" ]; then
1669 targetJson=$targetJson"{}"
1671 targetJson=$targetJson$(< $file)
1675 targetJson=$targetJson"]"
1676 if [ "$A1PMS_VERSION" == "V2" ]; then
1677 targetJson="{\"policy_schemas\": $targetJson }"
1679 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1680 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1682 if [ $res -ne 0 ]; then
1683 __log_test_fail_body
1688 __collect_endpoint_stats "A1PMS" 07 "GET" $A1PMS_API_PREFIX"/v2/policy-schemas" $status
1693 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1694 # arg: <response-code> <policy-id> [ (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>) ]
1695 # (Function for test scripts)
1696 a1pms_api_get_policy_status() {
1699 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
1700 __print_err "<response-code> <policy-id> [(STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)]" $@
1705 if [ $# -eq 2 ]; then
1707 elif [ "$3" == "STD" ]; then
1708 targetJson="{\"enforceStatus\":\"$4\""
1709 if [ $# -eq 5 ]; then
1710 targetJson=$targetJson",\"reason\":\"$5\""
1712 targetJson=$targetJson"}"
1713 elif [ "$3" == "STD2" ]; then
1714 if [ $4 == "EMPTY" ]; then
1715 targetJson="{\"enforceStatus\":\"\""
1717 targetJson="{\"enforceStatus\":\"$4\""
1719 if [ $# -eq 5 ]; then
1720 if [ $5 == "EMPTY" ]; then
1721 targetJson=$targetJson",\"enforceReason\":\"\""
1723 targetJson=$targetJson",\"enforceReason\":\"$5\""
1726 targetJson=$targetJson"}"
1727 elif [ "$3" == "OSC" ]; then
1728 targetJson="{\"instance_status\":\"$4\""
1729 if [ $# -eq 5 ]; then
1730 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1732 targetJson=$targetJson",\"created_at\":\"????\"}"
1734 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1738 if [ "$A1PMS_VERSION" == "V2" ]; then
1739 query="/v2/policies/$UUID$2/status"
1740 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1742 query="/policy_status?id="$UUID$2
1745 res="$(__do_curl_to_api A1PMS GET $query)"
1746 status=${res:${#res}-3}
1748 if [ $status -ne $1 ]; then
1749 __log_test_fail_status_code $1 $status
1752 if [ $# -gt 2 ]; then
1753 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1754 body=${res:0:${#res}-3}
1755 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1757 if [ $res -ne 0 ]; then
1758 __log_test_fail_body
1762 __collect_endpoint_stats "A1PMS" 08 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}/status" $status
1767 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1768 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1769 # (Function for test scripts)
1770 a1pms_api_get_policy_types() {
1773 if [ $# -lt 1 ]; then
1774 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1778 if [ "$A1PMS_VERSION" == "V2" ]; then
1779 if [ $# -eq 1 ]; then
1780 query="/v2/policy-types"
1781 elif [ $2 == "NORIC" ]; then
1782 query="/v2/policy-types"
1784 query="/v2/policy-types?ric_id=$2"
1787 if [ $# -eq 1 ]; then
1788 query="/policy_types"
1789 elif [ $2 == "NORIC" ]; then
1790 query="/policy_types"
1792 query="/policy_types?ric=$2"
1796 res="$(__do_curl_to_api A1PMS GET $query)"
1797 status=${res:${#res}-3}
1799 if [ $status -ne $1 ]; then
1800 __log_test_fail_status_code $1 $status
1804 if [ $# -gt 2 ]; then
1805 body=${res:0:${#res}-3}
1808 for pid in ${@:3} ; do
1809 if [ "$targetJson" != "[" ]; then
1810 targetJson=$targetJson","
1812 if [ $pid == "EMPTY" ]; then
1815 targetJson=$targetJson"\"$pid\""
1818 targetJson=$targetJson"]"
1819 if [ "$A1PMS_VERSION" == "V2" ]; then
1820 targetJson="{\"policytype_ids\": $targetJson }"
1822 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1823 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1825 if [ $res -ne 0 ]; then
1826 __log_test_fail_body
1831 __collect_endpoint_stats "A1PMS" 09 "GET" $A1PMS_API_PREFIX"/v2/policy-types" $status
1836 #########################################################
1837 #### Test case functions Health check
1838 #########################################################
1840 # API Test function: GET /status and V2 GET /status
1841 # args: <response-code>
1842 # (Function for test scripts)
1843 a1pms_api_get_status() {
1845 if [ $# -ne 1 ]; then
1846 __print_err "<response-code>" $@
1849 if [ "$A1PMS_VERSION" == "V2" ]; then
1854 res="$(__do_curl_to_api A1PMS GET $query)"
1855 status=${res:${#res}-3}
1857 if [ $status -ne $1 ]; then
1858 __log_test_fail_status_code $1 $status
1862 __collect_endpoint_stats "A1PMS" 10 "GET" $A1PMS_API_PREFIX"/v2/status" $status
1867 # API Test function: GET /status (root) without api prefix
1868 # args: <response-code>
1869 # (Function for test scripts)
1870 a1pms_api_get_status_root() {
1872 if [ $# -ne 1 ]; then
1873 __print_err "<response-code>" $@
1877 TMP_PREFIX=$A1PMS_API_PREFIX
1879 res="$(__do_curl_to_api A1PMS GET $query)"
1880 A1PMS_API_PREFIX=$TMP_PREFIX
1881 status=${res:${#res}-3}
1883 if [ $status -ne $1 ]; then
1884 __log_test_fail_status_code $1 $status
1888 __collect_endpoint_stats "A1PMS" 19 "GET" "/status" $status
1893 #########################################################
1894 #### Test case functions RIC Repository
1895 #########################################################
1897 # API Test function: GET /ric and V2 GET /v2/rics/ric
1898 # args: <reponse-code> <management-element-id> [<ric-id>]
1899 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1900 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1901 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1904 # (Function for test scripts)
1905 a1pms_api_get_ric() {
1908 if [ "$A1PMS_VERSION" == "V2" ]; then
1909 if [ $# -lt 3 ]; then
1910 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1914 if [ $2 != "NOME" ]; then
1915 search="?managed_element_id="$2
1917 if [ $3 != "NORIC" ]; then
1918 if [ -z $search ]; then
1921 search=$search"&ric_id="$3
1924 query="/v2/rics/ric"$search
1926 res="$(__do_curl_to_api A1PMS GET $query)"
1927 status=${res:${#res}-3}
1929 if [ $status -ne $1 ]; then
1930 __log_test_fail_status_code $1 $status
1934 if [ $# -gt 3 ]; then
1935 body=${res:0:${#res}-3}
1936 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1937 if [ $res -ne 0 ]; then
1938 __log_test_fail_general "Could not create target ric info json"
1942 targetJson=$(<./tmp/.tmp_rics.json)
1943 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1944 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1945 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1946 if [ $res -ne 0 ]; then
1947 __log_test_fail_body
1952 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1953 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1957 query="/ric?managedElementId="$2
1959 res="$(__do_curl_to_api A1PMS GET $query)"
1960 status=${res:${#res}-3}
1962 if [ $status -ne $1 ]; then
1963 __log_test_fail_status_code $1 $status
1967 if [ $# -eq 3 ]; then
1968 body=${res:0:${#res}-3}
1969 if [ "$body" != "$3" ]; then
1970 __log_test_fail_body
1976 __collect_endpoint_stats "A1PMS" 11 "GET" $A1PMS_API_PREFIX"/v2/rics/ric" $status
1981 # API test function: GET /rics and V2 GET /v2/rics
1982 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1983 # 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_........."
1984 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1985 # (Function for test scripts)
1986 a1pms_api_get_rics() {
1989 if [ $# -lt 2 ]; then
1990 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1994 if [ "$A1PMS_VERSION" == "V2" ]; then
1996 if [ $2 != "NOTYPE" ]; then
1997 query="/v2/rics?policytype_id="$2
2001 if [ $2 != "NOTYPE" ]; then
2002 query="/rics?policyType="$2
2006 res="$(__do_curl_to_api A1PMS GET $query)"
2007 status=${res:${#res}-3}
2009 if [ $status -ne $1 ]; then
2010 __log_test_fail_status_code $1 $status
2014 if [ $# -gt 2 ]; then
2015 body=${res:0:${#res}-3}
2016 if [ "$A1PMS_VERSION" == "V2" ]; then
2017 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
2019 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
2021 if [ $res -ne 0 ]; then
2022 __log_test_fail_general "Could not create target ric info json"
2026 targetJson=$(<./tmp/.tmp_rics.json)
2027 if [ "$A1PMS_VERSION" == "V2" ]; then
2028 targetJson="{\"rics\": $targetJson }"
2030 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2031 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2032 if [ $res -ne 0 ]; then
2033 __log_test_fail_body
2038 __collect_endpoint_stats "A1PMS" 12 "GET" $A1PMS_API_PREFIX"/v2/rics" $status
2043 ##################################################################
2044 #### API Test case functions Service registry and supervision ####
2045 ##################################################################
2047 # API test function: PUT /service and V2 PUT /service
2048 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
2049 # (Function for test scripts)
2050 a1pms_api_put_service() {
2052 if [ $# -ne 4 ]; then
2053 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
2057 if [ "$A1PMS_VERSION" == "V2" ]; then
2058 query="/v2/services"
2059 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
2062 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
2064 file="./tmp/.tmp.json"
2065 echo "$json" > $file
2067 res="$(__do_curl_to_api A1PMS PUT $query $file)"
2068 status=${res:${#res}-3}
2070 if [ $status -ne $1 ]; then
2071 __log_test_fail_status_code $1 $status
2075 __collect_endpoint_stats "A1PMS" 13 "PUT" $A1PMS_API_PREFIX"/v2/service" $status
2080 # API test function: GET /services and V2 GET /v2/services
2081 #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>]* )]
2082 # (Function for test scripts)
2083 a1pms_api_get_services() {
2085 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
2087 if [ $# -eq 1 ]; then
2089 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
2091 elif [ $# -eq 5 ]; then
2093 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
2095 if [ $(($argLen%3)) -eq 0 ]; then
2100 if [ $paramError -ne 0 ]; then
2101 __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>]* )]" $@
2105 if [ "$A1PMS_VERSION" == "V2" ]; then
2106 query="/v2/services"
2108 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2109 query="/v2/services?service_id="$2
2114 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2115 query="/services?name="$2
2118 res="$(__do_curl_to_api A1PMS GET $query)"
2119 status=${res:${#res}-3}
2121 if [ $status -ne $1 ]; then
2122 __log_test_fail_status_code $1 $status
2126 if [ $# -gt 2 ]; then
2127 variableArgCount=$(($#-2))
2128 body=${res:0:${#res}-3}
2132 while [ $cntr -lt $variableArgCount ]; do
2133 servicename=$1; shift;
2136 if [ $cntr -gt 0 ]; then
2137 targetJson=$targetJson","
2139 # timeSinceLastActivitySeconds value cannot be checked since value varies
2140 if [ "$A1PMS_VERSION" == "V2" ]; then
2141 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
2143 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2147 targetJson=$targetJson"]"
2148 if [ "$A1PMS_VERSION" == "V2" ]; then
2149 targetJson="{\"service_list\": $targetJson }"
2151 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2152 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2153 if [ $res -ne 0 ]; then
2154 __log_test_fail_body
2159 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX"/v2/services" $status
2164 # API test function: GET /services V2 GET /v2/services - (only checking service names)
2165 # args: <response-code> [<service-name>]*"
2166 # (Function for test scripts)
2167 a1pms_api_get_service_ids() {
2170 if [ $# -lt 1 ]; then
2171 __print_err "<response-code> [<service-name>]*" $@
2175 if [ "$A1PMS_VERSION" == "V2" ]; then
2176 query="/v2/services"
2180 res="$(__do_curl_to_api A1PMS GET $query)"
2181 status=${res:${#res}-3}
2183 if [ $status -ne $1 ]; then
2184 __log_test_fail_status_code $1 $status
2188 body=${res:0:${#res}-3}
2190 for rapp in ${@:2} ; do
2191 if [ "$targetJson" != "[" ]; then
2192 targetJson=$targetJson","
2194 if [ "$A1PMS_VERSION" == "V2" ]; then
2195 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2197 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2201 targetJson=$targetJson"]"
2202 if [ "$A1PMS_VERSION" == "V2" ]; then
2203 targetJson="{\"service_list\": $targetJson }"
2205 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2206 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2208 if [ $res -ne 0 ]; then
2209 __log_test_fail_body
2213 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX"/v2/services" $status
2218 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
2219 # args: <response-code> <service-name>
2220 # (Function for test scripts)
2221 a1pms_api_delete_services() {
2224 if [ $# -ne 2 ]; then
2225 __print_err "<response-code> <service-name>" $@
2228 if [ "$A1PMS_VERSION" == "V2" ]; then
2229 query="/v2/services/"$2
2231 query="/services?name="$2
2233 res="$(__do_curl_to_api A1PMS DELETE $query)"
2234 status=${res:${#res}-3}
2236 if [ $status -ne $1 ]; then
2237 __log_test_fail_status_code $1 $status
2241 __collect_endpoint_stats "A1PMS" 15 "DELETE" $A1PMS_API_PREFIX"/v2/services/{serviceId}" $status
2246 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
2247 # args: <response-code> <service-name>
2248 # (Function for test scripts)
2249 a1pms_api_put_services_keepalive() {
2252 if [ $# -ne 2 ]; then
2253 __print_err "<response-code> <service-name>" $@
2256 if [ "$A1PMS_VERSION" == "V2" ]; then
2257 query="/v2/services/$2/keepalive"
2259 query="/services/keepalive?name="$2
2262 res="$(__do_curl_to_api A1PMS PUT $query)"
2263 status=${res:${#res}-3}
2265 if [ $status -ne $1 ]; then
2266 __log_test_fail_status_code $1 $status
2270 __collect_endpoint_stats "A1PMS" 16 "PUT" $A1PMS_API_PREFIX"/v2/services/{service_id}/keepalive" $status
2275 ##################################################################
2276 #### API Test case functions Configuration ####
2277 ##################################################################
2279 # API Test function: PUT /v2/configuration
2280 # args: <response-code> <config-file>
2281 # (Function for test scripts)
2282 a1pms_api_put_configuration() {
2285 if [ "$A1PMS_VERSION" != "V2" ]; then
2286 __log_test_fail_not_supported
2290 if [ $# -ne 2 ]; then
2291 __print_err "<response-code> <config-file>" $@
2294 if [ ! -f $2 ]; then
2295 __log_test_fail_general "Config file "$2", does not exist"
2299 if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
2300 inputJson="{\"config\":"$inputJson"}"
2302 file="./tmp/.config.json"
2303 echo $inputJson > $file
2304 query="/v2/configuration"
2305 res="$(__do_curl_to_api A1PMS PUT $query $file)"
2306 status=${res:${#res}-3}
2308 if [ $status -ne $1 ]; then
2309 __log_test_fail_status_code $1 $status
2313 __collect_endpoint_stats "A1PMS" 17 "PUT" $A1PMS_API_PREFIX"/v2/configuration" $status
2318 # API Test function: GET /v2/configuration
2319 # args: <response-code> [<config-file>]
2320 # (Function for test scripts)
2321 a1pms_api_get_configuration() {
2324 if [ "$A1PMS_VERSION" != "V2" ]; then
2325 __log_test_fail_not_supported
2329 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2330 __print_err "<response-code> [<config-file>]" $@
2333 if [ ! -f $2 ]; then
2334 __log_test_fail_general "Config file "$2" for comparison, does not exist"
2338 query="/v2/configuration"
2339 res="$(__do_curl_to_api A1PMS GET $query)"
2340 status=${res:${#res}-3}
2342 if [ $status -ne $1 ]; then
2343 __log_test_fail_status_code $1 $status
2347 if [ $# -eq 2 ]; then
2349 body=${res:0:${#res}-3}
2352 targetJson="{\"config\":"$targetJson"}"
2353 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2354 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2356 if [ $res -ne 0 ]; then
2357 __log_test_fail_body
2362 __collect_endpoint_stats "A1PMS" 18 "GET" $A1PMS_API_PREFIX"/v2/configuration" $status
2367 ##########################################
2368 #### Reset types and instances ####
2369 ##########################################
2371 # Admin reset to remove all policies and services
2372 # All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2373 # NOTE - only works in kubernetes and the pod should not be running
2375 # (Function for test scripts)
2377 a1pms_kube_pvc_reset() {
2380 pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
2381 if [ -z "$pvc_name" ]; then
2382 pvc_name=policymanagementservice-vardata-pvc
2384 echo " Trying to reset pvc: "$pvc_name
2385 __kube_clean_pvc $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $A1PMS_CONTAINER_MNT_DIR
2391 # args: <realm> <client-name> <client-secret>
2392 a1pms_configure_sec() {
2393 export A1PMS_CREDS_GRANT_TYPE="client_credentials"
2394 export A1PMS_CREDS_CLIENT_SECRET=$3
2395 export A1PMS_CREDS_CLIENT_ID=$2
2396 export A1PMS_AUTH_SERVICE_URL=$KEYCLOAK_SERVICE_PATH$KEYCLOAK_TOKEN_URL_PREFIX/$1/protocol/openid-connect/token
2397 export A1PMS_SIDECAR_MOUNT="/token-cache"
2398 export A1PMS_SIDECAR_JWT_FILE=$A1PMS_SIDECAR_MOUNT"/jwt.txt"
2400 export AUTHSIDECAR_APP_NAME
2401 export AUTHSIDECAR_DISPLAY_NAME