X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=near-rt-ric-simulator%2Ftest%2FSTD_2.0.0%2Fbasic_test.sh;h=0e318bd8924177ef706cd77c8eb301caa0d95d45;hb=refs%2Fheads%2Fi-release;hp=576bd5ed28fdda0864bdc0c98422cd69299baea0;hpb=967079bda24e7a0f5268728f1474ce0ddc9e52d0;p=sim%2Fa1-interface.git diff --git a/near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh b/near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh index 576bd5e..0e318bd 100755 --- a/near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh +++ b/near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh @@ -1,7 +1,7 @@ #!/bin/bash # ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# Copyright (C) 2021 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. @@ -18,16 +18,30 @@ # # Script for basic test of the simulator. -# Run the build_and_start with the same arg as this script -if [ $# -ne 1 ]; then - echo "Usage: ./basic_test.sh nonsecure|secure" +# Run the build_and_start with the same arg, except arg 'nonsecure|secure', as this script + +print_usage() { + echo "Usage: ./basic_test.sh nonsecure|secure duplicate-check|ignore-duplicate ext-srv|ext-srv-secure|ignore-ext-srv" exit 1 +} + +if [ $# -ne 3 ]; then + print_usage fi -if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then - echo "Usage: ./basic_test.sh nonsecure|secure" - exit 1 + +if [ $1 != "nonsecure" ] && [ $1 != "secure" ]; then + print_usage +fi + +if [ $2 != "duplicate-check" ] && [ $2 != "ignore-duplicate" ]; then + print_usage fi +if [ $3 != "ext-srv" ] && [ $3 != "ext-srv-secure" ] && [ $3 != "ignore-ext-srv" ]; then + print_usage +fi + + if [ $1 == "nonsecure" ]; then #Default http port for the simulator PORT=8085 @@ -40,6 +54,28 @@ else HTTPX="https" fi +if [ $2 == "duplicate-check" ]; then + DUP_CHECK=1 +else + DUP_CHECK=0 +fi + +if [ $3 == "ext-srv" ]; then + #Default http port for the external server + PORT_EXT_SRV=9095 + # Set http protocol for external server + HTTPX_EXT_SRV="http" + EXT_SRV_EXIST=1 +elif [ $3 == "ext-srv-secure" ]; then + #Default https port for the external server + PORT_EXT_SRV=9195 + # Set https protocol for external server + HTTPX_EXT_SRV="https" + EXT_SRV_EXIST=1 +else + EXT_SRV_EXIST=0 +fi + . ../common/test_common.sh @@ -59,6 +95,21 @@ echo "=== Reset simulator, all ===" RESULT="All policy instances and types deleted" do_curl POST /deleteall 200 +#Test all admin functions in the external server +if [ $EXT_SRV_EXIST == 1 ]; then + echo "=== External server, hello world ===" + RESULT="OK" + do_curl_ext_srv GET / 200 + + echo "=== External server, reset all ===" + RESULT="All a1 policy instances deleted" + do_curl_ext_srv POST /serveradmin/deleteinstances 200 + + echo "=== External server, reset force delay ===" + RESULT="Force delay has been resetted for all external server responses" + do_curl_ext_srv POST /serveradmin/forcedelay 200 +fi + echo "=== Get counter: interface ===" RESULT="STD_2.0.0" do_curl GET /counter/interface 200 @@ -133,6 +184,13 @@ res=$(cat jsonfiles/pi1.json) RESULT="json:$res" do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 201 jsonfiles/pi1.json +if [ $EXT_SRV_EXIST == 1 ]; then + echo "=== External server, get a pi1 policy: pi1 ===" + res=$(cat jsonfiles/pi1.json) + RESULT="json:$res" + do_curl_ext_srv GET /a1policy/pi1 200 +fi + echo "=== API: Get policy instance pi1 of type: STD_1 ===" res=$(cat jsonfiles/pi1.json) RESULT="json:$res" @@ -143,29 +201,86 @@ res=$(cat jsonfiles/pi1.json) RESULT="json:$res" do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 200 jsonfiles/pi1.json +if [ $EXT_SRV_EXIST == 1 ]; then + echo "=== External server, get a pi1 policy: pi1 ===" + res=$(cat jsonfiles/pi1.json) + RESULT="json:$res" + do_curl_ext_srv GET /a1policy/pi1 200 +fi + echo "=== API: Update policy instance pi1 of type: STD_1===" res=$(cat jsonfiles/pi1_updated.json) RESULT="json:$res" do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 200 jsonfiles/pi1_updated.json -echo "=== API: Duplicate policy instance pi2 of type: STD_1===" +if [ $EXT_SRV_EXIST == 1 ]; then + echo "=== External server, get a pi1 policy: pi1 ===" + res=$(cat jsonfiles/pi1_updated.json) + RESULT="json:$res" + do_curl_ext_srv GET /a1policy/pi1 200 +fi + +echo "=== API: Duplicate policy instance json, pi2 of type: STD_1===" res=$(cat jsonfiles/pi1_updated.json) -RESULT="json:{\"title\": \"Duplicate, the policy json already exists.\", \"status\": 400, \"instance\": \"pi2\"}" -do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi2 400 jsonfiles/pi1_updated.json +if [ $DUP_CHECK == 1 ]; then + #Fail with dupl check + RESULT="json:{\"title\": \"Duplicate, the policy json already exists.\", \"status\": 400, \"instance\": \"pi2\"}" + do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi2 400 jsonfiles/pi1_updated.json +else + #OK without dupl check + res=$(cat jsonfiles/pi1_updated.json) + RESULT="json:$res" + do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi2 201 jsonfiles/pi1_updated.json + + if [ $EXT_SRV_EXIST == 1 ]; then + echo "=== External server, get a pi2 policy: pi2 ===" + res=$(cat jsonfiles/pi1_updated.json) + RESULT="json:$res" + do_curl_ext_srv GET /a1policy/pi2 200 + fi + + echo "=== API: DELETE policy instance pi2 ===" + RESULT="" + do_curl DELETE /A1-P/v2/policytypes/STD_1/policies/pi2 204 + + if [ $EXT_SRV_EXIST == 1 ]; then + echo "=== External server, get a pi2 policy: policy instance not found ===" + RESULT="json:{\"title\": \"The A1 policy requested does not exist.\", \"status\": 404, \"instance\": \"pi2\"}" + do_curl_ext_srv GET /a1policy/pi2 404 + fi +fi echo "=== API: Get policy instances, shall contain pi1==" RESULT="json:[ \"pi1\" ]" do_curl GET /A1-P/v2/policytypes/STD_1/policies 200 -echo "=== Get counter: types (shall be 1)===" -RESULT="1" +if [ $EXT_SRV_EXIST == 1 ]; then + echo "=== External server, get policy instances, shall contain pi1==" + RESULT="json:[ \"pi1\" ]" + do_curl_ext_srv GET /a1policies 200 +fi + +echo "=== Put a policy type: STD_2 ===" +RESULT="Policy type STD_2 is OK." +do_curl PUT '/policytype?id=STD_2' 201 jsonfiles/std_2.json + +echo "=== API: Duplicate policy instance id pi1 of type: STD_2===" +res=$(cat jsonfiles/pi1_updated.json) +RESULT="json:{\"title\": \"The policy id already exist for other policy type.\", \"status\": 400, \"instance\": \"pi1\"}" +do_curl PUT /A1-P/v2/policytypes/STD_2/policies/pi1 400 jsonfiles/pi1_updated.json + +echo "=== API: Get policy type ids, shall contain type STD_1 and STD_2 ==" +RESULT="json:[ \"STD_1\", \"STD_2\" ]" +do_curl GET /A1-P/v2/policytypes 200 + +echo "=== Get counter: types (shall be 2)===" +RESULT="2" do_curl GET /counter/num_types 200 echo "=== Get counter: intstance ===" RESULT="1" do_curl GET /counter/num_instances 200 - echo "=== Set force response code 409. ===" RESULT="*" do_curl POST '/forceresponse?code=409' 200 @@ -175,7 +290,7 @@ RESULT="json:{\"title\": \"Conflict\", \"status\": 409, \"detail\": \"Request co do_curl GET /A1-P/v2/policytypes/STD_1/policies 409 echo "=== API: Get policy status ===" -RESULT="json:{\"enforceStatus\": \"\", \"enforceReason\": \"\"}" +RESULT="json:{\"enforceStatus\": \"NOT_ENFORCED\", \"enforceReason\": \"OTHER_REASON\"}" do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1/status 200 echo "=== API: Create policy instance pi2 of type: STD_1 ===" @@ -192,8 +307,8 @@ echo "=== API: Get policy instances, shall contain pi1 and pi2==" RESULT="json:[ \"pi1\", \"pi2\" ]" do_curl GET /A1-P/v2/policytypes/STD_1/policies 200 -echo "=== Get counter: types (shall be 1)===" -RESULT="1" +echo "=== Get counter: types (shall be 2)===" +RESULT="2" do_curl GET /counter/num_types 200 echo "=== Get counter: intstance ===" @@ -226,33 +341,39 @@ echo "=== API: DELETE policy instance pi1 ===" RESULT="" do_curl DELETE /A1-P/v2/policytypes/STD_1/policies/pi1 204 -echo "=== API: Get policy instances, shall contain pi1 and pi2==" +echo "=== API: Get policy instances, shall contain pi2==" RESULT="json:[ \"pi2\" ]" do_curl GET /A1-P/v2/policytypes/STD_1/policies 200 +if [ $EXT_SRV_EXIST == 1 ]; then + echo "=== External server, get policy instances, shall contain pi2==" + RESULT="json:[ \"pi2\" ]" + do_curl_ext_srv GET /a1policies 200 +fi + echo "=== API: Get policy status ===" -RESULT="json:{\"enforceStatus\": \"\", \"enforceReason\": \"\"}" +RESULT="json:{\"enforceStatus\": \"NOT_ENFORCED\", \"enforceReason\": \"OTHER_REASON\"}" do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200 echo "=== Set status for policy instance pi2 ===" -RESULT="Status set to OK for policy: pi2" -do_curl PUT '/status?policyid=pi2&status=OK' 200 +RESULT="Status set to ENFORCED for policy: pi2" +do_curl PUT '/status?policyid=pi2&status=ENFORCED' 200 echo "=== API: Get policy status ===" -RESULT="json:{\"enforceStatus\": \"OK\"}" +RESULT="json:{\"enforceStatus\": \"ENFORCED\"}" do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200 echo "=== Set status for policy instance pi2 ===" -RESULT="Status set to NOTOK and notok_reason for policy: pi2" -do_curl PUT '/status?policyid=pi2&status=NOTOK&reason=notok_reason' 200 +RESULT="Status set to NOT_ENFORCED and SCOPE_NOT_APPLICABLE for policy: pi2" +do_curl PUT '/status?policyid=pi2&status=NOT_ENFORCED&reason=SCOPE_NOT_APPLICABLE' 200 echo "=== API: Get policy status ===" -RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\":\"notok_reason\"}" +RESULT="json:{\"enforceStatus\": \"NOT_ENFORCED\", \"enforceReason\":\"SCOPE_NOT_APPLICABLE\"}" do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200 echo "=== Send status for pi2===" -RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\": \"notok_reason\"}" -do_curl POST '/sendstatus?policyid=pi2' 200 +RESULT="" +do_curl POST '/sendstatus?policyid=pi2' 204 echo "=== Get counter: datadelivery ===" RESULT="0" @@ -271,8 +392,8 @@ echo "=== Get counter: intstance ===" RESULT="1" do_curl GET /counter/num_instances 200 -echo "=== Get counter: types (shall be 0)===" -RESULT="1" +echo "=== Get counter: types (shall be 2)===" +RESULT="2" do_curl GET /counter/num_types 200 echo "=== Get counter: interface ==="