BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 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 |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 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================================================= |
| 18 | # |
| 19 | |
| 20 | # This is a script that contains container/service management function |
| 21 | # and test functions for Message Router - mr stub |
| 22 | |
| 23 | ## Access to Message Router |
| 24 | # Host name may be changed if app started by kube |
| 25 | # Direct access from script |
| 26 | MR_HTTPX="http" |
| 27 | MR_STUB_HOST_NAME=$LOCALHOST_NAME |
| 28 | MR_DMAAP_HOST_NAME=$LOCALHOST_NAME |
| 29 | MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_HOST_NAME":"$MR_STUB_LOCALHOST_PORT |
| 30 | MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_HOST_NAME":"$MR_DMAAP_LOCALHOST_PORT |
| 31 | #Docker/Kube internal path |
| 32 | if [ $RUNMODE == "KUBE" ]; then |
| 33 | MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_PORT |
| 34 | __check_included_image "DMAAPMR" |
| 35 | if [ $? -eq 0 ]; then |
| 36 | MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_PORT |
| 37 | fi |
| 38 | __check_prestarted_image "DMAAPMR" |
| 39 | if [ $? -eq 0 ]; then |
| 40 | MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_PORT |
| 41 | fi |
| 42 | else |
| 43 | MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME":"$MR_INTERNAL_PORT |
| 44 | __check_included_image "DMAAPMR" |
| 45 | if [ $? -eq 0 ]; then |
| 46 | MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME":"$MR_INTERNAL_PORT |
| 47 | fi |
| 48 | fi |
| 49 | MR_ADAPTER_HTTP="http://"$MR_STUB_HOST_NAME":"$MR_STUB_LOCALHOST_PORT |
| 50 | MR_ADAPTER_HTTPS="https://"$MR_STUB_HOST_NAME":"$MR_STUB_LOCALHOST_SECURE_PORT |
| 51 | |
| 52 | |
| 53 | ##################### |
| 54 | ### MR stub functions |
| 55 | ##################### |
| 56 | |
| 57 | use_mr_http() { |
| 58 | echo -e $BOLD"MR protocol setting"$EBOLD |
| 59 | echo -e " Using $BOLD http $EBOLD towards MR" |
| 60 | MR_HTTPX="http" |
| 61 | MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_HOST_NAME":"$MR_STUB_LOCALHOST_PORT |
| 62 | MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_HOST_NAME":"$MR_DMAAP_LOCALHOST_PORT |
| 63 | #Docker/Kube internal path |
| 64 | if [ $RUNMODE == "KUBE" ]; then |
| 65 | MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_PORT |
| 66 | __check_included_image "DMAAPMR" |
| 67 | if [ $? -eq 0 ]; then |
| 68 | MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_PORT |
| 69 | fi |
| 70 | __check_prestarted_image "DMAAPMR" |
| 71 | if [ $? -eq 0 ]; then |
| 72 | MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_PORT |
| 73 | fi |
| 74 | else |
| 75 | MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME":"$MR_INTERNAL_PORT |
| 76 | __check_included_image "DMAAPMR" |
| 77 | if [ $? -eq 0 ]; then |
| 78 | MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME":"$MR_INTERNAL_PORT |
| 79 | fi |
| 80 | fi |
| 81 | echo "" |
| 82 | } |
| 83 | |
| 84 | use_mr_https() { |
| 85 | echo -e $BOLD"MR protocol setting"$EBOLD |
| 86 | echo -e " Using $BOLD https $EBOLD towards MR" |
| 87 | MR_HTTPX="https" |
| 88 | MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_HOST_NAME":"$MR_STUB_LOCALHOST_SECURE_PORT |
| 89 | MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_HOST_NAME":"$MR_DMAAP_LOCALHOST_SECURE_PORT |
| 90 | #Docker/Kube internal path |
| 91 | if [ $RUNMODE == "KUBE" ]; then |
| 92 | MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_SECURE_PORT |
| 93 | __check_included_image "DMAAPMR" |
| 94 | if [ $? -eq 0 ]; then |
| 95 | MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_SECURE_PORT |
| 96 | fi |
| 97 | __check_prestarted_image "DMAAPMR" |
| 98 | if [ $? -eq 0 ]; then |
| 99 | MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXTERNAL_SECURE_PORT |
| 100 | fi |
| 101 | else |
| 102 | MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME":"$MR_INTERNAL_SECURE_PORT |
| 103 | __check_included_image "DMAAPMR" |
| 104 | if [ $? -eq 0 ]; then |
| 105 | MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME":"$MR_INTERNAL_SECURE_PORT |
| 106 | fi |
| 107 | fi |
| 108 | echo "" |
| 109 | } |
| 110 | |
| 111 | # Create a dmaap mr topic |
| 112 | # args: <topic name> <topic-description> |
| 113 | __create_topic() { |
| 114 | echo -ne " Creating read topic: $1"$SAMELINE |
| 115 | |
| 116 | json_topic="{\"topicName\":\"$1\",\"partitionCount\":\"2\", \"replicationCount\":\"3\", \"transactionEnabled\":\"false\",\"topicDescription\":\"$2\"}" |
| 117 | echo $json_topic > ./tmp/$1.json |
| 118 | |
| 119 | curlString="$MR_DMAAP_PATH/topics/create -X POST -H Content-Type:application/json -d@./tmp/$1.json" |
| 120 | topic_retries=5 |
| 121 | while [ $topic_retries -gt 0 ]; do |
| 122 | let topic_retries=topic_retries-1 |
| 123 | result=$(__do_curl "$curlString") |
| 124 | if [ $? -eq 0 ]; then |
| 125 | topic_retries=0 |
| 126 | echo -e " Creating read topic: $1 $GREEN OK $EGREEN" |
| 127 | fi |
| 128 | if [ $? -ne 0 ]; then |
| 129 | if [ $topic_retries -eq 0 ]; then |
| 130 | echo -e " Creating read topic: $1 $RED Failed $ERED" |
| 131 | ((RES_CONF_FAIL++)) |
| 132 | return 1 |
| 133 | else |
| 134 | sleep 1 |
| 135 | fi |
| 136 | fi |
| 137 | done |
| 138 | return 0 |
| 139 | } |
| 140 | |
| 141 | # Do a pipeclean of a topic - to overcome dmaap mr bug... |
| 142 | # args: <topic> <post-url> <read-url> |
| 143 | __dmaap_pipeclean() { |
| 144 | pipeclean_retries=50 |
| 145 | echo -ne " Doing dmaap-mr pipe cleaning on topic: $1"$SAMELINE |
| 146 | while [ $pipeclean_retries -gt 0 ]; do |
| 147 | echo "{\"pipeclean-$1\":$pipeclean_retries}" > ./tmp/pipeclean.json |
| 148 | let pipeclean_retries=pipeclean_retries-1 |
| 149 | curlString="$MR_DMAAP_PATH$2 -X POST -H Content-Type:application/json -d@./tmp/pipeclean.json" |
| 150 | result=$(__do_curl "$curlString") |
| 151 | if [ $? -ne 0 ]; then |
| 152 | sleep 1 |
| 153 | else |
| 154 | curlString="$MR_DMAAP_PATH$3" |
| 155 | result=$(__do_curl "$curlString") |
| 156 | if [ $? -eq 0 ]; then |
| 157 | if [ $result != "[]" ]; then |
| 158 | echo -e " Doing dmaap-mr pipe cleaning on topic: $1 $GREEN OK $EGREEN" |
| 159 | return 0 |
| 160 | |
| 161 | else |
| 162 | sleep 1 |
| 163 | fi |
| 164 | fi |
| 165 | fi |
| 166 | done |
| 167 | echo -e "Doing dmaap-mr pipe cleaning on topic: $1 $RED Failed $ERED" |
| 168 | return 1 |
| 169 | } |
| 170 | |
| 171 | # Start the Message Router stub interface in the simulator group |
| 172 | # args: - |
| 173 | # (Function for test scripts) |
| 174 | start_mr() { |
| 175 | |
| 176 | echo -e $BOLD"Starting $MR_DMAAP_DISPLAY_NAME and/or $MR_STUB_DISPLAY_NAME"$EBOLD |
| 177 | |
| 178 | if [ $RUNMODE == "KUBE" ]; then |
| 179 | |
| 180 | # Table of possible combinations of included mr and included/prestarted dmaap-mr |
| 181 | # mr can never be prestarted |
| 182 | # mr can be used stand alone |
| 183 | # if dmaapmr is included/prestarted, then mr is needed as well as frontend |
| 184 | |
| 185 | # Inverted logic - 0 mean true, 1 means false |
| 186 | # mr prestarted 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 |
| 187 | # mr included 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 |
| 188 | # dmaap prestarted 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 |
| 189 | # dmaap included 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 |
| 190 | # ================================================== |
| 191 | # OK 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1 |
| 192 | |
| 193 | __check_prestarted_image 'MR' |
| 194 | retcode_prestarted_mr=$? |
| 195 | __check_included_image 'MR' |
| 196 | retcode_included_mr=$? |
| 197 | |
| 198 | __check_prestarted_image 'DMAAPMR' |
| 199 | retcode_prestarted_dmaapmr=$? |
| 200 | __check_included_image 'DMAAPMR' |
| 201 | retcode_included_dmaapmr=$? |
| 202 | |
| 203 | paramerror=1 |
| 204 | |
| 205 | if [ $retcode_prestarted_mr -ne 0 ] && [ $retcode_included_mr -eq 0 ]; then |
| 206 | if [ $retcode_prestarted_dmaapmr -ne 0 ] && [ $retcode_included_dmaapmr -eq 0 ]; then |
| 207 | paramerror=0 |
| 208 | fi |
| 209 | fi |
| 210 | |
| 211 | if [ $retcode_prestarted_mr -ne 0 ] && [ $retcode_included_mr -eq 0 ]; then |
| 212 | if [ $retcode_prestarted_dmaapmr -eq 0 ] && [ $retcode_included_dmaapmr -ne 0 ]; then |
| 213 | paramerror=0 |
| 214 | fi |
| 215 | fi |
| 216 | |
| 217 | if [ $retcode_prestarted_mr -ne 0 ] && [ $retcode_included_mr -eq 0 ]; then |
| 218 | if [ $retcode_prestarted_dmaapmr -ne 0 ] && [ $retcode_included_dmaapmr -ne 0 ]; then |
| 219 | paramerror=0 |
| 220 | fi |
| 221 | fi |
| 222 | |
| 223 | if [ $paramerror -ne 0 ]; then |
| 224 | echo -e $RED"The Message Router apps 'MR' and/or 'DMAAPMR' are not included in this test script"$ERED |
| 225 | echo -e $RED"The Message Router will not be started"$ERED |
| 226 | echo -e $RED"Both MR and DAAMPMR - or - only MR - need to be included and/or prestarted" |
| 227 | exit |
| 228 | fi |
| 229 | |
| 230 | if [ $retcode_prestarted_dmaapmr -eq 0 ]; then |
| 231 | echo -e " Using existing $MR_DMAAP_APP_NAME deployment and service" |
| 232 | __kube_scale deployment $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE 1 |
| 233 | fi |
| 234 | |
| 235 | if [ $retcode_included_dmaapmr -eq 0 ]; then |
| 236 | #export MR_DMAAP_APP_NAME |
| 237 | export MR_DMAAP_KUBE_APP_NAME=message-router |
| 238 | MR_DMAAP_APP_NAME=$MR_DMAAP_KUBE_APP_NAME |
| 239 | export KUBE_ONAP_NAMESPACE |
| 240 | export MR_EXTERNAL_PORT |
| 241 | export MR_INTERNAL_PORT |
| 242 | export MR_EXTERNAL_SECURE_PORT |
| 243 | export MR_INTERNAL_SECURE_PORT |
| 244 | export ONAP_DMAAPMR_IMAGE |
| 245 | |
| 246 | export MR_KAFKA_BWDS_NAME=akfak-bwds |
| 247 | export KUBE_ONAP_NAMESPACE |
| 248 | |
| 249 | export MR_ZOOKEEPER_APP_NAME |
| 250 | export ONAP_ZOOKEEPER_IMAGE |
| 251 | |
| 252 | #Check if onap namespace exists, if not create it |
| 253 | __kube_create_namespace $KUBE_ONAP_NAMESPACE |
| 254 | |
| 255 | # TODO - Fix domain name substitution in the prop file |
| 256 | # Create config maps - dmaapmr app |
| 257 | configfile=$PWD/tmp/MsgRtrApi.properties |
| 258 | cp $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"mnt/mr/KUBE-MsgRtrApi.properties $configfile |
| 259 | output_yaml=$PWD/tmp/dmaapmr_msgrtrapi_cfc.yaml |
| 260 | __kube_create_configmap dmaapmr-msgrtrapi.properties $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml |
| 261 | |
| 262 | configfile=$PWD/tmp/logback.xml |
| 263 | cp $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"mnt/mr/logback.xml $configfile |
| 264 | output_yaml=$PWD/tmp/dmaapmr_logback_cfc.yaml |
| 265 | __kube_create_configmap dmaapmr-logback.xml $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml |
| 266 | |
| 267 | configfile=$PWD/tmp/cadi.properties |
| 268 | cp $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"mnt/mr/cadi.properties $configfile |
| 269 | output_yaml=$PWD/tmp/dmaapmr_cadi_cfc.yaml |
| 270 | __kube_create_configmap dmaapmr-cadi.properties $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml |
| 271 | |
| 272 | # Create config maps - kafka app |
| 273 | configfile=$PWD/tmp/zk_client_jaas.conf |
| 274 | cp $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"mnt/kafka/zk_client_jaas.conf $configfile |
| 275 | output_yaml=$PWD/tmp/dmaapmr_zk_client_cfc.yaml |
| 276 | __kube_create_configmap dmaapmr-zk-client-jaas.conf $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml |
| 277 | |
| 278 | # Create config maps - zookeeper app |
| 279 | configfile=$PWD/tmp/zk_server_jaas.conf |
| 280 | cp $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"mnt/zk/zk_server_jaas.conf $configfile |
| 281 | output_yaml=$PWD/tmp/dmaapmr_zk_server_cfc.yaml |
| 282 | __kube_create_configmap dmaapmr-zk-server-jaas.conf $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml |
| 283 | |
| 284 | # Create service |
| 285 | input_yaml=$SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"svc.yaml |
| 286 | output_yaml=$PWD/tmp/dmaapmr_svc.yaml |
| 287 | __kube_create_instance service $MR_DMAAP_APP_NAME $input_yaml $output_yaml |
| 288 | |
| 289 | # Create app |
| 290 | input_yaml=$SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"app.yaml |
| 291 | output_yaml=$PWD/tmp/dmaapmr_app.yaml |
| 292 | __kube_create_instance app $MR_DMAAP_APP_NAME $input_yaml $output_yaml |
| 293 | |
| 294 | |
| 295 | echo " Retrieving host and ports for service..." |
| 296 | MR_DMAAP_HOST_NAME=$(__kube_get_service_host $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE) |
| 297 | |
| 298 | MR_EXT_PORT=$(__kube_get_service_port $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE "http") |
| 299 | MR_EXT_SECURE_PORT=$(__kube_get_service_port $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE "https") |
| 300 | |
| 301 | echo " Host IP, http port, https port: $MR_DMAAP_APP_NAME $MR_EXT_PORT $MR_EXT_SECURE_PORT" |
| 302 | MR_SERVICE_PATH="" |
| 303 | if [ $MR_HTTPX == "http" ]; then |
| 304 | MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_HOST_NAME":"$MR_EXT_PORT |
| 305 | MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXT_PORT |
| 306 | else |
| 307 | MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_HOST_NAME":"$MR_EXT_SECURE_PORT |
| 308 | MR_SERVICE_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXT_SECURE_PORT |
| 309 | fi |
| 310 | |
| 311 | __check_service_start $MR_DMAAP_APP_NAME $MR_DMAAP_PATH$MR_DMAAP_ALIVE_URL |
| 312 | |
| 313 | fi |
| 314 | |
| 315 | if [ $retcode_included_mr -eq 0 ]; then |
| 316 | #exporting needed var for deployment |
| 317 | export MR_STUB_APP_NAME |
| 318 | export KUBE_ONAP_NAMESPACE |
| 319 | export MRSTUB_IMAGE |
| 320 | export MR_INTERNAL_PORT |
| 321 | export MR_INTERNAL_SECURE_PORT |
| 322 | export MR_EXTERNAL_PORT |
| 323 | export MR_EXTERNAL_SECURE_PORT |
| 324 | |
| 325 | if [ $retcode_prestarted_dmaapmr -eq 0 ] || [ $retcode_included_dmaapmr -eq 0 ]; then # Set topics for dmaap |
| 326 | export TOPIC_READ="http://$MR_DMAAP_APP_NAME.$KUBE_ONAP_NAMESPACE:$MR_INTERNAL_PORT/events/$MR_READ_TOPIC" |
| 327 | 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" |
| 328 | else |
| 329 | export TOPIC_READ="" |
| 330 | export TOPIC_WRITE="" |
| 331 | fi |
| 332 | |
| 333 | #Check if onap namespace exists, if not create it |
| 334 | __kube_create_namespace $KUBE_ONAP_NAMESPACE |
| 335 | |
| 336 | # Create service |
| 337 | input_yaml=$SIM_GROUP"/"$MR_STUB_COMPOSE_DIR"/"svc.yaml |
| 338 | output_yaml=$PWD/tmp/mr_svc.yaml |
| 339 | __kube_create_instance service $MR_STUB_APP_NAME $input_yaml $output_yaml |
| 340 | |
| 341 | # Create app |
| 342 | input_yaml=$SIM_GROUP"/"$MR_STUB_COMPOSE_DIR"/"app.yaml |
| 343 | output_yaml=$PWD/tmp/mr_app.yaml |
| 344 | __kube_create_instance app $MR_STUB_APP_NAME $input_yaml $output_yaml |
| 345 | |
| 346 | |
| 347 | fi |
| 348 | |
| 349 | |
| 350 | echo " Retrieving host and ports for service..." |
| 351 | MR_STUB_HOST_NAME=$(__kube_get_service_host $MR_STUB_APP_NAME $KUBE_ONAP_NAMESPACE) |
| 352 | |
| 353 | MR_EXT_PORT=$(__kube_get_service_port $MR_STUB_APP_NAME $KUBE_ONAP_NAMESPACE "http") |
| 354 | MR_EXT_SECURE_PORT=$(__kube_get_service_port $MR_STUB_APP_NAME $KUBE_ONAP_NAMESPACE "https") |
| 355 | |
| 356 | echo " Host IP, http port, https port: $MR_STUB_APP_NAME $MR_EXT_PORT $MR_EXT_SECURE_PORT" |
| 357 | if [ $MR_HTTPX == "http" ]; then |
| 358 | MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_HOST_NAME":"$MR_EXT_PORT |
| 359 | if [ -z "$MR_SERVICE_PATH" ]; then |
| 360 | MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXT_PORT |
| 361 | fi |
| 362 | else |
| 363 | MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_HOST_NAME":"$MR_EXT_SECURE_PORT |
| 364 | if [ -z "$MR_SERVICE_PATH" ]; then |
| 365 | MR_SERVICE_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_EXT_SECURE_PORT |
| 366 | fi |
| 367 | fi |
| 368 | MR_ADAPTER_HTTP="http://"$MR_STUB_HOST_NAME":"$MR_EXT_PORT |
| 369 | MR_ADAPTER_HTTPS="https://"$MR_STUB_HOST_NAME":"$MR_EXT_SECURE_PORT |
| 370 | |
| 371 | __check_service_start $MR_STUB_APP_NAME $MR_STUB_PATH$MR_STUB_ALIVE_URL |
| 372 | |
| 373 | echo -ne " Service $MR_STUB_APP_NAME - reset "$SAMELINE |
| 374 | result=$(__do_curl $MR_STUB_APP_NAME $MR_STUB_PATH/reset) |
| 375 | if [ $? -ne 0 ]; then |
| 376 | echo -e " Service $MR_STUB_APP_NAME - reset $RED Failed $ERED - will continue" |
| 377 | else |
| 378 | echo -e " Service $MR_STUB_APP_NAME - reset $GREEN OK $EGREEN" |
| 379 | fi |
| 380 | |
| 381 | |
| 382 | else |
| 383 | |
| 384 | __check_included_image 'DMAAPMR' |
| 385 | retcode_dmaapmr=$? |
| 386 | __check_included_image 'MR' |
| 387 | retcode_mr=$? |
| 388 | |
| 389 | if [ $retcode_dmaapmr -ne 0 ] && [ $retcode_mr -ne 0 ]; then |
| 390 | echo -e $RED"The Message Router apps 'MR' and/or 'DMAAPMR' are not included in this test script"$ERED |
| 391 | echo -e $RED"The Message Router will not be started"$ERED |
| 392 | echo -e $RED"Both MR and DAAMPMR - or - only MR - need to be included" |
| 393 | exit |
| 394 | fi |
| 395 | |
| 396 | if [ $retcode_dmaapmr -eq 0 ] && [ $retcode_mr -ne 0 ]; then |
| 397 | echo -e $RED"The Message Router apps 'MR' and/or 'DMAAPMR' are not included in this test script"$ERED |
| 398 | echo -e $RED"The Message Router will not be started"$ERED |
| 399 | echo -e $RED"Both MR and DAAMPMR - or - only MR - need to be included" |
| 400 | exit |
| 401 | fi |
| 402 | |
| 403 | export TOPIC_READ="" |
| 404 | export TOPIC_WRITE="" |
| 405 | if [ $retcode_dmaapmr -eq 0 ]; then # Set topics for dmaap |
| 406 | export TOPIC_READ="http://$MR_DMAAP_APP_NAME:$MR_INTERNAL_PORT/events/$MR_READ_TOPIC" |
| 407 | export TOPIC_WRITE="http://$MR_DMAAP_APP_NAME:$MR_INTERNAL_PORT/events/$MR_WRITE_TOPIC/users/mr-stub?timeout=15000&limit=100" |
| 408 | fi |
| 409 | |
| 410 | export DOCKER_SIM_NWNAME |
| 411 | export ONAP_ZOOKEEPER_IMAGE |
| 412 | export MR_ZOOKEEPER_APP_NAME |
| 413 | export ONAP_KAFKA_IMAGE |
| 414 | export MR_KAFKA_APP_NAME |
| 415 | export ONAP_DMAAPMR_IMAGE |
| 416 | export MR_DMAAP_APP_NAME |
| 417 | export MR_DMAAP_LOCALHOST_PORT |
| 418 | export MR_INTERNAL_PORT |
| 419 | export MR_DMAAP_LOCALHOST_SECURE_PORT |
| 420 | export MR_INTERNAL_SECURE_PORT |
| 421 | |
| 422 | if [ $retcode_dmaapmr -eq 0 ]; then |
| 423 | __start_container $MR_DMAAP_COMPOSE_DIR NODOCKERARGS 1 $MR_DMAAP_APP_NAME |
| 424 | |
| 425 | __check_service_start $MR_DMAAP_APP_NAME $MR_DMAAP_PATH$MR_DMAAP_ALIVE_URL |
| 426 | |
| 427 | |
| 428 | __create_topic $MR_READ_TOPIC "Topic for reading policy messages" |
| 429 | |
| 430 | __create_topic $MR_WRITE_TOPIC "Topic for writing policy messages" |
| 431 | |
| 432 | __dmaap_pipeclean $MR_READ_TOPIC "/events/A1-POLICY-AGENT-READ" "/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=100" |
| 433 | |
| 434 | __dmaap_pipeclean $MR_WRITE_TOPIC "/events/A1-POLICY-AGENT-WRITE" "/events/A1-POLICY-AGENT-WRITE/users/mr-stub?timeout=1000&limit=100" |
| 435 | |
| 436 | echo " Current topics:" |
| 437 | curlString="$MR_DMAAP_PATH/topics" |
| 438 | result=$(__do_curl "$curlString") |
| 439 | echo $result | indent2 |
| 440 | fi |
| 441 | |
| 442 | export DOCKER_SIM_NWNAME |
| 443 | export MR_STUB_APP_NAME |
| 444 | export MRSTUB_IMAGE |
| 445 | export MR_INTERNAL_PORT |
| 446 | export MR_INTERNAL_SECURE_PORT |
| 447 | export MR_STUB_LOCALHOST_PORT |
| 448 | export MR_STUB_LOCALHOST_SECURE_PORT |
| 449 | export MR_STUB_CERT_MOUNT_DIR |
| 450 | |
| 451 | if [ $retcode_mr -eq 0 ]; then |
| 452 | __start_container $MR_STUB_COMPOSE_DIR NODOCKERARGS 1 $MR_STUB_APP_NAME |
| 453 | |
| 454 | __check_service_start $MR_STUB_APP_NAME $MR_STUB_PATH$MR_STUB_ALIVE_URL |
| 455 | fi |
| 456 | |
| 457 | fi |
| 458 | echo "" |
| 459 | return 0 |
| 460 | } |
| 461 | |
| 462 | ### Generic test cases for varaible checking |
| 463 | |
| 464 | # Tests if a variable value in the MR stub is equal to a target value and and optional timeout. |
| 465 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is |
| 466 | # equal to the target or not. |
| 467 | # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 468 | # before setting pass or fail depending on if the variable value becomes equal to the target |
| 469 | # value or not. |
| 470 | # (Function for test scripts) |
| 471 | mr_equal() { |
| 472 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
| 473 | __var_test "MR" $MR_STUB_PATH/counter/ $1 "=" $2 $3 |
| 474 | else |
| 475 | ((RES_CONF_FAIL++)) |
| 476 | __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@ |
| 477 | fi |
| 478 | } |
| 479 | |
| 480 | # Tests if a variable value in the MR stub is greater than a target value and and optional timeout. |
| 481 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is |
| 482 | # greater than the target or not. |
| 483 | # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 484 | # before setting pass or fail depending on if the variable value becomes greater than the target |
| 485 | # value or not. |
| 486 | # (Function for test scripts) |
| 487 | mr_greater() { |
| 488 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
| 489 | __var_test "MR" $MR_STUB_PATH/counter/ $1 ">" $2 $3 |
| 490 | else |
| 491 | ((RES_CONF_FAIL++)) |
| 492 | __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" $@ |
| 493 | fi |
| 494 | } |
| 495 | |
| 496 | # Read a variable value from MR sim and send to stdout. Arg: <variable-name> |
| 497 | mr_read() { |
| 498 | echo "$(__do_curl $MR_STUB_PATH/counter/$1)" |
| 499 | } |
| 500 | |
| 501 | # Print a variable value from the MR stub. |
| 502 | # arg: <variable-name> |
| 503 | # (Function for test scripts) |
| 504 | mr_print() { |
| 505 | if [ $# != 1 ]; then |
| 506 | ((RES_CONF_FAIL++)) |
| 507 | __print_err "need one arg, <mr-param>" $@ |
| 508 | exit 1 |
| 509 | fi |
| 510 | echo -e $BOLD"INFO(${BASH_LINENO[0]}): mrstub, $1 = $(__do_curl $MR_STUB_PATH/counter/$1)"$EBOLD |
| 511 | } |