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 MR shall never be pulled from remote 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
70 __retag_and_push_image MRSTUB_IMAGE
75 echo -e $RED" Build Failed"$ERED
78 echo -e $RED"Exiting...."$ERED
83 # Build image (only for simulator or interfaces stubs owned by the test environment)
84 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
85 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
86 __DMAAPMR_imagebuild() {
87 echo -e $RED"Image for app DMAAPMR shall never be built"$ERED
90 # Generate a string for each included image using the app display name and a docker images format string
91 # If a custom image repo is used then also the source image from the local repo is listed
92 # arg: <docker-images-format-string> <file-to-append>
94 echo -e "$MR_STUB_DISPLAY_NAME\t$(docker images --format $1 $MRSTUB_IMAGE)" >> $2
95 if [ ! -z "$MRSTUB_IMAGE_SOURCE" ]; then
96 echo -e "-- source image --\t$(docker images --format $1 $MRSTUB_IMAGE_SOURCE)" >> $2
100 # Generate a string for each included image using the app display name and a docker images format string
101 # If a custom image repo is used then also the source image from the local repo is listed
102 # arg: <docker-images-format-string> <file-to-append>
103 __DMAAPMR_image_data() {
104 echo -e "DMAAP Message Router\t$(docker images --format $1 $ONAP_DMAAPMR_IMAGE)" >> $2
105 if [ ! -z "$ONAP_DMAAPMR_IMAGE_SOURCE" ]; then
106 echo -e "-- source image --\t$(docker images --format $1 $ONAP_DMAAPMR_IMAGE_SOURCE)" >> $2
108 echo -e "ZooKeeper\t$(docker images --format $1 $ONAP_ZOOKEEPER_IMAGE)" >> $2
109 if [ ! -z "$ONAP_ZOOKEEPER_IMAGE_SOURCE" ]; then
110 echo -e "-- source image --\t$(docker images --format $1 $ONAP_ZOOKEEPER_IMAGE_SOURCE)" >> $2
112 echo -e "Kafka\t$(docker images --format $1 $ONAP_KAFKA_IMAGE)" >> $2
113 if [ ! -z "$ONAP_KAFKA_IMAGE_SOURCE" ]; then
114 echo -e "-- source image --\t$(docker images --format $1 $ONAP_KAFKA_IMAGE_SOURCE)" >> $2
118 # Scale kubernetes resources to zero
119 # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
120 # This function is called for apps fully managed by the test script
121 __MR_kube_scale_zero() {
122 __kube_scale_all_resources $KUBE_ONAP_NAMESPACE autotest MR
125 # Scale kubernetes resources to zero
126 # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
127 # This function is called for apps fully managed by the test script
128 __DMAAPMR_kube_scale_zero() {
129 __kube_scale_all_resources $KUBE_ONAP_NAMESPACE autotest DMAAPMR
132 # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
133 # This function is called for prestarted apps not managed by the test script.
134 __MR_kube_scale_zero_and_wait() {
135 echo -e " MR replicas kept as is"
138 # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
139 # This function is called for prestarted apps not managed by the test script.
140 __DMAAPMR_kube_scale_zero_and_wait() {
141 echo -e " DMAAP replicas kept as is"
144 # Delete all kube resouces for the app
145 # This function is called for apps managed by the test script.
146 __MR_kube_delete_all() {
147 __kube_delete_all_resources $KUBE_ONAP_NAMESPACE autotest MR
150 # Delete all kube resouces for the app
151 # This function is called for apps managed by the test script.
152 __DMAAPMR_kube_delete_all() {
153 __kube_delete_all_resources $KUBE_ONAP_NAMESPACE autotest DMAAPMR
157 # This function is called for apps managed by the test script.
158 # args: <log-dir> <file-prexix>
159 __MR_store_docker_logs() {
160 docker logs $MR_STUB_APP_NAME > $1$2_mr_stub.log 2>&1
164 # This function is called for apps managed by the test script.
165 # args: <log-dir> <file-prexix>
166 __DMAAPMR_store_docker_logs() {
167 docker logs $MR_DMAAP_APP_NAME > $1$2mr.log 2>&1
168 docker logs $MR_KAFKA_APP_NAME > $1$2_mr_kafka.log 2>&1
169 docker logs $MR_ZOOKEEPER_APP_NAME > $1$2_mr_zookeeper.log 2>&1
172 #######################################################
174 ## Access to Message Router
175 # Host name may be changed if app started by kube
176 # Direct access from script
178 MR_STUB_HOST_NAME=$LOCALHOST_NAME
179 MR_DMAAP_HOST_NAME=$LOCALHOST_NAME
180 MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_HOST_NAME":"$MR_STUB_LOCALHOST_PORT
181 MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_HOST_NAME":"$MR_DMAAP_LOCALHOST_PORT
182 #Docker/Kube internal path
183 if [ $RUNMODE == "KUBE" ]; then
184 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_PORT
185 __check_included_image "DMAAPMR"
186 if [ $? -eq 0 ]; then
187 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_PORT
189 __check_prestarted_image "DMAAPMR"
190 if [ $? -eq 0 ]; then
191 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_PORT
194 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME":"$MR_INTERNAL_PORT
195 __check_included_image "DMAAPMR"
196 if [ $? -eq 0 ]; then
197 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME":"$MR_INTERNAL_PORT
200 MR_ADAPTER_HTTP="http://"$MR_STUB_HOST_NAME":"$MR_STUB_LOCALHOST_PORT
201 MR_ADAPTER_HTTPS="https://"$MR_STUB_HOST_NAME":"$MR_STUB_LOCALHOST_SECURE_PORT
204 #####################
205 ### MR stub functions
206 #####################
209 echo -e $BOLD"MR protocol setting"$EBOLD
210 echo -e " Using $BOLD http $EBOLD towards MR"
212 MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_HOST_NAME":"$MR_STUB_LOCALHOST_PORT
213 MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_HOST_NAME":"$MR_DMAAP_LOCALHOST_PORT
214 #Docker/Kube internal path
215 if [ $RUNMODE == "KUBE" ]; then
216 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_PORT
217 __check_included_image "DMAAPMR"
218 if [ $? -eq 0 ]; then
219 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_PORT
221 __check_prestarted_image "DMAAPMR"
222 if [ $? -eq 0 ]; then
223 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_PORT
226 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME":"$MR_INTERNAL_PORT
227 __check_included_image "DMAAPMR"
228 if [ $? -eq 0 ]; then
229 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME":"$MR_INTERNAL_PORT
236 echo -e $BOLD"MR protocol setting"$EBOLD
237 echo -e " Using $BOLD https $EBOLD towards MR"
239 MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_HOST_NAME":"$MR_STUB_LOCALHOST_SECURE_PORT
240 MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_HOST_NAME":"$MR_DMAAP_LOCALHOST_SECURE_PORT
241 #Docker/Kube internal path
242 if [ $RUNMODE == "KUBE" ]; then
243 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_SECURE_PORT
244 __check_included_image "DMAAPMR"
245 if [ $? -eq 0 ]; then
246 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_SECURE_PORT
248 __check_prestarted_image "DMAAPMR"
249 if [ $? -eq 0 ]; then
250 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_SECURE_PORT
253 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME":"$MR_INTERNAL_SECURE_PORT
254 __check_included_image "DMAAPMR"
255 if [ $? -eq 0 ]; then
256 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME":"$MR_INTERNAL_SECURE_PORT
262 # Create a dmaap mr topic
263 # args: <topic name> <topic-description>
265 echo -ne " Creating read topic: $1"$SAMELINE
267 json_topic="{\"topicName\":\"$1\",\"partitionCount\":\"2\", \"replicationCount\":\"3\", \"transactionEnabled\":\"false\",\"topicDescription\":\"$2\"}"
268 echo $json_topic > ./tmp/$1.json
270 curlString="$MR_DMAAP_PATH/topics/create -X POST -H Content-Type:application/json -d@./tmp/$1.json"
272 while [ $topic_retries -gt 0 ]; do
273 let topic_retries=topic_retries-1
274 result=$(__do_curl "$curlString")
275 if [ $? -eq 0 ]; then
277 echo -e " Creating read topic: $1 $GREEN OK $EGREEN"
279 if [ $? -ne 0 ]; then
280 if [ $topic_retries -eq 0 ]; then
281 echo -e " Creating read topic: $1 $RED Failed $ERED"
292 # Do a pipeclean of a topic - to overcome dmaap mr bug...
293 # args: <topic> <post-url> <read-url>
294 __dmaap_pipeclean() {
296 echo -ne " Doing dmaap-mr pipe cleaning on topic: $1"$SAMELINE
297 while [ $pipeclean_retries -gt 0 ]; do
298 echo "{\"pipeclean-$1\":$pipeclean_retries}" > ./tmp/pipeclean.json
299 let pipeclean_retries=pipeclean_retries-1
300 curlString="$MR_DMAAP_PATH$2 -X POST -H Content-Type:application/json -d@./tmp/pipeclean.json"
301 result=$(__do_curl "$curlString")
302 if [ $? -ne 0 ]; then
305 curlString="$MR_DMAAP_PATH$3"
306 result=$(__do_curl "$curlString")
307 if [ $? -eq 0 ]; then
308 if [ $result != "[]" ]; then
309 echo -e " Doing dmaap-mr pipe cleaning on topic: $1 $GREEN OK $EGREEN"
318 echo -e "Doing dmaap-mr pipe cleaning on topic: $1 $RED Failed $ERED"
322 # Start the Message Router stub interface in the simulator group
324 # (Function for test scripts)
327 echo -e $BOLD"Starting $MR_DMAAP_DISPLAY_NAME and/or $MR_STUB_DISPLAY_NAME"$EBOLD
329 if [ $RUNMODE == "KUBE" ]; then
331 # Table of possible combinations of included mr and included/prestarted dmaap-mr
332 # mr can never be prestarted
333 # mr can be used stand alone
334 # if dmaapmr is included/prestarted, then mr is needed as well as frontend
336 # Inverted logic - 0 mean true, 1 means false
337 # mr prestarted 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
338 # mr included 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1
339 # dmaap prestarted 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1
340 # dmaap included 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
341 # ==================================================
342 # OK 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1
344 __check_prestarted_image 'MR'
345 retcode_prestarted_mr=$?
346 __check_included_image 'MR'
347 retcode_included_mr=$?
349 __check_prestarted_image 'DMAAPMR'
350 retcode_prestarted_dmaapmr=$?
351 __check_included_image 'DMAAPMR'
352 retcode_included_dmaapmr=$?
356 if [ $retcode_prestarted_mr -ne 0 ] && [ $retcode_included_mr -eq 0 ]; then
357 if [ $retcode_prestarted_dmaapmr -ne 0 ] && [ $retcode_included_dmaapmr -eq 0 ]; then
362 if [ $retcode_prestarted_mr -ne 0 ] && [ $retcode_included_mr -eq 0 ]; then
363 if [ $retcode_prestarted_dmaapmr -eq 0 ] && [ $retcode_included_dmaapmr -ne 0 ]; then
368 if [ $retcode_prestarted_mr -ne 0 ] && [ $retcode_included_mr -eq 0 ]; then
369 if [ $retcode_prestarted_dmaapmr -ne 0 ] && [ $retcode_included_dmaapmr -ne 0 ]; then
374 if [ $paramerror -ne 0 ]; then
375 echo -e $RED"The Message Router apps 'MR' and/or 'DMAAPMR' are not included in this test script"$ERED
376 echo -e $RED"The Message Router will not be started"$ERED
377 echo -e $RED"Both MR and DAAMPMR - or - only MR - need to be included and/or prestarted"
381 if [ $retcode_prestarted_dmaapmr -eq 0 ]; then
382 echo -e " Using existing $MR_DMAAP_APP_NAME deployment and service"
383 __kube_scale deployment $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE 1
386 if [ $retcode_included_dmaapmr -eq 0 ]; then
387 #export MR_DMAAP_APP_NAME
388 export MR_DMAAP_KUBE_APP_NAME=message-router
389 MR_DMAAP_APP_NAME=$MR_DMAAP_KUBE_APP_NAME
390 export KUBE_ONAP_NAMESPACE
391 export MR_EXTERNAL_PORT
392 export MR_INTERNAL_PORT
393 export MR_EXTERNAL_SECURE_PORT
394 export MR_INTERNAL_SECURE_PORT
395 export ONAP_DMAAPMR_IMAGE
397 export MR_KAFKA_BWDS_NAME=akfak-bwds
398 export KUBE_ONAP_NAMESPACE
400 export MR_ZOOKEEPER_APP_NAME
401 export ONAP_ZOOKEEPER_IMAGE
403 #Check if onap namespace exists, if not create it
404 __kube_create_namespace $KUBE_ONAP_NAMESPACE
406 # TODO - Fix domain name substitution in the prop file
407 # Create config maps - dmaapmr app
408 configfile=$PWD/tmp/MsgRtrApi.properties
409 cp $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"mnt/mr/KUBE-MsgRtrApi.properties $configfile
410 output_yaml=$PWD/tmp/dmaapmr_msgrtrapi_cfc.yaml
411 __kube_create_configmap dmaapmr-msgrtrapi.properties $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
413 configfile=$PWD/tmp/logback.xml
414 cp $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"mnt/mr/logback.xml $configfile
415 output_yaml=$PWD/tmp/dmaapmr_logback_cfc.yaml
416 __kube_create_configmap dmaapmr-logback.xml $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
418 configfile=$PWD/tmp/cadi.properties
419 cp $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"mnt/mr/cadi.properties $configfile
420 output_yaml=$PWD/tmp/dmaapmr_cadi_cfc.yaml
421 __kube_create_configmap dmaapmr-cadi.properties $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
423 # Create config maps - kafka app
424 configfile=$PWD/tmp/zk_client_jaas.conf
425 cp $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"mnt/kafka/zk_client_jaas.conf $configfile
426 output_yaml=$PWD/tmp/dmaapmr_zk_client_cfc.yaml
427 __kube_create_configmap dmaapmr-zk-client-jaas.conf $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
429 # Create config maps - zookeeper app
430 configfile=$PWD/tmp/zk_server_jaas.conf
431 cp $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"mnt/zk/zk_server_jaas.conf $configfile
432 output_yaml=$PWD/tmp/dmaapmr_zk_server_cfc.yaml
433 __kube_create_configmap dmaapmr-zk-server-jaas.conf $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
436 input_yaml=$SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"svc.yaml
437 output_yaml=$PWD/tmp/dmaapmr_svc.yaml
438 __kube_create_instance service $MR_DMAAP_APP_NAME $input_yaml $output_yaml
441 input_yaml=$SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"app.yaml
442 output_yaml=$PWD/tmp/dmaapmr_app.yaml
443 __kube_create_instance app $MR_DMAAP_APP_NAME $input_yaml $output_yaml
446 echo " Retrieving host and ports for service..."
447 MR_DMAAP_HOST_NAME=$(__kube_get_service_host $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE)
449 MR_EXT_PORT=$(__kube_get_service_port $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE "http")
450 MR_EXT_SECURE_PORT=$(__kube_get_service_port $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE "https")
452 echo " Host IP, http port, https port: $MR_DMAAP_APP_NAME $MR_EXT_PORT $MR_EXT_SECURE_PORT"
454 if [ $MR_HTTPX == "http" ]; then
455 MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_HOST_NAME":"$MR_EXT_PORT
456 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXT_PORT
458 MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_HOST_NAME":"$MR_EXT_SECURE_PORT
459 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXT_SECURE_PORT
462 __check_service_start $MR_DMAAP_APP_NAME $MR_DMAAP_PATH$MR_DMAAP_ALIVE_URL
466 if [ $retcode_included_mr -eq 0 ]; then
467 #exporting needed var for deployment
468 export MR_STUB_APP_NAME
469 export KUBE_ONAP_NAMESPACE
471 export MR_INTERNAL_PORT
472 export MR_INTERNAL_SECURE_PORT
473 export MR_EXTERNAL_PORT
474 export MR_EXTERNAL_SECURE_PORT
476 if [ $retcode_prestarted_dmaapmr -eq 0 ] || [ $retcode_included_dmaapmr -eq 0 ]; then # Set topics for dmaap
477 export TOPIC_READ="http://$MR_DMAAP_APP_NAME.$KUBE_ONAP_NAMESPACE:$MR_INTERNAL_PORT/events/$MR_READ_TOPIC"
478 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"
481 export TOPIC_WRITE=""
484 #Check if onap namespace exists, if not create it
485 __kube_create_namespace $KUBE_ONAP_NAMESPACE
488 input_yaml=$SIM_GROUP"/"$MR_STUB_COMPOSE_DIR"/"svc.yaml
489 output_yaml=$PWD/tmp/mr_svc.yaml
490 __kube_create_instance service $MR_STUB_APP_NAME $input_yaml $output_yaml
493 input_yaml=$SIM_GROUP"/"$MR_STUB_COMPOSE_DIR"/"app.yaml
494 output_yaml=$PWD/tmp/mr_app.yaml
495 __kube_create_instance app $MR_STUB_APP_NAME $input_yaml $output_yaml
501 echo " Retrieving host and ports for service..."
502 MR_STUB_HOST_NAME=$(__kube_get_service_host $MR_STUB_APP_NAME $KUBE_ONAP_NAMESPACE)
504 MR_EXT_PORT=$(__kube_get_service_port $MR_STUB_APP_NAME $KUBE_ONAP_NAMESPACE "http")
505 MR_EXT_SECURE_PORT=$(__kube_get_service_port $MR_STUB_APP_NAME $KUBE_ONAP_NAMESPACE "https")
507 echo " Host IP, http port, https port: $MR_STUB_APP_NAME $MR_EXT_PORT $MR_EXT_SECURE_PORT"
508 if [ $MR_HTTPX == "http" ]; then
509 MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_HOST_NAME":"$MR_EXT_PORT
510 if [ -z "$MR_SERVICE_PATH" ]; then
511 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXT_PORT
514 MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_HOST_NAME":"$MR_EXT_SECURE_PORT
515 if [ -z "$MR_SERVICE_PATH" ]; then
516 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXT_SECURE_PORT
519 MR_ADAPTER_HTTP="http://"$MR_STUB_HOST_NAME":"$MR_EXT_PORT
520 MR_ADAPTER_HTTPS="https://"$MR_STUB_HOST_NAME":"$MR_EXT_SECURE_PORT
522 __check_service_start $MR_STUB_APP_NAME $MR_STUB_PATH$MR_STUB_ALIVE_URL
524 echo -ne " Service $MR_STUB_APP_NAME - reset "$SAMELINE
525 result=$(__do_curl $MR_STUB_APP_NAME $MR_STUB_PATH/reset)
526 if [ $? -ne 0 ]; then
527 echo -e " Service $MR_STUB_APP_NAME - reset $RED Failed $ERED - will continue"
529 echo -e " Service $MR_STUB_APP_NAME - reset $GREEN OK $EGREEN"
535 __check_included_image 'DMAAPMR'
537 __check_included_image 'MR'
540 if [ $retcode_dmaapmr -ne 0 ] && [ $retcode_mr -ne 0 ]; then
541 echo -e $RED"The Message Router apps 'MR' and/or 'DMAAPMR' are not included in this test script"$ERED
542 echo -e $RED"The Message Router will not be started"$ERED
543 echo -e $RED"Both MR and DAAMPMR - or - only MR - need to be included"
547 if [ $retcode_dmaapmr -eq 0 ] && [ $retcode_mr -ne 0 ]; then
548 echo -e $RED"The Message Router apps 'MR' and/or 'DMAAPMR' are not included in this test script"$ERED
549 echo -e $RED"The Message Router will not be started"$ERED
550 echo -e $RED"Both MR and DAAMPMR - or - only MR - need to be included"
555 export TOPIC_WRITE=""
556 if [ $retcode_dmaapmr -eq 0 ]; then # Set topics for dmaap
557 export TOPIC_READ="http://$MR_DMAAP_APP_NAME:$MR_INTERNAL_PORT/events/$MR_READ_TOPIC"
558 export TOPIC_WRITE="http://$MR_DMAAP_APP_NAME:$MR_INTERNAL_PORT/events/$MR_WRITE_TOPIC/users/mr-stub?timeout=15000&limit=100"
561 export DOCKER_SIM_NWNAME
562 export ONAP_ZOOKEEPER_IMAGE
563 export MR_ZOOKEEPER_APP_NAME
564 export ONAP_KAFKA_IMAGE
565 export MR_KAFKA_APP_NAME
566 export ONAP_DMAAPMR_IMAGE
567 export MR_DMAAP_APP_NAME
568 export MR_DMAAP_LOCALHOST_PORT
569 export MR_INTERNAL_PORT
570 export MR_DMAAP_LOCALHOST_SECURE_PORT
571 export MR_INTERNAL_SECURE_PORT
573 if [ $retcode_dmaapmr -eq 0 ]; then
574 __start_container $MR_DMAAP_COMPOSE_DIR "" NODOCKERARGS 1 $MR_DMAAP_APP_NAME
576 __check_service_start $MR_DMAAP_APP_NAME $MR_DMAAP_PATH$MR_DMAAP_ALIVE_URL
579 __create_topic $MR_READ_TOPIC "Topic for reading policy messages"
581 __create_topic $MR_WRITE_TOPIC "Topic for writing policy messages"
583 __dmaap_pipeclean $MR_READ_TOPIC "/events/$MR_READ_TOPIC" "/events/$MR_READ_TOPIC/users/policy-agent?timeout=1000&limit=100"
585 __dmaap_pipeclean $MR_WRITE_TOPIC "/events/$MR_WRITE_TOPIC" "/events/$MR_WRITE_TOPIC/users/mr-stub?timeout=1000&limit=100"
587 echo " Current topics:"
588 curlString="$MR_DMAAP_PATH/topics"
589 result=$(__do_curl "$curlString")
590 echo $result | indent2
593 export DOCKER_SIM_NWNAME
594 export MR_STUB_APP_NAME
596 export MR_INTERNAL_PORT
597 export MR_INTERNAL_SECURE_PORT
598 export MR_STUB_LOCALHOST_PORT
599 export MR_STUB_LOCALHOST_SECURE_PORT
600 export MR_STUB_CERT_MOUNT_DIR
601 export MR_STUB_DISPLAY_NAME
603 if [ $retcode_mr -eq 0 ]; then
604 __start_container $MR_STUB_COMPOSE_DIR "" NODOCKERARGS 1 $MR_STUB_APP_NAME
606 __check_service_start $MR_STUB_APP_NAME $MR_STUB_PATH$MR_STUB_ALIVE_URL
614 ### Generic test cases for varaible checking
616 # Tests if a variable value in the MR stub is equal to a target value and and optional timeout.
617 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
618 # equal to the target or not.
619 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
620 # before setting pass or fail depending on if the variable value becomes equal to the target
622 # (Function for test scripts)
624 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
625 __var_test "MR" $MR_STUB_PATH/counter/ $1 "=" $2 $3
628 __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
632 # Tests if a variable value in the MR stub is greater than a target value and and optional timeout.
633 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
634 # greater than the target or not.
635 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
636 # before setting pass or fail depending on if the variable value becomes greater than the target
638 # (Function for test scripts)
640 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
641 __var_test "MR" $MR_STUB_PATH/counter/ $1 ">" $2 $3
644 __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
648 # Read a variable value from MR sim and send to stdout. Arg: <variable-name>
650 echo "$(__do_curl $MR_STUB_PATH/counter/$1)"
653 # Print a variable value from the MR stub.
654 # arg: <variable-name>
655 # (Function for test scripts)
659 __print_err "need one arg, <mr-param>" $@
662 echo -e $BOLD"INFO(${BASH_LINENO[0]}): mrstub, $1 = $(__do_curl $MR_STUB_PATH/counter/$1)"$EBOLD