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 Policy Agent
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
28 __check_and_create_image_var PA "POLICY_AGENT_IMAGE" "POLICY_AGENT_IMAGE_BASE" "POLICY_AGENT_IMAGE_TAG" $1 "$POLICY_AGENT_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 "$POLICY_AGENT_DISPLAY_NAME" $POLICY_AGENT_APP_NAME POLICY_AGENT_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
44 echo -e $RED" Image for app PA 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>
51 echo -e "$POLICY_AGENT_DISPLAY_NAME\t$(docker images --format $1 $POLICY_AGENT_IMAGE)" >> $2
52 if [ ! -z "$POLICY_AGENT_IMAGE_SOURCE" ]; then
53 echo -e "-- source image --\t$(docker images --format $1 $POLICY_AGENT_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 __PA_kube_scale_zero() {
61 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
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 __PA_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 __PA_kube_delete_all() {
73 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
77 # This function is called for apps managed by the test script.
78 # args: <log-dir> <file-prexix>
79 __PA_store_docker_logs() {
80 if [ $RUNMODE == "KUBE" ]; then
81 kubectl logs -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE --tail=-1 > $1$2_policy-agent.log 2>&1
83 docker logs $POLICY_AGENT_APP_NAME > $1$2_policy-agent.log 2>&1
87 # Initial setup of protocol, host and ports
88 # This function is called for apps managed by the test script.
90 __PA_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 __PA_statisics_setup() {
99 if [ $RUNMODE == "KUBE" ]; then
100 echo "PA $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE"
102 echo "PA $POLICY_AGENT_APP_NAME"
106 # Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
108 __PA_test_requirements() {
113 #######################################################
115 ###########################
116 ### Policy Agents functions
117 ###########################
119 # Set http as the protocol to use for all communication to the Policy Agent
121 # (Function for test scripts)
122 use_agent_rest_http() {
123 __agent_set_protocoll "http" $POLICY_AGENT_INTERNAL_PORT $POLICY_AGENT_EXTERNAL_PORT
126 # Set https as the protocol to use for all communication to the Policy Agent
128 # (Function for test scripts)
129 use_agent_rest_https() {
130 __agent_set_protocoll "https" $POLICY_AGENT_INTERNAL_SECURE_PORT $POLICY_AGENT_EXTERNAL_SECURE_PORT
133 # All calls to the agent will be directed to the agent dmaap interface over http from now on
135 # (Function for test scripts)
136 use_agent_dmaap_http() {
137 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME dmaap protocol setting"$EBOLD
138 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
139 PA_ADAPTER_TYPE="MR-HTTP"
143 # All calls to the agent will be directed to the agent dmaap interface over https from now on
145 # (Function for test scripts)
146 use_agent_dmaap_https() {
147 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME dmaap protocol setting"$EBOLD
148 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
149 echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
150 PA_ADAPTER_TYPE="MR-HTTPS"
154 # Setup paths to svc/container for internal and external access
155 # args: <protocol> <internal-port> <external-port>
156 __agent_set_protocoll() {
157 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME protocol setting"$EBOLD
158 echo -e " Using $BOLD $1 $EBOLD towards $POLICY_AGENT_DISPLAY_NAME"
160 ## Access to Dmaap adapter
162 PA_SERVICE_PATH=$1"://"$POLICY_AGENT_APP_NAME":"$2 # docker access, container->container and script->container via proxy
163 if [ $RUNMODE == "KUBE" ]; then
164 PA_SERVICE_PATH=$1"://"$POLICY_AGENT_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
167 # PA_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
168 PA_ADAPTER_TYPE="REST"
169 PA_ADAPTER=$PA_SERVICE_PATH
174 # Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
177 #Save first worker node the pod is started on
180 # Export env vars for config files, docker compose and kube resources
181 # args: PROXY|NOPROXY
182 __export_agent_vars() {
184 export POLICY_AGENT_APP_NAME
185 export POLICY_AGENT_APP_NAME_ALIAS
186 export POLICY_AGENT_DISPLAY_NAME
188 export KUBE_NONRTRIC_NAMESPACE
189 export POLICY_AGENT_IMAGE
190 export POLICY_AGENT_INTERNAL_PORT
191 export POLICY_AGENT_INTERNAL_SECURE_PORT
192 export POLICY_AGENT_EXTERNAL_PORT
193 export POLICY_AGENT_EXTERNAL_SECURE_PORT
194 export POLICY_AGENT_CONFIG_MOUNT_PATH
195 export POLICY_AGENT_DATA_MOUNT_PATH
196 export POLICY_AGENT_CONFIG_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-config"
197 export POLICY_AGENT_DATA_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-data"
198 export POLICY_AGENT_PKG_NAME
200 export CONSUL_INTERNAL_PORT
201 export CONFIG_BINDING_SERVICE
202 export POLICY_AGENT_CONFIG_KEY
203 export DOCKER_SIM_NWNAME
204 export POLICY_AGENT_HOST_MNT_DIR
205 export POLICY_AGENT_CONFIG_FILE
207 export POLICY_AGENT_DATA_PV_NAME=$POLICY_AGENT_APP_NAME"-pv"
208 export POLICY_AGENT_DATA_PVC_NAME=$POLICY_AGENT_APP_NAME"-pvc"
209 ##Create a unique path for the pv each time to prevent a previous volume to be reused
210 export POLICY_AGENT_PV_PATH="padata-"$(date +%s)
211 export POLICY_AGENT_CONTAINER_MNT_DIR
213 if [ $1 == "PROXY" ]; then
214 export AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
215 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
216 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
217 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
219 echo " Configured with http proxy"
222 export AGENT_HTTP_PROXY_CONFIG_PORT=0
223 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
224 echo " Configured without http proxy"
229 # Start the policy agent
230 # args: (docker) PROXY|NOPROXY <config-file>
231 # args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
232 # (Function for test scripts)
233 start_policy_agent() {
234 echo -e $BOLD"Starting $POLICY_AGENT_DISPLAY_NAME"$EBOLD
236 if [ $RUNMODE == "KUBE" ]; then
238 # Check if app shall be fully managed by the test script
239 __check_included_image "PA"
242 # Check if app shall only be used by the testscipt
243 __check_prestarted_image "PA"
246 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
247 echo -e $RED"The $POLICY_AGENT_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
248 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
251 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
252 echo -e $RED"The $POLICY_AGENT_APP_NAME app is included both as managed and prestarted in this test script"$ERED
253 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
257 if [ $retcode_p -eq 0 ]; then
258 echo -e " Using existing $POLICY_AGENT_APP_NAME deployment and service"
259 echo " Setting $POLICY_AGENT_APP_NAME replicas=1"
260 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
261 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
264 if [ $retcode_i -eq 0 ]; then
266 echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
268 #Check if nonrtric namespace exists, if not create it
269 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
271 __export_agent_vars $1
273 # Create config map for config
274 configfile=$PWD/tmp/$POLICY_AGENT_CONFIG_FILE
276 output_yaml=$PWD/tmp/pa_cfc.yaml
277 __kube_create_configmap $POLICY_AGENT_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $configfile $output_yaml
279 # Create config map for data
280 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
281 if [ $# -lt 3 ]; then
282 #create empty dummy file
283 echo "{}" > $data_json
287 output_yaml=$PWD/tmp/pa_cfd.yaml
288 __kube_create_configmap $POLICY_AGENT_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
291 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pv.yaml
292 output_yaml=$PWD/tmp/pa_pv.yaml
293 __kube_create_instance pv $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
296 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pvc.yaml
297 output_yaml=$PWD/tmp/pa_pvc.yaml
298 __kube_create_instance pvc $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
301 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"svc.yaml
302 output_yaml=$PWD/tmp/pa_svc.yaml
303 __kube_create_instance service $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
306 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"app.yaml
307 output_yaml=$PWD/tmp/pa_app.yaml
308 __kube_create_instance app $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
312 # 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
313 if [ $retcode_i -eq 0 ]; then
314 __PA_WORKER_NODE=$(kubectl get pod -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
315 if [ -z "$__PA_WORKER_NODE" ]; then
316 echo -e $YELLOW" Cannot find worker node for pod for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
319 echo -e $YELLOW" Persistency may not work for app $POLICY_AGENT_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
322 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
325 __check_included_image 'PA'
326 if [ $? -eq 1 ]; then
327 echo -e $RED"The Policy Agent app is not included in this test script"$ERED
328 echo -e $RED"The Policy Agent will not be started"$ERED
335 cd $POLICY_AGENT_HOST_MNT_DIR
338 if [ "$(ls -A $DIR)" ]; then
339 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
340 rm -rf db/* &> /dev/null
341 if [ $? -ne 0 ]; then
342 echo -e $RED" Cannot remove database files in: $PWD"$ERED
347 echo " No files in mounted dir or dir does not exists"
351 __export_agent_vars $1
353 dest_file=$SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_HOST_MNT_DIR/application.yaml
355 envsubst < $2 > $dest_file
357 __start_container $POLICY_AGENT_COMPOSE_DIR "" NODOCKERARGS 1 $POLICY_AGENT_APP_NAME
359 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
362 __collect_endpoint_stats_image_info "PMS" $POLICY_AGENT_IMAGE
367 # Stop the policy agent
370 # (Function for test scripts)
371 stop_policy_agent() {
372 echo -e $BOLD"Stopping $POLICY_AGENT_DISPLAY_NAME"$EBOLD
374 if [ $RUNMODE == "KUBE" ]; then
376 __check_prestarted_image "PA"
377 if [ $? -eq 0 ]; then
378 echo -e $YELLOW" Persistency may not work for app $POLICY_AGENT_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
379 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
380 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
383 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
384 echo " Deleting the replica set - a new will be started when the app is started"
385 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
386 if [ $? -ne 0 ]; then
387 echo -e $RED" Could not delete replica set "$RED
392 docker stop $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
393 if [ $? -ne 0 ]; then
394 __print_err "Could not stop $POLICY_AGENT_APP_NAME" $@
400 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
405 # Start a previously stopped policy agent
407 # (Function for test scripts)
408 start_stopped_policy_agent() {
409 echo -e $BOLD"Starting (the previously stopped) $POLICY_AGENT_DISPLAY_NAME"$EBOLD
411 if [ $RUNMODE == "KUBE" ]; then
413 __check_prestarted_image "PA"
414 if [ $? -eq 0 ]; then
415 echo -e $YELLOW" Persistency may not work for app $POLICY_AGENT_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
416 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
417 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
418 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
422 # Tie the PMS to the same worker node it was initially started on
423 # A PVC of type hostPath is mounted to PMS, for persistent storage, so the PMS must always be on the node which mounted the volume
424 if [ -z "$__PA_WORKER_NODE" ]; then
425 echo -e $RED" No initial worker node found for pod "$RED
429 echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__PA_WORKER_NODE to deployment for $POLICY_AGENT_APP_NAME. Pod will always run on this worker node: $__PA_WORKER_NODE"$BOLD
430 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
431 tmp=$(kubectl patch deployment $POLICY_AGENT_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__PA_WORKER_NODE'"}}}}}')
432 if [ $? -ne 0 ]; then
433 echo -e $YELLOW" Cannot set nodeSelector to deployment for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
435 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
438 docker start $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
439 if [ $? -ne 0 ]; then
440 __print_err "Could not start (the stopped) $POLICY_AGENT_APP_NAME" $@
446 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
447 if [ $? -ne 0 ]; then
455 # Function to perpare the consul configuration according to the current simulator configuration
456 # args: SDNC|NOSDNC <output-file>
457 # (Function for test scripts)
458 prepare_consul_config() {
459 echo -e $BOLD"Prepare Consul config"$EBOLD
461 echo " Writing consul config for "$POLICY_AGENT_APP_NAME" to file: "$2
465 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
469 if [ $1 == "SDNC" ]; then
470 echo -e " Config$BOLD including SDNC$EBOLD configuration"
471 elif [ $1 == "NOSDNC" ]; then
472 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
475 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
480 if [ $1 == "SDNC" ]; then
481 config_json=$config_json"\n \"controller\": ["
482 config_json=$config_json"\n {"
483 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
484 config_json=$config_json"\n \"baseUrl\": \"$SDNC_SERVICE_PATH\","
485 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
486 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
487 config_json=$config_json"\n }"
488 config_json=$config_json"\n ],"
491 config_json=$config_json"\n \"streams_publishes\": {"
492 config_json=$config_json"\n \"dmaap_publisher\": {"
493 config_json=$config_json"\n \"type\": \"message-router\","
494 config_json=$config_json"\n \"dmaap_info\": {"
495 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_WRITE_URL\""
496 config_json=$config_json"\n }"
497 config_json=$config_json"\n }"
498 config_json=$config_json"\n },"
499 config_json=$config_json"\n \"streams_subscribes\": {"
500 config_json=$config_json"\n \"dmaap_subscriber\": {"
501 config_json=$config_json"\n \"type\": \"message-router\","
502 config_json=$config_json"\n \"dmaap_info\": {"
503 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_READ_URL\""
504 config_json=$config_json"\n }"
505 config_json=$config_json"\n }"
506 config_json=$config_json"\n },"
508 config_json=$config_json"\n \"ric\": ["
510 if [ $RUNMODE == "KUBE" ]; then
511 result=$(kubectl get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICSIM")].metadata.name}')
514 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
515 for im in $result; do
516 if [[ $im != *"-0" ]]; then
517 ric_subdomain=$(kubectl get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
518 rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
519 let ric_cntr=ric_cntr+1
523 if [ $ric_cntr -eq 0 ]; then
524 echo $YELLOW"Warning: No rics found for the configuration"$EYELLOW
527 rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "status=running" --format {{.Names}})
528 if [ $? -ne 0 ] || [ -z "$rics" ]; then
529 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
536 if [ $cntr -gt 0 ]; then
537 config_json=$config_json"\n ,"
539 config_json=$config_json"\n {"
540 if [ $RUNMODE == "KUBE" ]; then
541 ric_id=${ric%.*.*} #extract pod id from full hosthame
542 ric_id=$(echo "$ric_id" | tr '-' '_')
544 if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
547 ric_id=$(echo "$ric" | tr '-' '_') #ric id still needs underscore as it is different from the container name
550 echo " Found a1 sim: "$ric_id
551 config_json=$config_json"\n \"name\": \"$ric_id\","
552 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
553 if [ $1 == "SDNC" ]; then
554 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
556 config_json=$config_json"\n \"managedElementIds\": ["
557 config_json=$config_json"\n \"me1_$ric_id\","
558 config_json=$config_json"\n \"me2_$ric_id\""
559 config_json=$config_json"\n ]"
560 config_json=$config_json"\n }"
564 config_json=$config_json"\n ]"
565 config_json=$config_json"\n}"
567 if [ $RUNMODE == "KUBE" ]; then
568 config_json="{\"config\":"$config_json"}"
571 printf "$config_json">$2
576 # Load the the appl config for the agent into a config map
577 agent_load_config() {
578 echo -e $BOLD"Agent - load config from "$EBOLD$1
579 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
581 output_yaml=$PWD/tmp/pa_cfd.yaml
582 __kube_create_configmap $POLICY_AGENT_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
587 # Turn on debug level tracing in the agent
589 # (Function for test scripts)
591 echo -e $BOLD"Setting agent debug logging"$EBOLD
592 curlString="$PA_SERVICE_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
593 result=$(__do_curl "$curlString")
594 if [ $? -ne 0 ]; then
595 __print_err "could not set debug mode" $@
603 # Turn on trace level tracing in the agent
605 # (Function for test scripts)
607 echo -e $BOLD"Setting agent trace logging"$EBOLD
608 curlString="$PA_SERVICE_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
609 result=$(__do_curl "$curlString")
610 if [ $? -ne 0 ]; then
611 __print_err "could not set trace mode" $@
619 # Perform curl retries when making direct call to the agent for the specified http response codes
620 # Speace separated list of http response codes
621 # args: [<response-code>]*
622 use_agent_retries() {
623 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
629 # Check the agent logs for WARNINGs and ERRORs
631 # (Function for test scripts)
632 check_policy_agent_logs() {
633 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
636 #########################################################
637 #### Test case functions A1 Policy management service
638 #########################################################
640 # This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
641 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
642 # args: json:<url> <target-value> [<timeout-in-seconds]
643 # (Function for test scripts)
645 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
646 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
647 if [[ $1 == "json:"* ]]; then
648 if [ "$PMS_VERSION" == "V2" ]; then
649 __var_test "Policy Agent" $PA_SERVICE_PATH$PMS_API_PREFIX"/v2/" $1 "=" $2 $3
651 __var_test "Policy Agent" $PA_SERVICE_PATH"/" $1 "=" $2 $3
656 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
660 # API Test function: GET /policies and V2 GET /v2/policy-instances
661 # 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>]*]
662 # 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>]*]
663 # (Function for test scripts)
667 if [ "$PMS_VERSION" == "V2" ]; then
669 variableParams=$(($#-4))
670 if [ $# -lt 4 ]; then
672 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
674 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
678 if [ $paramError -ne 0 ]; then
679 __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>]*]" $@
684 variableParams=$(($#-4))
685 if [ $# -lt 4 ]; then
687 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
689 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
693 if [ $paramError -ne 0 ]; then
694 __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>]*]" $@
700 if [ "$PMS_VERSION" == "V2" ]; then
701 if [ $2 != "NORIC" ]; then
702 queryparams="?ric_id="$2
704 if [ $3 != "NOSERVICE" ]; then
705 if [ -z $queryparams ]; then
706 queryparams="?service_id="$3
708 queryparams=$queryparams"&service_id="$3
711 if [ $4 != "NOTYPE" ]; then
712 if [ -z $queryparams ]; then
713 queryparams="?policytype_id="$4
715 queryparams=$queryparams"&policytype_id="$4
719 query="/v2/policy-instances"$queryparams
720 res="$(__do_curl_to_api PA GET $query)"
721 status=${res:${#res}-3}
723 if [ $status -ne $1 ]; then
724 __log_test_fail_status_code $1 $status
728 if [ $# -gt 4 ]; then
729 body=${res:0:${#res}-3}
730 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
736 for ((i=0; i<$(($#-4)); i=i+7)); do
738 if [ "$targetJson" != "[" ]; then
739 targetJson=$targetJson","
741 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
742 if [ "${arr[$i+3]}" == "EMPTY" ]; then
743 targetJson=$targetJson"\"\","
745 targetJson=$targetJson"\"${arr[$i+3]}\","
747 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
749 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
751 targetJson=$targetJson"\"policy_data\":"$json"}"
755 targetJson=$targetJson"]"
756 targetJson="{\"policies\": $targetJson}"
757 echo "TARGET JSON: $targetJson" >> $HTTPLOG
758 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
760 if [ $res -ne 0 ]; then
766 if [ $2 != "NORIC" ]; then
767 queryparams="?ric="$2
769 if [ $3 != "NOSERVICE" ]; then
770 if [ -z $queryparams ]; then
771 queryparams="?service="$3
773 queryparams=$queryparams"&service="$3
776 if [ $4 != "NOTYPE" ]; then
777 if [ -z $queryparams ]; then
778 queryparams="?type="$4
780 queryparams=$queryparams"&type="$4
784 query="/policies"$queryparams
785 res="$(__do_curl_to_api PA GET $query)"
786 status=${res:${#res}-3}
788 if [ $status -ne $1 ]; then
789 __log_test_fail_status_code $1 $status
793 if [ $# -gt 4 ]; then
794 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
797 body=${res:0:${#res}-3}
801 for ((i=0; i<$(($#-4)); i=i+5)); do
803 if [ "$targetJson" != "[" ]; then
804 targetJson=$targetJson","
806 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
807 if [ "${arr[$i+3]}" == "EMPTY" ]; then
808 targetJson=$targetJson"\"\","
810 targetJson=$targetJson"\"${arr[$i+3]}\","
813 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
815 targetJson=$targetJson"\"json\":"$json"}"
819 targetJson=$targetJson"]"
820 echo "TARGET JSON: $targetJson" >> $HTTPLOG
821 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
823 if [ $res -ne 0 ]; then
829 __collect_endpoint_stats "PMS" 00 "GET" $PMS_API_PREFIX"/v2/policy-instances" $status
836 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
837 # args: <response-code> <policy-id> [<template-file>]
838 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
840 # (Function for test scripts)
845 if [ "$PMS_VERSION" == "V2" ]; then
846 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
847 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
850 query="/v2/policies/$UUID$2"
852 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
853 __print_err "<response-code> <policy-id> [<template-file>] " $@
856 query="/policy?id=$UUID$2"
858 res="$(__do_curl_to_api PA GET $query)"
859 status=${res:${#res}-3}
861 if [ $status -ne $1 ]; then
862 __log_test_fail_status_code $1 $status
866 if [ "$PMS_VERSION" == "V2" ]; then
867 if [ $# -eq 8 ]; then
869 #Create a policy json to compare with
870 body=${res:0:${#res}-3}
872 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
873 if [ $7 != "NOTRANSIENT" ]; then
874 targetJson=$targetJson", \"transient\":$7"
876 if [ $6 != "NOTYPE" ]; then
877 targetJson=$targetJson", \"policytype_id\":\"$6\""
879 targetJson=$targetJson", \"policytype_id\":\"\""
881 if [ $8 != "NOURL" ]; then
882 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
885 data=$(sed 's/XXX/'${2}'/g' $3)
886 targetJson=$targetJson", \"policy_data\":$data"
887 targetJson="{$targetJson}"
889 echo "TARGET JSON: $targetJson" >> $HTTPLOG
890 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
891 if [ $res -ne 0 ]; then
897 if [ $# -eq 3 ]; then
898 #Create a policy json to compare with
899 body=${res:0:${#res}-3}
901 sed 's/XXX/'${2}'/g' $3 > $file
902 targetJson=$(< $file)
903 echo "TARGET JSON: $targetJson" >> $HTTPLOG
904 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
905 if [ $res -ne 0 ]; then
911 __collect_endpoint_stats "PMS" 01 "GET" $PMS_API_PREFIX"/v2/policies/{policy_id}" $status
916 # API Test function: PUT /policy and V2 PUT /policies
917 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
918 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
919 # (Function for test scripts)
923 if [ "$PMS_VERSION" == "V2" ]; then
924 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
925 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
929 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
930 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
943 if [ "$PMS_VERSION" == "V2" ]; then
946 if [ $# -eq 9 ]; then
951 if [ $# -eq 8 ]; then
956 while [ $count -lt $max ]; do
957 if [ "$PMS_VERSION" == "V2" ]; then
961 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
962 if [ $trans != "NOTRANSIENT" ]; then
963 inputJson=$inputJson", \"transient\":$trans"
965 if [ $pt != "NOTYPE" ]; then
966 inputJson=$inputJson", \"policytype_id\":\"$pt\""
968 inputJson=$inputJson", \"policytype_id\":\"\""
970 if [ $noti != "NOURL" ]; then
971 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
974 data=$(sed 's/XXX/'${pid}'/g' $temp)
975 inputJson=$inputJson", \"policy_data\":$data"
976 inputJson="{$inputJson}"
977 echo $inputJson > $file
979 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
981 if [ $pt != "NOTYPE" ]; then
982 query=$query"&type=$pt"
985 if [ $trans != NOTRANSIENT ]; then
986 query=$query"&transient=$trans"
990 sed 's/XXX/'${pid}'/g' $temp > $file
992 res="$(__do_curl_to_api PA PUT $query $file)"
993 status=${res:${#res}-3}
994 echo -ne " Executing "$count"("$max")${SAMELINE}"
995 if [ $status -ne $1 ]; then
996 echo " Executed "$count"?("$max")"
997 __log_test_fail_status_code $1 $status
1002 echo -ne " Executed "$count"("$max")${SAMELINE}"
1004 __collect_endpoint_stats "PMS" 02 "PUT" $PMS_API_PREFIX"/v2/policies" $status $max
1011 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
1012 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
1013 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
1014 # (Function for test scripts)
1016 api_put_policy_batch() {
1019 if [ "$PMS_VERSION" == "V2" ]; then
1020 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1021 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
1025 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1026 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
1038 if [ "$PMS_VERSION" == "V2" ]; then
1041 if [ $# -eq 9 ]; then
1046 if [ $# -eq 8 ]; then
1052 while [ $count -lt $max ]; do
1053 if [ "$PMS_VERSION" == "V2" ]; then
1054 query="/v2/policies"
1056 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1057 if [ $trans != "NOTRANSIENT" ]; then
1058 inputJson=$inputJson", \"transient\":$trans"
1060 if [ $pt != "NOTYPE" ]; then
1061 inputJson=$inputJson", \"policytype_id\":\"$pt\""
1063 inputJson=$inputJson", \"policytype_id\":\"\""
1065 if [ $noti != "NOURL" ]; then
1066 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1068 file="./tmp/.p.json"
1069 data=$(sed 's/XXX/'${pid}'/g' $temp)
1070 inputJson=$inputJson", \"policy_data\":$data"
1071 inputJson="{$inputJson}"
1072 echo $inputJson > $file
1074 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
1076 if [ $pt != "NOTYPE" ]; then
1077 query=$query"&type=$pt"
1080 if [ $trans != NOTRANSIENT ]; then
1081 query=$query"&transient=$trans"
1083 file="./tmp/.p.json"
1084 sed 's/XXX/'${pid}'/g' $temp > $file
1086 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
1087 status=${res:${#res}-3}
1088 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1090 if [ $status -ne 200 ]; then
1091 echo " Requested(batch) "$count"?("$max")"
1092 __log_test_fail_status_code 200 $status
1095 cid=${res:0:${#res}-3}
1099 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1106 res="$(__do_curl_to_api PA RESPONSE $cid)"
1107 status=${res:${#res}-3}
1108 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
1110 if [ $status -ne $1 ]; then
1111 echo " Accepted(batch) "$count"?("$max")"
1112 __log_test_fail_status_code $1 $status
1117 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
1119 __collect_endpoint_stats "PMS" 02 "PUT" $PMS_API_PREFIX"/v2/policies" $1 $max
1127 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
1128 # 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>
1129 # 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>
1130 # (Function for test scripts)
1131 api_put_policy_parallel() {
1134 if [ "$PMS_VERSION" == "V2" ]; then
1135 if [ $# -ne 11 ]; then
1136 __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>" $@
1140 if [ $# -ne 10 ]; then
1141 __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>" $@
1145 resp_code=$1; shift;
1151 transient=$1; shift;
1152 if [ "$PMS_VERSION" == "V2" ]; then
1161 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1162 if [ $PA_ADAPTER_TYPE != "REST" ]; then
1163 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1164 echo " Info - will execute over agent REST"
1166 if [ "$PMS_VERSION" == "V2" ]; then
1167 if [ $serv == "NOSERVICE" ]; then
1170 query="$PMS_API_PREFIX/v2/policies"
1172 if [ $serv == "NOSERVICE" ]; then
1175 query="/policy?service=$serv"
1177 if [ $type != "NOTYPE" ]; then
1178 query=$query"&type=$type"
1181 if [ $transient != NOTRANSIENT ]; then
1182 query=$query"&transient=$transient"
1186 urlbase=${PA_ADAPTER}${query}
1189 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1190 httpproxy=$KUBE_PROXY_PATH
1193 for ((i=1; i<=$pids; i++))
1196 if [ -z "$uuid" ]; then
1199 echo "" > "./tmp/.pid${i}.res.txt"
1200 if [ "$PMS_VERSION" == "V2" ]; then
1201 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1203 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1206 done | xargs -n 1 -I{} -P $pids bash -c '{
1208 echo " Parallel process $arg started"
1209 tmp=$(< "./tmp/.pid${arg}.txt")
1210 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1213 for ((i=1; i<=$pids; i++))
1215 file="./tmp/.pid${i}.res.txt"
1217 if [ -z "$tmp" ]; then
1218 echo " Process $i : unknown result (result file empty"
1222 if [ $res == "0" ]; then
1223 echo " Process $i : OK - "${tmp:1}
1225 echo " Process $i : failed - "${tmp:1}
1230 if [ -z $msg ]; then
1231 __collect_endpoint_stats "PMS" 02 "PUT" $PMS_API_PREFIX"/v2/policies" $resp_code $(($count*$num_rics))
1232 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1236 __log_test_fail_general "One of more processes failed to execute"
1240 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
1241 # args: <response-code> <policy-id> [count]
1242 # (Function for test scripts)
1243 api_delete_policy() {
1246 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1247 __print_err "<response-code> <policy-id> [count]" $@
1254 if [ $# -eq 3 ]; then
1260 while [ $count -lt $max ]; do
1261 if [ "$PMS_VERSION" == "V2" ]; then
1262 query="/v2/policies/"$UUID$pid
1264 query="/policy?id="$UUID$pid
1266 res="$(__do_curl_to_api PA DELETE $query)"
1267 status=${res:${#res}-3}
1268 echo -ne " Executing "$count"("$max")${SAMELINE}"
1270 if [ $status -ne $1 ]; then
1271 echo " Executed "$count"?("$max")"
1272 __log_test_fail_status_code $1 $status
1278 echo -ne " Executed "$count"("$max")${SAMELINE}"
1280 __collect_endpoint_stats "PMS" 03 "DELETE" $PMS_API_PREFIX"/v2/policies/{policy_id}" $status $max
1287 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
1288 # args: <response-code> <policy-id> [count]
1289 # (Function for test scripts)
1290 api_delete_policy_batch() {
1293 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1294 __print_err "<response-code> <policy-id> [count]" $@
1301 if [ $# -eq 3 ]; then
1307 while [ $count -lt $max ]; do
1308 if [ "$PMS_VERSION" == "V2" ]; then
1309 query="/v2/policies/"$UUID$pid
1311 query="/policy?id="$UUID$pid
1313 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
1314 status=${res:${#res}-3}
1315 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1317 if [ $status -ne 200 ]; then
1318 echo " Requested(batch) "$count"?("$max")"
1319 __log_test_fail_status_code 200 $status
1322 cid=${res:0:${#res}-3}
1326 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1334 res="$(__do_curl_to_api PA RESPONSE $cid)"
1335 status=${res:${#res}-3}
1336 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1338 if [ $status -ne $1 ]; then
1339 echo " Deleted(batch) "$count"?("$max")"
1340 __log_test_fail_status_code $1 $status
1345 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1347 __collect_endpoint_stats "PMS" 03 "DELETE" $PMS_API_PREFIX"/v2/policies/{policy_id}" $1 $max
1355 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1356 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1357 # (Function for test scripts)
1358 api_delete_policy_parallel() {
1361 if [ $# -ne 5 ]; then
1362 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1365 resp_code=$1; shift;
1371 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1372 if [ $PA_ADAPTER_TYPE != "REST" ]; then
1373 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1374 echo " Info - will execute over agent REST"
1377 if [ "$PMS_VERSION" == "V2" ]; then
1378 query="$PMS_API_PREFIX/v2/policies/"
1383 urlbase=${PA_ADAPTER}${query}
1386 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1387 httpproxy=$KUBE_PROXY_PATH
1390 for ((i=1; i<=$pids; i++))
1393 if [ -z "$uuid" ]; then
1396 echo "" > "./tmp/.pid${i}.del.res.txt"
1397 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
1399 done | xargs -n 1 -I{} -P $pids bash -c '{
1401 echo " Parallel process $arg started"
1402 tmp=$(< "./tmp/.pid${arg}.del.txt")
1403 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1406 for ((i=1; i<=$pids; i++))
1408 file="./tmp/.pid${i}.del.res.txt"
1410 if [ -z "$tmp" ]; then
1411 echo " Process $i : unknown result (result file empty"
1415 if [ $res == "0" ]; then
1416 echo " Process $i : OK - "${tmp:1}
1418 echo " Process $i : failed - "${tmp:1}
1423 if [ -z $msg ]; then
1424 __collect_endpoint_stats "PMS" 03 "DELETE" $PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count*$num_rics))
1425 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1429 __log_test_fail_general "One of more processes failed to execute"
1433 # API Test function: GET /policy_ids and V2 GET /v2/policies
1434 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1435 # (Function for test scripts)
1436 api_get_policy_ids() {
1439 if [ $# -lt 4 ]; then
1440 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1446 if [ "$PMS_VERSION" == "V2" ]; then
1447 if [ $2 != "NORIC" ]; then
1448 queryparams="?ric_id="$2
1451 if [ $3 != "NOSERVICE" ]; then
1452 if [ -z $queryparams ]; then
1453 queryparams="?service_id="$3
1455 queryparams=$queryparams"&service_id="$3
1458 if [ $4 != "NOTYPE" ]; then
1459 if [ -z $queryparams ]; then
1460 queryparams="?policytype_id="$4
1462 queryparams=$queryparams"&policytype_id="$4
1466 query="/v2/policies"$queryparams
1468 if [ $2 != "NORIC" ]; then
1469 queryparams="?ric="$2
1472 if [ $3 != "NOSERVICE" ]; then
1473 if [ -z $queryparams ]; then
1474 queryparams="?service="$3
1476 queryparams=$queryparams"&service="$3
1479 if [ $4 != "NOTYPE" ]; then
1480 if [ -z $queryparams ]; then
1481 queryparams="?type="$4
1483 queryparams=$queryparams"&type="$4
1487 query="/policy_ids"$queryparams
1490 res="$(__do_curl_to_api PA GET $query)"
1491 status=${res:${#res}-3}
1493 if [ $status -ne $1 ]; then
1494 __log_test_fail_status_code $1 $status
1498 if [ $# -gt 4 ]; then
1499 body=${res:0:${#res}-3}
1502 for pid in ${@:5} ; do
1503 if [ "$targetJson" != "[" ]; then
1504 targetJson=$targetJson","
1506 if [ $pid != "NOID" ]; then
1507 targetJson=$targetJson"\"$UUID$pid\""
1511 targetJson=$targetJson"]"
1512 if [ "$PMS_VERSION" == "V2" ]; then
1513 targetJson="{\"policy_ids\": $targetJson}"
1515 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1516 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1518 if [ $res -ne 0 ]; then
1519 __log_test_fail_body
1524 __collect_endpoint_stats "PMS" 04 "GET" $PMS_API_PREFIX"/v2/policies" $status
1529 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
1530 # args(V2): <response-code> <policy-type-id> [<schema-file>]
1531 # (Function for test scripts)
1532 api_get_policy_type() {
1535 if [ "$PMS_VERSION" != "V2" ]; then
1536 __log_test_fail_not_supported
1540 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1541 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1544 query="/v2/policy-types/$2"
1546 res="$(__do_curl_to_api PA GET $query)"
1547 status=${res:${#res}-3}
1549 if [ $status -ne $1 ]; then
1550 __log_test_fail_status_code $1 $status
1554 if [ $# -eq 3 ]; then
1556 body=${res:0:${#res}-3}
1559 targetJson="{\"policy_schema\":$targetJson}"
1560 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1561 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1563 if [ $res -ne 0 ]; then
1564 __log_test_fail_body
1569 __collect_endpoint_stats "PMS" 05 "GET" $PMS_API_PREFIX"/v2/policy-types/{policyTypeId}" $status
1574 # API Test function: GET /policy_schema
1575 # args: <response-code> <policy-type-id> [<schema-file>]
1576 # (Function for test scripts)
1577 api_get_policy_schema() {
1580 if [ "$PMS_VERSION" == "V2" ]; then
1581 __log_test_fail_not_supported
1585 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1586 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1589 query="/policy_schema?id=$2"
1590 res="$(__do_curl_to_api PA GET $query)"
1591 status=${res:${#res}-3}
1593 if [ $status -ne $1 ]; then
1594 __log_test_fail_status_code $1 $status
1598 if [ $# -eq 3 ]; then
1600 body=${res:0:${#res}-3}
1604 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1605 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1607 if [ $res -ne 0 ]; then
1608 __log_test_fail_body
1613 __collect_endpoint_stats "PMS" 06 "GET" $PMS_API_PREFIX"/v2/policy_schema" $status
1618 # API Test function: GET /policy_schemas
1619 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
1620 # args(V2): <response-code>
1621 # (Function for test scripts)
1622 api_get_policy_schemas() {
1625 if [ "$PMS_VERSION" == "V2" ]; then
1626 if [ $# -ne 1 ]; then
1627 __print_err "<response-code>" $@
1631 if [ $# -lt 2 ]; then
1632 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1636 if [ "$PMS_VERSION" == "V2" ]; then
1637 query="/v2/policy-schemas"
1639 query="/policy_schemas"
1640 if [ $2 != "NORIC" ]; then
1641 query=$query"?ric="$2
1645 res="$(__do_curl_to_api PA GET $query)"
1646 status=${res:${#res}-3}
1648 if [ $status -ne $1 ]; then
1649 __log_test_fail_status_code $1 $status
1653 if [ $# -gt 2 ]; then
1654 body=${res:0:${#res}-3}
1657 for file in ${@:3} ; do
1658 if [ "$targetJson" != "[" ]; then
1659 targetJson=$targetJson","
1661 if [ $file == "NOFILE" ]; then
1662 targetJson=$targetJson"{}"
1664 targetJson=$targetJson$(< $file)
1668 targetJson=$targetJson"]"
1669 if [ "$PMS_VERSION" == "V2" ]; then
1670 targetJson="{\"policy_schemas\": $targetJson }"
1672 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1673 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1675 if [ $res -ne 0 ]; then
1676 __log_test_fail_body
1681 __collect_endpoint_stats "PMS" 07 "GET" $PMS_API_PREFIX"/v2/policy-schemas" $status
1686 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1687 # arg: <response-code> <policy-id> [ (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>) ]
1688 # (Function for test scripts)
1689 api_get_policy_status() {
1692 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
1693 __print_err "<response-code> <policy-id> [(STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)]" $@
1698 if [ $# -eq 2 ]; then
1700 elif [ "$3" == "STD" ]; then
1701 targetJson="{\"enforceStatus\":\"$4\""
1702 if [ $# -eq 5 ]; then
1703 targetJson=$targetJson",\"reason\":\"$5\""
1705 targetJson=$targetJson"}"
1706 elif [ "$3" == "STD2" ]; then
1707 if [ $4 == "EMPTY" ]; then
1708 targetJson="{\"enforceStatus\":\"\""
1710 targetJson="{\"enforceStatus\":\"$4\""
1712 if [ $# -eq 5 ]; then
1713 if [ $5 == "EMPTY" ]; then
1714 targetJson=$targetJson",\"enforceReason\":\"\""
1716 targetJson=$targetJson",\"enforceReason\":\"$5\""
1719 targetJson=$targetJson"}"
1720 elif [ "$3" == "OSC" ]; then
1721 targetJson="{\"instance_status\":\"$4\""
1722 if [ $# -eq 5 ]; then
1723 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1725 targetJson=$targetJson",\"created_at\":\"????\"}"
1727 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1731 if [ "$PMS_VERSION" == "V2" ]; then
1732 query="/v2/policies/$UUID$2/status"
1733 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1735 query="/policy_status?id="$UUID$2
1738 res="$(__do_curl_to_api PA GET $query)"
1739 status=${res:${#res}-3}
1741 if [ $status -ne $1 ]; then
1742 __log_test_fail_status_code $1 $status
1745 if [ $# -gt 2 ]; then
1746 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1747 body=${res:0:${#res}-3}
1748 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1750 if [ $res -ne 0 ]; then
1751 __log_test_fail_body
1755 __collect_endpoint_stats "PMS" 08 "GET" $PMS_API_PREFIX"/v2/policies/{policy_id}/status" $status
1760 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1761 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1762 # (Function for test scripts)
1763 api_get_policy_types() {
1766 if [ $# -lt 1 ]; then
1767 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1771 if [ "$PMS_VERSION" == "V2" ]; then
1772 if [ $# -eq 1 ]; then
1773 query="/v2/policy-types"
1774 elif [ $2 == "NORIC" ]; then
1775 query="/v2/policy-types"
1777 query="/v2/policy-types?ric_id=$2"
1780 if [ $# -eq 1 ]; then
1781 query="/policy_types"
1782 elif [ $2 == "NORIC" ]; then
1783 query="/policy_types"
1785 query="/policy_types?ric=$2"
1789 res="$(__do_curl_to_api PA GET $query)"
1790 status=${res:${#res}-3}
1792 if [ $status -ne $1 ]; then
1793 __log_test_fail_status_code $1 $status
1797 if [ $# -gt 2 ]; then
1798 body=${res:0:${#res}-3}
1801 for pid in ${@:3} ; do
1802 if [ "$targetJson" != "[" ]; then
1803 targetJson=$targetJson","
1805 if [ $pid == "EMPTY" ]; then
1808 targetJson=$targetJson"\"$pid\""
1811 targetJson=$targetJson"]"
1812 if [ "$PMS_VERSION" == "V2" ]; then
1813 targetJson="{\"policytype_ids\": $targetJson }"
1815 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1816 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1818 if [ $res -ne 0 ]; then
1819 __log_test_fail_body
1824 __collect_endpoint_stats "PMS" 09 "GET" $PMS_API_PREFIX"/v2/policy-types" $status
1829 #########################################################
1830 #### Test case functions Health check
1831 #########################################################
1833 # API Test function: GET /status and V2 GET /status
1834 # args: <response-code>
1835 # (Function for test scripts)
1838 if [ $# -ne 1 ]; then
1839 __print_err "<response-code>" $@
1842 if [ "$PMS_VERSION" == "V2" ]; then
1847 res="$(__do_curl_to_api PA GET $query)"
1848 status=${res:${#res}-3}
1850 if [ $status -ne $1 ]; then
1851 __log_test_fail_status_code $1 $status
1855 __collect_endpoint_stats "PMS" 10 "GET" $PMS_API_PREFIX"/v2/status" $status
1860 # API Test function: GET /status (root) without api prefix
1861 # args: <response-code>
1862 # (Function for test scripts)
1863 api_get_status_root() {
1865 if [ $# -ne 1 ]; then
1866 __print_err "<response-code>" $@
1870 TMP_PREFIX=$PMS_API_PREFIX
1872 res="$(__do_curl_to_api PA GET $query)"
1873 PMS_API_PREFIX=$TMP_PREFIX
1874 status=${res:${#res}-3}
1876 if [ $status -ne $1 ]; then
1877 __log_test_fail_status_code $1 $status
1881 __collect_endpoint_stats "PMS" 19 "GET" "/status" $status
1886 #########################################################
1887 #### Test case functions RIC Repository
1888 #########################################################
1890 # API Test function: GET /ric and V2 GET /v2/rics/ric
1891 # args: <reponse-code> <management-element-id> [<ric-id>]
1892 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1893 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1894 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1897 # (Function for test scripts)
1901 if [ "$PMS_VERSION" == "V2" ]; then
1902 if [ $# -lt 3 ]; then
1903 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1907 if [ $2 != "NOME" ]; then
1908 search="?managed_element_id="$2
1910 if [ $3 != "NORIC" ]; then
1911 if [ -z $search ]; then
1914 search=$search"&ric_id="$3
1917 query="/v2/rics/ric"$search
1919 res="$(__do_curl_to_api PA GET $query)"
1920 status=${res:${#res}-3}
1922 if [ $status -ne $1 ]; then
1923 __log_test_fail_status_code $1 $status
1927 if [ $# -gt 3 ]; then
1928 body=${res:0:${#res}-3}
1929 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1930 if [ $res -ne 0 ]; then
1931 __log_test_fail_general "Could not create target ric info json"
1935 targetJson=$(<./tmp/.tmp_rics.json)
1936 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1937 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1938 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1939 if [ $res -ne 0 ]; then
1940 __log_test_fail_body
1945 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1946 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1950 query="/ric?managedElementId="$2
1952 res="$(__do_curl_to_api PA GET $query)"
1953 status=${res:${#res}-3}
1955 if [ $status -ne $1 ]; then
1956 __log_test_fail_status_code $1 $status
1960 if [ $# -eq 3 ]; then
1961 body=${res:0:${#res}-3}
1962 if [ "$body" != "$3" ]; then
1963 __log_test_fail_body
1969 __collect_endpoint_stats "PMS" 11 "GET" $PMS_API_PREFIX"/v2/rics/ric" $status
1974 # API test function: GET /rics and V2 GET /v2/rics
1975 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1976 # 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_........."
1977 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1978 # (Function for test scripts)
1982 if [ $# -lt 2 ]; then
1983 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1987 if [ "$PMS_VERSION" == "V2" ]; then
1989 if [ $2 != "NOTYPE" ]; then
1990 query="/v2/rics?policytype_id="$2
1994 if [ $2 != "NOTYPE" ]; then
1995 query="/rics?policyType="$2
1999 res="$(__do_curl_to_api PA GET $query)"
2000 status=${res:${#res}-3}
2002 if [ $status -ne $1 ]; then
2003 __log_test_fail_status_code $1 $status
2007 if [ $# -gt 2 ]; then
2008 body=${res:0:${#res}-3}
2009 if [ "$PMS_VERSION" == "V2" ]; then
2010 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
2012 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
2014 if [ $res -ne 0 ]; then
2015 __log_test_fail_general "Could not create target ric info json"
2019 targetJson=$(<./tmp/.tmp_rics.json)
2020 if [ "$PMS_VERSION" == "V2" ]; then
2021 targetJson="{\"rics\": $targetJson }"
2023 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2024 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2025 if [ $res -ne 0 ]; then
2026 __log_test_fail_body
2031 __collect_endpoint_stats "PMS" 12 "GET" $PMS_API_PREFIX"/v2/rics" $status
2036 ##################################################################
2037 #### API Test case functions Service registry and supervision ####
2038 ##################################################################
2040 # API test function: PUT /service and V2 PUT /service
2041 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
2042 # (Function for test scripts)
2045 if [ $# -ne 4 ]; then
2046 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
2050 if [ "$PMS_VERSION" == "V2" ]; then
2051 query="/v2/services"
2052 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
2055 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
2057 file="./tmp/.tmp.json"
2058 echo "$json" > $file
2060 res="$(__do_curl_to_api PA PUT $query $file)"
2061 status=${res:${#res}-3}
2063 if [ $status -ne $1 ]; then
2064 __log_test_fail_status_code $1 $status
2068 __collect_endpoint_stats "PMS" 13 "PUT" $PMS_API_PREFIX"/v2/service" $status
2073 # API test function: GET /services and V2 GET /v2/services
2074 #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>]* )]
2075 # (Function for test scripts)
2076 api_get_services() {
2078 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
2080 if [ $# -eq 1 ]; then
2082 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
2084 elif [ $# -eq 5 ]; then
2086 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
2088 if [ $(($argLen%3)) -eq 0 ]; then
2093 if [ $paramError -ne 0 ]; then
2094 __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>]* )]" $@
2098 if [ "$PMS_VERSION" == "V2" ]; then
2099 query="/v2/services"
2101 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2102 query="/v2/services?service_id="$2
2107 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2108 query="/services?name="$2
2111 res="$(__do_curl_to_api PA GET $query)"
2112 status=${res:${#res}-3}
2114 if [ $status -ne $1 ]; then
2115 __log_test_fail_status_code $1 $status
2119 if [ $# -gt 2 ]; then
2120 variableArgCount=$(($#-2))
2121 body=${res:0:${#res}-3}
2125 while [ $cntr -lt $variableArgCount ]; do
2126 servicename=$1; shift;
2129 if [ $cntr -gt 0 ]; then
2130 targetJson=$targetJson","
2132 # timeSinceLastActivitySeconds value cannot be checked since value varies
2133 if [ "$PMS_VERSION" == "V2" ]; then
2134 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
2136 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2140 targetJson=$targetJson"]"
2141 if [ "$PMS_VERSION" == "V2" ]; then
2142 targetJson="{\"service_list\": $targetJson }"
2144 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2145 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2146 if [ $res -ne 0 ]; then
2147 __log_test_fail_body
2152 __collect_endpoint_stats "PMS" 14 "GET" $PMS_API_PREFIX"/v2/services" $status
2157 # API test function: GET /services V2 GET /v2/services - (only checking service names)
2158 # args: <response-code> [<service-name>]*"
2159 # (Function for test scripts)
2160 api_get_service_ids() {
2163 if [ $# -lt 1 ]; then
2164 __print_err "<response-code> [<service-name>]*" $@
2168 if [ "$PMS_VERSION" == "V2" ]; then
2169 query="/v2/services"
2173 res="$(__do_curl_to_api PA GET $query)"
2174 status=${res:${#res}-3}
2176 if [ $status -ne $1 ]; then
2177 __log_test_fail_status_code $1 $status
2181 body=${res:0:${#res}-3}
2183 for rapp in ${@:2} ; do
2184 if [ "$targetJson" != "[" ]; then
2185 targetJson=$targetJson","
2187 if [ "$PMS_VERSION" == "V2" ]; then
2188 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2190 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2194 targetJson=$targetJson"]"
2195 if [ "$PMS_VERSION" == "V2" ]; then
2196 targetJson="{\"service_list\": $targetJson }"
2198 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2199 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2201 if [ $res -ne 0 ]; then
2202 __log_test_fail_body
2206 __collect_endpoint_stats "PMS" 14 "GET" $PMS_API_PREFIX"/v2/services" $status
2211 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
2212 # args: <response-code> <service-name>
2213 # (Function for test scripts)
2214 api_delete_services() {
2217 if [ $# -ne 2 ]; then
2218 __print_err "<response-code> <service-name>" $@
2221 if [ "$PMS_VERSION" == "V2" ]; then
2222 query="/v2/services/"$2
2224 query="/services?name="$2
2226 res="$(__do_curl_to_api PA DELETE $query)"
2227 status=${res:${#res}-3}
2229 if [ $status -ne $1 ]; then
2230 __log_test_fail_status_code $1 $status
2234 __collect_endpoint_stats "PMS" 15 "DELETE" $PMS_API_PREFIX"/v2/services/{serviceId}" $status
2239 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
2240 # args: <response-code> <service-name>
2241 # (Function for test scripts)
2242 api_put_services_keepalive() {
2245 if [ $# -ne 2 ]; then
2246 __print_err "<response-code> <service-name>" $@
2249 if [ "$PMS_VERSION" == "V2" ]; then
2250 query="/v2/services/$2/keepalive"
2252 query="/services/keepalive?name="$2
2255 res="$(__do_curl_to_api PA PUT $query)"
2256 status=${res:${#res}-3}
2258 if [ $status -ne $1 ]; then
2259 __log_test_fail_status_code $1 $status
2263 __collect_endpoint_stats "PMS" 16 "PUT" $PMS_API_PREFIX"/v2/services/{service_id}/keepalive" $status
2268 ##################################################################
2269 #### API Test case functions Configuration ####
2270 ##################################################################
2272 # API Test function: PUT /v2/configuration
2273 # args: <response-code> <config-file>
2274 # (Function for test scripts)
2275 api_put_configuration() {
2278 if [ "$PMS_VERSION" != "V2" ]; then
2279 __log_test_fail_not_supported
2283 if [ $# -ne 2 ]; then
2284 __print_err "<response-code> <config-file>" $@
2287 if [ ! -f $2 ]; then
2288 __log_test_fail_general "Config file "$2", does not exist"
2292 if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
2293 inputJson="{\"config\":"$inputJson"}"
2295 file="./tmp/.config.json"
2296 echo $inputJson > $file
2297 query="/v2/configuration"
2298 res="$(__do_curl_to_api PA PUT $query $file)"
2299 status=${res:${#res}-3}
2301 if [ $status -ne $1 ]; then
2302 __log_test_fail_status_code $1 $status
2306 __collect_endpoint_stats "PMS" 17 "PUT" $PMS_API_PREFIX"/v2/configuration" $status
2311 # API Test function: GET /v2/configuration
2312 # args: <response-code> [<config-file>]
2313 # (Function for test scripts)
2314 api_get_configuration() {
2317 if [ "$PMS_VERSION" != "V2" ]; then
2318 __log_test_fail_not_supported
2322 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2323 __print_err "<response-code> [<config-file>]" $@
2326 if [ ! -f $2 ]; then
2327 __log_test_fail_general "Config file "$2" for comparison, does not exist"
2331 query="/v2/configuration"
2332 res="$(__do_curl_to_api PA GET $query)"
2333 status=${res:${#res}-3}
2335 if [ $status -ne $1 ]; then
2336 __log_test_fail_status_code $1 $status
2340 if [ $# -eq 2 ]; then
2342 body=${res:0:${#res}-3}
2345 targetJson="{\"config\":"$targetJson"}"
2346 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2347 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2349 if [ $res -ne 0 ]; then
2350 __log_test_fail_body
2355 __collect_endpoint_stats "PMS" 18 "GET" $PMS_API_PREFIX"/v2/configuration" $status
2360 ##########################################
2361 #### Reset types and instances ####
2362 ##########################################
2364 # Admin reset to remove all policies and services
2365 # All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2366 # NOTE - only works in kubernetes and the pod should not be running
2368 # (Function for test scripts)
2370 pms_kube_pvc_reset() {
2373 pvc_name=$(kubectl get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
2374 if [ -z "$pvc_name" ]; then
2375 pvc_name=policymanagementservice-vardata-pvc
2377 echo " Trying to reset pvc: "$pvc_name
2378 __kube_clean_pvc $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $POLICY_AGENT_CONTAINER_MNT_DIR