From f38e1e8cb3652e73ea1e76b5a1a77a4aeb108577 Mon Sep 17 00:00:00 2001 From: BjornMagnussonXA Date: Sun, 11 Oct 2020 23:05:02 +0200 Subject: [PATCH] Add functions test cases for ECS Documentation in README files not yet included Issue-ID: NONRTRIC-297 Signed-off-by: BjornMagnussonXA Change-Id: I9365d6100f7ef0232e4787e350c69e3a8390de32 --- test/auto-test/FTC1.sh | 5 +- test/auto-test/FTC10.sh | 4 +- test/auto-test/FTC100.sh | 4 +- test/auto-test/FTC110.sh | 4 +- test/auto-test/FTC1100.sh | 199 ++++++- test/auto-test/FTC150.sh | 6 +- test/auto-test/FTC300.sh | 4 +- test/auto-test/FTC310.sh | 4 +- test/auto-test/FTC350.sh | 5 +- test/auto-test/FTC800.sh | 4 +- test/auto-test/FTC810.sh | 4 +- test/auto-test/FTC850.sh | 4 +- test/auto-test/FTC900.sh | 4 +- test/auto-test/{DEMO.sh => PM_DEMO.sh} | 4 +- test/auto-test/testdata/ecs/ei-type-1.json | 6 + test/auto-test/testdata/ecs/ei-type-2.json | 6 + test/auto-test/testdata/ecs/job-template.json | 5 + test/common/agent_api_functions.sh | 34 +- test/common/controller_api_functions.sh | 12 +- test/common/do_curl_function.sh | 4 +- test/common/ecs_api_functions.sh | 648 ++++++++++++++++++----- test/common/prodstub_api_functions.sh | 210 ++++++++ test/common/ricsimulator_api_functions.sh | 7 +- test/common/test_env.sh | 15 +- test/common/testcase_common.sh | 304 +++++++---- test/prodstub/.gitignore | 2 + test/prodstub/Dockerfile | 33 ++ test/prodstub/README.md | 46 ++ test/prodstub/app/job-schema.json | 20 + test/prodstub/app/nginx.conf | 100 ++++ test/prodstub/app/prodstub.py | 463 ++++++++++++++++ test/prodstub/app/requirements.txt | 3 + test/prodstub/app/start.sh | 23 + test/prodstub/basic_test.sh | 54 ++ test/prodstub/cert/cert.crt | 16 + test/prodstub/cert/generate_cert_and_key.sh | 21 + test/prodstub/cert/key.crt | 30 ++ test/prodstub/cert/pass | 1 + test/prodstub/prod-stub-build-start.sh | 24 + test/simulator-group/prodstub/.gitignore | 2 + test/simulator-group/prodstub/docker-compose.yml | 33 ++ test/simulator-group/sdnc/docker-compose.yml | 1 + 42 files changed, 2065 insertions(+), 313 deletions(-) rename test/auto-test/{DEMO.sh => PM_DEMO.sh} (97%) create mode 100644 test/auto-test/testdata/ecs/ei-type-1.json create mode 100644 test/auto-test/testdata/ecs/ei-type-2.json create mode 100644 test/auto-test/testdata/ecs/job-template.json create mode 100644 test/common/prodstub_api_functions.sh create mode 100644 test/prodstub/.gitignore create mode 100644 test/prodstub/Dockerfile create mode 100644 test/prodstub/README.md create mode 100644 test/prodstub/app/job-schema.json create mode 100644 test/prodstub/app/nginx.conf create mode 100644 test/prodstub/app/prodstub.py create mode 100644 test/prodstub/app/requirements.txt create mode 100755 test/prodstub/app/start.sh create mode 100755 test/prodstub/basic_test.sh create mode 100644 test/prodstub/cert/cert.crt create mode 100755 test/prodstub/cert/generate_cert_and_key.sh create mode 100644 test/prodstub/cert/key.crt create mode 100644 test/prodstub/cert/pass create mode 100755 test/prodstub/prod-stub-build-start.sh create mode 100644 test/simulator-group/prodstub/.gitignore create mode 100644 test/simulator-group/prodstub/docker-compose.yml diff --git a/test/auto-test/FTC1.sh b/test/auto-test/FTC1.sh index 39b6e6d5..e4482b60 100755 --- a/test/auto-test/FTC1.sh +++ b/test/auto-test/FTC1.sh @@ -20,8 +20,8 @@ TC_ONELINE_DESCR="Sanity test, create service and then create,update and delete a policy using http/https and Agent REST/DMAAP with/without SDNC controller" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="ECS" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh @@ -100,6 +100,7 @@ for __httpx in $TESTED_PROTOCOLS ; do start_policy_agent set_agent_debug + set_agent_trace cr_equal received_callbacks 0 mr_equal requests_submitted 0 diff --git a/test/auto-test/FTC10.sh b/test/auto-test/FTC10.sh index 754260e1..42b8f587 100755 --- a/test/auto-test/FTC10.sh +++ b/test/auto-test/FTC10.sh @@ -19,8 +19,8 @@ TC_ONELINE_DESCR="Basic use case, register service, create/update policy, delete policy, de-register service using both STD and OSC interface while mixing REST and Dmaap" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="SDNC ECS" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh diff --git a/test/auto-test/FTC100.sh b/test/auto-test/FTC100.sh index 929f3f2d..b617d3f1 100755 --- a/test/auto-test/FTC100.sh +++ b/test/auto-test/FTC100.sh @@ -20,8 +20,8 @@ TC_ONELINE_DESCR="Full agent API walk through using agent REST/DMAAP and with/without SDNC A1 Controller" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="ECS" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh diff --git a/test/auto-test/FTC110.sh b/test/auto-test/FTC110.sh index 90b78270..c840800a 100755 --- a/test/auto-test/FTC110.sh +++ b/test/auto-test/FTC110.sh @@ -20,8 +20,8 @@ TC_ONELINE_DESCR="Testing of service registration timeouts and keepalive" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="SDNC ECS" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh diff --git a/test/auto-test/FTC1100.sh b/test/auto-test/FTC1100.sh index 0d3371a8..a61f1bb9 100755 --- a/test/auto-test/FTC1100.sh +++ b/test/auto-test/FTC1100.sh @@ -20,51 +20,200 @@ TC_ONELINE_DESCR="Experimental ECS test case" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="SDNC PA CP CR MR RICSIM CONSUL CBS" +#App names to include in the test, space separated list +INCLUDED_IMAGES="ECS PRODSTUB" . ../common/testcase_common.sh $@ . ../common/ecs_api_functions.sh +. ../common/prodstub_api_functions.sh #### TEST BEGIN #### clean_containers -use_ecs_rest_https +use_ecs_rest_http -use_ecs_rest_https +use_prod_stub_http start_ecs +start_prod_stub + set_ecs_debug +set_ecs_trace + +# Setup prodstub sim to accept calls for producers, types and jobs +prodstub_arm_supervision 200 prod-a +prodstub_arm_supervision 200 prod-b +prodstub_arm_supervision 200 prod-c + +prodstub_arm_type 200 prod-a type1 +prodstub_arm_type 200 prod-b type2 +prodstub_arm_type 200 prod-b type3 + +prodstub_disarm_type 200 prod-b type3 +prodstub_arm_type 200 prod-b type1 +prodstub_disarm_type 200 prod-b type1 +prodstub_arm_create 200 prod-a job1 +prodstub_arm_create 200 prod-a job2 +prodstub_arm_create 200 prod-b job3 +prodstub_arm_delete 200 prod-a job1 +prodstub_arm_delete 200 prod-a job2 +prodstub_arm_delete 200 prod-b job3 -ecs_api_a1_get_job_ids 200 -ecs_api_a1_get_type 200 -ecs_api_a1_get_type_ids 200 -ecs_api_a1_get_job_status 200 -ecs_api_a1_get_job 200 -ecs_api_a1_delete_job 200 -ecs_api_a1_put_job 200 -ecs_api_edp_get_type_ids 200 -ecs_api_edp_get_producer_status 200 -ecs_api_edp_get_producer_ids 200 NOID -ecs_api_edp_get_type 200 -ecs_api_edp_get_producer 200 -ecs_api_edp_delete_producer 200 -ecs_api_edp_put_producer 200 -ecs_api_edp_get_producer_jobs 200 -ecs_api_sim_post_job_delete_error 200 -ecs_api_sim_get_producer_supervision 200 -ecs_api_sim_post_job_deleted 200 -ecs_api_get_producer_supervision_error 200 -ecs_api_sim_get_job_created_error 200 -ecs_api_sim_get_job_created 200 +prodstub_arm_create 200 prod-b job4 +prodstub_arm_create 200 prod-a job4 + +prodstub_arm_create 200 prod-b job5 +prodstub_arm_create 200 prod-a job5 +prodstub_arm_delete 200 prod-a job5 + +prodstub_arm_create 200 prod-b job6 + +# ecs status ecs_api_service_status 200 +# Initial tests - no config made +ecs_api_a1_get_type_ids 200 EMPTY +ecs_api_a1_get_type 404 test-type + +ecs_api_edp_get_type_ids 200 EMPTY +ecs_api_edp_get_type 404 test-type + +ecs_api_edp_get_producer_ids 200 EMPTY +ecs_api_edp_get_producer 404 test-prod + +ecs_api_edp_get_producer_status 404 test-prod + +ecs_api_edp_delete_producer 404 test-prod + +ecs_api_a1_get_job_ids 404 test-type NOWNER +ecs_api_a1_get_job_ids 404 test-type test-owner + +ecs_api_a1_get_job 404 test-type test-job + +ecs_api_a1_get_job_status 404 test-type test-job + +ecs_api_a1_delete_job 404 test-type test-job + +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 + +ecs_api_a1_get_type_ids 200 type1 +ecs_api_a1_get_type 200 type1 testdata/ecs/ei-type-1.json + +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_status 200 prod-a ENABLED + +ecs_api_a1_get_job_ids 200 type1 NOWNER EMPTY +ecs_api_a1_get_job_ids 200 type1 test-owner EMPTY + +ecs_api_a1_get_job 404 type1 test-job + +ecs_api_a1_get_job_status 404 type1 test-job + +ecs_api_edp_get_producer_jobs 200 prod-a EMPTY + + +#job1 - prod-a +ecs_api_a1_put_job 201 type1 job1 http://localhost:80/target1 ric1 testdata/ecs/job-template.json + +prodstub_check_jobdata 200 prod-a job1 type1 http://localhost:80/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 200 type1 job1 http://localhost:80/target1 ric1 testdata/ecs/job-template.json + +ecs_api_a1_get_job_status 200 type1 job1 ENABLED + +ecs_api_edp_get_producer_jobs 200 prod-a job1 type1 http://localhost:80/target1 testdata/ecs/job-template.json + + +#job2 - prod-a +ecs_api_a1_put_job 201 type1 job2 http://localhost:80/target2 ric2 testdata/ecs/job-template.json + +prodstub_check_jobdata 200 prod-a job2 type1 http://localhost:80/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 200 type1 job2 http://localhost:80/target2 ric2 testdata/ecs/job-template.json + +ecs_api_a1_get_job_status 200 type1 job2 ENABLED + +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 + + +#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 + +ecs_api_a1_get_type_ids 200 type1 type2 +ecs_api_a1_get_type 200 type1 testdata/ecs/ei-type-1.json +ecs_api_a1_get_type 200 type2 testdata/ecs/ei-type-2.json + +ecs_api_edp_get_type_ids 200 type1 type2 +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 + + +#job3 - prod-b +ecs_api_a1_put_job 201 type2 job3 http://localhost:80/target3 ric3 testdata/ecs/job-template.json + +prodstub_check_jobdata 200 prod-b job3 type2 http://localhost:80/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 200 type2 job3 http://localhost:80/target3 ric3 testdata/ecs/job-template.json + +ecs_api_a1_get_job_status 200 type2 job3 ENABLED + +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 + + +#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_status 200 prod-c ENABLED + +ecs_api_a1_delete_job 204 type2 job3 + +ecs_api_edp_delete_producer 204 prod-b + + +check_sndc_logs +check_ecs_logs store_logs END diff --git a/test/auto-test/FTC150.sh b/test/auto-test/FTC150.sh index 042765c8..ead424c3 100755 --- a/test/auto-test/FTC150.sh +++ b/test/auto-test/FTC150.sh @@ -20,8 +20,8 @@ TC_ONELINE_DESCR="Sample tests of the SDNC A1 controller restconf API using http/https (no agent)" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="PA CP ECS" +#App names to include in the test, space separated list +INCLUDED_IMAGES="RICSIM SDNC" . ../common/testcase_common.sh $@ . ../common/controller_api_functions.sh @@ -100,6 +100,8 @@ for __nb_httpx in $NB_TESTED_PROTOCOLS ; do controller_api_delete_A1_policy 202 OSC ricsim_g1_1 1 4000 controller_api_delete_A1_policy 204 STD ricsim_g2_1 5000 + check_sdnc_logs + store_logs "NB_"$__nb_httpx"_SB_"$__sb_httpx done diff --git a/test/auto-test/FTC300.sh b/test/auto-test/FTC300.sh index 9907dd67..fb7bc342 100755 --- a/test/auto-test/FTC300.sh +++ b/test/auto-test/FTC300.sh @@ -19,8 +19,8 @@ TC_ONELINE_DESCR="Resync 10000 policies using OSC interface over REST" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="ECS" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh diff --git a/test/auto-test/FTC310.sh b/test/auto-test/FTC310.sh index aa6c9e93..856d6f56 100755 --- a/test/auto-test/FTC310.sh +++ b/test/auto-test/FTC310.sh @@ -20,8 +20,8 @@ TC_ONELINE_DESCR="Resync of RIC via changes in the consul config" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="ECS" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh diff --git a/test/auto-test/FTC350.sh b/test/auto-test/FTC350.sh index a4858a17..4b2e3cb2 100755 --- a/test/auto-test/FTC350.sh +++ b/test/auto-test/FTC350.sh @@ -19,8 +19,8 @@ TC_ONELINE_DESCR="Change supported policy types and reconfigure rics" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="ECS" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh @@ -86,6 +86,7 @@ for interface in $TESTED_VARIANTS ; do start_policy_agent set_agent_debug + set_agent_trace api_get_status 200 diff --git a/test/auto-test/FTC800.sh b/test/auto-test/FTC800.sh index 92af3966..25678bed 100755 --- a/test/auto-test/FTC800.sh +++ b/test/auto-test/FTC800.sh @@ -19,8 +19,8 @@ TC_ONELINE_DESCR="Create 10000 policies in sequence using http/https and Agent REST/DMAAP with/without SDNC controller" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="ECS" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh diff --git a/test/auto-test/FTC810.sh b/test/auto-test/FTC810.sh index 460fb8ee..009efc04 100755 --- a/test/auto-test/FTC810.sh +++ b/test/auto-test/FTC810.sh @@ -19,8 +19,8 @@ TC_ONELINE_DESCR="Repeatedly create and delete policies in each RICs for 24h (or configured number of days). Via agent REST/DMAAP/DMAAP_BATCH and SDNC using http or https" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="ECS" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh diff --git a/test/auto-test/FTC850.sh b/test/auto-test/FTC850.sh index d6cc0013..7391331b 100755 --- a/test/auto-test/FTC850.sh +++ b/test/auto-test/FTC850.sh @@ -19,8 +19,8 @@ TC_ONELINE_DESCR="Create/delete policies in parallel over a number of ric using a number of child process" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="ECS" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL, CP, CR, MR, PA, RICSIM, SDNC" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh diff --git a/test/auto-test/FTC900.sh b/test/auto-test/FTC900.sh index abe648b9..32567973 100755 --- a/test/auto-test/FTC900.sh +++ b/test/auto-test/FTC900.sh @@ -19,8 +19,8 @@ TC_ONELINE_DESCR="Preparation for test of the Control Panel and the Health Check app - populating a number of ric simulators with types and instances" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="SDNC ECS" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh diff --git a/test/auto-test/DEMO.sh b/test/auto-test/PM_DEMO.sh similarity index 97% rename from test/auto-test/DEMO.sh rename to test/auto-test/PM_DEMO.sh index 7c0ba476..3696d567 100755 --- a/test/auto-test/DEMO.sh +++ b/test/auto-test/PM_DEMO.sh @@ -19,8 +19,8 @@ TC_ONELINE_DESCR="Preparation demo setup - populating a number of ric simulators with types and instances" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="ECS" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh diff --git a/test/auto-test/testdata/ecs/ei-type-1.json b/test/auto-test/testdata/ecs/ei-type-1.json new file mode 100644 index 00000000..c74ba28d --- /dev/null +++ b/test/auto-test/testdata/ecs/ei-type-1.json @@ -0,0 +1,6 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "STD_Type1_1.0.0", + "description": "EI-Type 1", + "type": "object" +} \ No newline at end of file diff --git a/test/auto-test/testdata/ecs/ei-type-2.json b/test/auto-test/testdata/ecs/ei-type-2.json new file mode 100644 index 00000000..68a11371 --- /dev/null +++ b/test/auto-test/testdata/ecs/ei-type-2.json @@ -0,0 +1,6 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "STD_Type2_1.0.0", + "description": "EI-Type 2", + "type": "object" +} \ No newline at end of file diff --git a/test/auto-test/testdata/ecs/job-template.json b/test/auto-test/testdata/ecs/job-template.json new file mode 100644 index 00000000..9426d277 --- /dev/null +++ b/test/auto-test/testdata/ecs/job-template.json @@ -0,0 +1,5 @@ +{ + "jobparam1":"value1_XXXX", + "jobparam2":"value2_XXXX", + "jobparam3":"value3_XXXX" +} \ No newline at end of file diff --git a/test/common/agent_api_functions.sh b/test/common/agent_api_functions.sh index 8ec8fdbc..29e1bf1a 100644 --- a/test/common/agent_api_functions.sh +++ b/test/common/agent_api_functions.sh @@ -114,7 +114,7 @@ api_get_policies() { else targetJson=$targetJson"\"${arr[$i+3]}\"," fi - file=".p.json" + file="./tmp/.p.json" sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file json=$(cat $file) targetJson=$targetJson"\"json\":"$json"}" @@ -166,7 +166,7 @@ api_get_policy() { if [ $# -eq 3 ]; then #Create a policy json to compare with body=${res:0:${#res}-3} - file=".p.json" + file="./tmp/.p.json" sed 's/XXX/'${2}'/g' $3 > $file targetJson=$(< $file) echo "TARGET JSON: $targetJson" >> $HTTPLOG @@ -219,7 +219,7 @@ api_put_policy() { query=$query"&transient=$6" fi - file=".p.json" + file="./tmp/.p.json" sed 's/XXX/'${pid}'/g' $7 > $file res="$(__do_curl_to_api PA PUT $query $file)" status=${res:${#res}-3} @@ -278,7 +278,7 @@ api_put_policy_batch() { query=$query"&transient=$6" fi - file=".p.json" + file="./tmp/.p.json" sed 's/XXX/'${pid}'/g' $7 > $file res="$(__do_curl_to_api PA PUT_BATCH $query $file)" status=${res:${#res}-3} @@ -374,19 +374,19 @@ api_put_policy_parallel() { if [ -z "$uuid" ]; then uuid="NOUUID" fi - echo "" > ".pid${i}.res.txt" - echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i > ".pid${i}.txt" + echo "" > "./tmp/.pid${i}.res.txt" + echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i > "./tmp/.pid${i}.txt" echo $i done | xargs -n 1 -I{} -P $pids bash -c '{ arg=$(echo {}) echo " Parallel process $arg started" - tmp=$(< ".pid${arg}.txt") - python3 ../common/create_policies_process.py $tmp > .pid${arg}.res.txt + tmp=$(< "./tmp/.pid${arg}.txt") + python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt }' msg="" for ((i=1; i<=$pids; i++)) do - file=".pid${i}.res.txt" + file="./tmp/.pid${i}.res.txt" tmp=$(< $file) if [ -z "$tmp" ]; then echo " Process $i : unknown result (result file empty" @@ -561,19 +561,19 @@ api_delete_policy_parallel() { if [ -z "$uuid" ]; then uuid="NOUUID" fi - echo "" > ".pid${i}.del.res.txt" - echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i > ".pid${i}.del.txt" + echo "" > "./tmp/.pid${i}.del.res.txt" + echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i > "./tmp/.pid${i}.del.txt" echo $i done | xargs -n 1 -I{} -P $pids bash -c '{ arg=$(echo {}) echo " Parallel process $arg started" - tmp=$(< ".pid${arg}.del.txt") - python3 ../common/delete_policies_process.py $tmp > .pid${arg}.del.res.txt + tmp=$(< "./tmp/pid${arg}.del.txt") + python3 ../common/delete_policies_process.py $tmp > ./tmp/pid${arg}.del.res.txt }' msg="" for ((i=1; i<=$pids; i++)) do - file=".pid${i}.del.res.txt" + file="./tmp/.pid${i}.del.res.txt" tmp=$(< $file) if [ -z "$tmp" ]; then echo " Process $i : unknown result (result file empty" @@ -1008,7 +1008,7 @@ api_get_rics() { if [ $# -gt 2 ]; then body=${res:0:${#res}-3} - res=$(python3 ../common/create_rics_json.py ".tmp_rics.json" "$3" ) + res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "$3" ) if [ $res -ne 0 ]; then echo -e $RED" FAIL, could not create target ric info json"$ERED ((RES_FAIL++)) @@ -1016,7 +1016,7 @@ api_get_rics() { return 1 fi - targetJson=$(<.tmp_rics.json) + targetJson=$(<./tmp/.tmp_rics.json) echo "TARGET JSON: $targetJson" >> $HTTPLOG res=$(python3 ../common/compare_json.py "$targetJson" "$body") if [ $res -ne 0 ]; then @@ -1050,7 +1050,7 @@ api_put_service() { query="/service" json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}" - file=".tmp.json" + file="./tmp/.tmp.json" echo "$json" > $file res="$(__do_curl_to_api PA PUT $query $file)" diff --git a/test/common/controller_api_functions.sh b/test/common/controller_api_functions.sh index 378a6d45..b0ae6418 100644 --- a/test/common/controller_api_functions.sh +++ b/test/common/controller_api_functions.sh @@ -41,9 +41,10 @@ __do_curl_to_controller() { body=$(echo "$3" | sed 's/"/\\"/g') json='{"input":{"near-rt-ric-url":"'$2'","body":"'"$body"'"}}' fi - echo "$json" > .sdnc.payload.json - echo " FILE: $json" >> $HTTPLOG - curlString="curl -skw %{http_code} -X POST $SDNC_HTTPX://$SDNC_USER:$SDNC_PWD@localhost:$SDNC_LOCAL_PORT$SDNC_API_URL$1 -H accept:application/json -H Content-Type:application/json --data-binary @.sdnc.payload.json" + payload="./tmp/.sdnc.payload.json" + echo "$json" > $payload + echo " FILE ($payload) : $json" >> $HTTPLOG + curlString="curl -skw %{http_code} -X POST $SDNC_HTTPX://$SDNC_USER:$SDNC_PWD@localhost:$SDNC_LOCAL_PORT$SDNC_API_URL$1 -H accept:application/json -H Content-Type:application/json --data-binary @$payload" echo " CMD: "$curlString >> $HTTPLOG res=$($curlString) retcode=$? @@ -62,8 +63,9 @@ __do_curl_to_controller() { fi body=${res:0:${#res}-3} echo " JSON: "$body >> $HTTPLOG - echo "$body" > .sdnc-reply.json - res=$(python3 ../common/extract_sdnc_reply.py .sdnc-reply.json) + reply="./tmp/.sdnc-reply.json" + echo "$body" > $reply + res=$(python3 ../common/extract_sdnc_reply.py $reply) echo " EXTRACED BODY+CODE: "$res >> $HTTPLOG echo "$res" return 0 diff --git a/test/common/do_curl_function.sh b/test/common/do_curl_function.sh index c4365d8b..ac945fe0 100755 --- a/test/common/do_curl_function.sh +++ b/test/common/do_curl_function.sh @@ -88,8 +88,8 @@ do_curl() { count=${RESULT:16:${#RESULT}} #Find dir of the common dir DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - echo $body > .tmp.json - res=$(python ${DIR}/count_json_elements.py .tmp.json) + echo $body > ./tmp/.tmp.json + res=$(python ${DIR}/count_json_elements.py ./tmp/.tmp.json) if [ $res -eq $count ]; then echo " Body (array size) as expected" else diff --git a/test/common/ecs_api_functions.sh b/test/common/ecs_api_functions.sh index 3c372991..6c726b9c 100644 --- a/test/common/ecs_api_functions.sh +++ b/test/common/ecs_api_functions.sh @@ -33,51 +33,157 @@ #Function prefix: ecs_api_a1 # API Test function: GET /A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs -# args: +# args: |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++)) + # Valid number of parameters 3,4,5,6 etc if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ + __print_err " |NOOWNER [ EMPTY | + ]" $@ + return 1 + fi + owner="" + if [ $3 != "NOWNER" ]; then + owner="?owner="$3 + fi + + query="/A1-EI/v1/eitypes/$2/eijobs$owner" + 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 [ $# -gt 3 ]; then + body=${res:0:${#res}-3} + targetJson="[" + + for pid in ${@:4} ; do + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + if [ $pid != "EMPTY" ]; then + targetJson=$targetJson"\"$pid\"" + fi + done + + 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 + return 1 + fi + fi + ((RES_PASS++)) echo -e $GREEN" PASS"$EGREEN return 0 } # API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId} -# args: +# 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++)) - if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ + if [ $# -lt 2 ] || [ $# -gt 3 ]; then + __print_err " []" $@ + return 1 + fi + + query="/A1-EI/v1/eitypes/$2" + 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} + 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 + return 1 + fi + targetJson="{\"eiJobParametersSchema\":$schema}" + 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 + fi + fi + + ((RES_PASS++)) echo -e $GREEN" PASS"$EGREEN return 0 } # API Test function: GET ​/A1-EI​/v1​/eitypes -# args: +# 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++)) - if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ + if [ $# -lt 2 ]; then + __print_err " (EMPTY | []+)" $@ + return 1 + fi + + query="/A1-EI/v1/eitypes" + 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 + body=${res:0:${#res}-3} + targetJson="[" + if [ $2 != "EMPTY" ]; then + for pid in ${@:2} ; do + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + targetJson=$targetJson"\"$pid\"" + done + fi + 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 return 1 fi @@ -87,17 +193,41 @@ ecs_api_a1_get_type_ids() { } # API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status -# args: +# args: [] # (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++)) - if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ + if [ $# -ne 3 ] && [ $# -ne 4 ]; then + __print_err " " $@ + return 1 + fi + + query="/A1-EI/v1/eitypes/$2/eijobs/$3/status" + 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 4 ]; then + body=${res:0:${#res}-3} + targetJson="{\"operationalState\": \"$4\"}" + 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 + fi + fi ((RES_PASS++)) echo -e $GREEN" PASS"$EGREEN @@ -105,33 +235,79 @@ ecs_api_a1_get_job_status() { } # API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId} -# args: +# args: [ ] # (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++)) - if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ + if [ $# -ne 3 ] && [ $# -ne 6 ]; then + __print_err " [ ]" $@ + return 1 + fi + + query="/A1-EI/v1/eitypes/$2/eijobs/$3" + 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 6 ]; then + body=${res:0:${#res}-3} + + if [ -f $6 ]; then + 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 + return 1 + fi + targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $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 + return 1 + fi + fi + ((RES_PASS++)) echo -e $GREEN" PASS"$EGREEN return 0 } # API Test function: DELETE ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId} -# args: +# args: # (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++)) - if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ + if [ $# -lt 3 ]; then + __print_err " " $@ + return 1 + fi + + query="/A1-EI/v1/eitypes/$2/eijobs/$3" + res="$(__do_curl_to_api ECS DELETE $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 @@ -141,15 +317,39 @@ ecs_api_a1_delete_job() { } # API Test function: PUT ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId} -# args: +# args: # (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++)) - if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ + if [ $# -lt 6 ]; then + __print_err " " $@ + return 1 + fi + if [ -f $6 ]; then + 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 + return 1 + fi + + inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}" + file="./tmp/.p.json" + echo "$inputJson" > $file + + query="/A1-EI/v1/eitypes/$2/eijobs/$3" + res="$(__do_curl_to_api ECS PUT $query $file)" + 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 @@ -165,7 +365,7 @@ ecs_api_a1_put_job() { # Function prefix: ecs_api_edp # API Test function: GET /ei-producer/v1/eitypes -# args: +# args: [ EMPTY | +] # (Function for test scripts) ecs_api_edp_get_type_ids() { echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD @@ -173,27 +373,85 @@ ecs_api_edp_get_type_ids() { ((RES_TEST++)) if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ + __print_err " [ EMPTY | +]" $@ return 1 fi + query="/ei-producer/v1/eitypes" + 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 [ $# -gt 1 ]; then + body=${res:0:${#res}-3} + targetJson="[" + if [ $2 != "EMPTY" ]; then + for pid in ${@:2} ; do + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + targetJson=$targetJson"\"$pid\"" + done + fi + 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 + return 1 + fi + fi + ((RES_PASS++)) echo -e $GREEN" PASS"$EGREEN 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++)) - if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ + if [ $# -lt 2 ] || [ $# -gt 3 ]; 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} + + 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 [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + fi ((RES_PASS++)) echo -e $GREEN" PASS"$EGREEN @@ -202,7 +460,7 @@ ecs_api_edp_get_producer_status() { # API Test function: GET /ei-producer/v1/eiproducers -# args: []*|NOID +# args: [ EMPTY | +] # (Function for test scripts) ecs_api_edp_get_producer_ids() { echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD @@ -210,7 +468,7 @@ ecs_api_edp_get_producer_ids() { ((RES_TEST++)) if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ + __print_err " [ EMPTY | +]" $@ return 1 fi @@ -233,13 +491,13 @@ ecs_api_edp_get_producer_ids() { if [ "$targetJson" != "[" ]; then targetJson=$targetJson"," fi - if [ $pid != "NOID" ]; then + if [ $pid != "EMPTY" ]; then targetJson=$targetJson"\"$pid\"" fi done targetJson=$targetJson"]" - echo "TARGET JSON: $targetJson" >> $HTTPLOG + echo " TARGET JSON: $targetJson" >> $HTTPLOG res=$(python3 ../common/compare_json.py "$targetJson" "$body") if [ $res -ne 0 ]; then @@ -256,129 +514,172 @@ ecs_api_edp_get_producer_ids() { } # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId} -# args: +# args: [ (NOID | []+)] # (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++)) - if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ + paramError=1 + if [ $# -eq 2 ]; then + paramError=0 + fi + if [ $# -gt 3 ]; then + paramError=0 + fi + if [ $paramError -ne 0 ]; then + __print_err " [ NOID | ([]+)]" $@ return 1 fi - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN - return 0 -} - -# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId} -# args: -# (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++)) + query="/ei-producer/v1/eitypes/$2" + res="$(__do_curl_to_api ECS GET $query)" + status=${res:${#res}-3} - if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ + 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 [ $# -gt 3 ]; then + body=${res:0:${#res}-3} - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN - return 0 -} + 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 + return 1 + fi -# API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId} -# 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++)) + targetJson="" + if [ $4 != "EMPTY" ]; then + for pid in ${@:4} ; do + if [ "$targetJson" != "" ]; then + targetJson=$targetJson"," + fi + targetJson=$targetJson"\"$pid\"" + done + fi + targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}" - if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ - return 1 - 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 + return 1 + fi + fi ((RES_PASS++)) echo -e $GREEN" PASS"$EGREEN return 0 } -# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId} -# args: +# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId} +# args: [ (EMPTY | [ ]+) ] # (Function for test scripts) -ecs_api_edp_put_producer() { +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++)) - if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ - return 1 + #Possible arg count: 2, 6 7, 9, 11 etc + paramError=1 + if [ $# -eq 2 ]; then + paramError=0 + fi + if [ $# -eq 6 ] && [ "$6" == "EMPTY" ]; then + paramError=0 + fi + variablecount=$(($#-5)) + if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then + paramError=0 fi - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN - return 0 -} + if [ $paramError -ne 0 ]; then + __print_err " [ (NOID | [ ]+) ]" $@ + return 1 + fi -# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs -# args: -# (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++)) + query="/ei-producer/v1/eiproducers/$2" + res="$(__do_curl_to_api ECS GET $query)" + status=${res:${#res}-3} - if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ + 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 [ $# -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 [ "$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 + return 1 + fi + + targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}" + done + 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\"}" + 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 + return 1 + fi + fi + ((RES_PASS++)) echo -e $GREEN" PASS"$EGREEN return 0 } - -########################################## -#### Producer Simulator #### -########################################## -# Function prefix: ecs_api_sim - -# API Test function: POST ​/producer_simulator​/job_deleted_error -# args: +# API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId} +# args: # (Function for test scripts) -ecs_api_sim_post_job_delete_error() { +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++)) - if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ + if [ $# -lt 2 ]; then + __print_err " " $@ return 1 fi - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN - return 0 -} - -# API Test function: GET /producer_simulator​/supervision -# args: -# (Function for test scripts) -ecs_api_sim_get_producer_supervision() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + query="/ei-producer/v1/eiproducers/$2" + res="$(__do_curl_to_api ECS DELETE $query)" + status=${res:${#res}-3} - if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + __check_stop_at_error return 1 fi @@ -387,34 +688,60 @@ ecs_api_sim_get_producer_supervision() { return 0 } -# API Test function: POST /producer_simulator​/job_deleted -# args: +# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId} +# args: NOTYPE|[ ]+ # (Function for test scripts) -ecs_api_sim_post_job_deleted() { +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++)) - if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ + #Valid number of parametrer 6,7,9,11, + paramError=1 + if [ $# -eq 6 ] && [ "$6" == "NOTYPE" ]; then + paramError=0 + elif [ $# -gt 6 ] && [ $(($#%2)) -eq 1 ]; then + paramError=0 + fi + if [ $paramError -ne 0 ]; then + __print_err " [ ]+" $@ return 1 fi - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN - return 0 -} + inputJson="[" + if [ $# -gt 6 ]; then + arr=(${@:6}) + for ((i=0; i<$(($#-6)); 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 + return 1 + fi + inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}" + done + fi + inputJson="\"supported_ei_types\":"$inputJson"]" -# API Test function: GET ​/producer_simulator​/supervision_error -# args: -# (Function for test scripts) -ecs_api_get_producer_supervision_error() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + inputJson=$inputJson",\"ei_job_creation_callback_url\": \"$3\",\"ei_job_deletion_callback_url\": \"$4\",\"ei_producer_supervision_callback_url\": \"$5\"" - if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ + inputJson="{"$inputJson"}" + + file="./tmp/.p.json" + echo "$inputJson" > $file + query="/ei-producer/v1/eiproducers/$2" + res="$(__do_curl_to_api ECS PUT $query $file)" + 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 @@ -423,35 +750,72 @@ ecs_api_get_producer_supervision_error() { return 0 } -# API Test function: POST /producer_simulator​/job_created_error -# args: +# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs +# args: (EMPTY | [ ]+) # (Function for test scripts) -ecs_api_sim_get_job_created_error() { +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++)) - if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ + #Valid number of parameter 2,3,6,10 + paramError=1 + if [ $# -eq 2 ]; then + paramError=0 + fi + if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then + paramError=0 + fi + variablecount=$(($#-2)) + if [ $# -gt 3 ] && [ $(($variablecount%4)) -eq 0 ]; then + paramError=0 + fi + if [ $paramError -eq 1 ]; then + __print_err " (EMPTY | [ ]+)" $@ return 1 fi - ((RES_PASS++)) - echo -e $GREEN" PASS"$EGREEN - return 0 -} + query="/ei-producer/v1/eiproducers/$2/eijobs" + 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 [ $# -gt 2 ]; then + body=${res:0:${#res}-3} + targetJson="[" + if [ $# -gt 3 ]; then + arr=(${@:3}) + for ((i=0; i<$(($#-3)); i=i+4)); do + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + if [ -f ${arr[$i+3]} ]; then + 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 + 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}" + done + fi + targetJson=$targetJson"]" -# API Test function: POST ​/producer_simulator​/job_created -# args: -# (Function for test scripts) -ecs_api_sim_get_job_created() { - echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD - echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - ((RES_TEST++)) + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") - if [ $# -lt 1 ]; then - __print_err " []*|NOID" $@ - return 1 + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi fi ((RES_PASS++)) diff --git a/test/common/prodstub_api_functions.sh b/test/common/prodstub_api_functions.sh new file mode 100644 index 00000000..b41c79b1 --- /dev/null +++ b/test/common/prodstub_api_functions.sh @@ -0,0 +1,210 @@ +#!/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================================================= +# + + +### Admin API functions producer stub + + +# 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 + 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 + return 1 + fi + status=${res:${#res}-3} + if [ $status -eq $2 ]; then + if [ $# -eq 4 ]; then + body=${res:0:${#res}-3} + jobfile=$(cat $4) + 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 + fi + fi + if [ $1 == "TEST" ]; then + echo -e $GREEN" PASS"$EGREEN + else + echo -e $GREEN" OK"$EGREEN + fi + return 0 + fi + echo -e $RED" FAIL - expected http response: "$2" but got http response: "$status $ERED + return 1 +} + +# Prodstub API: Set (or reset) response code for producer supervision +# [] +# (Function for test scripts) +prodstub_arm_supervision() { + echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + echo "CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG + if [ $# -ne 2 ] && [ $# -ne 3 ]; then + ((RES_CONF_FAIL++)) + __print_err " []" $@ + return 1 + fi + + curlString="curl -X PUT -skw %{http_code} $PROD_STUB_LOCALHOST/arm/supervision/"$2 + if [ $# -eq 3 ]; then + curlString=$curlString"?response="$3 + fi + + __execute_curl_to_prodstub CONF $1 "$curlString" + retcode=$? + if [ $? -ne 0 ]; then + ((RES_CONF_FAIL++)) + fi + return $retcode +} + +# Prodstub API: Set (or reset) response code job create +# [] +# (Function for test scripts) +prodstub_arm_create() { + echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + echo "CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG + if [ $# -ne 3 ] && [ $# -ne 4 ]; then + ((RES_CONF_FAIL++)) + __print_err " []" $@ + return 1 + fi + + curlString="curl -X PUT -skw %{http_code} $PROD_STUB_LOCALHOST/arm/create/$2/$3" + if [ $# -eq 4 ]; then + curlString=$curlString"?response="$4 + fi + + __execute_curl_to_prodstub CONF $1 "$curlString" + retcode=$? + if [ $? -ne 0 ]; then + ((RES_CONF_FAIL++)) + fi + return $retcode +} + +# Prodstub API: Set (or reset) response code job delete +# [] +# (Function for test scripts) +prodstub_arm_delete() { + echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + echo "CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG + if [ $# -ne 3 ] && [ $# -ne 4 ]; then + ((RES_CONF_FAIL++)) + __print_err " []" $@ + return 1 + fi + + curlString="curl -X PUT -skw %{http_code} $PROD_STUB_LOCALHOST/arm/delete/$2/$3" + if [ $# -eq 4 ]; then + curlString=$curlString"?response="$4 + fi + + __execute_curl_to_prodstub CONF $1 "$curlString" + retcode=$? + if [ $? -ne 0 ]; then + ((RES_CONF_FAIL++)) + fi + return $retcode +} + +# 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 + if [ $# -ne 3 ]; then + ((RES_CONF_FAIL++)) + __print_err " " $@ + return 1 + fi + + 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 +} + +# 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 + if [ $# -ne 3 ]; then + ((RES_CONF_FAIL++)) + __print_err " " $@ + return 1 + fi + + 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 +} + +# 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 + if [ $# -ne 6 ]; then + ((RES_FAIL++)) + __print_err " " $@ + return 1 + fi + if [ -f $6 ]; then + 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 + return 1 + fi + targetJson="{\"ei_job_identity\":\"$3\",\"ei_type_identity\":\"$4\",\"target_uri\":\"$5\",\"ei_job_data\":$jobfile}" + file="./tmp/.p.json" + echo "$targetJson" > $file + + 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 +} \ No newline at end of file diff --git a/test/common/ricsimulator_api_functions.sh b/test/common/ricsimulator_api_functions.sh index f0035592..67a398e1 100644 --- a/test/common/ricsimulator_api_functions.sh +++ b/test/common/ricsimulator_api_functions.sh @@ -22,13 +22,10 @@ # Excute a curl cmd towards a ricsimulator and check the response code. -# args: [] +# args: __execute_curl_to_sim() { echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG echo " CMD: $2" >> $HTTPLOG - if [ $# -eq 3 ]; then - echo " FILE: $(<$3)" >> $HTTPLOG - fi res="$($2)" echo " RESP: $res" >> $HTTPLOG retcode=$? @@ -118,7 +115,7 @@ sim_put_policy_type() { 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" $4 + __execute_curl_to_sim $1 "$curlString" return $? } diff --git a/test/common/test_env.sh b/test/common/test_env.sh index 56d75839..e86f8349 100755 --- a/test/common/test_env.sh +++ b/test/common/test_env.sh @@ -89,6 +89,11 @@ CR_LOCAL_IMAGE="callback-receiver" CR_LOCAL_IMAGE_TAG="latest" #No remote image for CR, local image always used +#Producer stub image and tag +PROD_STUB_LOCAL_IMAGE="producer-stub" +PROD_STUB_LOCAL_IMAGE_TAG="latest" +#No remote image for producer stub, local image always used + # Common env var for auto-test. Vars used by docker-compose need to be exported export DOCKER_SIM_NWNAME="nonrtric-docker-net" # Name of docker private network @@ -107,8 +112,8 @@ export ECS_EXTERNAL_SECURE_PORT=8434 # ECS container export ECS_INTERNAL_SECURE_PORT=8434 # ECS container internal secure port (container -> container) export ECS_APP_NAME="ecs" # Name for ECS container -ECS_LOGPATH="/var/log/ecs/application.log" # Path the application log in the ECS container -export ECS_APP_NAME_ALIAS="ecs-container" # Alias name, name used by the control panel +ECS_LOGPATH="/var/log/enrichment-coordinator-service/application.log" # Path the application log in the ECS container +export ECS_APP_NAME_ALIAS="enrichment-service-container" # Alias name, name used by the control panel export MR_EXTERNAL_PORT=3905 # MR stub container external port (host -> container) export MR_INTERNAL_PORT=3905 # MR stub container internal port (container -> container) @@ -124,6 +129,12 @@ export CR_EXTERNAL_SECURE_PORT=8091 # Callback recei export CR_INTERNAL_SECURE_PORT=8091 # Callback receiver container internal secure port (container -> container) export CR_APP_NAME="callback-receiver" # Name for the Callback receiver +export PROD_STUB_EXTERNAL_PORT=8092 # Producer stub container external port (host -> container) +export PROD_STUB_INTERNAL_PORT=8092 # Producer stub container internal port (container -> container) +export PROD_STUB_EXTERNAL_SECURE_PORT=8093 # Producer stub container external secure port (host -> container) +export PROD_STUB_INTERNAL_SECURE_PORT=8093 # Producer stub container internal secure port (container -> container) +export PROD_STUB_APP_NAME="producer-stub" # Name for the Producer stub + export CONSUL_HOST="consul-server" # Host name of consul export CONSUL_EXTERNAL_PORT=8500 # Consul container external port (host -> container) export CONSUL_INTERNAL_PORT=8500 # Consul container internal port (container -> container) diff --git a/test/common/testcase_common.sh b/test/common/testcase_common.sh index a90700aa..ed02c7b1 100755 --- a/test/common/testcase_common.sh +++ b/test/common/testcase_common.sh @@ -114,6 +114,12 @@ if [ ! -d "logs" ]; then fi TESTLOGS=$PWD/logs +# Create the tmp dir for temporary files that is not needed after the test +# hidden files for the test env is still stored in the current dir +if [ ! -d "tmp" ]; then + mkdir tmp +fi + # Create a http message log for this testcase HTTPLOG=$PWD"/.httplog_"$ATC".txt" echo "" > $HTTPLOG @@ -278,6 +284,11 @@ export CR_HTTPX="http" export CR_PORT=$CR_INTERNAL_PORT export CR_LOCAL_PORT=$CR_EXTERNAL_PORT #When CR is running outside the docker net +export PROD_STUB_HTTPX="http" +export PROD_STUB_PORT=$PROD_STUB_INTERNAL_PORT +export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_PORT #When CR is running outside the docker net +export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT + export SDNC_HTTPX="http" export SDNC_PORT=$SDNC_INTERNAL_PORT export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT #When agent is running outside the docker net @@ -287,7 +298,7 @@ echo -e $BOLD"Checking configured image setting for this test case"$EBOLD #Temp var to check for image variable name errors IMAGE_ERR=0 #Create a file with image info for later printing as a table -image_list_file=".image-list" +image_list_file="./tmp/.image-list" echo -e " Container\tImage\ttag" > $image_list_file # Check if image env var is set and if so export the env var with image to use (used by docker compose files) @@ -298,7 +309,7 @@ __check_image_var() { ((IMAGE_ERR++)) return fi - __check_excluded_image $6 + __check_included_image $6 if [ $? -ne 0 ]; then echo -e "$1\t\t" >> $image_list_file # Image is excluded since the corresponding app is not used in this test @@ -344,15 +355,16 @@ __check_image_local_override() { return 0 } -#Check if app uses image excluded from this test run -# Possible IDs for image exclusion: PA, CP, SDNC, RICSIM, MR, CR, CBS, CONSUL, ECS -__check_excluded_image() { - for im in $EXCLUDED_IMAGES; do +# Check if app uses image included in this test run +# Returns 0 if image is included, 1 if not +# Possible IDs for image inclusion: CBS, CONSUL, CP, CR, ECS, MR, PA, PRODSTUB, RICSIM, SDNC +__check_included_image() { + for im in $INCLUDED_IMAGES; do if [ "$1" == "$im" ]; then - return 1 + return 0 fi done - return 0 + return 1 } # Check that image env setting are available @@ -429,6 +441,7 @@ fi # These images are not built as part of this project official images, just check that env vars are set correctly __check_image_var " Message Router" $START_ARG "MRSTUB_IMAGE" "MRSTUB_LOCAL_IMAGE" "MRSTUB_LOCAL_IMAGE_TAG" MR __check_image_var " Callback Receiver" $START_ARG "CR_IMAGE" "CR_LOCAL_IMAGE" "CR_LOCAL_IMAGE_TAG" CR +__check_image_var " Producer stub" $START_ARG "PROD_STUB_IMAGE" "PROD_STUB_LOCAL_IMAGE" "PROD_STUB_LOCAL_IMAGE_TAG" PRODSTUB __check_image_var " Consul" $START_ARG "CONSUL_IMAGE" "CONSUL_REMOTE_IMAGE" "CONSUL_REMOTE_IMAGE_TAG" CONSUL __check_image_var " CBS" $START_ARG "CBS_IMAGE" "CBS_REMOTE_IMAGE" "CBS_REMOTE_IMAGE_TAG" CBS __check_image_var " SDNC DB" $START_ARG "SDNC_DB_IMAGE" "SDNC_DB_REMOTE_IMAGE" "SDNC_DB_REMOTE_IMAGE_TAG" SDNC #Uses sdnc app name @@ -489,24 +502,24 @@ __check_and_pull_image() { echo -ne " Attempt to stop and remove container(s), if running - ${SAMELINE}" tmp="$(docker ps -aq --filter name=${3})" if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then - docker stop $tmp &> .dockererr + docker stop $tmp &> ./tmp/.dockererr if [ $? -ne 0 ]; then ((IMAGE_ERR++)) echo "" echo -e $RED" Container(s) could not be stopped - try manual stopping the container(s)"$ERED - cat .dockererr + cat ./tmp/.dockererr return 1 fi fi echo -ne " Attempt to stop and remove container(s), if running - "$GREEN"stopped"$EGREEN"${SAMELINE}" tmp="$(docker ps -aq --filter name=${3})" &> /dev/null if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then - docker rm $tmp &> .dockererr + docker rm $tmp &> ./tmp/.dockererr if [ $? -ne 0 ]; then ((IMAGE_ERR++)) echo "" echo -e $RED" Container(s) could not be removed - try manual removal of the container(s)"$ERED - cat .dockererr + cat ./tmp/.dockererr return 1 fi fi @@ -514,12 +527,12 @@ __check_and_pull_image() { echo -ne " Removing image - ${SAMELINE}" tmp="$(docker images -q ${4})" &> /dev/null if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then - docker rmi --force $4 &> .dockererr + docker rmi --force $4 &> ./tmp/.dockererr if [ $? -ne 0 ]; then ((IMAGE_ERR++)) echo "" echo -e $RED" Image could not be removed - try manual removal of the image"$ERED - cat .dockererr + cat ./tmp/.dockererr return 1 fi echo -e " Removing image - "$GREEN"removed"$EGREEN @@ -530,13 +543,13 @@ __check_and_pull_image() { fi if [ -z "$tmp_im" ]; then echo -ne " Pulling image${SAMELINE}" - docker pull $4 &> .dockererr + docker pull $4 &> ./tmp/.dockererr tmp_im=$(docker images ${4} | grep -v REPOSITORY) if [ -z "$tmp_im" ]; then echo "" echo -e " Pulling image -$RED could not be pulled"$ERED ((IMAGE_ERR++)) - cat .dockererr + cat ./tmp/.dockererr return 1 fi echo -e " Pulling image -$GREEN Pulled $EGREEN" @@ -550,7 +563,7 @@ __check_and_pull_image() { echo -e $BOLD"Pulling configured images, if needed"$EBOLD -__check_excluded_image 'PA' +__check_included_image 'PA' if [ $? -eq 0 ]; then START_ARG_MOD=$START_ARG __check_image_local_override 'PA' @@ -562,7 +575,7 @@ else echo -e $YELLOW" Excluding PA image from image check/pull"$EYELLOW fi -__check_excluded_image 'ECS' +__check_included_image 'ECS' if [ $? -eq 0 ]; then START_ARG_MOD=$START_ARG __check_image_local_override 'ECS' @@ -574,7 +587,7 @@ else echo -e $YELLOW" Excluding ECS image from image check/pull"$EYELLOW fi -__check_excluded_image 'CP' +__check_included_image 'CP' if [ $? -eq 0 ]; then START_ARG_MOD=$START_ARG __check_image_local_override 'CP' @@ -586,7 +599,7 @@ else echo -e $YELLOW" Excluding Non-RT RIC Control Panel image from image check/pull"$EYELLOW fi -__check_excluded_image 'RICSIM' +__check_included_image 'RICSIM' if [ $? -eq 0 ]; then START_ARG_MOD=$START_ARG __check_image_local_override 'RICSIM' @@ -599,21 +612,21 @@ else fi -__check_excluded_image 'CONSUL' +__check_included_image 'CONSUL' if [ $? -eq 0 ]; then app="Consul"; __check_and_pull_image $START_ARG "$app" $CONSUL_APP_NAME $CONSUL_IMAGE else echo -e $YELLOW" Excluding Consul image from image check/pull"$EYELLOW fi -__check_excluded_image 'CBS' +__check_included_image 'CBS' if [ $? -eq 0 ]; then app="CBS"; __check_and_pull_image $START_ARG "$app" $CBS_APP_NAME $CBS_IMAGE else echo -e $YELLOW" Excluding CBS image from image check/pull"$EYELLOW fi -__check_excluded_image 'SDNC' +__check_included_image 'SDNC' if [ $? -eq 0 ]; then START_ARG_MOD=$START_ARG __check_image_local_override 'SDNC' @@ -642,12 +655,12 @@ echo "" echo -e $BOLD"Building images needed for test"$EBOLD curdir=$PWD -__check_excluded_image 'MR' +__check_included_image 'MR' if [ $? -eq 0 ]; then cd $curdir cd ../mrstub - echo " Building mrstub image: mrstub:latest" - docker build -t mrstub . &> .dockererr + echo " Building mrstub image: $MRSTUB_LOCAL_IMAGE:$MRSTUB_LOCAL_IMAGE_TAG" + docker build -t $MRSTUB_LOCAL_IMAGE . &> .dockererr if [ $? -eq 0 ]; then echo -e $GREEN" Build Ok"$EGREEN else @@ -660,11 +673,11 @@ else echo -e $YELLOW" Excluding mrstub from image build"$EYELLOW fi -__check_excluded_image 'CR' +__check_included_image 'CR' if [ $? -eq 0 ]; then cd ../cr - echo " Building Callback Receiver image: callback-receiver:latest" - docker build -t callback-receiver . &> .dockererr + echo " Building Callback Receiver image: $CR_LOCAL_IMAGE:$CR_IMAGE_TAG" + docker build -t $CR_LOCAL_IMAGE . &> .dockererr if [ $? -eq 0 ]; then echo -e $GREEN" Build Ok"$EGREEN else @@ -677,47 +690,68 @@ else echo -e $YELLOW" Excluding Callback Receiver from image build"$EYELLOW fi +__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 + if [ $? -eq 0 ]; then + echo -e $GREEN" Build Ok"$EGREEN + else + echo -e $RED" Build Failed"$ERED + ((RES_CONF_FAIL++)) + cat .dockererr + fi + cd $curdir +else + echo -e $YELLOW" Excluding Producer stub from image build"$EYELLOW +fi + echo "" # Create a table of the images used in the script echo -e $BOLD"Local docker registry images used in the this test script"$EBOLD -docker_tmp_file=.docker-images-table +docker_tmp_file=./tmp/.docker-images-table format_string="{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\\t{{.CreatedAt}}" echo -e " Application\tRepository\tTag\tCreated since\tSize\tCreated at" > $docker_tmp_file -__check_excluded_image 'PA' +__check_included_image 'PA' if [ $? -eq 0 ]; then echo -e " Policy Agent\t$(docker images --format $format_string $POLICY_AGENT_IMAGE)" >> $docker_tmp_file fi -__check_excluded_image 'ECS' +__check_included_image 'ECS' if [ $? -eq 0 ]; then echo -e " ECS\t$(docker images --format $format_string $ECS_IMAGE)" >> $docker_tmp_file fi -__check_excluded_image 'CP' +__check_included_image 'CP' if [ $? -eq 0 ]; then echo -e " Control Panel\t$(docker images --format $format_string $CONTROL_PANEL_IMAGE)" >> $docker_tmp_file fi -__check_excluded_image 'RICSIM' +__check_included_image 'RICSIM' if [ $? -eq 0 ]; then echo -e " RIC Simulator\t$(docker images --format $format_string $RIC_SIM_IMAGE)" >> $docker_tmp_file fi -__check_excluded_image 'MR' +__check_included_image 'MR' if [ $? -eq 0 ]; then echo -e " Message Router\t$(docker images --format $format_string $MRSTUB_IMAGE)" >> $docker_tmp_file fi -__check_excluded_image 'CR' +__check_included_image 'CR' if [ $? -eq 0 ]; then echo -e " Callback Receiver\t$(docker images --format $format_string $CR_IMAGE)" >> $docker_tmp_file fi -__check_excluded_image 'CONSUL' +__check_included_image 'PRODSTUB' +if [ $? -eq 0 ]; then + echo -e " Produccer stub\t$(docker images --format $format_string $PROD_STUB_IMAGE)" >> $docker_tmp_file +fi +__check_included_image 'CONSUL' if [ $? -eq 0 ]; then echo -e " Consul\t$(docker images --format $format_string $CONSUL_IMAGE)" >> $docker_tmp_file fi -__check_excluded_image 'CBS' +__check_included_image 'CBS' if [ $? -eq 0 ]; then echo -e " CBS\t$(docker images --format $format_string $CBS_IMAGE)" >> $docker_tmp_file fi -__check_excluded_image 'SDNC' +__check_included_image 'SDNC' if [ $? -eq 0 ]; then echo -e " SDNC A1 Controller\t$(docker images --format $format_string $SDNC_A1_CONTROLLER_IMAGE)" >> $docker_tmp_file echo -e " SDNC DB\t$(docker images --format $format_string $SDNC_DB_IMAGE)" >> $docker_tmp_file @@ -934,6 +968,7 @@ clean_containers() { "Non-RT RIC Simulator(s)" $(__check_app_name $RIC_SIM_PREFIX)\ "Message Router " $(__check_app_name $MR_APP_NAME)\ "Callback Receiver " $(__check_app_name $CR_APP_NAME)\ + "Producer stub " $(__check_app_name $PROD_STUB_APP_NAME)\ "Control Panel " $(__check_app_name $CONTROL_PANEL_APP_NAME)\ "SDNC A1 Controller " $(__check_app_name $SDNC_APP_NAME)\ "SDNC DB " $(__check_app_name $SDNC_DB_APP_NAME)\ @@ -975,21 +1010,17 @@ clean_containers() { fi fi echo -e "$GREEN Done$EGREEN" - echo "" echo -e $BOLD" Removing all unused docker neworks"$EBOLD docker network prune --force | indent2 echo -e "$GREEN Done$EGREEN" - echo "" echo -e $BOLD" Removing all unused docker volumes"$EBOLD docker volume prune --force | indent2 echo -e "$GREEN Done$EGREEN" - echo "" echo -e $BOLD" Removing all dangling/untagged docker images"$EBOLD docker rmi --force $(docker images -q -f dangling=true) &> /dev/null - echo "" echo -e "$GREEN Done$EGREEN" echo "" @@ -1247,14 +1278,15 @@ consul_config_app() { echo " Loading config for "$POLICY_AGENT_APP_NAME" from "$1 - curl -s $LOCALHOST${CONSUL_EXTERNAL_PORT}/v1/kv/${POLICY_AGENT_APP_NAME}?dc=dc1 -X PUT -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'X-Requested-With: XMLHttpRequest' --data-binary "@"$1 >/dev/null + curlString="$LOCALHOST${CONSUL_EXTERNAL_PORT}/v1/kv/${POLICY_AGENT_APP_NAME}?dc=dc1 -X PUT -H Accept:application/json -H Content-Type:application/json -H X-Requested-With:XMLHttpRequest --data-binary @"$1 + result=$(__do_curl "$curlString") if [ $? -ne 0 ]; then echo -e $RED" FAIL - json config could not be loaded to consul" $ERED ((RES_CONF_FAIL++)) return 1 fi body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)" - echo $body > ".output"$1 + echo $body > "./tmp/.output"$1 if [ $? -ne 0 ]; then echo -e $RED" FAIL - json config could not be loaded from consul/cbs, contents cannot be checked." $ERED @@ -1392,7 +1424,7 @@ prepare_consul_config() { start_consul_cbs() { echo -e $BOLD"Starting Consul and CBS"$EBOLD - __check_excluded_image 'CONSUL' + __check_included_image 'CONSUL' if [ $? -eq 1 ]; then echo -e $RED"The Consul image has not been checked for this test run due to arg to the test script"$ERED echo -e $RED"Consul will not be started"$ERED @@ -1430,7 +1462,7 @@ start_ric_simulators() { echo -e $BOLD"Starting RIC Simulators"$EBOLD - __check_excluded_image 'RICSIM' + __check_included_image 'RICSIM' if [ $? -eq 1 ]; then echo -e $RED"The Near-RT RIC Simulator image has not been checked for this test run due to arg to the test script"$ERED echo -e $RED"The Near-RT RIC Simulartor(s) will not be started"$ERED @@ -1493,7 +1525,7 @@ start_ric_simulators() { start_control_panel() { echo -e $BOLD"Starting Control Panel"$EBOLD - __check_excluded_image 'CP' + __check_included_image 'CP' if [ $? -eq 1 ]; then echo -e $RED"The Control Panel image has not been checked for this test run due to arg to the test script"$ERED echo -e $RED"The Control Panel will not be started"$ERED @@ -1514,7 +1546,7 @@ start_sdnc() { echo -e $BOLD"Starting SDNC A1 Controller"$EBOLD - __check_excluded_image 'SDNC' + __check_included_image 'SDNC' if [ $? -eq 1 ]; then echo -e $RED"The image for SDNC and the related DB has not been checked for this test run due to arg to the test script"$ERED echo -e $RED"SDNC will not be started"$ERED @@ -1551,7 +1583,7 @@ use_sdnc_https() { start_mr() { echo -e $BOLD"Starting Message Router 'mrstub'"$EBOLD - __check_excluded_image 'MR' + __check_included_image 'MR' if [ $? -eq 1 ]; then echo -e $RED"The Message Router image has not been checked for this test run due to arg to the test script"$ERED echo -e $RED"The Message Router will not be started"$ERED @@ -1588,7 +1620,7 @@ use_mr_https() { start_cr() { echo -e $BOLD"Starting Callback Receiver"$EBOLD - __check_excluded_image 'CR' + __check_included_image 'CR' if [ $? -eq 1 ]; then echo -e $RED"The Callback Receiver image has not been checked for this test run due to arg to the test script"$ERED echo -e $RED"The Callback Receiver will not be started"$ERED @@ -1614,6 +1646,44 @@ use_cr_https() { echo "" } +########################### +### Producer stub functions +########################### + +# Start the Producer stub in the simulator group +# args: - +# (Function for test scripts) +start_prod_stub() { + + echo -e $BOLD"Starting Producer stub"$EBOLD + __check_included_image 'PRODSTUB' + if [ $? -eq 1 ]; then + echo -e $RED"The Producer stub image has not been checked for this test run due to arg to the test script"$ERED + echo -e $RED"The Producer stub will not be started"$ERED + exit + fi + __start_container prodstub NODOCKERARGS $PROD_STUB_APP_NAME $PROD_STUB_EXTERNAL_PORT "/" "http" + +} + +use_prod_stub_http() { + 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 + export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT + echo "" +} + +use_prod_stub_https() { + 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 + export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT + echo "" +} + ########################### ### Policy Agents functions ########################### @@ -1631,7 +1701,7 @@ start_policy_agent() { echo -e $BOLD"Starting Policy Agent"$EBOLD if [ $AGENT_STAND_ALONE -eq 0 ]; then - __check_excluded_image 'PA' + __check_included_image 'PA' if [ $? -eq 1 ]; then echo -e $RED"The Policy Agent image has not been checked for this test run due to arg to the test script"$ERED echo -e $RED"The Policy Agent will not be started"$ERED @@ -1695,9 +1765,11 @@ use_agent_dmaap_https() { # (Function for test scripts) set_agent_debug() { echo -e $BOLD"Setting agent debug"$EBOLD - curl $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT/actuator/loggers/org.oransc.policyagent -X POST -H 'Content-Type: application/json' -d '{"configuredLevel":"debug"}' &> /dev/null + curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT/actuator/loggers/org.oransc.policyagent -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}" + result=$(__do_curl "$curlString") if [ $? -ne 0 ]; then __print_err "could not set debug mode" $@ + ((RES_CONF_FAIL++)) return 1 fi echo "" @@ -1709,9 +1781,11 @@ set_agent_debug() { # (Function for test scripts) set_agent_trace() { echo -e $BOLD"Setting agent trace"$EBOLD - curl $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT/actuator/loggers/org.oransc.policyagent -X POST -H 'Content-Type: application/json' -d '{"configuredLevel":"trace"}' &> /dev/null + curlString="$LOCALHOST$POLICY_AGENT_EXTERNAL_PORT/actuator/loggers/org.oransc.policyagent -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}" + result=$(__do_curl "$curlString") if [ $? -ne 0 ]; then __print_err "could not set trace mode" $@ + ((RES_CONF_FAIL++)) return 1 fi echo "" @@ -1738,14 +1812,14 @@ use_agent_retries() { start_ecs() { echo -e $BOLD"Starting ECS"$EBOLD - __check_excluded_image 'ECS' + __check_included_image 'ECS' if [ $? -eq 1 ]; then echo -e $RED"The ECS image has not been checked for this test run due to arg to the test script"$ERED echo -e $RED"ECS will not be started"$ERED exit fi export ECS_CERT_MOUNT_DIR="./cert" - __start_container ecs NODOCKERARGS $ECS_APP_NAME $ECS_EXTERNAL_PORT "/ei-producer/v1/eiproducers" "http" + __start_container ecs NODOCKERARGS $ECS_APP_NAME $ECS_EXTERNAL_PORT "/status" "http" } # All calls to ECS will be directed to the ECS REST interface from now on @@ -1792,9 +1866,11 @@ use_ecs_dmaap_https() { # (Function for test scripts) set_ecs_debug() { echo -e $BOLD"Setting ecs debug"$EBOLD - curl $LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H 'Content-Type: application/json' -d '{"configuredLevel":"debug"}' &> /dev/null + 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 - __print_err "could not set debug mode" $@ + __print_err "Could not set debug mode" $@ + ((RES_CONF_FAIL++)) return 1 fi echo "" @@ -1805,10 +1881,12 @@ set_ecs_debug() { # args: - # (Function for test scripts) set_ecs_trace() { - echo -e $BOLD"Setting agent trace"$EBOLD - curl $LOCALHOST$ECS_EXTERNAL_PORT/actuator/loggers/org.oransc.enrichment -X POST -H 'Content-Type: application/json' -d '{"configuredLevel":"trace"}' &> /dev/null + echo -e $BOLD"Setting ecs trace"$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 - __print_err "could not set trace mode" $@ + __print_err "Could not set trace mode" $@ + ((RES_CONF_FAIL++)) return 1 fi echo "" @@ -1834,21 +1912,28 @@ use_agent_retries() { # (Function for test scripts) check_policy_agent_logs() { - __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH + __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR } check_ecs_logs() { - __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH + __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR } check_control_panel_logs() { - __check_container_logs "Control Panel" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_LOGPATH + __check_container_logs "Control Panel" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_LOGPATH WARN ERR +} + +check_sdnc_logs() { + __check_container_logs "SDNC A1 Controller" $SDNC_APP_NAME $SDNC_KARAF_LOG WARN ERROR } __check_container_logs() { dispname=$1 appname=$2 logpath=$3 + warning=$4 + error=$5 + echo -e $BOLD"Checking $dispname container $appname log ($logpath) for WARNINGs and ERRORs"$EBOLD #tmp=$(docker ps | grep $appname) @@ -1857,7 +1942,7 @@ __check_container_logs() { echo $dispname" is not running, no check made" return fi - foundentries="$(docker exec $tmp grep WARN $logpath | wc -l)" + foundentries="$(docker exec -t $tmp grep $warning $logpath | wc -l)" if [ $? -ne 0 ];then echo " Problem to search $appname log $logpath" else @@ -1867,7 +1952,7 @@ __check_container_logs() { echo -e " Found \033[1m"$foundentries"\033[0m WARN entries in $appname log $logpath" fi fi - foundentries="$(docker exec $tmp grep ERR $logpath | wc -l)" + foundentries="$(docker exec -t $tmp grep $error $logpath | wc -l)" if [ $? -ne 0 ];then echo " Problem to search $appname log $logpath" else @@ -1893,43 +1978,84 @@ store_logs() { echo -e $BOLD"Storing all container logs using prefix: "$1$EBOLD docker stats --no-stream > $TESTLOGS/$ATC/$1_docker_stats.log 2>&1 - docker logs $CONSUL_APP_NAME > $TESTLOGS/$ATC/$1_consul.log 2>&1 - docker logs $CBS_APP_NAME > $TESTLOGS/$ATC/$1_cbs.log 2>&1 - docker logs $POLICY_AGENT_APP_NAME > $TESTLOGS/$ATC/$1_policy-agent.log 2>&1 - docker logs $ECS_APP_NAME > $TESTLOGS/$ATC/$1_ecs.log 2>&1 - docker logs $CONTROL_PANEL_APP_NAME > $TESTLOGS/$ATC/$1_control-panel.log 2>&1 - docker logs $MR_APP_NAME > $TESTLOGS/$ATC/$1_mr.log 2>&1 - docker logs $CR_APP_NAME > $TESTLOGS/$ATC/$1_cr.log 2>&1 + + __check_included_image 'CONSUL' + if [ $? -eq 0 ]; then + docker logs $CONSUL_APP_NAME > $TESTLOGS/$ATC/$1_consul.log 2>&1 + fi + + __check_included_image 'CBS' + if [ $? -eq 0 ]; then + docker logs $CBS_APP_NAME > $TESTLOGS/$ATC/$1_cbs.log 2>&1 + body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)" + echo "$body" > $TESTLOGS/$ATC/$1_consul_config.json 2>&1 + fi + + __check_included_image 'PA' + if [ $? -eq 0 ]; then + docker logs $POLICY_AGENT_APP_NAME > $TESTLOGS/$ATC/$1_policy-agent.log 2>&1 + fi + + __check_included_image 'ECS' + if [ $? -eq 0 ]; then + docker logs $ECS_APP_NAME > $TESTLOGS/$ATC/$1_ecs.log 2>&1 + fi + + __check_included_image 'CP' + if [ $? -eq 0 ]; then + docker logs $CONTROL_PANEL_APP_NAME > $TESTLOGS/$ATC/$1_control-panel.log 2>&1 + fi + + __check_included_image 'MR' + if [ $? -eq 0 ]; then + docker logs $MR_APP_NAME > $TESTLOGS/$ATC/$1_mr.log 2>&1 + fi + + __check_included_image 'CR' + if [ $? -eq 0 ]; then + docker logs $CR_APP_NAME > $TESTLOGS/$ATC/$1_cr.log 2>&1 + fi + cp .httplog_${ATC}.txt $TESTLOGS/$ATC/$1_httplog_${ATC}.txt 2>&1 - docker exec $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $TESTLOGS/$ATC/$1_SDNC_karaf.log 2>&1 + __check_included_image 'SDNC' + if [ $? -eq 0 ]; then + docker exec -t $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $TESTLOGS/$ATC/$1_SDNC_karaf.log 2>&1 + fi + + __check_included_image 'RICSIM' + if [ $? -eq 0 ]; then + rics=$(docker ps -f "name=$RIC_SIM_PREFIX" --format "{{.Names}}") + for ric in $rics; do + docker logs $ric > $TESTLOGS/$ATC/$1_$ric.log 2>&1 + done + fi - rics=$(docker ps -f "name=$RIC_SIM_PREFIX" --format "{{.Names}}") - for ric in $rics; do - docker logs $ric > $TESTLOGS/$ATC/$1_$ric.log 2>&1 - done - body="$(__do_curl $LOCALHOST$CBS_EXTERNAL_PORT/service_component_all/$POLICY_AGENT_APP_NAME)" - echo "$body" > $TESTLOGS/$ATC/$1_consul_config.json 2>&1 echo "" } ############### ## Generic curl ############### -# Generic curl function, assumed all 200-codes are ok -# args: +# Generic curl function, assumes all 200-codes are ok +# args: # returns: or "" or ">"" # returns: The return code is 0 for ok and 1 for not ok __do_curl() { echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG - curlString="curl -skw %{http_code} $1" + curlString="curl -skw %{http_code} $@" echo " CMD: $curlString" >> $HTTPLOG res=$($curlString) echo " RESP: $res" >> $HTTPLOG http_code="${res:${#res}-3}" if [ ${#res} -eq 3 ]; then - echo "" - return 1 + if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then + echo "" + return 1 + else + echo "X2" >> $HTTPLOG + return 0 + fi else if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then echo "" @@ -1978,8 +2104,8 @@ __var_test() { path=${3:5} result="$(__do_curl $2$path)" retcode=$? - echo "$result" > .tmp.curl.json - result=$(python3 ../common/count_json_elements.py ".tmp.curl.json") + echo "$result" > ./tmp/.tmp.curl.json + result=$(python3 ../common/count_json_elements.py "./tmp/.tmp.curl.json") fi duration=$((SECONDS-start)) echo -ne " Result=${result} after ${duration} seconds${SAMELINE}" @@ -2036,8 +2162,8 @@ __var_test() { path=${3:5} result="$(__do_curl $2$path)" retcode=$? - echo "$result" > .tmp.curl.json - result=$(python3 ../common/count_json_elements.py ".tmp.curl.json") + echo "$result" > ./tmp/.tmp.curl.json + result=$(python3 ../common/count_json_elements.py "./tmp/.tmp.curl.json") fi if [ $retcode -ne 0 ]; then ((RES_FAIL++)) diff --git a/test/prodstub/.gitignore b/test/prodstub/.gitignore new file mode 100644 index 00000000..4aa3a7ae --- /dev/null +++ b/test/prodstub/.gitignore @@ -0,0 +1,2 @@ +.tmp.json +.dockererr \ No newline at end of file diff --git a/test/prodstub/Dockerfile b/test/prodstub/Dockerfile new file mode 100644 index 00000000..bdc3521d --- /dev/null +++ b/test/prodstub/Dockerfile @@ -0,0 +1,33 @@ +# ============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================================================= +# + +FROM python:3.8-slim-buster + +COPY app/ /usr/src/app/ +COPY cert/ /usr/src/app/cert/ + +WORKDIR /usr/src/app + +RUN pip install -r requirements.txt + +RUN chmod +x start.sh + +#install nginx +RUN apt-get update +RUN apt-get install -y nginx=1.14.* + +CMD [ "./start.sh" ] diff --git a/test/prodstub/README.md b/test/prodstub/README.md new file mode 100644 index 00000000..aa23b78c --- /dev/null +++ b/test/prodstub/README.md @@ -0,0 +1,46 @@ +## producer stub - a stub interface to simulate data producers ## + +The producer stub is intended for function tests to simulate data producers. + + +# Ports and certificates +TBD + +| Port | Protocol | +| -------- | ----- | +| 8092 | http | +| 8093 | https | + + + +### Control interface ### + +TBD + + +### Build and start ### + +>Build image
+```docker build -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``` + +It will listen to http 8092 port and https 8093 port(using default certificates) at the same time. + +TBD + +## License + +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. \ No newline at end of file diff --git a/test/prodstub/app/job-schema.json b/test/prodstub/app/job-schema.json new file mode 100644 index 00000000..16620669 --- /dev/null +++ b/test/prodstub/app/job-schema.json @@ -0,0 +1,20 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "EI Job Schema", + "description": "Schema for EI Job", + "type": "object", + "properties": { + "ei_job_identity": { + "type": "string" + }, + "ei_type_identity": { + "type": "string" + }, + "target_uri": { + "type": "string" + }, + "ei_job_data": { + "type": "object" + } + } + } \ No newline at end of file diff --git a/test/prodstub/app/nginx.conf b/test/prodstub/app/nginx.conf new file mode 100644 index 00000000..8119b0d5 --- /dev/null +++ b/test/prodstub/app/nginx.conf @@ -0,0 +1,100 @@ +user www-data; +worker_processes auto; +pid /run/nginx.pid; +include /etc/nginx/modules-enabled/*.conf; + +events { + worker_connections 768; + # multi_accept on; +} + +http { + + ## + # Basic Settings + ## + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + # server_tokens off; + + # server_names_hash_bucket_size 64; + # server_name_in_redirect off; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + server { # simple reverse-proxy + listen 8092; + listen [::]:8092; + listen 8093 ssl; + listen [::]:8093 ssl; + server_name localhost; + ssl_certificate /usr/src/app/cert/cert.crt; + ssl_certificate_key /usr/src/app/cert/key.crt; + ssl_password_file /usr/src/app/cert/pass; + + # serve dynamic requests + location / { + proxy_pass http://localhost:2222; + } + } + ## + # SSL Settings + ## + + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE + ssl_prefer_server_ciphers on; + + ## + # Logging Settings + ## + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + ## + # Gzip Settings + ## + + gzip on; + + # gzip_vary on; + # gzip_proxied any; + # gzip_comp_level 6; + # gzip_buffers 16 8k; + # gzip_http_version 1.1; + # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; + + ## + # Virtual Host Configs + ## + + include /etc/nginx/conf.d/*.conf; + include /etc/nginx/sites-enabled/*; +} + + +#mail { +# # See sample authentication script at: +# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript +# +# # auth_http localhost/auth.php; +# # pop3_capabilities "TOP" "USER"; +# # imap_capabilities "IMAP4rev1" "UIDPLUS"; +# +# server { +# listen localhost:110; +# protocol pop3; +# proxy on; +# } +# +# server { +# listen localhost:143; +# protocol imap; +# proxy on; +# } +#} diff --git a/test/prodstub/app/prodstub.py b/test/prodstub/app/prodstub.py new file mode 100644 index 00000000..c21a7ab3 --- /dev/null +++ b/test/prodstub/app/prodstub.py @@ -0,0 +1,463 @@ + +# ============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================================================= +# + +from flask import Flask +from flask import request + +import json +from jsonschema import validate + +app = Flask(__name__) + +# # list of callback messages +# msg_callbacks={} + +# Server info +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_SUPERVISION_URL="/callbacks/supervision/" + +ARM_CREATE_RESPONSE="/arm/create//" +ARM_DELETE_RESPONSE="/arm/delete//" +ARM_SUPERVISION_RESPONSE="/arm/supervision/" +ARM_TYPE="/arm/type//" + +COUNTER_SUPERVISION="/counter/supervision/" +COUNTER_CREATE="/counter/create//" +COUNTER_DELETE="/counter/delete//" + +JOB_DATA="/jobdata//" + +STATUS="/status" + +#Constsants +APPL_JSON='application/json' +UNKNOWN_QUERY_PARAMETERS="Unknown query parameter(s)" +RETURNING_CONFIGURED_RESP="returning configured response code" +JOBID_NO_MATCH="job id in stored json does not match request" +PRODUCER_OR_JOB_NOT_FOUND="producer or job not found" +PRODUCER_NOT_FOUND="producer not found" +TYPE_NOT_FOUND="type not found" +TYPE_IN_USE="type is in use in a job" +JSON_CORRUPT="json in request is corrupt or missing" + +#Producer and job db, including armed responses +db={} +# producer +# armed response for supervision +# armed types +# supervision counter +# job +# job json +# armed response for create +# armed response for delete +# create counter +# delete counter + +# 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 +# if job_id is not None, the job level is setup and the job dict is returned (producer must exist) +def setup_callback_dict(producer_id, job_id): + + producer_dict=None + if (producer_id in db.keys()): + producer_dict=db[producer_id] + else: + if (job_id is not None): + return None + producer_dict={} + db[producer_id]=producer_dict + + producer_dict['supervision_response']=200 + producer_dict['supervision_counter']=0 + producer_dict['types']=[] + + if (job_id is None): + return producer_dict + + job_dict=None + if (job_id in producer_dict.keys()): + job_dict=producer_dict[job_id] + else: + job_dict={} + producer_dict[job_id]=job_dict + job_dict['create_response']=201 + job_dict['delete_response']=404 + job_dict['json']=None + job_dict['create_counter']=0 + job_dict['delete_counter']=0 + return job_dict + + +# Helper function to get an entry from the callback db +# if job_id is None then only the producer dict is returned (or None if producer is not found) +# if job_id is not None, the job is returned (or None if producer/job is not found) +def get_callback_dict(producer_id, job_id): + + producer_dict=None + if (producer_id in db.keys()): + producer_dict=db[producer_id] + + if (job_id is None): + return producer_dict + + job_dict=None + if (job_id in producer_dict.keys()): + job_dict=producer_dict[job_id] + + return job_dict + +# Helper function find if a key/valye exist in the dictionay tree +# True if found +def recursive_search(s_dict, s_key, s_id): + for pkey in s_dict: + if (pkey == s_key) and (s_dict[pkey] == s_id): + return True + if (isinstance(s_dict[pkey], dict)): + recursive_search(s_dict[pkey], s_key, s_id) + + return False + +# I'm alive function +# response: always 200 +@app.route('/', + methods=['GET']) +def index(): + return 'OK', 200 + +# Arm the create callback with a response code +# Omitting the query parameter switch to response back to the standard 200/201 response +# URI and parameters (PUT): /arm/create//[?response=] +# Setting +# response: 200 (400 if incorrect query params) +@app.route(ARM_CREATE_RESPONSE, + methods=['PUT']) +def arm_create(producer_id, job_id): + + arm_response=request.args.get('response') + + if (arm_response is None): + if (len(request.args) != 0): + return UNKNOWN_QUERY_PARAMETERS,400 + else: + if (len(request.args) != 1): + return UNKNOWN_QUERY_PARAMETERS,400 + + print("Arm create received for producer: "+str(producer_id)+" and job: "+str(job_id)+" and response: "+str(arm_response)) + + job_dict=setup_callback_dict(producer_id, job_id) + + if (arm_response is None): #Reset the response depending if a job exists or not + if (job_dict['json'] is None): + job_dict['create_response']=201 + else: + job_dict['create_response']=200 + else: + job_dict['create_response']=arm_response + + return "",200 + +# Arm the delete callback with a response code +# Omitting the query parameter switch to response back to the standard 204 response +# URI and parameters (PUT): /arm/delete//[?response=] +# response: 200 (400 if incorrect query params) +@app.route(ARM_DELETE_RESPONSE, + methods=['PUT']) +def arm_delete(producer_id, job_id): + + arm_response=request.args.get('response') + + if (arm_response is None): + if (len(request.args) != 0): + return UNKNOWN_QUERY_PARAMETERS,400 + else: + if (len(request.args) != 1): + return UNKNOWN_QUERY_PARAMETERS,400 + + print("Arm delete received for producer: "+str(producer_id)+" and job: "+str(job_id)+" and response: "+str(arm_response)) + + arm_response=request.args.get('response') + + job_dict=setup_callback_dict(producer_id, job_id) + + if (arm_response is None): #Reset the response depening if a job exists or not + if (job_dict['json'] is None): + job_dict['delete_response']=404 + else: + job_dict['delete_response']=204 + else: + job_dict['delete_response']=arm_response + + return "",200 + +# Arm the supervision callback with a response code +# Omitting the query parameter switch to response back to the standard 200 response +# URI and parameters (PUT): /arm/supervision/[?response=] +# response: 200 (400 if incorrect query params) +@app.route(ARM_SUPERVISION_RESPONSE, + methods=['PUT']) +def arm_supervision(producer_id): + + arm_response=request.args.get('response') + + if (arm_response is None): + if (len(request.args) != 0): + return UNKNOWN_QUERY_PARAMETERS,400 + else: + if (len(request.args) != 1): + return UNKNOWN_QUERY_PARAMETERS,400 + + print("Arm supervision received for producer: "+str(producer_id)+" and response: "+str(arm_response)) + + producer_dict=setup_callback_dict(producer_id, None) + if (arm_response is None): + producer_dict['supervision_response']=200 + else: + producer_dict['supervision_response']=arm_response + + return "",200 + +# Arm a producer with a type +# URI and parameters (PUT): /arm/type// +# response: 200 (404) +@app.route(ARM_TYPE, + methods=['PUT']) +def arm_type(producer_id, type_id): + + print("Arm type received for producer: "+str(producer_id)+" and type: "+str(type_id)) + + producer_dict=get_callback_dict(producer_id, None) + + if (producer_dict is None): + return PRODUCER_NOT_FOUND,404 + + type_list=producer_dict['types'] + if (type_id not in type_list): + type_list.append(type_id) + + return "",200 + +# Disarm a producer with a type +# URI and parameters (DELETE): /arm/type// +# response: 200 (404) +@app.route(ARM_TYPE, + methods=['DELETE']) +def disarm_type(producer_id, type_id): + + print("Disarm type received for producer: "+str(producer_id)+" and type: "+str(type_id)) + + producer_dict=get_callback_dict(producer_id, None) + + if (producer_dict is None): + return PRODUCER_NOT_FOUND,404 + + if (recursive_search(producer_dict, "ei_job_type",type_id) is True): + return "TYPE_IN_USE",400 + + type_list=producer_dict['types'] + type_list.remove(type_id) + + return "",200 + +# Callback for create job +# URI and parameters (POST): /callbacks/create/ +# response 201 at create, 200 at update or other configured response code +@app.route(CALLBACK_CREATE_URL, + methods=['POST']) +def callback_create(producer_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 + + producer_dict=get_callback_dict(producer_id, None) + if (producer_dict is None): + return PRODUCER_OR_JOB_NOT_FOUND,400 + type_list=producer_dict['types'] + type_id=req_json_dict['ei_type_identity'] + if (type_id not in type_list): + return TYPE_NOT_FOUND + + 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("Create callback received for producer: "+str(producer_id)+" and job: "+str(job_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 + 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: + return_msg=RETURNING_CONFIGURED_RESP + + job_dict['create_counter']=job_dict['create_counter']+1 + else: + return JOBID_NO_MATCH, 400 + + return return_msg,return_code + +# Callback for delete job +# URI and parameters (POST): /callbacks/delete/ +# response: 204 at delete or other configured response code +@app.route(CALLBACK_DELETE_URL, + methods=['POST']) +def callback_delete(producer_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 + 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 + else: + return JOBID_NO_MATCH, 400 + + return return_msg, return_code + +# Callback for supervision of producer +# URI and parameters (GET): /callbacks/supervision/ +# response: 200 or other configured response code +@app.route(CALLBACK_SUPERVISION_URL, + methods=['GET']) +def callback_supervision(producer_id): + + print("Supervision callback received for producer: "+str(producer_id)) + + producer_dict=get_callback_dict(producer_id, None) + if (producer_dict is None): + return PRODUCER_NOT_FOUND,400 + return_code=producer_dict['supervision_response'] + return_msg="" + if (return_code != 200): + return_msg="returning configured response code" + + producer_dict['supervision_counter']=producer_dict['supervision_counter']+1 + + return return_msg,producer_dict['supervision_response'] + +# Callback for supervision of producer +# URI and parameters (GET): "/jobdata//" +# response: 200 or 204 +@app.route(JOB_DATA, + methods=['GET']) +def get_jobdata(producer_id, job_id): + + print("Get job data received for producer: "+str(producer_id)+" and job: "+str(job_id)) + + job_dict=setup_callback_dict(producer_id, job_id) + if (job_dict['json'] is None): + return "",204 + else: + return json.dumps(job_dict['json']), 200 + + +# Counter for create calls for a job +# URI and parameters (GET): "/counter/create//" +# response: 200 and counter value +@app.route(COUNTER_CREATE, + methods=['GET']) +def counter_create(producer_id, job_id): + job_dict=get_callback_dict(producer_id, job_id) + if (job_dict is None): + return -1,200 + return str(job_dict['create_counter']),200 + +# Counter for delete calls for a job +# URI and parameters (GET): "/counter/delete//" +# response: 200 and counter value +@app.route(COUNTER_DELETE, + methods=['GET']) +def counter_delete(producer_id, job_id): + job_dict=get_callback_dict(producer_id, job_id) + if (job_dict is None): + return -1,200 + return str(job_dict['delete_counter']),200 + +# Counter for supervision calls for a producer +# URI and parameters (GET): "/counter/supervision/" +# response: 200 and counter value +@app.route(COUNTER_SUPERVISION, + methods=['GET']) +def counter_supervision(producer_id): + producer_dict=get_callback_dict(producer_id, None) + if (producer_dict is None): + return -1,200 + return str(producer_dict['supervision_counter']),200 + +# Get status info +# URI and parameters (GET): "/status" +# - +@app.route(STATUS, + methods=['GET']) +def status(): + global db + return json.dumps(db),200 + + +# Reset db +@app.route('/reset', + methods=['GET', 'POST', 'PUT']) +def reset(): + global db + db={} + return "",200 + +### Main function ### + +if __name__ == "__main__": + app.run(port=HOST_PORT, host=HOST_IP) diff --git a/test/prodstub/app/requirements.txt b/test/prodstub/app/requirements.txt new file mode 100644 index 00000000..cc0dabfa --- /dev/null +++ b/test/prodstub/app/requirements.txt @@ -0,0 +1,3 @@ +Flask==1.1.1 +jsonschema==3.2.0 + diff --git a/test/prodstub/app/start.sh b/test/prodstub/app/start.sh new file mode 100755 index 00000000..21858c81 --- /dev/null +++ b/test/prodstub/app/start.sh @@ -0,0 +1,23 @@ +#!/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================================================= +# + +#start nginx +nginx -c /usr/src/app/nginx.conf + +#start mrstub +python3 -u prodstub.py diff --git a/test/prodstub/basic_test.sh b/test/prodstub/basic_test.sh new file mode 100755 index 00000000..c0af24e0 --- /dev/null +++ b/test/prodstub/basic_test.sh @@ -0,0 +1,54 @@ +#!/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================================================= +# + +# Automated test script for producer stub container + +if [ $# -ne 1 ]; then + echo "Usage: ./basic_test.sh nonsecure|secure" + exit 1 +fi +if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then + echo "Usage: ./basic_test.sh nonsecure|secure" + exit 1 +fi + +if [ $1 == "nonsecure" ]; then + #Default http port for the simulator + PORT=8092 + # Set http protocol + HTTPX="http" +else + #Default https port for the simulator + PORT=8093 + # Set https protocol + HTTPX="https" +fi + +# source function to do curl and check result +. ../common/do_curl_function.sh + +echo "=== hello world ===" +RESULT="OK" +do_curl GET / 200 + + + +echo "********************" +echo "*** All tests ok ***" +echo "********************" diff --git a/test/prodstub/cert/cert.crt b/test/prodstub/cert/cert.crt new file mode 100644 index 00000000..a24dfc49 --- /dev/null +++ b/test/prodstub/cert/cert.crt @@ -0,0 +1,16 @@ +-----BEGIN CERTIFICATE----- +MIICljCCAX4CCQCv7SV/aTc/YjANBgkqhkiG9w0BAQsFADANMQswCQYDVQQGEwJT +RTAeFw0yMDA1MDMwMDI0MzdaFw00NzA5MTgwMDI0MzdaMA0xCzAJBgNVBAYTAlNF +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApsGQcCv+Ce/+AbHx+3Wu +ujGtWF7uLX+/MahOHPfdXqidwG7OpmYnGkL06cA52P0BcZdc1hPGQbQdFJC8aW6U +5X9owRz9IRiwpzRhRqmMJfeqrLaqLL9K5MpCv+qsDzXu9ngRLJDk5CyeEfTjosEr +GWDywWahQKHChamdH701djFGwWGP3gttGvQoMnaSpzeyDKitBZql6bSxKkhWgFop +yxfU7qjbzOASLWaMx2r+MIJ88+AYDqYBTj649N534AYrIdjlQnvEKzGH0sOgHFYO +oaTTvmE/vRPlmbSX1U7mo/SvMWNPZkKUPDltyapOpBltfMiRJH4ndLOXJWRgmYha +SQIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQAdAwQpntpgUWUxCTk/Pw2+w5v+VxMM +K6QWhm9JdRn3XKQnKrFexVRso/x8TA8V50EUGwQwbnKApNXvJsV2jvbP/YwDsG2u +jBxs0DSspjDvbhUTkuWNYufQZIUGYMyccHap+CKD4rD2loMkmwbh5rII3SGEzUFE +rOY4VhqDjGCcILbChiY/QMA6Uyb6jLGxTARhgblWi9RWr9LuKv7raaUcnAIz1GO8 +z559kUnOKbsB46RZKRa0uIumz9qqXqxnVLWnIwT3DinpXsnzcPqNyyhTk6XR+W5o +0AuUCyT1WKlejrfMmmV6hRNHbT4x7cQrx4EjNf5hM00mN++F+QdGMa/G +-----END CERTIFICATE----- diff --git a/test/prodstub/cert/generate_cert_and_key.sh b/test/prodstub/cert/generate_cert_and_key.sh new file mode 100755 index 00000000..0f79bbf7 --- /dev/null +++ b/test/prodstub/cert/generate_cert_and_key.sh @@ -0,0 +1,21 @@ +#!/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================================================= +# + +# This will generate a self-signed certificate with password 'test' +openssl req -x509 -passout pass:"test" -newkey rsa:2048 -keyout key.crt -out cert.crt -days 9999 diff --git a/test/prodstub/cert/key.crt b/test/prodstub/cert/key.crt new file mode 100644 index 00000000..105ee75b --- /dev/null +++ b/test/prodstub/cert/key.crt @@ -0,0 +1,30 @@ +-----BEGIN ENCRYPTED PRIVATE KEY----- +MIIFHzBJBgkqhkiG9w0BBQ0wPDAbBgkqhkiG9w0BBQwwDgQIpz2Uxhl1+ZwCAggA +MB0GCWCGSAFlAwQBKgQQu1or54X1Bk5IMPGoDrdxkASCBNCBKcePejHXlG0fb2qt +TtQrpEr8UR60iFOaeUQ2Lc1zK0wzFCXAIXEWEcaozv75mJ5ReemkBMCyuzPJnoiM +LTeKuoUw8l48S9arB9l+/vVgUnMY0fm+QDsnPffkXKxC2kNwwFgGCT7tIGezuo/e +a9a5JJY707YEnkhUKWAQI2Oz/I95tbeYu64d/WtSN2OLu5JVLsCGAhV4cqcShjEb +pFlfgOHrT0z+qK7YXVR9P74qAZtGsH2ydUrtPtdvddKRpOAm4LzDNmox4Bs6e9nr +jY56sVRiHGhqeeqW04qRks5ReZF7zuwEgUSzGNlAcbbHn6FNJPOZKuN0e8KYexEM +y0G04rSNW8qppMsvez6txsou62CeIZ5LyAumwaJJYzwkob0nCmWYcZl5tSpkXZly +HsQKI2UlO3tiRKd057a46/kxcK85Pwav3Il+FaRXJkzl2rkU3DSy9SjaGL0ROD0U +1EaZCjeDdzN2GmqRQ1WhN5ivowQyWVf6H/mrxtkWZ3qLKmpa1JmvUgOybPcbqqQr +tqjj3Oj0zvLFZDqBjfIlTAAimXPgh6qLHH+qUGrI62pMpaldNZNy/swnpPuTX2sF +TUxFZvnGOmG3qHyvPm91+PypbdVSMb0PeB75XQFqWmajwnua7xfWrH8PLSijp5xQ +aLyiJ1jjFqXWE9D2v7JhB2BNCYlHxP98UI8kHxh7Fw5y0EKT5pCcbrg2nuLzMrCz +D4QaxZRuiIiPgy21kowk3WbHLYAjG7f9cIcbbX6Khc/3ulbB8xJ24WNRuzv4EHeh +TATHqk8nIgpkn1zmvPsKILdWzqZh70IlSctSzoIGzI6C2J76ycSZmcKtar2BZya9 +f1coUlFgXMvdmrf4bt4j2u/biA48OJaVlWBYVfIXUbliFTAQ8biRZFC2n3Xg+W8t +U2xqW14lZWBOIQFJp27foG6Z4JzyL2WZgQ0PWe0m0+tDaKA/LSWB2Qpwt4o2n0cb +RCs++c0eFCeOgErEfmmeburMhzQsfkUqpsL+J/ZMaRSiuTCpYM8qbz+KKT/Z6zbl +2cHWxSFRIqRKAMsj2a61IANjNIdwi2uBHZrWH1HMVVXAbGUJQFKZhxdpn5PBrXqg +vHRa9u0MQFCjs9NcQAGnBQDS6u+pUVO02WT4MvTker+hbu+f6NPU9FMLu+QbQUEP +SUdEZL4W9ZuBTdS3n/fTHEL8wKRB5yEW/CS5JuD+8YinZZXrsd3n3Oky05fdk6Bk +QH9cjMXdsd0Sb0Epw3CWGtXZ6YTHlVWqjdTNlOQdzQ7qfzktgcKujGwvQK0Mgd8x +nmG+f/HWMOss0JEL3ZR+K9Rr50u8/R+W5+e4VE57yw1fg9Jpq2/sVe2Pt8S7isFK +qDLoFZtF5RXi1O9KcA9BpnQX1ihPSC1RoY1pGXoF2D4KkV9U4/4j2qM6MGxjQ6lw +MN0qJ/N70Lti3YWqvYiTymLwVJr8FqoMQsV19MB8012Xd51Bvy6igddhrO83wuuV +b8PlUzl3Tl7yOviYqxiJ0xd8qw+Hs4+FkHbZIFJcUzTHVbb4SlPUE3wn6nrrIcfK +rT4wsYhK3afrlvK3ILi6kzzazS1dK+Hv9+mNozNf5u5nNBFQ+7MhtttzLWIaiV6D +ilLpOwcoO0X0qrzXKR7a+rQ/Dw== +-----END ENCRYPTED PRIVATE KEY----- diff --git a/test/prodstub/cert/pass b/test/prodstub/cert/pass new file mode 100644 index 00000000..30d74d25 --- /dev/null +++ b/test/prodstub/cert/pass @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/test/prodstub/prod-stub-build-start.sh b/test/prodstub/prod-stub-build-start.sh new file mode 100755 index 00000000..7f111b64 --- /dev/null +++ b/test/prodstub/prod-stub-build-start.sh @@ -0,0 +1,24 @@ +#!/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================================================= +# + +#Builds the producer stub container and starts it in interactive mode + +docker build -t producer-stub . + +docker run -it -p 8092:8092 -p 8093:8093 --name producer-stub producer-stub diff --git a/test/simulator-group/prodstub/.gitignore b/test/simulator-group/prodstub/.gitignore new file mode 100644 index 00000000..4aa3a7ae --- /dev/null +++ b/test/simulator-group/prodstub/.gitignore @@ -0,0 +1,2 @@ +.tmp.json +.dockererr \ No newline at end of file diff --git a/test/simulator-group/prodstub/docker-compose.yml b/test/simulator-group/prodstub/docker-compose.yml new file mode 100644 index 00000000..1ce8b495 --- /dev/null +++ b/test/simulator-group/prodstub/docker-compose.yml @@ -0,0 +1,33 @@ +# ============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================================================= +# + +version: '3.0' +networks: + default: + external: + name: ${DOCKER_SIM_NWNAME} +services: + producer-stub: + networks: + default: + aliases: + - ${PROD_STUB_APP_NAME_ALIAS} + container_name: ${PROD_STUB_APP_NAME} + image: ${PROD_STUB_IMAGE} + ports: + - ${PROD_STUB_EXTERNAL_PORT}:${PROD_STUB_INTERNAL_PORT} + - ${PROD_STUB_EXTERNAL_SECURE_PORT}:${PROD_STUB_INTERNAL_SECURE_PORT} diff --git a/test/simulator-group/sdnc/docker-compose.yml b/test/simulator-group/sdnc/docker-compose.yml index f835504a..b9391eaf 100644 --- a/test/simulator-group/sdnc/docker-compose.yml +++ b/test/simulator-group/sdnc/docker-compose.yml @@ -54,6 +54,7 @@ services: - db:sdnctldb02 environment: - MYSQL_ROOT_PASSWORD=openECOMP1.0 + - SDNC_DB_INIT=true - SDNC_CONFIG_DIR=/opt/onap/sdnc/data/properties - A1_TRUSTSTORE_PASSWORD=${SDNC_A1_TRUSTSTORE_PASSWORD} logging: -- 2.16.6