Test updates for ECS, PMS and SDNC
[nonrtric.git] / test / common / controller_api_functions.sh
index e33c619..d703d83 100644 (file)
 #  ============LICENSE_END=================================================
 #
 
-# This is a script that contains specific test functions for A1 Controller API
+# This is a script that contains container/service management functions and test functions for A1 Controller API
+
+################ Test engine functions ################
+
+# Create the image var used during the test
+# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
+# <image-tag-suffix> is present only for images with staging, snapshot,release tags
+__SDNC_imagesetup() {
+
+       sdnc_suffix_tag=$1
+
+       for oia_name in $ONAP_IMAGES_APP_NAMES; do
+               if [ "$oia_name" == "SDNC" ]; then
+                       sdnc_suffix_tag="REMOTE_RELEASE_ONAP"
+               fi
+       done
+       __check_and_create_image_var SDNC "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_IMAGE_BASE" "SDNC_A1_CONTROLLER_IMAGE_TAG" $sdnc_suffix_tag "$SDNC_DISPLAY_NAME"
+       __check_and_create_image_var SDNC "SDNC_DB_IMAGE" "SDNC_DB_IMAGE_BASE" "SDNC_DB_IMAGE_TAG" REMOTE_PROXY "SDNC DB"
+
+}
+
+# Pull image from remote repo or use locally built image
+# arg: <pull-policy-override> <pull-policy-original>
+# <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
+# <pull-policy-original> Shall be used for images that does not allow overriding
+# Both var may contain: 'remote', 'remote-remove' or 'local'
+__SDNC_imagepull() {
+       __check_and_pull_image $1 "$SDNC_DISPLAY_NAME" $SDNC_APP_NAME SDNC_A1_CONTROLLER_IMAGE
+       __check_and_pull_image $2 "SDNC DB" $SDNC_APP_NAME SDNC_DB_IMAGE
+}
+
+# Build image (only for simulator or interfaces stubs owned by the test environment)
+# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
+# <image-tag-suffix> is present only for images with staging, snapshot,release tags
+__SDNC_imagebuild() {
+       echo -e $RED" Image for app SDNC shall never be built"$ERED
+}
+
+# Generate a string for each included image using the app display name and a docker images format string
+# If a custom image repo is used then also the source image from the local repo is listed
+# arg: <docker-images-format-string> <file-to-append>
+__SDNC_image_data() {
+       echo -e "$SDNC_DISPLAY_NAME\t$(docker images --format $1 $SDNC_A1_CONTROLLER_IMAGE)" >>   $2
+       if [ ! -z "$SDNC_A1_CONTROLLER_IMAGE_SOURCE" ]; then
+               echo -e "-- source image --\t$(docker images --format $1 $SDNC_A1_CONTROLLER_IMAGE_SOURCE)" >>   $2
+       fi
+       echo -e "SDNC DB\t$(docker images --format $1 $SDNC_DB_IMAGE)" >>   $2
+       if [ ! -z "$SDNC_DB_IMAGE_SOURCE" ]; then
+               echo -e "-- source image --\t$(docker images --format $1 $SDNC_DB_IMAGE_SOURCE)" >>   $2
+       fi
+}
+
+# Scale kubernetes resources to zero
+# All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
+# This function is called for apps fully managed by the test script
+__SDNC_kube_scale_zero() {
+       __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest SDNC
+}
+
+# Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
+# This function is called for prestarted apps not managed by the test script.
+__SDNC_kube_scale_zero_and_wait() {
+       echo -e " SDNC replicas kept as is"
+}
+
+# Delete all kube resouces for the app
+# This function is called for apps managed by the test script.
+__SDNC_kube_delete_all() {
+       __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest SDNC
+}
+
+# Store docker logs
+# This function is called for apps managed by the test script.
+# args: <log-dir> <file-prexix>
+__SDNC_store_docker_logs() {
+       docker exec -t $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $1$2_SDNC_karaf.log 2>&1
+}
+
+#######################################################
+
+
+SDNC_HTTPX="http"
+SDNC_HOST_NAME=$LOCALHOST_NAME
+SDNC_PATH=$SDNC_HTTPX"://"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_PORT
+SDNC_API_PATH=$SDNC_HTTPX"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_PORT$SDNC_API_URL
+#Docker/Kube internal path
+if [ $RUNMODE == "KUBE" ]; then
+       SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_EXTERNAL_PORT
+    #presume correct
+       SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME"."$KUBE_NONRTRIC_NAMESPACE":"$SDNC_EXTERNAL_PORT
+       #test
+       #SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME"."$KUBE_NONRTRIC_NAMESPACE":"$SDNC_EXTERNAL_PORT
+else
+       SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_INTERNAL_PORT
+fi
+
+use_sdnc_http() {
+       echo -e $BOLD"SDNC NB protocol setting"$EBOLD
+       echo -e " Using $BOLD http $EBOLD towards SDNC"
+       SDNC_HTTPX="http"
+       SDNC_PATH=$SDNC_HTTPX"://"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_PORT
+       SDNC_API_PATH=$SDNC_HTTPX"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_PORT$SDNC_API_URL
+       if [ $RUNMODE == "KUBE" ]; then
+               #presume correct
+               SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME"."$KUBE_NONRTRIC_NAMESPACE":"$SDNC_EXTERNAL_PORT
+               #test
+               #SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_EXTERNAL_PORT
+       else
+               SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_INTERNAL_PORT
+       fi
+       echo ""
+}
+
+use_sdnc_https() {
+       echo -e $BOLD"SDNC NB protocol setting"$EBOLD
+       echo -e " Using $BOLD https $EBOLD towards SDNC"
+       SDNC_HTTPX="https"
+       SDNC_PATH=$SDNC_HTTPX"://"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_SECURE_PORT
+       SDNC_API_PATH=$SDNC_HTTPX"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_SECURE_PORT$SDNC_API_URL
+       if [ $RUNMODE == "KUBE" ]; then
+               #presume correct
+               SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME"."$KUBE_NONRTRIC_NAMESPACE":"$SDNC_EXTERNAL_SECURE_PORT
+               #test
+               #SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_EXTERNAL_SECURE_PORT
+       else
+               SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_INTERNAL_SECURE_PORT
+       fi
+       echo ""
+}
+
+##################
+### SDNC functions
+##################
+
+# Start the SDNC A1 Controller
+# args: -
+# (Function for test scripts)
+start_sdnc() {
+
+       echo -e $BOLD"Starting $SDNC_DISPLAY_NAME"$EBOLD
+
+       if [ $RUNMODE == "KUBE" ]; then
+
+               # Check if app shall be fully managed by the test script
+               __check_included_image "SDNC"
+               retcode_i=$?
+
+               # Check if app shall only be used by the testscipt
+               __check_prestarted_image "SDNC"
+               retcode_p=$?
+
+               if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
+                       echo -e $RED"The $SDNC_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
+                       echo -e $RED"The $SDNC_APP_NAME will not be started"$ERED
+                       exit
+               fi
+               if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
+                       echo -e $RED"The $SDNC_APP_NAME app is included both as managed and prestarted in this test script"$ERED
+                       echo -e $RED"The $SDNC_APP_NAME will not be started"$ERED
+                       exit
+               fi
+
+
+               if [ $retcode_p -eq 0 ]; then
+                       echo -e " Using existing $SDNC_APP_NAME deployment and service"
+                       echo " Setting SDNC replicas=1"
+                       __kube_scale deployment $SDNC_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
+               fi
+
+                               # Check if app shall be fully managed by the test script
+               if [ $retcode_i -eq 0 ]; then
+
+                       echo -e " Creating $SDNC_APP_NAME app and expose service"
+
+                       #Check if nonrtric namespace exists, if not create it
+                       __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
+
+                       export KUBE_NONRTRIC_NAMESPACE
+                       export SDNC_APP_NAME
+                       export SDNC_A1_CONTROLLER_IMAGE
+                       export SDNC_INTERNAL_PORT
+                       export SDNC_EXTERNAL_PORT
+                       export SDNC_INTERNAL_SECURE_PORT
+                       export SDNC_EXTERNAL_SECURE_PORT
+                       export SDNC_A1_TRUSTSTORE_PASSWORD
+                       export SDNC_DB_APP_NAME
+                       export SDNC_DB_IMAGE
+                       export SDNC_USER
+                       export SDNC_PWD
+
+                       # Create service
+                       input_yaml=$SIM_GROUP"/"$SDNC_COMPOSE_DIR"/"svc.yaml
+                       output_yaml=$PWD/tmp/sdnc_svc.yaml
+                       __kube_create_instance service $SDNC_APP_NAME $input_yaml $output_yaml
+
+                       # Create app
+                       input_yaml=$SIM_GROUP"/"$SDNC_COMPOSE_DIR"/"$SDNC_KUBE_APP_FILE
+                       output_yaml=$PWD/tmp/sdnc_app.yaml
+                       __kube_create_instance app $SDNC_APP_NAME $input_yaml $output_yaml
+
+               fi
+
+        echo " Retrieving host and ports for service..."
+               SDNC_HOST_NAME=$(__kube_get_service_host $SDNC_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
+               SDNC_EXTERNAL_PORT=$(__kube_get_service_port $SDNC_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
+               SDNC_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $SDNC_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
+
+               echo " Host IP, http port, https port: $SDNC_HOST_NAME $SDNC_EXTERNAL_PORT $SDNC_EXTERNAL_SECURE_PORT"
+
+        if [ $SDNC_HTTPX == "http" ]; then
+                       SDNC_PATH=$SDNC_HTTPX"://"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_PORT
+                       SDNC_API_PATH=$SDNC_HTTPX"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_PORT$SDNC_API_URL
+            #presume correct
+                       SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME"."$KUBE_NONRTRIC_NAMESPACE":"$SDNC_EXTERNAL_PORT
+                       #test
+                       #SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_EXTERNAL_PORT
+               else
+                       SDNC_PATH=$SDNC_HTTPX"://"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_SECURE_PORT
+                       SDNC_API_PATH=$SDNC_HTTPX"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_SECURE_PORT$SDNC_API_URL
+            #presume correct
+                       SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME"."$KUBE_NONRTRIC_NAMESPACE":"$SDNC_EXTERNAL_SECURE_PORT
+                       #test
+                       #SDNC_SERVICE_PATH=$SDNC_HTTPX"://"$SDNC_APP_NAME":"$SDNC_EXTERNAL_SECURE_PORT
+               fi
+
+               __check_service_start $SDNC_APP_NAME $SDNC_PATH$SDNC_ALIVE_URL
+       else
+
+               __check_included_image 'SDNC'
+               if [ $? -eq 1 ]; then
+                       echo -e $RED"The SDNC A1 Controller app is not included in this test script"$ERED
+                       echo -e $RED"The Policy Agent will not be started"$ERED
+                       exit
+               fi
+
+               export SDNC_DB_APP_NAME
+        export SDNC_APP_NAME
+        export SDNC_INTERNAL_PORT
+        export SDNC_EXTERNAL_PORT
+        export SDNC_INTERNAL_SECURE_PORT
+        export SDNC_EXTERNAL_SECURE_PORT
+        export SDNC_A1_TRUSTSTORE_PASSWORD
+        export DOCKER_SIM_NWNAME
+               export SDNC_DISPLAY_NAME
+               export SDNC_USER
+               export SDNC_PWD
+
+               __start_container $SDNC_COMPOSE_DIR $SDNC_COMPOSE_FILE NODOCKERARGS 1 $SDNC_APP_NAME
+
+               __check_service_start $SDNC_APP_NAME $SDNC_PATH$SDNC_ALIVE_URL
+       fi
+    echo ""
+    return 0
+}
+
+
+# Stop the sndc
+# args: -
+# args: -
+# (Function for test scripts)
+stop_sdnc() {
+       echo -e $BOLD"Stopping $SDNC_DISPLAY_NAME"$EBOLD
+
+       if [ $RUNMODE == "KUBE" ]; then
+               __log_conf_fail_not_supported " Cannot stop sndc in KUBE mode"
+               return 1
+       else
+               docker stop $SDNC_APP_NAME &> ./tmp/.dockererr
+               if [ $? -ne 0 ]; then
+                       __print_err "Could not stop $SDNC_APP_NAME" $@
+                       cat ./tmp/.dockererr
+                       ((RES_CONF_FAIL++))
+                       return 1
+               fi
+       fi
+       echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
+       echo ""
+       return 0
+}
+
+# Start a previously stopped sdnc
+# args: -
+# (Function for test scripts)
+start_stopped_sdnc() {
+       echo -e $BOLD"Starting (the previously stopped) $SDNC_DISPLAY_NAME"$EBOLD
+
+       if [ $RUNMODE == "KUBE" ]; then
+               __log_conf_fail_not_supported " Cannot restart sndc in KUBE mode"
+               return 1
+       else
+               docker start $SDNC_APP_NAME &> ./tmp/.dockererr
+               if [ $? -ne 0 ]; then
+                       __print_err "Could not start (the stopped) $SDNC_APP_NAME" $@
+                       cat ./tmp/.dockererr
+                       ((RES_CONF_FAIL++))
+                       return 1
+               fi
+       fi
+       __check_service_start $SDNC_APP_NAME $SDNC_PATH$SDNC_ALIVE_URL
+       if [ $? -ne 0 ]; then
+               return 1
+       fi
+       echo ""
+       return 0
+}
+
+# Check the agent logs for WARNINGs and ERRORs
+# args: -
+# (Function for test scripts)
+check_sdnc_logs() {
+       __check_container_logs "SDNC A1 Controller" $SDNC_APP_NAME $SDNC_KARAF_LOG WARN ERROR
+}
 
 # Generic function to query the RICs via the A1-controller API.
 # args: <operation> <url> [<body>]
@@ -41,9 +352,20 @@ __do_curl_to_controller() {
         body=$(echo "$3" | sed 's/"/\\"/g')
         json='{"input":{"near-rt-ric-url":"'$2'","body":"'"$body"'"}}'
     fi
-    echo "$json" > .sdnc.payload.json
-    echo "  FILE: $json"  >> $HTTPLOG
-    curlString="curl -skw %{http_code} -X POST $SDNC_HTTPX://$SDNC_USER:$SDNC_PWD@localhost:$SDNC_LOCAL_PORT$SDNC_API_URL$1 -H accept:application/json -H Content-Type:application/json --data-binary @.sdnc.payload.json"
+       payload="./tmp/.sdnc.payload.json"
+    echo "$json" > $payload
+    echo "  FILE ($payload) : $json"  >> $HTTPLOG
+       proxyflag=""
+       if [ $RUNMODE == "KUBE" ]; then
+               if [ ! -z "$KUBE_PROXY_PATH" ]; then
+                       if [ $KUBE_PROXY_HTTPX == "http" ]; then
+                               proxyflag=" --proxy $KUBE_PROXY_PATH"
+                       else
+                               proxyflag=" --proxy-insecure --proxy $KUBE_PROXY_PATH"
+                       fi
+               fi
+       fi
+    curlString="curl -skw %{http_code} $proxyflag -X POST $SDNC_API_PATH$1 -H accept:application/json -H Content-Type:application/json --data-binary @$payload"
     echo "  CMD: "$curlString >> $HTTPLOG
     res=$($curlString)
     retcode=$?
@@ -62,8 +384,9 @@ __do_curl_to_controller() {
     fi
     body=${res:0:${#res}-3}
        echo "  JSON: "$body >> $HTTPLOG
-    echo "$body" > .sdnc-reply.json
-    res=$(python3 ../common/extract_sdnc_reply.py .sdnc-reply.json)
+       reply="./tmp/.sdnc-reply.json"
+    echo "$body" > $reply
+    res=$(python3 ../common/extract_sdnc_reply.py $SDNC_RESPONSE_JSON_KEY $reply)
     echo "  EXTRACED BODY+CODE: "$res >> $HTTPLOG
     echo "$res"
     return 0
@@ -73,16 +396,18 @@ __do_curl_to_controller() {
 # arg: <response-code> (OSC <ric-id> <policy-type-id> [ <policy-id> [<policy-id>]* ]) | ( STD <ric-id> [ <policy-id> [<policy-id>]* ] )
 # (Function for test scripts)
 controller_api_get_A1_policy_ids() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+       __log_test_start $@
 
+       ric_id=$3
+       if [ $RUNMODE == "KUBE" ]; then
+               ric_id=$(get_kube_sim_host $3)
+       fi
     paramError=1
     if [ $# -gt 3 ] && [ $2 == "OSC" ]; then
-        url="http://$3:$RIC_SIM_INTERNAL_PORT/a1-p/policytypes/$4/policies"
+        url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4/policies"
                paramError=0
     elif [ $# -gt 2 ] && [ $2 == "STD" ]; then
-        url="http://$3:$RIC_SIM_INTERNAL_PORT/A1-P/v1/policies"
+        url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies"
         paramError=0
        fi
 
@@ -95,17 +420,13 @@ controller_api_get_A1_policy_ids() {
     retcode=$?
     status=${res:${#res}-3}
 
-    if [ $? -ne 0 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+    if [ $retcode -ne 0 ]; then
+               __log_test_fail_status_code $1 $retcode "(likely remote server error)"
                return 1
        fi
 
        if [ $status -ne $1 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+               __log_test_fail_status_code $1 $status
                return 1
        fi
     body=${res:0:${#res}-3}
@@ -128,14 +449,11 @@ controller_api_get_A1_policy_ids() {
        res=$(python3 ../common/compare_json.py "$targetJson" "$body")
 
        if [ $res -ne 0 ]; then
-               echo -e $RED" FAIL, returned body not correct"$ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+               __log_test_fail_body
                return 1
        fi
 
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
        return 0
 }
 
@@ -144,13 +462,15 @@ controller_api_get_A1_policy_ids() {
 # arg: <response-code> OSC <ric-id> <policy-type-id> [<policy-type-file>]
 # (Function for test scripts)
 controller_api_get_A1_policy_type() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+       __log_test_start $@
 
+       ric_id=$3
+       if [ $RUNMODE == "KUBE" ]; then
+               ric_id=$(get_kube_sim_host $3)
+       fi
     paramError=1
     if [ $# -gt 3 ] && [ $2 == "OSC" ]; then
-        url="http://$3:$RIC_SIM_INTERNAL_PORT/a1-p/policytypes/$4"
+        url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4"
                paramError=0
        fi
 
@@ -163,17 +483,13 @@ controller_api_get_A1_policy_type() {
     retcode=$?
     status=${res:${#res}-3}
 
-    if [ $? -ne 0 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+    if [ $retcode -ne 0 ]; then
+               __log_test_fail_status_code $1 $retcode "(likely remote server error)"
                return 1
        fi
 
        if [ $status -ne $1 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+               __log_test_fail_status_code $1 $status
                return 1
        fi
     body=${res:0:${#res}-3}
@@ -187,15 +503,12 @@ controller_api_get_A1_policy_type() {
                res=$(python3 ../common/compare_json.py "$targetJson" "$body")
 
                if [ $res -ne 0 ]; then
-                       echo -e $RED" FAIL, returned body not correct"$ERED
-                       ((RES_FAIL++))
-                       __check_stop_at_error
+                       __log_test_fail_body
                        return 1
                fi
        fi
 
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
        return 0
 }
 
@@ -203,16 +516,18 @@ controller_api_get_A1_policy_type() {
 # arg: <response-code> (STD <ric-id> <policy-id>) | (OSC <ric-id> <policy-type-id> <policy-id>)
 # (Function for test scripts)
 controller_api_delete_A1_policy() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+       __log_test_start $@
 
+       ric_id=$3
+       if [ $RUNMODE == "KUBE" ]; then
+               ric_id=$(get_kube_sim_host $3)
+       fi
     paramError=1
     if [ $# -eq 5 ] && [ $2 == "OSC" ]; then
-        url="http://$3:$RIC_SIM_INTERNAL_PORT/a1-p/policytypes/$4/policies/$UUID$5"
+        url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5"
                paramError=0
     elif [ $# -eq 4 ] && [ $2 == "STD" ]; then
-        url="http://$3:$RIC_SIM_INTERNAL_PORT/A1-P/v1/policies/$UUID$4"
+        url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4"
         paramError=0
        fi
 
@@ -225,22 +540,17 @@ controller_api_delete_A1_policy() {
     retcode=$?
     status=${res:${#res}-3}
 
-    if [ $? -ne 0 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+    if [ $retcode -ne 0 ]; then
+               __log_test_fail_status_code $1 $retcode "(likely remote server error)"
                return 1
        fi
 
        if [ $status -ne $1 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+               __log_test_fail_status_code $1 $status
                return 1
        fi
 
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
        return 0
 }
 
@@ -248,18 +558,20 @@ controller_api_delete_A1_policy() {
 # arg: <response-code> (STD <ric-id> <policy-id> <template-file> ) | (OSC <ric-id> <policy-type-id> <policy-id> <template-file>)
 # (Function for test scripts)
 controller_api_put_A1_policy() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+       __log_test_start $@
 
+       ric_id=$3
+       if [ $RUNMODE == "KUBE" ]; then
+               ric_id=$(get_kube_sim_host $3)
+       fi
     paramError=1
     if [ $# -eq 6 ] && [ $2 == "OSC" ]; then
-        url="http://$3:$RIC_SIM_INTERNAL_PORT/a1-p/policytypes/$4/policies/$UUID$5"
+        url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5"
         body=$(sed 's/XXX/'${5}'/g' $6)
 
                paramError=0
     elif [ $# -eq 5 ] && [ $2 == "STD" ]; then
-        url="http://$3:$RIC_SIM_INTERNAL_PORT/A1-P/v1/policies/$UUID$4"
+        url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4"
         body=$(sed 's/XXX/'${4}'/g' $5)
         paramError=0
        fi
@@ -273,22 +585,17 @@ controller_api_put_A1_policy() {
     retcode=$?
     status=${res:${#res}-3}
 
-    if [ $? -ne 0 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+    if [ $retcode -ne 0 ]; then
+               __log_test_fail_status_code $1 $retcode "(likely remote server error)"
                return 1
        fi
 
        if [ $status -ne $1 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+               __log_test_fail_status_code $1 $status
                return 1
        fi
 
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
        return 0
 }
 
@@ -297,14 +604,16 @@ controller_api_put_A1_policy() {
 # arg: <response-code> (STD <ric-id> <policy-id> <enforce-status> [<reason>]) | (OSC <ric-id> <policy-type-id> <policy-id> <instance-status> <has-been-deleted>)
 # (Function for test scripts)
 controller_api_get_A1_policy_status() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+       __log_test_start $@
 
+       ric_id=$3
+       if [ $RUNMODE == "KUBE" ]; then
+               ric_id=$(get_kube_sim_host $3)
+       fi
     targetJson=""
     paramError=1
     if [ $# -ge 5 ] && [ $2 == "OSC" ]; then
-        url="http://$3:$RIC_SIM_INTERNAL_PORT/a1-p/policytypes/$4/policies/$UUID$5/status"
+        url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5/status"
         if [ $# -gt 5 ]; then
             targetJson="{\"instance_status\":\"$6\""
             targetJson=$targetJson",\"has_been_deleted\":\"$7\""
@@ -312,7 +621,7 @@ controller_api_get_A1_policy_status() {
         fi
                paramError=0
     elif [ $# -ge 4 ] && [ $2 == "STD" ]; then
-        url="http://$3:$RIC_SIM_INTERNAL_PORT/A1-P/v1/policies/$UUID$4/status"
+        url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4/status"
         if [ $# -gt 4 ]; then
             targetJson="{\"enforceStatus\":\"$5\""
             if [ $# -eq 6 ]; then
@@ -332,17 +641,13 @@ controller_api_get_A1_policy_status() {
     retcode=$?
     status=${res:${#res}-3}
 
-    if [ $? -ne 0 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+    if [ $retcode -ne 0 ]; then
+               __log_test_fail_status_code $1 $retcode "(likely remote server error)"
                return 1
        fi
 
        if [ $status -ne $1 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+               __log_test_fail_status_code $1 $status
                return 1
        fi
 
@@ -353,14 +658,11 @@ controller_api_get_A1_policy_status() {
                res=$(python3 ../common/compare_json.py "$targetJson" "$body")
 
                if [ $res -ne 0 ]; then
-                       echo -e $RED" FAIL, returned body not correct"$ERED
-                       ((RES_FAIL++))
-                       __check_stop_at_error
+                       __log_test_fail_body
                        return 1
                fi
        fi
 
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
        return 0
 }
\ No newline at end of file