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() {
94 # Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers
95 # For docker, the namespace shall be excluded
96 # This function is called for apps managed by the test script as well as for prestarted apps.
98 __A1PMS_statisics_setup() {
99 if [ $RUNMODE == "KUBE" ]; then
100 echo "A1PMS $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE"
102 echo "A1PMS $A1PMS_APP_NAME"
106 # Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
108 __A1PMS_test_requirements() {
113 #######################################################
115 ###########################
117 ###########################
119 # Set http as the protocol to use for all communication to the A1PMS
121 # (Function for test scripts)
122 use_a1pms_rest_http() {
123 __a1pms_set_protocoll "http" $A1PMS_INTERNAL_PORT $A1PMS_EXTERNAL_PORT
126 # Set https as the protocol to use for all communication to the A1PMS
128 # (Function for test scripts)
129 use_a1pms_rest_https() {
130 __a1pms_set_protocoll "https" $A1PMS_INTERNAL_SECURE_PORT $A1PMS_EXTERNAL_SECURE_PORT
133 # All calls to the a1pms will be directed to the a1pms dmaap interface over http from now on
135 # (Function for test scripts)
136 use_a1pms_dmaap_http() {
137 echo -e $BOLD"$A1PMS_DISPLAY_NAME dmaap protocol setting"$EBOLD
138 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the a1pms"
139 A1PMS_ADAPTER_TYPE="MR-HTTP"
143 # All calls to the a1pms will be directed to the a1pms dmaap interface over https from now on
145 # (Function for test scripts)
146 use_a1pms_dmaap_https() {
147 echo -e $BOLD"$A1PMS_DISPLAY_NAME dmaap protocol setting"$EBOLD
148 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the a1pms"
149 echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
150 A1PMS_ADAPTER_TYPE="MR-HTTPS"
154 # Setup paths to svc/container for internal and external access
155 # args: <protocol> <internal-port> <external-port>
156 __a1pms_set_protocoll() {
157 echo -e $BOLD"$A1PMS_DISPLAY_NAME protocol setting"$EBOLD
158 echo -e " Using $BOLD $1 $EBOLD towards $A1PMS_DISPLAY_NAME"
160 ## Access to Dmaap adapter
162 A1PMS_SERVICE_PATH=$1"://"$A1PMS_APP_NAME":"$2 # docker access, container->container and script->container via proxy
163 if [ $RUNMODE == "KUBE" ]; then
164 A1PMS_SERVICE_PATH=$1"://"$A1PMS_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
167 # A1PMS_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
168 A1PMS_ADAPTER_TYPE="REST"
169 A1PMS_ADAPTER=$A1PMS_SERVICE_PATH
174 # Make curl retries towards the a1pms for http response codes set in this env var, space separated list of codes
177 #Save first worker node the pod is started on
178 __A1PMS_WORKER_NODE=""
180 # Export env vars for config files, docker compose and kube resources
181 # args: PROXY|NOPROXY
182 __export_a1pms_vars() {
184 export A1PMS_APP_NAME
185 export A1PMS_APP_NAME_ALIAS
186 export A1PMS_DISPLAY_NAME
188 export KUBE_NONRTRIC_NAMESPACE
190 export A1PMS_INTERNAL_PORT
191 export A1PMS_INTERNAL_SECURE_PORT
192 export A1PMS_EXTERNAL_PORT
193 export A1PMS_EXTERNAL_SECURE_PORT
194 export A1PMS_CONFIG_MOUNT_PATH
195 export A1PMS_DATA_MOUNT_PATH
196 export A1PMS_CONFIG_CONFIGMAP_NAME=$A1PMS_APP_NAME"-config"
197 export A1PMS_DATA_CONFIGMAP_NAME=$A1PMS_APP_NAME"-data"
198 export A1PMS_PKG_NAME
200 export CONSUL_INTERNAL_PORT
201 export CONFIG_BINDING_SERVICE
202 export A1PMS_CONFIG_KEY
203 export DOCKER_SIM_NWNAME
204 export A1PMS_HOST_MNT_DIR
205 export A1PMS_CONFIG_FILE
207 export A1PMS_DATA_PV_NAME=$A1PMS_APP_NAME"-pv"
208 export A1PMS_DATA_PVC_NAME=$A1PMS_APP_NAME"-pvc"
209 ##Create a unique path for the pv each time to prevent a previous volume to be reused
210 export A1PMS_PV_PATH="a1pmsdata-"$(date +%s)
211 export A1PMS_CONTAINER_MNT_DIR
212 export HOST_PATH_BASE_DIR
214 if [ $1 == "PROXY" ]; then
215 export A1PMS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
216 export A1PMS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
217 if [ $A1PMS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$A1PMS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
218 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
220 echo " Configured with http proxy"
223 export A1PMS_HTTP_PROXY_CONFIG_PORT=0
224 export A1PMS_HTTP_PROXY_CONFIG_HOST_NAME=""
225 echo " Configured without http proxy"
231 # args: (docker) PROXY|NOPROXY <config-file>
232 # args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
233 # (Function for test scripts)
235 echo -e $BOLD"Starting $A1PMS_DISPLAY_NAME"$EBOLD
237 if [ $RUNMODE == "KUBE" ]; then
239 # Check if app shall be fully managed by the test script
240 __check_included_image "A1PMS"
243 # Check if app shall only be used by the testscipt
244 __check_prestarted_image "A1PMS"
247 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
248 echo -e $RED"The $A1PMS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
249 echo -e $RED"The $A1PMS_APP_NAME will not be started"$ERED
252 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
253 echo -e $RED"The $A1PMS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
254 echo -e $RED"The $A1PMS_APP_NAME will not be started"$ERED
258 if [ $retcode_p -eq 0 ]; then
259 echo -e " Using existing $A1PMS_APP_NAME deployment and service"
260 echo " Setting $A1PMS_APP_NAME replicas=1"
261 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
262 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
265 if [ $retcode_i -eq 0 ]; then
267 echo -e " Creating $A1PMS_APP_NAME app and expose service"
269 #Check if nonrtric namespace exists, if not create it
270 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
272 __export_a1pms_vars $1
274 # Create config map for config
275 configfile=$PWD/tmp/$A1PMS_CONFIG_FILE
277 output_yaml=$PWD/tmp/a1pms-cfc.yaml
278 __kube_create_configmap $A1PMS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $configfile $output_yaml
280 # Create config map for data
281 data_json=$PWD/tmp/$A1PMS_DATA_FILE
282 if [ $# -lt 3 ]; then
283 #create empty dummy file
284 echo "{}" > $data_json
288 output_yaml=$PWD/tmp/a1pms-cfd.yaml
289 __kube_create_configmap $A1PMS_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $data_json $output_yaml
292 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"pv.yaml
293 output_yaml=$PWD/tmp/a1pms-pv.yaml
294 __kube_create_instance pv $A1PMS_APP_NAME $input_yaml $output_yaml
297 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"pvc.yaml
298 output_yaml=$PWD/tmp/a1pms-pvc.yaml
299 __kube_create_instance pvc $A1PMS_APP_NAME $input_yaml $output_yaml
302 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"svc.yaml
303 output_yaml=$PWD/tmp/a1pmssvc.yaml
304 __kube_create_instance service $A1PMS_APP_NAME $input_yaml $output_yaml
307 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"app.yaml
308 output_yaml=$PWD/tmp/a1pmsapp.yaml
309 __kube_create_instance app $A1PMS_APP_NAME $input_yaml $output_yaml
313 # 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
314 if [ $retcode_i -eq 0 ]; then
315 __A1PMS_WORKER_NODE=$(kubectl $KUBECONF get pod -l "autotest=A1PMS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
316 if [ -z "$__A1PMS_WORKER_NODE" ]; then
317 echo -e $YELLOW" Cannot find worker node for pod for $A1PMS_APP_NAME, persistency may not work"$EYELLOW
320 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
323 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
326 __check_included_image 'A1PMS'
327 if [ $? -eq 1 ]; then
328 echo -e $RED"The A1PMS app is not included in this test script"$ERED
329 echo -e $RED"The A1PMS will not be started"$ERED
336 cd $A1PMS_HOST_MNT_DIR
339 if [ "$(ls -A $DIR)" ]; then
340 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
341 rm -rf db/* &> /dev/null
342 if [ $? -ne 0 ]; then
343 echo -e $RED" Cannot remove database files in: $PWD"$ERED
348 echo " No files in mounted dir or dir does not exists"
352 __export_a1pms_vars $1
354 dest_file=$SIM_GROUP/$A1PMS_COMPOSE_DIR/$A1PMS_HOST_MNT_DIR/application.yaml
356 envsubst < $2 > $dest_file
358 __start_container $A1PMS_COMPOSE_DIR "" NODOCKERARGS 1 $A1PMS_APP_NAME
360 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
363 __collect_endpoint_stats_image_info "A1PMS" $A1PMS_IMAGE
371 # (Function for test scripts)
373 echo -e $BOLD"Stopping $A1PMS_DISPLAY_NAME"$EBOLD
375 if [ $RUNMODE == "KUBE" ]; then
377 __check_prestarted_image "A1PMS"
378 if [ $? -eq 0 ]; then
379 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
380 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
381 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
384 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS
385 echo " Deleting the replica set - a new will be started when the app is started"
386 tmp=$(kubectl $KUBECONF delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
387 if [ $? -ne 0 ]; then
388 echo -e $RED" Could not delete replica set "$RED
393 docker stop $A1PMS_APP_NAME &> ./tmp/.dockererr
394 if [ $? -ne 0 ]; then
395 __print_err "Could not stop $A1PMS_APP_NAME" $@
401 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
406 # Start a previously stopped a1pms
408 # (Function for test scripts)
409 start_stopped_a1pms() {
410 echo -e $BOLD"Starting (the previously stopped) $A1PMS_DISPLAY_NAME"$EBOLD
412 if [ $RUNMODE == "KUBE" ]; then
414 __check_prestarted_image "A1PMS"
415 if [ $? -eq 0 ]; then
416 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
417 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
418 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
419 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
423 # Tie the A1PMS to the same worker node it was initially started on
424 # 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
425 if [ -z "$__A1PMS_WORKER_NODE" ]; then
426 echo -e $RED" No initial worker node found for pod "$RED
430 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
431 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
432 tmp=$(kubectl $KUBECONF patch deployment $A1PMS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__A1PMS_WORKER_NODE'"}}}}}')
433 if [ $? -ne 0 ]; then
434 echo -e $YELLOW" Cannot set nodeSelector to deployment for $A1PMS_APP_NAME, persistency may not work"$EYELLOW
436 __kube_scale deployment $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
439 docker start $A1PMS_APP_NAME &> ./tmp/.dockererr
440 if [ $? -ne 0 ]; then
441 __print_err "Could not start (the stopped) $A1PMS_APP_NAME" $@
447 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
448 if [ $? -ne 0 ]; then
456 # Function to perpare the consul configuration according to the current simulator configuration
457 # args: SDNC|NOSDNC <output-file>
458 # (Function for test scripts)
459 prepare_consul_config() {
460 echo -e $BOLD"Prepare Consul config"$EBOLD
462 echo " Writing consul config for "$A1PMS_APP_NAME" to file: "$2
466 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
470 if [ $1 == "SDNC" ]; then
471 echo -e " Config$BOLD including SDNC$EBOLD configuration"
472 elif [ $1 == "NOSDNC" ]; then
473 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
476 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
481 if [ $1 == "SDNC" ]; then
482 config_json=$config_json"\n \"controller\": ["
483 config_json=$config_json"\n {"
484 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
485 config_json=$config_json"\n \"baseUrl\": \"$SDNC_SERVICE_PATH\","
486 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
487 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
488 config_json=$config_json"\n }"
489 config_json=$config_json"\n ],"
492 config_json=$config_json"\n \"streams_publishes\": {"
493 config_json=$config_json"\n \"dmaap_publisher\": {"
494 config_json=$config_json"\n \"type\": \"message-router\","
495 config_json=$config_json"\n \"dmaap_info\": {"
496 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_WRITE_URL\""
497 config_json=$config_json"\n }"
498 config_json=$config_json"\n }"
499 config_json=$config_json"\n },"
500 config_json=$config_json"\n \"streams_subscribes\": {"
501 config_json=$config_json"\n \"dmaap_subscriber\": {"
502 config_json=$config_json"\n \"type\": \"message-router\","
503 config_json=$config_json"\n \"dmaap_info\": {"
504 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_READ_URL\""
505 config_json=$config_json"\n }"
506 config_json=$config_json"\n }"
507 config_json=$config_json"\n },"
509 config_json=$config_json"\n \"ric\": ["
511 if [ $RUNMODE == "KUBE" ]; then
512 result=$(kubectl $KUBECONF get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICSIM")].metadata.name}')
515 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
516 for im in $result; do
517 if [[ $im != *"-0" ]]; then
518 ric_subdomain=$(kubectl $KUBECONF get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
519 rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
520 let ric_cntr=ric_cntr+1
524 if [ $ric_cntr -eq 0 ]; then
525 echo $YELLOW"Warning: No rics found for the configuration"$EYELLOW
528 rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "status=running" --format {{.Names}})
529 if [ $? -ne 0 ] || [ -z "$rics" ]; then
530 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
537 if [ $cntr -gt 0 ]; then
538 config_json=$config_json"\n ,"
540 config_json=$config_json"\n {"
541 if [ $RUNMODE == "KUBE" ]; then
542 ric_id=${ric%.*.*} #extract pod id from full hosthame
543 ric_id=$(echo "$ric_id" | tr '-' '_')
545 if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
548 ric_id=$(echo "$ric" | tr '-' '_') #ric id still needs underscore as it is different from the container name
551 echo " Found a1 sim: "$ric_id
552 config_json=$config_json"\n \"name\": \"$ric_id\","
553 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
554 if [ $1 == "SDNC" ]; then
555 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
557 config_json=$config_json"\n \"managedElementIds\": ["
558 config_json=$config_json"\n \"me1_$ric_id\","
559 config_json=$config_json"\n \"me2_$ric_id\""
560 config_json=$config_json"\n ]"
561 config_json=$config_json"\n }"
565 config_json=$config_json"\n ]"
566 config_json=$config_json"\n}"
568 if [ $RUNMODE == "KUBE" ]; then
569 config_json="{\"config\":"$config_json"}"
572 printf "$config_json">$2
577 # Load the the appl config for the a1pms into a config map
578 a1pms_load_config() {
579 echo -e $BOLD"A1PMS - load config from "$EBOLD$1
580 data_json=$PWD/tmp/$A1PMS_DATA_FILE
582 output_yaml=$PWD/tmp/a1pms-cfd.yaml
583 __kube_create_configmap $A1PMS_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $data_json $output_yaml
588 # Turn on debug level tracing in the a1pms
590 # (Function for test scripts)
592 echo -e $BOLD"Setting a1pms debug logging"$EBOLD
593 curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
594 result=$(__do_curl "$curlString")
595 if [ $? -ne 0 ]; then
596 __print_err "could not set debug mode" $@
604 # Turn on trace level tracing in the a1pms
606 # (Function for test scripts)
608 echo -e $BOLD"Setting a1pms trace logging"$EBOLD
609 curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
610 result=$(__do_curl "$curlString")
611 if [ $? -ne 0 ]; then
612 __print_err "could not set trace mode" $@
620 # Perform curl retries when making direct call to the a1pms for the specified http response codes
621 # Speace separated list of http response codes
622 # args: [<response-code>]*
623 use_a1pms_retries() {
624 echo -e $BOLD"Do curl retries to the a1pms REST inteface for these response codes:$@"$EBOLD
630 # Check the a1pms logs for WARNINGs and ERRORs
632 # (Function for test scripts)
634 __check_container_logs "A1PMS" $A1PMS_APP_NAME $A1PMS_LOGPATH WARN ERR
637 #########################################################
638 #### Test case functions A1 Policy management service
639 #########################################################
641 # This function compare the size, towards a target value, of a json array returned from <url> of the A1PMS.
642 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
643 # args: json:<url> <target-value> [<timeout-in-seconds]
644 # (Function for test scripts)
646 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
647 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
648 if [[ $1 == "json:"* ]]; then
649 if [ "$A1PMS_VERSION" == "V2" ]; then
650 __var_test "A1PMS" $A1PMS_SERVICE_PATH$A1PMS_API_PREFIX"/v2/" $1 "=" $2 $3
652 __var_test "A1PMS" $A1PMS_SERVICE_PATH"/" $1 "=" $2 $3
657 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
661 # API Test function: GET /policies and V2 GET /v2/policy-instances
662 # 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>]*]
663 # 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>]*]
664 # (Function for test scripts)
665 a1pms_api_get_policies() {
668 if [ "$A1PMS_VERSION" == "V2" ]; then
670 variableParams=$(($#-4))
671 if [ $# -lt 4 ]; then
673 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
675 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
679 if [ $paramError -ne 0 ]; then
680 __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>]*]" $@
685 variableParams=$(($#-4))
686 if [ $# -lt 4 ]; then
688 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
690 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
694 if [ $paramError -ne 0 ]; then
695 __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>]*]" $@
701 if [ "$A1PMS_VERSION" == "V2" ]; then
702 if [ $2 != "NORIC" ]; then
703 queryparams="?ric_id="$2
705 if [ $3 != "NOSERVICE" ]; then
706 if [ -z $queryparams ]; then
707 queryparams="?service_id="$3
709 queryparams=$queryparams"&service_id="$3
712 if [ $4 != "NOTYPE" ]; then
713 if [ -z $queryparams ]; then
714 queryparams="?policytype_id="$4
716 queryparams=$queryparams"&policytype_id="$4
720 query="/v2/policy-instances"$queryparams
721 res="$(__do_curl_to_api A1PMS GET $query)"
722 status=${res:${#res}-3}
724 if [ $status -ne $1 ]; then
725 __log_test_fail_status_code $1 $status
729 if [ $# -gt 4 ]; then
730 body=${res:0:${#res}-3}
731 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
737 for ((i=0; i<$(($#-4)); i=i+7)); do
739 if [ "$targetJson" != "[" ]; then
740 targetJson=$targetJson","
742 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
743 if [ "${arr[$i+3]}" == "EMPTY" ]; then
744 targetJson=$targetJson"\"\","
746 targetJson=$targetJson"\"${arr[$i+3]}\","
748 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
750 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
752 targetJson=$targetJson"\"policy_data\":"$json"}"
756 targetJson=$targetJson"]"
757 targetJson="{\"policies\": $targetJson}"
758 echo "TARGET JSON: $targetJson" >> $HTTPLOG
759 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
761 if [ $res -ne 0 ]; then
767 if [ $2 != "NORIC" ]; then
768 queryparams="?ric="$2
770 if [ $3 != "NOSERVICE" ]; then
771 if [ -z $queryparams ]; then
772 queryparams="?service="$3
774 queryparams=$queryparams"&service="$3
777 if [ $4 != "NOTYPE" ]; then
778 if [ -z $queryparams ]; then
779 queryparams="?type="$4
781 queryparams=$queryparams"&type="$4
785 query="/policies"$queryparams
786 res="$(__do_curl_to_api A1PMS GET $query)"
787 status=${res:${#res}-3}
789 if [ $status -ne $1 ]; then
790 __log_test_fail_status_code $1 $status
794 if [ $# -gt 4 ]; then
795 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
798 body=${res:0:${#res}-3}
802 for ((i=0; i<$(($#-4)); i=i+5)); do
804 if [ "$targetJson" != "[" ]; then
805 targetJson=$targetJson","
807 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
808 if [ "${arr[$i+3]}" == "EMPTY" ]; then
809 targetJson=$targetJson"\"\","
811 targetJson=$targetJson"\"${arr[$i+3]}\","
814 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
816 targetJson=$targetJson"\"json\":"$json"}"
820 targetJson=$targetJson"]"
821 echo "TARGET JSON: $targetJson" >> $HTTPLOG
822 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
824 if [ $res -ne 0 ]; then
830 __collect_endpoint_stats "A1PMS" 00 "GET" $A1PMS_API_PREFIX"/v2/policy-instances" $status
837 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
838 # args: <response-code> <policy-id> [<template-file>]
839 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
841 # (Function for test scripts)
842 a1pms_api_get_policy() {
846 if [ "$A1PMS_VERSION" == "V2" ]; then
847 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
848 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
851 query="/v2/policies/$UUID$2"
853 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
854 __print_err "<response-code> <policy-id> [<template-file>] " $@
857 query="/policy?id=$UUID$2"
859 res="$(__do_curl_to_api A1PMS GET $query)"
860 status=${res:${#res}-3}
862 if [ $status -ne $1 ]; then
863 __log_test_fail_status_code $1 $status
867 if [ "$A1PMS_VERSION" == "V2" ]; then
868 if [ $# -eq 8 ]; then
870 #Create a policy json to compare with
871 body=${res:0:${#res}-3}
873 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
874 if [ $7 != "NOTRANSIENT" ]; then
875 targetJson=$targetJson", \"transient\":$7"
877 if [ $6 != "NOTYPE" ]; then
878 targetJson=$targetJson", \"policytype_id\":\"$6\""
880 targetJson=$targetJson", \"policytype_id\":\"\""
882 if [ $8 != "NOURL" ]; then
883 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
886 data=$(sed 's/XXX/'${2}'/g' $3)
887 targetJson=$targetJson", \"policy_data\":$data"
888 targetJson="{$targetJson}"
890 echo "TARGET JSON: $targetJson" >> $HTTPLOG
891 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
892 if [ $res -ne 0 ]; then
898 if [ $# -eq 3 ]; then
899 #Create a policy json to compare with
900 body=${res:0:${#res}-3}
902 sed 's/XXX/'${2}'/g' $3 > $file
903 targetJson=$(< $file)
904 echo "TARGET JSON: $targetJson" >> $HTTPLOG
905 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
906 if [ $res -ne 0 ]; then
912 __collect_endpoint_stats "A1PMS" 01 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $status
917 # API Test function: PUT /policy and V2 PUT /policies
918 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
919 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
920 # (Function for test scripts)
921 a1pms_api_put_policy() {
924 if [ "$A1PMS_VERSION" == "V2" ]; then
925 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
926 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
930 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
931 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
944 if [ "$A1PMS_VERSION" == "V2" ]; then
947 if [ $# -eq 9 ]; then
952 if [ $# -eq 8 ]; then
957 while [ $count -lt $max ]; do
958 if [ "$A1PMS_VERSION" == "V2" ]; then
962 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
963 if [ $trans != "NOTRANSIENT" ]; then
964 inputJson=$inputJson", \"transient\":$trans"
966 if [ $pt != "NOTYPE" ]; then
967 inputJson=$inputJson", \"policytype_id\":\"$pt\""
969 inputJson=$inputJson", \"policytype_id\":\"\""
971 if [ $noti != "NOURL" ]; then
972 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
975 data=$(sed 's/XXX/'${pid}'/g' $temp)
976 inputJson=$inputJson", \"policy_data\":$data"
977 inputJson="{$inputJson}"
978 echo $inputJson > $file
980 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
982 if [ $pt != "NOTYPE" ]; then
983 query=$query"&type=$pt"
986 if [ $trans != NOTRANSIENT ]; then
987 query=$query"&transient=$trans"
991 sed 's/XXX/'${pid}'/g' $temp > $file
993 res="$(__do_curl_to_api A1PMS PUT $query $file)"
994 status=${res:${#res}-3}
995 echo -ne " Executing "$count"("$max")${SAMELINE}"
996 if [ $status -ne $1 ]; then
997 echo " Executed "$count"?("$max")"
998 __log_test_fail_status_code $1 $status
1003 echo -ne " Executed "$count"("$max")${SAMELINE}"
1005 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $status $max
1012 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
1013 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
1014 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
1015 # (Function for test scripts)
1017 a1pms_api_put_policy_batch() {
1020 if [ "$A1PMS_VERSION" == "V2" ]; then
1021 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1022 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
1026 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1027 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
1039 if [ "$A1PMS_VERSION" == "V2" ]; then
1042 if [ $# -eq 9 ]; then
1047 if [ $# -eq 8 ]; then
1053 while [ $count -lt $max ]; do
1054 if [ "$A1PMS_VERSION" == "V2" ]; then
1055 query="/v2/policies"
1057 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1058 if [ $trans != "NOTRANSIENT" ]; then
1059 inputJson=$inputJson", \"transient\":$trans"
1061 if [ $pt != "NOTYPE" ]; then
1062 inputJson=$inputJson", \"policytype_id\":\"$pt\""
1064 inputJson=$inputJson", \"policytype_id\":\"\""
1066 if [ $noti != "NOURL" ]; then
1067 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1069 file="./tmp/.p.json"
1070 data=$(sed 's/XXX/'${pid}'/g' $temp)
1071 inputJson=$inputJson", \"policy_data\":$data"
1072 inputJson="{$inputJson}"
1073 echo $inputJson > $file
1075 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
1077 if [ $pt != "NOTYPE" ]; then
1078 query=$query"&type=$pt"
1081 if [ $trans != NOTRANSIENT ]; then
1082 query=$query"&transient=$trans"
1084 file="./tmp/.p.json"
1085 sed 's/XXX/'${pid}'/g' $temp > $file
1087 res="$(__do_curl_to_api A1PMS PUT_BATCH $query $file)"
1088 status=${res:${#res}-3}
1089 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1091 if [ $status -ne 200 ]; then
1092 echo " Requested(batch) "$count"?("$max")"
1093 __log_test_fail_status_code 200 $status
1096 cid=${res:0:${#res}-3}
1100 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1107 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1108 status=${res:${#res}-3}
1109 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
1111 if [ $status -ne $1 ]; then
1112 echo " Accepted(batch) "$count"?("$max")"
1113 __log_test_fail_status_code $1 $status
1118 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
1120 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $1 $max
1128 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
1129 # 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>
1130 # 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>
1131 # (Function for test scripts)
1132 a1pms_api_put_policy_parallel() {
1135 if [ "$A1PMS_VERSION" == "V2" ]; then
1136 if [ $# -ne 11 ]; then
1137 __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>" $@
1141 if [ $# -ne 10 ]; then
1142 __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>" $@
1146 resp_code=$1; shift;
1152 transient=$1; shift;
1153 if [ "$A1PMS_VERSION" == "V2" ]; then
1162 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1163 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1164 echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1165 echo " Info - will execute over a1pms REST"
1167 if [ "$A1PMS_VERSION" == "V2" ]; then
1168 if [ $serv == "NOSERVICE" ]; then
1171 query="$A1PMS_API_PREFIX/v2/policies"
1173 if [ $serv == "NOSERVICE" ]; then
1176 query="/policy?service=$serv"
1178 if [ $type != "NOTYPE" ]; then
1179 query=$query"&type=$type"
1182 if [ $transient != NOTRANSIENT ]; then
1183 query=$query"&transient=$transient"
1187 urlbase=${A1PMS_ADAPTER}${query}
1190 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1191 httpproxy=$KUBE_PROXY_PATH
1194 for ((i=1; i<=$pids; i++))
1197 if [ -z "$uuid" ]; then
1200 echo "" > "./tmp/.pid${i}.res.txt"
1201 if [ "$A1PMS_VERSION" == "V2" ]; then
1202 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1204 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1207 done | xargs -n 1 -I{} -P $pids bash -c '{
1209 echo " Parallel process $arg started"
1210 tmp=$(< "./tmp/.pid${arg}.txt")
1211 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1214 for ((i=1; i<=$pids; i++))
1216 file="./tmp/.pid${i}.res.txt"
1218 if [ -z "$tmp" ]; then
1219 echo " Process $i : unknown result (result file empty"
1223 if [ $res == "0" ]; then
1224 echo " Process $i : OK - "${tmp:1}
1226 echo " Process $i : failed - "${tmp:1}
1231 if [ -z $msg ]; then
1232 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $resp_code $(($count*$num_rics))
1233 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1237 __log_test_fail_general "One of more processes failed to execute"
1241 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
1242 # args: <response-code> <policy-id> [count]
1243 # (Function for test scripts)
1244 a1pms_api_delete_policy() {
1247 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1248 __print_err "<response-code> <policy-id> [count]" $@
1255 if [ $# -eq 3 ]; then
1261 while [ $count -lt $max ]; do
1262 if [ "$A1PMS_VERSION" == "V2" ]; then
1263 query="/v2/policies/"$UUID$pid
1265 query="/policy?id="$UUID$pid
1267 res="$(__do_curl_to_api A1PMS DELETE $query)"
1268 status=${res:${#res}-3}
1269 echo -ne " Executing "$count"("$max")${SAMELINE}"
1271 if [ $status -ne $1 ]; then
1272 echo " Executed "$count"?("$max")"
1273 __log_test_fail_status_code $1 $status
1279 echo -ne " Executed "$count"("$max")${SAMELINE}"
1281 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $status $max
1288 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
1289 # args: <response-code> <policy-id> [count]
1290 # (Function for test scripts)
1291 a1pms_api_delete_policy_batch() {
1294 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1295 __print_err "<response-code> <policy-id> [count]" $@
1302 if [ $# -eq 3 ]; then
1308 while [ $count -lt $max ]; do
1309 if [ "$A1PMS_VERSION" == "V2" ]; then
1310 query="/v2/policies/"$UUID$pid
1312 query="/policy?id="$UUID$pid
1314 res="$(__do_curl_to_api A1PMS DELETE_BATCH $query)"
1315 status=${res:${#res}-3}
1316 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1318 if [ $status -ne 200 ]; then
1319 echo " Requested(batch) "$count"?("$max")"
1320 __log_test_fail_status_code 200 $status
1323 cid=${res:0:${#res}-3}
1327 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1335 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1336 status=${res:${#res}-3}
1337 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1339 if [ $status -ne $1 ]; then
1340 echo " Deleted(batch) "$count"?("$max")"
1341 __log_test_fail_status_code $1 $status
1346 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1348 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $1 $max
1356 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1357 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1358 # (Function for test scripts)
1359 a1pms_api_delete_policy_parallel() {
1362 if [ $# -ne 5 ]; then
1363 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1366 resp_code=$1; shift;
1372 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1373 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1374 echo " Info - a1pms_api_delete_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1375 echo " Info - will execute over a1pms REST"
1378 if [ "$A1PMS_VERSION" == "V2" ]; then
1379 query="$A1PMS_API_PREFIX/v2/policies/"
1384 urlbase=${A1PMS_ADAPTER}${query}
1387 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1388 httpproxy=$KUBE_PROXY_PATH
1391 for ((i=1; i<=$pids; i++))
1394 if [ -z "$uuid" ]; then
1397 echo "" > "./tmp/.pid${i}.del.res.txt"
1398 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
1400 done | xargs -n 1 -I{} -P $pids bash -c '{
1402 echo " Parallel process $arg started"
1403 tmp=$(< "./tmp/.pid${arg}.del.txt")
1404 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1407 for ((i=1; i<=$pids; i++))
1409 file="./tmp/.pid${i}.del.res.txt"
1411 if [ -z "$tmp" ]; then
1412 echo " Process $i : unknown result (result file empty"
1416 if [ $res == "0" ]; then
1417 echo " Process $i : OK - "${tmp:1}
1419 echo " Process $i : failed - "${tmp:1}
1424 if [ -z $msg ]; then
1425 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count*$num_rics))
1426 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1430 __log_test_fail_general "One of more processes failed to execute"
1434 # API Test function: GET /policy_ids and V2 GET /v2/policies
1435 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1436 # (Function for test scripts)
1437 a1pms_api_get_policy_ids() {
1440 if [ $# -lt 4 ]; then
1441 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1447 if [ "$A1PMS_VERSION" == "V2" ]; then
1448 if [ $2 != "NORIC" ]; then
1449 queryparams="?ric_id="$2
1452 if [ $3 != "NOSERVICE" ]; then
1453 if [ -z $queryparams ]; then
1454 queryparams="?service_id="$3
1456 queryparams=$queryparams"&service_id="$3
1459 if [ $4 != "NOTYPE" ]; then
1460 if [ -z $queryparams ]; then
1461 queryparams="?policytype_id="$4
1463 queryparams=$queryparams"&policytype_id="$4
1467 query="/v2/policies"$queryparams
1469 if [ $2 != "NORIC" ]; then
1470 queryparams="?ric="$2
1473 if [ $3 != "NOSERVICE" ]; then
1474 if [ -z $queryparams ]; then
1475 queryparams="?service="$3
1477 queryparams=$queryparams"&service="$3
1480 if [ $4 != "NOTYPE" ]; then
1481 if [ -z $queryparams ]; then
1482 queryparams="?type="$4
1484 queryparams=$queryparams"&type="$4
1488 query="/policy_ids"$queryparams
1491 res="$(__do_curl_to_api A1PMS GET $query)"
1492 status=${res:${#res}-3}
1494 if [ $status -ne $1 ]; then
1495 __log_test_fail_status_code $1 $status
1499 if [ $# -gt 4 ]; then
1500 body=${res:0:${#res}-3}
1503 for pid in ${@:5} ; do
1504 if [ "$targetJson" != "[" ]; then
1505 targetJson=$targetJson","
1507 if [ $pid != "NOID" ]; then
1508 targetJson=$targetJson"\"$UUID$pid\""
1512 targetJson=$targetJson"]"
1513 if [ "$A1PMS_VERSION" == "V2" ]; then
1514 targetJson="{\"policy_ids\": $targetJson}"
1516 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1517 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1519 if [ $res -ne 0 ]; then
1520 __log_test_fail_body
1525 __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v2/policies" $status
1530 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
1531 # args(V2): <response-code> <policy-type-id> [<schema-file>]
1532 # (Function for test scripts)
1533 a1pms_api_get_policy_type() {
1536 if [ "$A1PMS_VERSION" != "V2" ]; then
1537 __log_test_fail_not_supported
1541 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1542 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1545 query="/v2/policy-types/$2"
1547 res="$(__do_curl_to_api A1PMS GET $query)"
1548 status=${res:${#res}-3}
1550 if [ $status -ne $1 ]; then
1551 __log_test_fail_status_code $1 $status
1555 if [ $# -eq 3 ]; then
1557 body=${res:0:${#res}-3}
1560 targetJson="{\"policy_schema\":$targetJson}"
1561 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1562 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1564 if [ $res -ne 0 ]; then
1565 __log_test_fail_body
1570 __collect_endpoint_stats "A1PMS" 05 "GET" $A1PMS_API_PREFIX"/v2/policy-types/{policyTypeId}" $status
1575 # API Test function: GET /policy_schema
1576 # args: <response-code> <policy-type-id> [<schema-file>]
1577 # (Function for test scripts)
1578 a1pms_api_get_policy_schema() {
1581 if [ "$A1PMS_VERSION" == "V2" ]; then
1582 __log_test_fail_not_supported
1586 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1587 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1590 query="/policy_schema?id=$2"
1591 res="$(__do_curl_to_api A1PMS GET $query)"
1592 status=${res:${#res}-3}
1594 if [ $status -ne $1 ]; then
1595 __log_test_fail_status_code $1 $status
1599 if [ $# -eq 3 ]; then
1601 body=${res:0:${#res}-3}
1605 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1606 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1608 if [ $res -ne 0 ]; then
1609 __log_test_fail_body
1614 __collect_endpoint_stats "A1PMS" 06 "GET" $A1PMS_API_PREFIX"/v2/policy_schema" $status
1619 # API Test function: GET /policy_schemas
1620 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
1621 # args(V2): <response-code>
1622 # (Function for test scripts)
1623 a1pms_api_get_policy_schemas() {
1626 if [ "$A1PMS_VERSION" == "V2" ]; then
1627 if [ $# -ne 1 ]; then
1628 __print_err "<response-code>" $@
1632 if [ $# -lt 2 ]; then
1633 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1637 if [ "$A1PMS_VERSION" == "V2" ]; then
1638 query="/v2/policy-schemas"
1640 query="/policy_schemas"
1641 if [ $2 != "NORIC" ]; then
1642 query=$query"?ric="$2
1646 res="$(__do_curl_to_api A1PMS GET $query)"
1647 status=${res:${#res}-3}
1649 if [ $status -ne $1 ]; then
1650 __log_test_fail_status_code $1 $status
1654 if [ $# -gt 2 ]; then
1655 body=${res:0:${#res}-3}
1658 for file in ${@:3} ; do
1659 if [ "$targetJson" != "[" ]; then
1660 targetJson=$targetJson","
1662 if [ $file == "NOFILE" ]; then
1663 targetJson=$targetJson"{}"
1665 targetJson=$targetJson$(< $file)
1669 targetJson=$targetJson"]"
1670 if [ "$A1PMS_VERSION" == "V2" ]; then
1671 targetJson="{\"policy_schemas\": $targetJson }"
1673 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1674 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1676 if [ $res -ne 0 ]; then
1677 __log_test_fail_body
1682 __collect_endpoint_stats "A1PMS" 07 "GET" $A1PMS_API_PREFIX"/v2/policy-schemas" $status
1687 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1688 # arg: <response-code> <policy-id> [ (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>) ]
1689 # (Function for test scripts)
1690 a1pms_api_get_policy_status() {
1693 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
1694 __print_err "<response-code> <policy-id> [(STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)]" $@
1699 if [ $# -eq 2 ]; then
1701 elif [ "$3" == "STD" ]; then
1702 targetJson="{\"enforceStatus\":\"$4\""
1703 if [ $# -eq 5 ]; then
1704 targetJson=$targetJson",\"reason\":\"$5\""
1706 targetJson=$targetJson"}"
1707 elif [ "$3" == "STD2" ]; then
1708 if [ $4 == "EMPTY" ]; then
1709 targetJson="{\"enforceStatus\":\"\""
1711 targetJson="{\"enforceStatus\":\"$4\""
1713 if [ $# -eq 5 ]; then
1714 if [ $5 == "EMPTY" ]; then
1715 targetJson=$targetJson",\"enforceReason\":\"\""
1717 targetJson=$targetJson",\"enforceReason\":\"$5\""
1720 targetJson=$targetJson"}"
1721 elif [ "$3" == "OSC" ]; then
1722 targetJson="{\"instance_status\":\"$4\""
1723 if [ $# -eq 5 ]; then
1724 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1726 targetJson=$targetJson",\"created_at\":\"????\"}"
1728 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1732 if [ "$A1PMS_VERSION" == "V2" ]; then
1733 query="/v2/policies/$UUID$2/status"
1734 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1736 query="/policy_status?id="$UUID$2
1739 res="$(__do_curl_to_api A1PMS GET $query)"
1740 status=${res:${#res}-3}
1742 if [ $status -ne $1 ]; then
1743 __log_test_fail_status_code $1 $status
1746 if [ $# -gt 2 ]; then
1747 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1748 body=${res:0:${#res}-3}
1749 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1751 if [ $res -ne 0 ]; then
1752 __log_test_fail_body
1756 __collect_endpoint_stats "A1PMS" 08 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}/status" $status
1761 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1762 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1763 # (Function for test scripts)
1764 a1pms_api_get_policy_types() {
1767 if [ $# -lt 1 ]; then
1768 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1772 if [ "$A1PMS_VERSION" == "V2" ]; then
1773 if [ $# -eq 1 ]; then
1774 query="/v2/policy-types"
1775 elif [ $2 == "NORIC" ]; then
1776 query="/v2/policy-types"
1778 query="/v2/policy-types?ric_id=$2"
1781 if [ $# -eq 1 ]; then
1782 query="/policy_types"
1783 elif [ $2 == "NORIC" ]; then
1784 query="/policy_types"
1786 query="/policy_types?ric=$2"
1790 res="$(__do_curl_to_api A1PMS GET $query)"
1791 status=${res:${#res}-3}
1793 if [ $status -ne $1 ]; then
1794 __log_test_fail_status_code $1 $status
1798 if [ $# -gt 2 ]; then
1799 body=${res:0:${#res}-3}
1802 for pid in ${@:3} ; do
1803 if [ "$targetJson" != "[" ]; then
1804 targetJson=$targetJson","
1806 if [ $pid == "EMPTY" ]; then
1809 targetJson=$targetJson"\"$pid\""
1812 targetJson=$targetJson"]"
1813 if [ "$A1PMS_VERSION" == "V2" ]; then
1814 targetJson="{\"policytype_ids\": $targetJson }"
1816 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1817 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1819 if [ $res -ne 0 ]; then
1820 __log_test_fail_body
1825 __collect_endpoint_stats "A1PMS" 09 "GET" $A1PMS_API_PREFIX"/v2/policy-types" $status
1830 #########################################################
1831 #### Test case functions Health check
1832 #########################################################
1834 # API Test function: GET /status and V2 GET /status
1835 # args: <response-code>
1836 # (Function for test scripts)
1837 a1pms_api_get_status() {
1839 if [ $# -ne 1 ]; then
1840 __print_err "<response-code>" $@
1843 if [ "$A1PMS_VERSION" == "V2" ]; then
1848 res="$(__do_curl_to_api A1PMS GET $query)"
1849 status=${res:${#res}-3}
1851 if [ $status -ne $1 ]; then
1852 __log_test_fail_status_code $1 $status
1856 __collect_endpoint_stats "A1PMS" 10 "GET" $A1PMS_API_PREFIX"/v2/status" $status
1861 # API Test function: GET /status (root) without api prefix
1862 # args: <response-code>
1863 # (Function for test scripts)
1864 a1pms_api_get_status_root() {
1866 if [ $# -ne 1 ]; then
1867 __print_err "<response-code>" $@
1871 TMP_PREFIX=$A1PMS_API_PREFIX
1873 res="$(__do_curl_to_api A1PMS GET $query)"
1874 A1PMS_API_PREFIX=$TMP_PREFIX
1875 status=${res:${#res}-3}
1877 if [ $status -ne $1 ]; then
1878 __log_test_fail_status_code $1 $status
1882 __collect_endpoint_stats "A1PMS" 19 "GET" "/status" $status
1887 #########################################################
1888 #### Test case functions RIC Repository
1889 #########################################################
1891 # API Test function: GET /ric and V2 GET /v2/rics/ric
1892 # args: <reponse-code> <management-element-id> [<ric-id>]
1893 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1894 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1895 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1898 # (Function for test scripts)
1899 a1pms_api_get_ric() {
1902 if [ "$A1PMS_VERSION" == "V2" ]; then
1903 if [ $# -lt 3 ]; then
1904 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1908 if [ $2 != "NOME" ]; then
1909 search="?managed_element_id="$2
1911 if [ $3 != "NORIC" ]; then
1912 if [ -z $search ]; then
1915 search=$search"&ric_id="$3
1918 query="/v2/rics/ric"$search
1920 res="$(__do_curl_to_api A1PMS GET $query)"
1921 status=${res:${#res}-3}
1923 if [ $status -ne $1 ]; then
1924 __log_test_fail_status_code $1 $status
1928 if [ $# -gt 3 ]; then
1929 body=${res:0:${#res}-3}
1930 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1931 if [ $res -ne 0 ]; then
1932 __log_test_fail_general "Could not create target ric info json"
1936 targetJson=$(<./tmp/.tmp_rics.json)
1937 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1938 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1939 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1940 if [ $res -ne 0 ]; then
1941 __log_test_fail_body
1946 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1947 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1951 query="/ric?managedElementId="$2
1953 res="$(__do_curl_to_api A1PMS GET $query)"
1954 status=${res:${#res}-3}
1956 if [ $status -ne $1 ]; then
1957 __log_test_fail_status_code $1 $status
1961 if [ $# -eq 3 ]; then
1962 body=${res:0:${#res}-3}
1963 if [ "$body" != "$3" ]; then
1964 __log_test_fail_body
1970 __collect_endpoint_stats "A1PMS" 11 "GET" $A1PMS_API_PREFIX"/v2/rics/ric" $status
1975 # API test function: GET /rics and V2 GET /v2/rics
1976 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1977 # 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_........."
1978 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1979 # (Function for test scripts)
1980 a1pms_api_get_rics() {
1983 if [ $# -lt 2 ]; then
1984 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1988 if [ "$A1PMS_VERSION" == "V2" ]; then
1990 if [ $2 != "NOTYPE" ]; then
1991 query="/v2/rics?policytype_id="$2
1995 if [ $2 != "NOTYPE" ]; then
1996 query="/rics?policyType="$2
2000 res="$(__do_curl_to_api A1PMS GET $query)"
2001 status=${res:${#res}-3}
2003 if [ $status -ne $1 ]; then
2004 __log_test_fail_status_code $1 $status
2008 if [ $# -gt 2 ]; then
2009 body=${res:0:${#res}-3}
2010 if [ "$A1PMS_VERSION" == "V2" ]; then
2011 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
2013 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
2015 if [ $res -ne 0 ]; then
2016 __log_test_fail_general "Could not create target ric info json"
2020 targetJson=$(<./tmp/.tmp_rics.json)
2021 if [ "$A1PMS_VERSION" == "V2" ]; then
2022 targetJson="{\"rics\": $targetJson }"
2024 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2025 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2026 if [ $res -ne 0 ]; then
2027 __log_test_fail_body
2032 __collect_endpoint_stats "A1PMS" 12 "GET" $A1PMS_API_PREFIX"/v2/rics" $status
2037 ##################################################################
2038 #### API Test case functions Service registry and supervision ####
2039 ##################################################################
2041 # API test function: PUT /service and V2 PUT /service
2042 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
2043 # (Function for test scripts)
2044 a1pms_api_put_service() {
2046 if [ $# -ne 4 ]; then
2047 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
2051 if [ "$A1PMS_VERSION" == "V2" ]; then
2052 query="/v2/services"
2053 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
2056 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
2058 file="./tmp/.tmp.json"
2059 echo "$json" > $file
2061 res="$(__do_curl_to_api A1PMS PUT $query $file)"
2062 status=${res:${#res}-3}
2064 if [ $status -ne $1 ]; then
2065 __log_test_fail_status_code $1 $status
2069 __collect_endpoint_stats "A1PMS" 13 "PUT" $A1PMS_API_PREFIX"/v2/service" $status
2074 # API test function: GET /services and V2 GET /v2/services
2075 #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>]* )]
2076 # (Function for test scripts)
2077 a1pms_api_get_services() {
2079 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
2081 if [ $# -eq 1 ]; then
2083 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
2085 elif [ $# -eq 5 ]; then
2087 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
2089 if [ $(($argLen%3)) -eq 0 ]; then
2094 if [ $paramError -ne 0 ]; then
2095 __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>]* )]" $@
2099 if [ "$A1PMS_VERSION" == "V2" ]; then
2100 query="/v2/services"
2102 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2103 query="/v2/services?service_id="$2
2108 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2109 query="/services?name="$2
2112 res="$(__do_curl_to_api A1PMS GET $query)"
2113 status=${res:${#res}-3}
2115 if [ $status -ne $1 ]; then
2116 __log_test_fail_status_code $1 $status
2120 if [ $# -gt 2 ]; then
2121 variableArgCount=$(($#-2))
2122 body=${res:0:${#res}-3}
2126 while [ $cntr -lt $variableArgCount ]; do
2127 servicename=$1; shift;
2130 if [ $cntr -gt 0 ]; then
2131 targetJson=$targetJson","
2133 # timeSinceLastActivitySeconds value cannot be checked since value varies
2134 if [ "$A1PMS_VERSION" == "V2" ]; then
2135 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
2137 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2141 targetJson=$targetJson"]"
2142 if [ "$A1PMS_VERSION" == "V2" ]; then
2143 targetJson="{\"service_list\": $targetJson }"
2145 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2146 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2147 if [ $res -ne 0 ]; then
2148 __log_test_fail_body
2153 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX"/v2/services" $status
2158 # API test function: GET /services V2 GET /v2/services - (only checking service names)
2159 # args: <response-code> [<service-name>]*"
2160 # (Function for test scripts)
2161 a1pms_api_get_service_ids() {
2164 if [ $# -lt 1 ]; then
2165 __print_err "<response-code> [<service-name>]*" $@
2169 if [ "$A1PMS_VERSION" == "V2" ]; then
2170 query="/v2/services"
2174 res="$(__do_curl_to_api A1PMS GET $query)"
2175 status=${res:${#res}-3}
2177 if [ $status -ne $1 ]; then
2178 __log_test_fail_status_code $1 $status
2182 body=${res:0:${#res}-3}
2184 for rapp in ${@:2} ; do
2185 if [ "$targetJson" != "[" ]; then
2186 targetJson=$targetJson","
2188 if [ "$A1PMS_VERSION" == "V2" ]; then
2189 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2191 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2195 targetJson=$targetJson"]"
2196 if [ "$A1PMS_VERSION" == "V2" ]; then
2197 targetJson="{\"service_list\": $targetJson }"
2199 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2200 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2202 if [ $res -ne 0 ]; then
2203 __log_test_fail_body
2207 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX"/v2/services" $status
2212 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
2213 # args: <response-code> <service-name>
2214 # (Function for test scripts)
2215 a1pms_api_delete_services() {
2218 if [ $# -ne 2 ]; then
2219 __print_err "<response-code> <service-name>" $@
2222 if [ "$A1PMS_VERSION" == "V2" ]; then
2223 query="/v2/services/"$2
2225 query="/services?name="$2
2227 res="$(__do_curl_to_api A1PMS DELETE $query)"
2228 status=${res:${#res}-3}
2230 if [ $status -ne $1 ]; then
2231 __log_test_fail_status_code $1 $status
2235 __collect_endpoint_stats "A1PMS" 15 "DELETE" $A1PMS_API_PREFIX"/v2/services/{serviceId}" $status
2240 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
2241 # args: <response-code> <service-name>
2242 # (Function for test scripts)
2243 a1pms_api_put_services_keepalive() {
2246 if [ $# -ne 2 ]; then
2247 __print_err "<response-code> <service-name>" $@
2250 if [ "$A1PMS_VERSION" == "V2" ]; then
2251 query="/v2/services/$2/keepalive"
2253 query="/services/keepalive?name="$2
2256 res="$(__do_curl_to_api A1PMS PUT $query)"
2257 status=${res:${#res}-3}
2259 if [ $status -ne $1 ]; then
2260 __log_test_fail_status_code $1 $status
2264 __collect_endpoint_stats "A1PMS" 16 "PUT" $A1PMS_API_PREFIX"/v2/services/{service_id}/keepalive" $status
2269 ##################################################################
2270 #### API Test case functions Configuration ####
2271 ##################################################################
2273 # API Test function: PUT /v2/configuration
2274 # args: <response-code> <config-file>
2275 # (Function for test scripts)
2276 a1pms_api_put_configuration() {
2279 if [ "$A1PMS_VERSION" != "V2" ]; then
2280 __log_test_fail_not_supported
2284 if [ $# -ne 2 ]; then
2285 __print_err "<response-code> <config-file>" $@
2288 if [ ! -f $2 ]; then
2289 __log_test_fail_general "Config file "$2", does not exist"
2293 if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
2294 inputJson="{\"config\":"$inputJson"}"
2296 file="./tmp/.config.json"
2297 echo $inputJson > $file
2298 query="/v2/configuration"
2299 res="$(__do_curl_to_api A1PMS PUT $query $file)"
2300 status=${res:${#res}-3}
2302 if [ $status -ne $1 ]; then
2303 __log_test_fail_status_code $1 $status
2307 __collect_endpoint_stats "A1PMS" 17 "PUT" $A1PMS_API_PREFIX"/v2/configuration" $status
2312 # API Test function: GET /v2/configuration
2313 # args: <response-code> [<config-file>]
2314 # (Function for test scripts)
2315 a1pms_api_get_configuration() {
2318 if [ "$A1PMS_VERSION" != "V2" ]; then
2319 __log_test_fail_not_supported
2323 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2324 __print_err "<response-code> [<config-file>]" $@
2327 if [ ! -f $2 ]; then
2328 __log_test_fail_general "Config file "$2" for comparison, does not exist"
2332 query="/v2/configuration"
2333 res="$(__do_curl_to_api A1PMS GET $query)"
2334 status=${res:${#res}-3}
2336 if [ $status -ne $1 ]; then
2337 __log_test_fail_status_code $1 $status
2341 if [ $# -eq 2 ]; then
2343 body=${res:0:${#res}-3}
2346 targetJson="{\"config\":"$targetJson"}"
2347 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2348 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2350 if [ $res -ne 0 ]; then
2351 __log_test_fail_body
2356 __collect_endpoint_stats "A1PMS" 18 "GET" $A1PMS_API_PREFIX"/v2/configuration" $status
2361 ##########################################
2362 #### Reset types and instances ####
2363 ##########################################
2365 # Admin reset to remove all policies and services
2366 # All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2367 # NOTE - only works in kubernetes and the pod should not be running
2369 # (Function for test scripts)
2371 a1pms_kube_pvc_reset() {
2374 pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
2375 if [ -z "$pvc_name" ]; then
2376 pvc_name=policymanagementservice-vardata-pvc
2378 echo " Trying to reset pvc: "$pvc_name
2379 __kube_clean_pvc $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $A1PMS_CONTAINER_MNT_DIR