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 if [ $RUNMODE == "KUBE" ]; then
161 kubectl logs -l "autotest=MR" -n $KUBE_ONAP_NAMESPACE --tail=-1 > $1$2_mr_stub.log 2>&1
163 docker logs $MR_STUB_APP_NAME > $1$2_mr_stub.log 2>&1
168 # This function is called for apps managed by the test script.
169 # args: <log-dir> <file-prexix>
170 __DMAAPMR_store_docker_logs() {
171 if [ $RUNMODE == "KUBE" ]; then
172 for podname in $(kubectl get pods -n $KUBE_ONAP_NAMESPACE -l "autotest=DMAAPMR" -o custom-columns=":metadata.name"); do
173 kubectl logs -n $KUBE_ONAP_NAMESPACE $podname --tail=-1 > $1$2_$podname.log 2>&1
176 docker logs $MR_DMAAP_APP_NAME > $1$2mr.log 2>&1
177 docker logs $MR_KAFKA_APP_NAME > $1$2_mr_kafka.log 2>&1
178 docker logs $MR_ZOOKEEPER_APP_NAME > $1$2_mr_zookeeper.log 2>&1
182 # Initial setup of protocol, host and ports
183 # This function is called for apps managed by the test script.
185 __MR_initial_setup() {
189 # Initial setup of protocol, host and ports
190 # This function is called for apps managed by the test script.
192 __DMAAPMR_initial_setup() {
193 : # handle by __MR_initial_setup
197 #######################################################
200 __mr_set_protocoll "http" $MR_INTERNAL_PORT $MR_EXTERNAL_PORT $MR_INTERNAL_PORT $MR_EXTERNAL_PORT $MR_INTERNAL_SECURE_PORT $MR_EXT_SECURE_PORT
204 __mr_set_protocoll "https" $MR_INTERNAL_SECURE_PORT $MR_EXTERNAL_SECURE_PORT
207 # Setup paths to svc/container for internal and external access
208 # args: <protocol> <internal-port> <external-port> <mr-stub-internal-port> <mr-stub-external-port> <mr-stub-internal-secure-port> <mr-stub-external-secure-port>
209 __mr_set_protocoll() {
210 echo -e $BOLD"$MR_STUB_DISPLAY_NAME and $MR_DMAAP_DISPLAY_NAME protocol setting"$EBOLD
211 echo -e " Using $BOLD http $EBOLD towards $MR_STUB_DISPLAY_NAME and $MR_DMAAP_DISPLAY_NAME"
213 ## Access to Dmaap mediator
217 # Access via test script
218 MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME":"$2 # access from script via proxy, docker
219 MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME":"$2 # access from script via proxy, docker
221 MR_SERVICE_PATH=$MR_STUB_PATH # access container->container, docker - access pod->svc, kube
222 __check_included_image "DMAAPMR"
223 if [ $? -eq 0 ]; then
224 MR_SERVICE_PATH=$MR_DMAAP_PATH # access container->container, docker - access pod->svc, kube
227 # For directing calls from script to e.g.PMS via message rounter
228 # Theses case shall always go though the mr-stub
229 MR_ADAPTER_HTTP="http://"$MR_STUB_APP_NAME":"$4
230 MR_ADAPTER_HTTPS="https://"$MR_STUB_APP_NAME":"$6
232 if [ $RUNMODE == "KUBE" ]; then
233 MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME.$KUBE_ONAP_NAMESPACE":"$3 # access from script via proxy, kube
234 MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME.$KUBE_ONAP_NAMESPACE":"$3 # access from script via proxy, kube
236 MR_SERVICE_PATH=$MR_STUB_PATH
237 __check_included_image "DMAAPMR"
238 if [ $? -eq 0 ]; then
239 MR_SERVICE_PATH=$MR_DMAAP_PATH
241 __check_prestarted_image "DMAAPMR"
242 if [ $? -eq 0 ]; then
243 MR_SERVICE_PATH=$MR_DMAAP_PATH
246 # For directing calls from script to e.g.PMS, via message rounter
247 # These calls shall always go though the mr-stub
248 MR_ADAPTER_HTTP="http://"$MR_STUB_APP_NAME":"$5
249 MR_ADAPTER_HTTPS="https://"$MR_STUB_APP_NAME":"$7
252 # For calls from script to the mr-stub
253 MR_STUB_ADAPTER=$MR_STUB_PATH
254 MR_STUB_ADAPTER_TYPE="REST"
259 # Export env vars for config files, docker compose and kube resources
261 __dmaapmr_export_vars() {
263 export DOCKER_SIM_NWNAME
264 export ONAP_ZOOKEEPER_IMAGE
265 export MR_ZOOKEEPER_APP_NAME
266 export ONAP_KAFKA_IMAGE
267 export MR_KAFKA_APP_NAME
268 export ONAP_DMAAPMR_IMAGE
269 export MR_DMAAP_APP_NAME
270 export MR_DMAAP_LOCALHOST_PORT
271 export MR_INTERNAL_PORT
272 export MR_DMAAP_LOCALHOST_SECURE_PORT
273 export MR_INTERNAL_SECURE_PORT
274 export MR_DMAAP_HOST_MNT_DIR
277 # Export env vars for config files, docker compose and kube resources
281 export DOCKER_SIM_NWNAME
282 export MR_STUB_APP_NAME
284 export MR_INTERNAL_PORT
285 export MR_INTERNAL_SECURE_PORT
286 export MR_STUB_LOCALHOST_PORT
287 export MR_STUB_LOCALHOST_SECURE_PORT
288 export MR_STUB_CERT_MOUNT_DIR
289 export MR_STUB_DISPLAY_NAME
293 # Start the Message Router stub interface in the simulator group
295 # (Function for test scripts)
298 echo -e $BOLD"Starting $MR_DMAAP_DISPLAY_NAME and/or $MR_STUB_DISPLAY_NAME"$EBOLD
300 if [ $RUNMODE == "KUBE" ]; then
302 # Table of possible combinations of included mr and included/prestarted dmaap-mr
303 # mr can never be prestarted
304 # mr can be used stand alone
305 # if dmaapmr is included/prestarted, then mr is needed as well as frontend
307 # Inverted logic - 0 mean true, 1 means false
308 # mr prestarted 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
309 # mr included 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1
310 # dmaap prestarted 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1
311 # dmaap included 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
312 # ==================================================
313 # OK 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1
315 __check_prestarted_image 'MR'
316 retcode_prestarted_mr=$?
317 __check_included_image 'MR'
318 retcode_included_mr=$?
320 __check_prestarted_image 'DMAAPMR'
321 retcode_prestarted_dmaapmr=$?
322 __check_included_image 'DMAAPMR'
323 retcode_included_dmaapmr=$?
327 if [ $retcode_prestarted_mr -ne 0 ] && [ $retcode_included_mr -eq 0 ]; then
328 if [ $retcode_prestarted_dmaapmr -ne 0 ] && [ $retcode_included_dmaapmr -eq 0 ]; then
333 if [ $retcode_prestarted_mr -ne 0 ] && [ $retcode_included_mr -eq 0 ]; then
334 if [ $retcode_prestarted_dmaapmr -eq 0 ] && [ $retcode_included_dmaapmr -ne 0 ]; then
339 if [ $retcode_prestarted_mr -ne 0 ] && [ $retcode_included_mr -eq 0 ]; then
340 if [ $retcode_prestarted_dmaapmr -ne 0 ] && [ $retcode_included_dmaapmr -ne 0 ]; then
345 if [ $paramerror -ne 0 ]; then
346 echo -e $RED"The Message Router apps 'MR' and/or 'DMAAPMR' are not included in this test script"$ERED
347 echo -e $RED"The Message Router will not be started"$ERED
348 echo -e $RED"Both MR and DAAMPMR - or - only MR - need to be included and/or prestarted"$ERED
352 if [ $retcode_prestarted_dmaapmr -eq 0 ]; then
353 echo -e " Using existing $MR_DMAAP_APP_NAME deployment and service"
354 __kube_scale deployment $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE 1
357 if [ $retcode_included_dmaapmr -eq 0 ]; then
359 __dmaapmr_export_vars
361 #export MR_DMAAP_APP_NAME
362 export MR_DMAAP_KUBE_APP_NAME=message-router
363 MR_DMAAP_APP_NAME=$MR_DMAAP_KUBE_APP_NAME
364 export KUBE_ONAP_NAMESPACE
365 export MR_EXTERNAL_PORT
366 export MR_INTERNAL_PORT
367 export MR_EXTERNAL_SECURE_PORT
368 export MR_INTERNAL_SECURE_PORT
369 export ONAP_DMAAPMR_IMAGE
371 export MR_KAFKA_BWDS_NAME=akfak-bwds
372 export MR_KAFKA_BWDS_NAME=kaka
373 export KUBE_ONAP_NAMESPACE
375 export MR_ZOOKEEPER_APP_NAME
376 export ONAP_ZOOKEEPER_IMAGE
378 #Check if onap namespace exists, if not create it
379 __kube_create_namespace $KUBE_ONAP_NAMESPACE
381 # TODO - Fix domain name substitution in the prop file
382 # Create config maps - dmaapmr app
383 configfile=$PWD/tmp/MsgRtrApi.properties
384 cp $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"$MR_DMAAP_HOST_MNT_DIR"/mr/KUBE-MsgRtrApi.properties $configfile
386 output_yaml=$PWD/tmp/dmaapmr_msgrtrapi_cfc.yaml
387 __kube_create_configmap dmaapmr-msgrtrapi.properties $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
389 configfile=$PWD/tmp/logback.xml
390 cp $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"$MR_DMAAP_HOST_MNT_DIR"/mr/logback.xml $configfile
391 output_yaml=$PWD/tmp/dmaapmr_logback_cfc.yaml
392 __kube_create_configmap dmaapmr-logback.xml $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
394 configfile=$PWD/tmp/cadi.properties
395 cp $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"$MR_DMAAP_HOST_MNT_DIR"/mr/cadi.properties $configfile
396 output_yaml=$PWD/tmp/dmaapmr_cadi_cfc.yaml
397 __kube_create_configmap dmaapmr-cadi.properties $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
399 # Create config maps - kafka app
400 configfile=$PWD/tmp/zk_client_jaas.conf
401 cp $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"$MR_DMAAP_HOST_MNT_DIR"/kafka/zk_client_jaas.conf $configfile
402 output_yaml=$PWD/tmp/dmaapmr_zk_client_cfc.yaml
403 __kube_create_configmap dmaapmr-zk-client-jaas.conf $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
405 # Create config maps - zookeeper app
406 configfile=$PWD/tmp/zk_server_jaas.conf
407 cp $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"$MR_DMAAP_HOST_MNT_DIR"/zk/zk_server_jaas.conf $configfile
408 output_yaml=$PWD/tmp/dmaapmr_zk_server_cfc.yaml
409 __kube_create_configmap dmaapmr-zk-server-jaas.conf $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
412 input_yaml=$SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"svc.yaml
413 output_yaml=$PWD/tmp/dmaapmr_svc.yaml
414 __kube_create_instance service $MR_DMAAP_APP_NAME $input_yaml $output_yaml
417 input_yaml=$SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"app.yaml
418 output_yaml=$PWD/tmp/dmaapmr_app.yaml
419 __kube_create_instance app $MR_DMAAP_APP_NAME $input_yaml $output_yaml
422 echo " Retrieving host and ports for service..."
423 MR_DMAAP_HOST_NAME=$(__kube_get_service_host $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE)
425 MR_EXT_PORT=$(__kube_get_service_port $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE "http")
426 MR_EXT_SECURE_PORT=$(__kube_get_service_port $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE "https")
428 echo " Host IP, http port, https port: $MR_DMAAP_APP_NAME $MR_EXT_PORT $MR_EXT_SECURE_PORT"
430 if [ $MR_HTTPX == "http" ]; then
431 MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_HOST_NAME":"$MR_EXT_PORT
432 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXT_PORT
434 MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_HOST_NAME":"$MR_EXT_SECURE_PORT
435 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXT_SECURE_PORT
438 __check_service_start $MR_DMAAP_APP_NAME $MR_DMAAP_PATH$MR_DMAAP_ALIVE_URL
442 if [ $retcode_included_mr -eq 0 ]; then
443 #exporting needed var for deployment
444 export MR_STUB_APP_NAME
445 export KUBE_ONAP_NAMESPACE
447 export MR_INTERNAL_PORT
448 export MR_INTERNAL_SECURE_PORT
449 export MR_EXTERNAL_PORT
450 export MR_EXTERNAL_SECURE_PORT
452 if [ $retcode_prestarted_dmaapmr -eq 0 ] || [ $retcode_included_dmaapmr -eq 0 ]; then # Set topics for dmaap
453 export TOPIC_READ="http://$MR_DMAAP_APP_NAME.$KUBE_ONAP_NAMESPACE:$MR_INTERNAL_PORT/events/$MR_READ_TOPIC"
454 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"
457 export TOPIC_WRITE=""
460 #Check if onap namespace exists, if not create it
461 __kube_create_namespace $KUBE_ONAP_NAMESPACE
464 input_yaml=$SIM_GROUP"/"$MR_STUB_COMPOSE_DIR"/"svc.yaml
465 output_yaml=$PWD/tmp/mr_svc.yaml
466 __kube_create_instance service $MR_STUB_APP_NAME $input_yaml $output_yaml
469 input_yaml=$SIM_GROUP"/"$MR_STUB_COMPOSE_DIR"/"app.yaml
470 output_yaml=$PWD/tmp/mr_app.yaml
471 __kube_create_instance app $MR_STUB_APP_NAME $input_yaml $output_yaml
477 echo " Retrieving host and ports for service..."
478 MR_STUB_HOST_NAME=$(__kube_get_service_host $MR_STUB_APP_NAME $KUBE_ONAP_NAMESPACE)
480 MR_EXT_PORT=$(__kube_get_service_port $MR_STUB_APP_NAME $KUBE_ONAP_NAMESPACE "http")
481 MR_EXT_SECURE_PORT=$(__kube_get_service_port $MR_STUB_APP_NAME $KUBE_ONAP_NAMESPACE "https")
483 echo " Host IP, http port, https port: $MR_STUB_APP_NAME $MR_EXT_PORT $MR_EXT_SECURE_PORT"
484 if [ $MR_HTTPX == "http" ]; then
485 MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_HOST_NAME":"$MR_EXT_PORT
486 if [ -z "$MR_SERVICE_PATH" ]; then
487 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXT_PORT
490 MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_HOST_NAME":"$MR_EXT_SECURE_PORT
491 if [ -z "$MR_SERVICE_PATH" ]; then
492 MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXT_SECURE_PORT
495 MR_ADAPTER_HTTP="http://"$MR_STUB_HOST_NAME":"$MR_EXT_PORT
496 MR_ADAPTER_HTTPS="https://"$MR_STUB_HOST_NAME":"$MR_EXT_SECURE_PORT
498 MR_STUB_ADAPTER=$MR_STUB_PATH
499 MR_STUB_ADAPTER_TYPE="REST"
501 __check_service_start $MR_STUB_APP_NAME $MR_STUB_PATH$MR_STUB_ALIVE_URL
503 echo -ne " Service $MR_STUB_APP_NAME - reset "$SAMELINE
504 result=$(__do_curl $MR_STUB_PATH/reset)
505 if [ $? -ne 0 ]; then
506 echo -e " Service $MR_STUB_APP_NAME - reset $RED Failed $ERED - will continue"
508 echo -e " Service $MR_STUB_APP_NAME - reset $GREEN OK $EGREEN"
514 __check_included_image 'DMAAPMR'
516 __check_included_image 'MR'
519 if [ $retcode_dmaapmr -ne 0 ] && [ $retcode_mr -ne 0 ]; then
520 echo -e $RED"The Message Router apps 'MR' and/or 'DMAAPMR' are not included in this test script"$ERED
521 echo -e $RED"The Message Router will not be started"$ERED
522 echo -e $RED"Both MR and DAAMPMR - or - only MR - need to be included"
526 if [ $retcode_dmaapmr -eq 0 ] && [ $retcode_mr -ne 0 ]; then
527 echo -e $RED"The Message Router apps 'MR' and/or 'DMAAPMR' are not included in this test script"$ERED
528 echo -e $RED"The Message Router will not be started"$ERED
529 echo -e $RED"Both MR and DAAMPMR - or - only MR - need to be included"
534 export TOPIC_WRITE=""
535 if [ $retcode_dmaapmr -eq 0 ]; then # Set topics for dmaap
536 export TOPIC_READ="http://$MR_DMAAP_APP_NAME:$MR_INTERNAL_PORT/events/$MR_READ_TOPIC"
537 export TOPIC_WRITE="http://$MR_DMAAP_APP_NAME:$MR_INTERNAL_PORT/events/$MR_WRITE_TOPIC/users/mr-stub?timeout=15000&limit=100"
540 __dmaapmr_export_vars
542 if [ $retcode_dmaapmr -eq 0 ]; then
543 __start_container $MR_DMAAP_COMPOSE_DIR "" NODOCKERARGS 1 $MR_DMAAP_APP_NAME
545 __check_service_start $MR_DMAAP_APP_NAME $MR_DMAAP_PATH$MR_DMAAP_ALIVE_URL
548 __create_topic $MR_READ_TOPIC "Topic for reading policy messages"
550 __create_topic $MR_WRITE_TOPIC "Topic for writing policy messages"
552 __dmaap_pipeclean $MR_READ_TOPIC "/events/$MR_READ_TOPIC" "/events/$MR_READ_TOPIC/users/policy-agent?timeout=1000&limit=100"
554 __dmaap_pipeclean $MR_WRITE_TOPIC "/events/$MR_WRITE_TOPIC" "/events/$MR_WRITE_TOPIC/users/mr-stub?timeout=1000&limit=100"
556 echo " Current topics:"
557 curlString="$MR_DMAAP_PATH/topics"
558 result=$(__do_curl "$curlString")
559 echo $result | indent2
564 if [ $retcode_mr -eq 0 ]; then
565 __start_container $MR_STUB_COMPOSE_DIR "" NODOCKERARGS 1 $MR_STUB_APP_NAME
567 __check_service_start $MR_STUB_APP_NAME $MR_STUB_PATH$MR_STUB_ALIVE_URL
575 # Create a dmaap mr topic
576 # args: <topic name> <topic-description>
578 echo -ne " Creating read topic: $1"$SAMELINE
580 json_topic="{\"topicName\":\"$1\",\"partitionCount\":\"2\", \"replicationCount\":\"3\", \"transactionEnabled\":\"false\",\"topicDescription\":\"$2\"}"
581 echo $json_topic > ./tmp/$1.json
583 curlString="$MR_DMAAP_PATH/topics/create -X POST -H Content-Type:application/json -d@./tmp/$1.json"
585 while [ $topic_retries -gt 0 ]; do
586 let topic_retries=topic_retries-1
587 result=$(__do_curl "$curlString")
588 if [ $? -eq 0 ]; then
590 echo -e " Creating read topic: $1 $GREEN OK $EGREEN"
592 if [ $? -ne 0 ]; then
593 if [ $topic_retries -eq 0 ]; then
594 echo -e " Creating read topic: $1 $RED Failed $ERED"
605 # Do a pipeclean of a topic - to overcome dmaap mr bug...
606 # args: <topic> <post-url> <read-url>
607 __dmaap_pipeclean() {
609 echo -ne " Doing dmaap-mr pipe cleaning on topic: $1"$SAMELINE
610 while [ $pipeclean_retries -gt 0 ]; do
611 echo "{\"pipeclean-$1\":$pipeclean_retries}" > ./tmp/pipeclean.json
612 let pipeclean_retries=pipeclean_retries-1
613 curlString="$MR_DMAAP_PATH$2 -X POST -H Content-Type:application/json -d@./tmp/pipeclean.json"
614 result=$(__do_curl "$curlString")
615 if [ $? -ne 0 ]; then
618 curlString="$MR_DMAAP_PATH$3"
619 result=$(__do_curl "$curlString")
620 if [ $? -eq 0 ]; then
621 if [ $result != "[]" ]; then
622 echo -e " Doing dmaap-mr pipe cleaning on topic: $1 $GREEN OK $EGREEN"
631 echo -e "Doing dmaap-mr pipe cleaning on topic: $1 $RED Failed $ERED"
636 ### Generic test cases for varaible checking
638 # Tests if a variable value in the MR stub is equal to a target value and and optional timeout.
639 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
640 # equal to the target or not.
641 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
642 # before setting pass or fail depending on if the variable value becomes equal to the target
644 # (Function for test scripts)
646 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
647 __var_test "MR" $MR_STUB_PATH/counter/ $1 "=" $2 $3
650 __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
654 # Tests if a variable value in the MR stub is greater than a target value and and optional timeout.
655 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
656 # greater than the target or not.
657 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
658 # before setting pass or fail depending on if the variable value becomes greater than the target
660 # (Function for test scripts)
662 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
663 __var_test "MR" $MR_STUB_PATH/counter/ $1 ">" $2 $3
666 __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
670 # Read a variable value from MR sim and send to stdout. Arg: <variable-name>
672 echo "$(__do_curl $MR_STUB_PATH/counter/$1)"
675 # Print a variable value from the MR stub.
676 # arg: <variable-name>
677 # (Function for test scripts)
681 __print_err "need one arg, <mr-param>" $@
684 echo -e $BOLD"INFO(${BASH_LINENO[0]}): mrstub, $1 = $(__do_curl $MR_STUB_PATH/counter/$1)"$EBOLD
687 # Send json to topic in mr-stub.
688 # arg: <topic-url> <json-msg>
689 # (Function for test scripts)
692 if [ $# -ne 2 ]; then
693 __print_err "<topic-url> <json-msg>" $@
697 fname=$PWD/tmp/json_payload_to_mr.json
699 res="$(__do_curl_to_api MRSTUB POST $query $fname)"
701 status=${res:${#res}-3}
702 if [ $status -ne 200 ]; then
703 __log_test_fail_status_code 200 $status