3 # ============LICENSE_START===============================================
4 # Copyright (C) 2020 Nordix Foundation. All rights reserved.
5 # ========================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=================================================
20 # This is a script that contains container/service managemnt functions test functions for the Callback Reciver
22 ## Access to Callback Receiver
23 # Host name may be changed if app started by kube
24 # Direct access from script
26 CR_HOST_NAME=$LOCALHOST_NAME
27 CR_PATH=$CR_HTTPX"://"$CR_HOST_NAME":"$CR_EXTERNAL_PORT
28 #Docker/Kube internal path
29 if [ $RUNMODE == "KUBE" ]; then
30 CR_SERVICE_PATH=$CR_HTTPX"://"$CR_APP_NAME"."$KUBE_SIM_NAMESPACE":"$CR_EXTERNAL_PORT$CR_APP_CALLBACK
32 CR_SERVICE_PATH=$CR_HTTPX"://"$CR_APP_NAME":"$CR_INTERNAL_PORT$CR_APP_CALLBACK
34 # CR_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
35 CR_ADAPTER_TYPE="REST"
42 # Set http as the protocol to use for all communication to the Callback Receiver
44 # (Function for test scripts)
46 echo -e $BOLD"CR protocol setting"$EBOLD
47 echo -e " Using $BOLD http $EBOLD towards CR"
50 CR_PATH=$CR_HTTPX"://"$CR_HOST_NAME":"$CR_EXTERNAL_PORT
52 #Docker/Kube internal path
53 if [ $RUNMODE == "KUBE" ]; then
54 CR_SERVICE_PATH=$CR_HTTPX"://"$CR_APP_NAME"."$KUBE_SIM_NAMESPACE":"$CR_EXTERNAL_PORT$CR_APP_CALLBACK
56 CR_SERVICE_PATH=$CR_HTTPX"://"$CR_APP_NAME":"$CR_INTERNAL_PORT$CR_APP_CALLBACK
58 CR_ADAPTER_TYPE="REST"
63 # Set https as the protocol to use for all communication to the Callback Receiver
65 # (Function for test scripts)
67 echo -e $BOLD"CR protocol setting"$EBOLD
68 echo -e " Using $BOLD https $EBOLD towards CR"
71 CR_PATH=$CR_HTTPX"://"$CR_HOST_NAME":"$CR_EXTERNAL_SECURE_PORT
73 if [ $RUNMODE == "KUBE" ]; then
74 CR_SERVICE_PATH=$CR_HTTPX"://"$CR_APP_NAME"."$KUBE_SIM_NAMESPACE":"$CR_EXTERNAL_SECURE_PORT$CR_APP_CALLBACK
76 CR_SERVICE_PATH=$CR_HTTPX"://"$CR_APP_NAME":"$CR_INTERNAL_SECURE_PORT$CR_APP_CALLBACK
79 CR_ADAPTER_TYPE="REST"
84 # Start the Callback reciver in the simulator group
86 # (Function for test scripts)
89 echo -e $BOLD"Starting $CR_DISPLAY_NAME"$EBOLD
91 if [ $RUNMODE == "KUBE" ]; then
93 # Check if app shall be fully managed by the test script
94 __check_included_image "CR"
97 # Check if app shall only be used by the testscipt
98 __check_prestarted_image "CR"
101 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
102 echo -e $RED"The $CR_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
103 echo -e $RED"The $CR_APP_NAME will not be started"$ERED
106 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
107 echo -e $RED"The $CR_APP_NAME app is included both as managed and prestarted in this test script"$ERED
108 echo -e $RED"The $CR_APP_NAME will not be started"$ERED
112 # Check if app shall be used - not managed - by the test script
113 if [ $retcode_p -eq 0 ]; then
114 echo -e " Using existing $CR_APP_NAME deployment and service"
115 echo " Setting CR replicas=1"
116 __kube_scale deployment $CR_APP_NAME $KUBE_SIM_NAMESPACE 1
119 if [ $retcode_i -eq 0 ]; then
120 echo -e " Creating $CR_APP_NAME deployment and service"
122 export KUBE_SIM_NAMESPACE
124 export CR_INTERNAL_PORT
125 export CR_INTERNAL_SECURE_PORT
126 export CR_EXTERNAL_PORT
127 export CR_EXTERNAL_SECURE_PORT
129 __kube_create_namespace $KUBE_SIM_NAMESPACE
132 input_yaml=$SIM_GROUP"/"$CR_COMPOSE_DIR"/"svc.yaml
133 output_yaml=$PWD/tmp/cr_svc.yaml
134 __kube_create_instance service $CR_APP_NAME $input_yaml $output_yaml
137 input_yaml=$SIM_GROUP"/"$CR_COMPOSE_DIR"/"app.yaml
138 output_yaml=$PWD/tmp/cr_app.yaml
139 __kube_create_instance app $CR_APP_NAME $input_yaml $output_yaml
143 echo " Retrieving host and ports for service..."
144 CR_HOST_NAME=$(__kube_get_service_host $CR_APP_NAME $KUBE_SIM_NAMESPACE)
146 CR_EXTERNAL_PORT=$(__kube_get_service_port $CR_APP_NAME $KUBE_SIM_NAMESPACE "http")
147 CR_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $CR_APP_NAME $KUBE_SIM_NAMESPACE "https")
149 echo " Host IP, http port, https port: $CR_HOST_NAME $CR_EXTERNAL_PORT $CR_EXTERNAL_SECURE_PORT"
150 if [ $CR_HTTPX == "http" ]; then
151 CR_PATH=$CR_HTTPX"://"$CR_HOST_NAME":"$CR_EXTERNAL_PORT
152 CR_SERVICE_PATH=$CR_HTTPX"://"$CR_APP_NAME"."$KUBE_SIM_NAMESPACE":"$CR_EXTERNAL_PORT$CR_APP_CALLBACK
154 CR_PATH=$CR_HTTPX"://"$CR_HOST_NAME":"$CR_EXTERNAL_SECURE_PORT
155 CR_SERVICE_PATH=$CR_HTTPX"://"$CR_APP_NAME"."$KUBE_SIM_NAMESPACE":"$CR_EXTERNAL_SECURE_PORT$CR_APP_CALLBACK
157 if [ $CR_ADAPTER_TYPE == "REST" ]; then
161 __check_service_start $CR_APP_NAME $CR_PATH$CR_ALIVE_URL
163 echo -ne " Service $CR_APP_NAME - reset "$SAMELINE
164 result=$(__do_curl $CR_APP_NAME $CR_PATH/reset)
165 if [ $? -ne 0 ]; then
166 echo -e " Service $CR_APP_NAME - reset $RED Failed $ERED - will continue"
168 echo -e " Service $CR_APP_NAME - reset $GREEN OK $EGREEN"
171 # Check if docker app shall be fully managed by the test script
172 __check_included_image 'CR'
173 if [ $? -eq 1 ]; then
174 echo -e $RED"The Callback Receiver app is not included in this test script"$ERED
175 echo -e $RED"The Callback Receiver will not be started"$ERED
180 export CR_INTERNAL_PORT
181 export CR_EXTERNAL_PORT
182 export CR_INTERNAL_SECURE_PORT
183 export CR_EXTERNAL_SECURE_PORT
184 export DOCKER_SIM_NWNAME
186 __start_container $CR_COMPOSE_DIR NODOCKERARGS 1 $CR_APP_NAME
188 __check_service_start $CR_APP_NAME $CR_PATH$CR_ALIVE_URL
194 # Tests if a variable value in the CR is equal to a target value and and optional timeout.
195 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
196 # equal to the target or not.
197 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
198 # before setting pass or fail depending on if the variable value becomes equal to the target
200 # (Function for test scripts)
202 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
203 __var_test "CR" "$CR_PATH/counter/" $1 "=" $2 $3
205 __print_err "Wrong args to cr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
209 # CR API: Check the contents of all current ric sync events for one id from PMS
210 # <response-code> <id> [ EMPTY | ( <ric-id> )+ ]
211 # (Function for test scripts)
212 cr_api_check_all_sync_events() {
215 if [ "$PMS_VERSION" != "V2" ]; then
216 __log_test_fail_not_supported
220 if [ $# -lt 2 ]; then
221 __print_err "<response-code> <id> [ EMPTY | ( <ric-id> )+ ]" $@
225 query="/get-all-events/"$2
226 res="$(__do_curl_to_api CR GET $query)"
227 status=${res:${#res}-3}
229 if [ $status -ne $1 ]; then
230 __log_test_fail_status_code $1 $status
234 if [ $# -gt 2 ]; then
235 body=${res:0:${#res}-3}
236 if [ $# -eq 3 ] && [ $3 == "EMPTY" ]; then
242 for ((i=0; i<$(($#-2)); i=i+1)); do
244 if [ "$targetJson" != "[" ]; then
245 targetJson=$targetJson","
247 targetJson=$targetJson"{\"ric_id\":\"${arr[$i]}\",\"event_type\":\"AVAILABLE\"}"
251 targetJson=$targetJson"]"
252 echo "TARGET JSON: $targetJson" >> $HTTPLOG
253 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
255 if [ $res -ne 0 ]; then
264 # CR API: Check the contents of all current status events for one id from ECS
265 # <response-code> <id> [ EMPTY | ( <status> )+ ]
266 # (Function for test scripts)
267 cr_api_check_all_ecs_events() {
270 if [ $# -lt 2 ]; then
271 __print_err "<response-code> <id> [ EMPTY | ( <status> )+ ]" $@
275 query="/get-all-events/"$2
276 res="$(__do_curl_to_api CR GET $query)"
277 status=${res:${#res}-3}
279 if [ $status -ne $1 ]; then
280 __log_test_fail_status_code $1 $status
284 if [ $# -gt 2 ]; then
285 body=${res:0:${#res}-3}
286 if [ $# -eq 3 ] && [ $3 == "EMPTY" ]; then
292 for ((i=0; i<$(($#-2)); i=i+1)); do
294 if [ "$targetJson" != "[" ]; then
295 targetJson=$targetJson","
297 targetJson=$targetJson"{\"eiJobStatus\":\"${arr[$i]}\"}"
301 targetJson=$targetJson"]"
302 echo "TARGET JSON: $targetJson" >> $HTTPLOG
303 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
305 if [ $res -ne 0 ]; then