From 7b36db6ef1b31daa41e115b7f199bb04f1cd0725 Mon Sep 17 00:00:00 2001 From: BjornMagnussonXA Date: Mon, 23 Nov 2020 10:57:57 +0100 Subject: [PATCH] Enhanced ECS function tests Documentation updates Also includes re-factoring of some scripts and functions Issue-ID: NONRTRIC-311 Signed-off-by: BjornMagnussonXA Change-Id: I891ab5b093699530c771b3d6177bfc24daae3b1d --- test/auto-test/FTC1.sh | 4 +- test/auto-test/FTC100.sh | 14 +- test/auto-test/FTC110.sh | 2 +- test/auto-test/FTC1100.sh | 579 ++++++++++++++++++++++++---- test/auto-test/FTC150.sh | 2 +- test/auto-test/FTC1800.sh | 384 ++++++++++++++++++ test/auto-test/FTC300.sh | 2 +- test/auto-test/FTC310.sh | 137 ++++--- test/auto-test/FTC350.sh | 2 +- test/auto-test/FTC800.sh | 2 +- test/auto-test/FTC810.sh | 2 +- test/auto-test/FTC850.sh | 4 +- test/auto-test/FTC900.sh | 2 +- test/auto-test/PM_DEMO.sh | 13 +- test/auto-test/PM_EI_DEMO.sh | 198 ++++++++++ test/auto-test/testdata/ecs/ei-type-3.json | 6 + test/auto-test/testdata/ecs/ei-type-4.json | 6 + test/auto-test/testdata/ecs/ei-type-5.json | 6 + test/auto-test/testdata/ecs/ei-type-6.json | 6 + test/common/README.md | 63 ++- test/common/agent_api_functions.sh | 447 ++++++++++----------- test/common/api_curl.sh | 3 +- test/common/controller_api_functions.sh | 97 ++--- test/common/cr_api_functions.sh | 72 +++- test/common/do_curl_function.sh | 2 + test/common/ecs_api_functions.sh | 389 ++++++++----------- test/common/prodstub_api_functions.sh | 103 +++-- test/common/ricsimulator_api_functions.sh | 66 +--- test/common/test_env-onap-guilin.sh | 9 +- test/common/test_env-onap-master.sh | 9 +- test/common/test_env-oran-master.sh | 12 +- test/common/testcase_common.sh | 182 +++++++-- test/cr/Dockerfile | 4 +- test/cr/README.md | 12 +- test/cr/app/cr.py | 18 +- test/cr/cr-build-start.sh | 4 +- test/mrstub/.gitignore | 1 + test/mrstub/Dockerfile | 4 +- test/mrstub/README.md | 10 +- test/mrstub/app/main.py | 9 + test/mrstub/mrstub-build-start.sh | 4 +- test/prodstub/Dockerfile | 4 +- test/prodstub/README.md | 131 ++++++- test/prodstub/app/prodstub.py | 117 +++--- test/prodstub/basic_test.sh | 20 +- test/prodstub/prod-stub-build-start.sh | 6 +- test/simulator-group/ecs/docker-compose.yml | 2 + test/simulator-group/ecs/mnt/.gitignore | 1 + test/simulator-group/sim-monitor.js | 341 +++++++++------- 49 files changed, 2405 insertions(+), 1108 deletions(-) create mode 100755 test/auto-test/FTC1800.sh create mode 100755 test/auto-test/PM_EI_DEMO.sh create mode 100644 test/auto-test/testdata/ecs/ei-type-3.json create mode 100644 test/auto-test/testdata/ecs/ei-type-4.json create mode 100644 test/auto-test/testdata/ecs/ei-type-5.json create mode 100644 test/auto-test/testdata/ecs/ei-type-6.json create mode 100644 test/simulator-group/ecs/mnt/.gitignore diff --git a/test/auto-test/FTC1.sh b/test/auto-test/FTC1.sh index 3b025106..1fd48e38 100755 --- a/test/auto-test/FTC1.sh +++ b/test/auto-test/FTC1.sh @@ -24,7 +24,7 @@ TC_ONELINE_DESCR="Sanity test, create service and then create,update and delete INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" #SUPPORTED TEST ENV FILE -SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN" +SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN ORAN-MASTER" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh @@ -125,7 +125,7 @@ for __httpx in $TESTED_PROTOCOLS ; do api_equal json:rics 3 60 - api_equal json:policy-types 2 120 + api_equal json:policy-types 3 120 api_equal json:policies 0 diff --git a/test/auto-test/FTC100.sh b/test/auto-test/FTC100.sh index e20adabe..e3570414 100755 --- a/test/auto-test/FTC100.sh +++ b/test/auto-test/FTC100.sh @@ -18,14 +18,14 @@ # -TC_ONELINE_DESCR="Full agent API walk through using agent REST/DMAAP and with/without SDNC A1 Controller" +TC_ONELINE_DESCR="Full agent API walkthrough using agent REST/DMAAP and with/without SDNC A1 Controller" #App names to include in the test, space separated list INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" #SUPPORTED TEST ENV FILE -SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN" +SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN ORAN-MASTER" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh @@ -55,9 +55,11 @@ for __httpx in $TESTED_PROTOCOLS ; do clean_containers if [ $__httpx == "HTTPS" ]; then + use_cr_https use_agent_rest_https else use_agent_rest_http + use_cr_http fi start_policy_agent @@ -70,7 +72,6 @@ for __httpx in $TESTED_PROTOCOLS ; do if [ $__httpx == "HTTPS" ]; then - use_cr_https use_simulator_https use_mr_https if [[ $interface = *"SDNC"* ]]; then @@ -82,7 +83,6 @@ for __httpx in $TESTED_PROTOCOLS ; do use_agent_rest_https fi else - use_cr_http use_simulator_http use_mr_http if [[ $interface = *"SDNC"* ]]; then @@ -392,7 +392,7 @@ for __httpx in $TESTED_PROTOCOLS ; do api_get_policy_status 200 5000 OSC "$VAL" "false" api_get_policy_status 200 5100 STD "UNDEFINED" if [ "$PMS_VERSION" == "V2" ]; then - api_get_policy_status 200 5200 STD "UNDEFINED" + api_get_policy_status 200 5200 STD2 EMPTY EMPTY fi @@ -467,9 +467,9 @@ for __httpx in $TESTED_PROTOCOLS ; do api_get_policy 200 5100 testdata/STD/pi1_template.json "service10" ricsim_g2_1 NOTYPE false $notificationurl - api_get_policy 200 5200 testdata/STD2/pi_qos2_template.json "service10" ricsim_g3_1 NOTYPE false $notificationurl + api_get_policy 200 5200 testdata/STD2/pi_qos2_template.json "service10" ricsim_g3_1 STD_QOS2_0.1.0 false $notificationurl - api_get_policies 200 ricsim_g1_1 "service10" 1 5000 ricsim_g1_1 "service10" STD_QOS2_0 true $notificationurl testdata/OSC/pi1_template.json + api_get_policies 200 ricsim_g1_1 "service10" 1 5000 ricsim_g1_1 "service10" 1 false $notificationurl testdata/OSC/pi1_template.json else api_get_policy 200 5000 testdata/OSC/pi1_template.json diff --git a/test/auto-test/FTC110.sh b/test/auto-test/FTC110.sh index bc566df8..6171ec38 100755 --- a/test/auto-test/FTC110.sh +++ b/test/auto-test/FTC110.sh @@ -24,7 +24,7 @@ TC_ONELINE_DESCR="Testing of service registration timeouts and keepalive" INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM" #SUPPORTED TEST ENV FILE -SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN" +SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN ORAN-MASTER" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh diff --git a/test/auto-test/FTC1100.sh b/test/auto-test/FTC1100.sh index 0a1a0144..266b3b50 100755 --- a/test/auto-test/FTC1100.sh +++ b/test/auto-test/FTC1100.sh @@ -18,14 +18,18 @@ # -TC_ONELINE_DESCR="Experimental ECS test case" +TC_ONELINE_DESCR="ECS full intefaces walkthrough" #App names to include in the test, space separated list -INCLUDED_IMAGES="ECS PRODSTUB" +INCLUDED_IMAGES="ECS PRODSTUB CR RICSIM CP" + +#SUPPORTED TEST ENV FILE +SUPPORTED_PROFILES="ONAP-MASTER ORAN-MASTER" . ../common/testcase_common.sh $@ . ../common/ecs_api_functions.sh . ../common/prodstub_api_functions.sh +. ../common/cr_api_functions.sh #### TEST BEGIN #### @@ -33,35 +37,77 @@ FLAT_A1_EI="1" clean_containers -use_ecs_rest_http +use_ecs_rest_https + +use_prod_stub_https -use_prod_stub_http +use_simulator_https + +use_cr_https start_ecs start_prod_stub -set_ecs_debug - set_ecs_trace -# Setup prodstub sim to accept calls for producers, types and jobs +start_control_panel + +if [ "$PMS_VERSION" == "V2" ]; then + start_ric_simulators ricsim_g3 4 STD_2.0.0 +fi + +start_cr + +CB_JOB="$PROD_STUB_HTTPX://$PROD_STUB_APP_NAME:$PROD_STUB_PORT/callbacks/job" +CB_SV="$PROD_STUB_HTTPX://$PROD_STUB_APP_NAME:$PROD_STUB_PORT/callbacks/supervision" +TARGET1="$RIC_SIM_HTTPX://ricsim_g3_1:$RIC_SIM_PORT/datadelivery" +TARGET2="$RIC_SIM_HTTPX://ricsim_g3_2:$RIC_SIM_PORT/datadelivery" +TARGET3="$RIC_SIM_HTTPX://ricsim_g3_3:$RIC_SIM_PORT/datadelivery" +TARGET8="$RIC_SIM_HTTPX://ricsim_g3_4:$RIC_SIM_PORT/datadelivery" +TARGET10="$RIC_SIM_HTTPX://ricsim_g3_4:$RIC_SIM_PORT/datadelivery" + +STATUS1="$CR_HTTPX://$CR_APP_NAME:$CR_PORT/callbacks/job1-status" +STATUS2="$CR_HTTPX://$CR_APP_NAME:$CR_PORT/callbacks/job2-status" +STATUS3="$CR_HTTPX://$CR_APP_NAME:$CR_PORT/callbacks/job3-status" +STATUS8="$CR_HTTPX://$CR_APP_NAME:$CR_PORT/callbacks/job8-status" +STATUS10="$CR_HTTPX://$CR_APP_NAME:$CR_PORT/callbacks/job10-status" + +### Setup prodstub sim to accept calls for producers, types and jobs +## prod-a type1 +## prod-b type1 and type2 +## prod-c no-type +## prod-d type4 +## prod-e type6 +## prod-f type6 + +## job1 -> prod-a +## job2 -> prod-a +## job3 -> prod-b +## job4 -> prod-a +## job6 -> prod-b +## job8 -> prod-d +## job10 -> prod-e and prod-f + prodstub_arm_producer 200 prod-a prodstub_arm_producer 200 prod-b prodstub_arm_producer 200 prod-c - prodstub_arm_producer 200 prod-d -prodstub_arm_type 200 prod-d type4 -prodstub_arm_job_create 200 prod-d job8 +prodstub_arm_producer 200 prod-e +prodstub_arm_producer 200 prod-f prodstub_arm_type 200 prod-a type1 prodstub_arm_type 200 prod-b type2 prodstub_arm_type 200 prod-b type3 +prodstub_arm_type 200 prod-d type4 +prodstub_arm_type 200 prod-e type6 +prodstub_arm_type 200 prod-f type6 prodstub_disarm_type 200 prod-b type3 prodstub_arm_type 200 prod-b type1 prodstub_disarm_type 200 prod-b type1 + prodstub_arm_job_create 200 prod-a job1 prodstub_arm_job_create 200 prod-a job2 prodstub_arm_job_create 200 prod-b job3 @@ -73,16 +119,21 @@ prodstub_arm_job_delete 200 prod-b job3 prodstub_arm_job_create 200 prod-b job4 prodstub_arm_job_create 200 prod-a job4 -prodstub_arm_job_create 200 prod-b job5 -prodstub_arm_job_create 200 prod-a job5 -prodstub_arm_job_delete 200 prod-a job5 - prodstub_arm_job_create 200 prod-b job6 -# ecs status +prodstub_arm_job_create 200 prod-d job8 + +prodstub_arm_job_create 200 prod-e job10 +prodstub_arm_job_create 200 prod-f job10 + +### ecs status ecs_api_service_status 200 -# Initial tests - no config made +cr_equal received_callbacks 0 + +### Initial tests - no config made +### GET: type ids, types, producer ids, producers, job ids, jobs +### DELETE: jobs ecs_api_a1_get_type_ids 200 EMPTY ecs_api_a1_get_type 404 test-type @@ -121,10 +172,12 @@ fi ecs_api_edp_get_producer_jobs 404 test-prod -# Setup of producer/job and test apis -#prod-a -ecs_api_edp_put_producer 201 prod-a http://producer-stub:8092/callbacks/create/prod-a http://producer-stub:8092/callbacks/delete/prod-a http://producer-stub:8092/callbacks/supervision/prod-a type1 testdata/ecs/ei-type-1.json -ecs_api_edp_put_producer 200 prod-a http://producer-stub:8092/callbacks/create/prod-a http://producer-stub:8092/callbacks/delete/prod-a http://producer-stub:8092/callbacks/supervision/prod-a type1 testdata/ecs/ei-type-1.json +### Setup of producer/job and testing apis ### + +## Setup prod-a +ecs_api_edp_put_producer 201 prod-a $CB_JOB/prod-a $CB_SV/prod-a type1 testdata/ecs/ei-type-1.json +ecs_api_edp_put_producer 200 prod-a $CB_JOB/prod-a $CB_SV/prod-a type1 testdata/ecs/ei-type-1.json + ecs_api_a1_get_type_ids 200 type1 if [ -z "$FLAT_A1_EI" ]; then @@ -137,7 +190,8 @@ ecs_api_edp_get_type_ids 200 type1 ecs_api_edp_get_type 200 type1 testdata/ecs/ei-type-1.json prod-a ecs_api_edp_get_producer_ids 200 prod-a -ecs_api_edp_get_producer 200 prod-a http://producer-stub:8092/callbacks/create/prod-a http://producer-stub:8092/callbacks/delete/prod-a http://producer-stub:8092/callbacks/supervision/prod-a type1 testdata/ecs/ei-type-1.json + +ecs_api_edp_get_producer 200 prod-a $CB_JOB/prod-a $CB_SV/prod-a type1 testdata/ecs/ei-type-1.json ecs_api_edp_get_producer_status 200 prod-a ENABLED @@ -156,66 +210,72 @@ fi ecs_api_edp_get_producer_jobs 200 prod-a EMPTY - -#job1 - prod-a +## Create a job for prod-a +## job1 - prod-a if [ -z "$FLAT_A1_EI" ]; then - ecs_api_a1_put_job 201 type1 job1 http://localhost:80/target1 ric1 testdata/ecs/job-template.json + ecs_api_a1_put_job 201 type1 job1 $TARGET1 ricsim_g3_1 testdata/ecs/job-template.json else - ecs_api_a1_put_job 201 job1 type1 http://localhost:80/target1 ric1 http://localhost:80/status1 testdata/ecs/job-template.json + ecs_api_a1_put_job 201 job1 type1 $TARGET1 ricsim_g3_1 $STATUS1 testdata/ecs/job-template.json fi -prodstub_check_jobdata 200 prod-a job1 type1 http://localhost:80/target1 testdata/ecs/job-template.json +# Check the job data in the producer +prodstub_check_jobdata 200 prod-a job1 type1 $TARGET1 testdata/ecs/job-template.json ecs_api_a1_get_job_ids 200 type1 NOWNER job1 -ecs_api_a1_get_job_ids 200 type1 ric1 job1 +ecs_api_a1_get_job_ids 200 type1 ricsim_g3_1 job1 + if [ ! -z "$FLAT_A1_EI" ]; then ecs_api_a1_get_job_ids 200 NOTYPE NOWNER job1 fi if [ -z "$FLAT_A1_EI" ]; then - ecs_api_a1_get_job 200 type1 job1 http://localhost:80/target1 ric1 testdata/ecs/job-template.json + ecs_api_a1_get_job 200 type1 job1 $TARGET1 ricsim_g3_1 testdata/ecs/job-template.json ecs_api_a1_get_job_status 200 type1 job1 ENABLED else - ecs_api_a1_get_job 200 job1 type1 http://localhost:80/target1 ric1 http://localhost:80/status1 testdata/ecs/job-template.json + ecs_api_a1_get_job 200 job1 type1 $TARGET1 ricsim_g3_1 $STATUS1 testdata/ecs/job-template.json ecs_api_a1_get_job_status 200 job1 ENABLED fi -ecs_api_edp_get_producer_jobs 200 prod-a job1 type1 http://localhost:80/target1 testdata/ecs/job-template.json +prodstub_equal create/prod-a/job1 1 +ecs_api_edp_get_producer_jobs 200 prod-a job1 type1 $TARGET1 testdata/ecs/job-template.json -#job2 - prod-a +## Create a second job for prod-a +## job2 - prod-a if [ -z "$FLAT_A1_EI" ]; then - ecs_api_a1_put_job 201 type1 job2 http://localhost:80/target2 ric2 testdata/ecs/job-template.json + ecs_api_a1_put_job 201 type1 job2 $TARGET2 ricsim_g3_2 testdata/ecs/job-template.json else - ecs_api_a1_put_job 201 job2 type1 http://localhost:80/target2 ric2 http://localhost:80/status2 testdata/ecs/job-template.json + ecs_api_a1_put_job 201 job2 type1 $TARGET2 ricsim_g3_2 $STATUS2 testdata/ecs/job-template.json fi -prodstub_check_jobdata 200 prod-a job2 type1 http://localhost:80/target2 testdata/ecs/job-template.json +# Check the job data in the producer +prodstub_check_jobdata 200 prod-a job2 type1 $TARGET2 testdata/ecs/job-template.json ecs_api_a1_get_job_ids 200 type1 NOWNER job1 job2 -ecs_api_a1_get_job_ids 200 type1 ric1 job1 -ecs_api_a1_get_job_ids 200 type1 ric2 job2 +ecs_api_a1_get_job_ids 200 type1 ricsim_g3_1 job1 +ecs_api_a1_get_job_ids 200 type1 ricsim_g3_2 job2 if [ ! -z "$FLAT_A1_EI" ]; then ecs_api_a1_get_job_ids 200 NOTYPE NOWNER job1 job2 fi if [ -z "$FLAT_A1_EI" ]; then - ecs_api_a1_get_job 200 type1 job2 http://localhost:80/target2 ric2 testdata/ecs/job-template.json + ecs_api_a1_get_job 200 type1 job2 $TARGET2 ricsim_g3_2 testdata/ecs/job-template.json ecs_api_a1_get_job_status 200 type1 job2 ENABLED else - ecs_api_a1_get_job 200 job2 type1 http://localhost:80/target2 ric2 http://localhost:80/status2 testdata/ecs/job-template.json + ecs_api_a1_get_job 200 job2 type1 $TARGET2 ricsim_g3_2 $STATUS2 testdata/ecs/job-template.json ecs_api_a1_get_job_status 200 job2 ENABLED fi -ecs_api_edp_get_producer_jobs 200 prod-a job1 type1 http://localhost:80/target1 testdata/ecs/job-template.json job2 type1 http://localhost:80/target2 testdata/ecs/job-template.json +prodstub_equal create/prod-a/job2 1 +ecs_api_edp_get_producer_jobs 200 prod-a job1 type1 $TARGET1 testdata/ecs/job-template.json job2 type1 $TARGET2 testdata/ecs/job-template.json -#prod-b -ecs_api_edp_put_producer 201 prod-b http://producer-stub:8092/callbacks/create/prod-b http://producer-stub:8092/callbacks/delete/prod-b http://producer-stub:8092/callbacks/supervision/prod-b type2 testdata/ecs/ei-type-2.json +## Setup prod-b +ecs_api_edp_put_producer 201 prod-b $CB_JOB/prod-b $CB_SV/prod-b type2 testdata/ecs/ei-type-2.json ecs_api_a1_get_type_ids 200 type1 type2 if [ -z "$FLAT_A1_EI" ]; then @@ -231,107 +291,477 @@ ecs_api_edp_get_type 200 type1 testdata/ecs/ei-type-1.json prod-a ecs_api_edp_get_type 200 type2 testdata/ecs/ei-type-2.json prod-b ecs_api_edp_get_producer_ids 200 prod-a prod-b -ecs_api_edp_get_producer 200 prod-a http://producer-stub:8092/callbacks/create/prod-a http://producer-stub:8092/callbacks/delete/prod-a http://producer-stub:8092/callbacks/supervision/prod-a type1 testdata/ecs/ei-type-1.json -ecs_api_edp_get_producer 200 prod-b http://producer-stub:8092/callbacks/create/prod-b http://producer-stub:8092/callbacks/delete/prod-b http://producer-stub:8092/callbacks/supervision/prod-b type2 testdata/ecs/ei-type-2.json -ecs_api_edp_get_producer_status 200 prod-b ENABLED +ecs_api_edp_get_producer 200 prod-a $CB_JOB/prod-a $CB_SV/prod-a type1 testdata/ecs/ei-type-1.json +ecs_api_edp_get_producer 200 prod-b $CB_JOB/prod-b $CB_SV/prod-b type2 testdata/ecs/ei-type-2.json -#job3 - prod-b +ecs_api_edp_get_producer_status 200 prod-b ENABLED + +## Create job for prod-b +## job3 - prod-b if [ -z "$FLAT_A1_EI" ]; then - ecs_api_a1_put_job 201 type2 job3 http://localhost:80/target3 ric3 testdata/ecs/job-template.json + ecs_api_a1_put_job 201 type2 job3 $TARGET3 ricsim_g3_3 testdata/ecs/job-template.json else - ecs_api_a1_put_job 201 job3 type2 http://localhost:80/target3 ric3 http://localhost:80/status3 testdata/ecs/job-template.json + ecs_api_a1_put_job 201 job3 type2 $TARGET3 ricsim_g3_3 $STATUS3 testdata/ecs/job-template.json fi -prodstub_check_jobdata 200 prod-b job3 type2 http://localhost:80/target3 testdata/ecs/job-template.json +prodstub_equal create/prod-b/job3 1 + +# Check the job data in the producer +prodstub_check_jobdata 200 prod-b job3 type2 $TARGET3 testdata/ecs/job-template.json ecs_api_a1_get_job_ids 200 type1 NOWNER job1 job2 ecs_api_a1_get_job_ids 200 type2 NOWNER job3 -ecs_api_a1_get_job_ids 200 type1 ric1 job1 -ecs_api_a1_get_job_ids 200 type1 ric2 job2 -ecs_api_a1_get_job_ids 200 type2 ric3 job3 +ecs_api_a1_get_job_ids 200 type1 ricsim_g3_1 job1 +ecs_api_a1_get_job_ids 200 type1 ricsim_g3_2 job2 +ecs_api_a1_get_job_ids 200 type2 ricsim_g3_3 job3 if [ -z "$FLAT_A1_EI" ]; then - ecs_api_a1_get_job 200 type2 job3 http://localhost:80/target3 ric3 testdata/ecs/job-template.json + ecs_api_a1_get_job 200 type2 job3 $TARGET3 ricsim_g3_3 testdata/ecs/job-template.json ecs_api_a1_get_job_status 200 type2 job3 ENABLED else - ecs_api_a1_get_job 200 job3 type2 http://localhost:80/target3 ric3 http://localhost:80/status3 testdata/ecs/job-template.json + ecs_api_a1_get_job 200 job3 type2 $TARGET3 ricsim_g3_3 $STATUS3 testdata/ecs/job-template.json ecs_api_a1_get_job_status 200 job3 ENABLED fi -ecs_api_edp_get_producer_jobs 200 prod-a job1 type1 http://localhost:80/target1 testdata/ecs/job-template.json job2 type1 http://localhost:80/target2 testdata/ecs/job-template.json -ecs_api_edp_get_producer_jobs 200 prod-b job3 type2 http://localhost:80/target3 testdata/ecs/job-template.json +ecs_api_edp_get_producer_jobs 200 prod-a job1 type1 $TARGET1 testdata/ecs/job-template.json job2 type1 $TARGET2 testdata/ecs/job-template.json +ecs_api_edp_get_producer_jobs 200 prod-b job3 type2 $TARGET3 testdata/ecs/job-template.json + +## Setup prod-c (no types) +ecs_api_edp_put_producer 201 prod-c $CB_JOB/prod-c $CB_SV/prod-c NOTYPE -#prod-c (no types) -ecs_api_edp_put_producer 201 prod-c http://producer-stub:8092/callbacks/create/prod-c http://producer-stub:8092/callbacks/delete/prod-c http://producer-stub:8092/callbacks/supervision/prod-c NOTYPE ecs_api_edp_get_producer_ids 200 prod-a prod-b prod-c -ecs_api_edp_get_producer 200 prod-a http://producer-stub:8092/callbacks/create/prod-a http://producer-stub:8092/callbacks/delete/prod-a http://producer-stub:8092/callbacks/supervision/prod-a type1 testdata/ecs/ei-type-1.json -ecs_api_edp_get_producer 200 prod-b http://producer-stub:8092/callbacks/create/prod-b http://producer-stub:8092/callbacks/delete/prod-b http://producer-stub:8092/callbacks/supervision/prod-b type2 testdata/ecs/ei-type-2.json -ecs_api_edp_get_producer 200 prod-c http://producer-stub:8092/callbacks/create/prod-c http://producer-stub:8092/callbacks/delete/prod-c http://producer-stub:8092/callbacks/supervision/prod-c EMPTY + +ecs_api_edp_get_producer 200 prod-a $CB_JOB/prod-a $CB_SV/prod-a type1 testdata/ecs/ei-type-1.json +ecs_api_edp_get_producer 200 prod-b $CB_JOB/prod-b $CB_SV/prod-b type2 testdata/ecs/ei-type-2.json +ecs_api_edp_get_producer 200 prod-c $CB_JOB/prod-c $CB_SV/prod-c EMPTY ecs_api_edp_get_producer_status 200 prod-c ENABLED + +## Delete job3 and prod-b and re-create if different order + +# Delete job then producer +ecs_api_a1_get_job_ids 200 NOTYPE NOWNER job1 job2 job3 +ecs_api_edp_get_producer_ids 200 prod-a prod-b prod-c + if [ -z "$FLAT_A1_EI" ]; then ecs_api_a1_delete_job 204 type2 job3 else ecs_api_a1_delete_job 204 job3 fi +ecs_api_a1_get_job_ids 200 NOTYPE NOWNER job1 job2 +ecs_api_edp_get_producer_ids 200 prod-a prod-b prod-c + ecs_api_edp_delete_producer 204 prod-b +ecs_api_edp_get_producer_status 404 prod-b -prodstub_equal create/prod-d/job8 0 -prodstub_equal delete/prod-d/job8 0 +ecs_api_a1_get_job_ids 200 NOTYPE NOWNER job1 job2 +ecs_api_edp_get_producer_ids 200 prod-a prod-c + +prodstub_equal delete/prod-b/job3 1 + +if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_put_job 404 type2 job3 $TARGET3 ricsim_g3_3 testdata/ecs/job-template.json +else + ecs_api_a1_put_job 404 job3 type2 $TARGET3 ricsim_g3_3 $STATUS3 testdata/ecs/job-template.json +fi + +# Put producer then job +ecs_api_edp_put_producer 201 prod-b $CB_JOB/prod-b $CB_SV/prod-b type2 testdata/ecs/ei-type-2.json + +ecs_api_edp_get_producer_status 200 prod-b ENABLED + +if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_put_job 201 type2 job3 $TARGET3 ricsim_g3_3 testdata/ecs/job-template2.json + ecs_api_a1_get_job_status 200 type2 job3 ENABLED +else + ecs_api_a1_put_job 201 job3 type2 $TARGET3 ricsim_g3_3 $STATUS3 testdata/ecs/job-template2.json + ecs_api_a1_get_job_status 200 job3 ENABLED +fi + +prodstub_check_jobdata 200 prod-b job3 type2 $TARGET3 testdata/ecs/job-template2.json + +ecs_api_a1_get_job_ids 200 NOTYPE NOWNER job1 job2 job3 +ecs_api_edp_get_producer_ids 200 prod-a prod-b prod-c + +prodstub_equal create/prod-b/job3 2 +prodstub_equal delete/prod-b/job3 1 + +# Delete only the producer +ecs_api_edp_delete_producer 204 prod-b + +ecs_api_edp_get_producer_status 404 prod-b + +ecs_api_a1_get_job_ids 200 NOTYPE NOWNER job1 job2 job3 +ecs_api_edp_get_producer_ids 200 prod-a prod-c + +if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type2 job3 DISABLED +else + ecs_api_a1_get_job_status 200 job3 DISABLED +fi + +cr_equal received_callbacks 1 30 +cr_equal received_callbacks?id=job3-status 1 +cr_api_check_all_ecs_events 200 job3-status DISABLED + +# Re-create the producer +ecs_api_edp_put_producer 201 prod-b $CB_JOB/prod-b $CB_SV/prod-b type2 testdata/ecs/ei-type-2.json + +ecs_api_edp_get_producer_status 200 prod-b ENABLED + +if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type2 job3 ENABLED +else + ecs_api_a1_get_job_status 200 job3 ENABLED +fi + +cr_equal received_callbacks 2 30 +cr_equal received_callbacks?id=job3-status 2 +cr_api_check_all_ecs_events 200 job3-status ENABLED -ecs_api_edp_put_producer 201 prod-d http://producer-stub:8092/callbacks/create/prod-d http://producer-stub:8092/callbacks/delete/prod-d http://producer-stub:8092/callbacks/supervision/prod-d type4 testdata/ecs/ei-type-1.json +prodstub_check_jobdata 200 prod-b job3 type2 $TARGET3 testdata/ecs/job-template2.json + + +## Setup prod-d +ecs_api_edp_put_producer 201 prod-d $CB_JOB/prod-d $CB_SV/prod-d type4 testdata/ecs/ei-type-1.json ecs_api_a1_get_job_ids 200 type4 NOWNER EMPTY if [ -z "$FLAT_A1_EI" ]; then - ecs_api_a1_put_job 201 type4 job8 http://localhost:80/target8 ric4 testdata/ecs/job-template.json + ecs_api_a1_put_job 201 type4 job8 $TARGET8 ricsim_g3_4 testdata/ecs/job-template.json else - ecs_api_a1_put_job 201 job8 type4 http://localhost:80/target8 ric4 http://localhost:80/status4 testdata/ecs/job-template.json + ecs_api_a1_put_job 201 job8 type4 $TARGET8 ricsim_g3_4 $STATUS8 testdata/ecs/job-template.json fi -read -p "" + +prodstub_check_jobdata 200 prod-d job8 type4 $TARGET8 testdata/ecs/job-template.json + prodstub_equal create/prod-d/job8 1 prodstub_equal delete/prod-d/job8 0 ecs_api_a1_get_job_ids 200 type4 NOWNER job8 -ecs_api_edp_put_producer 200 prod-d http://producer-stub:8092/callbacks/create/prod-d http://producer-stub:8092/callbacks/delete/prod-d http://producer-stub:8092/callbacks/supervision/prod-d NOTYPE +if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type4 job8 ENABLED +else + ecs_api_a1_get_job_status 200 job8 ENABLED +fi + +# Re-PUT the producer with zero types +ecs_api_edp_put_producer 200 prod-d $CB_JOB/prod-d $CB_SV/prod-d NOTYPE if [ -z "$FLAT_A1_EI" ]; then ecs_api_a1_get_job_ids 404 type4 NOWNER else - ecs_api_a1_get_job_ids 200 type4 NOWNER EMPTY - ecs_api_a1_get_job_ids 200 NOTYPE NOWNER job1 job2 job8 + ecs_api_a1_get_job_ids 200 type4 NOWNER job8 + ecs_api_a1_get_job_ids 200 NOTYPE NOWNER job1 job2 job3 job8 fi +if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type4 job8 DISABLED +else + ecs_api_a1_get_job_status 200 job8 DISABLED +fi + +cr_equal received_callbacks 3 30 +cr_equal received_callbacks?id=job8-status 1 +cr_api_check_all_ecs_events 200 job8-status DISABLED + prodstub_equal create/prod-d/job8 1 prodstub_equal delete/prod-d/job8 0 +## Re-setup prod-d +ecs_api_edp_put_producer 200 prod-d $CB_JOB/prod-d $CB_SV/prod-d type4 testdata/ecs/ei-type-1.json + +if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_ids 404 type4 NOWNER +else + ecs_api_a1_get_job_ids 200 type4 NOWNER job8 + ecs_api_a1_get_job_ids 200 NOTYPE NOWNER job1 job2 job3 job8 +fi +if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type4 job8 ENABLED +else + ecs_api_a1_get_job_status 200 job8 ENABLED +fi -ecs_api_edp_put_producer 200 prod-d http://producer-stub:8092/callbacks/create/prod-d http://producer-stub:8092/callbacks/delete/prod-d http://producer-stub:8092/callbacks/supervision/prod-d type4 testdata/ecs/ei-type-1.json +ecs_api_edp_get_producer_status 200 prod-a ENABLED +ecs_api_edp_get_producer_status 200 prod-b ENABLED +ecs_api_edp_get_producer_status 200 prod-c ENABLED +ecs_api_edp_get_producer_status 200 prod-d ENABLED + +cr_equal received_callbacks 4 30 +cr_equal received_callbacks?id=job8-status 2 +cr_api_check_all_ecs_events 200 job8-status ENABLED + +prodstub_equal create/prod-d/job8 2 +prodstub_equal delete/prod-d/job8 0 + + +## Setup prod-e +ecs_api_edp_put_producer 201 prod-e $CB_JOB/prod-e $CB_SV/prod-e type6 testdata/ecs/ei-type-6.json + +ecs_api_a1_get_job_ids 200 type6 NOWNER EMPTY if [ -z "$FLAT_A1_EI" ]; then - ecs_api_a1_get_job_ids 404 type4 NOWNER + ecs_api_a1_put_job 201 type6 job10 $TARGET10 ricsim_g3_4 testdata/ecs/job-template.json else - ecs_api_a1_get_job_ids 200 type4 NOWNER EMPTY - ecs_api_a1_get_job_ids 200 NOTYPE NOWNER job1 job2 job8 + ecs_api_a1_put_job 201 job10 type6 $TARGET10 ricsim_g3_4 $STATUS10 testdata/ecs/job-template.json fi +prodstub_check_jobdata 200 prod-e job10 type6 $TARGET10 testdata/ecs/job-template.json + +prodstub_equal create/prod-e/job10 1 +prodstub_equal delete/prod-e/job10 0 + +ecs_api_a1_get_job_ids 200 type6 NOWNER job10 + +if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type6 job10 ENABLED +else + ecs_api_a1_get_job_status 200 job10 ENABLED +fi +## Setup prod-f +ecs_api_edp_put_producer 201 prod-f $CB_JOB/prod-f $CB_SV/prod-f type6 testdata/ecs/ei-type-6.json +ecs_api_a1_get_job_ids 200 type6 NOWNER job10 +prodstub_check_jobdata 200 prod-f job10 type6 $TARGET10 testdata/ecs/job-template.json +prodstub_equal create/prod-f/job10 1 +prodstub_equal delete/prod-f/job10 0 -check_sdnc_logs +ecs_api_a1_get_job_ids 200 type6 NOWNER job10 + +if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type6 job10 ENABLED +else + ecs_api_a1_get_job_status 200 job10 ENABLED +fi + +## Status updates prod-a and jobs + +ecs_api_edp_get_producer_ids 200 prod-a prod-b prod-c prod-d prod-e prod-f + +ecs_api_edp_get_producer_status 200 prod-a ENABLED +ecs_api_edp_get_producer_status 200 prod-b ENABLED +ecs_api_edp_get_producer_status 200 prod-c ENABLED +ecs_api_edp_get_producer_status 200 prod-d ENABLED +ecs_api_edp_get_producer_status 200 prod-e ENABLED +ecs_api_edp_get_producer_status 200 prod-f ENABLED + +# Arm producer prod-a for supervision failure +prodstub_arm_producer 200 prod-a 400 + +# Wait for producer prod-a to go disabled +ecs_api_edp_get_producer_status 200 prod-a DISABLED 360 + +ecs_api_edp_get_producer_ids 200 prod-a prod-b prod-c prod-d prod-e prod-f + +ecs_api_edp_get_producer_status 200 prod-a DISABLED +ecs_api_edp_get_producer_status 200 prod-b ENABLED +ecs_api_edp_get_producer_status 200 prod-c ENABLED +ecs_api_edp_get_producer_status 200 prod-d ENABLED +ecs_api_edp_get_producer_status 200 prod-e ENABLED +ecs_api_edp_get_producer_status 200 prod-f ENABLED + + +if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type1 job1 ENABLED + ecs_api_a1_get_job_status 200 type1 job2 ENABLED + ecs_api_a1_get_job_status 200 type2 job3 ENABLED + ecs_api_a1_get_job_status 200 type4 job8 ENABLED + ecs_api_a1_get_job_status 200 type6 job10 ENABLED +else + ecs_api_a1_get_job_status 200 job1 ENABLED + ecs_api_a1_get_job_status 200 job2 ENABLED + ecs_api_a1_get_job_status 200 job3 ENABLED + ecs_api_a1_get_job_status 200 job8 ENABLED + ecs_api_a1_get_job_status 200 job10 ENABLED +fi + +# Arm producer prod-a for supervision +prodstub_arm_producer 200 prod-a 200 + +# Wait for producer prod-a to go enabled +ecs_api_edp_get_producer_status 200 prod-a ENABLED 360 + +ecs_api_edp_get_producer_ids 200 prod-a prod-b prod-c prod-d prod-e prod-f + +ecs_api_edp_get_producer_status 200 prod-a ENABLED +ecs_api_edp_get_producer_status 200 prod-b ENABLED +ecs_api_edp_get_producer_status 200 prod-c ENABLED +ecs_api_edp_get_producer_status 200 prod-d ENABLED +ecs_api_edp_get_producer_status 200 prod-e ENABLED +ecs_api_edp_get_producer_status 200 prod-f ENABLED + +if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type1 job1 ENABLED + ecs_api_a1_get_job_status 200 type1 job2 ENABLED + ecs_api_a1_get_job_status 200 type2 job3 ENABLED + ecs_api_a1_get_job_status 200 type4 job8 ENABLED + ecs_api_a1_get_job_status 200 type6 job10 ENABLED +else + ecs_api_a1_get_job_status 200 job1 ENABLED + ecs_api_a1_get_job_status 200 job2 ENABLED + ecs_api_a1_get_job_status 200 job3 ENABLED + ecs_api_a1_get_job_status 200 job8 ENABLED + ecs_api_a1_get_job_status 200 job10 ENABLED +fi + +# Arm producer prod-a for supervision failure +prodstub_arm_producer 200 prod-a 400 + +# Wait for producer prod-a to go disabled +ecs_api_edp_get_producer_status 200 prod-a DISABLED 360 + +ecs_api_edp_get_producer_ids 200 prod-a prod-b prod-c prod-d prod-e prod-f + +ecs_api_edp_get_producer_status 200 prod-a DISABLED +ecs_api_edp_get_producer_status 200 prod-b ENABLED +ecs_api_edp_get_producer_status 200 prod-c ENABLED +ecs_api_edp_get_producer_status 200 prod-d ENABLED +ecs_api_edp_get_producer_status 200 prod-e ENABLED +ecs_api_edp_get_producer_status 200 prod-f ENABLED + +if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type1 job1 ENABLED + ecs_api_a1_get_job_status 200 type1 job2 ENABLED + ecs_api_a1_get_job_status 200 type2 job3 ENABLED + ecs_api_a1_get_job_status 200 type4 job8 ENABLED + ecs_api_a1_get_job_status 200 type6 job10 ENABLED +else + ecs_api_a1_get_job_status 200 job1 ENABLED + ecs_api_a1_get_job_status 200 job2 ENABLED + ecs_api_a1_get_job_status 200 job3 ENABLED + ecs_api_a1_get_job_status 200 job8 ENABLED + ecs_api_a1_get_job_status 200 job10 ENABLED +fi + +# Wait for producer prod-a to be removed +ecs_equal json:ei-producer/v1/eiproducers 5 1000 + +ecs_api_edp_get_producer_ids 200 prod-b prod-c prod-d prod-e prod-f + +ecs_api_edp_get_producer_status 404 prod-a +ecs_api_edp_get_producer_status 200 prod-b ENABLED +ecs_api_edp_get_producer_status 200 prod-c ENABLED +ecs_api_edp_get_producer_status 200 prod-d ENABLED +ecs_api_edp_get_producer_status 200 prod-e ENABLED +ecs_api_edp_get_producer_status 200 prod-f ENABLED + +if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type1 job1 DISABLED + ecs_api_a1_get_job_status 200 type1 job2 DISABLED + ecs_api_a1_get_job_status 200 type2 job3 ENABLED + ecs_api_a1_get_job_status 200 type4 job8 ENABLED + ecs_api_a1_get_job_status 200 type6 job10 ENABLED +else + ecs_api_a1_get_job_status 200 job1 DISABLED + ecs_api_a1_get_job_status 200 job2 DISABLED + ecs_api_a1_get_job_status 200 job3 ENABLED + ecs_api_a1_get_job_status 200 job8 ENABLED + ecs_api_a1_get_job_status 200 job10 ENABLED +fi + +cr_equal received_callbacks 6 30 +cr_equal received_callbacks?id=job1-status 1 +cr_equal received_callbacks?id=job2-status 1 + +cr_api_check_all_ecs_events 200 job1-status DISABLED +cr_api_check_all_ecs_events 200 job2-status DISABLED + + +# Arm producer prod-e for supervision failure +prodstub_arm_producer 200 prod-e 400 + +ecs_api_edp_get_producer_status 200 prod-e DISABLED 1000 + +ecs_api_edp_get_producer_ids 200 prod-b prod-c prod-d prod-e prod-f + +ecs_api_edp_get_producer_status 404 prod-a +ecs_api_edp_get_producer_status 200 prod-b ENABLED +ecs_api_edp_get_producer_status 200 prod-c ENABLED +ecs_api_edp_get_producer_status 200 prod-d ENABLED +ecs_api_edp_get_producer_status 200 prod-e DISABLED +ecs_api_edp_get_producer_status 200 prod-f ENABLED + +if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type1 job1 DISABLED + ecs_api_a1_get_job_status 200 type1 job2 DISABLED + ecs_api_a1_get_job_status 200 type2 job3 ENABLED + ecs_api_a1_get_job_status 200 type4 job8 ENABLED + ecs_api_a1_get_job_status 200 type6 job10 ENABLED +else + ecs_api_a1_get_job_status 200 job1 DISABLED + ecs_api_a1_get_job_status 200 job2 DISABLED + ecs_api_a1_get_job_status 200 job3 ENABLED + ecs_api_a1_get_job_status 200 job8 ENABLED + ecs_api_a1_get_job_status 200 job10 ENABLED +fi + +#Disable create for job10 in prod-e +prodstub_arm_job_create 200 prod-e job10 400 + +#Update tjob 10 - only prod-f will be updated +if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_put_job 200 type6 job10 $TARGET10 ricsim_g3_4 testdata/ecs/job-template2.json +else + ecs_api_a1_put_job 200 job10 type6 $TARGET10 ricsim_g3_4 $STATUS10 testdata/ecs/job-template2.json +fi +#Reset producer and job responses +prodstub_arm_producer 200 prod-e 200 +prodstub_arm_job_create 200 prod-e job10 200 + +ecs_api_edp_get_producer_status 200 prod-e ENABLED 360 + +ecs_api_edp_get_producer_ids 200 prod-b prod-c prod-d prod-e prod-f + +#Job 10 should be updated when the producer goes enabled +deviation "Job 10 should be updated when the producer prod-e goes enabled" +prodstub_check_jobdata 200 prod-e job10 type6 $TARGET10 testdata/ecs/job-template2.json +prodstub_check_jobdata 200 prod-f job10 type6 $TARGET10 testdata/ecs/job-template2.json + +prodstub_arm_producer 200 prod-f 400 + +ecs_api_edp_get_producer_status 200 prod-f DISABLED 360 + +ecs_equal json:ei-producer/v1/eiproducers 4 1000 + +ecs_api_edp_get_producer_ids 200 prod-b prod-c prod-d prod-e + +ecs_api_edp_get_producer_status 404 prod-a +ecs_api_edp_get_producer_status 200 prod-b ENABLED +ecs_api_edp_get_producer_status 200 prod-c ENABLED +ecs_api_edp_get_producer_status 200 prod-d ENABLED +ecs_api_edp_get_producer_status 200 prod-e ENABLED +ecs_api_edp_get_producer_status 404 prod-f + +if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type1 job1 DISABLED + ecs_api_a1_get_job_status 200 type1 job2 DISABLED + ecs_api_a1_get_job_status 200 type2 job3 ENABLED + ecs_api_a1_get_job_status 200 type4 job8 ENABLED + ecs_api_a1_get_job_status 200 type6 job10 ENABLED +else + ecs_api_a1_get_job_status 200 job1 DISABLED + ecs_api_a1_get_job_status 200 job2 DISABLED + ecs_api_a1_get_job_status 200 job3 ENABLED + ecs_api_a1_get_job_status 200 job8 ENABLED + ecs_api_a1_get_job_status 200 job10 ENABLED +fi + +cr_equal received_callbacks 6 check_ecs_logs @@ -339,7 +769,6 @@ store_logs END #### TEST COMPLETE #### - print_result auto_clean_containers diff --git a/test/auto-test/FTC150.sh b/test/auto-test/FTC150.sh index bd33bee4..60108ba9 100755 --- a/test/auto-test/FTC150.sh +++ b/test/auto-test/FTC150.sh @@ -24,7 +24,7 @@ TC_ONELINE_DESCR="Sample tests of the SDNC A1 controller restconf API using http INCLUDED_IMAGES="RICSIM SDNC" #SUPPORTED TEST ENV FILE -SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN" +SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN ORAN-MASTER" . ../common/testcase_common.sh $@ . ../common/controller_api_functions.sh diff --git a/test/auto-test/FTC1800.sh b/test/auto-test/FTC1800.sh new file mode 100755 index 00000000..d8ecc85e --- /dev/null +++ b/test/auto-test/FTC1800.sh @@ -0,0 +1,384 @@ +#!/bin/bash + +# ============LICENSE_START=============================================== +# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + + +TC_ONELINE_DESCR="ECS Create 10000 jobs and restart, test job persisency" + +#App names to include in the test, space separated list +INCLUDED_IMAGES="ECS PRODSTUB CR CP" + +#SUPPORTED TEST ENV FILE +SUPPORTED_PROFILES="ONAP-MASTER ORAN-MASTER" + +. ../common/testcase_common.sh $@ +. ../common/ecs_api_functions.sh +. ../common/prodstub_api_functions.sh + +#### TEST BEGIN #### + +FLAT_A1_EI="1" + +clean_containers + +use_ecs_rest_http + +use_prod_stub_http + +start_ecs + +start_prod_stub + +set_ecs_trace + +start_control_panel + +start_cr + +CB_JOB="http://$PROD_STUB_APP_NAME:$PROD_STUB_PORT/callbacks/job" +CB_SV="http://$PROD_STUB_APP_NAME:$PROD_STUB_PORT/callbacks/supervision" +TARGET="http://localhost:80/target" # Dummy target + +NUM_JOBS=10000 + +# Setup prodstub sim to accept calls for producers, types and jobs +prodstub_arm_producer 200 prod-a +prodstub_arm_producer 200 prod-b +prodstub_arm_producer 200 prod-c +prodstub_arm_producer 200 prod-d + +prodstub_arm_type 200 prod-a type1 + +prodstub_arm_type 200 prod-b type1 +prodstub_arm_type 200 prod-b type2 + +prodstub_arm_type 200 prod-c type1 +prodstub_arm_type 200 prod-c type2 +prodstub_arm_type 200 prod-c type3 + +prodstub_arm_type 200 prod-d type4 +prodstub_arm_type 200 prod-d type5 + +for ((i=1; i<=$NUM_JOBS; i++)) +do + if [ $(($i%5)) -eq 0 ]; then + prodstub_arm_job_create 200 prod-a job$i + prodstub_arm_job_create 200 prod-b job$i + prodstub_arm_job_create 200 prod-c job$i + fi + if [ $(($i%5)) -eq 1 ]; then + prodstub_arm_job_create 200 prod-b job$i + prodstub_arm_job_create 200 prod-c job$i + fi + if [ $(($i%5)) -eq 2 ]; then + prodstub_arm_job_create 200 prod-c job$i + fi + if [ $(($i%5)) -eq 3 ]; then + prodstub_arm_job_create 200 prod-d job$i + fi + if [ $(($i%5)) -eq 4 ]; then + prodstub_arm_job_create 200 prod-d job$i + fi +done + +ecs_api_edp_put_producer 201 prod-a $CB_JOB/prod-a $CB_SV/prod-a type1 testdata/ecs/ei-type-1.json + +ecs_api_edp_put_producer 201 prod-b $CB_JOB/prod-b $CB_SV/prod-b type1 testdata/ecs/ei-type-1.json type2 testdata/ecs/ei-type-2.json + +ecs_api_edp_put_producer 201 prod-c $CB_JOB/prod-c $CB_SV/prod-c type1 testdata/ecs/ei-type-1.json type2 testdata/ecs/ei-type-2.json type3 testdata/ecs/ei-type-3.json + +ecs_api_edp_put_producer 201 prod-d $CB_JOB/prod-d $CB_SV/prod-d type4 testdata/ecs/ei-type-4.json type5 testdata/ecs/ei-type-5.json + +ecs_equal json:ei-producer/v1/eiproducers 4 + +ecs_api_edp_get_producer_status 200 prod-a ENABLED +ecs_api_edp_get_producer_status 200 prod-b ENABLED +ecs_api_edp_get_producer_status 200 prod-c ENABLED +ecs_api_edp_get_producer_status 200 prod-d ENABLED + +for ((i=1; i<=$NUM_JOBS; i++)) +do + if [ $(($i%5)) -eq 0 ]; then + ecs_api_a1_put_job 201 job$i type1 $TARGET ric1 $CR_PATH/job_status_ric1 testdata/ecs/job-template.json + if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type1 job$i ENABLED + else + ecs_api_a1_get_job_status 200 job$i ENABLED + fi + fi + if [ $(($i%5)) -eq 1 ]; then + ecs_api_a1_put_job 201 job$i type2 $TARGET ric1 $CR_PATH/job_status_ric1 testdata/ecs/job-template.json + if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type2 job$i ENABLED + else + ecs_api_a1_get_job_status 200 job$i ENABLED + fi + fi + if [ $(($i%5)) -eq 2 ]; then + ecs_api_a1_put_job 201 job$i type3 $TARGET ric1 $CR_PATH/job_status_ric1 testdata/ecs/job-template.json + if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type3 job$i ENABLED + else + ecs_api_a1_get_job_status 200 job$i ENABLED + fi + fi + if [ $(($i%5)) -eq 3 ]; then + ecs_api_a1_put_job 201 job$i type4 $TARGET ric1 $CR_PATH/job_status_ric1 testdata/ecs/job-template.json + if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type4 job$i ENABLED + else + ecs_api_a1_get_job_status 200 job$i ENABLED + fi + fi + if [ $(($i%5)) -eq 4 ]; then + ecs_api_a1_put_job 201 job$i type5 $TARGET ric1 $CR_PATH/job_status_ric1 testdata/ecs/job-template.json + if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type5 job$i ENABLED + else + ecs_api_a1_get_job_status 200 job$i ENABLED + fi + fi +done + +if [ -z "$FLAT_A1_EI" ]; then + ecs_equal json:A1-EI/v1/eitypes/type1/eijobs $(($NUM_JOBS/5)) + ecs_equal json:A1-EI/v1/eitypes/type2/eijobs $(($NUM_JOBS/5)) + ecs_equal json:A1-EI/v1/eitypes/type3/eijobs $(($NUM_JOBS/5)) + ecs_equal json:A1-EI/v1/eitypes/type4/eijobs $(($NUM_JOBS/5)) + ecs_equal json:A1-EI/v1/eitypes/type5/eijobs $(($NUM_JOBS/5)) +else + ecs_equal json:A1-EI/v1/eijobs?eiTypeId=type1 $(($NUM_JOBS/5)) + ecs_equal json:A1-EI/v1/eijobs?eiTypeId=type1 $(($NUM_JOBS/5)) + ecs_equal json:A1-EI/v1/eijobs?eiTypeId=type1 $(($NUM_JOBS/5)) + ecs_equal json:A1-EI/v1/eijobs?eiTypeId=type1 $(($NUM_JOBS/5)) + ecs_equal json:A1-EI/v1/eijobs?eiTypeId=type1 $(($NUM_JOBS/5)) +fi + +restart_ecs + +set_ecs_trace + +for ((i=1; i<=$NUM_JOBS; i++)) +do + if [ $(($i%5)) -eq 0 ]; then + prodstub_delete_jobdata 204 prod-a job$i + prodstub_delete_jobdata 204 prod-b job$i + prodstub_delete_jobdata 204 prod-c job$i + fi + if [ $(($i%5)) -eq 1 ]; then + prodstub_delete_jobdata 204 prod-b job$i + prodstub_delete_jobdata 204 prod-c job$i + fi + if [ $(($i%5)) -eq 2 ]; then + prodstub_delete_jobdata 204 prod-c job$i + fi + if [ $(($i%5)) -eq 3 ]; then + prodstub_delete_jobdata 204 prod-d job$i + fi + if [ $(($i%5)) -eq 4 ]; then + prodstub_delete_jobdata 204 prod-d job$i + fi +done + +ecs_api_edp_get_producer_status 404 prod-a +ecs_api_edp_get_producer_status 404 prod-b +ecs_api_edp_get_producer_status 404 prod-c +ecs_api_edp_get_producer_status 404 prod-d + +for ((i=1; i<=$NUM_JOBS; i++)) +do + if [ $(($i%5)) -eq 0 ]; then + if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type1 job$i DISABLED + else + ecs_api_a1_get_job_status 200 job$i DISABLED + fi + fi + if [ $(($i%5)) -eq 1 ]; then + if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type2 job$i DISABLED + else + ecs_api_a1_get_job_status 200 job$i DISABLED + fi + fi + if [ $(($i%5)) -eq 2 ]; then + if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type3 job$i DISABLED + else + ecs_api_a1_get_job_status 200 job$i DISABLED + fi + fi + if [ $(($i%5)) -eq 3 ]; then + if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type4 job$i DISABLED + else + ecs_api_a1_get_job_status 200 job$i DISABLED + fi + fi + if [ $(($i%5)) -eq 4 ]; then + if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type5 job$i DISABLED + else + ecs_api_a1_get_job_status 200 job$i DISABLED + fi + fi +done + + +ecs_api_edp_put_producer 201 prod-a $CB_JOB/prod-a $CB_SV/prod-a type1 testdata/ecs/ei-type-1.json + +ecs_api_edp_put_producer 201 prod-b $CB_JOB/prod-b $CB_SV/prod-b type1 testdata/ecs/ei-type-1.json type2 testdata/ecs/ei-type-2.json + +ecs_api_edp_put_producer 201 prod-c $CB_JOB/prod-c $CB_SV/prod-c type1 testdata/ecs/ei-type-1.json type2 testdata/ecs/ei-type-2.json type3 testdata/ecs/ei-type-3.json + +ecs_api_edp_put_producer 201 prod-d $CB_JOB/prod-d $CB_SV/prod-d type4 testdata/ecs/ei-type-4.json type5 testdata/ecs/ei-type-5.json + +ecs_equal json:ei-producer/v1/eiproducers 4 + +ecs_api_edp_get_producer_status 200 prod-a ENABLED +ecs_api_edp_get_producer_status 200 prod-b ENABLED +ecs_api_edp_get_producer_status 200 prod-c ENABLED +ecs_api_edp_get_producer_status 200 prod-d ENABLED + +for ((i=1; i<=$NUM_JOBS; i++)) +do + if [ $(($i%5)) -eq 0 ]; then + if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type1 job$i ENABLED + else + ecs_api_a1_get_job_status 200 job$i ENABLED + fi + fi + if [ $(($i%5)) -eq 1 ]; then + if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type2 job$i ENABLED + else + ecs_api_a1_get_job_status 200 job$i ENABLED + fi + fi + if [ $(($i%5)) -eq 2 ]; then + if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type3 job$i ENABLED + else + ecs_api_a1_get_job_status 200 job$i ENABLED + fi + fi + if [ $(($i%5)) -eq 3 ]; then + if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type4 job$i ENABLED + else + ecs_api_a1_get_job_status 200 job$i ENABLED + fi + fi + if [ $(($i%5)) -eq 4 ]; then + if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_get_job_status 200 type5 job$i ENABLED + else + ecs_api_a1_get_job_status 200 job$i ENABLED + fi + fi +done + + +if [ -z "$FLAT_A1_EI" ]; then + ecs_equal json:A1-EI/v1/eitypes/type1/eijobs $(($NUM_JOBS/5)) + ecs_equal json:A1-EI/v1/eitypes/type2/eijobs $(($NUM_JOBS/5)) + ecs_equal json:A1-EI/v1/eitypes/type3/eijobs $(($NUM_JOBS/5)) + ecs_equal json:A1-EI/v1/eitypes/type4/eijobs $(($NUM_JOBS/5)) + ecs_equal json:A1-EI/v1/eitypes/type5/eijobs $(($NUM_JOBS/5)) +else + ecs_equal json:A1-EI/v1/eijobs?eiTypeId=type1 $(($NUM_JOBS/5)) + ecs_equal json:A1-EI/v1/eijobs?eiTypeId=type1 $(($NUM_JOBS/5)) + ecs_equal json:A1-EI/v1/eijobs?eiTypeId=type1 $(($NUM_JOBS/5)) + ecs_equal json:A1-EI/v1/eijobs?eiTypeId=type1 $(($NUM_JOBS/5)) + ecs_equal json:A1-EI/v1/eijobs?eiTypeId=type1 $(($NUM_JOBS/5)) +fi + +for ((i=1; i<=$NUM_JOBS; i++)) +do + if [ $(($i%5)) -eq 0 ]; then + prodstub_check_jobdata 200 prod-a job$i type1 $TARGET testdata/ecs/job-template.json + prodstub_check_jobdata 200 prod-b job$i type1 $TARGET testdata/ecs/job-template.json + prodstub_check_jobdata 200 prod-c job$i type1 $TARGET testdata/ecs/job-template.json + fi + if [ $(($i%5)) -eq 1 ]; then + prodstub_check_jobdata 200 prod-b job$i type2 $TARGET testdata/ecs/job-template.json + prodstub_check_jobdata 200 prod-c job$i type2 $TARGET testdata/ecs/job-template.json + fi + if [ $(($i%5)) -eq 2 ]; then + prodstub_check_jobdata 200 prod-c job$i type3 $TARGET testdata/ecs/job-template.json + fi + if [ $(($i%5)) -eq 3 ]; then + prodstub_check_jobdata 200 prod-d job$i type4 $TARGET testdata/ecs/job-template.json + fi + if [ $(($i%5)) -eq 4 ]; then + prodstub_check_jobdata 200 prod-d job$i type5 $TARGET testdata/ecs/job-template.json + fi +done + + +for ((i=1; i<=$NUM_JOBS; i++)) +do + if [ $(($i%5)) -eq 0 ]; then + ecs_api_a1_delete_job 204 job$i + fi + if [ $(($i%5)) -eq 1 ]; then + ecs_api_a1_delete_job 204 job$i + fi + if [ $(($i%5)) -eq 2 ]; then + ecs_api_a1_delete_job 204 job$i + fi + if [ $(($i%5)) -eq 3 ]; then + ecs_api_a1_delete_job 204 job$i + fi + if [ $(($i%5)) -eq 4 ]; then + ecs_api_a1_delete_job 204 job$i + fi +done + +ecs_equal json:ei-producer/v1/eiproducers 4 + +ecs_api_edp_get_producer_status 200 prod-a ENABLED +ecs_api_edp_get_producer_status 200 prod-b ENABLED +ecs_api_edp_get_producer_status 200 prod-c ENABLED +ecs_api_edp_get_producer_status 200 prod-d ENABLED + +if [ -z "$FLAT_A1_EI" ]; then + ecs_equal json:A1-EI/v1/eitypes/type1/eijobs 0 + ecs_equal json:A1-EI/v1/eitypes/type2/eijobs 0 + ecs_equal json:A1-EI/v1/eitypes/type3/eijobs 0 + ecs_equal json:A1-EI/v1/eitypes/type4/eijobs 0 + ecs_equal json:A1-EI/v1/eitypes/type5/eijobs 0 +else + ecs_equal json:A1-EI/v1/eijobs?eiTypeId=type1 0 + ecs_equal json:A1-EI/v1/eijobs?eiTypeId=type1 0 + ecs_equal json:A1-EI/v1/eijobs?eiTypeId=type1 0 + ecs_equal json:A1-EI/v1/eijobs?eiTypeId=type1 0 + ecs_equal json:A1-EI/v1/eijobs?eiTypeId=type1 0 +fi + +check_ecs_logs + +store_logs END + +#### TEST COMPLETE #### + + +print_result + +auto_clean_containers diff --git a/test/auto-test/FTC300.sh b/test/auto-test/FTC300.sh index 61ae8d6a..f33146ff 100755 --- a/test/auto-test/FTC300.sh +++ b/test/auto-test/FTC300.sh @@ -23,7 +23,7 @@ TC_ONELINE_DESCR="Resync 10000 policies using OSC and STD interface" INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" #SUPPORTED TEST ENV FILE -SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN" +SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN ORAN-MASTER" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh diff --git a/test/auto-test/FTC310.sh b/test/auto-test/FTC310.sh index 3edb0220..994d0ca3 100755 --- a/test/auto-test/FTC310.sh +++ b/test/auto-test/FTC310.sh @@ -18,13 +18,13 @@ # -TC_ONELINE_DESCR="Resync of RIC via changes in the consul config" +TC_ONELINE_DESCR="Resync of RIC via changes in the consul config or pushed config" #App names to include in the test, space separated list INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM" #SUPPORTED TEST ENV FILE -SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN" +SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN ORAN-MASTER" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh @@ -33,87 +33,114 @@ SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN" #### TEST BEGIN #### -generate_uuid +if [ "$PMS_VERSION" == "V2" ]; then + TESTED_VARIANTS="CONSUL NOCONSUL" +else + TESTED_VARIANTS="CONSUL" +fi -# Clean container and start all needed containers # -clean_containers +for consul_conf in $TESTED_VARIANTS ; do + generate_uuid -start_policy_agent + # Clean container and start all needed containers # + clean_containers -set_agent_trace + start_policy_agent -# Create service to be able to receive events when rics becomes available -# Must use rest towards the agent since dmaap is not configured yet -api_put_service 201 "ric-registration" 0 "$CR_PATH/ric-registration" + set_agent_trace -# Start one RIC of each type -start_ric_simulators ricsim_g1 1 OSC_2.1.0 -start_ric_simulators ricsim_g2 1 STD_1.1.3 -if [ "$PMS_VERSION" == "V2" ]; then - start_ric_simulators ricsim_g3 1 STD_2.0.0 -fi + # Create service to be able to receive events when rics becomes available + # Must use rest towards the agent since dmaap is not configured yet + api_put_service 201 "ric-registration" 0 "$CR_PATH/ric-registration" -start_mr + # Start one RIC of each type + start_ric_simulators ricsim_g1 1 OSC_2.1.0 + start_ric_simulators ricsim_g2 1 STD_1.1.3 + if [ "$PMS_VERSION" == "V2" ]; then + start_ric_simulators ricsim_g3 1 STD_2.0.0 + fi -start_cr + start_mr -start_consul_cbs + start_cr -start_control_panel + start_control_panel -prepare_consul_config NOSDNC ".consul_config.json" + if [ $consul_conf == "CONSUL" ]; then + start_consul_cbs + fi -consul_config_app ".consul_config.json" + prepare_consul_config NOSDNC ".consul_config.json" -if [ "$PMS_VERSION" == "V2" ]; then - api_equal json:rics 3 120 + if [ "$PMS_VERSION" == "V2" ] && [ $consul_conf == "NOCONSUL" ]; then + api_put_configuration 200 ".consul_config.json" + api_get_configuration 200 ".consul_config.json" + else + consul_config_app ".consul_config.json" + fi - cr_equal received_callbacks 3 120 + if [ "$PMS_VERSION" == "V2" ]; then + api_equal json:rics 3 120 - cr_api_check_all_sync_events 200 ric-registration ricsim_g1_1 ricsim_g2_1 ricsim_g3_1 -else - api_equal json:rics 2 120 -fi + cr_equal received_callbacks 3 120 -# Add an STD RIC and check -start_ric_simulators ricsim_g2 2 STD_1.1.3 + cr_api_check_all_sync_events 200 ric-registration ricsim_g1_1 ricsim_g2_1 ricsim_g3_1 + else + api_equal json:rics 2 120 + fi -prepare_consul_config NOSDNC ".consul_config.json" + # Add an STD RIC and check + start_ric_simulators ricsim_g2 2 STD_1.1.3 -consul_config_app ".consul_config.json" + prepare_consul_config NOSDNC ".consul_config.json" + if [ "$PMS_VERSION" == "V2" ] && [ $consul_conf == "NOCONSUL" ]; then + api_put_configuration 200 ".consul_config.json" + api_get_configuration 200 ".consul_config.json" + else + consul_config_app ".consul_config.json" + fi -if [ "$PMS_VERSION" == "V2" ]; then - api_equal json:rics 4 120 + if [ "$PMS_VERSION" == "V2" ]; then + api_equal json:rics 4 120 - cr_equal received_callbacks 4 120 + cr_equal received_callbacks 4 120 - cr_api_check_all_sync_events 200 ric-registration ricsim_g2_2 -else - api_equal json:rics 3 120 -fi + cr_api_check_all_sync_events 200 ric-registration ricsim_g2_2 + else + api_equal json:rics 3 120 + fi -check_policy_agent_logs -check_control_panel_logs + check_policy_agent_logs + check_control_panel_logs -# Remove one RIC RIC and check -start_ric_simulators ricsim_g2 1 STD_1.1.3 + # Remove one RIC RIC and check + start_ric_simulators ricsim_g2 1 STD_1.1.3 -prepare_consul_config NOSDNC ".consul_config.json" + prepare_consul_config NOSDNC ".consul_config.json" + if [ "$PMS_VERSION" == "V2" ] && [ $consul_conf == "NOCONSUL" ]; then + api_put_configuration 200 ".consul_config.json" + api_get_configuration 200 ".consul_config.json" + else + consul_config_app ".consul_config.json" + fi -consul_config_app ".consul_config.json" + if [ "$PMS_VERSION" == "V2" ]; then + api_equal json:rics 3 120 -if [ "$PMS_VERSION" == "V2" ]; then - api_equal json:rics 3 120 + cr_equal received_callbacks 4 120 + else + api_equal json:rics 2 120 + fi - cr_equal received_callbacks 4 120 -else - api_equal json:rics 2 120 -fi + if [ "$PMS_VERSION" == "V2" ] && [ $consul_conf == "NOCONSUL" ]; then + api_get_configuration 200 ".consul_config.json" + fi -check_policy_agent_logs -check_control_panel_logs + check_policy_agent_logs + check_control_panel_logs -store_logs END + store_logs END_$consul_conf +done #### TEST COMPLETE #### diff --git a/test/auto-test/FTC350.sh b/test/auto-test/FTC350.sh index 959f00f8..3c6f4437 100755 --- a/test/auto-test/FTC350.sh +++ b/test/auto-test/FTC350.sh @@ -23,7 +23,7 @@ TC_ONELINE_DESCR="Change supported policy types and reconfigure rics" INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" #SUPPORTED TEST ENV FILE -SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN" +SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN ORAN-MASTER" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh diff --git a/test/auto-test/FTC800.sh b/test/auto-test/FTC800.sh index b7e49d4f..401d3101 100755 --- a/test/auto-test/FTC800.sh +++ b/test/auto-test/FTC800.sh @@ -23,7 +23,7 @@ TC_ONELINE_DESCR="Create 10000 policies in sequence using http/https and Agent R INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" #SUPPORTED TEST ENV FILE -SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN" +SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN ORAN-MASTER" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh diff --git a/test/auto-test/FTC810.sh b/test/auto-test/FTC810.sh index 3dd2a0e5..74ecf72e 100755 --- a/test/auto-test/FTC810.sh +++ b/test/auto-test/FTC810.sh @@ -23,7 +23,7 @@ TC_ONELINE_DESCR="Repeatedly create and delete policies in each RICs for 24h (or INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" #SUPPORTED TEST ENV FILE -SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN" +SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN ORAN-MASTER" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh diff --git a/test/auto-test/FTC850.sh b/test/auto-test/FTC850.sh index c6f61d79..26a5ffa1 100755 --- a/test/auto-test/FTC850.sh +++ b/test/auto-test/FTC850.sh @@ -17,13 +17,13 @@ # ============LICENSE_END================================================= # -TC_ONELINE_DESCR="Create/delete policies in parallel over a number of ric using a number of child process" +TC_ONELINE_DESCR="Create/delete policies in parallel over a number of rics using a number of child process" #App names to include in the test, space separated list INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" #SUPPORTED TEST ENV FILE -SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN" +SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN ORAN-MASTER" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh diff --git a/test/auto-test/FTC900.sh b/test/auto-test/FTC900.sh index f7e91e32..ea3ef87c 100755 --- a/test/auto-test/FTC900.sh +++ b/test/auto-test/FTC900.sh @@ -23,7 +23,7 @@ TC_ONELINE_DESCR="Preparation for test of the Control Panel and the Health Check INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM" #SUPPORTED TEST ENV FILE -SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN" +SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN ORAN-MASTER" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh diff --git a/test/auto-test/PM_DEMO.sh b/test/auto-test/PM_DEMO.sh index 3e0858fa..ce54a5ff 100755 --- a/test/auto-test/PM_DEMO.sh +++ b/test/auto-test/PM_DEMO.sh @@ -23,7 +23,7 @@ TC_ONELINE_DESCR="Preparation demo setup - populating a number of ric simulator INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" #SUPPORTED TEST ENV FILE -SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN" +SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN ORAN-MASTER" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh @@ -34,16 +34,17 @@ SUPPORTED_PROFILES="ONAP-MASTER ONAP-GUILIN" #Local vars in test script ########################## +use_cr_https +use_agent_rest_https +use_sdnc_https +use_simulator_https + if [ "$PMS_VERSION" == "V2" ]; then notificationurl=$CR_PATH"/test" else notificationurl="" fi -use_agent_rest_https -use_sdnc_https -use_simulator_https - clean_containers OSC_NUM_RICS=6 @@ -61,8 +62,6 @@ start_mr #Just to prevent errors in the agent log... start_control_panel -start_control_panel - start_sdnc start_consul_cbs diff --git a/test/auto-test/PM_EI_DEMO.sh b/test/auto-test/PM_EI_DEMO.sh new file mode 100755 index 00000000..2bca307a --- /dev/null +++ b/test/auto-test/PM_EI_DEMO.sh @@ -0,0 +1,198 @@ +#!/usr/bin/env bash + +# ============LICENSE_START=============================================== +# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + +TC_ONELINE_DESCR="Preparation demo setup - policy management and enrichment information" + +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC ECS PRODSTUB" + +#SUPPORTED TEST ENV FILE +SUPPORTED_PROFILES="ONAP-MASTER ORAN-MASTER" + +. ../common/testcase_common.sh $@ +. ../common/agent_api_functions.sh +. ../common/ricsimulator_api_functions.sh +. ../common/ecs_api_functions.sh +. ../common/prodstub_api_functions.sh +. ../common/cr_api_functions.sh + +#### TEST BEGIN #### + +#Local vars in test script +########################## + +use_cr_https +use_agent_rest_https +use_sdnc_https +use_simulator_https +use_ecs_rest_https +use_prod_stub_https + +if [ "$PMS_VERSION" == "V2" ]; then + notificationurl=$CR_PATH"/test" +else + echo "PMS VERSION 2 (V2) is required" + exit 1 +fi + +clean_containers + +STD_NUM_RICS=2 + +start_ric_simulators $RIC_SIM_PREFIX"_g3" $STD_NUM_RICS STD_2.0.0 + +start_mr #Just to prevent errors in the agent log... + +start_control_panel + +start_sdnc + +start_consul_cbs + +prepare_consul_config SDNC ".consul_config.json" +consul_config_app ".consul_config.json" + +start_policy_agent + +start_cr + +start_prod_stub + +start_ecs + +set_agent_trace + +set_ecs_trace + +api_get_status 200 + +# Print the A1 version for STD 2.X +for ((i=1; i<=$STD_NUM_RICS; i++)) +do + sim_print $RIC_SIM_PREFIX"_g3_"$i interface +done +# Load the polictypes in std +for ((i=1; i<=$STD_NUM_RICS; i++)) +do + sim_put_policy_type 201 $RIC_SIM_PREFIX"_g3_"$i STD_QOS_0_2_0 demo-testdata/STD2/sim_qos.json + sim_put_policy_type 201 $RIC_SIM_PREFIX"_g3_"$i STD_QOS2_0.1.0 demo-testdata/STD2/sim_qos2.json +done + +#Check the number of schemas and the individual schemas in STD +api_equal json:policy-types 2 120 + +for ((i=1; i<=$STD_NUM_RICS; i++)) +do + api_equal json:policy-types?ric_id=$RIC_SIM_PREFIX"_g3_"$i 2 120 +done + +# Check the schemas in STD +for ((i=1; i<=$STD_NUM_RICS; i++)) +do + api_get_policy_type 200 STD_QOS_0_2_0 demo-testdata/STD2/qos-agent-modified.json + api_get_policy_type 200 'STD_QOS2_0.1.0' demo-testdata/STD2/qos2-agent-modified.json +done + +#Check the number of types +api_equal json:policy-types 2 120 + +api_put_service 201 "Emergency-response-app" 0 "$CR_PATH/1" + +# Create policies in STD +for ((i=1; i<=$STD_NUM_RICS; i++)) +do + generate_uuid + api_put_policy 201 "Emergency-response-app" $RIC_SIM_PREFIX"_g3_"$i STD_QOS_0_2_0 $((2300+$i)) NOTRANSIENT $notificationurl demo-testdata/STD2/pi1_template.json 1 + generate_uuid + api_put_policy 201 "Emergency-response-app" $RIC_SIM_PREFIX"_g3_"$i 'STD_QOS2_0.1.0' $((2400+$i)) NOTRANSIENT $notificationurl demo-testdata/STD2/pi1_template.json 1 +done + + +# Check the number of policies in STD +for ((i=1; i<=$STD_NUM_RICS; i++)) +do + sim_equal $RIC_SIM_PREFIX"_g3_"$i num_instances 2 +done + + + +FLAT_A1_EI="1" + +CB_JOB="$PROD_STUB_HTTPX://$PROD_STUB_APP_NAME:$PROD_STUB_PORT/callbacks/job" +CB_SV="$PROD_STUB_HTTPX://$PROD_STUB_APP_NAME:$PROD_STUB_PORT/callbacks/supervision" +TARGET1="$RIC_SIM_HTTPX://ricsim_g3_1:$RIC_SIM_PORT/datadelivery" +TARGET2="$RIC_SIM_HTTPX://ricsim_g3_2:$RIC_SIM_PORT/datadelivery" + +STATUS1="$CR_HTTPX://$CR_APP_NAME:$CR_PORT/callbacks/job1-status" +STATUS2="$CR_HTTPX://$CR_APP_NAME:$CR_PORT/callbacks/job2-status" + +prodstub_arm_producer 200 prod-a +prodstub_arm_type 200 prod-a type1 +prodstub_arm_job_create 200 prod-a job1 +prodstub_arm_job_create 200 prod-a job2 + + +### ecs status +ecs_api_service_status 200 + + + +## Setup prod-a +ecs_api_edp_put_producer 201 prod-a $CB_JOB/prod-a $CB_SV/prod-a type1 testdata/ecs/ei-type-1.json + +ecs_api_edp_get_producer 200 prod-a $CB_JOB/prod-a $CB_SV/prod-a type1 testdata/ecs/ei-type-1.json + +ecs_api_edp_get_producer_status 200 prod-a ENABLED + + +## Create a job for prod-a +## job1 - prod-a +if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_put_job 201 type1 job1 $TARGET1 ricsim_g3_1 testdata/ecs/job-template.json +else + ecs_api_a1_put_job 201 job1 type1 $TARGET1 ricsim_g3_1 $STATUS1 testdata/ecs/job-template.json +fi + +# Check the job data in the producer +prodstub_check_jobdata 200 prod-a job1 type1 $TARGET1 testdata/ecs/job-template.json + + +## Create a second job for prod-a +## job2 - prod-a +if [ -z "$FLAT_A1_EI" ]; then + ecs_api_a1_put_job 201 type1 job2 $TARGET2 ricsim_g3_2 testdata/ecs/job-template.json +else + ecs_api_a1_put_job 201 job2 type1 $TARGET2 ricsim_g3_2 $STATUS2 testdata/ecs/job-template.json +fi + +# Check the job data in the producer +prodstub_check_jobdata 200 prod-a job2 type1 $TARGET2 testdata/ecs/job-template.json + + + + +check_policy_agent_logs +check_ecs_logs +check_sdnc_logs + +#### TEST COMPLETE #### + +store_logs END + +print_result diff --git a/test/auto-test/testdata/ecs/ei-type-3.json b/test/auto-test/testdata/ecs/ei-type-3.json new file mode 100644 index 00000000..8dcbbc87 --- /dev/null +++ b/test/auto-test/testdata/ecs/ei-type-3.json @@ -0,0 +1,6 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "STD_Type3_1.0.0", + "description": "EI-Type 3", + "type": "object" +} \ No newline at end of file diff --git a/test/auto-test/testdata/ecs/ei-type-4.json b/test/auto-test/testdata/ecs/ei-type-4.json new file mode 100644 index 00000000..56d0ad1d --- /dev/null +++ b/test/auto-test/testdata/ecs/ei-type-4.json @@ -0,0 +1,6 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "STD_Type4_1.0.0", + "description": "EI-Type 4", + "type": "object" +} \ No newline at end of file diff --git a/test/auto-test/testdata/ecs/ei-type-5.json b/test/auto-test/testdata/ecs/ei-type-5.json new file mode 100644 index 00000000..3b95ec72 --- /dev/null +++ b/test/auto-test/testdata/ecs/ei-type-5.json @@ -0,0 +1,6 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "STD_Type5_1.0.0", + "description": "EI-Type 5", + "type": "object" +} \ No newline at end of file diff --git a/test/auto-test/testdata/ecs/ei-type-6.json b/test/auto-test/testdata/ecs/ei-type-6.json new file mode 100644 index 00000000..8b6d6800 --- /dev/null +++ b/test/auto-test/testdata/ecs/ei-type-6.json @@ -0,0 +1,6 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "STD_Type6_1.0.0", + "description": "EI-Type 6", + "type": "object" +} \ No newline at end of file diff --git a/test/common/README.md b/test/common/README.md index 24dfc9dc..4cde5323 100644 --- a/test/common/README.md +++ b/test/common/README.md @@ -742,15 +742,17 @@ Test of GET '/policy_status' or V2 GET '/policies/{policy_id}/status'. | arg list | |--| -| ` (STD [])|(OSC )` | +| ` (STD|STD2 |EMPTY [|EMPTY])|(OSC )` | | parameter | description | | --------- | ----------- | | `` | Expected http response code | | `` | Id of the policy | | `STD` | Indicator of status of Standarized A1 | +| `STD2` | Indicator of status of Standarized A1 version 2 | | `` | Enforcement status | | `` | Optional reason | +| `EMPTY` | Indicator of empty string status or reason | | `OSC` | Indicator of status of Non-Standarized OSC A1 | | `` | Instance status | | `` | Deleted status, true or false | @@ -890,6 +892,30 @@ Test of PUT '/services/keepalive' or V2 PUT '/v2/services/{service_id}/keepalive | `` | Expected http response code | | `` | Service name | +## Function: api_put_configuration() ## +Test of PUT '/v2/configuration' + +| arg list | +|--| +| ` | + +| parameter | description | +| --------- | ----------- | +| `` | Expected http response code | +| `` | Path json config file | + +## Function: api_get_configuration() ## +Test of GET '/v2/configuration' + +| arg list | +|--| +| []` | + +| parameter | description | +| --------- | ----------- | +| `` | Expected http response code | +| `` | Path json config file to compare the retrieved config with | + # Description of functions in ricsimulator_api_functions.sh # The functions below only use the admin interface of the simulator, no usage of the A1 interface. @@ -1115,6 +1141,22 @@ Checks the status of a policy # Description of functions in ecs_api_function.sh # +## Function: ecs_equal ## +Tests if a variable value in the ECS is equal to a target value. +Without the timeout, the test sets pass or fail immediately depending on if the variable is equal to the target or not. +With the timeout, the test waits up to the timeout seconds before setting pass or fail depending on if the variable value becomes equal to the target value or not. +See the 'a1-interface' repo for more details. + +| arg list | +|--| +| ` [ ]` | + +| parameter | description | +| --------- | ----------- | +| `` | Variable name in ecs | +| `` | Target value for the variable | +| `` | Max time to wait for the variable to reach the target value | + ## Function: ecs_api_a1_get_job_ids() ## Test of GET '/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs' and optional check of the array of returned job ids. To test the response code only, provide the response code parameter as well as a type id and an owner id. @@ -1329,14 +1371,13 @@ To test, provide all parameters. The list of type/schema pair may be empty. | arg list | |--| -| ` (EMPTY | [ ]+)` | +| ` (EMPTY | [ ]+)` | | parameter | description | | --------- | ----------- | | `` | Expected http response code | | `` | Id of the producer | -| `` | Callback for create job | -| `` | Callback for delete job | +| `` | Callback for create/delete job | | `` | Callback for producer supervision | | `` | Id of the EI type | | `` | Path to a schema file | @@ -1456,6 +1497,20 @@ Check a job in the prodstub towards the list of provided parameters. | `` | Target url for data delivery | | `` | Path to a job template file | +## Function: prodstub_delete_jobdata() ## +Delete the job parameters, job data, for a job. + +| arg list | +|--| +| ` ` | + +| parameter | description | +| --------- | ----------- | +| `` | Expected http response code | +| `` | Id of the producer | +| `` | Id of the job | + + ## Function: prodstub_equal ## Tests if a variable value in the prodstub is equal to a target value. Without the timeout, the test sets pass or fail immediately depending on if the variable is equal to the target or not. diff --git a/test/common/agent_api_functions.sh b/test/common/agent_api_functions.sh index 5f5a2c69..fbd9fc49 100644 --- a/test/common/agent_api_functions.sh +++ b/test/common/agent_api_functions.sh @@ -43,8 +43,6 @@ api_equal() { return 0 fi fi - - ((RES_CONF_FAIL++)) __print_err "needs two or three args: json: [ timeout ]" $@ return 1 } @@ -54,9 +52,7 @@ api_equal() { # args(V2): |NORIC |NOSERVICE |NOTYPE [ NOID | [ EMPTY| ]*] # (Function for test scripts) api_get_policies() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ "$PMS_VERSION" == "V2" ]; then paramError=0 @@ -115,9 +111,7 @@ api_get_policies() { status=${res:${#res}-3} 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 @@ -154,9 +148,7 @@ api_get_policies() { 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 @@ -184,9 +176,7 @@ api_get_policies() { status=${res:${#res}-3} 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 @@ -221,16 +211,13 @@ api_get_policies() { 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 fi - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN + __log_test_pass return 0 } @@ -242,9 +229,7 @@ api_get_policies() { # (Function for test scripts) api_get_policy() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ "$PMS_VERSION" == "V2" ]; then @@ -264,9 +249,7 @@ api_get_policy() { status=${res:${#res}-3} 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 @@ -275,7 +258,6 @@ api_get_policy() { #Create a policy json to compare with body=${res:0:${#res}-3} - file="./tmp/.p.json" targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\"" if [ $7 != "NOTRANSIENT" ]; then @@ -290,16 +272,14 @@ api_get_policy() { targetJson=$targetJson", \"status_notification_uri\":\"$8\"" fi - data=$(sed 's/XXX/'${2}'/g' $temp) + data=$(sed 's/XXX/'${2}'/g' $3) targetJson=$targetJson", \"policy_data\":$data" targetJson="{$targetJson}" echo "TARGET JSON: $targetJson" >> $HTTPLOG 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 @@ -313,16 +293,12 @@ api_get_policy() { echo "TARGET JSON: $targetJson" >> $HTTPLOG 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 - return 1 + __log_test_fail_body fi fi fi - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN + __log_test_pass return 0 } @@ -331,9 +307,7 @@ api_get_policy() { # args(V2): |NOTYPE |NOTRANSIENT |NOURL [] # (Function for test scripts) api_put_policy() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ "$PMS_VERSION" == "V2" ]; then if [ $# -lt 8 ] || [ $# -gt 9 ]; then @@ -409,9 +383,7 @@ api_put_policy() { echo -ne " Executing "$count"("$max")${SAMELINE}" if [ $status -ne $1 ]; then echo " Executed "$count"?("$max")" - 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 @@ -421,8 +393,7 @@ api_put_policy() { done echo "" - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN + __log_test_pass return 0 } @@ -432,9 +403,7 @@ api_put_policy() { # (Function for test scripts) api_put_policy_batch() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ "$PMS_VERSION" == "V2" ]; then if [ $# -lt 8 ] || [ $# -gt 9 ]; then @@ -509,9 +478,7 @@ api_put_policy_batch() { if [ $status -ne 200 ]; then echo " Requested(batch) "$count"?("$max")" - echo -e $RED" FAIL. Exepected status 200 (in request), got "$status $ERED - ((RES_FAIL++)) - __check_stop_at_error + __log_test_fail_status_code 200 $status return 1 fi cid=${res:0:${#res}-3} @@ -531,9 +498,7 @@ api_put_policy_batch() { if [ $status -ne $1 ]; then echo " Accepted(batch) "$count"?("$max")" - 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 @@ -543,8 +508,7 @@ api_put_policy_batch() { echo "" - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN + __log_test_pass return 0 } @@ -553,9 +517,7 @@ api_put_policy_batch() { # args(V2): |NOURL # (Function for test scripts) api_put_policy_parallel() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ "$PMS_VERSION" == "V2" ]; then if [ $# -ne 11 ]; then @@ -648,15 +610,11 @@ api_put_policy_parallel() { fi done if [ -z $msg ]; then - echo " $(($count*$num_rics)) policy request(s) executed" - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN + __log_test_pass " $(($count*$num_rics)) policy request(s) executed" return 0 fi - echo -e $RED" FAIL. One of more processes failed to execute" $ERED - ((RES_FAIL++)) - __check_stop_at_error + __log_test_fail_general "One of more processes failed to execute" return 1 } @@ -664,9 +622,7 @@ api_put_policy_parallel() { # args: [count] # (Function for test scripts) api_delete_policy() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ $# -lt 2 ] || [ $# -gt 3 ]; then __print_err " [count]" $@ @@ -694,9 +650,7 @@ api_delete_policy() { if [ $status -ne $1 ]; then echo " Executed "$count"?("$max")" - 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 let pid=$pid+1 @@ -705,8 +659,7 @@ api_delete_policy() { done echo "" - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN + __log_test_pass return 0 } @@ -714,9 +667,7 @@ api_delete_policy() { # args: [count] # (Function for test scripts) api_delete_policy_batch() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ $# -lt 2 ] || [ $# -gt 3 ]; then __print_err " [count]" $@ @@ -744,9 +695,7 @@ api_delete_policy_batch() { if [ $status -ne 200 ]; then echo " Requested(batch) "$count"?("$max")" - echo -e $RED" FAIL. Exepected status 200 (in request), got "$status $ERED - ((RES_FAIL++)) - __check_stop_at_error + __log_test_fail_status_code 200 $status return 1 fi cid=${res:0:${#res}-3} @@ -767,9 +716,7 @@ api_delete_policy_batch() { if [ $status -ne $1 ]; then echo " Deleted(batch) "$count"?("$max")" - 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 @@ -779,8 +726,7 @@ api_delete_policy_batch() { echo "" - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN + __log_test_pass return 0 } @@ -788,9 +734,7 @@ api_delete_policy_batch() { # args: # (Function for test scripts) api_delete_policy_parallel() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ $# -ne 5 ]; then __print_err " " $@ @@ -849,15 +793,11 @@ api_delete_policy_parallel() { fi done if [ -z $msg ]; then - echo " $(($count*$num_rics)) policy request(s) executed" - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN + __log_test_pass " $(($count*$num_rics)) policy request(s) executed" return 0 fi - echo -e $RED" FAIL. One of more processes failed to execute" $ERED - ((RES_FAIL++)) - __check_stop_at_error + __log_test_fail_general "One of more processes failed to execute" return 1 } @@ -865,9 +805,7 @@ api_delete_policy_parallel() { # args: |NORIC |NOSERVICE |NOTYPE ([> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ $# -lt 4 ]; then __print_err " |NORIC |NOSERVICE |NOTYPE ([ [] # (Function for test scripts) api_get_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 $@ if [ "$PMS_VERSION" != "V2" ]; then - echo -e $RED" FAIL, function not supported"$ERED - ((RES_FAIL++)) - __check_stop_at_error + __log_test_fail_not_supported return 1 fi @@ -988,9 +917,7 @@ api_get_policy_type() { status=${res:${#res}-3} 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 @@ -1004,15 +931,12 @@ api_get_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 } @@ -1020,14 +944,10 @@ api_get_policy_type() { # args: [] # (Function for test scripts) api_get_policy_schema() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ "$PMS_VERSION" == "V2" ]; then - echo -e $RED" FAIL, function not supported"$ERED - ((RES_FAIL++)) - __check_stop_at_error + __log_test_fail_not_supported return 1 fi @@ -1040,9 +960,7 @@ api_get_policy_schema() { status=${res:${#res}-3} 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 @@ -1056,15 +974,12 @@ api_get_policy_schema() { 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 } @@ -1073,9 +988,7 @@ api_get_policy_schema() { # args(V2): # (Function for test scripts) api_get_policy_schemas() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ "$PMS_VERSION" == "V2" ]; then if [ $# -ne 1 ]; then @@ -1101,9 +1014,7 @@ api_get_policy_schemas() { status=${res:${#res}-3} 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 @@ -1130,28 +1041,23 @@ api_get_policy_schemas() { 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 } # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status -# arg: (STD [])|(OSC ) +# arg: (STD|STD2 |EMPTY [|EMPTY])|(OSC ) # (Function for test scripts) api_get_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 $@ if [ $# -lt 4 ] || [ $# -gt 5 ]; then - __print_err " (STD [])|(OSC )" $@ + __print_err " (STD |EMPTY [|EMPTY])|(OSC )" $@ return 1 fi @@ -1163,6 +1069,20 @@ api_get_policy_status() { targetJson=$targetJson",\"reason\":\"$5\"" fi targetJson=$targetJson"}" + elif [ $3 == "STD2" ]; then + if [ $4 == "EMPTY" ]; then + targetJson="{\"enforceStatus\":\"\"" + else + targetJson="{\"enforceStatus\":\"$4\"" + fi + if [ $# -eq 5 ]; then + if [ $5 == "EMPTY" ]; then + targetJson=$targetJson",\"enforceReason\":\"\"" + else + targetJson=$targetJson",\"enforceReason\":\"$5\"" + fi + fi + targetJson=$targetJson"}" elif [ $3 == "OSC" ]; then targetJson="{\"instance_status\":\"$4\"" if [ $# -eq 5 ]; then @@ -1185,9 +1105,7 @@ api_get_policy_status() { status=${res:${#res}-3} 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 @@ -1196,14 +1114,11 @@ api_get_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 - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN + __log_test_pass return 0 } @@ -1211,9 +1126,7 @@ api_get_policy_status() { # args: [|NORIC [|EMPTY []*]] # (Function for test scripts) api_get_policy_types() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ $# -lt 1 ]; then __print_err " [|NORIC [|EMPTY []*]]" $@ @@ -1242,9 +1155,7 @@ api_get_policy_types() { status=${res:${#res}-3} 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 @@ -1270,15 +1181,12 @@ api_get_policy_types() { 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 } @@ -1290,9 +1198,7 @@ api_get_policy_types() { # args: # (Function for test scripts) api_get_status() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ $# -ne 1 ]; then __print_err "" $@ return 1 @@ -1306,14 +1212,11 @@ api_get_status() { status=${res:${#res}-3} 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 } @@ -1330,9 +1233,7 @@ api_get_status() { # (Function for test scripts) api_get_ric() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ "$PMS_VERSION" == "V2" ]; then if [ $# -lt 3 ]; then @@ -1356,9 +1257,7 @@ api_get_ric() { status=${res:${#res}-3} 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 @@ -1366,9 +1265,7 @@ api_get_ric() { body=${res:0:${#res}-3} res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" ) if [ $res -ne 0 ]; then - echo -e $RED" FAIL, could not create target ric info json"$ERED - ((RES_FAIL++)) - __check_stop_at_error + __log_test_fail_general "Could not create target ric info json" return 1 fi @@ -1377,9 +1274,7 @@ api_get_ric() { echo " TARGET JSON: $targetJson" >> $HTTPLOG 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 @@ -1395,24 +1290,19 @@ api_get_ric() { status=${res:${#res}-3} 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 if [ $# -eq 3 ]; then body=${res:0:${#res}-3} if [ "$body" != "$3" ]; then - echo -e $RED" FAIL, returned body not correct"$ERED - ((RES_FAIL++)) - __check_stop_at_error + __log_test_fail_body return 1 fi fi fi - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN + __log_test_pass return 0 } @@ -1422,9 +1312,7 @@ api_get_ric() { # format of ric-info: :: # (Function for test scripts) api_get_rics() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ $# -lt 2 ]; then __print_err " |NOTYPE []" $@ @@ -1447,9 +1335,7 @@ api_get_rics() { status=${res:${#res}-3} 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 @@ -1461,9 +1347,7 @@ api_get_rics() { res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" ) fi if [ $res -ne 0 ]; then - echo -e $RED" FAIL, could not create target ric info json"$ERED - ((RES_FAIL++)) - __check_stop_at_error + __log_test_fail_general "Could not create target ric info json" return 1 fi @@ -1474,15 +1358,12 @@ api_get_rics() { echo "TARGET JSON: $targetJson" >> $HTTPLOG 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 } @@ -1494,9 +1375,7 @@ api_get_rics() { # args: # (Function for test scripts) api_put_service() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ $# -ne 4 ]; then __print_err " " $@ return 1 @@ -1516,14 +1395,11 @@ api_put_service() { status=${res:${#res}-3} 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 } @@ -1531,9 +1407,7 @@ api_put_service() { #args: [ ( ) | (NOSERVICE [ ]* )] # (Function for test scripts) api_get_services() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ #Number of accepted parameters: 1, 2, 4, 7, 10, 13,... paramError=1 if [ $# -eq 1 ]; then @@ -1571,9 +1445,7 @@ api_get_services() { status=${res:${#res}-3} 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 @@ -1605,15 +1477,12 @@ api_get_services() { echo "TARGET JSON: $targetJson" >> $HTTPLOG 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 } @@ -1621,9 +1490,7 @@ api_get_services() { # args: []*" # (Function for test scripts) api_get_service_ids() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ $# -lt 1 ]; then __print_err " []*" $@ @@ -1639,9 +1506,7 @@ api_get_service_ids() { status=${res:${#res}-3} 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 @@ -1666,14 +1531,11 @@ api_get_service_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 } @@ -1681,9 +1543,7 @@ api_get_service_ids() { # args: # (Function for test scripts) api_delete_services() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ $# -ne 2 ]; then __print_err " " $@ @@ -1698,14 +1558,11 @@ api_delete_services() { status=${res:${#res}-3} 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 } @@ -1713,9 +1570,7 @@ api_delete_services() { # args: # (Function for test scripts) api_put_services_keepalive() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ $# -ne 2 ]; then __print_err " " $@ @@ -1731,14 +1586,98 @@ api_put_services_keepalive() { status=${res:${#res}-3} 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 } +################################################################## +#### API Test case functions Configuration #### +################################################################## + +# API Test function: PUT /v2/configuration +# args: +# (Function for test scripts) +api_put_configuration() { + __log_test_start $@ + + if [ "$PMS_VERSION" != "V2" ]; then + __log_test_fail_not_supported + return 1 + fi + + if [ $# -ne 2 ]; then + __print_err " " $@ + return 1 + fi + if [ ! -f $2 ]; then + _log_test_fail_general "Config file "$2", does not exist" + return 1 + fi + inputJson=$(< $2) + inputJson="{\"config\":"$inputJson"}" + file="./tmp/.config.json" + echo $inputJson > $file + query="/v2/configuration" + res="$(__do_curl_to_api PA PUT $query $file)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + __log_test_fail_status_code $1 $status + return 1 + fi + + __log_test_pass + return 0 +} + +# API Test function: GET /v2/configuration +# args: [] +# (Function for test scripts) +api_get_configuration() { + __log_test_start $@ + + if [ "$PMS_VERSION" != "V2" ]; then + __log_test_fail_not_supported + return 1 + fi + + if [ $# -lt 1 ] || [ $# -gt 2 ]; then + __print_err " []" $@ + return 1 + fi + if [ ! -f $2 ]; then + _log_test_fail_general "Config file "$2" for comparison, does not exist" + return 1 + fi + + query="/v2/configuration" + res="$(__do_curl_to_api PA GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + __log_test_fail_status_code $1 $status + return 1 + fi + + if [ $# -eq 2 ]; then + + body=${res:0:${#res}-3} + + targetJson=$(< $2) + targetJson="{\"config\":"$targetJson"}" + echo "TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + __log_test_fail_body + return 1 + fi + fi + + __log_test_pass + return 0 +} \ No newline at end of file diff --git a/test/common/api_curl.sh b/test/common/api_curl.sh index 611fc4dc..cd3e9790 100644 --- a/test/common/api_curl.sh +++ b/test/common/api_curl.sh @@ -26,7 +26,8 @@ # arg: (PA|ECS GET|PUT|POST|DELETE|GET_BATCH|PUT_BATCH|POST_BATCH|DELETE_BATCH []) | (PA|ECS RESPONSE ) # (Not for test scripts) __do_curl_to_api() { - echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S") + echo " (${BASH_LINENO[0]}) - ${TIMESTAMP}: ${FUNCNAME[0]}" $@ >> $HTTPLOG paramError=0 if [ $# -gt 0 ]; then diff --git a/test/common/controller_api_functions.sh b/test/common/controller_api_functions.sh index b0ae6418..4d568d76 100644 --- a/test/common/controller_api_functions.sh +++ b/test/common/controller_api_functions.sh @@ -75,9 +75,7 @@ __do_curl_to_controller() { # arg: (OSC [ []* ]) | ( STD [ []* ] ) # (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 $@ paramError=1 if [ $# -gt 3 ] && [ $2 == "OSC" ]; then @@ -97,17 +95,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} @@ -130,14 +124,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 } @@ -146,9 +137,7 @@ controller_api_get_A1_policy_ids() { # arg: OSC [] # (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 $@ paramError=1 if [ $# -gt 3 ] && [ $2 == "OSC" ]; then @@ -165,17 +154,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} @@ -189,15 +174,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 } @@ -205,9 +187,7 @@ controller_api_get_A1_policy_type() { # arg: (STD ) | (OSC ) # (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 $@ paramError=1 if [ $# -eq 5 ] && [ $2 == "OSC" ]; then @@ -227,22 +207,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 } @@ -250,9 +225,7 @@ controller_api_delete_A1_policy() { # arg: (STD ) | (OSC ) # (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 $@ paramError=1 if [ $# -eq 6 ] && [ $2 == "OSC" ]; then @@ -275,22 +248,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 } @@ -299,9 +267,7 @@ controller_api_put_A1_policy() { # arg: (STD []) | (OSC ) # (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 $@ targetJson="" paramError=1 @@ -334,17 +300,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 @@ -355,14 +317,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 diff --git a/test/common/cr_api_functions.sh b/test/common/cr_api_functions.sh index fe4b1fd6..e2b94913 100644 --- a/test/common/cr_api_functions.sh +++ b/test/common/cr_api_functions.sh @@ -57,23 +57,18 @@ cr_equal() { if [ $# -eq 2 ] || [ $# -eq 3 ]; then __var_test "CR" "$LOCALHOST$CR_EXTERNAL_PORT/counter/" $1 "=" $2 $3 else - ((RES_CONF_FAIL++)) __print_err "Wrong args to cr_equal, needs two or three args: [ timeout ]" $@ fi } -# CR API: Check the contents of all current ric sync events from PMS +# CR API: Check the contents of all current ric sync events for one id from PMS # [ EMPTY | ( )+ ] # (Function for test scripts) cr_api_check_all_sync_events() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ "$PMS_VERSION" != "V2" ]; then - echo -e $RED" FAIL, function not supported"$ERED - ((RES_FAIL++)) - __check_stop_at_error + __log_test_fail_not_supported return 1 fi @@ -87,9 +82,7 @@ cr_api_check_all_sync_events() { status=${res:${#res}-3} 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 @@ -115,13 +108,60 @@ cr_api_check_all_sync_events() { 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 + __log_test_pass + return 0 +} + +# CR API: Check the contents of all current status events for one id from ECS +# [ EMPTY | ( )+ ] +# (Function for test scripts) +cr_api_check_all_ecs_events() { + __log_test_start $@ + + if [ $# -lt 2 ]; then + __print_err " [ EMPTY | ( )+ ]" $@ + return 1 + fi + + query="/get-all-events/"$2 + res="$(__do_curl_to_api CR GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + __log_test_fail_status_code $1 $status + return 1 + fi + + if [ $# -gt 2 ]; then + body=${res:0:${#res}-3} + if [ $# -eq 3 ] && [ $3 == "EMPTY" ]; then + targetJson="[" + else + targetJson="[" + arr=(${@:3}) + + for ((i=0; i<$(($#-2)); i=i+1)); do + + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + targetJson=$targetJson"{\"eiJobStatus\":\"${arr[$i]}\"}" + done + fi + + targetJson=$targetJson"]" + echo "TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + __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 diff --git a/test/common/do_curl_function.sh b/test/common/do_curl_function.sh index ac945fe0..1cff7a1f 100755 --- a/test/common/do_curl_function.sh +++ b/test/common/do_curl_function.sh @@ -33,6 +33,7 @@ # Env BODY contains the response body after the call # Any error will stop script execution # How to use in a test script: source this file into your bash test script to the make the function available. +# The function may create a dir 'tmp' for temporary files. do_curl() { echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD @@ -88,6 +89,7 @@ do_curl() { count=${RESULT:16:${#RESULT}} #Find dir of the common dir DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + mkdir -p tmp echo $body > ./tmp/.tmp.json res=$(python ${DIR}/count_json_elements.py ./tmp/.tmp.json) if [ $res -eq $count ]; then diff --git a/test/common/ecs_api_functions.sh b/test/common/ecs_api_functions.sh index b76d43b7..56c2a2e1 100644 --- a/test/common/ecs_api_functions.sh +++ b/test/common/ecs_api_functions.sh @@ -21,14 +21,24 @@ . ../common/api_curl.sh -############### EXPERIMENTAL ############# +# Tests if a variable value in the ECS is equal to a target value and and optional timeout. +# Arg: - This test set pass or fail depending on if the variable is +# equal to the target or not. +# Arg: - This test waits up to the timeout seconds +# before setting pass or fail depending on if the variable value becomes equal to the target +# value or not. +# (Function for test scripts) +ecs_equal() { + if [ $# -eq 2 ] || [ $# -eq 3 ]; then + __var_test ECS "$LOCALHOST$ECS_EXTERNAL_PORT/" $1 "=" $2 $3 + else + __print_err "Wrong args to ecs_equal, needs two or three args: [ timeout ]" $@ + fi +} -########################################## -###### Mainly only function skeletons #### -########################################## ########################################## -### A1-E Enrichment Data Consumer API #### +######### A1-E Enrichment API ########## ########################################## #Function prefix: ecs_api_a1 @@ -37,9 +47,7 @@ # args (flat uri structure): |NOTYPE |NOOWNER [ EMPTY | + ] # (Function for test scripts) ecs_api_a1_get_job_ids() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ -z "$FLAT_A1_EI" ]; then # Valid number of parameters 4,5,6 etc @@ -76,9 +84,7 @@ ecs_api_a1_get_job_ids() { status=${res:${#res}-3} 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 @@ -100,15 +106,12 @@ ecs_api_a1_get_job_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 fi - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN + __log_test_pass return 0 } @@ -116,9 +119,7 @@ ecs_api_a1_get_job_ids() { # args: [] # (Function for test scripts) ecs_api_a1_get_type() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ $# -lt 2 ] || [ $# -gt 3 ]; then __print_err " []" $@ @@ -130,9 +131,7 @@ ecs_api_a1_get_type() { status=${res:${#res}-3} 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 @@ -141,9 +140,7 @@ ecs_api_a1_get_type() { if [ -f $3 ]; then schema=$(cat $3) else - echo -e $RED" FAIL. Schema file "$3", does not exist"$ERED - ((RES_FAIL++)) - __check_stop_at_error + __log_test_fail_general "Schema file "$3", does not exist" return 1 fi if [ -z "$FLAT_A1_EI" ]; then @@ -155,15 +152,12 @@ ecs_api_a1_get_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 } @@ -171,9 +165,7 @@ ecs_api_a1_get_type() { # args: [ (EMPTY | []+) ] # (Function for test scripts) ecs_api_a1_get_type_ids() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ $# -lt 1 ]; then __print_err " [ (EMPTY | []+) ]" $@ @@ -185,9 +177,7 @@ ecs_api_a1_get_type_ids() { status=${res:${#res}-3} 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 if [ $# -gt 1 ]; then @@ -206,15 +196,12 @@ ecs_api_a1_get_type_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 fi - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN + __log_test_pass return 0 } @@ -223,9 +210,7 @@ ecs_api_a1_get_type_ids() { # args (flat uri structure): [] # (Function for test scripts) ecs_api_a1_get_job_status() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ -z "$FLAT_A1_EI" ]; then if [ $# -ne 3 ] && [ $# -ne 4 ]; then @@ -239,9 +224,7 @@ ecs_api_a1_get_job_status() { status=${res:${#res}-3} 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 if [ $# -eq 4 ]; then @@ -251,9 +234,7 @@ ecs_api_a1_get_job_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 @@ -270,9 +251,7 @@ ecs_api_a1_get_job_status() { status=${res:${#res}-3} 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 if [ $# -eq 3 ]; then @@ -282,16 +261,13 @@ ecs_api_a1_get_job_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 fi - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN + __log_test_pass return 0 } @@ -300,9 +276,7 @@ ecs_api_a1_get_job_status() { # args (flat uri structure): [ ] # (Function for test scripts) ecs_api_a1_get_job() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ -z "$FLAT_A1_EI" ]; then if [ $# -ne 3 ] && [ $# -ne 6 ]; then @@ -322,9 +296,7 @@ ecs_api_a1_get_job() { status=${res:${#res}-3} 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 @@ -336,9 +308,7 @@ ecs_api_a1_get_job() { jobfile=$(cat $6) jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") else - echo -e $RED" FAIL. Job template file "$6", does not exist"$ERED - ((RES_FAIL++)) - __check_stop_at_error + _log_test_fail_general "Job template file "$6", does not exist" return 1 fi targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}" @@ -346,9 +316,7 @@ ecs_api_a1_get_job() { 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 @@ -360,26 +328,21 @@ ecs_api_a1_get_job() { jobfile=$(cat $7) jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g") else - echo -e $RED" FAIL. Job template file "$6", does not exist"$ERED - ((RES_FAIL++)) - __check_stop_at_error + _log_test_fail_general "Job template file "$6", does not exist" return 1 fi - targetJson="{\"eiTypeId\": \"$3\", \"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}" + targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}" echo " TARGET JSON: $targetJson" >> $HTTPLOG 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 fi - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN + __log_test_pass return 0 } @@ -388,9 +351,7 @@ ecs_api_a1_get_job() { # args (flat uri structure): # (Function for test scripts) ecs_api_a1_delete_job() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ -z "$FLAT_A1_EI" ]; then if [ $# -ne 3 ]; then @@ -411,14 +372,11 @@ ecs_api_a1_delete_job() { status=${res:${#res}-3} 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 } @@ -427,9 +385,7 @@ ecs_api_a1_delete_job() { # args (flat uri structure): # (Function for test scripts) ecs_api_a1_put_job() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ -z "$FLAT_A1_EI" ]; then if [ $# -lt 6 ]; then @@ -440,9 +396,7 @@ ecs_api_a1_put_job() { jobfile=$(cat $6) jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") else - echo -e $RED" FAIL. Job template file "$6", does not exist"$ERED - ((RES_FAIL++)) - __check_stop_at_error + _log_test_fail_general "Job template file "$6", does not exist" return 1 fi @@ -461,9 +415,7 @@ ecs_api_a1_put_job() { jobfile=$(cat $7) jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g") else - echo -e $RED" FAIL. Job template file "$7", does not exist"$ERED - ((RES_FAIL++)) - __check_stop_at_error + _log_test_fail_general "Job template file "$7", does not exist" return 1 fi @@ -478,14 +430,11 @@ ecs_api_a1_put_job() { status=${res:${#res}-3} 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 } @@ -499,9 +448,7 @@ ecs_api_a1_put_job() { # args: [ EMPTY | +] # (Function for test scripts) ecs_api_edp_get_type_ids() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ $# -lt 1 ]; then __print_err " [ EMPTY | +]" $@ @@ -513,9 +460,7 @@ ecs_api_edp_get_type_ids() { status=${res:${#res}-3} 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 @@ -535,58 +480,74 @@ ecs_api_edp_get_type_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 fi - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN + __log_test_pass return 0 } # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status -# args: [] +# args: [ []] # (Function for test scripts) ecs_api_edp_get_producer_status() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ - if [ $# -lt 2 ] || [ $# -gt 3 ]; then - __print_err " []" $@ + if [ $# -lt 2 ] || [ $# -gt 4 ]; then + __print_err " [ []]" $@ return 1 fi query="/ei-producer/v1/eiproducers/$2/status" - res="$(__do_curl_to_api ECS GET $query)" - status=${res:${#res}-3} + start=$SECONDS + for (( ; ; )); do + res="$(__do_curl_to_api ECS GET $query)" + status=${res:${#res}-3} - if [ $status -ne $1 ]; then - echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED - ((RES_FAIL++)) - __check_stop_at_error - return 1 - fi - if [ $# -eq 3 ]; then - body=${res:0:${#res}-3} - targetJson="{\"operational_state\": \"$3\"}" - echo " TARGET JSON: $targetJson" >> $HTTPLOG - res=$(python3 ../common/compare_json.py "$targetJson" "$body") + if [ $# -eq 4 ]; then + duration=$((SECONDS-start)) + echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}" + if [ $duration -gt $4 ]; then + echo "" + duration=-1 #Last iteration + fi + else + duration=-1 #single test, no wait + fi - if [ $res -ne 0 ]; then - echo -e $RED" FAIL, returned body not correct"$ERED - ((RES_FAIL++)) - __check_stop_at_error - return 1 + if [ $status -ne $1 ]; then + if [ $duration -eq -1 ]; then + __log_test_fail_status_code $1 $status + return 1 + fi fi - fi + if [ $# -ge 3 ] && [ $status -eq $1 ]; then + body=${res:0:${#res}-3} + targetJson="{\"operational_state\": \"$3\"}" + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN - return 0 + if [ $res -ne 0 ]; then + if [ $duration -eq -1 ]; then + __log_test_fail_body + return 1 + fi + else + duration=-1 #Goto pass + fi + fi + if [ $duration -eq -1 ]; then + if [ $# -eq 4 ]; then + echo "" + fi + __log_test_pass + return 0 + else + sleep 1 + fi + done } @@ -594,9 +555,7 @@ ecs_api_edp_get_producer_status() { # args: [ EMPTY | +] # (Function for test scripts) ecs_api_edp_get_producer_ids() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ $# -lt 1 ]; then __print_err " [ EMPTY | +]" $@ @@ -608,9 +567,7 @@ ecs_api_edp_get_producer_ids() { status=${res:${#res}-3} 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 @@ -632,15 +589,12 @@ ecs_api_edp_get_producer_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 fi - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN + __log_test_pass return 0 } @@ -648,9 +602,7 @@ ecs_api_edp_get_producer_ids() { # args: [ (EMPTY | []+)] # (Function for test scripts) ecs_api_edp_get_type() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ paramError=1 if [ $# -eq 2 ]; then @@ -669,9 +621,7 @@ ecs_api_edp_get_type() { status=${res:${#res}-3} 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 if [ $# -gt 3 ]; then @@ -680,9 +630,7 @@ ecs_api_edp_get_type() { if [ -f $3 ]; then schema=$(cat $3) else - echo -e $RED" FAIL. Job template file "$3", does not exist"$ERED - ((RES_FAIL++)) - __check_stop_at_error + __log_test_fail_general "Job template file "$3", does not exist" return 1 fi @@ -701,40 +649,35 @@ ecs_api_edp_get_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 } # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId} -# args: [ (EMPTY | [ ]+) ] +# args: [ (EMPTY | [ ]+) ] # (Function for test scripts) ecs_api_edp_get_producer() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ - #Possible arg count: 2, 6 7, 9, 11 etc + #Possible arg count: 2, 5 6, 8, 10 etc paramError=1 if [ $# -eq 2 ]; then paramError=0 fi - if [ $# -eq 6 ] && [ "$6" == "EMPTY" ]; then + if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then paramError=0 fi - variablecount=$(($#-5)) + variablecount=$(($#-4)) if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then paramError=0 fi if [ $paramError -ne 0 ]; then - __print_err " [ (NOID | [ ]+) ]" $@ + __print_err " [ (NOID | [ ]+) ]" $@ return 1 fi @@ -743,27 +686,23 @@ ecs_api_edp_get_producer() { status=${res:${#res}-3} 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 if [ $# -gt 2 ]; then body=${res:0:${#res}-3} targetJson="[" - if [ $# -gt 6 ]; then - arr=(${@:6}) - for ((i=0; i<$(($#-6)); i=i+2)); do + if [ $# -gt 5 ]; then + arr=(${@:5}) + for ((i=0; i<$(($#-5)); i=i+2)); do if [ "$targetJson" != "[" ]; then targetJson=$targetJson"," fi if [ -f ${arr[$i+1]} ]; then schema=$(cat ${arr[$i+1]}) else - echo -e $RED" FAIL. Schema file "${arr[$i+1]}", does not exist"$ERED - ((RES_FAIL++)) - __check_stop_at_error + _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist" return 1 fi @@ -772,21 +711,18 @@ ecs_api_edp_get_producer() { fi targetJson=$targetJson"]" if [ $# -gt 4 ]; then - targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_creation_callback_url\": \"$3\",\"ei_job_deletion_callback_url\": \"$4\",\"ei_producer_supervision_callback_url\": \"$5\"}" + targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}" fi echo " TARGET JSON: $targetJson" >> $HTTPLOG 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 } @@ -794,9 +730,7 @@ ecs_api_edp_get_producer() { # args: # (Function for test scripts) ecs_api_edp_delete_producer() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ $# -lt 2 ]; then __print_err " " $@ @@ -808,50 +742,43 @@ ecs_api_edp_delete_producer() { status=${res:${#res}-3} 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 } # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId} -# args: NOTYPE|[ ]+ +# args: NOTYPE|[ ]+ # (Function for test scripts) ecs_api_edp_put_producer() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ - #Valid number of parametrer 6,7,9,11, + #Valid number of parametrer 5,6,8,10, paramError=1 - if [ $# -eq 6 ] && [ "$6" == "NOTYPE" ]; then + if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then paramError=0 - elif [ $# -gt 6 ] && [ $(($#%2)) -eq 1 ]; then + elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then paramError=0 fi if [ $paramError -ne 0 ]; then - __print_err " [ ]+" $@ + __print_err " NOTYPE|[ ]+" $@ return 1 fi inputJson="[" - if [ $# -gt 6 ]; then - arr=(${@:6}) - for ((i=0; i<$(($#-6)); i=i+2)); do + if [ $# -gt 5 ]; then + arr=(${@:5}) + for ((i=0; i<$(($#-5)); i=i+2)); do if [ "$inputJson" != "[" ]; then inputJson=$inputJson"," fi if [ -f ${arr[$i+1]} ]; then schema=$(cat ${arr[$i+1]}) else - echo -e $RED" FAIL. Schema file "${arr[$i+1]}", does not exist"$ERED - ((RES_FAIL++)) - __check_stop_at_error + _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist" return 1 fi inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}" @@ -859,7 +786,7 @@ ecs_api_edp_put_producer() { fi inputJson="\"supported_ei_types\":"$inputJson"]" - inputJson=$inputJson",\"ei_job_creation_callback_url\": \"$3\",\"ei_job_deletion_callback_url\": \"$4\",\"ei_producer_supervision_callback_url\": \"$5\"" + inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"" inputJson="{"$inputJson"}" @@ -870,14 +797,11 @@ ecs_api_edp_put_producer() { status=${res:${#res}-3} 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 } @@ -885,9 +809,7 @@ ecs_api_edp_put_producer() { # args: (EMPTY | [ ]+) # (Function for test scripts) ecs_api_edp_get_producer_jobs() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ #Valid number of parameter 2,3,6,10 paramError=1 @@ -910,9 +832,7 @@ ecs_api_edp_get_producer_jobs() { res="$(__do_curl_to_api ECS GET $query)" status=${res:${#res}-3} 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 if [ $# -gt 2 ]; then @@ -928,9 +848,7 @@ ecs_api_edp_get_producer_jobs() { jobfile=$(cat ${arr[$i+3]}) jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g") else - echo -e $RED" FAIL. Job template file "${arr[$i+3]}", does not exist"$ERED - ((RES_FAIL++)) - __check_stop_at_error + _log_test_fail_general "Job template file "${arr[$i+3]}", does not exist" return 1 fi targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"ei_job_data\":$jobfile}" @@ -942,15 +860,12 @@ ecs_api_edp_get_producer_jobs() { 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 } @@ -964,16 +879,18 @@ ecs_api_edp_get_producer_jobs() { # args: # (Function for test scripts) ecs_api_service_status() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + __log_test_start $@ if [ $# -lt 1 ]; then __print_err " []*|NOID" $@ return 1 fi - - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN + res="$(__do_curl_to_api ECS GET /status)" + status=${res:${#res}-3} + if [ $status -ne $1 ]; then + __log_test_fail_status_code $1 $status + return 1 + fi + __log_test_pass return 0 } \ No newline at end of file diff --git a/test/common/prodstub_api_functions.sh b/test/common/prodstub_api_functions.sh index f30b8761..f974df7b 100644 --- a/test/common/prodstub_api_functions.sh +++ b/test/common/prodstub_api_functions.sh @@ -24,15 +24,14 @@ # Excute a curl cmd towards the prodstub simulator and check the response code. # args: TEST|CONF [] __execute_curl_to_prodstub() { - #echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG - echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S") + echo "(${BASH_LINENO[0]}) - ${TIMESTAMP}: ${FUNCNAME[0]}" $@ >> $HTTPLOG echo " CMD: $3" >> $HTTPLOG res="$($3)" echo " RESP: $res" >> $HTTPLOG retcode=$? if [ $retcode -ne 0 ]; then - echo " RETCODE: "$retcode - echo -e $RED" FAIL - fatal error when executing curl."$ERED + __log_conf_fail_general " Fatal error when executing curl, response: "$retcode return 1 fi status=${res:${#res}-3} @@ -43,18 +42,26 @@ __execute_curl_to_prodstub() { echo " TARGET JSON: $jobfile" >> $HTTPLOG res=$(python3 ../common/compare_json.py "$jobfile" "$body") if [ $res -ne 0 ]; then - echo -e $RED" FAIL, returned body not correct"$ERED - return 1 + if [ $1 == "TEST" ]; then + __log_test_fail_body + else + __log_conf_fail_body + fi + return 1 fi fi if [ $1 == "TEST" ]; then - echo -e $GREEN" PASS"$EGREEN + __log_test_pass else - echo -e $GREEN" OK"$EGREEN + __log_conf_ok fi return 0 fi - echo -e $RED" FAIL - expected http response: "$2" but got http response: "$status $ERED + if [ $1 == "TEST" ]; then + __log_test_fail_status_code $2 $status + else + __log_conf_fail_status_code $2 $status + fi return 1 } @@ -62,10 +69,8 @@ __execute_curl_to_prodstub() { # [] # (Function for test scripts) prodstub_arm_producer() { - echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD - echo "CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG + __log_conf_start $@ if [ $# -ne 2 ] && [ $# -ne 3 ]; then - ((RES_CONF_FAIL++)) __print_err " []" $@ return 1 fi @@ -76,21 +81,15 @@ prodstub_arm_producer() { fi __execute_curl_to_prodstub CONF $1 "$curlString" - retcode=$? - if [ $? -ne 0 ]; then - ((RES_CONF_FAIL++)) - fi - return $retcode + return $? } # Prodstub API: Set (or reset) response code job create # [] # (Function for test scripts) prodstub_arm_job_create() { - echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD - echo "CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG + __log_conf_start $@ if [ $# -ne 3 ] && [ $# -ne 4 ]; then - ((RES_CONF_FAIL++)) __print_err " []" $@ return 1 fi @@ -101,21 +100,15 @@ prodstub_arm_job_create() { fi __execute_curl_to_prodstub CONF $1 "$curlString" - retcode=$? - if [ $? -ne 0 ]; then - ((RES_CONF_FAIL++)) - fi - return $retcode + return $? } # Prodstub API: Set (or reset) response code job delete # [] # (Function for test scripts) prodstub_arm_job_delete() { - echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD - echo "CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG + __log_conf_start $@ if [ $# -ne 3 ] && [ $# -ne 4 ]; then - ((RES_CONF_FAIL++)) __print_err " []" $@ return 1 fi @@ -126,21 +119,15 @@ prodstub_arm_job_delete() { fi __execute_curl_to_prodstub CONF $1 "$curlString" - retcode=$? - if [ $? -ne 0 ]; then - ((RES_CONF_FAIL++)) - fi - return $retcode + return $? } # Prodstub API: Arm a type of a producer # # (Function for test scripts) prodstub_arm_type() { - echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD - echo "CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG + __log_conf_start $@ if [ $# -ne 3 ]; then - ((RES_CONF_FAIL++)) __print_err " " $@ return 1 fi @@ -148,21 +135,15 @@ prodstub_arm_type() { curlString="curl -X PUT -skw %{http_code} $PROD_STUB_LOCALHOST/arm/type/$2/$3" __execute_curl_to_prodstub CONF $1 "$curlString" - retcode=$? - if [ $? -ne 0 ]; then - ((RES_CONF_FAIL++)) - fi - return $retcode + return $? } # Prodstub API: Disarm a type in a producer # # (Function for test scripts) prodstub_disarm_type() { - echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD - echo "CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG + __log_conf_start $@ if [ $# -ne 3 ]; then - ((RES_CONF_FAIL++)) __print_err " " $@ return 1 fi @@ -170,21 +151,15 @@ prodstub_disarm_type() { curlString="curl -X DELETE -skw %{http_code} $PROD_STUB_LOCALHOST/arm/type/$2/$3" __execute_curl_to_prodstub CONF $1 "$curlString" - retcode=$? - if [ $? -ne 0 ]; then - ((RES_CONF_FAIL++)) - fi - return $retcode + return $? } # Prodstub API: Get job data for a job and compare with a target job json # # (Function for test scripts) prodstub_check_jobdata() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG + __log_test_start $@ if [ $# -ne 6 ]; then - ((RES_FAIL++)) __print_err " " $@ return 1 fi @@ -192,7 +167,7 @@ prodstub_check_jobdata() { jobfile=$(cat $6) jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") else - echo -e $RED" FAIL. Template file "$6" for jobdata, does not exist"$ERED + _log_test_fail_general "Template file "$6" for jobdata, does not exist" return 1 fi targetJson="{\"ei_job_identity\":\"$3\",\"ei_type_identity\":\"$4\",\"target_uri\":\"$5\",\"ei_job_data\":$jobfile}" @@ -202,11 +177,22 @@ prodstub_check_jobdata() { curlString="curl -X GET -skw %{http_code} $PROD_STUB_LOCALHOST/jobdata/$2/$3" __execute_curl_to_prodstub TEST $1 "$curlString" $file - retcode=$? - if [ $? -ne 0 ]; then - ((RES_FAIL++)) - fi - return $retcode + return $? +} + +# Prodstub API: Delete the job data +# +# (Function for test scripts) +prodstub_delete_jobdata() { + __log_conf_start + if [ $# -ne 3 ]; then + __print_err " " $@ + return 1 + fi + curlString="curl -X DELETE -skw %{http_code} $PROD_STUB_LOCALHOST/jobdata/$2/$3" + + __execute_curl_to_prodstub CONF $1 "$curlString" + return $? } # Tests if a variable value in the prod stub is equal to a target value and and optional timeout. @@ -220,7 +206,6 @@ prodstub_equal() { if [ $# -eq 2 ] || [ $# -eq 3 ]; then __var_test "PRODSTUB" "$LOCALHOST$PROD_STUB_EXTERNAL_PORT/counter/" $1 "=" $2 $3 else - ((RES_CONF_FAIL++)) __print_err "Wrong args to prodstub_equal, needs two or three args: [ timeout ]" $@ fi } \ No newline at end of file diff --git a/test/common/ricsimulator_api_functions.sh b/test/common/ricsimulator_api_functions.sh index 56f968ee..2a68aa0e 100644 --- a/test/common/ricsimulator_api_functions.sh +++ b/test/common/ricsimulator_api_functions.sh @@ -55,12 +55,10 @@ __execute_curl_to_sim() { sim_equal() { if [ $# -eq 3 ] || [ $# -eq 4 ]; then - app=$1 - port=$(__find_sim_port $app) - __var_test $app "$RIC_SIM_LOCALHOST$port/counter/" $2 "=" $3 $4 + port=$(__find_sim_port $1) + __var_test $1 "$RIC_SIM_LOCALHOST$port/counter/" $2 "=" $3 $4 return 0 else - ((RES_CONF_FAIL++)) __print_err "needs three or four args: [ timeout ]" return 1 fi @@ -72,13 +70,11 @@ sim_equal() { sim_print() { if [ $# != 2 ]; then - ((RES_CONF_FAIL++)) __print_err "need two args, " $@ exit 1 fi - app=$1 - port=$(__find_sim_port $app) - echo -e $BOLD"INFO(${BASH_LINENO[0]}): $app, $2 = $(__do_curl $RIC_SIM_LOCALHOST$port/counter/$2)"$EBOLD + port=$(__find_sim_port $1) + echo -e $BOLD"INFO(${BASH_LINENO[0]}): $1, $2 = $(__do_curl $RIC_SIM_LOCALHOST$port/counter/$2)"$EBOLD } # Tests if a variable value in the RIC simulator contains the target string and and optional timeout @@ -91,12 +87,10 @@ sim_print() { sim_contains_str() { if [ $# -eq 3 ] || [ $# -eq 4 ]; then - app=$1 - port=$(__find_sim_port $app) - __var_test $app "$RIC_SIM_LOCALHOST$port/counter/" $2 "contain_str" $3 $4 + port=$(__find_sim_port $1) + __var_test $1 "$RIC_SIM_LOCALHOST$port/counter/" $2 "contain_str" $3 $4 return 0 else - ((RES_CONF_FAIL++)) __print_err "needs three or four args: [ timeout ]" return 1 fi @@ -106,17 +100,13 @@ sim_contains_str() { # args: # (Function for test scripts) sim_put_policy_type() { - echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + __log_conf_start $@ if [ $# -ne 4 ]; then - ((RES_CONF_FAIL++)) __print_err " " $@ return 1 fi - app=$2 - res=$(__find_sim_port $app) - + res=$(__find_sim_port $2) curlString="curl -X PUT -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/policytype?id="$3" -H Content-Type:application/json --data-binary @"$4 - __execute_curl_to_sim $1 "$curlString" return $? } @@ -125,17 +115,13 @@ sim_put_policy_type() { # # (Function for test scripts) sim_delete_policy_type() { - echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + __log_conf_start $@ if [ $# -ne 3 ]; then - ((RES_CONF_FAIL++)) __print_err " " $@ return 1 fi - app=$2 - res=$(__find_sim_port $app) - + res=$(__find_sim_port $2) curlString="curl -X DELETE -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/policytype?id="$3 - __execute_curl_to_sim $1 "$curlString" return $? } @@ -144,17 +130,13 @@ sim_delete_policy_type() { # # (Function for test scripts) sim_post_delete_instances() { - echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + __log_conf_start $@ if [ $# -ne 2 ]; then - ((RES_CONF_FAIL++)) __print_err " " $@ return 1 fi - app=$2 - res=$(__find_sim_port $app) - + res=$(__find_sim_port $2) curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/deleteinstances" - __execute_curl_to_sim $1 "$curlString" return $? } @@ -163,17 +145,13 @@ sim_post_delete_instances() { # # (Function for test scripts) sim_post_delete_all() { - echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + __log_conf_start $@ if [ $# -ne 3 ]; then - ((RES_CONF_FAIL++)) __print_err " " $@ return 1 fi - app=$2 - res=$(__find_sim_port $app) - + res=$(__find_sim_port $2) curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/deleteall" - __execute_curl_to_sim $1 "$curlString" return $? } @@ -182,20 +160,16 @@ sim_post_delete_all() { # [] # (Function for test scripts) sim_post_forcedresponse() { - echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + __log_conf_start $@ if [ $# -ne 3 ]; then - ((RES_CONF_FAIL++)) __print_err " " $@ return 1 fi - app=$2 - res=$(__find_sim_port $app) - + res=$(__find_sim_port $2) curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/forceresponse" if [ $# -eq 3 ]; then curlString=$curlString"?code="$3 fi - __execute_curl_to_sim $1 "$curlString" return $? } @@ -204,20 +178,16 @@ sim_post_forcedresponse() { # [] # (Function for test scripts) sim_post_forcedelay() { - echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + __log_conf_start $@ if [ $# -ne 3 ]; then - ((RES_CONF_FAIL++)) __print_err " []" $@ return 1 fi - app=$2 - res=$(__find_sim_port $app) - + res=$(__find_sim_port $2) curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST$res/forcedelay" if [ $# -eq 3 ]; then curlString=$curlString"?delay="$3 fi - __execute_curl_to_sim $1 "$curlString" return $? } \ No newline at end of file diff --git a/test/common/test_env-onap-guilin.sh b/test/common/test_env-onap-guilin.sh index 51eab698..1dc2b363 100644 --- a/test/common/test_env-onap-guilin.sh +++ b/test/common/test_env-onap-guilin.sh @@ -16,8 +16,9 @@ # limitations under the License. # ============LICENSE_END================================================= # - +#Profile for ONAP guilin release TEST_ENV_PROFILE="ONAP-GUILIN" +NEXUS_PROXY_REPO="nexus3.onap.org:10001/" # Set up the image and tags for the test. Do not add the image tag to the image names. @@ -28,7 +29,7 @@ TEST_ENV_PROFILE="ONAP-GUILIN" # Tag for guilin branch # Remote Policy Agent image and tag POLICY_AGENT_REMOTE_IMAGE="nexus3.onap.org:10003/onap/ccsdk-oran-a1policymanagementservice" -POLICY_AGENT_REMOTE_IMAGE_TAG="1.0.1-SNAPSHOT" +POLICY_AGENT_REMOTE_IMAGE_TAG="1.0.2-SNAPSHOT" # Control Panel remote image and tag @@ -42,7 +43,7 @@ SDNC_A1_CONTROLLER_REMOTE_IMAGE_TAG="2.0.2-STAGING-latest" #SDNC DB remote image and tag -SDNC_DB_REMOTE_IMAGE="mysql/mysql-server" +SDNC_DB_REMOTE_IMAGE=$NEXUS_PROXY_REPO"mysql/mysql-server" SDNC_DB_REMOTE_IMAGE_TAG="5.6" #No local image for DB, remote image always used @@ -53,7 +54,7 @@ RIC_SIM_REMOTE_IMAGE_TAG="2.0.0" #Consul remote image and tag -CONSUL_REMOTE_IMAGE="consul" +CONSUL_REMOTE_IMAGE=$NEXUS_PROXY_REPO"consul" CONSUL_REMOTE_IMAGE_TAG="1.7.2" #No local image for Consul, remote image always used diff --git a/test/common/test_env-onap-master.sh b/test/common/test_env-onap-master.sh index f97309c2..29647bd2 100644 --- a/test/common/test_env-onap-master.sh +++ b/test/common/test_env-onap-master.sh @@ -16,8 +16,9 @@ # limitations under the License. # ============LICENSE_END================================================= # - +#Profile for ONAP master TEST_ENV_PROFILE="ONAP-MASTER" +NEXUS_PROXY_REPO="nexus3.onap.org:10001/" # Set up the image and tags for the test. Do not add the image tag to the image names. @@ -53,7 +54,7 @@ SDNC_A1_CONTROLLER_REMOTE_IMAGE_TAG="2.1.0-STAGING-latest" #SDNC DB remote image and tag -SDNC_DB_REMOTE_IMAGE="mysql/mysql-server" +SDNC_DB_REMOTE_IMAGE=$NEXUS_PROXY_REPO"mysql/mysql-server" SDNC_DB_REMOTE_IMAGE_TAG="5.6" #No local image for DB, remote image always used @@ -66,7 +67,7 @@ RIC_SIM_REMOTE_IMAGE_TAG="2.1.0" #Consul remote image and tag -CONSUL_REMOTE_IMAGE="consul" +CONSUL_REMOTE_IMAGE=$NEXUS_PROXY_REPO"consul" CONSUL_REMOTE_IMAGE_TAG="1.7.2" #No local image for Consul, remote image always used @@ -100,7 +101,7 @@ export POLICY_AGENT_INTERNAL_PORT=8081 # Policy Agent c export POLICY_AGENT_EXTERNAL_SECURE_PORT=8433 # Policy Agent container external secure port (host -> container) export POLICY_AGENT_INTERNAL_SECURE_PORT=8433 # Policy Agent container internal secure port (container -> container) export POLICY_AGENT_APIS="V1 V2" # Supported northbound api versions -export PMS_VERSION="V2" +export PMS_VERSION="V2" # Tested version of northbound API export POLICY_AGENT_APP_NAME="policy-agent" # Name for Policy Agent container POLICY_AGENT_LOGPATH="/var/log/policy-agent/application.log" # Path the application log in the Policy Agent container diff --git a/test/common/test_env-oran-master.sh b/test/common/test_env-oran-master.sh index 0077ef09..c0e28f6b 100755 --- a/test/common/test_env-oran-master.sh +++ b/test/common/test_env-oran-master.sh @@ -16,8 +16,9 @@ # limitations under the License. # ============LICENSE_END================================================= # - +#Profile for ORAN master TEST_ENV_PROFILE="ORAN-MASTER" +NEXUS_PROXY_REPO="nexus3.onap.org:10001/" # Set up the image and tags for the test. Do not add the image tag to the image names. @@ -56,7 +57,7 @@ SDNC_A1_CONTROLLER_REMOTE_IMAGE_TAG="2.1.0" #SDNC DB remote image and tag -SDNC_DB_REMOTE_IMAGE="mysql/mysql-server" +SDNC_DB_REMOTE_IMAGE=$NEXUS_PROXY_REPO"mysql/mysql-server" SDNC_DB_REMOTE_IMAGE_TAG="5.6" #No local image for DB, remote image always used @@ -66,11 +67,11 @@ RIC_SIM_LOCAL_IMAGE="o-ran-sc/a1-simulator" RIC_SIM_LOCAL_IMAGE_TAG="latest" # Near RT RIC Simulator remote image and tag RIC_SIM_REMOTE_IMAGE="nexus3.o-ran-sc.org:10004/o-ran-sc/a1-simulator" -RIC_SIM_REMOTE_IMAGE_TAG="2.0.0" +RIC_SIM_REMOTE_IMAGE_TAG="2.1.0" #Consul remote image and tag -CONSUL_REMOTE_IMAGE="consul" +CONSUL_REMOTE_IMAGE=$NEXUS_PROXY_REPO"consul" CONSUL_REMOTE_IMAGE_TAG="1.7.2" #No local image for Consul, remote image always used @@ -103,7 +104,8 @@ export POLICY_AGENT_EXTERNAL_PORT=8081 # Policy Agent c export POLICY_AGENT_INTERNAL_PORT=8081 # Policy Agent container internal port (container -> container) export POLICY_AGENT_EXTERNAL_SECURE_PORT=8433 # Policy Agent container external secure port (host -> container) export POLICY_AGENT_INTERNAL_SECURE_PORT=8433 # Policy Agent container internal secure port (container -> container) -export POLICY_AGENT_APIS="V1" # Supported northbound api versions +export POLICY_AGENT_APIS="V1 V2" # Supported northbound api versions +export PMS_VERSION="V2" # Tested version of northbound API export POLICY_AGENT_APP_NAME="policy-agent" # Name for Policy Agent container POLICY_AGENT_LOGPATH="/var/log/policy-agent/application.log" # Path the application log in the Policy Agent container diff --git a/test/common/testcase_common.sh b/test/common/testcase_common.sh index 3ed51c91..dd9e57ac 100755 --- a/test/common/testcase_common.sh +++ b/test/common/testcase_common.sh @@ -159,6 +159,94 @@ RES_DEVIATION=0 DEVIATION_FILE=".tmp_deviations" rm $DEVIATION_FILE &> /dev/null + +# Trap "command not found" and make the script fail +trap_fnc() { + + if [ $? -eq 127 ]; then + echo -e $RED"Function not found, set script to FAIL"$ERED + ((RES_CONF_FAIL++)) + fi +} +trap trap_fnc ERR + +# Counter for tests +TEST_SEQUENCE_NR=1 + +__log_test_start() { + TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S") + echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${FUNCNAME[1]}" $@ $EBOLD + echo "TEST $TEST_SEQUENCE_NR - ${TIMESTAMP}: (${BASH_LINENO[1]}): ${FUNCNAME[1]}" $@ >> $HTTPLOG + ((RES_TEST++)) + ((TEST_SEQUENCE_NR++)) +} + +__log_test_fail_general() { + echo -e $RED" FAIL."$1 $ERED + ((RES_FAIL++)) + __check_stop_at_error +} + +__log_test_fail_status_code() { + echo -e $RED" FAIL. Exepected status "$1", got "$2 $3 $ERED + ((RES_FAIL++)) + __check_stop_at_error +} + +__log_test_fail_body() { + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error +} + +__log_test_fail_not_supported() { + echo -e $RED" FAIL, function not supported"$ERED + ((RES_FAIL++)) + __check_stop_at_error +} + +__log_test_pass() { + if [ $# -gt 0 ]; then + echo $@ + fi + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN +} + +#Counter for configurations +CONF_SEQUENCE_NR=1 +__log_conf_start() { + TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S") + echo -e $BOLD"CONF $CONF_SEQUENCE_NR (${BASH_LINENO[1]}): "${FUNCNAME[1]} $@ $EBOLD + echo "CONF $CONF_SEQUENCE_NR - ${TIMESTAMP}: (${BASH_LINENO[1]}): "${FUNCNAME[1]} $@ >> $HTTPLOG + ((CONF_SEQUENCE_NR++)) +} + +__log_conf_fail_general() { + echo -e $RED" FAIL."$1 $ERED + ((RES_CONF_FAIL++)) + __check_stop_at_error +} + +__log_conf_fail_status_code() { + echo -e $RED" FAIL. Exepected status "$1", got "$2 $3 $ERED + ((RES_CONF_FAIL++)) + __check_stop_at_error +} + +__log_conf_fail_body() { + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_CONF_FAIL++)) + __check_stop_at_error +} + +__log_conf_ok() { + if [ $# -gt 0 ]; then + echo $@ + fi + echo -e $GREEN" OK"$EGREEN +} + #Var for measuring execution time TCTEST_START=$SECONDS @@ -691,7 +779,7 @@ if [ $? -eq 0 ]; then cd $curdir cd ../mrstub echo " Building mrstub image: $MRSTUB_LOCAL_IMAGE:$MRSTUB_LOCAL_IMAGE_TAG" - docker build -t $MRSTUB_LOCAL_IMAGE . &> .dockererr + docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $MRSTUB_LOCAL_IMAGE . &> .dockererr if [ $? -eq 0 ]; then echo -e $GREEN" Build Ok"$EGREEN else @@ -710,7 +798,7 @@ __check_included_image 'CR' if [ $? -eq 0 ]; then cd ../cr echo " Building Callback Receiver image: $CR_LOCAL_IMAGE:$CR_IMAGE_TAG" - docker build -t $CR_LOCAL_IMAGE . &> .dockererr + docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $CR_LOCAL_IMAGE . &> .dockererr if [ $? -eq 0 ]; then echo -e $GREEN" Build Ok"$EGREEN else @@ -729,7 +817,7 @@ __check_included_image 'PRODSTUB' if [ $? -eq 0 ]; then cd ../prodstub echo " Building Producer stub image: $PROD_STUB_LOCAL_IMAGE:$PROD_STUB_LOCAL_IMAGE_TAG" - docker build -t $PROD_STUB_LOCAL_IMAGE . &> .dockererr + docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $PROD_STUB_LOCAL_IMAGE . &> .dockererr if [ $? -eq 0 ]; then echo -e $GREEN" Build Ok"$EGREEN else @@ -1066,7 +1154,8 @@ clean_containers() { if [ $? -eq 0 ]; then if [ $CONTRS -ne 0 ]; then echo -e $RED"Containers running, may cause distubance to the test case"$ERED - docker ps -a + docker ps -a | indent1 + echo "" fi fi } @@ -1112,6 +1201,7 @@ __print_err() { if [ $# -gt 1 ]; then echo -e $RED" Got: "${FUNCNAME[1]} ${@:2} $ERED fi + ((RES_CONF_FAIL++)) } @@ -1482,7 +1572,8 @@ start_consul_cbs() { ########################### use_simulator_http() { - echo -e "Using $BOLD http $EBOLD towards the simulators" + echo -e $BOLD"RICSIM protocol setting"$EBOLD + echo -e " Using $BOLD http $EBOLD towards the simulators" export RIC_SIM_HTTPX="http" export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:" export RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT @@ -1490,7 +1581,8 @@ use_simulator_http() { } use_simulator_https() { - echo -e "Using $BOLD https $EBOLD towards the simulators" + echo -e $BOLD"RICSIM protocol setting"$EBOLD + echo -e " Using $BOLD https $EBOLD towards the simulators" export RIC_SIM_HTTPX="https" export RIC_SIM_LOCALHOST=$RIC_SIM_HTTPX"://localhost:" export RIC_SIM_PORT=$RIC_SIM_INTERNAL_SECURE_PORT @@ -1611,7 +1703,8 @@ start_sdnc() { } use_sdnc_http() { - echo -e "Using $BOLD http $EBOLD towards SDNC" + echo -e $BOLD"SDNC protocol setting"$EBOLD + echo -e " Using $BOLD http $EBOLD towards SDNC" export SDNC_HTTPX="http" export SDNC_PORT=$SDNC_INTERNAL_PORT export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT @@ -1619,7 +1712,8 @@ use_sdnc_http() { } use_sdnc_https() { - echo -e "Using $BOLD https $EBOLD towards SDNC" + echo -e $BOLD"SDNC protocol setting"$EBOLD + echo -e " Using $BOLD https $EBOLD towards SDNC" export SDNC_HTTPX="https" export SDNC_PORT=$SDNC_INTERNAL_SECURE_PORT export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_SECURE_PORT @@ -1647,7 +1741,8 @@ start_mr() { } use_mr_http() { - echo -e "Using $BOLD http $EBOLD towards MR" + echo -e $BOLD"MR protocol setting"$EBOLD + echo -e " Using $BOLD http $EBOLD towards MR" export MR_HTTPX="http" export MR_PORT=$MR_INTERNAL_PORT export MR_LOCAL_PORT=$MR_EXTERNAL_PORT @@ -1655,7 +1750,8 @@ use_mr_http() { } use_mr_https() { - echo -e "Using $BOLD https $EBOLD towards MR" + echo -e $BOLD"MR protocol setting"$EBOLD + echo -e " Using $BOLD https $EBOLD towards MR" export MR_HTTPX="https" export MR_PORT=$MR_INTERNAL_SECURE_PORT export MR_LOCAL_PORT=$MR_EXTERNAL_SECURE_PORT @@ -1684,7 +1780,8 @@ start_cr() { } use_cr_http() { - echo -e "Using $BOLD http $EBOLD towards CR" + echo -e $BOLD"CR protocol setting"$EBOLD + echo -e " Using $BOLD http $EBOLD towards CR" export CR_HTTPX="http" export CR_PORT=$CR_INTERNAL_PORT export CR_LOCAL_PORT=$CR_EXTERNAL_PORT @@ -1693,7 +1790,8 @@ use_cr_http() { } use_cr_https() { - echo -e "Using $BOLD https $EBOLD towards CR" + echo -e $BOLD"CR protocol setting"$EBOLD + echo -e " Using $BOLD https $EBOLD towards CR" export CR_HTTPX="https" export CR_PORT=$CR_INTERNAL_SECURE_PORT export CR_LOCAL_PORT=$CR_EXTERNAL_SECURE_PORT @@ -1722,7 +1820,8 @@ start_prod_stub() { } use_prod_stub_http() { - echo -e "Using $BOLD http $EBOLD towards Producer stub" + echo -e $BOLD"Producer stub protocol setting"$EBOLD + echo -e " Using $BOLD http $EBOLD towards Producer stub" export PROD_STUB_HTTPX="http" export PROD_STUB_PORT=$PROD_STUB_INTERNAL_PORT export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_PORT @@ -1731,7 +1830,8 @@ use_prod_stub_http() { } use_prod_stub_https() { - echo -e "Using $BOLD https $EBOLD towards Producer stub" + echo -e $BOLD"Producer stub protocol setting"$EBOLD + echo -e " Using $BOLD https $EBOLD towards Producer stub" export PROD_STUB_HTTPX="https" export PROD_STUB_PORT=$PROD_STUB_INTERNAL_SECURE_PORT export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_SECURE_PORT @@ -1780,7 +1880,8 @@ start_policy_agent() { # args: - # (Function for test scripts) use_agent_rest_http() { - echo -e "Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards the agent" + echo -e $BOLD"Agent protocol setting"$EBOLD + echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards the agent" export ADAPTER=$RESTBASE echo "" } @@ -1789,7 +1890,8 @@ use_agent_rest_http() { # args: - # (Function for test scripts) use_agent_rest_https() { - echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent" + echo -e $BOLD"Agent protocol setting"$EBOLD + echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent" export ADAPTER=$RESTBASE_SECURE echo "" return 0 @@ -1799,7 +1901,8 @@ use_agent_rest_https() { # args: - # (Function for test scripts) use_agent_dmaap_http() { - echo -e "Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent" + echo -e $BOLD"Agent dmaap protocol setting"$EBOLD + echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent" export ADAPTER=$DMAAPBASE echo "" return 0 @@ -1809,7 +1912,8 @@ use_agent_dmaap_http() { # args: - # (Function for test scripts) use_agent_dmaap_https() { - echo -e "Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent" + echo -e $BOLD"Agent dmaap protocol setting"$EBOLD + echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent" export ADAPTER=$DMAAPBASE_SECURE echo "" return 0 @@ -1819,7 +1923,7 @@ use_agent_dmaap_https() { # args: - # (Function for test scripts) set_agent_debug() { - echo -e $BOLD"Setting agent debug"$EBOLD + echo -e $BOLD"Setting agent debug logging"$EBOLD actuator="/actuator/loggers/org.oransc.policyagent" if [[ $POLICY_AGENT_IMAGE = *"onap"* ]]; then actuator="/actuator/loggers/org.onap.ccsdk.oran.a1policymanagementservice" @@ -1839,7 +1943,7 @@ set_agent_debug() { # args: - # (Function for test scripts) set_agent_trace() { - echo -e $BOLD"Setting agent trace"$EBOLD + echo -e $BOLD"Setting agent trace logging"$EBOLD actuator="/actuator/loggers/org.oransc.policyagent" if [[ $POLICY_AGENT_IMAGE = *"onap"* ]]; then actuator="/actuator/loggers/org.onap.ccsdk.oran.a1policymanagementservice" @@ -1881,11 +1985,13 @@ start_ecs() { cd ecs cd $ECS_HOST_MNT_DIR if [ -d database ]; then - echo -e $BOLD" Cleaning files in mounted dir: $PWD/database"$EBOLD - rm database/* > /dev/null - if [ $? -ne 0 ]; then - echo -e $RED" Cannot remove database files in: $PWD"$ERED - exit 1 + if [ "$(ls -A $DIR)" ]; then + echo -e $BOLD" Cleaning files in mounted dir: $PWD/database"$EBOLD + rm -rf database/* &> /dev/null + if [ $? -ne 0 ]; then + echo -e $RED" Cannot remove database files in: $PWD"$ERED + exit 1 + fi fi else echo " No files in mounted dir or dir does not exists" @@ -1906,6 +2012,7 @@ start_ecs() { # args: - # (Function for test scripts) restart_ecs() { + echo -e $BOLD"Re-starting ECS"$EBOLD docker restart $ECS_APP_NAME &> ./tmp/.dockererr if [ $? -ne 0 ]; then __print_err "Could restart $ECS_APP_NAME" $@ @@ -1923,7 +2030,8 @@ restart_ecs() { # args: - # (Function for test scripts) use_ecs_rest_http() { - echo -e "Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS" + echo -e $BOLD"ECS protocol setting"$EBOLD + echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS" export ECS_ADAPTER=$ECS_RESTBASE echo "" } @@ -1932,7 +2040,8 @@ use_ecs_rest_http() { # args: - # (Function for test scripts) use_ecs_rest_https() { - echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS" + echo -e $BOLD"ECS protocol setting"$EBOLD + echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS" export ECS_ADAPTER=$ECS_RESTBASE_SECURE echo "" return 0 @@ -1942,7 +2051,9 @@ use_ecs_rest_https() { # args: - # (Function for test scripts) use_ecs_dmaap_http() { - echo -e "Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS" + echo -e $BOLD"ECS dmaap protocol setting"$EBOLD + echo -e $RED" - NOT SUPPORTED - "$ERED + echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS" export ECS_ADAPTER=$ECS_DMAAPBASE echo "" return 0 @@ -1952,7 +2063,9 @@ use_ecs_dmaap_http() { # args: - # (Function for test scripts) use_ecs_dmaap_https() { - echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS" + echo -e $BOLD"RICSIM protocol setting"$EBOLD + echo -e $RED" - NOT SUPPORTED - "$ERED + echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS" export ECS_ADAPTER=$ECS_DMAAPBASE_SECURE echo "" return 0 @@ -1962,7 +2075,7 @@ use_ecs_dmaap_https() { # args: - # (Function for test scripts) set_ecs_debug() { - echo -e $BOLD"Setting ecs debug"$EBOLD + echo -e $BOLD"Setting ecs debug logging"$EBOLD curlString="$LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}" result=$(__do_curl "$curlString") if [ $? -ne 0 ]; then @@ -1978,7 +2091,7 @@ set_ecs_debug() { # args: - # (Function for test scripts) set_ecs_trace() { - echo -e $BOLD"Setting ecs trace"$EBOLD + echo -e $BOLD"Setting ecs trace logging"$EBOLD curlString="$LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}" result=$(__do_curl "$curlString") if [ $? -ne 0 ]; then @@ -2155,7 +2268,6 @@ __do_curl() { echo "" return 1 else - echo "X2" >> $HTTPLOG return 0 fi else @@ -2193,8 +2305,9 @@ __var_test() { checkjsonarraycount=1 fi - echo -e $BOLD"TEST(${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5} within ${6} seconds"$EBOLD + echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5} within ${6} seconds"$EBOLD ((RES_TEST++)) + ((TEST_SEQUENCE_NR++)) start=$SECONDS ctr=0 for (( ; ; )); do @@ -2254,8 +2367,9 @@ __var_test() { checkjsonarraycount=1 fi - echo -e $BOLD"TEST(${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5}"$EBOLD + echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${1}, ${3} ${4} ${5}"$EBOLD ((RES_TEST++)) + ((TEST_SEQUENCE_NR++)) if [ $checkjsonarraycount -eq 0 ]; then result="$(__do_curl $2$3)" retcode=$? diff --git a/test/cr/Dockerfile b/test/cr/Dockerfile index 8349554b..24c90332 100644 --- a/test/cr/Dockerfile +++ b/test/cr/Dockerfile @@ -15,7 +15,9 @@ # ============LICENSE_END================================================= # -FROM python:3.8-slim-buster +ARG NEXUS_PROXY_REPO + +FROM ${NEXUS_PROXY_REPO}python:3.8-slim-buster #install nginx RUN apt-get update diff --git a/test/cr/README.md b/test/cr/README.md index becace1a..b8c4ad17 100644 --- a/test/cr/README.md +++ b/test/cr/README.md @@ -53,10 +53,10 @@ All counters also support the query parameter "id" to fetch counter for one indi ### Build and start ### >Build image
-```docker build -t callback-receiver .``` +```docker build --build-arg NEXUS_PROXY_REPO=nexus3.onap.org:10001/ -t callback-receiver .``` >Start the image on both http and https
-```docker run -it -p 8090:8090 -p 8091:8091 callback-receiver``` +```docker run --rm -it -p 8090:8090 -p 8091:8091 callback-receiver``` It will listen to http 8090 port and https 8091 port(using default certificates) at the same time. @@ -69,16 +69,16 @@ file "pass" stores the password when you run the shell script This certificates/key can be overriden by mounting a volume when using "docker run" or "docker-compose" In 'docker run', use field: --volume "$PWD/certificate:/usr/src/app/cert" a1test -```docker run -it -p 8090:8090 -p 8091:8091 -v "/PATH_TO_CERT/cert:/usr/src/app/cert" callback-receiver``` +```docker run --rm -it -p 8090:8090 -p 8091:8091 -v "/PATH_TO_CERT/cert:/usr/src/app/cert" callback-receiver``` In 'docker-compose.yml', use field: volumes: - ./certificate:/usr/src/app/cert:ro -The script ```crstub-build-start.sh``` do the above two steps in one go. This starts the callback-receiver container in stand-alone mode for basic test.
If the callback-receiver should be executed manually with the agent, replace docker run with this command to connect to the docker network with the correct service name (--name shall be aligned with the other components, i.e. the host named given in all callback urls). -```docker run -it -p 8090:8090 -p 8091:8091 --network nonrtric-docker-net --name callback-receiver callback-receiver``` +The script ```cr-build-start.sh``` do the above two steps in one go. This starts the callback-receiver container in stand-alone mode for basic test.
If the callback-receiver should be executed manually with the agent, replace docker run with this command to connect to the docker network with the correct service name (--name shall be aligned with the other components, i.e. the host named given in all callback urls). +```docker run --rm -it -p 8090:8090 -p 8091:8091 --network nonrtric-docker-net --name callback-receiver callback-receiver``` >Start the image on http only
-```docker run -it -p 8090:8090 callback-receiver``` +```docker run --rm -it -p 8090:8090 callback-receiver``` ### Basic test ### diff --git a/test/cr/app/cr.py b/test/cr/app/cr.py index fe0fbe4e..fa42c204 100644 --- a/test/cr/app/cr.py +++ b/test/cr/app/cr.py @@ -19,9 +19,18 @@ from flask import Flask, request, Response from time import sleep import time -import datetime +from datetime import datetime import json import traceback +import logging + +# Disable all logging of GET on reading counters and db +class AjaxFilter(logging.Filter): + def filter(self, record): + return ("/counter/" not in record.getMessage()) and ("/db" not in record.getMessage()) + +log = logging.getLogger('werkzeug') +log.addFilter(AjaxFilter()) app = Flask(__name__) @@ -47,6 +56,7 @@ MIME_TEXT="text/plain" MIME_JSON="application/json" CAUGHT_EXCEPTION="Caught exception: " SERVER_ERROR="Server error :" +TIME_STAMP="cr-timestamp" #I'm alive function @app.route('/', @@ -71,6 +81,7 @@ def receiveresponse(id): cntr_callbacks[id][1]+=1 msg=msg_callbacks[id][0] print("Fetching msg for id: "+id+", msg="+str(msg)) + del msg[TIME_STAMP] del msg_callbacks[id][0] return json.dumps(msg),200 print("No messages for id: "+id) @@ -96,6 +107,8 @@ def receiveresponse_all(id): cntr_callbacks[id][1]+=len(msg_callbacks[id]) msg=msg_callbacks[id] print("Fetching all msgs for id: "+id+", msg="+str(msg)) + for sub_msg in msg: + del sub_msg[TIME_STAMP] del msg_callbacks[id] return json.dumps(msg),200 print("No messages for id: "+id) @@ -132,6 +145,7 @@ def events_write(id): traceback.print_exc() cntr_msg_callbacks += 1 + msg[TIME_STAMP]=str(datetime.now()) if (id in msg_callbacks.keys()): msg_callbacks[id].append(msg) else: @@ -210,10 +224,12 @@ def reset(): global msg_callbacks global cntr_msg_fetched global cntr_msg_callbacks + global cntr_callbacks msg_callbacks={} cntr_msg_fetched=0 cntr_msg_callbacks=0 + cntr_callbacks={} return Response('OK', status=200, mimetype=MIME_TEXT) diff --git a/test/cr/cr-build-start.sh b/test/cr/cr-build-start.sh index 22346798..03e9ed29 100755 --- a/test/cr/cr-build-start.sh +++ b/test/cr/cr-build-start.sh @@ -19,6 +19,6 @@ #Builds the callback receiver container and starts it in interactive mode -docker build -t callback-receiver . +docker build --build-arg NEXUS_PROXY_REPO=nexus3.onap.org:10001/ -t callback-receiver . -docker run --rm -it -p 8090:8090 -p 8091:8091 callback-receiver +docker run --rm -it -p 8090:8090 -p 8091:8091 --name cr callback-receiver diff --git a/test/mrstub/.gitignore b/test/mrstub/.gitignore index e7940a26..d2a3fbac 100644 --- a/test/mrstub/.gitignore +++ b/test/mrstub/.gitignore @@ -1,3 +1,4 @@ +tmp .tmp.json .dockererr nginx_wsgi_flask/__init__.py diff --git a/test/mrstub/Dockerfile b/test/mrstub/Dockerfile index 513894cd..5219e747 100644 --- a/test/mrstub/Dockerfile +++ b/test/mrstub/Dockerfile @@ -15,7 +15,9 @@ # ============LICENSE_END================================================= # -FROM python:3.8-slim-buster +ARG NEXUS_PROXY_REPO + +FROM ${NEXUS_PROXY_REPO}python:3.8-slim-buster COPY app/ /usr/src/app/ COPY cert/ /usr/src/app/cert/ diff --git a/test/mrstub/README.md b/test/mrstub/README.md index e8e8edf3..4365d761 100644 --- a/test/mrstub/README.md +++ b/test/mrstub/README.md @@ -59,10 +59,10 @@ There are a number of counters that can be read to monitor the message processin ### Build and start ### >Build image
-```docker build -t mrstub .``` +```docker build --build-arg NEXUS_PROXY_REPO=nexus3.onap.org:10001/ -t mrstub .``` >Start the image on http only
-```docker run -it -p 3905:3905 mrstub``` +```docker run --rm -it -p 3905:3905 mrstub``` >Start the image on http and https
By default, this image has default certificates under /usr/src/app/cert @@ -72,20 +72,20 @@ file "generate_cert_and_key.sh" is a shell script to generate certificate and ke file "pass" stores the password when you run the shell script Start the a1-interface container without specifing external certificates: -```docker run -it -p 3905:3905 -p 3906:3906 mrstub``` +```docker run --rm -it -p 3905:3905 -p 3906:3906 mrstub``` It will listen to http 3905 port and https 3906 port(using default certificates) at the same time. This certificates/key can be overriden by mounting a volume when using "docker run" or "docker-compose" In 'docker run', use field: --volume "$PWD/certificate:/usr/src/app/cert" a1test -```docker run -it -p 3905:3905 -p 3906:3906 -v "/PATH_TO_CERT/cert:/usr/src/app/cert" mrstub``` +```docker run --rm -it -p 3905:3905 -p 3906:3906 -v "/PATH_TO_CERT/cert:/usr/src/app/cert" mrstub``` In 'docker-compose.yml', use field: volumes: - ./certificate:/usr/src/app/cert:ro The script ```mrstub-build-start.sh``` do the build and docker run in one go. This starts the stub container in stand-alone mode for basic test.
If the mrstub should be executed manually with the agent, replace docker run with this command to connect to the docker network with the correct service name (--name shall be the same as configured in consul for the read and write streams). -```docker run -it -p 3905:3905 --network nonrtric-docker-net --name message-router mrstub``` +```docker run --rm -it -p 3905:3905 --network nonrtric-docker-net --name message-router mrstub``` ### Basic test ### diff --git a/test/mrstub/app/main.py b/test/mrstub/app/main.py index 8804a044..75b23f12 100644 --- a/test/mrstub/app/main.py +++ b/test/mrstub/app/main.py @@ -25,6 +25,15 @@ from flask import Flask from flask import Response import traceback from threading import RLock +import logging + +# Disable all logging of GET on reading counters +class AjaxFilter(logging.Filter): + def filter(self, record): + return ("/counter/" not in record.getMessage()) + +log = logging.getLogger('werkzeug') +log.addFilter(AjaxFilter()) app = Flask(__name__) lock = RLock() diff --git a/test/mrstub/mrstub-build-start.sh b/test/mrstub/mrstub-build-start.sh index 3e431167..8ad1d164 100755 --- a/test/mrstub/mrstub-build-start.sh +++ b/test/mrstub/mrstub-build-start.sh @@ -19,6 +19,6 @@ #Builds the mrstub container and starts it in interactive mode -docker build -t mrstub . +docker build --build-arg NEXUS_PROXY_REPO=nexus3.onap.org:10001/ -t mrstub . -docker run -it -p 3905:3905 -p 3906:3906 -v "$PWD/cert:/usr/src/app/cert" mrstub +docker run --rm -it -p 3905:3905 -p 3906:3906 -v "$PWD/cert:/usr/src/app/cert" mrstub diff --git a/test/prodstub/Dockerfile b/test/prodstub/Dockerfile index bdc3521d..4768bf95 100644 --- a/test/prodstub/Dockerfile +++ b/test/prodstub/Dockerfile @@ -15,7 +15,9 @@ # ============LICENSE_END================================================= # -FROM python:3.8-slim-buster +ARG NEXUS_PROXY_REPO + +FROM ${NEXUS_PROXY_REPO}python:3.8-slim-buster COPY app/ /usr/src/app/ COPY cert/ /usr/src/app/cert/ diff --git a/test/prodstub/README.md b/test/prodstub/README.md index aa23b78c..2fe2d598 100644 --- a/test/prodstub/README.md +++ b/test/prodstub/README.md @@ -1,34 +1,153 @@ ## producer stub - a stub interface to simulate data producers ## -The producer stub is intended for function tests to simulate data producers. +The producer stub is intended for function tests of simulate data producers. +The simulator handles the callbacks for supervision of producers as well as create/update and delete jobs. +As an intial step, the indended job and producers, with supported types, are setup (armed) in the simulator. +In addition, specific response codes can configured for each callback request. # Ports and certificates -TBD +The prodstub normally opens the port 8092 for http. If a certificate and a key are provided the simulator will also open port 8093 for https. +The certificate and key shall be placed in the same dir and the dir shall be mounted to /usr/src/app/cert in the container. | Port | Protocol | | -------- | ----- | | 8092 | http | | 8093 | https | +The dir cert contains a self-signed cert. Use the script generate_cert_and_key.sh to generate a new certificate and key. The password of the certificate must be set 'test'. +The same urls are availables on both the http port 8092 and the https port 8093. If using curl and https, the flag -k shall be given to make curl ignore checking the certificate. + + +### Prodstub interface ### + +>Create callback
+This method receives a callback for create job. The request shall contain a job json. The request is checked towards what has been setup (armed) and the response will be set accordingly.
+```URI and payload, (POST): /callbacks/job/, ```
+```response: 200/201 (or configured response) or 400 for other errors``` + +>Delete callback
+This method receives a callback for delete job. The request is checked towards what has been setup (armed) and the response will be set accordingly.
+```URI and payload, (DELETE): /callbacks/job/```
+```response: 204 (or configured response) or 400 for other errors``` + +>Supervision callback
+This method receives a callback for producer supervision. The request is checked towards what has been setup (armed) and the response will be set accordingly.
+```URI and payload, (GET): /callbacks/supervision/```
+```response: 200 (or configured response) or 400 for other errors``` ### Control interface ### -TBD +The control interface can be used by any test script. +The following REST operations are available: + +>Arm a job create
+This method arms a job for creation and sets an optional response code for create/update
+```URI and payload, (PUT): /arm/create//[?response=]```
+```response: 200 or 400 for other errors``` + +>Arm a job delete
+This method arms a job for deletion and sets an optional response code for delete
+```URI and payload, (PUT): /arm/delete//[?response=]```
+```response: 200 or 400 for other errors``` + +>Arm a producer supervision
+This method arms a supervision and sets an optional response code for supervision calls
+```URI and payload, (PUT): /arm/delete/[?response=]```
+```response: 200 or 400 for other errors``` + +>Arm a type for a producer
+This method arms a type for a producer
+```URI and payload, (PUT): /arm/type//```
+```response: 200 or 400 for other errors``` + +>Disarm a type for a producer
+This method disarms a type for a producer
+```URI and payload, (DELETE): /arm/type//```
+```response: 200 or 400 for other errors``` + +>Get job data parameters
+This method fetches the job data parameters of a job
+```URI and payload, (GET): /jobdata/job_id>```
+```response: 200 or 400 for other errors``` + +>Remove job data parameters
+This method removes the job data parameters from a job
+```URI and payload, (DELETE): /jobdata/job_id>```
+```response: 200 or 400 for other errors``` + +>Start/stop job data delivery
+This method start (or stops) delivering job data to the configured target url. Action is either 'start' or s'stop'
+```URI and payload, (POST): /jobdata/job_id>?action=action```
+```response: 200 or 400 for other errors``` + +>Counter for create job
+This method returns the number of create/update calls to a job
+```URI and payload, (GET): /counter/create/producer_id>/```
+```response: 200 or 400 for other errors``` + +>Counter for delete job
+This method returns the number of delete calls to a job
+```URI and payload, (GET): /counter/delete/producer_id>/```
+```response: 200 or 400 for other errors``` + +>Counter for producer supervision
+This method returns the number of supervision calls to a producer
+```URI and payload, (GET): /counter/supervision/producer_id>```
+```response: 200 or 400 for other errors``` + +>Get internal db
+This method dumps the internal db of producer and jobs as a json file
+```URI and payload, (GET): /status```
+```response: 200 or 400 for other errors``` + +>Reset
+This method makes a full reset by removing all producers and jobs
+```URI and payload, (GET or PUT or POST): /reset```
+```response: 200 or 400 for other errors``` ### Build and start ### >Build image
-```docker build -t producer-stub .``` +```docker build --build-arg NEXUS_PROXY_REPO=nexus3.onap.org:10001/ -t producer-stub .``` >Start the image on both http and https
-```docker run -it -p 8092:8092 -p 8093:8093 --name producer-stub producer-stub``` +```docker run --rm -it -p 8092:8092 -p 8093:8093 --name producer-stub producer-stub``` + +It will listen to http 8092 port and https 8093 port(using default certificates) at the same time. + +>Start the image on http and https
+By default, this image has default certificates under /usr/src/app/cert +file "cert.crt" is the certificate file +file "key.crt" is the key file +file "generate_cert_and_key.sh" is a shell script to generate certificate and key +file "pass" stores the password when you run the shell script + +Start the container without specifing external certificates: +```docker run --rm -it --p 8092:8092 -p 8093:8093 producer-stub``` It will listen to http 8092 port and https 8093 port(using default certificates) at the same time. -TBD +This certificates/key can be overriden by mounting a volume when using "docker run" or "docker-compose" +In 'docker run', use field: +--volume "$PWD/certificate:/usr/src/app/cert" a1test +```docker run --rm -it --p 8092:8092 -p 8093:8093 -v "/PATH_TO_CERT/cert:/usr/src/app/cert" producer-stub``` +In 'docker-compose.yml', use field: +volumes: + - ./certificate:/usr/src/app/cert:ro + +The script ```prodstub-build-start.sh``` do the build and docker run in one go. This starts the stub container in stand-alone mode for basic test.
If the producer-stub should be executed manually with the agent, replace docker run with this command to connect to the docker network with the correct service name (--name shall be the same as configured in consul for the read and write streams). +```docker run --rm -it -p 8092:8092 -p 8093:8093 --name producer-stub producer-stub``` + + +### Basic test ### + +Basic test is made with the script ```basic_test.sh nonsecure|secure``` which tests all the available urls with a subset of the possible operations. Choose nonsecure for http and secure for https. Use the script ```prodstub-build-start.sh``` to start the producer-stub in a container first. + + + ## License diff --git a/test/prodstub/app/prodstub.py b/test/prodstub/app/prodstub.py index 7323d3a4..ea8b914d 100644 --- a/test/prodstub/app/prodstub.py +++ b/test/prodstub/app/prodstub.py @@ -27,6 +27,15 @@ from jsonschema import validate import threading import time import datetime +import logging + +# Disable all logging of GET on reading counters and status +class AjaxFilter(logging.Filter): + def filter(self, record): + return ("/counter/" not in record.getMessage()) and ("/status" not in record.getMessage()) + +log = logging.getLogger('werkzeug') +log.addFilter(AjaxFilter()) app = Flask(__name__) @@ -37,13 +46,9 @@ app = Flask(__name__) HOST_IP = "::" HOST_PORT = 2222 -# # Metrics vars -# cntr_msg_callbacks=0 -# cntr_msg_fetched=0 - # Request and response constants -CALLBACK_CREATE_URL="/callbacks/create/" -CALLBACK_DELETE_URL="/callbacks/delete/" +CALLBACK_CREATE_URL="/callbacks/job/" +CALLBACK_DELETE_URL="/callbacks/job//" CALLBACK_SUPERVISION_URL="/callbacks/supervision/" ARM_CREATE_RESPONSE="/arm/create//" @@ -84,6 +89,12 @@ db={} # armed response for delete # create counter # delete counter +# delivering status + +# disable warning about unverified https requests +from requests.packages import urllib3 + +urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # Helper function to populate a callback dict with the basic structure # if job_id is None then only the producer level is setup and the producer dict is returned @@ -117,7 +128,7 @@ def setup_callback_dict(producer_id, job_id): job_dict['json']=None job_dict['create_counter']=0 job_dict['delete_counter']=0 - job_dict['delivering']=False + job_dict['delivering']="stopped" job_dict['delivery_attempts']=0 return job_dict @@ -309,7 +320,7 @@ def disarm_type(producer_id, type_id): # Callback for create job -# URI and parameters (POST): /callbacks/create/ +# URI and parameters (POST): /callbacks/job/ # response 201 at create, 200 at update or other configured response code @app.route(CALLBACK_CREATE_URL, methods=['POST']) @@ -343,12 +354,14 @@ def callback_create(producer_id): return_code=job_dict['create_response'] if ((job_dict['create_response'] == 200) or (job_dict['create_response'] == 201)): job_dict['json']=req_json_dict - job_dict['delivering']=True + job_dict['delivering']="delivering" if (job_dict['create_response'] == 201): #Set up next response code if create was ok job_dict['create_response'] = 200 if (job_dict['delete_response'] == 404): job_dict['delete_response'] = 204 else: + if(job_dict['delivering'] == "delivering"): + job_dict['delivering']="hold" return_msg=RETURNING_CONFIGURED_RESP job_dict['create_counter']=job_dict['create_counter']+1 @@ -358,42 +371,29 @@ def callback_create(producer_id): return return_msg, return_code # Callback for delete job -# URI and parameters (POST): /callbacks/delete/ +# URI and parameters (DELETE): /callbacks/job// # response: 204 at delete or other configured response code @app.route(CALLBACK_DELETE_URL, - methods=['POST']) -def callback_delete(producer_id): + methods=['DELETE']) +def callback_delete(producer_id, job_id): - req_json_dict=None - try: - req_json_dict = json.loads(request.data) - with open('job-schema.json') as f: - schema = json.load(f) - validate(instance=req_json_dict, schema=schema) - except Exception: - return JSON_CORRUPT,400 - - job_id=req_json_dict['ei_job_identity'] job_dict=get_callback_dict(producer_id, job_id) if (job_dict is None): return PRODUCER_OR_JOB_NOT_FOUND,400 return_code=0 return_msg="" - if (req_json_dict['ei_job_identity'] == job_id): - print("Delete callback received for producer: "+str(producer_id)+" and job: "+str(job_id)) - return_code=job_dict['delete_response'] - if (job_dict['delete_response'] == 204): - job_dict['json']=None - job_dict['delete_response']=404 - job_dict['delivering']=False - if (job_dict['create_response'] == 200): - job_dict['create_response'] = 201 # reset create response if delete was ok - else: - return_msg=RETURNING_CONFIGURED_RESP - - job_dict['delete_counter']=job_dict['delete_counter']+1 + print("Delete callback received for producer: "+str(producer_id)+" and job: "+str(job_id)) + return_code=job_dict['delete_response'] + if (job_dict['delete_response'] == 204): + job_dict['json']=None + job_dict['delete_response']=404 + job_dict['delivering']="stopped" + if (job_dict['create_response'] == 200): + job_dict['create_response'] = 201 # reset create response if delete was ok else: - return JOBID_NO_MATCH, 400 + return_msg=RETURNING_CONFIGURED_RESP + + job_dict['delete_counter']=job_dict['delete_counter']+1 return return_msg, return_code @@ -437,6 +437,25 @@ def get_jobdata(producer_id, job_id): else: return json.dumps(job_dict['json']), 200 +# Delete the job definition for a job +# URI and parameters (DELETE): "/jobdata//" +# response: 204 +@app.route(JOB_DATA, + methods=['DELETE']) +def del_jobdata(producer_id, job_id): + + print("Delete job data received for producer: "+str(producer_id)+" and job: "+str(job_id)) + + job_dict=get_callback_dict(producer_id, job_id) + + if (job_dict is None): + return PRODUCER_OR_JOB_NOT_FOUND,400 + + job_dict['json']=None + + return "",204 + + # Start data delivery for a job, action : START or STOP # URI and parameters (POST): "/jobdata//?action=action" # response: 200 or 204 @@ -465,9 +484,9 @@ def start_jobdata(producer_id, job_id): return JOB_DATA_NOT_FOUND, 400 else: if (action == "START"): - job_dict['delivering']=True + job_dict['delivering']="delivering" else: - job_dict['delivering']=False + job_dict['delivering']="stopped" return "",200 @@ -529,18 +548,18 @@ def datadelivery() : job_dicts=get_all_jobs() for key in job_dicts: job=job_dicts[key] - if (job['delivering'] == True and job['json'] != None): + if (job['delivering'] == "delivering" and job['json'] != None): url=job['json']['target_uri'] - - data={} - data["date"]=str(datetime.datetime.now()) - data["job"]=""+key - data["sequence_no"]=""+str(job['delivery_attempts']) - data["value"]=str(100) - print("Sending to "+url+" payload:"+json.dumps(data)) - - requests.post(url, json=data, verify=False, timeout=2) #NOSONAR - job['delivery_attempts'] += 1 + if (str(url).find("localhost:") == -1): #Dont deliver to localhost... + data={} + data["date"]=str(datetime.datetime.now()) + data["job"]=""+key + data["sequence_no"]=""+str(job['delivery_attempts']) + data["value"]=str(100) + print("Sending to "+url+" payload:"+json.dumps(data)) + + requests.post(url, json=data, verify=False, timeout=2) #NOSONAR + job['delivery_attempts'] += 1 except Exception as err: print("Error during data delivery: "+ str(err)) time.sleep(1) diff --git a/test/prodstub/basic_test.sh b/test/prodstub/basic_test.sh index a17c8041..18b77358 100755 --- a/test/prodstub/basic_test.sh +++ b/test/prodstub/basic_test.sh @@ -157,7 +157,7 @@ do_curl PUT /arm/create/prod-x/job-y?response=405 200 ## check the db echo "=== status ===" -RESULT="json:{\"prod-x\": {\"supervision_response\": 400, \"supervision_counter\": 2, \"types\": [\"10\", \"15\"], \"job-y\": {\"create_response\": 405, \"delete_response\": 404, \"json\": null, \"create_counter\": 0, \"delete_counter\": 0, \"delivering\": false, \"delivery_attempts\": 0}}}" +RESULT="json:{\"prod-x\": {\"supervision_response\": 400, \"supervision_counter\": 2, \"types\": [\"10\", \"15\"], \"job-y\": {\"create_response\": 405, \"delete_response\": 404, \"json\": null, \"create_counter\": 0, \"delete_counter\": 0, \"delivering\": \"stopped\", \"delivery_attempts\": 0}}}" do_curl GET /status 200 ## add delete response for job @@ -169,7 +169,7 @@ do_curl PUT /arm/delete/prod-x/job-y?response=407 200 ## check the db echo "=== status ===" -RESULT="json:{\"prod-x\": {\"supervision_response\": 400, \"supervision_counter\": 2, \"types\": [\"10\", \"15\"], \"job-y\": {\"create_response\": 405, \"delete_response\": 407, \"json\": null, \"create_counter\": 0, \"delete_counter\": 0, \"delivering\": false, \"delivery_attempts\": 0}}}" +RESULT="json:{\"prod-x\": {\"supervision_response\": 400, \"supervision_counter\": 2, \"types\": [\"10\", \"15\"], \"job-y\": {\"create_response\": 405, \"delete_response\": 407, \"json\": null, \"create_counter\": 0, \"delete_counter\": 0, \"delivering\": \"stopped\", \"delivery_attempts\": 0}}}" do_curl GET /status 200 ## Get jobdata @@ -188,12 +188,12 @@ do_curl PUT /arm/delete/prod-x/job-1 200 echo "=== callback create job ===" RESULT="" echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json -do_curl POST /callbacks/create/prod-x 201 .p.json +do_curl POST /callbacks/job/prod-x 201 .p.json echo "=== callback create job -update ===" RESULT="" echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json -do_curl POST /callbacks/create/prod-x 200 .p.json +do_curl POST /callbacks/job/prod-x 200 .p.json ## Get jobdata echo "=== job data ===" @@ -203,7 +203,7 @@ do_curl GET /jobdata/prod-x/job-1 200 ## check the db echo "=== status ===" -RESULT="json:{\"prod-x\": {\"supervision_response\": 400, \"supervision_counter\": 2, \"types\": [\"10\", \"15\"], \"job-y\": {\"create_response\": 405, \"delete_response\": 407, \"json\": null, \"create_counter\": 0, \"delete_counter\": 0, \"delivering\": false, \"delivery_attempts\": 0}, \"job-1\": {\"create_response\": 200, \"delete_response\": 204, \"json\": {\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\", \"ei_type_identity\": \"10\"}, \"create_counter\": 2, \"delete_counter\": 0, \"delivering\": false, \"delivery_attempts\": 0}}}" +RESULT="json:{\"prod-x\": {\"supervision_response\": 400, \"supervision_counter\": 2, \"types\": [\"10\", \"15\"], \"job-y\": {\"create_response\": 405, \"delete_response\": 407, \"json\": null, \"create_counter\": 0, \"delete_counter\": 0, \"delivering\": \"stopped\", \"delivery_attempts\": 0}, \"job-1\": {\"create_response\": 200, \"delete_response\": 204, \"json\": {\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\", \"ei_type_identity\": \"10\"}, \"create_counter\": 2, \"delete_counter\": 0, \"delivering\": \"delivering\", \"delivery_attempts\": 0}}}" do_curl GET /status 200 # create and delete job tests @@ -214,7 +214,7 @@ do_curl PUT /arm/create/prod-x/job-1?response=404 200 echo "=== callback create job -update ===" RESULT="returning configured response code" echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json -do_curl POST /callbacks/create/prod-x 404 .p.json +do_curl POST /callbacks/job/prod-x 404 .p.json echo "=== set job delete response ===" RESULT="" @@ -223,7 +223,7 @@ do_curl PUT /arm/delete/prod-x/job-1?response=404 200 echo "=== callback delete job===" RESULT="returning configured response code" echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json -do_curl POST /callbacks/delete/prod-x 404 .p.json +do_curl DELETE /callbacks/job/prod-x/job-1 404 .p.json echo "=== set job delete response ===" RESULT="" @@ -232,12 +232,12 @@ do_curl PUT /arm/delete/prod-x/job-1 200 echo "=== callback delete job===" RESULT="" echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json -do_curl POST /callbacks/delete/prod-x 204 .p.json +do_curl DELETE /callbacks/job/prod-x/job-1 204 .p.json ## check the db echo "=== status ===" -RESULT="json:{\"prod-x\": {\"supervision_response\": 400, \"supervision_counter\": 2, \"types\": [\"10\", \"15\"], \"job-y\": {\"create_response\": 405, \"delete_response\": 407, \"json\": null, \"create_counter\": 0, \"delete_counter\": 0, \"delivering\": false, \"delivery_attempts\": 0}, \"job-1\": {\"create_response\": 404, \"delete_response\": 404, \"json\": null, \"create_counter\": 3, \"delete_counter\": 2, \"delivering\": false, \"delivery_attempts\": 0}}}" +RESULT="json:{\"prod-x\": {\"supervision_response\": 400, \"supervision_counter\": 2, \"types\": [\"10\", \"15\"], \"job-y\": {\"create_response\": 405, \"delete_response\": 407, \"json\": null, \"create_counter\": 0, \"delete_counter\": 0, \"delivering\": \"stopped\", \"delivery_attempts\": 0}, \"job-1\": {\"create_response\": 404, \"delete_response\": 404, \"json\": null, \"create_counter\": 3, \"delete_counter\": 2, \"delivering\": \"stopped\", \"delivery_attempts\": 0}}}" do_curl GET /status 200 @@ -250,7 +250,7 @@ do_curl PUT /arm/create/prod-x/job-1 200 echo "=== callback create job ===" RESULT="" echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json -do_curl POST /callbacks/create/prod-x 201 .p.json +do_curl POST /callbacks/job/prod-x 201 .p.json echo "=== data delivery start ===" RESULT="job not found" diff --git a/test/prodstub/prod-stub-build-start.sh b/test/prodstub/prod-stub-build-start.sh index b16e6132..89cc967d 100755 --- a/test/prodstub/prod-stub-build-start.sh +++ b/test/prodstub/prod-stub-build-start.sh @@ -22,8 +22,6 @@ NAME="producer-stub-test" IMAGE_NAME="producer-stub-test-image" -docker build -t $IMAGE_NAME . +docker build --build-arg NEXUS_PROXY_REPO=nexus3.onap.org:10001/ -t $IMAGE_NAME . -docker stop $NAME -docker rm -f $NAME -docker run -it -p 8992:8092 -p 8993:8093 --name $NAME $IMAGE_NAME +docker run --rm -it -p 8992:8092 -p 8993:8093 --name $NAME $IMAGE_NAME diff --git a/test/simulator-group/ecs/docker-compose.yml b/test/simulator-group/ecs/docker-compose.yml index 11cf8105..824156e0 100644 --- a/test/simulator-group/ecs/docker-compose.yml +++ b/test/simulator-group/ecs/docker-compose.yml @@ -26,6 +26,8 @@ services: default: aliases: - ${ECS_APP_NAME_ALIAS} + volumes: + - ${ECS_HOST_MNT_DIR}:${ECS_CONTAINER_MNT_DIR} ports: - ${ECS_EXTERNAL_PORT}:${ECS_INTERNAL_PORT} - ${ECS_EXTERNAL_SECURE_PORT}:${ECS_INTERNAL_SECURE_PORT} diff --git a/test/simulator-group/ecs/mnt/.gitignore b/test/simulator-group/ecs/mnt/.gitignore new file mode 100644 index 00000000..aa0d57e8 --- /dev/null +++ b/test/simulator-group/ecs/mnt/.gitignore @@ -0,0 +1 @@ +database diff --git a/test/simulator-group/sim-monitor.js b/test/simulator-group/sim-monitor.js index 7d7ffdf8..7a220263 100644 --- a/test/simulator-group/sim-monitor.js +++ b/test/simulator-group/sim-monitor.js @@ -69,7 +69,7 @@ function getSimCtr(url, index, cb) { } catch(err) { cb("no response", index); } -}; +} //Format a comma separated list of data to a html-safe string with fixed fieldsizes @@ -121,9 +121,9 @@ function formatIdRowCompact(commaList) { } //Pad a string upto a certain size using a pad string -function padding(val, fieldSize, pad) { +function padding(val, size, pad) { var s=""+val; - for(var i=s.length;i" + "" if (summary == "false") { - htmlStr=htmlStr+"

