From: BjornMagnussonXA Date: Thu, 19 Mar 2020 13:31:06 +0000 (+0100) Subject: Updated function test environment X-Git-Tag: 2.0.0~74^2 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F70%2F3270%2F2;p=nonrtric.git Updated function test environment Added interface stub for MR Added simulator monitor Added function test and test cases Added a server for catching callbacks from the agent Added test cases for SNDC A1-Controller NB README files are generally not updated. Will be made in later commits. Change-Id: Ibf35f70b3e6f2d3f9c117aaf26ecdb03f80158f8 Issue-ID: NONRTRIC-154 Signed-off-by: BjornMagnussonXA --- diff --git a/near-rt-ric-simulator/auto-test/.gitignore b/near-rt-ric-simulator/auto-test/.gitignore index 1c5ae4ee..6215d91c 100644 --- a/near-rt-ric-simulator/auto-test/.gitignore +++ b/near-rt-ric-simulator/auto-test/.gitignore @@ -1,2 +1,10 @@ logs -.tmp_* \ No newline at end of file +.tmp_* +.http* +.p.json +.tmp.json +.docker-images-table +.image-list +.tmp.curl.json +.consul* +.ext.consul* diff --git a/near-rt-ric-simulator/auto-test/Dockerize_test.sh b/near-rt-ric-simulator/auto-test/Dockerize_test.sh index 34532c93..dec32177 100755 --- a/near-rt-ric-simulator/auto-test/Dockerize_test.sh +++ b/near-rt-ric-simulator/auto-test/Dockerize_test.sh @@ -16,7 +16,7 @@ start_simulators consul_config_app "../simulator-group/consul_cbs/config.json" -start_dashboard +start_control_panel start_sdnc diff --git a/near-rt-ric-simulator/auto-test/FTC1.sh b/near-rt-ric-simulator/auto-test/FTC1.sh deleted file mode 100755 index 7c614a4d..00000000 --- a/near-rt-ric-simulator/auto-test/FTC1.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash - -TC_ONELINE_DESCR="Auto test for Policy Agent refreshing configurations from consul/cbs" - -. ../common/testcase_common.sh $1 - -#### TEST BEGIN #### - -clean_containers - -start_simulators - -consul_config_app "../simulator-group/consul_cbs/config.json" - -start_policy_agent - -check_policy_agent_logs - -#### TEST COMPLETE #### - -store_logs END - diff --git a/near-rt-ric-simulator/auto-test/FTC10.sh b/near-rt-ric-simulator/auto-test/FTC10.sh new file mode 100755 index 00000000..88088959 --- /dev/null +++ b/near-rt-ric-simulator/auto-test/FTC10.sh @@ -0,0 +1,170 @@ +#!/usr/bin/env bash + +# ============LICENSE_START=============================================== +# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + +TC_ONELINE_DESCR="Basic use case, register rapp, create/update policy, delete policy, de-register rapp using both STD and OSC interface over REST and Dmaap" + +. ../common/testcase_common.sh $@ +. ../common/agent_api_functions.sh + + +#### TEST BEGIN #### + +#Local vars in test script +########################## +# Path to callback receiver +CR_PATH="http://$CR_APP_NAME:$CR_EXTERNAL_PORT/callbacks" + +clean_containers + +start_ric_simulators ricsim_g1 3 OSC_2.1.0 + +start_ric_simulators ricsim_g2 5 STD_1.1.3 + +start_mr + +start_cr + +start_consul_cbs + +prepare_consul_config NOSDNC ".consul_config.json" +consul_config_app ".consul_config.json" + +start_control_panel + +#start_sdnc + +start_policy_agent + +use_agent_rest + +api_get_status 200 + +sim_print ricsim_g1_1 interface + +sim_print ricsim_g2_1 interface + +sim_put_policy_type 201 ricsim_g1_1 1 testdata/OSC/sim_1.json + +api_equal json:policy_types 2 60 + + +# Create policies +use_agent_rest + +api_put_service 201 "rapp1" 3600 "$CR_PATH/callbacks/1" + +api_put_policy 201 "rapp1" ricsim_g1_1 1 2000 testdata/OSC/pi1_template.json 1 + +sim_equal ricsim_g1_1 num_instances 1 + + +use_agent_dmaap + +api_put_policy 201 "rapp1" ricsim_g1_1 1 3000 testdata/OSC/pi1_template.json 1 + +sim_equal ricsim_g1_1 num_instances 2 + + +use_agent_rest + +api_put_policy 201 "rapp1" ricsim_g2_1 NOTYPE 2100 testdata/STD/pi1_template.json 1 + +sim_equal ricsim_g2_1 num_instances 1 + + +use_agent_dmaap + +api_put_policy 201 "rapp1" ricsim_g2_1 NOTYPE 3100 testdata/STD/pi1_template.json 1 + +sim_equal ricsim_g2_1 num_instances 2 + + +#Update policies +use_agent_rest + +api_put_service 200 "rapp1" 3600 "$CR_PATH/callbacks/1" + +api_put_policy 200 "rapp1" ricsim_g1_1 1 2000 testdata/OSC/pi1_template.json 1 + +sim_equal ricsim_g1_1 num_instances 2 + + +use_agent_dmaap + +api_put_policy 200 "rapp1" ricsim_g1_1 1 3000 testdata/OSC/pi1_template.json 1 + +sim_equal ricsim_g1_1 num_instances 2 + + +use_agent_rest + + +api_put_policy 200 "rapp1" ricsim_g2_1 NOTYPE 2100 testdata/STD/pi1_template.json 1 + +sim_equal ricsim_g2_1 num_instances 2 + + +use_agent_dmaap + +api_put_policy 200 "rapp1" ricsim_g2_1 NOTYPE 3100 testdata/STD/pi1_template.json 1 + +sim_equal ricsim_g2_1 num_instances 2 + +# Check policies +api_get_policy 200 2000 testdata/OSC/pi1_template.json +api_get_policy 200 3000 testdata/OSC/pi1_template.json +api_get_policy 200 2100 testdata/STD/pi1_template.json +api_get_policy 200 3100 testdata/STD/pi1_template.json + +# Remove policies + +use_agent_dmaap +api_delete_policy 204 2000 +use_agent_rest +api_delete_policy 204 3000 +use_agent_dmaap +api_delete_policy 204 2100 +use_agent_rest +api_delete_policy 204 3100 + +sim_equal ricsim_g1_1 num_instances 0 +sim_equal ricsim_g2_1 num_instances 0 + +# Check policy removal +use_agent_rest +api_get_policy 404 2000 +api_get_policy 404 3000 +api_get_policy 404 2100 +api_get_policy 404 3100 + +# Remove the service +use_agent_dmaap +api_delete_services 204 "rapp1" + +api_get_services 404 "rapp1" + + + +check_policy_agent_logs + +#### TEST COMPLETE #### + +store_logs END + +print_result \ No newline at end of file diff --git a/near-rt-ric-simulator/auto-test/FTC100.sh b/near-rt-ric-simulator/auto-test/FTC100.sh new file mode 100755 index 00000000..79fdd491 --- /dev/null +++ b/near-rt-ric-simulator/auto-test/FTC100.sh @@ -0,0 +1,324 @@ +#!/usr/bin/env bash + +# ============LICENSE_START=============================================== +# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + + +TC_ONELINE_DESCR="Full agent API walk through using agent REST/DMAAP and with/without SDNC A1 Controller" + +. ../common/testcase_common.sh $@ +. ../common/agent_api_functions.sh +. ../common/ricsimulator_api_functions.sh +. ../common/controller_api_functions.sh + +#### TEST BEGIN #### + +#Local vars in test script +########################## + +# Path to callback receiver +CR_PATH="http://$CR_APP_NAME:$CR_EXTERNAL_PORT/callbacks" + +# Tested variants of REST/DMAAP/SDNC config +TESTED_VARIANTS="REST DMAAP REST+SDNC DMAAP+SDNC" + + +for interface in $TESTED_VARIANTS ; do + + echo "#####################################################################" + echo "#####################################################################" + echo "### Testing agent: "$interface + echo "#####################################################################" + echo "#####################################################################" + + + # Clean container and start all needed containers # + clean_containers + + start_ric_simulators ricsim_g1 1 OSC_2.1.0 + start_ric_simulators ricsim_g2 1 STD_1.1.3 + + start_mr + + start_cr + + start_consul_cbs + + if [ $interface == "SDNC" ] || [ $interface == "DMAAP+SDNC" ]; then + prepare_consul_config SDNC ".consul_config.json" + else + prepare_consul_config NOSDNC ".consul_config.json" + fi + + consul_config_app ".consul_config.json" + + start_control_panel + + if [ $interface == "SDNC" ] || [ $interface == "DMAAP+SDNC" ]; then + start_sdnc + fi + + start_policy_agent + + if [ $interface == "DMAAP" ] || [ $interface == "DMAAP+SDNC" ]; then + use_agent_dmaap + else + use_agent_rest + fi + + + cr_equal received_callbacks 0 + mr_equal requests_submitted 0 + + sim_put_policy_type 201 ricsim_g1_1 1 testdata/OSC/sim_1.json + sim_put_policy_type 201 ricsim_g1_1 2 testdata/OSC/sim_2.json + + api_equal json:rics 2 60 + + api_equal json:policy_schemas 3 120 + + api_equal json:policy_types 3 + + api_equal json:policies 0 + + api_equal json:policy_ids 0 + + + + + echo "############################################" + echo "############## Health check ################" + echo "############################################" + + api_get_status 200 + + echo "############################################" + echo "##### Service registry and supervision #####" + echo "############################################" + + api_get_services 404 "rapp1" + + api_put_service 201 "rapp1" 1000 "$CR_PATH/1" + + api_put_service 200 "rapp1" 2000 "$CR_PATH/1" + + + api_put_service 400 "rapp2" -1 "$CR_PATH/2" + + api_put_service 400 "rapp2" "wrong" "$CR_PATH/2" + + api_put_service 400 "rapp2" 100 "/test" + + api_put_service 400 "rapp2" 100 "test-path" + + api_put_service 201 "rapp2" 300 "ftp://localhost:80/test" + + api_get_services 200 "rapp1" "rapp1" 2000 "$CR_PATH/1" + + api_get_service_ids 200 "rapp1" "rapp2" + + + api_put_service 201 "rapp3" 5000 "$CR_PATH/3" + + + api_get_service_ids 200 "rapp1" "rapp2" "rapp3" + + + api_get_services 200 "rapp1" "rapp1" 2000 "$CR_PATH/1" + + api_get_services 200 NOSERVICE "rapp1" 2000 "$CR_PATH/1" "rapp2" 300 "ftp://localhost:80/test" "rapp3" 5000 "$CR_PATH/3" + + api_get_services 200 + + echo -e $YELLOW"TR2"$EYELLOW + api_put_services_keepalive 201 "rapp1" + echo -e $YELLOW"TR2"$EYELLOW + api_put_services_keepalive 201 "rapp3" + + api_put_services_keepalive 200 "rapp1" + + api_put_services_keepalive 200 "rapp3" + + api_put_services_keepalive 404 "rapp5" + + api_get_service_ids 200 "rapp1" "rapp2" "rapp3" + + api_delete_services 204 "rapp1" + + api_get_service_ids 200 "rapp2" "rapp3" + + + api_put_service 201 "rapp1" 50 "$CR_PATH/1" + + api_get_service_ids 200 "rapp1" "rapp2" "rapp3" + + + api_delete_services 204 "rapp1" + api_delete_services 204 "rapp3" + + api_equal json:services 1 + + api_delete_services 204 "rapp2" + + api_equal json:services 0 + + + echo "############################################" + echo "############## RIC Repository ##############" + echo "############################################" + + api_get_rics 200 NOTYPE "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2:AVAILABLE ricsim_g2_1:me1_ricsim_g2_1,me2_ricsim_g2_1:EMPTYTYPE:AVAILABLE" + + api_get_rics 200 1 "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2:AVAILABLE" + + api_get_rics 404 47 + + api_get_rics 404 "test" + + + api_get_ric 200 me1_ricsim_g1_1 ricsim_g1_1 + + api_get_ric 200 me2_ricsim_g1_1 ricsim_g1_1 + + api_get_ric 200 me1_ricsim_g2_1 ricsim_g2_1 + + api_get_ric 200 me2_ricsim_g2_1 ricsim_g2_1 + + api_get_ric 404 test + + + echo "############################################" + echo "########### A1 Policy Management ###########" + echo "############################################" + echo -e $YELLOW"TR9"$EYELLOW + api_get_policy_schema 200 1 testdata/OSC/1.json + echo -e $YELLOW"TR9"$EYELLOW + api_get_policy_schema 200 2 testdata/OSC/2.json + + api_get_policy_schema 404 3 + echo -e $YELLOW"TR9"$EYELLOW + api_get_policy_schemas 200 NORIC testdata/OSC/1.json testdata/OSC/2.json NOFILE + echo -e $YELLOW"TR9"$EYELLOW + api_get_policy_schemas 200 ricsim_g1_1 testdata/OSC/1.json testdata/OSC/2.json + + api_get_policy_schemas 200 ricsim_g2_1 NOFILE + + api_get_policy_schemas 404 test + + + + api_get_policy_types 200 NORIC 1 2 EMPTY + + api_get_policy_types 200 ricsim_g1_1 1 2 + + api_get_policy_types 200 ricsim_g2_1 EMPTY + + api_get_policy_types 404 dummy-ric + + + + api_put_service 201 "rapp10" 3600 "$CR_PATH/1" + echo -e $YELLOW"TR10"$EYELLOW + api_put_policy 400 "unregistered-r-app" ricsim_g1_1 1 2000 testdata/OSC/pi1_template.json + + api_put_policy 201 "rapp10" ricsim_g1_1 1 5000 testdata/OSC/pi1_template.json + api_put_policy 200 "rapp10" ricsim_g1_1 1 5000 testdata/OSC/pi1_template.json + + api_put_policy 201 "rapp10" ricsim_g2_1 NOTYPE 5100 testdata/STD/pi1_template.json + api_put_policy 200 "rapp10" ricsim_g2_1 NOTYPE 5100 testdata/STD/pi1_template.json + + VAL='NOT IN EFFECT' + api_get_policy_status 200 5000 OSC "$VAL" "false" + api_get_policy_status 200 5100 STD "UNDEFINED" + + + echo -e $YELLOW"TR10"$EYELLOW + api_equal json:policies 2 + echo -e $YELLOW"TR10"$EYELLOW + api_equal json:policy_ids 2 + echo -e $YELLOW"TR10"$EYELLOW + api_get_policy_ids 200 NORIC NOSERVICE NOTYPE 5000 5100 + echo -e $YELLOW"TR10"$EYELLOW + api_get_policy_ids 200 ricsim_g1_1 NOSERVICE NOTYPE 5000 + + api_get_policy_ids 200 ricsim_g2_1 NOSERVICE NOTYPE 5100 + + + api_get_policy_ids 200 NORIC "rapp10" NOTYPE 5000 5100 + echo -e $YELLOW"TR10"$EYELLOW + api_get_policy_ids 200 NORIC NOSERVICE 1 5000 + + api_get_policy_ids 200 NORIC NOSERVICE 2 NOID + + api_get_policy_ids 200 ricsim_g2_1 NOSERVICE 1 NOID + + + api_get_policy 200 5000 testdata/OSC/pi1_template.json + + api_get_policy 200 5100 testdata/STD/pi1_template.json + + + + api_get_policies 200 ricsim_g1_1 "rapp10" 1 5000 ricsim_g1_1 "rapp10" 1 testdata/OSC/pi1_template.json + + + + + echo -e $YELLOW"TR10"$EYELLOW + api_delete_policy 404 2000 + + api_delete_policy 404 1500 + + api_delete_policy 204 5000 + + api_equal json:policies 1 + + api_equal json:policy_ids 1 + + api_delete_policy 204 5100 + + api_equal json:policies 0 + + api_equal json:policy_ids 0 + + cr_equal received_callbacks 0 + + if [ $interface == "DMAAP" ] || [ $interface == "DMAAP+SDNC" ]; then + mr_greater requests_submitted 0 + VAL=$(mr_read requests_submitted) + mr_equal requests_fetched $VAL + mr_equal responses_submitted $VAL + mr_equal responses_fetched $VAL + mr_equal current_requests 0 + mr_equal current_responses 0 + else + mr_equal requests_submitted 0 + fi + + check_policy_agent_logs + check_control_panel_logs + + store_logs $interface + +done + +#### TEST COMPLETE #### + + +print_result + +auto_clean_containers diff --git a/near-rt-ric-simulator/auto-test/FTC200.sh b/near-rt-ric-simulator/auto-test/FTC200.sh new file mode 100755 index 00000000..2f62c56d --- /dev/null +++ b/near-rt-ric-simulator/auto-test/FTC200.sh @@ -0,0 +1,158 @@ +#!/usr/bin/env bash + +# ============LICENSE_START=============================================== +# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + + +TC_ONELINE_DESCR="Testing of service registration timeouts and keepalive" + +. ../common/testcase_common.sh $@ +. ../common/agent_api_functions.sh +. ../common/ricsimulator_api_functions.sh + + +#Local vars in test script +########################## +# Path to callback receiver +CR_PATH="http://$CR_APP_NAME:$CR_EXTERNAL_PORT/callbacks" + + +#### TEST BEGIN #### + +clean_containers + +start_ric_simulators ricsim_g1 1 OSC_2.1.0 + +start_mr + +start_cr + +start_consul_cbs + +prepare_consul_config NOSDNC ".consul_config.json" +consul_config_app ".consul_config.json" + +start_control_panel + +#start_sdnc + +start_policy_agent + +use_agent_rest + +#Verify no callbacks or dmaap messages has been sent +cr_equal received_callbacks 0 +mr_equal requests_submitted 0 + +#Check agent alive +api_get_status 200 + +#Print simulator interface version +sim_print ricsim_g1_1 interface + +api_put_service 201 "rapp1" 15 "$CR_PATH/rapp1" + +api_get_services 200 "rapp1" 15 "$CR_PATH/rapp1" + +api_put_service 201 "rapp2" 120 "$CR_PATH/rapp2" + +api_get_services 200 "rapp2" 120 "$CR_PATH/rapp2" + +api_put_service 200 "rapp1" 50 "$CR_PATH/rapp1" +api_put_service 200 "rapp2" 180 "$CR_PATH/rapp2" + +api_get_services 200 "rapp1" 50 "$CR_PATH/rapp1" +api_get_services 200 "rapp2" 180 "$CR_PATH/rapp2" + +api_get_service_ids 200 "rapp1" "rapp2" + +sleep_wait 30 "Waiting for keep alive timeout" + +api_get_services 200 "rapp1" 50 "$CR_PATH/rapp1" +api_get_services 200 "rapp2" 180 "$CR_PATH/rapp2" + +sleep_wait 100 "Waiting for keep alive timeout" + +api_get_services 404 "rapp1" +api_get_services 200 "rapp2" 180 "$CR_PATH/rapp2" + +api_delete_services 204 "rapp2" + +api_get_services 404 "rapp1" +api_get_services 404 "rapp2" + +api_put_service 201 "rapp3" 60 "$CR_PATH/rapp3" + +api_get_services 200 "rapp3" 60 "$CR_PATH/rapp3" + +sleep_wait 30 "Waiting for keep alive timeout" + +api_put_service 200 "rapp3" 60 "$CR_PATH/rapp3" + +sleep_wait 100 "Waiting for keep alive timeout" + +api_get_services 404 "rapp3" + +api_put_service 201 "rapp4" 120 "$CR_PATH/rapp4" + +sleep_wait 60 "Waiting for keep alive timeout" + +api_get_services 200 "rapp4" 120 "$CR_PATH/rapp4" + +api_put_services_keepalive 200 "rapp4" + +sleep_wait 90 "Waiting for keep alive timeout" + +api_get_services 200 "rapp4" 120 "$CR_PATH/rapp4" + +api_delete_services 204 "rapp4" + +api_get_services 404 "rapp4" + +api_get_services 404 "rapp1" +api_get_services 404 "rapp2" +api_get_services 404 "rapp3" + +api_get_service_ids 200 + +api_delete_services 404 "rapp1" +api_delete_services 404 "rapp2" +api_delete_services 404 "rapp3" +api_delete_services 404 "rapp4" + +api_put_services_keepalive 404 "rapp1" +api_put_services_keepalive 404 "rapp2" +api_put_services_keepalive 404 "rapp3" +api_put_services_keepalive 404 "rapp4" + +api_get_service_ids 200 + + + +cr_equal received_callbacks 0 +mr_equal requests_submitted 0 + +check_policy_agent_logs +check_control_panel_logs + +#### TEST COMPLETE #### + +store_logs END + +print_result + +auto_clean_containers \ No newline at end of file diff --git a/near-rt-ric-simulator/auto-test/FTC300.sh b/near-rt-ric-simulator/auto-test/FTC300.sh new file mode 100755 index 00000000..3b07f603 --- /dev/null +++ b/near-rt-ric-simulator/auto-test/FTC300.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env bash + +# ============LICENSE_START=============================================== +# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + +TC_ONELINE_DESCR="Resync 10000 policies using OSC interface over REST" + +. ../common/testcase_common.sh $@ +. ../common/agent_api_functions.sh +. ../common/ricsimulator_api_functions.sh + +#### TEST BEGIN #### + +#Local vars in test script +########################## +# Path to callback receiver +CR_PATH="http://$CR_APP_NAME:$CR_EXTERNAL_PORT/callbacks" + +clean_containers + +start_ric_simulators ricsim_g1 4 OSC_2.1.0 + +start_mr + +start_cr + +start_consul_cbs + +prepare_consul_config NOSDNC ".consul_config.json" +consul_config_app ".consul_config.json" + +start_control_panel + + +start_policy_agent + +use_agent_rest + +api_get_status 200 + +sim_print ricsim_g1_1 interface + +sim_put_policy_type 201 ricsim_g1_1 1 testdata/OSC/sim_1.json + +api_equal json:policy_types 1 120 #Wait for the agent to refresh types from the simulator + +api_put_service 201 "rapp1" 3600 "$CR_PATH/callbacks/1" + +api_put_policy 201 "rapp1" ricsim_g1_1 1 2000 testdata/OSC/pi1_template.json 10000 + +sim_equal ricsim_g1_1 num_instances 10000 + +sim_post_delete_instances 200 ricsim_g1_1 + +sim_equal ricsim_g1_1 num_instances 0 + +sim_equal ricsim_g1_1 num_instances 10000 300 + +api_delete_policy 204 2435 + +api_delete_policy 204 8693 + +sim_post_delete_instances 200 ricsim_g1_1 + +sim_post_delete_instances 200 ricsim_g1_1 + +sim_equal ricsim_g1_1 num_instances 9998 300 + + +check_policy_agent_logs + +#### TEST COMPLETE #### + +store_logs END + +print_result \ No newline at end of file diff --git a/near-rt-ric-simulator/auto-test/FTC310.sh b/near-rt-ric-simulator/auto-test/FTC310.sh new file mode 100755 index 00000000..0edd82e5 --- /dev/null +++ b/near-rt-ric-simulator/auto-test/FTC310.sh @@ -0,0 +1,172 @@ +#!/usr/bin/env bash + +# ============LICENSE_START=============================================== +# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + +TC_ONELINE_DESCR="Repeatedly create and delete 10000 policies in each RICs for 24h. Via agent REST" + +. ../common/testcase_common.sh $@ +. ../common/agent_api_functions.sh +. ../common/ricsimulator_api_functions.sh + +#### TEST BEGIN #### + +#Local vars in test script +########################## +# Path to callback receiver +CR_PATH="http://$CR_APP_NAME:$CR_EXTERNAL_PORT/callbacks" +# Number of RICs per interface type (OSC and STD) +NUM_RICS=4 +# Number of policy instances per RIC +NUM_INSTANCES=10000 + +clean_containers + +start_ric_simulators ricsim_g1 4 OSC_2.1.0 + +start_ric_simulators ricsim_g2 4 STD_1.1.3 + +start_mr + +start_cr + +start_consul_cbs + +prepare_consul_config NOSDNC ".consul_config.json" +consul_config_app ".consul_config.json" + +start_control_panel + +start_policy_agent + +use_agent_rest + +api_get_status 200 + +echo "Print the interface for group 1 simulators, shall be OSC" +for ((i=1; i<=$NUM_RICS; i++)) +do + sim_print ricsim_g1_$i interface +done + +echo "Print the interface for group 2 simulators, shall be STD" +for ((i=1; i<=$NUM_RICS; i++)) +do + sim_print ricsim_g2_$i interface +done + +echo "Load policy type in group 1 simulators" +for ((i=1; i<=$NUM_RICS; i++)) +do + sim_put_policy_type 201 ricsim_g1_$i 1 testdata/OSC/sim_1.json +done + +echo "Check the number of instances in group 1 simulators, shall be 0" +for ((i=1; i<=$NUM_RICS; i++)) +do + sim_equal ricsim_g1_$i num_instances 0 +done + +echo "Check the number of instances in group 2 simulators, shall be 0" +for ((i=1; i<=$NUM_RICS; i++)) +do + sim_equal ricsim_g2_$i num_instances 0 +done + +echo "Wait for the agent to refresh types from the simulator" +api_equal json:policy_types 2 120 + +echo "Check the number of types in the agent for each ric is 1" +for ((i=1; i<=$NUM_RICS; i++)) +do + api_equal json:policy_types?ric=ricsim_g1_$i 1 120 +done + +echo "Register a service" +api_put_service 201 "rapp1" 0 "$CR_PATH/1" + +TEST_DURATION=$((24*3600)) +TEST_START=$SECONDS + +while [ $(($SECONDS-$TEST_START)) -lt $TEST_DURATION ]; do + + echo "" + echo "#########################################################################################################" + echo -e $BOLD"INFO: Test executed for: "$(($SECONDS-$TEST_START)) "seconds. Target is: "$TEST_DURATION" seconds (24h)."$EBOLD + echo "#########################################################################################################" + echo "" + + + echo "Create 10000 instances in each OSC RIC" + INSTANCE_ID=200000 + INSTANCES=0 + for ((i=1; i<=$NUM_RICS; i++)) + do + api_put_policy 201 "rapp1" ricsim_g1_$i 1 $INSTANCE_ID testdata/OSC/pi1_template.json $NUM_INSTANCES + sim_equal ricsim_g1_$i num_instances $NUM_INSTANCES + INSTANCE_ID=$(($INSTANCE_ID+$NUM_INSTANCES)) + INSTANCES=$(($INSTANCES+$NUM_INSTANCES)) + done + + api_equal json:policy_ids $INSTANCES + + echo "Create 10000 instances in each OSC RIC" + for ((i=1; i<=$NUM_RICS; i++)) + do + api_put_policy 201 "rapp1" ricsim_g2_$i NOTYPE $INSTANCE_ID testdata/STD/pi1_template.json $NUM_INSTANCES + sim_equal ricsim_g2_$i num_instances $NUM_INSTANCES + INSTANCE_ID=$(($INSTANCE_ID+$NUM_INSTANCES)) + INSTANCES=$(($INSTANCES+$NUM_INSTANCES)) + done + + api_equal json:policy_ids $INSTANCES + + + echo "Delete all instances in each OSC RIC" + + INSTANCE_ID=200000 + for ((i=1; i<=$NUM_RICS; i++)) + do + api_delete_policy 204 $INSTANCE_ID $NUM_INSTANCES + INSTANCES=$(($INSTANCES-$NUM_INSTANCES)) + sim_equal ricsim_g1_$i num_instances $NUM_INSTANCES + INSTANCE_ID=$(($INSTANCE_ID+$NUM_INSTANCES)) + done + + api_equal json:policy_ids $INSTANCES + + echo "Delete all instances in each STD RIC" + INSTANCE_ID=200000 + for ((i=1; i<=$NUM_RICS; i++)) + do + api_delete_policy 204 $INSTANCE_ID $NUM_INSTANCES + INSTANCES=$(($INSTANCES-$NUM_INSTANCES)) + sim_equal ricsim_g2_$i num_instances $NUM_INSTANCES + INSTANCE_ID=$(($INSTANCE_ID+$NUM_INSTANCES)) + done + + api_equal json:policy_ids 0 +done + + +check_policy_agent_logs + +#### TEST COMPLETE #### + +store_logs END + +print_result \ No newline at end of file diff --git a/near-rt-ric-simulator/auto-test/FTC320.sh b/near-rt-ric-simulator/auto-test/FTC320.sh new file mode 100755 index 00000000..2b1b96a5 --- /dev/null +++ b/near-rt-ric-simulator/auto-test/FTC320.sh @@ -0,0 +1,202 @@ +#!/usr/bin/env bash + +# ============LICENSE_START=============================================== +# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + +TC_ONELINE_DESCR="Create and delete 50 policies in each 50 RICs, 25 STD version, 25 OSC version. Via agent REST" + +. ../common/testcase_common.sh $@ +. ../common/agent_api_functions.sh +. ../common/ricsimulator_api_functions.sh + +#### TEST BEGIN #### + +#Local vars in test script +########################## +# Path to callback receiver +CR_PATH="http://$CR_APP_NAME:$CR_EXTERNAL_PORT/callbacks" +# Number of RICs +NUM_RICS=25 +# Number of instances per RIC +NUM_INST=50 + +# Clean and start all containers +clean_containers + +start_ric_simulators ricsim_g1 $NUM_RICS OSC_2.1.0 + +start_ric_simulators ricsim_g2 $NUM_RICS STD_1.1.3 + +start_mr + +start_cr + +start_consul_cbs + +prepare_consul_config NOSDNC ".consul_config.json" +consul_config_app ".consul_config.json" + +start_control_panel + +start_policy_agent + +use_agent_rest + +set_agent_debug + +# Main tests + +echo "Checking agent is alive" +api_get_status 200 + + +echo "Print the interface for group 1 simulators, shall be OSC" +for ((i=1; i<=$NUM_RICS; i++)) +do + sim_print ricsim_g1_$i interface +done + +echo "Print the interface for group 2 simulators, shall be STD" +for ((i=1; i<=$NUM_RICS; i++)) +do + sim_print ricsim_g2_$i interface +done + +echo "Checking the number of policy instances in each group 1 simulator, shall be 0" +for ((i=1; i<=$NUM_RICS; i++)) +do + sim_equal ricsim_g1_$i num_instances 0 +done + +echo "Checking the number of policy instances in each group 2 simulator, shall be 0" +for ((i=1; i<=$NUM_RICS; i++)) +do + sim_equal ricsim_g1_$i num_instances 0 +done + +echo "Load policy type 1 in each group 1 simulator" +for ((i=1; i<=$NUM_RICS; i++)) +do + sim_put_policy_type 201 ricsim_g1_$i 1 testdata/OSC/sim_1.json +done + +echo "Checking the number of policy types in each group 1 simulator, shall be 1" +for ((i=1; i<=$NUM_RICS; i++)) +do + sim_equal ricsim_g1_$i num_types 1 +done + +echo "Checking the number of policy types in each group 2 simulator, shall be 0" +for ((i=1; i<=$NUM_RICS; i++)) +do + sim_equal ricsim_g2_$i num_types 0 +done + +echo "Check the number of rics, shall be the configured number: ""$(($NUM_RICS*2))" +api_equal json:rics "$(($NUM_RICS*2))" 120 + +api_equal json:policy_types 2 120 #Wait for the agent to refresh types from the simulator + +sleep_wait 120 "Wait for the agent to refresh the types from all rics" + +echo "Check the number of types in the agent for each group 1 rics, shall be 1" +for ((i=1; i<=$NUM_RICS; i++)) +do + api_equal json:policy_types?ric=ricsim_g1_$i 1 +done + +echo "Check the number of types in the agent for each group 2 rics, shall be 1" +for ((i=1; i<=$NUM_RICS; i++)) +do + api_equal json:policy_types?ric=ricsim_g2_$i 1 +done + +echo "Register the service" +api_put_service 201 "rapp1" 0 "$CR_PATH/1" + +echo "Loading "$NUM_INST" policies in each group 1 ric" +for ((i=1; i<=$NUM_RICS; i++)) +do + inst=$((1000000+$i*$NUM_INST)) + api_put_policy 201 "rapp1" ricsim_g1_$i 1 $inst testdata/OSC/pi1_template.json $NUM_INST +done + +echo "Loading "$NUM_INST" policies in each group 2 ric" +for ((i=1; i<=$NUM_RICS; i++)) +do + inst=$((2000000+$i*$NUM_INST)) + api_put_policy 201 "rapp1" ricsim_g2_$i NOTYPE $inst testdata/STD/pi1_template.json $NUM_INST +done + +echo "Check the number of types in the agent for each group 1 rics, shall be 1" +for ((i=1; i<=$NUM_RICS; i++)) +do + api_equal json:policy_types?ric=ricsim_g1_$i 1 +done + +echo "Check the number of types in the agent for each group 2 rics, shall be 1" +for ((i=1; i<=$NUM_RICS; i++)) +do + api_equal json:policy_types?ric=ricsim_g2_$i 1 +done + +echo "Checking the number of policy instances in each group 1 simulator, shall be "$NUM_INST +for ((i=1; i<=$NUM_RICS; i++)) +do + sim_equal ricsim_g1_$i num_instances 50 +done + +echo "Checking the number of policy instances in each group 2 simulator, shall be "$NUM_INST +for ((i=1; i<=$NUM_RICS; i++)) +do + sim_equal ricsim_g2_$i num_instances 50 +done + +echo "Deleting "$NUM_INST" policies in each group 1 ric" +for ((i=1; i<=$NUM_RICS; i++)) +do + inst=$((1000000+$i*$NUM_INST)) + api_delete_policy 201 $NUM_INST +done + +echo "Deleting "$NUM_INST" policies in each group 2 ric" +for ((i=1; i<=$NUM_RICS; i++)) +do + inst=$((2000000+$i*$NUM_INST)) + api_delete_policy 201 $NUM_INST +done + +echo "Checking the number of policy instances in each group 1 simulator, shall be 0" +for ((i=1; i<=$NUM_RICS; i++)) +do + sim_equal ricsim_g1_$i num_instances 50 +done + +echo "Checking the number of policy instances in each group 1 simulator, shall be 0" +for ((i=1; i<=$NUM_RICS; i++)) +do + sim_equal ricsim_g2_$i num_instances 50 +done + + +check_policy_agent_logs + +#### TEST COMPLETE #### + +store_logs END + +print_result \ No newline at end of file diff --git a/near-rt-ric-simulator/auto-test/FTC500.sh b/near-rt-ric-simulator/auto-test/FTC500.sh new file mode 100755 index 00000000..41c08244 --- /dev/null +++ b/near-rt-ric-simulator/auto-test/FTC500.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash + +# ============LICENSE_START=============================================== +# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + + +TC_ONELINE_DESCR="Sample tests of the SDNC A1 controller restconf API" + +. ../common/testcase_common.sh $@ +. ../common/controller_api_functions.sh +. ../common/ricsimulator_api_functions.sh + +#### TEST BEGIN #### + +# Clean container and start all needed containers # +clean_containers + +start_ric_simulators ricsim_g1 1 OSC_2.1.0 +start_ric_simulators ricsim_g2 1 STD_1.1.3 + +start_sdnc + +# API tests +echo -e $YELLOW"TR13"$EYELLOW +controller_api_get_A1_policy_type 404 OSC ricsim_g1_1 1 + +sim_put_policy_type 201 ricsim_g1_1 1 testdata/OSC/sim_1.json + + +controller_api_get_A1_policy_ids 200 OSC ricsim_g1_1 1 +controller_api_get_A1_policy_ids 200 STD ricsim_g2_1 + +controller_api_get_A1_policy_type 200 OSC ricsim_g1_1 1 +controller_api_get_A1_policy_type 200 OSC ricsim_g1_1 1 testdata/OSC/sim_1.json + +controller_api_put_A1_policy 202 OSC ricsim_g1_1 1 4000 testdata/OSC/pi1_template.json +controller_api_put_A1_policy 201 STD ricsim_g2_1 5000 testdata/STD/pi1_template.json + +controller_api_get_A1_policy_ids 200 OSC ricsim_g1_1 1 4000 +controller_api_get_A1_policy_ids 200 STD ricsim_g2_1 5000 + +controller_api_get_A1_policy_status 200 OSC ricsim_g1_1 1 4000 +controller_api_get_A1_policy_status 200 STD ricsim_g2_1 5000 + +VAL='NOT IN EFFECT' +controller_api_get_A1_policy_status 200 OSC ricsim_g1_1 1 4000 "$VAL" "false" +controller_api_get_A1_policy_status 200 STD ricsim_g2_1 5000 "UNDEFINED" + +controller_api_delete_A1_policy 202 OSC ricsim_g1_1 1 4000 +controller_api_delete_A1_policy 204 STD ricsim_g2_1 5000 + + + +store_logs END + +#### TEST COMPLETE #### + +print_result + +auto_clean_containers \ No newline at end of file diff --git a/near-rt-ric-simulator/auto-test/FTC_SDNC.sh b/near-rt-ric-simulator/auto-test/FTC_SDNC.sh new file mode 100755 index 00000000..0a8dce5c --- /dev/null +++ b/near-rt-ric-simulator/auto-test/FTC_SDNC.sh @@ -0,0 +1,94 @@ +#!/usr/bin/env bash + +# ============LICENSE_START=============================================== +# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + +TC_ONELINE_DESCR="Create 1 policy with SDNC and 1 policy without SDNC over agent REST" + +. ../common/testcase_common.sh $@ +. ../common/agent_api_functions.sh + +#### TEST BEGIN #### + +VARIANTS="NOSDNC SDNC" + +for TEST in $VARIANTS ; do + + + clean_containers + + start_ric_simulators ricsim_g1 1 OSC_2.1.0 + start_ric_simulators ricsim_g2 1 STD_1.1.3 + + start_mr + + start_cr + + start_consul_cbs + + prepare_consul_config $TEST ".consul_config.json" + consul_config_app ".consul_config.json" + + start_control_panel + + if [ $TEST == "SDNC" ]; then + start_sdnc + fi + + start_policy_agent + + + set_agent_debug + + use_agent_rest + + echo "Using: "$TEST + + api_get_status 200 + + sim_print ricsim_g1_1 interface + sim_print ricsim_g2_1 interface + + sim_put_policy_type 201 ricsim_g1_1 1 testdata/OSC/sim_1.json + + api_equal json:policy_types 2 120 #Wait for the agent to refresh types from the simulator + + api_put_service 201 "rapp1" 3600 "http://callback-receiver:8090/callbacks/1" + + api_put_policy 201 "rapp1" ricsim_g1_1 1 2000 testdata/OSC/pi1_template.json 10 + + api_put_policy 201 "rapp1" ricsim_g2_1 NOTYPE 3000 testdata/STD/pi1_template.json 10 + + sim_equal ricsim_g1_1 num_instances 10 + sim_equal ricsim_g2_1 num_instances 10 + + + check_policy_agent_logs + check_control_panel_logs + + store_logs $TEST + + echo "" + echo -e $BOLD"Test complete for variant: "$TEST $EBOLD + echo "" + +done + +#### TEST COMPLETE #### + +print_result + diff --git a/near-rt-ric-simulator/auto-test/Suite-interfaces.sh b/near-rt-ric-simulator/auto-test/Suite-interfaces.sh new file mode 100755 index 00000000..38eb83af --- /dev/null +++ b/near-rt-ric-simulator/auto-test/Suite-interfaces.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +TS_ONELINE_DESCR="Test suite - interface testing. Agent REST and SNDC controller resconf" + +. ../common/testsuite_common.sh + +suite_setup + +############# TEST CASES ################# + +./FTC10.sh $1 +./FTC500.sh $1 + +########################################## + +suite_complete \ No newline at end of file diff --git a/near-rt-ric-simulator/auto-test/testdata/OSC/1.json b/near-rt-ric-simulator/auto-test/testdata/OSC/1.json new file mode 100644 index 00000000..5fe68ce0 --- /dev/null +++ b/near-rt-ric-simulator/auto-test/testdata/OSC/1.json @@ -0,0 +1,40 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "OSC_Type1_1.0.0", + "description": "Type 1 policy type", + "type": "object", + "properties": { + "scope": { + "type": "object", + "properties": { + "ueId": { + "type": "string" + }, + "qosId": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "ueId", + "qosId" + ] + }, + "qosObjective": { + "type": "object", + "properties": { + "priorityLevel": { + "type": "number" + } + }, + "additionalProperties": false, + "required": [ + "priorityLevel" + ] + } + }, + "additionalProperties": false, + "required": [ + "scope", "qosObjective" + ] +} diff --git a/near-rt-ric-simulator/auto-test/testdata/OSC/2.json b/near-rt-ric-simulator/auto-test/testdata/OSC/2.json new file mode 100644 index 00000000..9f8a4d4e --- /dev/null +++ b/near-rt-ric-simulator/auto-test/testdata/OSC/2.json @@ -0,0 +1,36 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "OSC_Type2_1.0.0", + "description": "Type 2 policy type", + "type": "object", + "properties": { + "scope": { + "type": "object", + "properties": { + "sliceId": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "sliceId" + ] + }, + "qoeObjectives": { + "type": "object", + "properties": { + "qoeScore": { + "type": "number" + } + }, + "additionalProperties": false, + "required": [ + "qoeScore" + ] + } + }, + "additionalProperties": false, + "required": [ + "scope", "qoeObjectives" + ] +} diff --git a/near-rt-ric-simulator/auto-test/testdata/OSC/pi1_template.json b/near-rt-ric-simulator/auto-test/testdata/OSC/pi1_template.json new file mode 100644 index 00000000..77958087 --- /dev/null +++ b/near-rt-ric-simulator/auto-test/testdata/OSC/pi1_template.json @@ -0,0 +1,9 @@ +{ + "scope": { + "ueId": "ueXXX", + "qosId": "qosXXX" + }, + "qosObjective": { + "priorityLevel": XXX + } + } \ No newline at end of file diff --git a/near-rt-ric-simulator/auto-test/testdata/OSC/pi2_template.json b/near-rt-ric-simulator/auto-test/testdata/OSC/pi2_template.json new file mode 100644 index 00000000..c8ac887c --- /dev/null +++ b/near-rt-ric-simulator/auto-test/testdata/OSC/pi2_template.json @@ -0,0 +1,8 @@ +{ + "scope": { + "sliceId": "sliceXXX" + }, + "qoeObjectives": { + "qoeScore": XXX + } + } \ No newline at end of file diff --git a/near-rt-ric-simulator/auto-test/testdata/OSC/sim_1.json b/near-rt-ric-simulator/auto-test/testdata/OSC/sim_1.json new file mode 100644 index 00000000..537d86f7 --- /dev/null +++ b/near-rt-ric-simulator/auto-test/testdata/OSC/sim_1.json @@ -0,0 +1,45 @@ +{ + "name": "pt1", + "description": "pt1 policy type", + "policy_type_id": 1, + "create_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "OSC_Type1_1.0.0", + "description": "Type 1 policy type", + "type": "object", + "properties": { + "scope": { + "type": "object", + "properties": { + "ueId": { + "type": "string" + }, + "qosId": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "ueId", + "qosId" + ] + }, + "qosObjective": { + "type": "object", + "properties": { + "priorityLevel": { + "type": "number" + } + }, + "additionalProperties": false, + "required": [ + "priorityLevel" + ] + } + }, + "additionalProperties": false, + "required": [ + "scope", "qosObjective" + ] + } +} diff --git a/near-rt-ric-simulator/auto-test/testdata/OSC/sim_2.json b/near-rt-ric-simulator/auto-test/testdata/OSC/sim_2.json new file mode 100644 index 00000000..a9eb8f35 --- /dev/null +++ b/near-rt-ric-simulator/auto-test/testdata/OSC/sim_2.json @@ -0,0 +1,41 @@ +{ + "name": "pt2", + "description": "Pt2 policy type", + "policy_type_id": 1, + "create_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "OSC_Type2_1.0.0", + "description": "Type 2 policy type", + "type": "object", + "properties": { + "scope": { + "type": "object", + "properties": { + "sliceId": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "sliceId" + ] + }, + "qoeObjectives": { + "type": "object", + "properties": { + "qoeScore": { + "type": "number" + } + }, + "additionalProperties": false, + "required": [ + "qoeScore" + ] + } + }, + "additionalProperties": false, + "required": [ + "scope", "qoeObjectives" + ] + } +} diff --git a/near-rt-ric-simulator/auto-test/testdata/STD/EMPTYTYPE.json b/near-rt-ric-simulator/auto-test/testdata/STD/EMPTYTYPE.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/near-rt-ric-simulator/auto-test/testdata/STD/EMPTYTYPE.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/near-rt-ric-simulator/auto-test/testdata/STD/pi1_template.json b/near-rt-ric-simulator/auto-test/testdata/STD/pi1_template.json new file mode 100644 index 00000000..2a875131 --- /dev/null +++ b/near-rt-ric-simulator/auto-test/testdata/STD/pi1_template.json @@ -0,0 +1,9 @@ +{ + "scope": { + "ueId": "ueXXX", + "qosId": "qosXXX" + }, + "qosObjective": { + "priorityLevel": XXX + } +} \ No newline at end of file diff --git a/near-rt-ric-simulator/auto-test/utils/pa-logviewer.sh b/near-rt-ric-simulator/auto-test/utils/pa-logviewer.sh new file mode 100755 index 00000000..562bbea2 --- /dev/null +++ b/near-rt-ric-simulator/auto-test/utils/pa-logviewer.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# ============LICENSE_START=============================================== +# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + +#Setup trace on + +curl http://localhost:8081/actuator/loggers/org.oransc.policyagent.clients.AsyncRestClient -X POST -H 'Content-Type: application/json' -d '{"configuredLevel":"debug"}' + +docker logs -f policy-agent-container \ No newline at end of file diff --git a/near-rt-ric-simulator/common/agent_api_functions.sh b/near-rt-ric-simulator/common/agent_api_functions.sh new file mode 100644 index 00000000..fbcf2402 --- /dev/null +++ b/near-rt-ric-simulator/common/agent_api_functions.sh @@ -0,0 +1,1078 @@ +#!/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 is a script that contains specific test functions for Policy Agent API + +### API functiond towards the Policy Agent + +# Generic function to query the agent via the REST or DMAAP interface. +# Used by all other agent api test functions +# REST or DMAAP is controlled of the base url of $ADAPTER +# arg: GET|PUT|POST|DELETE [] +# (Not for test scripts) +__do_curl_to_agent() { + echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + paramError=0 + + if [ $# -lt 2 ] || [ $# -gt 3 ]; then + paramError=1 + else + timeout="" + oper="" + file='' + httpcode=" -sw %{http_code}" + accept='' + content='' + + if [ $# -gt 2 ]; then + content=" -H Content-Type:application/json" + fi + if [ $1 == "GET" ]; then + oper="GET" + if [ $# -ne 2 ];then + paramError=1 + fi + elif [ $1 == "PUT" ]; then + oper="PUT" + if [ $# -eq 3 ]; then + file=" --data-binary @$3" + fi + accept=" -H accept:application/json" + elif [ $1 == "POST" ]; then + oper="POST" + accept=" -H accept:*/*" + if [ $# -ne 2 ];then + paramError=1 + fi + elif [ $1 == "DELETE" ]; then + oper="DELETE" + if [ $# -ne 2 ];then + paramError=1 + fi + else + paramError=1 + fi + fi + + if [ $paramError -eq 1 ]; then + ((RES_CONF_FAIL++)) + echo "-Incorrect number of parameters to __do_curl_agent " $@ >> $HTTPLOG + echo "-Expected: GET|PUT|POST|DELETE []" >> $HTTPLOG + echo "-Returning response 000" >> $HTTPLOG + echo "-000" + return 1 + fi + + if [ $ADAPTER == $RESTBASE ]; then + url=" "${ADAPTER}${2} + oper=" -X "$oper + curlString="curl"${oper}${timeout}${httpcode}${accept}${content}${url}${file} + echo " CMD: "$curlString >> $HTTPLOG + if [ $# -eq 3 ]; then + echo " FILE: $(<$3)" >> $HTTPLOG + fi + + # Do retry for configured response codes, otherwise only one attempt + maxretries=5 + while [ $maxretries -ge 0 ]; do + + let maxretries=maxretries-1 + res=$($curlString) + retcode=$? + if [ $retcode -ne 0 ]; then + echo " RETCODE: "$retcode >> $HTTPLOG + echo "000" + return 1 + fi + retry=0 + echo " RESP: "$res >> $HTTPLOG + status=${res:${#res}-3} + if [ ! -z "${AGENT_RETRY_CODES}" ]; then + for retrycode in $AGENT_RETRY_CODES; do + if [ $retrycode -eq $status ]; then + echo -e $RED" Retrying (according to set codes for retry), got status $status....."$ERED >> $HTTPLOG + sleep 1 + retry=1 + fi + done + fi + if [ $retry -eq 0 ]; then + maxretries=-1 + fi + done + echo $res + return 0 + else + requestUrl=$2 + if [ $1 == "PUT" ] && [ $# -eq 3 ]; then + payload="$(cat $3 | tr -d '\n' | tr -d ' ' )" + echo "payload: "$payload >> $HTTPLOG + file=" --data-binary "$payload + fi + #urlencode the request url since it will be carried by send-request url + requestUrl=$(python -c "import urllib, sys; print urllib.quote(sys.argv[1])" "$2") + url=" "${ADAPTER}"/send-request?url="${requestUrl}"&operation="${oper} + curlString="curl -X POST${timeout}${httpcode}${content}${url}${file}" + echo " CMD: "$curlString >> $HTTPLOG + res=$($curlString) + retcode=$? + if [ $retcode -ne 0 ]; then + echo " RETCODE: "$retcode >> $HTTPLOG + echo "000" + return 1 + fi + echo " RESP: "$res >> $HTTPLOG + status=${res:${#res}-3} + if [ $status -ne 200 ]; then + echo "000" + return 1 + fi + cid=${res:0:${#res}-3} + url=" "${ADAPTER}"/receive-response?correlationid="${cid} + curlString="curl -X GET"${timeout}${httpcode}${url} + echo " CMD: "$curlString >> $HTTPLOG + res=$($curlString) + retcode=$? + if [ $retcode -ne 0 ]; then + echo " RETCODE: "$retcode >> $HTTPLOG + echo "000" + return 1 + fi + echo " RESP: "$res >> $HTTPLOG + status=${res:${#res}-3} + TS=$SECONDS + # wait of the reply from the agent... + while [ $status -eq 204 ]; do + if [ $(($SECONDS - $TS)) -gt 90 ]; then + echo " RETCODE: (timeout after 90s)" >> $HTTPLOG + echo "000" + return 1 + fi + sleep 1 + echo " CMD: "$curlString >> $HTTPLOG + res=$($curlString) + if [ $retcode -ne 0 ]; then + echo " RETCODE: "$retcode >> $HTTPLOG + echo "000" + return 1 + fi + echo " RESP: "$res >> $HTTPLOG + status=${res:${#res}-3} + done + if [ $status -eq 200 ]; then + body=${res:0:${#res}-3} + echo $body + return 0 + fi + echo "Status not 200, returning response 000" >> $HTTPLOG + echo "0000" + return 1 + fi +} + + +######################################################### +#### Test case functions A1 Policy management service +######################################################### + +# This function compare the size, towards a target value, of a json array returned from of the Policy Agent. +# This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL +# args: json: [> $HTTPLOG + if [ $# -eq 2 ] || [ $# -eq 3 ]; then + if [[ $1 == "json:"* ]]; then + __var_test "Policy Agent" $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT"/" $1 "=" $2 $3 + return 0 + fi + fi + + ((RES_CONF_FAIL++)) + __print_err "needs two or three args: json: [ timeout ]" $@ + return 1 +} + +# API Test function: GET /policies +# args: |NORIC |NOSERVICE |NOTYPE [ NOID | [ EMPTY| ]*] +# (Function for test scripts) +api_get_policies() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + paramError=0 + if [ $# -lt 4 ]; then + paramError=1 + elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then + paramError=1 + elif [ $# -gt 4 ] && [ $(($#%5)) -ne 4 ]; then + paramError=1 + fi + + if [ $paramError -ne 0 ]; then + __print_err " |NORIC |NOSERVICE |NOTYPE [ NOID | [ EMPTY| ]*]" $@ + return 1 + fi + queryparams="" + if [ $2 != "NORIC" ]; then + queryparams="?ric="$2 + fi + if [ $3 != "NOSERVICE" ]; then + if [ -z $queryparams ]; then + queryparams="?service="$3 + else + queryparams=$queryparams"&service="$3 + fi + fi + if [ $4 != "NOTYPE" ]; then + if [ -z $queryparams ]; then + queryparams="?type="$4 + else + queryparams=$queryparams"&type="$4 + fi + fi + + query="/policies"$queryparams + res="$(__do_curl_to_agent GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + + if [ $# -gt 4 ]; then + if [ $# -eq 5 ] && [ $5 == "NOID" ]; then + targetJson="[" + else + body=${res:0:${#res}-3} + targetJson="[" + arr=(${@:5}) + + for ((i=0; i<$(($#-4)); i=i+5)); do + + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + targetJson=$targetJson"{\"id\":\"${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":" + if [ "${arr[$i+3]}" == "EMPTY" ]; then + targetJson=$targetJson"\"\"," + else + targetJson=$targetJson"\"${arr[$i+3]}\"," + fi + file=".p.json" + sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file + json=$(cat $file) + targetJson=$targetJson"\"json\":"$json"}" + done + fi + + targetJson=$targetJson"]" + echo "TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python ../common/compare_json.py "$targetJson" "$body" "id") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + return 1 + fi + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 + +} + +# API Test function: GET /policy +#args: [] +# (Function for test scripts) +api_get_policy() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -lt 2 ] || [ $# -gt 3 ]; then + __print_err " [] " $@ + return 1 + fi + + query="/policy?id=$2" + res="$(__do_curl_to_agent GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + + if [ $# -eq 3 ]; then + #Create a policy json to compare with + body=${res:0:${#res}-3} + file=".p.json" + sed 's/XXX/'${2}'/g' $3 > $file + targetJson=$(< $file) + echo "TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python ../common/compare_json.py "$targetJson" "$body") + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + return 1 + fi + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API Test function: PUT /policy +# args: [] +# (Function for test scripts) +api_put_policy() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -lt 6 ] || [ $# -gt 7 ]; then + __print_err " []" $@ + return 1 + fi + + ric=$3 + count=0 + max=1 + + if [ $# -eq 7 ]; then + max=$7 + fi + + pid=$5 + file=$6 + + while [ $count -lt $max ]; do + query="/policy?id=$pid&ric=$ric&service=$2" + + if [ $4 == "NOTYPE" ]; then + query="/policy?id=$pid&ric=$ric&service=$2" + else + query="/policy?id=$pid&ric=$ric&service=$2&type=$4" + fi + + file=".p.json" + sed 's/XXX/'${pid}'/g' $6 > $file + res="$(__do_curl_to_agent PUT $query $file)" + status=${res:${#res}-3} + echo -ne " Creating "$count"("$max")\033[0K\r" + + if [ $status -ne $1 ]; then + let pid=$pid+1 + echo " Created "$count"?("$max")" + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + + let pid=$pid+1 + let count=$count+1 + echo -ne " Created "$count"("$max")\033[0K\r" + done + echo "" + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + + +# API Test function: DELETE /policy +# args: [count] +# (Function for test scripts) +api_delete_policy() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -lt 2 ] || [ $# -gt 3 ]; then + __print_err " [count]" $@ + return 1 + fi + + count=0 + max=1 + + if [ $# -eq 3 ]; then + max=$3 + fi + + pid=$2 + + while [ $count -lt $max ]; do + query="/policy?id="$pid + res="$(__do_curl_to_agent DELETE $query)" + status=${res:${#res}-3} + echo -ne " Deleting "$count"("$max")\033[0K\r" + + if [ $status -ne $1 ]; then + echo " Deleted "$count"?("$max")" + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + let pid=$pid+1 + let count=$count+1 + echo -ne " Deleted "$count"("$max")\033[0K\r" + done + echo "" + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API Test function: GET /policy_ids +# args: |NORIC |NOSERVICE |NOTYPE ([> $HTTPLOG + ((RES_TEST++)) + + if [ $# -lt 4 ]; then + __print_err " |NORIC |NOSERVICE |NOTYPE ([> $HTTPLOG + res=$(python ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + return 1 + fi + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API Test function: GET /policy_schema +# args: [] +# (Function for test scripts) +api_get_policy_schema() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -lt 2 ] || [ $# -gt 3 ]; then + __print_err " []" $@ + return 1 + fi + + query="/policy_schema?id=$2" + res="$(__do_curl_to_agent GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + + if [ $# -eq 3 ]; then + + body=${res:0:${#res}-3} + + targetJson=$(< $3) + echo "TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + return 1 + fi + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API Test function: GET /policy_schemas +# args: |NORIC [|NOFILE]* +# (Function for test scripts) +api_get_policy_schemas() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -lt 2 ]; then + __print_err " |NORIC [|NOFILE]*" $@ + return 1 + fi + + query="/policy_schemas" + if [ $2 != "NORIC" ]; then + query=$query"?ric="$2 + fi + + res="$(__do_curl_to_agent GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + + if [ $# -gt 2 ]; then + body=${res:0:${#res}-3} + targetJson="[" + + for file in ${@:3} ; do + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + if [ $file == "NOFILE" ]; then + targetJson=$targetJson"{}" + else + targetJson=$targetJson$(< $3) + fi + done + + targetJson=$targetJson"]" + echo "TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + return 1 + fi + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API Test function: GET /policy_status +# arg: (STD [])|(OSC ) +# (Function for test scripts) +api_get_policy_status() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + if [ $# -lt 4 ] || [ $# -gt 5 ]; then + __print_err " (STD [])|(OSC )" $@ + return 1 + fi + + targetJson="" + + if [ $3 == "STD" ]; then + targetJson="{\"enforceStatus\":\"$4\"" + if [ $# -eq 5 ]; then + targetJson=$targetJson",\"reason\":\"$5\"" + fi + targetJson=$targetJson"}" + elif [ $3 == "OSC" ]; then + targetJson="{\"instance_status\":\"$4\"" + if [ $# -eq 5 ]; then + targetJson=$targetJson",\"has_been_deleted\":\"$5\"" + fi + targetJson=$targetJson",\"created_at\":\"????\"}" + else + __print_err " (STD [])|(OSC )" $@ + return 1 + fi + + query="/policy_status?id="$2 + + res="$(__do_curl_to_agent GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + + echo "TARGET JSON: $targetJson" >> $HTTPLOG + body=${res:0:${#res}-3} + res=$(python ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + return 1 + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API Test function: GET /policy_types +# args: [|NORIC [|EMPTY []*]] +# (Function for test scripts) +api_get_policy_types() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -lt 1 ]; then + __print_err " [|NORIC [|EMPTY []*]]" $@ + return 1 + fi + + if [ $# -eq 1 ]; then + query="/policy_types" + elif [ $2 == "NORIC" ]; then + query="/policy_types" + else + query="/policy_types?ric=$2" + fi + + res="$(__do_curl_to_agent GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + + if [ $# -gt 2 ]; then + body=${res:0:${#res}-3} + targetJson="[" + + for pid in ${@:3} ; do + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + if [ $pid == "EMPTY" ]; then + pid="" + fi + targetJson=$targetJson"\"$pid\"" + done + + targetJson=$targetJson"]" + echo "TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + return 1 + fi + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +######################################################### +#### Test case functions Health check +######################################################### + +# API Test function: GET /status +# args: +# (Function for test scripts) +api_get_status() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + if [ $# -ne 1 ]; then + __print_err "" $@ + return 1 + fi + query="/status" + res="$(__do_curl_to_agent GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +######################################################### +#### Test case functions RIC Repository +######################################################### + +# API Test function: GET /ric +# args: [] +# (Function for test scripts) +api_get_ric() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + if [ $# -lt 2 ] || [ $# -gt 3 ]; then + __print_err " []" $@ + return 1 + fi + + query="/ric?managedElementId="$2 + + res="$(__do_curl_to_agent GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + + if [ $# -eq 3 ]; then + body=${res:0:${#res}-3} + if [ "$body" != "$3" ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + return 1 + fi + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API test function: GET /rics +# args: |NOTYPE [] +# example of = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4 ricsim_g1_1:me2_........." +# format of ric-info: :: +# (Function for test scripts) +api_get_rics() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -lt 2 ]; then + __print_err " |NOTYPE []" $@ + return 1 + fi + + query="/rics" + if [ $2 != "NOTYPE" ]; then + query="/rics?policyType="$2 + fi + + res="$(__do_curl_to_agent GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + + if [ $# -gt 2 ]; then + body=${res:0:${#res}-3} + res=$(python ../common/create_rics_json.py ".tmp_rics.json" "$3" ) + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, could not create target ric info json"$ERED + ((RES_FAIL++)) + return 1 + fi + + targetJson=$(<.tmp_rics.json) + echo "TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python ../common/compare_json.py "$targetJson" "$body") + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + return 1 + fi + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +################################################################## +#### API Test case functions Service registry and supervision #### +################################################################## + +# API test function: PUT /service +# args: +# (Function for test scripts) +api_put_service() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + if [ $# -ne 4 ]; then + __print_err " " $@ + return 1 + fi + + query="/service" + json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}" + file=".tmp.json" + echo "$json" > $file + + res="$(__do_curl_to_agent PUT $query $file)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API test function: GET /services +#args: [ ( ) | (NOSERVICE [ ]* )] +# (Function for test scripts) +api_get_services() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + #Number of accepted parameters: 1, 2, 4, 7, 10, 13,... + paramError=1 + if [ $# -eq 1 ]; then + paramError=0 + elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then + paramError=0 + elif [ $# -eq 5 ]; then + paramError=0 + elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then + argLen=$(($#-2)) + if [ $(($argLen%3)) -eq 0 ]; then + paramError=0 + fi + fi + + if [ $paramError -ne 0 ]; then + __print_err " [ ( ) | (NOSERVICE [ ]* )]" $@ + return 1 + fi + + query="/services" + + if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then + query="/services?name="$2 + fi + + res="$(__do_curl_to_agent GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + + if [ $# -gt 2 ]; then + variableArgCount=$(($#-2)) + body=${res:0:${#res}-3} + targetJson="[" + shift; shift; + cntr=0 + while [ $cntr -lt $variableArgCount ]; do + servicename=$1; shift; + timeout=$1; shift; + callback=$1; shift; + if [ $cntr -gt 0 ]; then + targetJson=$targetJson"," + fi + # timeSinceLastActivitySeconds value cannot be checked since value varies + targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}" + let cntr=cntr+3 + done + targetJson=$targetJson"]" + echo "TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python ../common/compare_json.py "$targetJson" "$body" "serviceName") + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + return 1 + fi + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API test function: GET /services (only checking service names) +# args: []*" +# (Function for test scripts) +api_get_service_ids() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -lt 1 ]; then + __print_err " []*" $@ + return 1 + fi + + query="/services" + res="$(__do_curl_to_agent GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + + body=${res:0:${#res}-3} + targetJson="[" + for rapp in ${@:2} ; do + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}" + done + + targetJson=$targetJson"]" + echo "TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python ../common/compare_json.py "$targetJson" "$body" "serviceName") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + return 1 + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API test function: DELETE /services +# args: +# (Function for test scripts) +api_delete_services() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -ne 2 ]; then + __print_err " " $@ + return 1 + fi + + query="/services?name="$2 + res="$(__do_curl_to_agent DELETE $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API test function: PUT /services/keepalive +# args: +# (Function for test scripts) +api_put_services_keepalive() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -ne 2 ]; then + __print_err " " $@ + return 1 + fi + + query="/services/keepalive?name="$2 + res="$(__do_curl_to_agent PUT $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + diff --git a/near-rt-ric-simulator/common/compare_json.py b/near-rt-ric-simulator/common/compare_json.py new file mode 100644 index 00000000..7110f480 --- /dev/null +++ b/near-rt-ric-simulator/common/compare_json.py @@ -0,0 +1,65 @@ +# ============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================================================= +# + +import os +import json +import sys + +# Deep compare of two json obects +# If a parameter value in the target json is set to '????' then the result json value is not checked for the that parameter +# Any included json array will be sorted before comparison +# An optional array key can be given to sort array of objects containing that key + +def comparejson(jsonTarget,jsonResult,arrayKey): + + if isinstance(jsonTarget, dict): + if (len(jsonTarget) != len(jsonResult)): + return 1 + for key in jsonTarget.keys(): + if (jsonResult.get(key) is None): + return 1 + if (comparejson(jsonTarget.get(key), jsonResult.get(key), arrayKey) != 0): + return 1 + elif isinstance(jsonTarget, list): + if (len(jsonTarget) != len(jsonResult)): + return 1 + if (arrayKey is None): + jsonTarget.sort() + jsonResult.sort() + else: + jsonTarget.sort(key=lambda k: k[arrayKey]) + jsonResult.sort(key=lambda k: k[arrayKey]) + + for i in range(len(jsonTarget)): + if (comparejson(jsonTarget[i], jsonResult[i], arrayKey) != 0): + return 1 + else: + if (jsonTarget != "????") and (jsonTarget != jsonResult): + return 1 + return 0 + +try: + jsonTarget = json.loads(sys.argv[1]) + jsonResult = json.loads(sys.argv[2]) + arrayKey = None + if (len(sys.argv) > 3): + arrayKey = sys.argv[3] + print(comparejson(jsonTarget,jsonResult,arrayKey)) + +except Exception as e: + print (1) +sys.exit() \ No newline at end of file diff --git a/near-rt-ric-simulator/common/controller_api_functions.sh b/near-rt-ric-simulator/common/controller_api_functions.sh new file mode 100644 index 00000000..ed298f16 --- /dev/null +++ b/near-rt-ric-simulator/common/controller_api_functions.sh @@ -0,0 +1,352 @@ +#!/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 is a script that contains specific test functions for A1 Controller API + +# Generic function to query the RICs via the A1-controller API. +# args: [] +# : getA1Policy,putA1Policy,getA1PolicyType,deleteA1Policy,getA1PolicyStatus +# response: <3-digit-response-code> +# (Not for test scripts) +__do_curl_to_controller() { + echo " (${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + if [ $# -ne 2 ] && [ $# -ne 3 ]; then + ((RES_CONF_FAIL++)) + echo "-Incorrect number of parameters to __do_curl_to_controller " $@ >> $HTTPLOG + echo "-Expected: []" >> $HTTPLOG + echo "-Returning response 000" >> $HTTPLOG + echo "000" + return 1 + fi + if [ $# -eq 2 ]; then + json='{"input":{"near-rt-ric-url":"'$2'"}}' + else + # Escape quotes in the body + body=$(echo "$3" | sed 's/"/\\"/g') + json='{"input":{"near-rt-ric-url":"'$2'","body":"'"$body"'"}}' + fi + echo "$json" > .sndc.payload.json + echo " FILE: $json" >> $HTTPLOG + curlString="curl -sw %{http_code} -X POST http://$SDNC_USER:$SDNC_PWD@localhost:$SDNC_EXTERNAL_PORT$SDNC_API_URL$1 -H accept:application/json -H Content-Type:application/json --data-binary @.sndc.payload.json" + echo " CMD: "$curlString >> $HTTPLOG + res=$($curlString) + retcode=$? + echo " RESP: "$res >> $HTTPLOG + if [ $retcode -ne 0 ]; then + echo " RETCODE: "$retcode >> $HTTPLOG + echo "000" + return 1 + fi + + status=${res:${#res}-3} + + if [ $status -ne 200 ]; then + echo "000" + return 1 + fi + body=${res:0:${#res}-3} + echo "$body" > .sdnc-reply.json + res=$(python ../common/extract_sdnc_reply.py .sdnc-reply.json) + echo " EXTRACED BODY+CODE: "$res >> $HTTPLOG + echo "$res" + return 0 +} + +# Controller API Test function: getA1Policy (return ids only) +# arg: (OSC [ []* ]) | ( STD [ []* ] ) +# (Function for test scripts) +controller_api_get_A1_policy_ids() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + paramError=1 + if [ $# -gt 3 ] && [ $2 == "OSC" ]; then + url="http://$3:$RIC_SIM_INTERNAL_PORT/a1-p/policytypes/$4/policies" + paramError=0 + elif [ $# -gt 2 ] && [ $2 == "STD" ]; then + url="http://$3:$RIC_SIM_INTERNAL_PORT/A1-P/v1/policies" + paramError=0 + fi + + if [ $paramError -ne 0 ]; then + __print_err " (OSC [ []* ]) | ( STD [ []* ] )" $@ + return 1 + fi + + res=$(__do_curl_to_controller getA1Policy "$url") + retcode=$? + status=${res:${#res}-3} + + if [ $? -ne 0 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED + ((RES_FAIL++)) + return 1 + fi + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + body=${res:0:${#res}-3} + + targetJson="[" + start=4 + if [ $2 == "OSC" ]; then + start=5 + fi + for pid in ${@:$start} ; do + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + targetJson=$targetJson"\"$pid\"" + done + targetJson=$targetJson"]" + + echo " TARGET JSON: $targetJson" >> $HTTPLOG + + res=$(python ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + return 1 + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + + +# Controller API Test function: getA1PolicyType +# arg: OSC [] +# (Function for test scripts) +controller_api_get_A1_policy_type() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + paramError=1 + if [ $# -gt 3 ] && [ $2 == "OSC" ]; then + url="http://$3:$RIC_SIM_INTERNAL_PORT/a1-p/policytypes/$4" + paramError=0 + fi + + if [ $paramError -ne 0 ]; then + __print_err " OSC []" $@ + return 1 + fi + + res=$(__do_curl_to_controller getA1PolicyType "$url") + retcode=$? + status=${res:${#res}-3} + + if [ $? -ne 0 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED + ((RES_FAIL++)) + return 1 + fi + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + body=${res:0:${#res}-3} + + if [ $# -eq 5 ]; then + + body=${res:0:${#res}-3} + + targetJson=$(< $5) + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + return 1 + fi + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# Controller API Test function: deleteA1Policy +# arg: (STD ) | (OSC ) +# (Function for test scripts) +controller_api_delete_A1_policy() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + paramError=1 + if [ $# -eq 5 ] && [ $2 == "OSC" ]; then + url="http://$3:$RIC_SIM_INTERNAL_PORT/a1-p/policytypes/$4/policies/$5" + paramError=0 + elif [ $# -eq 4 ] && [ $2 == "STD" ]; then + url="http://$3:$RIC_SIM_INTERNAL_PORT/A1-P/v1/policies/$4" + paramError=0 + fi + + if [ $paramError -ne 0 ]; then + __print_err " (STD ) | (OSC )" $@ + return 1 + fi + + res=$(__do_curl_to_controller deleteA1Policy "$url") + retcode=$? + status=${res:${#res}-3} + + if [ $? -ne 0 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED + ((RES_FAIL++)) + return 1 + fi + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# Controller API Test function: putA1Policy +# arg: (STD ) | (OSC ) +# (Function for test scripts) +controller_api_put_A1_policy() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + paramError=1 + if [ $# -eq 6 ] && [ $2 == "OSC" ]; then + url="http://$3:$RIC_SIM_INTERNAL_PORT/a1-p/policytypes/$4/policies/$5" + body=$(sed 's/XXX/'${5}'/g' $6) + + paramError=0 + elif [ $# -eq 5 ] && [ $2 == "STD" ]; then + url="http://$3:$RIC_SIM_INTERNAL_PORT/A1-P/v1/policies/$4" + body=$(sed 's/XXX/'${4}'/g' $5) + paramError=0 + fi + + if [ $paramError -ne 0 ]; then + __print_err " (STD ) | (OSC )" $@ + return 1 + fi + + res=$(__do_curl_to_controller putA1Policy "$url" "$body") + retcode=$? + status=${res:${#res}-3} + + if [ $? -ne 0 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED + ((RES_FAIL++)) + return 1 + fi + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + + +# Controller API Test function: getA1PolicyStatus +# arg: (STD []) | (OSC ) +# (Function for test scripts) +controller_api_get_A1_policy_status() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + targetJson="" + paramError=1 + if [ $# -ge 5 ] && [ $2 == "OSC" ]; then + url="http://$3:$RIC_SIM_INTERNAL_PORT/a1-p/policytypes/$4/policies/$5/status" + if [ $# -gt 5 ]; then + targetJson="{\"instance_status\":\"$6\"" + targetJson=$targetJson",\"has_been_deleted\":\"$7\"" + targetJson=$targetJson",\"created_at\":\"????\"}" + fi + paramError=0 + elif [ $# -ge 4 ] && [ $2 == "STD" ]; then + url="http://$3:$RIC_SIM_INTERNAL_PORT/A1-P/v1/policies/$4/status" + if [ $# -gt 4 ]; then + targetJson="{\"enforceStatus\":\"$5\"" + if [ $# -eq 6 ]; then + targetJson=$targetJson",\"reason\":\"$6\"" + fi + targetJson=$targetJson"}" + fi + paramError=0 + fi + + if [ $paramError -ne 0 ]; then + __print_err " (STD []) | (OSC )" $@ + return 1 + fi + + res=$(__do_curl_to_controller getA1PolicyStatus "$url") + retcode=$? + status=${res:${#res}-3} + + if [ $? -ne 0 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status "(likely remote server error)"$ERED + ((RES_FAIL++)) + return 1 + fi + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + return 1 + fi + + if [ ! -z "$targetJson" ]; then + + body=${res:0:${#res}-3} + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + return 1 + fi + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} \ No newline at end of file diff --git a/near-rt-ric-simulator/common/count_json_elements.py b/near-rt-ric-simulator/common/count_json_elements.py new file mode 100644 index 00000000..936e3f8a --- /dev/null +++ b/near-rt-ric-simulator/common/count_json_elements.py @@ -0,0 +1,35 @@ +# ============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================================================= +# + +import os +import json +import sys + +# Print the length of json array, -1 will be printed in any problem is encountered + +try: + with open(sys.argv[1]) as json_file: + jsonarray = json.load(json_file) + + if isinstance(jsonarray, list): + print(len(jsonarray)) + else: + print(-1) + +except Exception as e: + print(-1) +sys.exit() \ No newline at end of file diff --git a/near-rt-ric-simulator/common/create_rics_json.py b/near-rt-ric-simulator/common/create_rics_json.py new file mode 100644 index 00000000..d6a095bc --- /dev/null +++ b/near-rt-ric-simulator/common/create_rics_json.py @@ -0,0 +1,63 @@ +# ============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================================================= +# + +import os +import json +import sys +import re + + + +#Create a ric info json, example input: ricsim_g1_1:kista_ricsim_g1_1,stockholm_ricsim_g1_1:1,2,4 ricsim_g1_2:kista_ricsim_g1_2,stockholm_ricsim_g1_2:2 +#Format of string :: +#To indicate that no types exist, use 'NOTYPE'. Ex. ricsim_g1_1:kista_ricsim_g1_1,stockholm_ricsim_g1_1:NOTYPE +#To indicate that special STD zero length name type, use 'EMPTYTYPE'. Ex. ricsim_g1_1:kista_ricsim_g1_1,stockholm_ricsim_g1_1:EMPTYTYPE +#Save in indicated file + +try: + file_name = sys.argv[1] + ric_string = sys.argv[2] + ric_string=ric_string.strip() + ric_string = re.sub(' +',' ',ric_string) + ric_arr=[] + rics=ric_string.split(' ') + for i in range(len(rics)): + ricDict={} + items=rics[i].split(':') + ricDict['ricName']=items[0] + ricDict['managedElementIds']=items[1].split(',') + if (items[2] == "EMPTYTYPE"): + empty_arr=[] + empty_arr.append("") + ricDict['policyTypes']=empty_arr + elif (items[2] == "NOTYPE"): + empty_arr=[] + ricDict['policyTypes']=empty_arr + else: + ricDict['policyTypes']=items[2].split(',') + ricDict['state']=items[3] + ric_arr.append(ricDict) + + with open(file_name, 'w') as f: + json.dump(ric_arr, f) + + print(0) + +except Exception as e: + print(str(e)) + print(1) +sys.exit() \ No newline at end of file diff --git a/near-rt-ric-simulator/common/do_curl_function.sh b/near-rt-ric-simulator/common/do_curl_function.sh new file mode 100755 index 00000000..e1d890d0 --- /dev/null +++ b/near-rt-ric-simulator/common/do_curl_function.sh @@ -0,0 +1,84 @@ +#!/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================================================= +# + + + +# Function to execute curl towards a container (or process) and compare + print result +# Intended use is for basic test scripts where testing is done with curl and the returned response and payload need to be checked. +# args: GET|PUT|POST|DELETE [] +# All calls made to 'localhost:'. +# Expects env PORT set to intended port number +# Expects env RESULT to contain the target response body. +# RESULT="*" means that returned payload is not checked, may container any text +# RESULT="" menans that the returned payload has to match the exactly +# RESULT="json:" means that the returned json payload is compared with the expected result (order of json keys and index is irrelevant) +# Env BODY contains the response body after the call +# Any error will stop script execution +# How to use in a test script: source this file into your bash test script to the make the function available. + +do_curl() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + if [ $# -lt 3 ]; then + echo "Need 3 or more parameters, [file]: "$@ + echo "Exting test script....." + exit 1 + fi + curlstr="curl -X "$1" -sw %{http_code} localhost:$PORT$2 -H accept:*/*" + if [ $# -gt 3 ]; then + curlstr=$curlstr" -H Content-Type:application/json --data-binary @"$4 + fi + echo " CMD:"$curlstr + res=$($curlstr) + status=${res:${#res}-3} + body=${res:0:${#res}-3} + export body + if [ $status -ne $3 ]; then + echo " Error status:"$status" Expected status: "$3 + echo " Body: "$body + echo "Exting test script....." + exit 1 + else + echo " OK, code: "$status" (Expected)" + echo " Body: "$body + if [ "$RESULT" == "*" ]; then + echo " Body contents not checked" + elif [[ "$RESULT" == "json:"* ]]; then + result=${RESULT:5:${#RESULT}} + #Find dir of the common dir + DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + res=$(python ${DIR}/compare_json.py "$result" "$body") + if [ $res -eq 0 ]; then + echo " Body as expected" + else + echo " Expected json body: "$result + echo "Exiting....." + exit 1 + fi + else + body="$(echo $body | tr -d '\n' )" + if [ "$RESULT" == "$body" ]; then + echo " Body as expected" + else + echo " Expected body: "$RESULT + echo "Exiting....." + exit 1 + fi + fi + fi +} \ No newline at end of file diff --git a/near-rt-ric-simulator/common/extract_sdnc_reply.py b/near-rt-ric-simulator/common/extract_sdnc_reply.py new file mode 100644 index 00000000..cb80e5e2 --- /dev/null +++ b/near-rt-ric-simulator/common/extract_sdnc_reply.py @@ -0,0 +1,41 @@ +# ============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================================================= +# + +import os +import json +import sys + +# Extract the response code and optional response message body from and SDNC A1 Controller API reply + +try: + with open(sys.argv[1]) as json_file: + reply = json.load(json_file) + + output=reply['output'] + status=str(output['http-status']) + while(len(status) < 3): + status="0"+status + resp=status + if ( 'body' in output.keys()): + body=str(output['body']) + bodyJson=json.loads(body) + resp=str(json.dumps(bodyJson))+str(status) + print(resp) + +except Exception as e: + print("000") +sys.exit() \ No newline at end of file diff --git a/near-rt-ric-simulator/common/ricsimulator_api_functions.sh b/near-rt-ric-simulator/common/ricsimulator_api_functions.sh new file mode 100644 index 00000000..049e43db --- /dev/null +++ b/near-rt-ric-simulator/common/ricsimulator_api_functions.sh @@ -0,0 +1,203 @@ +#!/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 for the RIC simulator + + +# Excute a curl cmd towards a ricsimulator and check the response code. +# 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=$? + if [ $retcode -ne 0 ]; then + echo " RETCODE: "$retcode + echo -e $RED" ERROR - fatal error when executing curl."$ERED + return 1 + fi + status=${res:${#res}-3} + if [ $status -eq $1 ]; then + echo -e $GREEN" OK"$EGREEN + return 0 + fi + echo -e $RED" ERROR - expected http response: "$1" but got http response: "$status $ERED + return 1 +} + +# Tests if a variable value in the ricsimulator is equal to a target value and and optional timeout. +# Arg: - This test set pass or fail depending on if the variable is +# equal to the target or not. +# Arg: - This test waits up to the timeout seconds +# before setting pass or fail depending on if the variable value becomes equal to the target +# value or not. +# (Function for test scripts) +sim_equal() { + + if [ $# -eq 3 ] || [ $# -eq 4 ]; then + app=$1 + port=$(__find_sim_port $app) + __var_test $app "$LOCALHOST$port/counter/" $2 "=" $3 $4 + return 0 + else + ((RES_CONF_FAIL++)) + __print_err "needs three or four args: [ timeout ]" + return 1 + fi +} + +# Print a variable value from the RIC sim. +# args: +# (Function for test scripts) +sim_print() { + + if [ $# != 2 ]; then + ((RES_CONF_FAIL++)) + __print_err "need two args, " $@ + exit 1 + fi + app=$1 + port=$(__find_sim_port $app) + echo -e $BOLD"INFO(${BASH_LINENO[0]}): $app, $2 = $(__do_curl $LOCALHOST$port/counter/$2)"$EBOLD +} + +# Simulator API: Put a policy type in a ric +# args: +# (Function for test scripts) +sim_put_policy_type() { + echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + if [ $# -ne 4 ]; then + ((RES_CONF_FAIL++)) + __print_err " " $@ + return 1 + fi + app=$2 + res=$(__find_sim_port $app) + + curlString="curl -X PUT -sw %{http_code} $LOCALHOST"$res"/policytype?id="$3" -H Content-Type:application/json --data-binary @"$4 + + __execute_curl_to_sim $1 "$curlString" $4 + return $? +} + +# DSimulator API: Delete a policy type in a ric +# +# (Function for test scripts) +sim_delete_policy_type() { + echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + if [ $# -ne 3 ]; then + ((RES_CONF_FAIL++)) + __print_err " " $@ + return 1 + fi + app=$2 + res=$(__find_sim_port $app) + + curlString="curl -X DELETE -sw %{http_code} $LOCALHOST"$res"/policytype?id="$3 + + __execute_curl_to_sim $1 "$curlString" + return $? +} + +# Simulator API: Delete instances (and status), for one ric +# +# (Function for test scripts) +sim_post_delete_instances() { + echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + if [ $# -ne 2 ]; then + ((RES_CONF_FAIL++)) + __print_err " " $@ + return 1 + fi + app=$2 + res=$(__find_sim_port $app) + + curlString="curl -X POST -sw %{http_code} $LOCALHOST"$res"/deleteinstances" + + __execute_curl_to_sim $1 "$curlString" + return $? +} + +# Simulator API: Delete all (instances/types/statuses/settings), for one ric +# +# (Function for test scripts) +sim_post_delete_all() { + echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + if [ $# -ne 3 ]; then + ((RES_CONF_FAIL++)) + __print_err " " $@ + return 1 + fi + app=$2 + res=$(__find_sim_port $app) + + curlString="curl -X POST -sw %{http_code} $LOCALHOST"$res"/deleteall" + + __execute_curl_to_sim $1 "$curlString" + return $? +} + +# Simulator API: Set (or reset) response code for next A1 message, for one ric +# [] +# (Function for test scripts) +sim_post_forcedresponse() { + echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + if [ $# -ne 3 ]; then + ((RES_CONF_FAIL++)) + __print_err " " $@ + return 1 + fi + app=$2 + res=$(__find_sim_port $app) + + curlString="curl -X POST -sw %{http_code} $LOCALHOST"$res"/forceresponse" + if [ $# -eq 3 ]; then + curlString=$curlString"?code="$3 + fi + + __execute_curl_to_sim $1 "$curlString" + return $? +} + +# Simulator API: Set (or reset) A1 response delay, for one ric +# [] +# (Function for test scripts) +sim_post_forcedelay() { + echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + if [ $# -ne 3 ]; then + ((RES_CONF_FAIL++)) + __print_err " []" $@ + return 1 + fi + app=$2 + res=$(__find_sim_port $app) + + curlString="curl -X POST -sw %{http_code} $LOCALHOST$res/delay" + if [ $# -eq 3 ]; then + curlString=$curlString"?delay="$3 + fi + + __execute_curl_to_sim $1 "$curlString" + return $? +} \ No newline at end of file diff --git a/near-rt-ric-simulator/common/test_env.sh b/near-rt-ric-simulator/common/test_env.sh index 82afa169..3bda6019 100755 --- a/near-rt-ric-simulator/common/test_env.sh +++ b/near-rt-ric-simulator/common/test_env.sh @@ -1,22 +1,135 @@ -#!/usr/bin/env bash +#!/bin/bash -# Set the images for the Policy Agent app to use for the auto tests. Do not add the image tag. +# ============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 # -# Local Policy Agent image and tag, shall point to locally built image (non-nexus path) -export POLICY_AGENT_LOCAL_IMAGE=o-ran-sc/nonrtric-policy-agent -# Remote image -export POLICY_AGENT_REMOTE_IMAGE=nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-policy-agent -# SDNC A1 Adapter remote image -export SDNC_A1_ADAPTER_IMAGE=nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-a1-controller:1.7.4 -# Dashboard remote image -export DASHBOARD_IMAGE=nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-dashboard:1.0.1 - -# Common env var for auto-test. - -POLICY_AGENT_PORT=8081 -POLICY_AGENT_LOGPATH="/var/log/policy-agent/application.log" #Path the application log in the Policy Agent container -DOCKER_SIM_NWNAME="nonrtric-docker-net" #Name of docker private network -CONSUL_HOST="consul-server" #Host name of consul -CONSUL_PORT=8500 #Port number of consul -CONFIG_BINDING_SERVICE="config-binding-service" #Host name of CBS -PA_APP_BASE="policy-agent" #Base name for Policy Agent container +# 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================================================= +# + +# Set up the image and tags for the test. Do not add the image tag to the image names. + +# NOTE: A env var for each container is created by the test script. +# This var will point to the local or remote var depending on how +# the test script is started. The name format is _IMAGE, ie with 'LOCAL' or 'REMOTE'. + +# Local Policy Agent image and tag +POLICY_AGENT_LOCAL_IMAGE="o-ran-sc/nonrtric-policy-agent" +POLICY_AGENT_LOCAL_IMAGE_TAG="1.0.0-SNAPSHOT" +# Remote Policy Agent image and tag +POLICY_AGENT_REMOTE_IMAGE="nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-policy-agent" +POLICY_AGENT_REMOTE_IMAGE_TAG="1.0.0" + + +# Control Panel local image and tag +CONTROL_PANEL_LOCAL_IMAGE="o-ran-sc/nonrtric-controlpanel" +CONTROL_PANEL_LOCAL_IMAGE_TAG="1.0.0-SNAPSHOT" +# Control Panel remote image and tag +CONTROL_PANEL_REMOTE_IMAGE="nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-controlpanel" +CONTROL_PANEL_REMOTE_IMAGE_TAG="1.0.0" + + +# SDNC A1 Controller local image and tag +SDNC_A1_CONTROLLER_LOCAL_IMAGE="o-ran-sc/nonrtric-a1-controller" +SDNC_A1_CONTROLLER_LOCAL_IMAGE_TAG="1.0.0-SNAPSHOT" +# SDNC A1 Controller remote image and tag +SDNC_A1_CONTROLLER_REMOTE_IMAGE="nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-a1-controller" +SDNC_A1_CONTROLLER_REMOTE_IMAGE_TAG="1.7.4" + + +#SDNC DN remote image and tag +SDNC_DB_REMOTE_IMAGE="mysql/mysql-server" +SDNC_DB_REMOTE_IMAGE_TAG="5.6" +#No local image for DB, remote image always used + + +# Near RT RIC Simulator local image and tag +RIC_SIM_LOCAL_IMAGE="nexus3.o-ran-sc.org:10004/o-ran-sc/a1-simulator" +RIC_SIM_LOCAL_IMAGE_TAG="latest" +# Near RT RIC Simulator remote image and tag +RIC_SIM_REMOTE_IMAGE="nexus3.o-ran-sc.org:10004/o-ran-sc/a1-simulator" +RIC_SIM_REMOTE_IMAGE_TAG="1.0.1" + + +#Consul remote image and tag +CONSUL_REMOTE_IMAGE="consul" +CONSUL_REMOTE_IMAGE_TAG="1.7.2" +#No local image for Consul, remote image always used + + +#CBS remote image and tag +CBS_REMOTE_IMAGE="nexus3.onap.org:10001/onap/org.onap.dcaegen2.platform.configbinding.app-app" +CBS_REMOTE_IMAGE="onap/org.onap.dcaegen2.platform.configbinding.app-app" +CBS_REMOTE_IMAGE_TAG="2.3.0" +#No local image for CBS, remote image always used + + +#MR stub image and tag +MRSTUB_LOCAL_IMAGE="mrstub" +MRSTUB_LOCAL_IMAGE_TAG="latest" +#No remote image for MR stub, local image always used + +#Callback receiver image and tag +CR_LOCAL_IMAGE="callback-receiver" +CR_LOCAL_IMAGE_TAG="latest" +#No remote image for CR, 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 + +export POLICY_AGENT_EXTERNAL_PORT=8081 # Policy Agent container external port (host -> container) +export POLICY_AGENT_INTERNAL_PORT=8081 # Policy Agent container internal port (container -> container) +export POLICY_AGENT_APP_NAME="policy-agent" # Name for Policy Agent container +POLICY_AGENT_LOGPATH="/var/log/policy-agent/application.log" # Path the application log in the Policy Agent container + +export MR_EXTERNAL_PORT=3905 # MR stub container external port (host -> container) +export MR_INTERNAL_PORT=3905 # MR stub container internal port (container -> container) +export MR_APP_NAME="message-router" # Name for the MR + +export CR_EXTERNAL_PORT=8090 # Callback receiver container external port (host -> container) +export CR_INTERNAL_PORT=8090 # Callback receiver container internal port (container -> container) +export CR_APP_NAME="callback-receiver" # Name for the Callback receiver + +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) +export CONSUL_APP_NAME="polman-consul" # Name for consul container + +export CBS_APP_NAME="polman-cbs" # Name for CBS container +export CBS_EXTERNAL_PORT=10000 # CBS container external port (host -> container) +export CBS_INTERNAL_PORT=10000 # CBS container internal port (container -> container) +export CONFIG_BINDING_SERVICE="config-binding-service" # Host name of CBS + +export RIC_SIM_BASE="g" # Base name of the RIC Simulator container, shall be the group code + # Note, a prefix is added to each container name by the .env file in the 'ric' dir +RIC_SIM_PREFIX="ricsim" # Prefix added to ric container name, added in the .env file in the 'ric' dir +export RIC_SIM_INTERNAL_PORT=8085 # RIC Simulator container internal port (container -> container). + # (externl ports allocated by docker) + +export SDNC_APP_NAME="a1-controller" # Name of the SNDC A1 Controller container +export SDNC_EXTERNAL_PORT=8282 # SNDC A1 Controller container external port (host -> container) +export SDNC_INTERNAL_PORT=8181 # SNDC A1 Controller container internal port (container -> container) +export SDNC_DB_APP_NAME="sdnc-db" # Name of the SDNC DB container +SDNC_USER="admin" # SDNC username +SDNC_PWD="Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U" # SNDC PWD +SDNC_API_URL="/restconf/operations/A1-ADAPTER-API:" # Base url path for SNDC API + +export CONTROL_PANEL_APP_NAME="control-panel" # Name of the Control Panel container +export CONTROL_PANEL_EXTERNAL_PORT=8080 # Control Panel container external port (host -> container) +export CONTROL_PANEL_INTERNAL_PORT=8080 # Control Panel container external port (host -> container) +CONTROL_PANEL_LOGPATH="/logs/nonrtric-controlpanel.log" # Path the application log in the Control Panel container + +RESTBASE="http://localhost:"$POLICY_AGENT_EXTERNAL_PORT # Base url to the R-APP interface +DMAAPBASE="http://localhost:"$MR_EXTERNAL_PORT # Base url to the Dmaap adapter +ADAPTER=$RESTBASE # Adapter holds the address the agent R-APP interface (REST OR DMAAP) + # The values of this var is swiched between the two base url when needed \ No newline at end of file diff --git a/near-rt-ric-simulator/common/testcase_common.sh b/near-rt-ric-simulator/common/testcase_common.sh index b4ceb0d0..088995fd 100755 --- a/near-rt-ric-simulator/common/testcase_common.sh +++ b/near-rt-ric-simulator/common/testcase_common.sh @@ -1,36 +1,59 @@ -#!/usr/bin/env bash +#!/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 is a script that contains all the functions needed for auto test +# Arg: local|remote|remote-remove [auto-clean] + +#Formatting for 'echo' cmd +BOLD="\033[1m" +EBOLD="\033[0m" +RED="\033[31m\033[1m" +ERED="\033[0m" +GREEN="\033[32m\033[1m" +EGREEN="\033[0m" +YELLOW="\033[33m\033[1m" +EYELLOW="\033[0m" + +# Just resetting any previous echo formatting... +echo -ne $EBOLD$ERED$EGREEN + +# source test environment variables . ../common/test_env.sh -echo "Test case started as: ${BASH_SOURCE[$i+1]} "$1 $2 $3 -echo "Numbers of ric simulator started" $2 +echo "Test case started as: ${BASH_SOURCE[$i+1]} "$@ -# This is a script that contains all the functions needed for auto test -# Arg: local | remote (1, 2, 3, 4....) +#Vars for A1 interface version and container count +G1_A1_VERSION="" +G2_A1_VERSION="" +G3_A1_VERSION="" +G1_COUNT=0 +G2_COUNT=0 +G3_COUNT=0 -STARTED_POLICY_AGENT="" #Policy Agent app names added to this var to keep track of started container in the script -START_ARG=$1 -IMAGE_TAG="1.0.0-SNAPSHOT" -IMAGE_TAG_REMOTE="latest" -RIC_NUMBER=$2 -SDNC=$3 +#Localhost constant +LOCALHOST="http://localhost:" -if [ $# -lt 1 ] || [ $# -gt 4 ]; then - echo "Expected arg: local | remote and numbers of the rics and SDNC " - exit 1 -elif [ $1 == "local" ]; then - if [ -z $POLICY_AGENT_LOCAL_IMAGE ]; then - echo "POLICY_AGENT_LOCAL_IMAGE not set in test_env" - exit 1 - fi - POLICY_AGENT_IMAGE=$POLICY_AGENT_LOCAL_IMAGE":"$IMAGE_TAG -elif [ $1 == "remote" ]; then - if [ -z $POLICY_AGENT_REMOTE_IMAGE ]; then - echo "POLICY_AGENT_REMOTE_IMAGE not set in test_env" - exit 1 - fi - POLICY_AGENT_IMAGE=$POLICY_AGENT_REMOTE_IMAGE":"$IMAGE_TAG_REMOTE -fi +# Make curl retries for http response codes set in this env var, space separated list of codes +AGENT_RETRY_CODES="" + +# Var to hold 'auto' in case containers shall be stopped when test case ends +AUTO_CLEAN="" # Set a description string for the test case if [ -z "$TC_ONELINE_DESCR" ]; then @@ -38,18 +61,36 @@ if [ -z "$TC_ONELINE_DESCR" ]; then echo "No test case description found, TC_ONELINE_DESCR should be set on in the test script , using "$TC_ONELINE_DESCR fi -ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh) +# Counter for test suites +if [ -f .tmp_tcsuite_ctr ]; then + tmpval=$(< .tmp_tcsuite_ctr) + ((tmpval++)) + echo $tmpval > .tmp_tcsuite_ctr +fi +# Create a test case id, ATC (Auto Test Case), from the name of the test case script. +# FTC1.sh -> ATC == FTC1 +ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh) # Create the logs dir if not already created in the current dir if [ ! -d "logs" ]; then mkdir logs fi - TESTLOGS=$PWD/logs +# Create a http message log for this testcase +HTTPLOG=$PWD"/.httplog_"$ATC".txt" +echo "" > $HTTPLOG + +# Create a log dir for the test case mkdir -p $TESTLOGS/$ATC +# Clear the log dir for the test case +rm $TESTLOGS/$ATC/*.log &> /dev/null +rm $TESTLOGS/$ATC/*.txt &> /dev/null +rm $TESTLOGS/$ATC/*.json &> /dev/null + +# Log all output from the test case to a TC log TCLOG=$TESTLOGS/$ATC/TC.log exec &> >(tee ${TCLOG}) @@ -57,6 +98,9 @@ exec &> >(tee ${TCLOG}) RES_TEST=0 RES_PASS=0 RES_FAIL=0 +RES_CONF_FAIL=0 + +#Var for measuring execution time TCTEST_START=$SECONDS echo "-------------------------------------------------------------------------------------------------" @@ -67,318 +111,1037 @@ echo "-- Description: "$TC_ONELINE_DESCR echo "-------------------------------------------------------------------------------------------------" echo "----------------------------------- Test case setup -----------------------------------" +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" +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) +# arg: