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 management function
21 # and test functions for Message Router - mr stub
23 ################ Test engine functions ################
25 # Create the image var used during the test
26 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
27 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
29 __check_and_create_image_var MR "MRSTUB_IMAGE" "MRSTUB_IMAGE_BASE" "MRSTUB_IMAGE_TAG" LOCAL "$MR_STUB_DISPLAY_NAME"
32 # Create the image var used during the test
33 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
34 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
35 __DMAAPMR_imagesetup() {
36 __check_and_create_image_var DMAAPMR "ONAP_DMAAPMR_IMAGE" "ONAP_DMAAPMR_IMAGE_BASE" "ONAP_DMAAPMR_IMAGE_TAG" REMOTE_RELEASE_ONAP "DMAAP Message Router"
37 __check_and_create_image_var DMAAPMR "ONAP_ZOOKEEPER_IMAGE" "ONAP_ZOOKEEPER_IMAGE_BASE" "ONAP_ZOOKEEPER_IMAGE_TAG" REMOTE_RELEASE_ONAP "ZooKeeper"
38 __check_and_create_image_var DMAAPMR "ONAP_KAFKA_IMAGE" "ONAP_KAFKA_IMAGE_BASE" "ONAP_KAFKA_IMAGE_TAG" REMOTE_RELEASE_ONAP "Kafka"
41 # Pull image from remote repo or use locally built image
42 # arg: <pull-policy-override> <pull-policy-original>
43 # <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
44 # <pull-policy-original> Shall be used for images that does not allow overriding
45 # Both var may contain: 'remote', 'remote-remove' or 'local'
47 echo -e $RED"Image for app CR shall never be pulled from remove repo"$ERED
50 # Pull image from remote repo or use locally built image
51 # arg: <pull-policy-override> <pull-policy-original>
52 # <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released (remote) images
53 # <pull-policy-original> Shall be used for images that does not allow overriding
54 # Both var may contain: 'remote', 'remote-remove' or 'local'
55 __DMAAPMR_imagepull() {
56 __check_and_pull_image $2 "DMAAP Message Router" $MR_DMAAP_APP_NAME $ONAP_DMAAPMR_IMAGE
57 __check_and_pull_image $2 "ZooKeeper" $MR_ZOOKEEPER_APP_NAME $ONAP_ZOOKEEPER_IMAGE
58 __check_and_pull_image $2 "Kafka" $MR_KAFKA_APP_NAME $ONAP_KAFKA_IMAGE
61 # Build image (only for simulator or interfaces stubs owned by the test environment)
62 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
63 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
66 echo " Building MR - $MR_STUB_DISPLAY_NAME - image: $MRSTUB_IMAGE"
67 docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $MRSTUB_IMAGE . &> .dockererr
69 echo -e $GREEN" Build Ok"$EGREEN
71 echo -e $RED" Build Failed"$ERED
74 echo -e $RED"Exiting...."$ERED
79 # Build image (only for simulator or interfaces stubs owned by the test environment)
80 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
81 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
82 __DMAAPMR_imagebuild() {
83 echo -e $RED"Image for app DMAAPMR shall never be built"$ERED
86 # Generate a string for each included image using the app display name and a docker images format string
87 # arg: <docker-images-format-string> <file-to-append>
89 echo -e "$MR_STUB_DISPLAY_NAME\t$(docker images --format $1 $MRSTUB_IMAGE)" >> $2
92 # Generate a string for each included image using the app display name and a docker images format string
93 # arg: <docker-images-format-string> <file-to-append>
94 __DMAAPMR_image_data() {
95 echo -e "DMAAP Message Router\t$(docker images --format $1 $ONAP_DMAAPMR_IMAGE)" >> $2
96 echo -e "ZooKeeper\t$(docker images --format $1 $ONAP_ZOOKEEPER_IMAGE)" >> $2
97 echo -e "Kafka\t$(docker images --format $1 $ONAP_KAFKA_IMAGE)" >> $2
100 # Scale kubernetes resources to zero
101 # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
102 # This function is called for apps fully managed by the test script
103 __MR_kube_scale_zero() {
104 __kube_scale_all_resources $KUBE_ONAP_NAMESPACE autotest MR
107 # Scale kubernetes resources to zero
108 # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
109 # This function is called for apps fully managed by the test script
110 __DMAAPMR_kube_scale_zero() {
111 __kube_scale_all_resources $KUBE_ONAP_NAMESPACE autotest DMAAPMR
114 # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
115 # This function is called for prestarted apps not managed by the test script.
116 __MR_kube_scale_zero_and_wait() {
117 echo -e " MR replicas kept as is"
120 # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
121 # This function is called for prestarted apps not managed by the test script.
122 __DMAAPMR_kube_scale_zero_and_wait() {
123 echo -e " DMAAP replicas kept as is"
126 # Delete all kube resouces for the app
127 # This function is called for apps managed by the test script.
128 __MR_kube_delete_all() {
129 __kube_delete_all_resources $KUBE_ONAP_NAMESPACE autotest MR
132 # Delete all kube resouces for the app
133 # This function is called for apps managed by the test script.
134 __DMAAPMR_kube_delete_all() {
135 __kube_delete_all_resources $KUBE_ONAP_NAMESPACE autotest DMAAPMR
139 # This function is called for apps managed by the test script.
140 # args: <log-dir> <file-prexix>
141 __MR_store_docker_logs() {
142 docker logs $MR_STUB_APP_NAME > $1$2_mr_stub.log 2>&1
146 # This function is called for apps managed by the test script.
147 # args: <log-dir> <file-prexix>
148 __DMAAPMR_store_docker_logs() {
149 docker logs $MR_DMAAP_APP_NAME > $1$2mr.log 2>&1
150 docker logs $MR_KAFKA_APP_NAME > $1$2_mr_kafka.log 2>&1
151 docker logs $MR_ZOOKEEPER_APP_NAME > $1$2_mr_zookeeper.log 2>&1
154 #######################################################
156 ## Access to Message Router
157 # Host name may be changed if app started by kube
158 # Direct access from script
160 MR_STUB_HOST_NAME=$LOCALHOST_NAME
161 MR_DMAAP_HOST_NAME=$LOCALHOST_NAME
162 MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_HOST_NAME":"$MR_STUB_LOCALHOST_PORT
163 MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_HOST_NAME":"$MR_DMAAP_LOCALHOST_PORT
164 #Docker/Kube internal path
165 if [ $RUNMODE == "KUBE" ]; then
166 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_PORT
167 __check_included_image "DMAAPMR"
168 if [ $? -eq 0 ]; then
169 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_PORT
171 __check_prestarted_image "DMAAPMR"
172 if [ $? -eq 0 ]; then
173 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_PORT
176 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME":"$MR_INTERNAL_PORT
177 __check_included_image "DMAAPMR"
178 if [ $? -eq 0 ]; then
179 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME":"$MR_INTERNAL_PORT
182 MR_ADAPTER_HTTP="http://"$MR_STUB_HOST_NAME":"$MR_STUB_LOCALHOST_PORT
183 MR_ADAPTER_HTTPS="https://"$MR_STUB_HOST_NAME":"$MR_STUB_LOCALHOST_SECURE_PORT
186 #####################
187 ### MR stub functions
188 #####################
191 echo -e $BOLD"MR protocol setting"$EBOLD
192 echo -e " Using $BOLD http $EBOLD towards MR"
194 MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_HOST_NAME":"$MR_STUB_LOCALHOST_PORT
195 MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_HOST_NAME":"$MR_DMAAP_LOCALHOST_PORT
196 #Docker/Kube internal path
197 if [ $RUNMODE == "KUBE" ]; then
198 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_PORT
199 __check_included_image "DMAAPMR"
200 if [ $? -eq 0 ]; then
201 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_PORT
203 __check_prestarted_image "DMAAPMR"
204 if [ $? -eq 0 ]; then
205 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_PORT
208 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME":"$MR_INTERNAL_PORT
209 __check_included_image "DMAAPMR"
210 if [ $? -eq 0 ]; then
211 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME":"$MR_INTERNAL_PORT
218 echo -e $BOLD"MR protocol setting"$EBOLD
219 echo -e " Using $BOLD https $EBOLD towards MR"
221 MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_HOST_NAME":"$MR_STUB_LOCALHOST_SECURE_PORT
222 MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_HOST_NAME":"$MR_DMAAP_LOCALHOST_SECURE_PORT
223 #Docker/Kube internal path
224 if [ $RUNMODE == "KUBE" ]; then
225 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_SECURE_PORT
226 __check_included_image "DMAAPMR"
227 if [ $? -eq 0 ]; then
228 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_SECURE_PORT
230 __check_prestarted_image "DMAAPMR"
231 if [ $? -eq 0 ]; then
232 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_SECURE_PORT
235 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME":"$MR_INTERNAL_SECURE_PORT
236 __check_included_image "DMAAPMR"
237 if [ $? -eq 0 ]; then
238 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME":"$MR_INTERNAL_SECURE_PORT
244 # Create a dmaap mr topic
245 # args: <topic name> <topic-description>
247 echo -ne " Creating read topic: $1"$SAMELINE
249 json_topic="{\"topicName\":\"$1\",\"partitionCount\":\"2\", \"replicationCount\":\"3\", \"transactionEnabled\":\"false\",\"topicDescription\":\"$2\"}"
250 echo $json_topic > ./tmp/$1.json
252 curlString="$MR_DMAAP_PATH/topics/create -X POST -H Content-Type:application/json -d@./tmp/$1.json"
254 while [ $topic_retries -gt 0 ]; do
255 let topic_retries=topic_retries-1
256 result=$(__do_curl "$curlString")
257 if [ $? -eq 0 ]; then
259 echo -e " Creating read topic: $1 $GREEN OK $EGREEN"
261 if [ $? -ne 0 ]; then
262 if [ $topic_retries -eq 0 ]; then
263 echo -e " Creating read topic: $1 $RED Failed $ERED"
274 # Do a pipeclean of a topic - to overcome dmaap mr bug...
275 # args: <topic> <post-url> <read-url>
276 __dmaap_pipeclean() {
278 echo -ne " Doing dmaap-mr pipe cleaning on topic: $1"$SAMELINE
279 while [ $pipeclean_retries -gt 0 ]; do
280 echo "{\"pipeclean-$1\":$pipeclean_retries}" > ./tmp/pipeclean.json
281 let pipeclean_retries=pipeclean_retries-1
282 curlString="$MR_DMAAP_PATH$2 -X POST -H Content-Type:application/json -d@./tmp/pipeclean.json"
283 result=$(__do_curl "$curlString")
284 if [ $? -ne 0 ]; then
287 curlString="$MR_DMAAP_PATH$3"
288 result=$(__do_curl "$curlString")
289 if [ $? -eq 0 ]; then
290 if [ $result != "[]" ]; then
291 echo -e " Doing dmaap-mr pipe cleaning on topic: $1 $GREEN OK $EGREEN"
300 echo -e "Doing dmaap-mr pipe cleaning on topic: $1 $RED Failed $ERED"
304 # Start the Message Router stub interface in the simulator group
306 # (Function for test scripts)
309 echo -e $BOLD"Starting $MR_DMAAP_DISPLAY_NAME and/or $MR_STUB_DISPLAY_NAME"$EBOLD
311 if [ $RUNMODE == "KUBE" ]; then
313 # Table of possible combinations of included mr and included/prestarted dmaap-mr
314 # mr can never be prestarted
315 # mr can be used stand alone
316 # if dmaapmr is included/prestarted, then mr is needed as well as frontend
318 # Inverted logic - 0 mean true, 1 means false
319 # mr prestarted 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
320 # mr included 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1
321 # dmaap prestarted 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1
322 # dmaap included 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
323 # ==================================================
324 # OK 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1
326 __check_prestarted_image 'MR'
327 retcode_prestarted_mr=$?
328 __check_included_image 'MR'
329 retcode_included_mr=$?
331 __check_prestarted_image 'DMAAPMR'
332 retcode_prestarted_dmaapmr=$?
333 __check_included_image 'DMAAPMR'
334 retcode_included_dmaapmr=$?
338 if [ $retcode_prestarted_mr -ne 0 ] && [ $retcode_included_mr -eq 0 ]; then
339 if [ $retcode_prestarted_dmaapmr -ne 0 ] && [ $retcode_included_dmaapmr -eq 0 ]; then
344 if [ $retcode_prestarted_mr -ne 0 ] && [ $retcode_included_mr -eq 0 ]; then
345 if [ $retcode_prestarted_dmaapmr -eq 0 ] && [ $retcode_included_dmaapmr -ne 0 ]; then
350 if [ $retcode_prestarted_mr -ne 0 ] && [ $retcode_included_mr -eq 0 ]; then
351 if [ $retcode_prestarted_dmaapmr -ne 0 ] && [ $retcode_included_dmaapmr -ne 0 ]; then
356 if [ $paramerror -ne 0 ]; then
357 echo -e $RED"The Message Router apps 'MR' and/or 'DMAAPMR' are not included in this test script"$ERED
358 echo -e $RED"The Message Router will not be started"$ERED
359 echo -e $RED"Both MR and DAAMPMR - or - only MR - need to be included and/or prestarted"
363 if [ $retcode_prestarted_dmaapmr -eq 0 ]; then
364 echo -e " Using existing $MR_DMAAP_APP_NAME deployment and service"
365 __kube_scale deployment $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE 1
368 if [ $retcode_included_dmaapmr -eq 0 ]; then
369 #export MR_DMAAP_APP_NAME
370 export MR_DMAAP_KUBE_APP_NAME=message-router
371 MR_DMAAP_APP_NAME=$MR_DMAAP_KUBE_APP_NAME
372 export KUBE_ONAP_NAMESPACE
373 export MR_EXTERNAL_PORT
374 export MR_INTERNAL_PORT
375 export MR_EXTERNAL_SECURE_PORT
376 export MR_INTERNAL_SECURE_PORT
377 export ONAP_DMAAPMR_IMAGE
379 export MR_KAFKA_BWDS_NAME=akfak-bwds
380 export KUBE_ONAP_NAMESPACE
382 export MR_ZOOKEEPER_APP_NAME
383 export ONAP_ZOOKEEPER_IMAGE
385 #Check if onap namespace exists, if not create it
386 __kube_create_namespace $KUBE_ONAP_NAMESPACE
388 # TODO - Fix domain name substitution in the prop file
389 # Create config maps - dmaapmr app
390 configfile=$PWD/tmp/MsgRtrApi.properties
391 cp $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"mnt/mr/KUBE-MsgRtrApi.properties $configfile
392 output_yaml=$PWD/tmp/dmaapmr_msgrtrapi_cfc.yaml
393 __kube_create_configmap dmaapmr-msgrtrapi.properties $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
395 configfile=$PWD/tmp/logback.xml
396 cp $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"mnt/mr/logback.xml $configfile
397 output_yaml=$PWD/tmp/dmaapmr_logback_cfc.yaml
398 __kube_create_configmap dmaapmr-logback.xml $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
400 configfile=$PWD/tmp/cadi.properties
401 cp $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"mnt/mr/cadi.properties $configfile
402 output_yaml=$PWD/tmp/dmaapmr_cadi_cfc.yaml
403 __kube_create_configmap dmaapmr-cadi.properties $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
405 # Create config maps - kafka app
406 configfile=$PWD/tmp/zk_client_jaas.conf
407 cp $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"mnt/kafka/zk_client_jaas.conf $configfile
408 output_yaml=$PWD/tmp/dmaapmr_zk_client_cfc.yaml
409 __kube_create_configmap dmaapmr-zk-client-jaas.conf $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
411 # Create config maps - zookeeper app
412 configfile=$PWD/tmp/zk_server_jaas.conf
413 cp $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"mnt/zk/zk_server_jaas.conf $configfile
414 output_yaml=$PWD/tmp/dmaapmr_zk_server_cfc.yaml
415 __kube_create_configmap dmaapmr-zk-server-jaas.conf $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
418 input_yaml=$SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"svc.yaml
419 output_yaml=$PWD/tmp/dmaapmr_svc.yaml
420 __kube_create_instance service $MR_DMAAP_APP_NAME $input_yaml $output_yaml
423 input_yaml=$SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"app.yaml
424 output_yaml=$PWD/tmp/dmaapmr_app.yaml
425 __kube_create_instance app $MR_DMAAP_APP_NAME $input_yaml $output_yaml
428 echo " Retrieving host and ports for service..."
429 MR_DMAAP_HOST_NAME=$(__kube_get_service_host $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE)
431 MR_EXT_PORT=$(__kube_get_service_port $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE "http")
432 MR_EXT_SECURE_PORT=$(__kube_get_service_port $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE "https")
434 echo " Host IP, http port, https port: $MR_DMAAP_APP_NAME $MR_EXT_PORT $MR_EXT_SECURE_PORT"
436 if [ $MR_HTTPX == "http" ]; then
437 MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_HOST_NAME":"$MR_EXT_PORT
438 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXT_PORT
440 MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_HOST_NAME":"$MR_EXT_SECURE_PORT
441 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXT_SECURE_PORT
444 __check_service_start $MR_DMAAP_APP_NAME $MR_DMAAP_PATH$MR_DMAAP_ALIVE_URL
448 if [ $retcode_included_mr -eq 0 ]; then
449 #exporting needed var for deployment
450 export MR_STUB_APP_NAME
451 export KUBE_ONAP_NAMESPACE
453 export MR_INTERNAL_PORT
454 export MR_INTERNAL_SECURE_PORT
455 export MR_EXTERNAL_PORT
456 export MR_EXTERNAL_SECURE_PORT
458 if [ $retcode_prestarted_dmaapmr -eq 0 ] || [ $retcode_included_dmaapmr -eq 0 ]; then # Set topics for dmaap
459 export TOPIC_READ="http://$MR_DMAAP_APP_NAME.$KUBE_ONAP_NAMESPACE:$MR_INTERNAL_PORT/events/$MR_READ_TOPIC"
460 export TOPIC_WRITE="http://$MR_DMAAP_APP_NAME.$KUBE_ONAP_NAMESPACE:$MR_INTERNAL_PORT/events/$MR_WRITE_TOPIC/users/mr-stub?timeout=15000&limit=100"
463 export TOPIC_WRITE=""
466 #Check if onap namespace exists, if not create it
467 __kube_create_namespace $KUBE_ONAP_NAMESPACE
470 input_yaml=$SIM_GROUP"/"$MR_STUB_COMPOSE_DIR"/"svc.yaml
471 output_yaml=$PWD/tmp/mr_svc.yaml
472 __kube_create_instance service $MR_STUB_APP_NAME $input_yaml $output_yaml
475 input_yaml=$SIM_GROUP"/"$MR_STUB_COMPOSE_DIR"/"app.yaml
476 output_yaml=$PWD/tmp/mr_app.yaml
477 __kube_create_instance app $MR_STUB_APP_NAME $input_yaml $output_yaml
483 echo " Retrieving host and ports for service..."
484 MR_STUB_HOST_NAME=$(__kube_get_service_host $MR_STUB_APP_NAME $KUBE_ONAP_NAMESPACE)
486 MR_EXT_PORT=$(__kube_get_service_port $MR_STUB_APP_NAME $KUBE_ONAP_NAMESPACE "http")
487 MR_EXT_SECURE_PORT=$(__kube_get_service_port $MR_STUB_APP_NAME $KUBE_ONAP_NAMESPACE "https")
489 echo " Host IP, http port, https port: $MR_STUB_APP_NAME $MR_EXT_PORT $MR_EXT_SECURE_PORT"
490 if [ $MR_HTTPX == "http" ]; then
491 MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_HOST_NAME":"$MR_EXT_PORT
492 if [ -z "$MR_SERVICE_PATH" ]; then
493 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXT_PORT
496 MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_HOST_NAME":"$MR_EXT_SECURE_PORT
497 if [ -z "$MR_SERVICE_PATH" ]; then
498 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXT_SECURE_PORT
501 MR_ADAPTER_HTTP="http://"$MR_STUB_HOST_NAME":"$MR_EXT_PORT
502 MR_ADAPTER_HTTPS="https://"$MR_STUB_HOST_NAME":"$MR_EXT_SECURE_PORT
504 __check_service_start $MR_STUB_APP_NAME $MR_STUB_PATH$MR_STUB_ALIVE_URL
506 echo -ne " Service $MR_STUB_APP_NAME - reset "$SAMELINE
507 result=$(__do_curl $MR_STUB_APP_NAME $MR_STUB_PATH/reset)
508 if [ $? -ne 0 ]; then
509 echo -e " Service $MR_STUB_APP_NAME - reset $RED Failed $ERED - will continue"
511 echo -e " Service $MR_STUB_APP_NAME - reset $GREEN OK $EGREEN"
517 __check_included_image 'DMAAPMR'
519 __check_included_image 'MR'
522 if [ $retcode_dmaapmr -ne 0 ] && [ $retcode_mr -ne 0 ]; then
523 echo -e $RED"The Message Router apps 'MR' and/or 'DMAAPMR' are not included in this test script"$ERED
524 echo -e $RED"The Message Router will not be started"$ERED
525 echo -e $RED"Both MR and DAAMPMR - or - only MR - need to be included"
529 if [ $retcode_dmaapmr -eq 0 ] && [ $retcode_mr -ne 0 ]; then
530 echo -e $RED"The Message Router apps 'MR' and/or 'DMAAPMR' are not included in this test script"$ERED
531 echo -e $RED"The Message Router will not be started"$ERED
532 echo -e $RED"Both MR and DAAMPMR - or - only MR - need to be included"
537 export TOPIC_WRITE=""
538 if [ $retcode_dmaapmr -eq 0 ]; then # Set topics for dmaap
539 export TOPIC_READ="http://$MR_DMAAP_APP_NAME:$MR_INTERNAL_PORT/events/$MR_READ_TOPIC"
540 export TOPIC_WRITE="http://$MR_DMAAP_APP_NAME:$MR_INTERNAL_PORT/events/$MR_WRITE_TOPIC/users/mr-stub?timeout=15000&limit=100"
543 export DOCKER_SIM_NWNAME
544 export ONAP_ZOOKEEPER_IMAGE
545 export MR_ZOOKEEPER_APP_NAME
546 export ONAP_KAFKA_IMAGE
547 export MR_KAFKA_APP_NAME
548 export ONAP_DMAAPMR_IMAGE
549 export MR_DMAAP_APP_NAME
550 export MR_DMAAP_LOCALHOST_PORT
551 export MR_INTERNAL_PORT
552 export MR_DMAAP_LOCALHOST_SECURE_PORT
553 export MR_INTERNAL_SECURE_PORT
555 if [ $retcode_dmaapmr -eq 0 ]; then
556 __start_container $MR_DMAAP_COMPOSE_DIR "" NODOCKERARGS 1 $MR_DMAAP_APP_NAME
558 __check_service_start $MR_DMAAP_APP_NAME $MR_DMAAP_PATH$MR_DMAAP_ALIVE_URL
561 __create_topic $MR_READ_TOPIC "Topic for reading policy messages"
563 __create_topic $MR_WRITE_TOPIC "Topic for writing policy messages"
565 __dmaap_pipeclean $MR_READ_TOPIC "/events/A1-POLICY-AGENT-READ" "/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=100"
567 __dmaap_pipeclean $MR_WRITE_TOPIC "/events/A1-POLICY-AGENT-WRITE" "/events/A1-POLICY-AGENT-WRITE/users/mr-stub?timeout=1000&limit=100"
569 echo " Current topics:"
570 curlString="$MR_DMAAP_PATH/topics"
571 result=$(__do_curl "$curlString")
572 echo $result | indent2
575 export DOCKER_SIM_NWNAME
576 export MR_STUB_APP_NAME
578 export MR_INTERNAL_PORT
579 export MR_INTERNAL_SECURE_PORT
580 export MR_STUB_LOCALHOST_PORT
581 export MR_STUB_LOCALHOST_SECURE_PORT
582 export MR_STUB_CERT_MOUNT_DIR
583 export MR_STUB_DISPLAY_NAME
585 if [ $retcode_mr -eq 0 ]; then
586 __start_container $MR_STUB_COMPOSE_DIR "" NODOCKERARGS 1 $MR_STUB_APP_NAME
588 __check_service_start $MR_STUB_APP_NAME $MR_STUB_PATH$MR_STUB_ALIVE_URL
596 ### Generic test cases for varaible checking
598 # Tests if a variable value in the MR stub is equal to a target value and and optional timeout.
599 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
600 # equal to the target or not.
601 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
602 # before setting pass or fail depending on if the variable value becomes equal to the target
604 # (Function for test scripts)
606 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
607 __var_test "MR" $MR_STUB_PATH/counter/ $1 "=" $2 $3
610 __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
614 # Tests if a variable value in the MR stub is greater than a target value and and optional timeout.
615 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
616 # greater than the target or not.
617 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
618 # before setting pass or fail depending on if the variable value becomes greater than the target
620 # (Function for test scripts)
622 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
623 __var_test "MR" $MR_STUB_PATH/counter/ $1 ">" $2 $3
626 __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
630 # Read a variable value from MR sim and send to stdout. Arg: <variable-name>
632 echo "$(__do_curl $MR_STUB_PATH/counter/$1)"
635 # Print a variable value from the MR stub.
636 # arg: <variable-name>
637 # (Function for test scripts)
641 __print_err "need one arg, <mr-param>" $@
644 echo -e $BOLD"INFO(${BASH_LINENO[0]}): mrstub, $1 = $(__do_curl $MR_STUB_PATH/counter/$1)"$EBOLD