Set query param '?summary' to true to only show summary statistics

" + htmlStr=htmlStr+"

Set query param '?summary' to true to only show summary statistics.

" } else { htmlStr=htmlStr+"

Set query param '?summary' to false to only show full statistics

" } + if (ecs_job_status.length > 10) { + htmlStr=htmlStr+"
Avoid running the server for large number of producers and/or jobs
" + } htmlStr=htmlStr+"
" + "

Enrichment Coordinator Service

" + "" + @@ -723,24 +792,34 @@ app.get("/mon2",function(req, res){ } } htmlStr=htmlStr+"
"; - for(var i=0;i" + s = "Producer jobs....." + formatDataRow(ecs_producer_jobs_arr[i]) + "
" htmlStr=htmlStr+s } } htmlStr=htmlStr+"
"; - for(var i=0;i" + s = "Producer status..." + formatDataRow(tmp) + "
" + htmlStr=htmlStr+s + } + } + htmlStr=htmlStr+"
"; + for(i=0;i" htmlStr=htmlStr+s } } htmlStr=htmlStr+"
"+"
" + "
" } + htmlStr=htmlStr+ "

Producer stub

" + "" + @@ -755,26 +834,26 @@ app.get("/mon2",function(req, res){ "Producer ids:....." + formatDataRow(ps_producers) + "
" + "Type ids:........." + formatDataRow(ps_types) + "
" + "
"; - for(var i=0;i" + s = "Producer types...." + formatDataRow(ps_producer_type_arr[i]) + "
" htmlStr=htmlStr+s } } htmlStr=htmlStr+"
"; - for(var i=0;i" + s = "Producer jobs....." + formatDataRow(ps_producer_jobs_arr[i]) + "
" htmlStr=htmlStr+s } } htmlStr=htmlStr+"
"; - for(var i=0;i" + s = "Producer delivery." + formatDataRow(ps_producer_delivery_arr[i]) + "
" htmlStr=htmlStr+s } } -- 2.16.6