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 RAPP Catalogue API
22 ## Access to RAPP Catalogue
23 # Host name may be changed if app started by kube
24 # Direct access from script
26 RC_HOST_NAME=$LOCALHOST_NAME
27 RC_PATH=$RC_HTTPX"://"$RC_HOST_NAME":"$RAPP_CAT_EXTERNAL_PORT
28 # RC_ADAPTER used for switch between REST and DMAAP (only REST supported currently)
29 RC_ADAPTER_TYPE="REST"
33 ###########################
35 ###########################
37 # Set http as the protocol to use for all communication to the RAPP Catalogue
39 # (Function for test scripts)
40 use_rapp_catalogue_http() {
41 echo -e $BOLD"RAPP Catalogue protocol setting"$EBOLD
42 echo -e " Using $BOLD http $EBOLD towards the RAPP Catalogue"
44 RC_PATH=$RC_HTTPX"://"$RC_HOST_NAME":"$RAPP_CAT_EXTERNAL_PORT
45 RC_ADAPTER_TYPE="REST"
50 # Set https as the protocol to use for all communication to the RAPP Catalogue
52 # (Function for test scripts)
53 use_rapp_catalogue_https() {
54 echo -e $BOLD"RAPP Catalogue protocol setting"$EBOLD
55 echo -e " Using $BOLD https $EBOLD towards the RAPP Catalogue"
57 RC_PATH=$RC_HTTPX"://"$RC_HOST_NAME":"$RAPP_CAT_EXTERNAL_SECURE_PORT
58 RC_ADAPTER_TYPE="REST"
63 # Start the RAPP Catalogue container
65 # (Function for test scripts)
66 start_rapp_catalogue() {
68 echo -e $BOLD"Starting $RAPP_CAT_DISPLAY_NAME"$EBOLD
70 if [ $RUNMODE == "KUBE" ]; then
72 # Check if app shall be fully managed by the test script
73 __check_included_image "RC"
76 # Check if app shall only be used by the testscipt
77 __check_prestarted_image "RC"
80 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
81 echo -e $RED"The $RAPP_CAT_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
82 echo -e $RED"The $RAPP_CAT_APP_NAME will not be started"$ERED
85 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
86 echo -e $RED"The $RAPP_CAT_APP_NAME app is included both as managed and prestarted in this test script"$ERED
87 echo -e $RED"The $RAPP_CAT_APP_NAME will not be started"$ERED
91 if [ $retcode_p -eq 0 ]; then
92 echo -e " Using existing $RAPP_CAT_APP_NAME deployment and service"
93 echo " Setting $RAPP_CAT_APP_NAME replicas=1"
94 __kube_scale deployment $RAPP_CAT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
97 if [ $retcode_i -eq 0 ]; then
99 echo -e " Creating $RAPP_CAT_APP_NAME app and expose service"
101 #Check if nonrtric namespace exists, if not create it
102 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
104 export RAPP_CAT_APP_NAME
105 export KUBE_NONRTRIC_NAMESPACE
106 export RAPP_CAT_IMAGE
107 export RAPP_CAT_INTERNAL_PORT
108 export RAPP_CAT_INTERNAL_SECURE_PORT
109 export RAPP_CAT_EXTERNAL_PORT
110 export RAPP_CAT_EXTERNAL_SECURE_PORT
113 input_yaml=$SIM_GROUP"/"$RAPP_CAT_COMPOSE_DIR"/"svc.yaml
114 output_yaml=$PWD/tmp/rac_svc.yaml
115 __kube_create_instance service $RAPP_CAT_APP_NAME $input_yaml $output_yaml
118 input_yaml=$SIM_GROUP"/"$RAPP_CAT_COMPOSE_DIR"/"app.yaml
119 output_yaml=$PWD/tmp/rac_app.yaml
120 __kube_create_instance app $RAPP_CAT_APP_NAME $input_yaml $output_yaml
123 echo " Retrieving host and ports for service..."
124 RC_HOST_NAME=$(__kube_get_service_host $RAPP_CAT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
126 RAPP_CAT_EXTERNAL_PORT=$(__kube_get_service_port $RAPP_CAT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
127 RAPP_CAT_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $RAPP_CAT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
129 echo " Host IP, http port, https port: $RC_HOST_NAME $RAPP_CAT_EXTERNAL_PORT $RAPP_CAT_EXTERNAL_SECURE_PORT"
130 if [ $RC_HTTPX == "http" ]; then
131 RC_PATH=$RC_HTTPX"://"$RC_HOST_NAME":"$RAPP_CAT_EXTERNAL_PORT
133 RC_PATH=$RC_HTTPX"://"$RC_HOST_NAME":"$RAPP_CAT_EXTERNAL_SECURE_PORT
136 __check_service_start $RAPP_CAT_APP_NAME $RC_PATH$RAPP_CAT_ALIVE_URL
138 # Update the curl adapter if set to rest, no change if type dmaap
139 if [ $RC_ADAPTER_TYPE == "REST" ]; then
143 __check_included_image 'RC'
144 if [ $? -eq 1 ]; then
145 echo -e $RED"The RAPP Catalogue app is not included as managed in this test script"$ERED
146 echo -e $RED"The RAPP Catalogue will not be started"$ERED
150 export RAPP_CAT_APP_NAME
151 export RAPP_CAT_INTERNAL_PORT
152 export RAPP_CAT_EXTERNAL_PORT
153 export RAPP_CAT_INTERNAL_SECURE_PORT
154 export RAPP_CAT_EXTERNAL_SECURE_PORT
155 export DOCKER_SIM_NWNAME
157 __start_container $RAPP_CAT_COMPOSE_DIR NODOCKERARGS 1 $RAPP_CAT_APP_NAME
159 __check_service_start $RAPP_CAT_APP_NAME $RC_PATH$RAPP_CAT_ALIVE_URL
164 # Tests if a variable value in the RAPP Catalogue is equal to a target value and and optional timeout.
165 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
166 # equal to the target or not.
167 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
168 # before setting pass or fail depending on if the variable value becomes equal to the target
170 # (Function for test scripts)
172 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
173 #__var_test RC "$LOCALHOST_HTTP:$RC_EXTERNAL_PORT/" $1 "=" $2 $3
174 __var_test RC "$RC_PATH/" $1 "=" $2 $3
176 __print_err "Wrong args to ecs_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
181 ##########################################
182 ######### RAPP Catalogue API ##########
183 ##########################################
184 #Function prefix: rapp_cat_api
186 # API Test function: GET /services
187 # args: <response-code> [(<service-id> <version> <display-name> <description>)+ | EMPTY ]
188 # (Function for test scripts)
189 rapp_cat_api_get_services() {
192 if [ $# -lt 1 ]; then
193 __print_err "<response-code> [(<service-id> <version> <display-name> <description>)+ | EMPTY ]" $@
197 res="$(__do_curl_to_api RC GET $query)"
198 status=${res:${#res}-3}
200 if [ $status -ne $1 ]; then
201 __log_test_fail_status_code $1 $status
205 if [ $# -gt 1 ]; then
206 body=${res:0:${#res}-3}
210 if [ $# -eq 2 ]; then
213 for ((i=0; i<$(($#-1)); i=i+4)); do
214 if [ "$targetJson" != "[" ]; then
215 targetJson=$targetJson","
217 targetJson=$targetJson"{\"name\": \"${arr[$i]}\",\"version\": \"${arr[$i+1]}\",\"display_name\": \"${arr[$i+2]}\",\"description\": \"${arr[$i+3]}\",\"registrationDate\": \"????\"}"
219 targetJson=$targetJson"]"
221 echo " TARGET JSON: $targetJson" >> $HTTPLOG
222 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
224 if [ $res -ne 0 ]; then
234 # API Test function: PUT /services/{service-id}
235 # args: <response-code> <service-id> <version> <display-name> <description>
236 # (Function for test scripts)
237 rapp_cat_api_put_service() {
240 if [ $# -ne 5 ]; then
241 __print_err "<response-code> <service-id> <version> <display-name> <description>" $@
245 inputJson="{\"version\": \"$3\",\"display_name\": \"$4\",\"description\": \"$5\"}"
247 echo "$inputJson" > $file
249 res="$(__do_curl_to_api RC PUT $query $file)"
250 status=${res:${#res}-3}
252 if [ $status -ne $1 ]; then
253 __log_test_fail_status_code $1 $status
261 # API Test function: GET /services/{service-id}
262 # args: <response-code> <service-id>
263 # (Function for test scripts)
264 rapp_cat_api_get_service() {
267 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
268 __print_err "<response-code> <service-id> <version> <display-name> <description>" $@
273 res="$(__do_curl_to_api RC GET $query)"
274 status=${res:${#res}-3}
276 if [ $status -ne $1 ]; then
277 __log_test_fail_status_code $1 $status
281 if [ $# -gt 2 ]; then
282 body=${res:0:${#res}-3}
283 targetJson="{\"name\": \"$2\",\"version\": \"$3\",\"display_name\": \"$4\",\"description\": \"$5\",\"registrationDate\": \"????\"}"
284 echo " TARGET JSON: $targetJson" >> $HTTPLOG
285 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
287 if [ $res -ne 0 ]; then
297 # API Test function: DELETE /services/{service-id}
298 # args: <response-code> <service-id>
299 # (Function for test scripts)
300 rapp_cat_api_delete_service() {
303 if [ $# -ne 2 ]; then
304 __print_err "<response-code> <service-id>" $@
309 res="$(__do_curl_to_api RC DELETE $query)"
310 status=${res:${#res}-3}
312 if [ $status -ne $1 ]; then
313 __log_test_fail_status_code $1 $status