Merge "Integrated PMS 2.0 to test env and test cases"
[nonrtric.git] / test / common / testcase_common.sh
index ed02c7b..ea940a1 100755 (executable)
@@ -61,7 +61,7 @@ fi
 echo -ne $EBOLD
 
 # default test environment variables
-TEST_ENV_VAR_FILE="../common/test_env.sh"
+TEST_ENV_VAR_FILE=""
 
 echo "Test case started as: ${BASH_SOURCE[$i+1]} "$@
 
@@ -215,7 +215,7 @@ while [ $paramerror -eq 0 ] && [ $foundparm -eq 0 ]; do
                        if [ -z "$1" ]; then
                                paramerror=1
                        else
-                               echo "Option set - Overriding test_env.sh with: "$1
+                               echo "Option set - Reading test env from: "$1
                                shift;
                                foundparm=0
                        fi
@@ -259,6 +259,9 @@ if [ -f "$TEST_ENV_VAR_FILE" ]; then
        . $TEST_ENV_VAR_FILE
 else
        echo -e $RED"Selected env var file does not exist: "$TEST_ENV_VAR_FILE$ERED
+       echo " Select one of following env var file matching the intended target of the test"
+       echo " Restart the test using the flag '--env-file <path-to-env-file>"
+       ls ../common/test_env* | indent1
        exit 1
 fi
 
@@ -266,9 +269,13 @@ fi
 G1_A1_VERSION=""
 G2_A1_VERSION=""
 G3_A1_VERSION=""
+G4_A1_VERSION=""
+G5_A1_VERSION=""
 G1_COUNT=0
 G2_COUNT=0
 G3_COUNT=0
+G4_COUNT=0
+G5_COUNT=0
 
 # Vars to switch between http and https. Extra curl flag needed for https
 export RIC_SIM_HTTPX="http"
