3 # ============LICENSE_START===============================================
4 # Copyright (C) 2020 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 nonrtric-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 docker logs $POLICY_AGENT_APP_NAME > $1$2_policy-agent.log 2>&1
83 #######################################################
85 ## Access to Policy agent
86 # Host name may be changed if app started by kube
87 # Direct access from script
89 PA_HOST_NAME=$LOCALHOST_NAME
90 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
92 # PA_ADAPTER used for switch between REST and DMAAP
93 PA_ADAPTER_TYPE="REST"
96 # Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
99 #Save first worker node the pod is started on
102 ###########################
103 ### Policy Agents functions
104 ###########################
106 # All calls to the agent will be directed to the agent REST interface from now on
108 # (Function for test scripts)
109 use_agent_rest_http() {
110 echo -e $BOLD"Agent protocol setting"$EBOLD
111 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards the agent"
113 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
115 PA_ADAPTER_TYPE="REST"
120 # All calls to the agent will be directed to the agent REST interface from now on
122 # (Function for test scripts)
123 use_agent_rest_https() {
124 echo -e $BOLD"Agent protocol setting"$EBOLD
125 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent"
127 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_SECURE_PORT
129 PA_ADAPTER_TYPE="REST"
134 # All calls to the agent will be directed to the agent dmaap interface over http from now on
136 # (Function for test scripts)
137 use_agent_dmaap_http() {
138 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
139 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
140 PA_ADAPTER_TYPE="MR-HTTP"
144 # All calls to the agent will be directed to the agent dmaap interface over https from now on
146 # (Function for test scripts)
147 use_agent_dmaap_https() {
148 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
149 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
150 echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
151 PA_ADAPTER_TYPE="MR-HTTPS"
155 # Start the policy agent
156 # args: (docker) PROXY|NOPROXY <config-file>
157 # args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
158 # (Function for test scripts)
159 start_policy_agent() {
160 echo -e $BOLD"Starting $POLICY_AGENT_DISPLAY_NAME"$EBOLD
162 if [ $RUNMODE == "KUBE" ]; then
164 # Check if app shall be fully managed by the test script
165 __check_included_image "PA"
168 # Check if app shall only be used by the testscipt
169 __check_prestarted_image "PA"
172 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
173 echo -e $RED"The $POLICY_AGENT_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
174 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
177 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
178 echo -e $RED"The $POLICY_AGENT_APP_NAME app is included both as managed and prestarted in this test script"$ERED
179 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
183 if [ $retcode_p -eq 0 ]; then
184 echo -e " Using existing $POLICY_AGENT_APP_NAME deployment and service"
185 echo " Setting $POLICY_AGENT_APP_NAME replicas=1"
186 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
189 if [ $retcode_i -eq 0 ]; then
191 echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
193 #Check if nonrtric namespace exists, if not create it
194 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
196 #Export all vars needed for service and deployment
197 export POLICY_AGENT_APP_NAME
198 export KUBE_NONRTRIC_NAMESPACE
199 export POLICY_AGENT_IMAGE
200 export POLICY_AGENT_INTERNAL_PORT
201 export POLICY_AGENT_INTERNAL_SECURE_PORT
202 export POLICY_AGENT_EXTERNAL_PORT
203 export POLICY_AGENT_EXTERNAL_SECURE_PORT
204 export POLICY_AGENT_CONFIG_MOUNT_PATH
205 export POLICY_AGENT_DATA_MOUNT_PATH
206 export POLICY_AGENT_CONFIG_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-config"
207 export POLICY_AGENT_DATA_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-data"
208 export POLICY_AGENT_PKG_NAME
210 export POLICY_AGENT_DATA_PV_NAME=$POLICY_AGENT_APP_NAME"-pv"
211 export POLICY_AGENT_DATA_PVC_NAME=$POLICY_AGENT_APP_NAME"-pvc"
212 ##Create a unique path for the pv each time to prevent a previous volume to be reused
213 export POLICY_AGENT_PV_PATH="padata-"$(date +%s)
214 export POLICY_AGENT_CONTAINER_MNT_DIR
216 if [ $1 == "PROXY" ]; then
217 AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
218 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
219 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
220 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
222 echo " Configured with http proxy"
225 AGENT_HTTP_PROXY_CONFIG_PORT=0
226 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
227 echo " Configured without http proxy"
229 export AGENT_HTTP_PROXY_CONFIG_PORT
230 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME
233 # Create config map for config
234 configfile=$PWD/tmp/$POLICY_AGENT_CONFIG_FILE
236 output_yaml=$PWD/tmp/pa_cfc.yaml
237 __kube_create_configmap $POLICY_AGENT_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $configfile $output_yaml
239 # Create config map for data
240 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
241 if [ $# -lt 3 ]; then
242 #create empty dummy file
243 echo "{}" > $data_json
247 output_yaml=$PWD/tmp/pa_cfd.yaml
248 __kube_create_configmap $POLICY_AGENT_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
251 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pv.yaml
252 output_yaml=$PWD/tmp/pa_pv.yaml
253 __kube_create_instance pv $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
256 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pvc.yaml
257 output_yaml=$PWD/tmp/pa_pvc.yaml
258 __kube_create_instance pvc $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
261 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"svc.yaml
262 output_yaml=$PWD/tmp/pa_svc.yaml
263 __kube_create_instance service $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
266 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"app.yaml
267 output_yaml=$PWD/tmp/pa_app.yaml
268 __kube_create_instance app $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
272 # 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
273 if [ $retcode_i -eq 0 ]; then
274 __PA_WORKER_NODE=$(kubectl get pod -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
275 if [ -z "$__PA_WORKER_NODE" ]; then
276 echo -e $YELLOW" Cannot find worker node for pod for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
279 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
282 echo " Retrieving host and ports for service..."
283 PA_HOST_NAME=$(__kube_get_service_host $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
284 POLICY_AGENT_EXTERNAL_PORT=$(__kube_get_service_port $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
285 POLICY_AGENT_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
287 echo " Host IP, http port, https port: $PA_HOST_NAME $POLICY_AGENT_EXTERNAL_PORT $POLICY_AGENT_EXTERNAL_SECURE_PORT"
289 if [ $PA_HTTPX == "http" ]; then
290 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
292 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_SECURE_PORT
294 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
296 if [ $PA_ADAPTER_TYPE == "REST" ]; then
300 __check_included_image 'PA'
301 if [ $? -eq 1 ]; then
302 echo -e $RED"The Policy Agent app is not included in this test script"$ERED
303 echo -e $RED"The Policy Agent will not be started"$ERED
310 cd $POLICY_AGENT_HOST_MNT_DIR
313 if [ "$(ls -A $DIR)" ]; then
314 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
315 rm -rf db/* &> /dev/null
316 if [ $? -ne 0 ]; then
317 echo -e $RED" Cannot remove database files in: $PWD"$ERED
322 echo " No files in mounted dir or dir does not exists"
326 #Export all vars needed for docker-compose
327 export POLICY_AGENT_APP_NAME
328 export POLICY_AGENT_APP_NAME_ALIAS
329 export POLICY_AGENT_INTERNAL_PORT
330 export POLICY_AGENT_EXTERNAL_PORT
331 export POLICY_AGENT_INTERNAL_SECURE_PORT
332 export POLICY_AGENT_EXTERNAL_SECURE_PORT
334 export CONSUL_INTERNAL_PORT
335 export CONFIG_BINDING_SERVICE
336 export POLICY_AGENT_CONFIG_KEY
337 export DOCKER_SIM_NWNAME
338 export POLICY_AGENT_HOST_MNT_DIR
339 export POLICY_AGENT_CONFIG_MOUNT_PATH
340 export POLICY_AGENT_CONFIG_FILE
341 export POLICY_AGENT_PKG_NAME
342 export POLICY_AGENT_DISPLAY_NAME
343 export POLICY_AGENT_CONTAINER_MNT_DIR
345 if [ $1 == "PROXY" ]; then
346 AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
347 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
348 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
349 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
351 echo " Configured with http proxy"
354 AGENT_HTTP_PROXY_CONFIG_PORT=0
355 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
356 echo " Configured without http proxy"
358 export AGENT_HTTP_PROXY_CONFIG_PORT
359 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME
361 dest_file=$SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_HOST_MNT_DIR/application.yaml
363 envsubst < $2 > $dest_file
365 __start_container $POLICY_AGENT_COMPOSE_DIR "" NODOCKERARGS 1 $POLICY_AGENT_APP_NAME
367 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
373 # Stop the policy agent
376 # (Function for test scripts)
377 stop_policy_agent() {
378 echo -e $BOLD"Stopping $POLICY_AGENT_DISPLAY_NAME"$EBOLD
380 if [ $RUNMODE == "KUBE" ]; then
382 __check_prestarted_image "PA"
383 if [ $? -eq 0 ]; then
384 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
385 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
388 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
389 echo " Deleting the replica set - a new will be started when the app is started"
390 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
391 if [ $? -ne 0 ]; then
392 echo -e $RED" Could not delete replica set "$RED
397 docker stop $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
398 if [ $? -ne 0 ]; then
399 __print_err "Could not stop $POLICY_AGENT_APP_NAME" $@
405 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
410 # Start a previously stopped policy agent
412 # (Function for test scripts)
413 start_stopped_policy_agent() {
414 echo -e $BOLD"Starting (the previously stopped) $POLICY_AGENT_DISPLAY_NAME"$EBOLD
416 if [ $RUNMODE == "KUBE" ]; then
418 __check_prestarted_image "PA"
419 if [ $? -eq 0 ]; then
420 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
421 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
422 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
426 # Tie the PMS to the same worker node it was initially started on
427 # 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
428 if [ -z "$__PA_WORKER_NODE" ]; then
429 echo -e $RED" No initial worker node found for pod "$RED
433 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
434 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
435 tmp=$(kubectl patch deployment $POLICY_AGENT_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__PA_WORKER_NODE'"}}}}}')
436 if [ $? -ne 0 ]; then
437 echo -e $YELLOW" Cannot set nodeSelector to deployment for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
439 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
442 docker start $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
443 if [ $? -ne 0 ]; then
444 __print_err "Could not start (the stopped) $POLICY_AGENT_APP_NAME" $@
450 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
451 if [ $? -ne 0 ]; then
460 # Load the the appl config for the agent into a config map
461 agent_load_config() {
462 echo -e $BOLD"Agent - load config from "$EBOLD$1
463 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
465 output_yaml=$PWD/tmp/pa_cfd.yaml
466 __kube_create_configmap $POLICY_AGENT_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
471 # Turn on debug level tracing in the agent
473 # (Function for test scripts)
475 echo -e $BOLD"Setting agent debug logging"$EBOLD
476 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
477 result=$(__do_curl "$curlString")
478 if [ $? -ne 0 ]; then
479 __print_err "could not set debug mode" $@
487 # Turn on trace level tracing in the agent
489 # (Function for test scripts)
491 echo -e $BOLD"Setting agent trace logging"$EBOLD
492 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
493 result=$(__do_curl "$curlString")
494 if [ $? -ne 0 ]; then
495 __print_err "could not set trace mode" $@
503 # Perform curl retries when making direct call to the agent for the specified http response codes
504 # Speace separated list of http response codes
505 # args: [<response-code>]*
506 use_agent_retries() {
507 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
513 # Check the agent logs for WARNINGs and ERRORs
515 # (Function for test scripts)
516 check_policy_agent_logs() {
517 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
520 #########################################################
521 #### Test case functions A1 Policy management service
522 #########################################################
524 # This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
525 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
526 # args: json:<url> <target-value> [<timeout-in-seconds]
527 # (Function for test scripts)
529 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
530 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
531 if [[ $1 == "json:"* ]]; then
532 if [ "$PMS_VERSION" == "V2" ]; then
533 __var_test "Policy Agent" $PA_PATH$PMS_API_PREFIX"/v2/" $1 "=" $2 $3
535 __var_test "Policy Agent" $PA_PATH"/" $1 "=" $2 $3
540 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
544 # API Test function: GET /policies and V2 GET /v2/policy-instances
545 # 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>]*]
546 # 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>]*]
547 # (Function for test scripts)
551 if [ "$PMS_VERSION" == "V2" ]; then
553 variableParams=$(($#-4))
554 if [ $# -lt 4 ]; then
556 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
558 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
562 if [ $paramError -ne 0 ]; then
563 __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>]*]" $@
568 variableParams=$(($#-4))
569 if [ $# -lt 4 ]; then
571 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
573 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
577 if [ $paramError -ne 0 ]; then
578 __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>]*]" $@
584 if [ "$PMS_VERSION" == "V2" ]; then
585 if [ $2 != "NORIC" ]; then
586 queryparams="?ric_id="$2
588 if [ $3 != "NOSERVICE" ]; then
589 if [ -z $queryparams ]; then
590 queryparams="?service_id="$3
592 queryparams=$queryparams"&service_id="$3
595 if [ $4 != "NOTYPE" ]; then
596 if [ -z $queryparams ]; then
597 queryparams="?policytype_id="$4
599 queryparams=$queryparams"&policytype_id="$4
603 query="/v2/policy-instances"$queryparams
604 res="$(__do_curl_to_api PA GET $query)"
605 status=${res:${#res}-3}
607 if [ $status -ne $1 ]; then
608 __log_test_fail_status_code $1 $status
612 if [ $# -gt 4 ]; then
613 body=${res:0:${#res}-3}
614 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
620 for ((i=0; i<$(($#-4)); i=i+7)); do
622 if [ "$targetJson" != "[" ]; then
623 targetJson=$targetJson","
625 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
626 if [ "${arr[$i+3]}" == "EMPTY" ]; then
627 targetJson=$targetJson"\"\","
629 targetJson=$targetJson"\"${arr[$i+3]}\","
631 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
633 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
635 targetJson=$targetJson"\"policy_data\":"$json"}"
639 targetJson=$targetJson"]"
640 targetJson="{\"policies\": $targetJson}"
641 echo "TARGET JSON: $targetJson" >> $HTTPLOG
642 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
644 if [ $res -ne 0 ]; then
650 if [ $2 != "NORIC" ]; then
651 queryparams="?ric="$2
653 if [ $3 != "NOSERVICE" ]; then
654 if [ -z $queryparams ]; then
655 queryparams="?service="$3
657 queryparams=$queryparams"&service="$3
660 if [ $4 != "NOTYPE" ]; then
661 if [ -z $queryparams ]; then
662 queryparams="?type="$4
664 queryparams=$queryparams"&type="$4
668 query="/policies"$queryparams
669 res="$(__do_curl_to_api PA GET $query)"
670 status=${res:${#res}-3}
672 if [ $status -ne $1 ]; then
673 __log_test_fail_status_code $1 $status
677 if [ $# -gt 4 ]; then
678 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
681 body=${res:0:${#res}-3}
685 for ((i=0; i<$(($#-4)); i=i+5)); do
687 if [ "$targetJson" != "[" ]; then
688 targetJson=$targetJson","
690 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
691 if [ "${arr[$i+3]}" == "EMPTY" ]; then
692 targetJson=$targetJson"\"\","
694 targetJson=$targetJson"\"${arr[$i+3]}\","
697 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
699 targetJson=$targetJson"\"json\":"$json"}"
703 targetJson=$targetJson"]"
704 echo "TARGET JSON: $targetJson" >> $HTTPLOG
705 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
707 if [ $res -ne 0 ]; then
720 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
721 # args: <response-code> <policy-id> [<template-file>]
722 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
724 # (Function for test scripts)
729 if [ "$PMS_VERSION" == "V2" ]; then
730 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
731 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
734 query="/v2/policies/$UUID$2"
736 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
737 __print_err "<response-code> <policy-id> [<template-file>] " $@
740 query="/policy?id=$UUID$2"
742 res="$(__do_curl_to_api PA GET $query)"
743 status=${res:${#res}-3}
745 if [ $status -ne $1 ]; then
746 __log_test_fail_status_code $1 $status
750 if [ "$PMS_VERSION" == "V2" ]; then
751 if [ $# -eq 8 ]; then
753 #Create a policy json to compare with
754 body=${res:0:${#res}-3}
756 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
757 if [ $7 != "NOTRANSIENT" ]; then
758 targetJson=$targetJson", \"transient\":$7"
760 if [ $6 != "NOTYPE" ]; then
761 targetJson=$targetJson", \"policytype_id\":\"$6\""
763 targetJson=$targetJson", \"policytype_id\":\"\""
765 if [ $8 != "NOURL" ]; then
766 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
769 data=$(sed 's/XXX/'${2}'/g' $3)
770 targetJson=$targetJson", \"policy_data\":$data"
771 targetJson="{$targetJson}"
773 echo "TARGET JSON: $targetJson" >> $HTTPLOG
774 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
775 if [ $res -ne 0 ]; then
781 if [ $# -eq 3 ]; then
782 #Create a policy json to compare with
783 body=${res:0:${#res}-3}
785 sed 's/XXX/'${2}'/g' $3 > $file
786 targetJson=$(< $file)
787 echo "TARGET JSON: $targetJson" >> $HTTPLOG
788 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
789 if [ $res -ne 0 ]; then
799 # API Test function: PUT /policy and V2 PUT /policies
800 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
801 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
802 # (Function for test scripts)
806 if [ "$PMS_VERSION" == "V2" ]; then
807 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
808 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
812 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
813 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
826 if [ "$PMS_VERSION" == "V2" ]; then
829 if [ $# -eq 9 ]; then
834 if [ $# -eq 8 ]; then
839 while [ $count -lt $max ]; do
840 if [ "$PMS_VERSION" == "V2" ]; then
844 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
845 if [ $trans != "NOTRANSIENT" ]; then
846 inputJson=$inputJson", \"transient\":$trans"
848 if [ $pt != "NOTYPE" ]; then
849 inputJson=$inputJson", \"policytype_id\":\"$pt\""
851 inputJson=$inputJson", \"policytype_id\":\"\""
853 if [ $noti != "NOURL" ]; then
854 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
857 data=$(sed 's/XXX/'${pid}'/g' $temp)
858 inputJson=$inputJson", \"policy_data\":$data"
859 inputJson="{$inputJson}"
860 echo $inputJson > $file
862 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
864 if [ $pt != "NOTYPE" ]; then
865 query=$query"&type=$pt"
868 if [ $trans != NOTRANSIENT ]; then
869 query=$query"&transient=$trans"
873 sed 's/XXX/'${pid}'/g' $temp > $file
875 res="$(__do_curl_to_api PA PUT $query $file)"
876 status=${res:${#res}-3}
877 echo -ne " Executing "$count"("$max")${SAMELINE}"
878 if [ $status -ne $1 ]; then
879 echo " Executed "$count"?("$max")"
880 __log_test_fail_status_code $1 $status
886 echo -ne " Executed "$count"("$max")${SAMELINE}"
894 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
895 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
896 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
897 # (Function for test scripts)
899 api_put_policy_batch() {
902 if [ "$PMS_VERSION" == "V2" ]; then
903 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
904 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
908 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
909 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
921 if [ "$PMS_VERSION" == "V2" ]; then
924 if [ $# -eq 9 ]; then
929 if [ $# -eq 8 ]; then
935 while [ $count -lt $max ]; do
936 if [ "$PMS_VERSION" == "V2" ]; then
939 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
940 if [ $trans != "NOTRANSIENT" ]; then
941 inputJson=$inputJson", \"transient\":$trans"
943 if [ $pt != "NOTYPE" ]; then
944 inputJson=$inputJson", \"policytype_id\":\"$pt\""
946 inputJson=$inputJson", \"policytype_id\":\"\""
948 if [ $noti != "NOURL" ]; then
949 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
952 data=$(sed 's/XXX/'${pid}'/g' $temp)
953 inputJson=$inputJson", \"policy_data\":$data"
954 inputJson="{$inputJson}"
955 echo $inputJson > $file
957 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
959 if [ $pt != "NOTYPE" ]; then
960 query=$query"&type=$pt"
963 if [ $trans != NOTRANSIENT ]; then
964 query=$query"&transient=$trans"
967 sed 's/XXX/'${pid}'/g' $temp > $file
969 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
970 status=${res:${#res}-3}
971 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
973 if [ $status -ne 200 ]; then
974 echo " Requested(batch) "$count"?("$max")"
975 __log_test_fail_status_code 200 $status
978 cid=${res:0:${#res}-3}
982 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
989 res="$(__do_curl_to_api PA RESPONSE $cid)"
990 status=${res:${#res}-3}
991 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
993 if [ $status -ne $1 ]; then
994 echo " Accepted(batch) "$count"?("$max")"
995 __log_test_fail_status_code $1 $status
1000 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
1009 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
1010 # 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>
1011 # 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>
1012 # (Function for test scripts)
1013 api_put_policy_parallel() {
1016 if [ "$PMS_VERSION" == "V2" ]; then
1017 if [ $# -ne 11 ]; then
1018 __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>" $@
1022 if [ $# -ne 10 ]; then
1023 __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>" $@
1027 resp_code=$1; shift;
1033 transient=$1; shift;
1034 if [ "$PMS_VERSION" == "V2" ]; then
1043 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1044 if [ $PA_ADAPTER_TYPE != "REST" ]; then
1045 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1046 echo " Info - will execute over agent REST"
1048 if [ "$PMS_VERSION" == "V2" ]; then
1049 if [ $serv == "NOSERVICE" ]; then
1052 query="$PMS_API_PREFIX/v2/policies"
1054 if [ $serv == "NOSERVICE" ]; then
1057 query="/policy?service=$serv"
1059 if [ $type != "NOTYPE" ]; then
1060 query=$query"&type=$type"
1063 if [ $transient != NOTRANSIENT ]; then
1064 query=$query"&transient=$transient"
1068 urlbase=${PA_ADAPTER}${query}
1071 if [ $RUNMODE == "KUBE" ]; then
1072 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1073 httpproxy=$KUBE_PROXY_PATH
1077 for ((i=1; i<=$pids; i++))
1080 if [ -z "$uuid" ]; then
1083 echo "" > "./tmp/.pid${i}.res.txt"
1084 if [ "$PMS_VERSION" == "V2" ]; then
1085 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1087 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1090 done | xargs -n 1 -I{} -P $pids bash -c '{
1092 echo " Parallel process $arg started"
1093 tmp=$(< "./tmp/.pid${arg}.txt")
1094 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1097 for ((i=1; i<=$pids; i++))
1099 file="./tmp/.pid${i}.res.txt"
1101 if [ -z "$tmp" ]; then
1102 echo " Process $i : unknown result (result file empty"
1106 if [ $res == "0" ]; then
1107 echo " Process $i : OK - "${tmp:1}
1109 echo " Process $i : failed - "${tmp:1}
1114 if [ -z $msg ]; then
1115 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1119 __log_test_fail_general "One of more processes failed to execute"
1123 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
1124 # args: <response-code> <policy-id> [count]
1125 # (Function for test scripts)
1126 api_delete_policy() {
1129 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1130 __print_err "<response-code> <policy-id> [count]" $@
1137 if [ $# -eq 3 ]; then
1143 while [ $count -lt $max ]; do
1144 if [ "$PMS_VERSION" == "V2" ]; then
1145 query="/v2/policies/"$UUID$pid
1147 query="/policy?id="$UUID$pid
1149 res="$(__do_curl_to_api PA DELETE $query)"
1150 status=${res:${#res}-3}
1151 echo -ne " Executing "$count"("$max")${SAMELINE}"
1153 if [ $status -ne $1 ]; then
1154 echo " Executed "$count"?("$max")"
1155 __log_test_fail_status_code $1 $status
1160 echo -ne " Executed "$count"("$max")${SAMELINE}"
1168 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
1169 # args: <response-code> <policy-id> [count]
1170 # (Function for test scripts)
1171 api_delete_policy_batch() {
1174 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1175 __print_err "<response-code> <policy-id> [count]" $@
1182 if [ $# -eq 3 ]; then
1188 while [ $count -lt $max ]; do
1189 if [ "$PMS_VERSION" == "V2" ]; then
1190 query="/v2/policies/"$UUID$pid
1192 query="/policy?id="$UUID$pid
1194 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
1195 status=${res:${#res}-3}
1196 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1198 if [ $status -ne 200 ]; then
1199 echo " Requested(batch) "$count"?("$max")"
1200 __log_test_fail_status_code 200 $status
1203 cid=${res:0:${#res}-3}
1207 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1215 res="$(__do_curl_to_api PA RESPONSE $cid)"
1216 status=${res:${#res}-3}
1217 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1219 if [ $status -ne $1 ]; then
1220 echo " Deleted(batch) "$count"?("$max")"
1221 __log_test_fail_status_code $1 $status
1226 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1235 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1236 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1237 # (Function for test scripts)
1238 api_delete_policy_parallel() {
1241 if [ $# -ne 5 ]; then
1242 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1245 resp_code=$1; shift;
1251 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1252 if [ $PA_ADAPTER_TYPE != "REST" ]; then
1253 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1254 echo " Info - will execute over agent REST"
1257 if [ "$PMS_VERSION" == "V2" ]; then
1258 query="$PMS_API_PREFIX/v2/policies/"
1263 urlbase=${PA_ADAPTER}${query}
1266 if [ $RUNMODE == "KUBE" ]; then
1267 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1268 httpproxy=$KUBE_PROXY_PATH
1272 for ((i=1; i<=$pids; i++))
1275 if [ -z "$uuid" ]; then
1278 echo "" > "./tmp/.pid${i}.del.res.txt"
1279 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
1281 done | xargs -n 1 -I{} -P $pids bash -c '{
1283 echo " Parallel process $arg started"
1284 tmp=$(< "./tmp/.pid${arg}.del.txt")
1285 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1288 for ((i=1; i<=$pids; i++))
1290 file="./tmp/.pid${i}.del.res.txt"
1292 if [ -z "$tmp" ]; then
1293 echo " Process $i : unknown result (result file empty"
1297 if [ $res == "0" ]; then
1298 echo " Process $i : OK - "${tmp:1}
1300 echo " Process $i : failed - "${tmp:1}
1305 if [ -z $msg ]; then
1306 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1310 __log_test_fail_general "One of more processes failed to execute"
1314 # API Test function: GET /policy_ids and V2 GET /v2/policies
1315 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1316 # (Function for test scripts)
1317 api_get_policy_ids() {
1320 if [ $# -lt 4 ]; then
1321 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1327 if [ "$PMS_VERSION" == "V2" ]; then
1328 if [ $2 != "NORIC" ]; then
1329 queryparams="?ric_id="$2
1332 if [ $3 != "NOSERVICE" ]; then
1333 if [ -z $queryparams ]; then
1334 queryparams="?service_id="$3
1336 queryparams=$queryparams"&service_id="$3
1339 if [ $4 != "NOTYPE" ]; then
1340 if [ -z $queryparams ]; then
1341 queryparams="?policytype_id="$4
1343 queryparams=$queryparams"&policytype_id="$4
1347 query="/v2/policies"$queryparams
1349 if [ $2 != "NORIC" ]; then
1350 queryparams="?ric="$2
1353 if [ $3 != "NOSERVICE" ]; then
1354 if [ -z $queryparams ]; then
1355 queryparams="?service="$3
1357 queryparams=$queryparams"&service="$3
1360 if [ $4 != "NOTYPE" ]; then
1361 if [ -z $queryparams ]; then
1362 queryparams="?type="$4
1364 queryparams=$queryparams"&type="$4
1368 query="/policy_ids"$queryparams
1371 res="$(__do_curl_to_api PA GET $query)"
1372 status=${res:${#res}-3}
1374 if [ $status -ne $1 ]; then
1375 __log_test_fail_status_code $1 $status
1379 if [ $# -gt 4 ]; then
1380 body=${res:0:${#res}-3}
1383 for pid in ${@:5} ; do
1384 if [ "$targetJson" != "[" ]; then
1385 targetJson=$targetJson","
1387 if [ $pid != "NOID" ]; then
1388 targetJson=$targetJson"\"$UUID$pid\""
1392 targetJson=$targetJson"]"
1393 if [ "$PMS_VERSION" == "V2" ]; then
1394 targetJson="{\"policy_ids\": $targetJson}"
1396 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1397 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1399 if [ $res -ne 0 ]; then
1400 __log_test_fail_body
1409 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
1410 # args(V2): <response-code> <policy-type-id> [<schema-file>]
1411 # (Function for test scripts)
1412 api_get_policy_type() {
1415 if [ "$PMS_VERSION" != "V2" ]; then
1416 __log_test_fail_not_supported
1420 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1421 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1424 query="/v2/policy-types/$2"
1426 res="$(__do_curl_to_api PA GET $query)"
1427 status=${res:${#res}-3}
1429 if [ $status -ne $1 ]; then
1430 __log_test_fail_status_code $1 $status
1434 if [ $# -eq 3 ]; then
1436 body=${res:0:${#res}-3}
1439 targetJson="{\"policy_schema\":$targetJson}"
1440 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1441 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1443 if [ $res -ne 0 ]; then
1444 __log_test_fail_body
1453 # API Test function: GET /policy_schema
1454 # args: <response-code> <policy-type-id> [<schema-file>]
1455 # (Function for test scripts)
1456 api_get_policy_schema() {
1459 if [ "$PMS_VERSION" == "V2" ]; then
1460 __log_test_fail_not_supported
1464 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1465 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1468 query="/policy_schema?id=$2"
1469 res="$(__do_curl_to_api PA GET $query)"
1470 status=${res:${#res}-3}
1472 if [ $status -ne $1 ]; then
1473 __log_test_fail_status_code $1 $status
1477 if [ $# -eq 3 ]; then
1479 body=${res:0:${#res}-3}
1483 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1484 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1486 if [ $res -ne 0 ]; then
1487 __log_test_fail_body
1496 # API Test function: GET /policy_schemas
1497 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
1498 # args(V2): <response-code>
1499 # (Function for test scripts)
1500 api_get_policy_schemas() {
1503 if [ "$PMS_VERSION" == "V2" ]; then
1504 if [ $# -ne 1 ]; then
1505 __print_err "<response-code>" $@
1509 if [ $# -lt 2 ]; then
1510 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1514 if [ "$PMS_VERSION" == "V2" ]; then
1515 query="/v2/policy-schemas"
1517 query="/policy_schemas"
1518 if [ $2 != "NORIC" ]; then
1519 query=$query"?ric="$2
1523 res="$(__do_curl_to_api PA GET $query)"
1524 status=${res:${#res}-3}
1526 if [ $status -ne $1 ]; then
1527 __log_test_fail_status_code $1 $status
1531 if [ $# -gt 2 ]; then
1532 body=${res:0:${#res}-3}
1535 for file in ${@:3} ; do
1536 if [ "$targetJson" != "[" ]; then
1537 targetJson=$targetJson","
1539 if [ $file == "NOFILE" ]; then
1540 targetJson=$targetJson"{}"
1542 targetJson=$targetJson$(< $file)
1546 targetJson=$targetJson"]"
1547 if [ "$PMS_VERSION" == "V2" ]; then
1548 targetJson="{\"policy_schemas\": $targetJson }"
1550 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1551 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1553 if [ $res -ne 0 ]; then
1554 __log_test_fail_body
1563 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1564 # arg: <response-code> <policy-id> (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)
1565 # (Function for test scripts)
1566 api_get_policy_status() {
1569 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
1570 __print_err "<response-code> <policy-id> (STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)" $@
1576 if [ $3 == "STD" ]; then
1577 targetJson="{\"enforceStatus\":\"$4\""
1578 if [ $# -eq 5 ]; then
1579 targetJson=$targetJson",\"reason\":\"$5\""
1581 targetJson=$targetJson"}"
1582 elif [ $3 == "STD2" ]; then
1583 if [ $4 == "EMPTY" ]; then
1584 targetJson="{\"enforceStatus\":\"\""
1586 targetJson="{\"enforceStatus\":\"$4\""
1588 if [ $# -eq 5 ]; then
1589 if [ $5 == "EMPTY" ]; then
1590 targetJson=$targetJson",\"enforceReason\":\"\""
1592 targetJson=$targetJson",\"enforceReason\":\"$5\""
1595 targetJson=$targetJson"}"
1596 elif [ $3 == "OSC" ]; then
1597 targetJson="{\"instance_status\":\"$4\""
1598 if [ $# -eq 5 ]; then
1599 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1601 targetJson=$targetJson",\"created_at\":\"????\"}"
1603 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1607 if [ "$PMS_VERSION" == "V2" ]; then
1608 query="/v2/policies/$UUID$2/status"
1609 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1611 query="/policy_status?id="$UUID$2
1614 res="$(__do_curl_to_api PA GET $query)"
1615 status=${res:${#res}-3}
1617 if [ $status -ne $1 ]; then
1618 __log_test_fail_status_code $1 $status
1622 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1623 body=${res:0:${#res}-3}
1624 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1626 if [ $res -ne 0 ]; then
1627 __log_test_fail_body
1635 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1636 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1637 # (Function for test scripts)
1638 api_get_policy_types() {
1641 if [ $# -lt 1 ]; then
1642 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1646 if [ "$PMS_VERSION" == "V2" ]; then
1647 if [ $# -eq 1 ]; then
1648 query="/v2/policy-types"
1649 elif [ $2 == "NORIC" ]; then
1650 query="/v2/policy-types"
1652 query="/v2/policy-types?ric_id=$2"
1655 if [ $# -eq 1 ]; then
1656 query="/policy_types"
1657 elif [ $2 == "NORIC" ]; then
1658 query="/policy_types"
1660 query="/policy_types?ric=$2"
1664 res="$(__do_curl_to_api PA GET $query)"
1665 status=${res:${#res}-3}
1667 if [ $status -ne $1 ]; then
1668 __log_test_fail_status_code $1 $status
1672 if [ $# -gt 2 ]; then
1673 body=${res:0:${#res}-3}
1676 for pid in ${@:3} ; do
1677 if [ "$targetJson" != "[" ]; then
1678 targetJson=$targetJson","
1680 if [ $pid == "EMPTY" ]; then
1683 targetJson=$targetJson"\"$pid\""
1686 targetJson=$targetJson"]"
1687 if [ "$PMS_VERSION" == "V2" ]; then
1688 targetJson="{\"policytype_ids\": $targetJson }"
1690 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1691 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1693 if [ $res -ne 0 ]; then
1694 __log_test_fail_body
1703 #########################################################
1704 #### Test case functions Health check
1705 #########################################################
1707 # API Test function: GET /status and V2 GET /status
1708 # args: <response-code>
1709 # (Function for test scripts)
1712 if [ $# -ne 1 ]; then
1713 __print_err "<response-code>" $@
1716 if [ "$PMS_VERSION" == "V2" ]; then
1721 res="$(__do_curl_to_api PA GET $query)"
1722 status=${res:${#res}-3}
1724 if [ $status -ne $1 ]; then
1725 __log_test_fail_status_code $1 $status
1733 #########################################################
1734 #### Test case functions RIC Repository
1735 #########################################################
1737 # API Test function: GET /ric and V2 GET /v2/rics/ric
1738 # args: <reponse-code> <management-element-id> [<ric-id>]
1739 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1740 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1741 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1744 # (Function for test scripts)
1748 if [ "$PMS_VERSION" == "V2" ]; then
1749 if [ $# -lt 3 ]; then
1750 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1754 if [ $2 != "NOME" ]; then
1755 search="?managed_element_id="$2
1757 if [ $3 != "NORIC" ]; then
1758 if [ -z $search ]; then
1761 search=$search"&ric_id="$3
1764 query="/v2/rics/ric"$search
1766 res="$(__do_curl_to_api PA GET $query)"
1767 status=${res:${#res}-3}
1769 if [ $status -ne $1 ]; then
1770 __log_test_fail_status_code $1 $status
1774 if [ $# -gt 3 ]; then
1775 body=${res:0:${#res}-3}
1776 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1777 if [ $res -ne 0 ]; then
1778 __log_test_fail_general "Could not create target ric info json"
1782 targetJson=$(<./tmp/.tmp_rics.json)
1783 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1784 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1785 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1786 if [ $res -ne 0 ]; then
1787 __log_test_fail_body
1792 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1793 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1797 query="/ric?managedElementId="$2
1799 res="$(__do_curl_to_api PA GET $query)"
1800 status=${res:${#res}-3}
1802 if [ $status -ne $1 ]; then
1803 __log_test_fail_status_code $1 $status
1807 if [ $# -eq 3 ]; then
1808 body=${res:0:${#res}-3}
1809 if [ "$body" != "$3" ]; then
1810 __log_test_fail_body
1819 # API test function: GET /rics and V2 GET /v2/rics
1820 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1821 # 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_........."
1822 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1823 # (Function for test scripts)
1827 if [ $# -lt 2 ]; then
1828 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1832 if [ "$PMS_VERSION" == "V2" ]; then
1834 if [ $2 != "NOTYPE" ]; then
1835 query="/v2/rics?policytype_id="$2
1839 if [ $2 != "NOTYPE" ]; then
1840 query="/rics?policyType="$2
1844 res="$(__do_curl_to_api PA GET $query)"
1845 status=${res:${#res}-3}
1847 if [ $status -ne $1 ]; then
1848 __log_test_fail_status_code $1 $status
1852 if [ $# -gt 2 ]; then
1853 body=${res:0:${#res}-3}
1854 if [ "$PMS_VERSION" == "V2" ]; then
1855 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
1857 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
1859 if [ $res -ne 0 ]; then
1860 __log_test_fail_general "Could not create target ric info json"
1864 targetJson=$(<./tmp/.tmp_rics.json)
1865 if [ "$PMS_VERSION" == "V2" ]; then
1866 targetJson="{\"rics\": $targetJson }"
1868 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1869 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1870 if [ $res -ne 0 ]; then
1871 __log_test_fail_body
1880 ##################################################################
1881 #### API Test case functions Service registry and supervision ####
1882 ##################################################################
1884 # API test function: PUT /service and V2 PUT /service
1885 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1886 # (Function for test scripts)
1889 if [ $# -ne 4 ]; then
1890 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1894 if [ "$PMS_VERSION" == "V2" ]; then
1895 query="/v2/services"
1896 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
1899 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1901 file="./tmp/.tmp.json"
1902 echo "$json" > $file
1904 res="$(__do_curl_to_api PA PUT $query $file)"
1905 status=${res:${#res}-3}
1907 if [ $status -ne $1 ]; then
1908 __log_test_fail_status_code $1 $status
1916 # API test function: GET /services and V2 GET /v2/services
1917 #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>]* )]
1918 # (Function for test scripts)
1919 api_get_services() {
1921 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1923 if [ $# -eq 1 ]; then
1925 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1927 elif [ $# -eq 5 ]; then
1929 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1931 if [ $(($argLen%3)) -eq 0 ]; then
1936 if [ $paramError -ne 0 ]; then
1937 __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>]* )]" $@
1941 if [ "$PMS_VERSION" == "V2" ]; then
1942 query="/v2/services"
1944 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1945 query="/v2/services?service_id="$2
1950 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1951 query="/services?name="$2
1954 res="$(__do_curl_to_api PA GET $query)"
1955 status=${res:${#res}-3}
1957 if [ $status -ne $1 ]; then
1958 __log_test_fail_status_code $1 $status
1962 if [ $# -gt 2 ]; then
1963 variableArgCount=$(($#-2))
1964 body=${res:0:${#res}-3}
1968 while [ $cntr -lt $variableArgCount ]; do
1969 servicename=$1; shift;
1972 if [ $cntr -gt 0 ]; then
1973 targetJson=$targetJson","
1975 # timeSinceLastActivitySeconds value cannot be checked since value varies
1976 if [ "$PMS_VERSION" == "V2" ]; then
1977 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
1979 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1983 targetJson=$targetJson"]"
1984 if [ "$PMS_VERSION" == "V2" ]; then
1985 targetJson="{\"service_list\": $targetJson }"
1987 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1988 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1989 if [ $res -ne 0 ]; then
1990 __log_test_fail_body
1999 # API test function: GET /services V2 GET /v2/services - (only checking service names)
2000 # args: <response-code> [<service-name>]*"
2001 # (Function for test scripts)
2002 api_get_service_ids() {
2005 if [ $# -lt 1 ]; then
2006 __print_err "<response-code> [<service-name>]*" $@
2010 if [ "$PMS_VERSION" == "V2" ]; then
2011 query="/v2/services"
2015 res="$(__do_curl_to_api PA GET $query)"
2016 status=${res:${#res}-3}
2018 if [ $status -ne $1 ]; then
2019 __log_test_fail_status_code $1 $status
2023 body=${res:0:${#res}-3}
2025 for rapp in ${@:2} ; do
2026 if [ "$targetJson" != "[" ]; then
2027 targetJson=$targetJson","
2029 if [ "$PMS_VERSION" == "V2" ]; then
2030 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2032 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2036 targetJson=$targetJson"]"
2037 if [ "$PMS_VERSION" == "V2" ]; then
2038 targetJson="{\"service_list\": $targetJson }"
2040 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2041 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2043 if [ $res -ne 0 ]; then
2044 __log_test_fail_body
2052 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
2053 # args: <response-code> <service-name>
2054 # (Function for test scripts)
2055 api_delete_services() {
2058 if [ $# -ne 2 ]; then
2059 __print_err "<response-code> <service-name>" $@
2062 if [ "$PMS_VERSION" == "V2" ]; then
2063 query="/v2/services/"$2
2065 query="/services?name="$2
2067 res="$(__do_curl_to_api PA DELETE $query)"
2068 status=${res:${#res}-3}
2070 if [ $status -ne $1 ]; then
2071 __log_test_fail_status_code $1 $status
2079 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
2080 # args: <response-code> <service-name>
2081 # (Function for test scripts)
2082 api_put_services_keepalive() {
2085 if [ $# -ne 2 ]; then
2086 __print_err "<response-code> <service-name>" $@
2089 if [ "$PMS_VERSION" == "V2" ]; then
2090 query="/v2/services/$2/keepalive"
2092 query="/services/keepalive?name="$2
2095 res="$(__do_curl_to_api PA PUT $query)"
2096 status=${res:${#res}-3}
2098 if [ $status -ne $1 ]; then
2099 __log_test_fail_status_code $1 $status
2107 ##################################################################
2108 #### API Test case functions Configuration ####
2109 ##################################################################
2111 # API Test function: PUT /v2/configuration
2112 # args: <response-code> <config-file>
2113 # (Function for test scripts)
2114 api_put_configuration() {
2117 if [ "$PMS_VERSION" != "V2" ]; then
2118 __log_test_fail_not_supported
2122 if [ $# -ne 2 ]; then
2123 __print_err "<response-code> <config-file>" $@
2126 if [ ! -f $2 ]; then
2127 __log_test_fail_general "Config file "$2", does not exist"
2131 inputJson="{\"config\":"$inputJson"}"
2132 file="./tmp/.config.json"
2133 echo $inputJson > $file
2134 query="/v2/configuration"
2135 res="$(__do_curl_to_api PA PUT $query $file)"
2136 status=${res:${#res}-3}
2138 if [ $status -ne $1 ]; then
2139 __log_test_fail_status_code $1 $status
2147 # API Test function: GET /v2/configuration
2148 # args: <response-code> [<config-file>]
2149 # (Function for test scripts)
2150 api_get_configuration() {
2153 if [ "$PMS_VERSION" != "V2" ]; then
2154 __log_test_fail_not_supported
2158 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2159 __print_err "<response-code> [<config-file>]" $@
2162 if [ ! -f $2 ]; then
2163 __log_test_fail_general "Config file "$2" for comparison, does not exist"
2167 query="/v2/configuration"
2168 res="$(__do_curl_to_api PA GET $query)"
2169 status=${res:${#res}-3}
2171 if [ $status -ne $1 ]; then
2172 __log_test_fail_status_code $1 $status
2176 if [ $# -eq 2 ]; then
2178 body=${res:0:${#res}-3}
2181 targetJson="{\"config\":"$targetJson"}"
2182 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2183 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2185 if [ $res -ne 0 ]; then
2186 __log_test_fail_body
2195 ##########################################
2196 #### Reset types and instances ####
2197 ##########################################
2199 # Admin reset to remove all policies and services
2200 # All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2201 # NOTE - only works in kubernetes and the pod should not be running
2203 # (Function for test scripts)
2205 pms_kube_pvc_reset() {
2208 __kube_clean_pvc $POLICY_AGENT_APP_NAME nonrtric policymanagementservice-vardata-pvc /var/policy-management-service/database