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 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
187 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
190 if [ $retcode_i -eq 0 ]; then
192 echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
194 #Check if nonrtric namespace exists, if not create it
195 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
197 #Export all vars needed for service and deployment
198 export POLICY_AGENT_APP_NAME
199 export KUBE_NONRTRIC_NAMESPACE
200 export POLICY_AGENT_IMAGE
201 export POLICY_AGENT_INTERNAL_PORT
202 export POLICY_AGENT_INTERNAL_SECURE_PORT
203 export POLICY_AGENT_EXTERNAL_PORT
204 export POLICY_AGENT_EXTERNAL_SECURE_PORT
205 export POLICY_AGENT_CONFIG_MOUNT_PATH
206 export POLICY_AGENT_DATA_MOUNT_PATH
207 export POLICY_AGENT_CONFIG_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-config"
208 export POLICY_AGENT_DATA_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-data"
209 export POLICY_AGENT_PKG_NAME
211 export POLICY_AGENT_DATA_PV_NAME=$POLICY_AGENT_APP_NAME"-pv"
212 export POLICY_AGENT_DATA_PVC_NAME=$POLICY_AGENT_APP_NAME"-pvc"
213 ##Create a unique path for the pv each time to prevent a previous volume to be reused
214 export POLICY_AGENT_PV_PATH="padata-"$(date +%s)
215 export POLICY_AGENT_CONTAINER_MNT_DIR
217 if [ $1 == "PROXY" ]; then
218 AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
219 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
220 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
221 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
223 echo " Configured with http proxy"
226 AGENT_HTTP_PROXY_CONFIG_PORT=0
227 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
228 echo " Configured without http proxy"
230 export AGENT_HTTP_PROXY_CONFIG_PORT
231 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME
234 # Create config map for config
235 configfile=$PWD/tmp/$POLICY_AGENT_CONFIG_FILE
237 output_yaml=$PWD/tmp/pa_cfc.yaml
238 __kube_create_configmap $POLICY_AGENT_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $configfile $output_yaml
240 # Create config map for data
241 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
242 if [ $# -lt 3 ]; then
243 #create empty dummy file
244 echo "{}" > $data_json
248 output_yaml=$PWD/tmp/pa_cfd.yaml
249 __kube_create_configmap $POLICY_AGENT_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
252 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pv.yaml
253 output_yaml=$PWD/tmp/pa_pv.yaml
254 __kube_create_instance pv $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
257 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pvc.yaml
258 output_yaml=$PWD/tmp/pa_pvc.yaml
259 __kube_create_instance pvc $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
262 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"svc.yaml
263 output_yaml=$PWD/tmp/pa_svc.yaml
264 __kube_create_instance service $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
267 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"app.yaml
268 output_yaml=$PWD/tmp/pa_app.yaml
269 __kube_create_instance app $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
273 # 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
274 if [ $retcode_i -eq 0 ]; then
275 __PA_WORKER_NODE=$(kubectl get pod -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
276 if [ -z "$__PA_WORKER_NODE" ]; then
277 echo -e $YELLOW" Cannot find worker node for pod for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
280 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
283 echo " Retrieving host and ports for service..."
284 PA_HOST_NAME=$(__kube_get_service_host $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
285 POLICY_AGENT_EXTERNAL_PORT=$(__kube_get_service_port $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
286 POLICY_AGENT_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
288 echo " Host IP, http port, https port: $PA_HOST_NAME $POLICY_AGENT_EXTERNAL_PORT $POLICY_AGENT_EXTERNAL_SECURE_PORT"
290 if [ $PA_HTTPX == "http" ]; then
291 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
293 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_SECURE_PORT
295 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
297 if [ $PA_ADAPTER_TYPE == "REST" ]; then
301 __check_included_image 'PA'
302 if [ $? -eq 1 ]; then
303 echo -e $RED"The Policy Agent app is not included in this test script"$ERED
304 echo -e $RED"The Policy Agent will not be started"$ERED
311 cd $POLICY_AGENT_HOST_MNT_DIR
314 if [ "$(ls -A $DIR)" ]; then
315 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
316 rm -rf db/* &> /dev/null
317 if [ $? -ne 0 ]; then
318 echo -e $RED" Cannot remove database files in: $PWD"$ERED
323 echo " No files in mounted dir or dir does not exists"
327 #Export all vars needed for docker-compose
328 export POLICY_AGENT_APP_NAME
329 export POLICY_AGENT_APP_NAME_ALIAS
330 export POLICY_AGENT_INTERNAL_PORT
331 export POLICY_AGENT_EXTERNAL_PORT
332 export POLICY_AGENT_INTERNAL_SECURE_PORT
333 export POLICY_AGENT_EXTERNAL_SECURE_PORT
335 export CONSUL_INTERNAL_PORT
336 export CONFIG_BINDING_SERVICE
337 export POLICY_AGENT_CONFIG_KEY
338 export DOCKER_SIM_NWNAME
339 export POLICY_AGENT_HOST_MNT_DIR
340 export POLICY_AGENT_CONFIG_MOUNT_PATH
341 export POLICY_AGENT_CONFIG_FILE
342 export POLICY_AGENT_PKG_NAME
343 export POLICY_AGENT_DISPLAY_NAME
344 export POLICY_AGENT_CONTAINER_MNT_DIR
346 if [ $1 == "PROXY" ]; then
347 AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
348 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
349 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
350 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
352 echo " Configured with http proxy"
355 AGENT_HTTP_PROXY_CONFIG_PORT=0
356 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
357 echo " Configured without http proxy"
359 export AGENT_HTTP_PROXY_CONFIG_PORT
360 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME
362 dest_file=$SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_HOST_MNT_DIR/application.yaml
364 envsubst < $2 > $dest_file
366 __start_container $POLICY_AGENT_COMPOSE_DIR "" NODOCKERARGS 1 $POLICY_AGENT_APP_NAME
368 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
374 # Stop the policy agent
377 # (Function for test scripts)
378 stop_policy_agent() {
379 echo -e $BOLD"Stopping $POLICY_AGENT_DISPLAY_NAME"$EBOLD
381 if [ $RUNMODE == "KUBE" ]; then
383 __check_prestarted_image "PA"
384 if [ $? -eq 0 ]; then
385 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
386 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
387 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
390 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
391 echo " Deleting the replica set - a new will be started when the app is started"
392 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
393 if [ $? -ne 0 ]; then
394 echo -e $RED" Could not delete replica set "$RED
399 docker stop $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
400 if [ $? -ne 0 ]; then
401 __print_err "Could not stop $POLICY_AGENT_APP_NAME" $@
407 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
412 # Start a previously stopped policy agent
414 # (Function for test scripts)
415 start_stopped_policy_agent() {
416 echo -e $BOLD"Starting (the previously stopped) $POLICY_AGENT_DISPLAY_NAME"$EBOLD
418 if [ $RUNMODE == "KUBE" ]; then
420 __check_prestarted_image "PA"
421 if [ $? -eq 0 ]; then
422 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
423 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
424 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
425 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
429 # Tie the PMS to the same worker node it was initially started on
430 # 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
431 if [ -z "$__PA_WORKER_NODE" ]; then
432 echo -e $RED" No initial worker node found for pod "$RED
436 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
437 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
438 tmp=$(kubectl patch deployment $POLICY_AGENT_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__PA_WORKER_NODE'"}}}}}')
439 if [ $? -ne 0 ]; then
440 echo -e $YELLOW" Cannot set nodeSelector to deployment for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
442 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
445 docker start $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
446 if [ $? -ne 0 ]; then
447 __print_err "Could not start (the stopped) $POLICY_AGENT_APP_NAME" $@
453 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
454 if [ $? -ne 0 ]; then
463 # Load the the appl config for the agent into a config map
464 agent_load_config() {
465 echo -e $BOLD"Agent - load config from "$EBOLD$1
466 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
468 output_yaml=$PWD/tmp/pa_cfd.yaml
469 __kube_create_configmap $POLICY_AGENT_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
474 # Turn on debug level tracing in the agent
476 # (Function for test scripts)
478 echo -e $BOLD"Setting agent debug logging"$EBOLD
479 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
480 result=$(__do_curl "$curlString")
481 if [ $? -ne 0 ]; then
482 __print_err "could not set debug mode" $@
490 # Turn on trace level tracing in the agent
492 # (Function for test scripts)
494 echo -e $BOLD"Setting agent trace logging"$EBOLD
495 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
496 result=$(__do_curl "$curlString")
497 if [ $? -ne 0 ]; then
498 __print_err "could not set trace mode" $@
506 # Perform curl retries when making direct call to the agent for the specified http response codes
507 # Speace separated list of http response codes
508 # args: [<response-code>]*
509 use_agent_retries() {
510 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
516 # Check the agent logs for WARNINGs and ERRORs
518 # (Function for test scripts)
519 check_policy_agent_logs() {
520 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
523 #########################################################
524 #### Test case functions A1 Policy management service
525 #########################################################
527 # This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
528 # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
529 # args: json:<url> <target-value> [<timeout-in-seconds]
530 # (Function for test scripts)
532 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
533 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
534 if [[ $1 == "json:"* ]]; then
535 if [ "$PMS_VERSION" == "V2" ]; then
536 __var_test "Policy Agent" $PA_PATH$PMS_API_PREFIX"/v2/" $1 "=" $2 $3
538 __var_test "Policy Agent" $PA_PATH"/" $1 "=" $2 $3
543 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
547 # API Test function: GET /policies and V2 GET /v2/policy-instances
548 # 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>]*]
549 # 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>]*]
550 # (Function for test scripts)
554 if [ "$PMS_VERSION" == "V2" ]; then
556 variableParams=$(($#-4))
557 if [ $# -lt 4 ]; then
559 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
561 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
565 if [ $paramError -ne 0 ]; then
566 __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>]*]" $@
571 variableParams=$(($#-4))
572 if [ $# -lt 4 ]; then
574 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
576 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
580 if [ $paramError -ne 0 ]; then
581 __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>]*]" $@
587 if [ "$PMS_VERSION" == "V2" ]; then
588 if [ $2 != "NORIC" ]; then
589 queryparams="?ric_id="$2
591 if [ $3 != "NOSERVICE" ]; then
592 if [ -z $queryparams ]; then
593 queryparams="?service_id="$3
595 queryparams=$queryparams"&service_id="$3
598 if [ $4 != "NOTYPE" ]; then
599 if [ -z $queryparams ]; then
600 queryparams="?policytype_id="$4
602 queryparams=$queryparams"&policytype_id="$4
606 query="/v2/policy-instances"$queryparams
607 res="$(__do_curl_to_api PA GET $query)"
608 status=${res:${#res}-3}
610 if [ $status -ne $1 ]; then
611 __log_test_fail_status_code $1 $status
615 if [ $# -gt 4 ]; then
616 body=${res:0:${#res}-3}
617 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
623 for ((i=0; i<$(($#-4)); i=i+7)); do
625 if [ "$targetJson" != "[" ]; then
626 targetJson=$targetJson","
628 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
629 if [ "${arr[$i+3]}" == "EMPTY" ]; then
630 targetJson=$targetJson"\"\","
632 targetJson=$targetJson"\"${arr[$i+3]}\","
634 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
636 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
638 targetJson=$targetJson"\"policy_data\":"$json"}"
642 targetJson=$targetJson"]"
643 targetJson="{\"policies\": $targetJson}"
644 echo "TARGET JSON: $targetJson" >> $HTTPLOG
645 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
647 if [ $res -ne 0 ]; then
653 if [ $2 != "NORIC" ]; then
654 queryparams="?ric="$2
656 if [ $3 != "NOSERVICE" ]; then
657 if [ -z $queryparams ]; then
658 queryparams="?service="$3
660 queryparams=$queryparams"&service="$3
663 if [ $4 != "NOTYPE" ]; then
664 if [ -z $queryparams ]; then
665 queryparams="?type="$4
667 queryparams=$queryparams"&type="$4
671 query="/policies"$queryparams
672 res="$(__do_curl_to_api PA GET $query)"
673 status=${res:${#res}-3}
675 if [ $status -ne $1 ]; then
676 __log_test_fail_status_code $1 $status
680 if [ $# -gt 4 ]; then
681 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
684 body=${res:0:${#res}-3}
688 for ((i=0; i<$(($#-4)); i=i+5)); do
690 if [ "$targetJson" != "[" ]; then
691 targetJson=$targetJson","
693 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
694 if [ "${arr[$i+3]}" == "EMPTY" ]; then
695 targetJson=$targetJson"\"\","
697 targetJson=$targetJson"\"${arr[$i+3]}\","
700 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
702 targetJson=$targetJson"\"json\":"$json"}"
706 targetJson=$targetJson"]"
707 echo "TARGET JSON: $targetJson" >> $HTTPLOG
708 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
710 if [ $res -ne 0 ]; then
723 # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
724 # args: <response-code> <policy-id> [<template-file>]
725 # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
727 # (Function for test scripts)
732 if [ "$PMS_VERSION" == "V2" ]; then
733 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
734 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
737 query="/v2/policies/$UUID$2"
739 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
740 __print_err "<response-code> <policy-id> [<template-file>] " $@
743 query="/policy?id=$UUID$2"
745 res="$(__do_curl_to_api PA GET $query)"
746 status=${res:${#res}-3}
748 if [ $status -ne $1 ]; then
749 __log_test_fail_status_code $1 $status
753 if [ "$PMS_VERSION" == "V2" ]; then
754 if [ $# -eq 8 ]; then
756 #Create a policy json to compare with
757 body=${res:0:${#res}-3}
759 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
760 if [ $7 != "NOTRANSIENT" ]; then
761 targetJson=$targetJson", \"transient\":$7"
763 if [ $6 != "NOTYPE" ]; then
764 targetJson=$targetJson", \"policytype_id\":\"$6\""
766 targetJson=$targetJson", \"policytype_id\":\"\""
768 if [ $8 != "NOURL" ]; then
769 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
772 data=$(sed 's/XXX/'${2}'/g' $3)
773 targetJson=$targetJson", \"policy_data\":$data"
774 targetJson="{$targetJson}"
776 echo "TARGET JSON: $targetJson" >> $HTTPLOG
777 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
778 if [ $res -ne 0 ]; then
784 if [ $# -eq 3 ]; then
785 #Create a policy json to compare with
786 body=${res:0:${#res}-3}
788 sed 's/XXX/'${2}'/g' $3 > $file
789 targetJson=$(< $file)
790 echo "TARGET JSON: $targetJson" >> $HTTPLOG
791 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
792 if [ $res -ne 0 ]; then
802 # API Test function: PUT /policy and V2 PUT /policies
803 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
804 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
805 # (Function for test scripts)
809 if [ "$PMS_VERSION" == "V2" ]; then
810 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
811 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
815 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
816 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
829 if [ "$PMS_VERSION" == "V2" ]; then
832 if [ $# -eq 9 ]; then
837 if [ $# -eq 8 ]; then
842 while [ $count -lt $max ]; do
843 if [ "$PMS_VERSION" == "V2" ]; then
847 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
848 if [ $trans != "NOTRANSIENT" ]; then
849 inputJson=$inputJson", \"transient\":$trans"
851 if [ $pt != "NOTYPE" ]; then
852 inputJson=$inputJson", \"policytype_id\":\"$pt\""
854 inputJson=$inputJson", \"policytype_id\":\"\""
856 if [ $noti != "NOURL" ]; then
857 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
860 data=$(sed 's/XXX/'${pid}'/g' $temp)
861 inputJson=$inputJson", \"policy_data\":$data"
862 inputJson="{$inputJson}"
863 echo $inputJson > $file
865 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
867 if [ $pt != "NOTYPE" ]; then
868 query=$query"&type=$pt"
871 if [ $trans != NOTRANSIENT ]; then
872 query=$query"&transient=$trans"
876 sed 's/XXX/'${pid}'/g' $temp > $file
878 res="$(__do_curl_to_api PA PUT $query $file)"
879 status=${res:${#res}-3}
880 echo -ne " Executing "$count"("$max")${SAMELINE}"
881 if [ $status -ne $1 ]; then
882 echo " Executed "$count"?("$max")"
883 __log_test_fail_status_code $1 $status
889 echo -ne " Executed "$count"("$max")${SAMELINE}"
897 # API Test function: PUT /policy and V2 PUT /policies, to run in batch
898 # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
899 # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
900 # (Function for test scripts)
902 api_put_policy_batch() {
905 if [ "$PMS_VERSION" == "V2" ]; then
906 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
907 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
911 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
912 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
924 if [ "$PMS_VERSION" == "V2" ]; then
927 if [ $# -eq 9 ]; then
932 if [ $# -eq 8 ]; then
938 while [ $count -lt $max ]; do
939 if [ "$PMS_VERSION" == "V2" ]; then
942 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
943 if [ $trans != "NOTRANSIENT" ]; then
944 inputJson=$inputJson", \"transient\":$trans"
946 if [ $pt != "NOTYPE" ]; then
947 inputJson=$inputJson", \"policytype_id\":\"$pt\""
949 inputJson=$inputJson", \"policytype_id\":\"\""
951 if [ $noti != "NOURL" ]; then
952 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
955 data=$(sed 's/XXX/'${pid}'/g' $temp)
956 inputJson=$inputJson", \"policy_data\":$data"
957 inputJson="{$inputJson}"
958 echo $inputJson > $file
960 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
962 if [ $pt != "NOTYPE" ]; then
963 query=$query"&type=$pt"
966 if [ $trans != NOTRANSIENT ]; then
967 query=$query"&transient=$trans"
970 sed 's/XXX/'${pid}'/g' $temp > $file
972 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
973 status=${res:${#res}-3}
974 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
976 if [ $status -ne 200 ]; then
977 echo " Requested(batch) "$count"?("$max")"
978 __log_test_fail_status_code 200 $status
981 cid=${res:0:${#res}-3}
985 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
992 res="$(__do_curl_to_api PA RESPONSE $cid)"
993 status=${res:${#res}-3}
994 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
996 if [ $status -ne $1 ]; then
997 echo " Accepted(batch) "$count"?("$max")"
998 __log_test_fail_status_code $1 $status
1003 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
1012 # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
1013 # 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>
1014 # 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>
1015 # (Function for test scripts)
1016 api_put_policy_parallel() {
1019 if [ "$PMS_VERSION" == "V2" ]; then
1020 if [ $# -ne 11 ]; then
1021 __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>" $@
1025 if [ $# -ne 10 ]; then
1026 __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>" $@
1030 resp_code=$1; shift;
1036 transient=$1; shift;
1037 if [ "$PMS_VERSION" == "V2" ]; then
1046 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1047 if [ $PA_ADAPTER_TYPE != "REST" ]; then
1048 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1049 echo " Info - will execute over agent REST"
1051 if [ "$PMS_VERSION" == "V2" ]; then
1052 if [ $serv == "NOSERVICE" ]; then
1055 query="$PMS_API_PREFIX/v2/policies"
1057 if [ $serv == "NOSERVICE" ]; then
1060 query="/policy?service=$serv"
1062 if [ $type != "NOTYPE" ]; then
1063 query=$query"&type=$type"
1066 if [ $transient != NOTRANSIENT ]; then
1067 query=$query"&transient=$transient"
1071 urlbase=${PA_ADAPTER}${query}
1074 if [ $RUNMODE == "KUBE" ]; then
1075 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1076 httpproxy=$KUBE_PROXY_PATH
1080 for ((i=1; i<=$pids; i++))
1083 if [ -z "$uuid" ]; then
1086 echo "" > "./tmp/.pid${i}.res.txt"
1087 if [ "$PMS_VERSION" == "V2" ]; then
1088 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1090 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
1093 done | xargs -n 1 -I{} -P $pids bash -c '{
1095 echo " Parallel process $arg started"
1096 tmp=$(< "./tmp/.pid${arg}.txt")
1097 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1100 for ((i=1; i<=$pids; i++))
1102 file="./tmp/.pid${i}.res.txt"
1104 if [ -z "$tmp" ]; then
1105 echo " Process $i : unknown result (result file empty"
1109 if [ $res == "0" ]; then
1110 echo " Process $i : OK - "${tmp:1}
1112 echo " Process $i : failed - "${tmp:1}
1117 if [ -z $msg ]; then
1118 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1122 __log_test_fail_general "One of more processes failed to execute"
1126 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
1127 # args: <response-code> <policy-id> [count]
1128 # (Function for test scripts)
1129 api_delete_policy() {
1132 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1133 __print_err "<response-code> <policy-id> [count]" $@
1140 if [ $# -eq 3 ]; then
1146 while [ $count -lt $max ]; do
1147 if [ "$PMS_VERSION" == "V2" ]; then
1148 query="/v2/policies/"$UUID$pid
1150 query="/policy?id="$UUID$pid
1152 res="$(__do_curl_to_api PA DELETE $query)"
1153 status=${res:${#res}-3}
1154 echo -ne " Executing "$count"("$max")${SAMELINE}"
1156 if [ $status -ne $1 ]; then
1157 echo " Executed "$count"?("$max")"
1158 __log_test_fail_status_code $1 $status
1163 echo -ne " Executed "$count"("$max")${SAMELINE}"
1171 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
1172 # args: <response-code> <policy-id> [count]
1173 # (Function for test scripts)
1174 api_delete_policy_batch() {
1177 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1178 __print_err "<response-code> <policy-id> [count]" $@
1185 if [ $# -eq 3 ]; then
1191 while [ $count -lt $max ]; do
1192 if [ "$PMS_VERSION" == "V2" ]; then
1193 query="/v2/policies/"$UUID$pid
1195 query="/policy?id="$UUID$pid
1197 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
1198 status=${res:${#res}-3}
1199 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1201 if [ $status -ne 200 ]; then
1202 echo " Requested(batch) "$count"?("$max")"
1203 __log_test_fail_status_code 200 $status
1206 cid=${res:0:${#res}-3}
1210 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1218 res="$(__do_curl_to_api PA RESPONSE $cid)"
1219 status=${res:${#res}-3}
1220 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1222 if [ $status -ne $1 ]; then
1223 echo " Deleted(batch) "$count"?("$max")"
1224 __log_test_fail_status_code $1 $status
1229 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1238 # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
1239 # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1240 # (Function for test scripts)
1241 api_delete_policy_parallel() {
1244 if [ $# -ne 5 ]; then
1245 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1248 resp_code=$1; shift;
1254 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
1255 if [ $PA_ADAPTER_TYPE != "REST" ]; then
1256 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1257 echo " Info - will execute over agent REST"
1260 if [ "$PMS_VERSION" == "V2" ]; then
1261 query="$PMS_API_PREFIX/v2/policies/"
1266 urlbase=${PA_ADAPTER}${query}
1269 if [ $RUNMODE == "KUBE" ]; then
1270 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1271 httpproxy=$KUBE_PROXY_PATH
1275 for ((i=1; i<=$pids; i++))
1278 if [ -z "$uuid" ]; then
1281 echo "" > "./tmp/.pid${i}.del.res.txt"
1282 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
1284 done | xargs -n 1 -I{} -P $pids bash -c '{
1286 echo " Parallel process $arg started"
1287 tmp=$(< "./tmp/.pid${arg}.del.txt")
1288 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
1291 for ((i=1; i<=$pids; i++))
1293 file="./tmp/.pid${i}.del.res.txt"
1295 if [ -z "$tmp" ]; then
1296 echo " Process $i : unknown result (result file empty"
1300 if [ $res == "0" ]; then
1301 echo " Process $i : OK - "${tmp:1}
1303 echo " Process $i : failed - "${tmp:1}
1308 if [ -z $msg ]; then
1309 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
1313 __log_test_fail_general "One of more processes failed to execute"
1317 # API Test function: GET /policy_ids and V2 GET /v2/policies
1318 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1319 # (Function for test scripts)
1320 api_get_policy_ids() {
1323 if [ $# -lt 4 ]; then
1324 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1330 if [ "$PMS_VERSION" == "V2" ]; then
1331 if [ $2 != "NORIC" ]; then
1332 queryparams="?ric_id="$2
1335 if [ $3 != "NOSERVICE" ]; then
1336 if [ -z $queryparams ]; then
1337 queryparams="?service_id="$3
1339 queryparams=$queryparams"&service_id="$3
1342 if [ $4 != "NOTYPE" ]; then
1343 if [ -z $queryparams ]; then
1344 queryparams="?policytype_id="$4
1346 queryparams=$queryparams"&policytype_id="$4
1350 query="/v2/policies"$queryparams
1352 if [ $2 != "NORIC" ]; then
1353 queryparams="?ric="$2
1356 if [ $3 != "NOSERVICE" ]; then
1357 if [ -z $queryparams ]; then
1358 queryparams="?service="$3
1360 queryparams=$queryparams"&service="$3
1363 if [ $4 != "NOTYPE" ]; then
1364 if [ -z $queryparams ]; then
1365 queryparams="?type="$4
1367 queryparams=$queryparams"&type="$4
1371 query="/policy_ids"$queryparams
1374 res="$(__do_curl_to_api PA GET $query)"
1375 status=${res:${#res}-3}
1377 if [ $status -ne $1 ]; then
1378 __log_test_fail_status_code $1 $status
1382 if [ $# -gt 4 ]; then
1383 body=${res:0:${#res}-3}
1386 for pid in ${@:5} ; do
1387 if [ "$targetJson" != "[" ]; then
1388 targetJson=$targetJson","
1390 if [ $pid != "NOID" ]; then
1391 targetJson=$targetJson"\"$UUID$pid\""
1395 targetJson=$targetJson"]"
1396 if [ "$PMS_VERSION" == "V2" ]; then
1397 targetJson="{\"policy_ids\": $targetJson}"
1399 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1400 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1402 if [ $res -ne 0 ]; then
1403 __log_test_fail_body
1412 # API Test function: V2 GET /v2/policy-types/{policyTypeId}
1413 # args(V2): <response-code> <policy-type-id> [<schema-file>]
1414 # (Function for test scripts)
1415 api_get_policy_type() {
1418 if [ "$PMS_VERSION" != "V2" ]; then
1419 __log_test_fail_not_supported
1423 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1424 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1427 query="/v2/policy-types/$2"
1429 res="$(__do_curl_to_api PA GET $query)"
1430 status=${res:${#res}-3}
1432 if [ $status -ne $1 ]; then
1433 __log_test_fail_status_code $1 $status
1437 if [ $# -eq 3 ]; then
1439 body=${res:0:${#res}-3}
1442 targetJson="{\"policy_schema\":$targetJson}"
1443 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1444 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1446 if [ $res -ne 0 ]; then
1447 __log_test_fail_body
1456 # API Test function: GET /policy_schema
1457 # args: <response-code> <policy-type-id> [<schema-file>]
1458 # (Function for test scripts)
1459 api_get_policy_schema() {
1462 if [ "$PMS_VERSION" == "V2" ]; then
1463 __log_test_fail_not_supported
1467 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1468 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1471 query="/policy_schema?id=$2"
1472 res="$(__do_curl_to_api PA GET $query)"
1473 status=${res:${#res}-3}
1475 if [ $status -ne $1 ]; then
1476 __log_test_fail_status_code $1 $status
1480 if [ $# -eq 3 ]; then
1482 body=${res:0:${#res}-3}
1486 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1487 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1489 if [ $res -ne 0 ]; then
1490 __log_test_fail_body
1499 # API Test function: GET /policy_schemas
1500 # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
1501 # args(V2): <response-code>
1502 # (Function for test scripts)
1503 api_get_policy_schemas() {
1506 if [ "$PMS_VERSION" == "V2" ]; then
1507 if [ $# -ne 1 ]; then
1508 __print_err "<response-code>" $@
1512 if [ $# -lt 2 ]; then
1513 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1517 if [ "$PMS_VERSION" == "V2" ]; then
1518 query="/v2/policy-schemas"
1520 query="/policy_schemas"
1521 if [ $2 != "NORIC" ]; then
1522 query=$query"?ric="$2
1526 res="$(__do_curl_to_api PA GET $query)"
1527 status=${res:${#res}-3}
1529 if [ $status -ne $1 ]; then
1530 __log_test_fail_status_code $1 $status
1534 if [ $# -gt 2 ]; then
1535 body=${res:0:${#res}-3}
1538 for file in ${@:3} ; do
1539 if [ "$targetJson" != "[" ]; then
1540 targetJson=$targetJson","
1542 if [ $file == "NOFILE" ]; then
1543 targetJson=$targetJson"{}"
1545 targetJson=$targetJson$(< $file)
1549 targetJson=$targetJson"]"
1550 if [ "$PMS_VERSION" == "V2" ]; then
1551 targetJson="{\"policy_schemas\": $targetJson }"
1553 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1554 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1556 if [ $res -ne 0 ]; then
1557 __log_test_fail_body
1566 # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
1567 # arg: <response-code> <policy-id> (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)
1568 # (Function for test scripts)
1569 api_get_policy_status() {
1572 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
1573 __print_err "<response-code> <policy-id> (STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)" $@
1579 if [ $3 == "STD" ]; then
1580 targetJson="{\"enforceStatus\":\"$4\""
1581 if [ $# -eq 5 ]; then
1582 targetJson=$targetJson",\"reason\":\"$5\""
1584 targetJson=$targetJson"}"
1585 elif [ $3 == "STD2" ]; then
1586 if [ $4 == "EMPTY" ]; then
1587 targetJson="{\"enforceStatus\":\"\""
1589 targetJson="{\"enforceStatus\":\"$4\""
1591 if [ $# -eq 5 ]; then
1592 if [ $5 == "EMPTY" ]; then
1593 targetJson=$targetJson",\"enforceReason\":\"\""
1595 targetJson=$targetJson",\"enforceReason\":\"$5\""
1598 targetJson=$targetJson"}"
1599 elif [ $3 == "OSC" ]; then
1600 targetJson="{\"instance_status\":\"$4\""
1601 if [ $# -eq 5 ]; then
1602 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1604 targetJson=$targetJson",\"created_at\":\"????\"}"
1606 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1610 if [ "$PMS_VERSION" == "V2" ]; then
1611 query="/v2/policies/$UUID$2/status"
1612 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1614 query="/policy_status?id="$UUID$2
1617 res="$(__do_curl_to_api PA GET $query)"
1618 status=${res:${#res}-3}
1620 if [ $status -ne $1 ]; then
1621 __log_test_fail_status_code $1 $status
1625 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1626 body=${res:0:${#res}-3}
1627 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1629 if [ $res -ne 0 ]; then
1630 __log_test_fail_body
1638 # API Test function: GET /policy_types and V2 GET /v2/policy-types
1639 # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1640 # (Function for test scripts)
1641 api_get_policy_types() {
1644 if [ $# -lt 1 ]; then
1645 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1649 if [ "$PMS_VERSION" == "V2" ]; then
1650 if [ $# -eq 1 ]; then
1651 query="/v2/policy-types"
1652 elif [ $2 == "NORIC" ]; then
1653 query="/v2/policy-types"
1655 query="/v2/policy-types?ric_id=$2"
1658 if [ $# -eq 1 ]; then
1659 query="/policy_types"
1660 elif [ $2 == "NORIC" ]; then
1661 query="/policy_types"
1663 query="/policy_types?ric=$2"
1667 res="$(__do_curl_to_api PA GET $query)"
1668 status=${res:${#res}-3}
1670 if [ $status -ne $1 ]; then
1671 __log_test_fail_status_code $1 $status
1675 if [ $# -gt 2 ]; then
1676 body=${res:0:${#res}-3}
1679 for pid in ${@:3} ; do
1680 if [ "$targetJson" != "[" ]; then
1681 targetJson=$targetJson","
1683 if [ $pid == "EMPTY" ]; then
1686 targetJson=$targetJson"\"$pid\""
1689 targetJson=$targetJson"]"
1690 if [ "$PMS_VERSION" == "V2" ]; then
1691 targetJson="{\"policytype_ids\": $targetJson }"
1693 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1694 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1696 if [ $res -ne 0 ]; then
1697 __log_test_fail_body
1706 #########################################################
1707 #### Test case functions Health check
1708 #########################################################
1710 # API Test function: GET /status and V2 GET /status
1711 # args: <response-code>
1712 # (Function for test scripts)
1715 if [ $# -ne 1 ]; then
1716 __print_err "<response-code>" $@
1719 if [ "$PMS_VERSION" == "V2" ]; then
1724 res="$(__do_curl_to_api PA GET $query)"
1725 status=${res:${#res}-3}
1727 if [ $status -ne $1 ]; then
1728 __log_test_fail_status_code $1 $status
1736 #########################################################
1737 #### Test case functions RIC Repository
1738 #########################################################
1740 # API Test function: GET /ric and V2 GET /v2/rics/ric
1741 # args: <reponse-code> <management-element-id> [<ric-id>]
1742 # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1743 # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1744 # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1747 # (Function for test scripts)
1751 if [ "$PMS_VERSION" == "V2" ]; then
1752 if [ $# -lt 3 ]; then
1753 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1757 if [ $2 != "NOME" ]; then
1758 search="?managed_element_id="$2
1760 if [ $3 != "NORIC" ]; then
1761 if [ -z $search ]; then
1764 search=$search"&ric_id="$3
1767 query="/v2/rics/ric"$search
1769 res="$(__do_curl_to_api PA GET $query)"
1770 status=${res:${#res}-3}
1772 if [ $status -ne $1 ]; then
1773 __log_test_fail_status_code $1 $status
1777 if [ $# -gt 3 ]; then
1778 body=${res:0:${#res}-3}
1779 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1780 if [ $res -ne 0 ]; then
1781 __log_test_fail_general "Could not create target ric info json"
1785 targetJson=$(<./tmp/.tmp_rics.json)
1786 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1787 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1788 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1789 if [ $res -ne 0 ]; then
1790 __log_test_fail_body
1795 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1796 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1800 query="/ric?managedElementId="$2
1802 res="$(__do_curl_to_api PA GET $query)"
1803 status=${res:${#res}-3}
1805 if [ $status -ne $1 ]; then
1806 __log_test_fail_status_code $1 $status
1810 if [ $# -eq 3 ]; then
1811 body=${res:0:${#res}-3}
1812 if [ "$body" != "$3" ]; then
1813 __log_test_fail_body
1822 # API test function: GET /rics and V2 GET /v2/rics
1823 # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1824 # 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_........."
1825 # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1826 # (Function for test scripts)
1830 if [ $# -lt 2 ]; then
1831 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1835 if [ "$PMS_VERSION" == "V2" ]; then
1837 if [ $2 != "NOTYPE" ]; then
1838 query="/v2/rics?policytype_id="$2
1842 if [ $2 != "NOTYPE" ]; then
1843 query="/rics?policyType="$2
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 if [ $# -gt 2 ]; then
1856 body=${res:0:${#res}-3}
1857 if [ "$PMS_VERSION" == "V2" ]; then
1858 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
1860 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
1862 if [ $res -ne 0 ]; then
1863 __log_test_fail_general "Could not create target ric info json"
1867 targetJson=$(<./tmp/.tmp_rics.json)
1868 if [ "$PMS_VERSION" == "V2" ]; then
1869 targetJson="{\"rics\": $targetJson }"
1871 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1872 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1873 if [ $res -ne 0 ]; then
1874 __log_test_fail_body
1883 ##################################################################
1884 #### API Test case functions Service registry and supervision ####
1885 ##################################################################
1887 # API test function: PUT /service and V2 PUT /service
1888 # args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1889 # (Function for test scripts)
1892 if [ $# -ne 4 ]; then
1893 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1897 if [ "$PMS_VERSION" == "V2" ]; then
1898 query="/v2/services"
1899 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
1902 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1904 file="./tmp/.tmp.json"
1905 echo "$json" > $file
1907 res="$(__do_curl_to_api PA PUT $query $file)"
1908 status=${res:${#res}-3}
1910 if [ $status -ne $1 ]; then
1911 __log_test_fail_status_code $1 $status
1919 # API test function: GET /services and V2 GET /v2/services
1920 #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>]* )]
1921 # (Function for test scripts)
1922 api_get_services() {
1924 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1926 if [ $# -eq 1 ]; then
1928 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1930 elif [ $# -eq 5 ]; then
1932 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1934 if [ $(($argLen%3)) -eq 0 ]; then
1939 if [ $paramError -ne 0 ]; then
1940 __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>]* )]" $@
1944 if [ "$PMS_VERSION" == "V2" ]; then
1945 query="/v2/services"
1947 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1948 query="/v2/services?service_id="$2
1953 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1954 query="/services?name="$2
1957 res="$(__do_curl_to_api PA GET $query)"
1958 status=${res:${#res}-3}
1960 if [ $status -ne $1 ]; then
1961 __log_test_fail_status_code $1 $status
1965 if [ $# -gt 2 ]; then
1966 variableArgCount=$(($#-2))
1967 body=${res:0:${#res}-3}
1971 while [ $cntr -lt $variableArgCount ]; do
1972 servicename=$1; shift;
1975 if [ $cntr -gt 0 ]; then
1976 targetJson=$targetJson","
1978 # timeSinceLastActivitySeconds value cannot be checked since value varies
1979 if [ "$PMS_VERSION" == "V2" ]; then
1980 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
1982 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1986 targetJson=$targetJson"]"
1987 if [ "$PMS_VERSION" == "V2" ]; then
1988 targetJson="{\"service_list\": $targetJson }"
1990 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1991 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1992 if [ $res -ne 0 ]; then
1993 __log_test_fail_body
2002 # API test function: GET /services V2 GET /v2/services - (only checking service names)
2003 # args: <response-code> [<service-name>]*"
2004 # (Function for test scripts)
2005 api_get_service_ids() {
2008 if [ $# -lt 1 ]; then
2009 __print_err "<response-code> [<service-name>]*" $@
2013 if [ "$PMS_VERSION" == "V2" ]; then
2014 query="/v2/services"
2018 res="$(__do_curl_to_api PA GET $query)"
2019 status=${res:${#res}-3}
2021 if [ $status -ne $1 ]; then
2022 __log_test_fail_status_code $1 $status
2026 body=${res:0:${#res}-3}
2028 for rapp in ${@:2} ; do
2029 if [ "$targetJson" != "[" ]; then
2030 targetJson=$targetJson","
2032 if [ "$PMS_VERSION" == "V2" ]; then
2033 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2035 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2039 targetJson=$targetJson"]"
2040 if [ "$PMS_VERSION" == "V2" ]; then
2041 targetJson="{\"service_list\": $targetJson }"
2043 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2044 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2046 if [ $res -ne 0 ]; then
2047 __log_test_fail_body
2055 # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
2056 # args: <response-code> <service-name>
2057 # (Function for test scripts)
2058 api_delete_services() {
2061 if [ $# -ne 2 ]; then
2062 __print_err "<response-code> <service-name>" $@
2065 if [ "$PMS_VERSION" == "V2" ]; then
2066 query="/v2/services/"$2
2068 query="/services?name="$2
2070 res="$(__do_curl_to_api PA DELETE $query)"
2071 status=${res:${#res}-3}
2073 if [ $status -ne $1 ]; then
2074 __log_test_fail_status_code $1 $status
2082 # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
2083 # args: <response-code> <service-name>
2084 # (Function for test scripts)
2085 api_put_services_keepalive() {
2088 if [ $# -ne 2 ]; then
2089 __print_err "<response-code> <service-name>" $@
2092 if [ "$PMS_VERSION" == "V2" ]; then
2093 query="/v2/services/$2/keepalive"
2095 query="/services/keepalive?name="$2
2098 res="$(__do_curl_to_api PA PUT $query)"
2099 status=${res:${#res}-3}
2101 if [ $status -ne $1 ]; then
2102 __log_test_fail_status_code $1 $status
2110 ##################################################################
2111 #### API Test case functions Configuration ####
2112 ##################################################################
2114 # API Test function: PUT /v2/configuration
2115 # args: <response-code> <config-file>
2116 # (Function for test scripts)
2117 api_put_configuration() {
2120 if [ "$PMS_VERSION" != "V2" ]; then
2121 __log_test_fail_not_supported
2125 if [ $# -ne 2 ]; then
2126 __print_err "<response-code> <config-file>" $@
2129 if [ ! -f $2 ]; then
2130 __log_test_fail_general "Config file "$2", does not exist"
2134 inputJson="{\"config\":"$inputJson"}"
2135 file="./tmp/.config.json"
2136 echo $inputJson > $file
2137 query="/v2/configuration"
2138 res="$(__do_curl_to_api PA PUT $query $file)"
2139 status=${res:${#res}-3}
2141 if [ $status -ne $1 ]; then
2142 __log_test_fail_status_code $1 $status
2150 # API Test function: GET /v2/configuration
2151 # args: <response-code> [<config-file>]
2152 # (Function for test scripts)
2153 api_get_configuration() {
2156 if [ "$PMS_VERSION" != "V2" ]; then
2157 __log_test_fail_not_supported
2161 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2162 __print_err "<response-code> [<config-file>]" $@
2165 if [ ! -f $2 ]; then
2166 __log_test_fail_general "Config file "$2" for comparison, does not exist"
2170 query="/v2/configuration"
2171 res="$(__do_curl_to_api PA GET $query)"
2172 status=${res:${#res}-3}
2174 if [ $status -ne $1 ]; then
2175 __log_test_fail_status_code $1 $status
2179 if [ $# -eq 2 ]; then
2181 body=${res:0:${#res}-3}
2184 targetJson="{\"config\":"$targetJson"}"
2185 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2186 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2188 if [ $res -ne 0 ]; then
2189 __log_test_fail_body
2198 ##########################################
2199 #### Reset types and instances ####
2200 ##########################################
2202 # Admin reset to remove all policies and services
2203 # All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2204 # NOTE - only works in kubernetes and the pod should not be running
2206 # (Function for test scripts)
2208 pms_kube_pvc_reset() {
2211 pvc_name=$(kubectl get pvc -n nonrtric --no-headers -o custom-columns=":metadata.name" | grep policy)
2212 if [ -z "$pvc_name" ]; then
2213 pvc_name=policymanagementservice-vardata-pvc
2215 echo " Trying to reset pvc: "$pvc_name
2216 __kube_clean_pvc $POLICY_AGENT_APP_NAME nonrtric $pvc_name /var/policy-management-service/database