@@ -321,7 +328,7 @@ __check_image_var() {
        tag="${!5}"
 
        if [ -z $image ]; then
-               echo -e $RED"\$"$4" not set in test_env"$ERED
+               echo -e $RED"\$"$4" not set in $TEST_ENV_VAR_FILE"$ERED
                ((IMAGE_ERR++))
                echo ""
                tmp=$tmp"<no-image>\t"
@@ -329,7 +336,7 @@ __check_image_var() {
                tmp=$tmp$image"\t"
        fi
        if [ -z $tag ]; then
-               echo -e $RED"\$"$5" not set in test_env"$ERED
+               echo -e $RED"\$"$5" not set in $TEST_ENV_VAR_FILE"$ERED
                ((IMAGE_ERR++))
                echo ""
                tmp=$tmp"<no-tag>\t"
@@ -464,13 +471,13 @@ if [ -z "$SIM_GROUP" ]; then
        SIM_GROUP=$PWD/../simulator-group
        if [ ! -d  $SIM_GROUP ]; then
                echo "Trying to set env var SIM_GROUP to dir 'simulator-group' in the nontrtric repo, but failed."
-               echo -e $RED"Please set the SIM_GROUP manually in the test_env.sh"$ERED
+               echo -e $RED"Please set the SIM_GROUP manually in the applicable $TEST_ENV_VAR_FILE"$ERED
                exit 1
        else
                echo " SIM_GROUP auto set to: " $SIM_GROUP
        fi
 elif [ $SIM_GROUP = *simulator_group ]; then
-       echo -e $RED"Env var SIM_GROUP does not seem to point to dir 'simulator-group' in the repo, check common/test_env.sh"$ERED
+       echo -e $RED"Env var SIM_GROUP does not seem to point to dir 'simulator-group' in the repo, check $TEST_ENV_VAR_FILE"$ERED
        exit 1
 else
        echo " SIM_GROUP env var already set to: " $SIM_GROUP
@@ -1454,9 +1461,9 @@ use_simulator_https() {
        echo ""
 }
 
-# Start one group (ricsim_g1, ricsim_g2 or ricsim_g3) with a number of RIC Simulators using a given A interface
+# Start one group (ricsim_g1, ricsim_g2 .. ricsim_g5) with a number of RIC Simulators using a given A interface
 # 'ricsim' may be set on command line to other prefix
-# args:  ricsim_g1|ricsim_g2|ricsim_g3 <count> <interface-id>
+# args:  ricsim_g1|ricsim_g2|ricsim_g3|ricsim_g4|ricsim_g5 <count> <interface-id>
 # (Function for test scripts)
 start_ric_simulators() {
 
@@ -1472,10 +1479,12 @@ start_ric_simulators() {
        RIC1=$RIC_SIM_PREFIX"_g1"
        RIC2=$RIC_SIM_PREFIX"_g2"
        RIC3=$RIC_SIM_PREFIX"_g3"
+       RIC4=$RIC_SIM_PREFIX"_g4"
+       RIC5=$RIC_SIM_PREFIX"_g5"
 
        if [ $# != 3 ]; then
                ((RES_CONF_FAIL++))
-       __print_err "need three args,  $RIC1|$RIC2|$RIC3 <count> <interface-id>" $@
+       __print_err "need three args,  $RIC1|$RIC2|$RIC3|$RIC4|$RIC5 <count> <interface-id>" $@
                exit 1
        fi
        echo " $2 simulators using basename: $1 on interface: $3"
@@ -1489,9 +1498,15 @@ start_ric_simulators() {
        elif [ $1 == "$RIC3" ]; then
                G3_COUNT=$2
                G3_A1_VERSION=$3
+       elif [ $1 == "$RIC4" ]; then
+               G4_COUNT=$2
+               G4_A1_VERSION=$3
+       elif [ $1 == "$RIC5" ]; then
+               G5_COUNT=$2
+               G5_A1_VERSION=$3
        else
                ((RES_CONF_FAIL++))
-       __print_err "need three args, $RIC1|$RIC2|$RIC3 <count> <interface-id>" $@
+       __print_err "need three args, $RIC1|$RIC2|$RIC3|$RIC4|$RIC5 <count> <interface-id>" $@
                exit 1
        fi
 
@@ -1501,8 +1516,10 @@ start_ric_simulators() {
        export G1_A1_VERSION
        export G2_A1_VERSION
        export G3_A1_VERSION
+       export G4_A1_VERSION
+       export G5_A1_VERSION
 
-       docker_args="--scale g1=$G1_COUNT --scale g2=$G2_COUNT --scale g3=$G3_COUNT"
+       docker_args="--scale g1=$G1_COUNT --scale g2=$G2_COUNT --scale g3=$G3_COUNT --scale g4=$G4_COUNT --scale g5=$G5_COUNT"
        app_data=""
        cntr=1
        while [ $cntr -le $2 ]; do
@@ -1765,7 +1782,11 @@ use_agent_dmaap_https() {
 # (Function for test scripts)
 set_agent_debug() {
        echo -e $BOLD"Setting agent debug"$EBOLD
-       curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT/actuator/loggers/org.oransc.policyagent -X POST  -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
+       actuator="/actuator/loggers/org.oransc.policyagent"
+       if [[ $POLICY_AGENT_IMAGE = *"onap"* ]]; then
+               actuator="/actuator/loggers/org.onap.ccsdk.oran.a1policymanagementservice"
+       fi
+       curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT$actuator -X POST  -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
        result=$(__do_curl "$curlString")
        if [ $? -ne 0 ]; then
                __print_err "could not set debug mode" $@
@@ -1781,7 +1802,11 @@ set_agent_debug() {
 # (Function for test scripts)
 set_agent_trace() {
        echo -e $BOLD"Setting agent trace"$EBOLD
-       curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT/actuator/loggers/org.oransc.policyagent -X POST  -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
+       actuator="/actuator/loggers/org.oransc.policyagent"
+       if [[ $POLICY_AGENT_IMAGE = *"onap"* ]]; then
+               actuator="/actuator/loggers/org.onap.ccsdk.oran.a1policymanagementservice"
+       fi
+       curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT$actuator -X POST  -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
        result=$(__do_curl "$curlString")
        if [ $? -ne 0 ]; then
                __print_err "could not set trace mode" $@
@@ -2031,6 +2056,11 @@ store_logs() {
                done
        fi
 
+       __check_included_image 'PRODSTUB'
+       if [ $? -eq 0 ]; then
+               docker logs $PROD_STUB_APP_NAME > $TESTLOGS/$ATC/$1_prodstub.log 2>&1
+       fi
+
        echo ""
 }