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
196 # Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers
197 # For docker, the namespace shall be excluded
198 # This function is called for apps managed by the test script as well as for prestarted apps.
200 __MR_statisics_setup() {
201 if [ $RUNMODE == "KUBE" ]; then
202 echo "MR $MR_STUB_APP_NAME $KUBE_ONAP_NAMESPACE"
204 echo "MR $MR_STUB_APP_NAME"
208 # Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers
209 # For docker, the namespace shall be excluded
210 # This function is called for apps managed by the test script as well as for prestarted apps.
212 __DMAAPMR_statisics_setup() {
213 if [ $RUNMODE == "KUBE" ]; then
220 #######################################################
222 # Description of port mappings when running MR-STUB only or MR-STUB + MESSAGE-ROUTER
224 # 'MR-STUB only' is started when only 'MR' is included in the test script. Both the test scripts and app will then use MR-STUB as a message-router simulator.
226 # 'MR-STUB + MESSAGE-ROUTER' is started when 'MR' and 'DMAAPMR' is included in the testscripts. DMAAPMR is the real message router including kafka and zookeeper.
227 # In this configuration, MR-STUB is used by the test-script as frontend to the message-router while app are using the real message-router.
230 # ---------------------------------------------------------------------------------------------------------------------------------------------------
234 # localhost container service pod
235 # ==============================================================================================================================================
236 # 10 MR_STUB_LOCALHOST_PORT -> 13 MR_INTERNAL_PORT 15 MR_EXTERNAL_PORT -> 17 MR_INTERNAL_PORT
237 # 12 MR_STUB_LOCALHOST_SECURE_PORT -> 14 MR_INTERNAL_SECURE_PORT 16 MR_EXTERNAL_SECURE_PORT -> 18 MR_INTERNAL_SECURE_PORT
241 # MESSAGE-ROUTER MESSAGE-ROUTER
242 # ++++++++++++++ ++++++++++++++
243 # localhost container service pod
244 # ===================================================================================================================================================
245 # 20 MR_DMAAP_LOCALHOST_PORT -> 23 MR_INTERNAL_PORT 25 MR_EXTERNAL_PORT -> 27 MR_INTERNAL_PORT
246 # 22 MR_DMAAP_LOCALHOST_SECURE_PORT -> 24 MR_INTERNAL_SECURE_PORT 26 MR_EXTERNAL_SECURE_PORT -> 28 MR_INTERNAL_SECURE_PORT
249 # Running only the MR-STUB - apps using MR-STUB
251 # localhost: 10 and 12 -
252 # via proxy (script): 13 and 14 via proxy (script): 15 and 16
253 # apps: 13 and 14 apps: 15 and 16
255 # Running MR-STUB (as frontend for test script) and MESSAGE-ROUTER - apps using MESSAGE-ROUTER
257 # localhost: 10 and 12 -
258 # via proxy (script): 13 and 14 via proxy (script): 15 and 16
259 # apps: 23 and 24 apps: 25 and 26
265 __mr_set_protocoll "http" $MR_INTERNAL_PORT $MR_EXTERNAL_PORT $MR_INTERNAL_SECURE_PORT $MR_EXTERNAL_SECURE_PORT
269 __mr_set_protocoll "https" $MR_INTERNAL_PORT $MR_EXTERNAL_PORT $MR_INTERNAL_SECURE_PORT $MR_EXTERNAL_SECURE_PORT
272 # Setup paths to svc/container for internal and external access
273 # args: <protocol> <internal-port> <external-port> <internal-secure-port> <external-secure-port>
274 __mr_set_protocoll() {
275 echo -e $BOLD"$MR_STUB_DISPLAY_NAME and $MR_DMAAP_DISPLAY_NAME protocol setting"$EBOLD
276 echo -e " Using $BOLD http $EBOLD towards $MR_STUB_DISPLAY_NAME and $MR_DMAAP_DISPLAY_NAME"
278 ## Access to Dmaap mediator
282 if [ $MR_HTTPX == "http" ]; then
290 # Access via test script
291 MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME":"$INT_PORT # access from script via proxy, docker
292 MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME":"$INT_PORT # access from script via proxy, docker
293 MR_DMAAP_ADAPTER_HTTP="" # Access to dmaap mr via proyx - set only if app is included
295 MR_SERVICE_PATH=$MR_STUB_PATH # access container->container, docker - access pod->svc, kube
296 MR_KAFKA_SERVICE_PATH=""
297 __check_included_image "DMAAPMR"
298 if [ $? -eq 0 ]; then
299 MR_SERVICE_PATH=$MR_DMAAP_PATH # access container->container, docker - access pod->svc, kube
300 MR_DMAAP_ADAPTER_HTTP=$MR_DMAAP_PATH
302 MR_KAFKA_SERVICE_PATH=$MR_KAFKA_APP_NAME":"$MR_KAFKA_PORT
305 # For directing calls from script to e.g.PMS via message rounter
306 # These cases shall always go though the mr-stub
307 MR_ADAPTER_HTTP="http://"$MR_STUB_APP_NAME":"$2
308 MR_ADAPTER_HTTPS="https://"$MR_STUB_APP_NAME":"$4
310 MR_DMAAP_ADAPTER_TYPE="REST"
314 if [ $RUNMODE == "KUBE" ]; then
315 MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME.$KUBE_ONAP_NAMESPACE":"$EXT_PORT # access from script via proxy, kube
316 MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME.$KUBE_ONAP_NAMESPACE":"$EXT_PORT # access from script via proxy, kube
318 MR_SERVICE_PATH=$MR_STUB_PATH
319 __check_included_image "DMAAPMR"
320 if [ $? -eq 0 ]; then
321 MR_SERVICE_PATH=$MR_DMAAP_PATH
322 MR_DMAAP_ADAPTER_HTTP=$MR_DMAAP_PATH
323 MR_KAFKA_SERVICE_PATH=$MR_KAFKA_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_KAFKA_PORT
325 __check_prestarted_image "DMAAPMR"
326 if [ $? -eq 0 ]; then
327 MR_SERVICE_PATH=$MR_DMAAP_PATH
328 MR_DMAAP_ADAPTER_HTTP=$MR_DMAAP_PATH
329 MR_KAFKA_SERVICE_PATH=$MR_KAFKA_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_KAFKA_PORT
332 # For directing calls from script to e.g.PMS, via message rounter
333 # These calls shall always go though the mr-stub
334 MR_ADAPTER_HTTP="http://"$MR_STUB_APP_NAME.$KUBE_ONAP_NAMESPACE":"$3
335 MR_ADAPTER_HTTPS="https://"$MR_STUB_APP_NAME.$KUBE_ONAP_NAMESPACE":"$5
338 # For calls from script to the mr-stub
339 MR_STUB_ADAPTER=$MR_STUB_PATH
340 MR_STUB_ADAPTER_TYPE="REST"
347 # use_mr_http() { 2 3 4 5 6 7
348 # __mr_set_protocoll "http" $MR_INTERNAL_PORT $MR_EXTERNAL_PORT $MR_INTERNAL_PORT $MR_EXTERNAL_PORT $MR_INTERNAL_SECURE_PORT $MR_EXT_SECURE_PORT
352 # __mr_set_protocoll "https" $MR_INTERNAL_SECURE_PORT $MR_EXTERNAL_SECURE_PORT
355 # # Setup paths to svc/container for internal and external access
356 # # args: <protocol> <internal-port> <external-port> <mr-stub-internal-port> <mr-stub-external-port> <mr-stub-internal-secure-port> <mr-stub-external-secure-port>
357 # __mr_set_protocoll() {
358 # echo -e $BOLD"$MR_STUB_DISPLAY_NAME and $MR_DMAAP_DISPLAY_NAME protocol setting"$EBOLD
359 # echo -e " Using $BOLD http $EBOLD towards $MR_STUB_DISPLAY_NAME and $MR_DMAAP_DISPLAY_NAME"
361 # ## Access to Dmaap mediator
365 # # Access via test script
366 # MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME":"$2 # access from script via proxy, docker
367 # MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME":"$2 # access from script via proxy, docker
368 # MR_DMAAP_ADAPTER_HTTP="" # Access to dmaap mr via proyx - set only if app is included
370 # MR_SERVICE_PATH=$MR_STUB_PATH # access container->container, docker - access pod->svc, kube
371 # __check_included_image "DMAAPMR"
372 # if [ $? -eq 0 ]; then
373 # MR_SERVICE_PATH=$MR_DMAAP_PATH # access container->container, docker - access pod->svc, kube
374 # MR_DMAAP_ADAPTER_HTTP=$MR_DMAAP_PATH
377 # # For directing calls from script to e.g.PMS via message rounter
378 # # These cases shall always go though the mr-stub
379 # MR_ADAPTER_HTTP="http://"$MR_STUB_APP_NAME":"$4
380 # MR_ADAPTER_HTTPS="https://"$MR_STUB_APP_NAME":"$6
382 # MR_DMAAP_ADAPTER_TYPE="REST"
384 # if [ $RUNMODE == "KUBE" ]; then
385 # MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME.$KUBE_ONAP_NAMESPACE":"$3 # access from script via proxy, kube
386 # MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME.$KUBE_ONAP_NAMESPACE":"$3 # access from script via proxy, kube
388 # MR_SERVICE_PATH=$MR_STUB_PATH
389 # __check_included_image "DMAAPMR"
390 # if [ $? -eq 0 ]; then
391 # MR_SERVICE_PATH=$MR_DMAAP_PATH
392 # MR_DMAAP_ADAPTER_HTTP=$MR_DMAAP_PATH
394 # __check_prestarted_image "DMAAPMR"
395 # if [ $? -eq 0 ]; then
396 # MR_SERVICE_PATH=$MR_DMAAP_PATH
397 # MR_DMAAP_ADAPTER_HTTP=$MR_DMAAP_PATH
400 # # For directing calls from script to e.g.PMS, via message rounter
401 # # These calls shall always go though the mr-stub
402 # MR_ADAPTER_HTTP="http://"$MR_STUB_APP_NAME":"$5
403 # MR_ADAPTER_HTTPS="https://"$MR_STUB_APP_NAME":"$7
406 # # For calls from script to the mr-stub
407 # MR_STUB_ADAPTER=$MR_STUB_PATH
408 # MR_STUB_ADAPTER_TYPE="REST"
414 # Export env vars for config files, docker compose and kube resources
416 __dmaapmr_export_vars() {
418 export DOCKER_SIM_NWNAME
419 export ONAP_ZOOKEEPER_IMAGE
420 export MR_ZOOKEEPER_APP_NAME
421 export ONAP_KAFKA_IMAGE
422 export MR_KAFKA_APP_NAME
423 export ONAP_DMAAPMR_IMAGE
424 export MR_DMAAP_APP_NAME
425 export MR_DMAAP_LOCALHOST_PORT
426 export MR_INTERNAL_PORT
427 export MR_DMAAP_LOCALHOST_SECURE_PORT
428 export MR_INTERNAL_SECURE_PORT
429 export MR_DMAAP_HOST_MNT_DIR
431 export KUBE_ONAP_NAMESPACE
432 export MR_EXTERNAL_PORT
433 export MR_EXTERNAL_SECURE_PORT
435 export MR_ZOOKEEPER_PORT
437 export MR_KAFKA_SERVICE_PATH
440 # Export env vars for config files, docker compose and kube resources
444 export DOCKER_SIM_NWNAME
445 export MR_STUB_APP_NAME
447 export MR_INTERNAL_PORT
448 export MR_INTERNAL_SECURE_PORT
449 export MR_EXTERNAL_PORT
450 export MR_EXTERNAL_SECURE_PORT
451 export MR_STUB_LOCALHOST_PORT
452 export MR_STUB_LOCALHOST_SECURE_PORT
453 export MR_STUB_CERT_MOUNT_DIR
454 export MR_STUB_DISPLAY_NAME
456 export KUBE_ONAP_NAMESPACE
457 export MR_EXTERNAL_PORT
459 export MR_KAFKA_SERVICE_PATH
463 # Start the Message Router stub interface in the simulator group
465 # (Function for test scripts)
468 echo -e $BOLD"Starting $MR_DMAAP_DISPLAY_NAME and/or $MR_STUB_DISPLAY_NAME"$EBOLD
470 if [ $RUNMODE == "KUBE" ]; then
472 # Table of possible combinations of included mr and included/prestarted dmaap-mr
473 # mr can never be prestarted
474 # mr can be used stand alone
475 # if dmaapmr is included/prestarted, then mr is needed as well as frontend
477 # Inverted logic - 0 mean true, 1 means false
478 # mr prestarted 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
479 # mr included 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1
480 # dmaap prestarted 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1
481 # dmaap included 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
482 # ==================================================
483 # OK 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1
485 __check_prestarted_image 'MR'
486 retcode_prestarted_mr=$?
487 __check_included_image 'MR'
488 retcode_included_mr=$?
490 __check_prestarted_image 'DMAAPMR'
491 retcode_prestarted_dmaapmr=$?
492 __check_included_image 'DMAAPMR'
493 retcode_included_dmaapmr=$?
497 if [ $retcode_prestarted_mr -ne 0 ] && [ $retcode_included_mr -eq 0 ]; then
498 if [ $retcode_prestarted_dmaapmr -ne 0 ] && [ $retcode_included_dmaapmr -eq 0 ]; then
503 if [ $retcode_prestarted_mr -ne 0 ] && [ $retcode_included_mr -eq 0 ]; then
504 if [ $retcode_prestarted_dmaapmr -eq 0 ] && [ $retcode_included_dmaapmr -ne 0 ]; then
509 if [ $retcode_prestarted_mr -ne 0 ] && [ $retcode_included_mr -eq 0 ]; then
510 if [ $retcode_prestarted_dmaapmr -ne 0 ] && [ $retcode_included_dmaapmr -ne 0 ]; then
515 if [ $paramerror -ne 0 ]; then
516 echo -e $RED"The Message Router apps 'MR' and/or 'DMAAPMR' are not included in this test script"$ERED
517 echo -e $RED"The Message Router will not be started"$ERED
518 echo -e $RED"Both MR and DAAMPMR - or - only MR - need to be included and/or prestarted"$ERED
522 if [ $retcode_prestarted_dmaapmr -eq 0 ]; then
523 echo -e " Using existing $MR_DMAAP_APP_NAME deployment and service"
524 __kube_scale deployment $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE 1
527 if [ $retcode_included_dmaapmr -eq 0 ]; then
529 __dmaapmr_export_vars
531 #Check if onap namespace exists, if not create it
532 __kube_create_namespace $KUBE_ONAP_NAMESPACE
535 MR_MNT_CONFIG_BASEPATH=$SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR$MR_DMAAP_HOST_MNT_DIR
536 cp -r $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR$MR_DMAAP_HOST_CONFIG_DIR/* $MR_MNT_CONFIG_BASEPATH
538 # Create config maps - dmaapmr app
539 configfile=$MR_MNT_CONFIG_BASEPATH/mr/MsgRtrApi.properties
540 output_yaml=$PWD/tmp/dmaapmr_msgrtrapi_cfc.yaml
541 __kube_create_configmap dmaapmr-msgrtrapi.properties $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
543 configfile=$MR_MNT_CONFIG_BASEPATH/mr/logback.xml
544 output_yaml=$PWD/tmp/dmaapmr_logback_cfc.yaml
545 __kube_create_configmap dmaapmr-logback.xml $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
547 configfile=$MR_MNT_CONFIG_BASEPATH/mr/cadi.properties
548 output_yaml=$PWD/tmp/dmaapmr_cadi_cfc.yaml
549 __kube_create_configmap dmaapmr-cadi.properties $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
551 # Create config maps - kafka app
552 configfile=$MR_MNT_CONFIG_BASEPATH/kafka/zk_client_jaas.conf
553 output_yaml=$PWD/tmp/dmaapmr_zk_client_cfc.yaml
554 __kube_create_configmap dmaapmr-zk-client-jaas.conf $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
556 # Create config maps - zookeeper app
557 configfile=$MR_MNT_CONFIG_BASEPATH/zk/zk_server_jaas.conf
558 output_yaml=$PWD/tmp/dmaapmr_zk_server_cfc.yaml
559 __kube_create_configmap dmaapmr-zk-server-jaas.conf $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
562 input_yaml=$SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"svc.yaml
563 output_yaml=$PWD/tmp/dmaapmr_svc.yaml
564 __kube_create_instance service $MR_DMAAP_APP_NAME $input_yaml $output_yaml
567 input_yaml=$SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"app.yaml
568 output_yaml=$PWD/tmp/dmaapmr_app.yaml
569 __kube_create_instance app $MR_DMAAP_APP_NAME $input_yaml $output_yaml
572 # echo " Retrieving host and ports for service..."
573 # MR_DMAAP_HOST_NAME=$(__kube_get_service_host $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE)
575 # MR_EXT_PORT=$(__kube_get_service_port $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE "http")
576 # MR_EXT_SECURE_PORT=$(__kube_get_service_port $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE "https")
578 # echo " Host IP, http port, https port: $MR_DMAAP_APP_NAME $MR_EXT_PORT $MR_EXT_SECURE_PORT"
580 # if [ $MR_HTTPX == "http" ]; then
581 # MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_HOST_NAME":"$MR_EXT_PORT
582 # MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXT_PORT
584 # MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_HOST_NAME":"$MR_EXT_SECURE_PORT
585 # MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXT_SECURE_PORT
588 __check_service_start $MR_DMAAP_APP_NAME $MR_DMAAP_PATH$MR_DMAAP_ALIVE_URL
590 # Cannot create topics, returns 400 forever.....topics will be created during pipeclean below
591 #__create_topic $MR_READ_TOPIC "Topic for reading policy messages"
593 #__create_topic $MR_WRITE_TOPIC "Topic for writing policy messages"
595 # __dmaap_pipeclean $MR_READ_TOPIC "/events/$MR_READ_TOPIC" "/events/$MR_READ_TOPIC/users/policy-agent?timeout=1000&limit=100"
597 # __dmaap_pipeclean $MR_WRITE_TOPIC "/events/$MR_WRITE_TOPIC" "/events/$MR_WRITE_TOPIC/users/mr-stub?timeout=1000&limit=100"
600 #__dmaap_pipeclean "unauthenticated.dmaapmed.json" "/events/unauthenticated.dmaapmed.json" "/events/unauthenticated.dmaapmed.json/dmaapmediatorproducer/STD_Fault_Messages?timeout=1000&limit=100"
601 #__dmaap_pipeclean "unauthenticated.dmaapadp.json" "/events/unauthenticated.dmaapadp.json" "/events/unauthenticated.dmaapadp.json/dmaapadapterproducer/msgs?timeout=1000&limit=100"
603 if [ $# -gt 0 ]; then
604 if [ $(($#%3)) -eq 0 ]; then
605 while [ $# -gt 0 ]; do
606 __dmaap_pipeclean "$1" "$2/$1" "$2/$1/$3?timeout=1000&limit=100"
610 echo -e $RED" args: start_mr [<topic-name> <base-url> <group-and-user-url>]*"$ERED
611 echo -e $RED" Got: $@"$ERED
616 echo " Current topics:"
617 curlString="$MR_DMAAP_PATH/topics"
618 result=$(__do_curl "$curlString")
619 echo $result | indent2
623 if [ $retcode_included_mr -eq 0 ]; then
627 if [ $retcode_prestarted_dmaapmr -eq 0 ] || [ $retcode_included_dmaapmr -eq 0 ]; then # Set topics for dmaap
628 export TOPIC_READ="http://$MR_DMAAP_APP_NAME.$KUBE_ONAP_NAMESPACE:$MR_INTERNAL_PORT/events/$MR_READ_TOPIC"
629 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"
630 export GENERIC_TOPICS_UPLOAD_BASEURL="http://$MR_DMAAP_APP_NAME.$KUBE_ONAP_NAMESPACE:$MR_INTERNAL_PORT"
633 export TOPIC_WRITE=""
634 export GENERIC_TOPICS_UPLOAD_BASEURL=""
637 #Check if onap namespace exists, if not create it
638 __kube_create_namespace $KUBE_ONAP_NAMESPACE
641 input_yaml=$SIM_GROUP"/"$MR_STUB_COMPOSE_DIR"/"svc.yaml
642 output_yaml=$PWD/tmp/mr_svc.yaml
643 __kube_create_instance service $MR_STUB_APP_NAME $input_yaml $output_yaml
646 input_yaml=$SIM_GROUP"/"$MR_STUB_COMPOSE_DIR"/"app.yaml
647 output_yaml=$PWD/tmp/mr_app.yaml
648 __kube_create_instance app $MR_STUB_APP_NAME $input_yaml $output_yaml
653 # echo " Retrieving host and ports for service..."
654 # MR_STUB_HOST_NAME=$(__kube_get_service_host $MR_STUB_APP_NAME $KUBE_ONAP_NAMESPACE)
656 # MR_EXT_PORT=$(__kube_get_service_port $MR_STUB_APP_NAME $KUBE_ONAP_NAMESPACE "http")
657 # MR_EXT_SECURE_PORT=$(__kube_get_service_port $MR_STUB_APP_NAME $KUBE_ONAP_NAMESPACE "https")
659 # echo " Host IP, http port, https port: $MR_STUB_APP_NAME $MR_EXT_PORT $MR_EXT_SECURE_PORT"
660 # if [ $MR_HTTPX == "http" ]; then
661 # MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_HOST_NAME":"$MR_EXT_PORT
662 # if [ -z "$MR_SERVICE_PATH" ]; then
663 # MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXT_PORT
666 # MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_HOST_NAME":"$MR_EXT_SECURE_PORT
667 # if [ -z "$MR_SERVICE_PATH" ]; then
668 # MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXT_SECURE_PORT
671 # MR_ADAPTER_HTTP="http://"$MR_STUB_HOST_NAME":"$MR_EXT_PORT
672 # MR_ADAPTER_HTTPS="https://"$MR_STUB_HOST_NAME":"$MR_EXT_SECURE_PORT
674 # MR_STUB_ADAPTER=$MR_STUB_PATH
675 # MR_STUB_ADAPTER_TYPE="REST"
677 __check_service_start $MR_STUB_APP_NAME $MR_STUB_PATH$MR_STUB_ALIVE_URL
679 echo -ne " Service $MR_STUB_APP_NAME - reset "$SAMELINE
680 result=$(__do_curl $MR_STUB_PATH/reset)
681 if [ $? -ne 0 ]; then
682 echo -e " Service $MR_STUB_APP_NAME - reset $RED Failed $ERED - will continue"
684 echo -e " Service $MR_STUB_APP_NAME - reset $GREEN OK $EGREEN"
690 __check_included_image 'DMAAPMR'
692 __check_included_image 'MR'
695 if [ $retcode_dmaapmr -ne 0 ] && [ $retcode_mr -ne 0 ]; then
696 echo -e $RED"The Message Router apps 'MR' and/or 'DMAAPMR' are not included in this test script"$ERED
697 echo -e $RED"The Message Router will not be started"$ERED
698 echo -e $RED"Both MR and DAAMPMR - or - only MR - need to be included"
702 if [ $retcode_dmaapmr -eq 0 ] && [ $retcode_mr -ne 0 ]; then
703 echo -e $RED"The Message Router apps 'MR' and/or 'DMAAPMR' are not included in this test script"$ERED
704 echo -e $RED"The Message Router will not be started"$ERED
705 echo -e $RED"Both MR and DAAMPMR - or - only MR - need to be included"
710 export TOPIC_WRITE=""
711 export GENERIC_TOPICS_UPLOAD_BASEURL=""
712 if [ $retcode_dmaapmr -eq 0 ]; then # Set topics for dmaap
713 export TOPIC_READ="http://$MR_DMAAP_APP_NAME:$MR_INTERNAL_PORT/events/$MR_READ_TOPIC"
714 export TOPIC_WRITE="http://$MR_DMAAP_APP_NAME:$MR_INTERNAL_PORT/events/$MR_WRITE_TOPIC/users/mr-stub?timeout=15000&limit=100"
715 export GENERIC_TOPICS_UPLOAD_BASEURL="http://$MR_DMAAP_APP_NAME:$MR_INTERNAL_PORT"
718 __dmaapmr_export_vars
720 if [ $retcode_dmaapmr -eq 0 ]; then
723 MR_MNT_CONFIG_BASEPATH=$SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR$MR_DMAAP_HOST_MNT_DIR
724 cp -r $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR$MR_DMAAP_HOST_CONFIG_DIR/* $MR_MNT_CONFIG_BASEPATH
727 configfile=$MR_MNT_CONFIG_BASEPATH/mr/MsgRtrApi.properties
728 cp $configfile $configfile"_tmp"
729 envsubst < $configfile"_tmp" > $configfile
731 __start_container $MR_DMAAP_COMPOSE_DIR "" NODOCKERARGS 1 $MR_DMAAP_APP_NAME
733 __check_service_start $MR_DMAAP_APP_NAME $MR_DMAAP_PATH$MR_DMAAP_ALIVE_URL
736 # Cannot create topics, returns 400 forever.....topics will be created during pipeclean below
737 #__create_topic $MR_READ_TOPIC "Topic for reading policy messages"
739 #__create_topic $MR_WRITE_TOPIC "Topic for writing policy messages"
741 #__dmaap_pipeclean $MR_READ_TOPIC "/events/$MR_READ_TOPIC" "/events/$MR_READ_TOPIC/users/policy-agent?timeout=1000&limit=100"
743 #__dmaap_pipeclean $MR_WRITE_TOPIC "/events/$MR_WRITE_TOPIC" "/events/$MR_WRITE_TOPIC/users/mr-stub?timeout=1000&limit=100"
745 if [ $# -gt 0 ]; then
746 if [ $(($#%3)) -eq 0 ]; then
747 while [ $# -gt 0 ]; do
748 __dmaap_pipeclean "$1" "$2/$1" "$2/$1/$3?timeout=1000&limit=100"
752 echo -e $RED" args: start_mr [<topic-name> <base-url> <group-and-user-url>]*"$ERED
753 echo -e $RED" Got: $@"$ERED
758 #__dmaap_pipeclean "unauthenticated.dmaapmed.json" "/events/unauthenticated.dmaapmed.json" "/events/unauthenticated.dmaapmed.json/dmaapmediatorproducer/STD_Fault_Messages?timeout=1000&limit=100"
759 #__dmaap_pipeclean "unauthenticated.dmaapadp.json" "/events/unauthenticated.dmaapadp.json" "/events/unauthenticated.dmaapadp.json/dmaapadapterproducer/msgs?timeout=1000&limit=100"
761 echo " Current topics:"
762 curlString="$MR_DMAAP_PATH/topics"
763 result=$(__do_curl "$curlString")
764 echo $result | indent2
769 if [ $retcode_mr -eq 0 ]; then
770 __start_container $MR_STUB_COMPOSE_DIR "" NODOCKERARGS 1 $MR_STUB_APP_NAME
772 __check_service_start $MR_STUB_APP_NAME $MR_STUB_PATH$MR_STUB_ALIVE_URL
780 # Create a dmaap mr topic
781 # args: <topic name> <topic-description>
783 echo -ne " Creating topic: $1"$SAMELINE
785 json_topic="{\"topicName\":\"$1\",\"partitionCount\":\"2\", \"replicationCount\":\"3\", \"transactionEnabled\":\"false\",\"topicDescription\":\"$2\"}"
786 fname="./tmp/$1.json"
787 echo $json_topic > $fname
789 query="/topics/create"
791 while [ $topic_retries -gt 0 ]; do
792 let topic_retries=topic_retries-1
793 res="$(__do_curl_to_api DMAAPMR POST $query $fname)"
794 status=${res:${#res}-3}
796 if [[ $status == "2"* ]]; then
798 echo -e " Creating topic: $1 $GREEN OK $EGREEN"
800 if [ $topic_retries -eq 0 ]; then
801 echo -e " Creating topic: $1 $RED Failed $ERED"
813 # Do a pipeclean of a topic - to overcome dmaap mr bug...
814 # args: <topic> <post-url> <read-url> [<num-retries>]
815 __dmaap_pipeclean() {
817 if [ $# -eq 4 ]; then
820 echo -ne " Doing dmaap-mr pipe cleaning on topic: $1"$SAMELINE
821 while [ $pipeclean_retries -gt 0 ]; do
822 if [[ $1 == *".text" ]]; then
823 echo "pipeclean-$1:$pipeclean_retries" > ./tmp/__dmaap_pipeclean.txt
824 curlString="$MR_DMAAP_PATH$2 -X POST -H Content-Type:text/plain -d@./tmp/__dmaap_pipeclean.txt"
826 echo "{\"pipeclean-$1\":$pipeclean_retries}" > ./tmp/__dmaap_pipeclean.json
827 curlString="$MR_DMAAP_PATH$2 -X POST -H Content-Type:application/json -d@./tmp/__dmaap_pipeclean.json"
829 let pipeclean_retries=pipeclean_retries-1
830 result=$(__do_curl "$curlString")
831 if [ $? -ne 0 ]; then
834 curlString="$MR_DMAAP_PATH$3"
835 result=$(__do_curl "$curlString")
836 if [ $? -eq 0 ]; then
837 if [ $result != "[]" ]; then
838 echo -e " Doing dmaap-mr pipe cleaning on topic: $1 $GREEN OK $EGREEN"
847 echo -e "Doing dmaap-mr pipe cleaning on topic: $1 $RED Failed $ERED"
852 ### Generic test cases for varaible checking
854 # Tests if a variable value in the MR stub is equal to a target value and and optional timeout.
855 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
856 # equal to the target or not.
857 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
858 # before setting pass or fail depending on if the variable value becomes equal to the target
860 # (Function for test scripts)
862 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
863 __var_test "MR" $MR_STUB_PATH/counter/ $1 "=" $2 $3
866 __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
870 # Tests if a variable value in the MR stub is greater than a target value and and optional timeout.
871 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
872 # greater than the target or not.
873 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
874 # before setting pass or fail depending on if the variable value becomes greater than the target
876 # (Function for test scripts)
878 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
879 __var_test "MR" $MR_STUB_PATH/counter/ $1 ">" $2 $3
882 __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
886 # Read a variable value from MR sim and send to stdout. Arg: <variable-name>
888 echo "$(__do_curl $MR_STUB_PATH/counter/$1)"
891 # Print a variable value from the MR stub.
892 # arg: <variable-name>
893 # (Function for test scripts)
897 __print_err "need one arg, <mr-param>" $@
900 echo -e $BOLD"INFO(${BASH_LINENO[0]}): mrstub, $1 = $(__do_curl $MR_STUB_PATH/counter/$1)"$EBOLD
903 # Send json to topic in mr-stub.
904 # arg: <topic-url> <json-msg>
905 # (Function for test scripts)
908 if [ $# -ne 2 ]; then
909 __print_err "<topic-url> <json-msg>" $@
913 fname=$PWD/tmp/json_payload_to_mr.json
915 res="$(__do_curl_to_api MRSTUB POST $query $fname)"
917 status=${res:${#res}-3}
918 if [ $status -ne 200 ]; then
919 __log_conf_fail_status_code 200 $status
927 # Send text to topic in mr-stub.
928 # arg: <topic-url> <text-msg>
929 # (Function for test scripts)
932 if [ $# -ne 2 ]; then
933 __print_err "<topic-url> <text-msg>" $@
937 fname=$PWD/tmp/text_payload_to_mr.txt
939 res="$(__do_curl_to_api MRSTUB POST $query $fname text/plain)"
941 status=${res:${#res}-3}
942 if [ $status -ne 200 ]; then
943 __log_conf_fail_status_code 200 $status
951 # Send json file to topic in mr-stub.
952 # arg: <topic-url> <json-file>
953 # (Function for test scripts)
954 mr_api_send_json_file() {
956 if [ $# -ne 2 ]; then
957 __print_err "<topic-url> <json-file>" $@
962 __log_test_fail_general "File $2 does not exist"
965 #Create json array for mr
966 datafile="tmp/mr_api_send_json_file.json"
967 { echo -n "[" ; cat $2 ; echo -n "]" ;} > $datafile
969 res="$(__do_curl_to_api MRSTUB POST $query $datafile)"
971 status=${res:${#res}-3}
972 if [ $status -ne 200 ]; then
973 __log_conf_fail_status_code 200 $status
981 # Send text file to topic in mr-stub.
982 # arg: <topic-url> <text-file>
983 # (Function for test scripts)
984 mr_api_send_text_file() {
986 if [ $# -ne 2 ]; then
987 __print_err "<topic-url> <text-file>" $@
992 __log_test_fail_general "File $2 does not exist"
996 res="$(__do_curl_to_api MRSTUB POST $query $2 text/plain)"
998 status=${res:${#res}-3}
999 if [ $status -ne 200 ]; then
1000 __log_conf_fail_status_code 200 $status
1008 # Create json file for payload
1009 # arg: <size-in-kb> <filename>
1010 mr_api_generate_json_payload_file() {
1012 if [ $# -ne 2 ]; then
1013 __print_err "<topic-url> <json-file>" $@
1016 if [ $1 -lt 1 ] || [ $1 -gt 10000 ]; then
1017 __log_conf_fail_general "Only size between 1k and 10000k supported"
1020 echo -n "{\"a\":[" > $2
1022 echo -n "\"a0\"" >> $2
1023 for ((idx=1; idx<$LEN; idx++))
1025 echo -n ",\"a$idx\"" >> $2
1033 # Create tet file for payload
1034 # arg: <size-in-kb> <filename>
1035 mr_api_generate_text_payload_file() {
1037 if [ $# -ne 2 ]; then
1038 __print_err "<topic-url> <text-file>" $@
1041 if [ $1 -lt 1 ] || [ $1 -gt 10000 ]; then
1042 __log_conf_fail_general "Only size between 1k and 10000k supported"
1047 for ((idx=0; idx<$LEN; idx++))
1049 echo -n "ABCDEFGHIJ" >> $2