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 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 23 | ################ Test engine functions ################ |
| 24 | |
| 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 |
| 28 | __MR_imagesetup() { |
| 29 | __check_and_create_image_var MR "MRSTUB_IMAGE" "MRSTUB_IMAGE_BASE" "MRSTUB_IMAGE_TAG" LOCAL "$MR_STUB_DISPLAY_NAME" |
| 30 | } |
| 31 | |
| 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" |
| 39 | } |
| 40 | |
| 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' |
| 46 | __MR_imagepull() { |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 47 | echo -e $RED"Image for app MR shall never be pulled from remote repo"$ERED |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 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() { |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame] | 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 |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 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 |
| 64 | __MR_imagebuild() { |
| 65 | cd ../mrstub |
| 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 |
| 68 | if [ $? -eq 0 ]; then |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame] | 69 | echo -e $GREEN" Build Ok"$EGREEN |
| 70 | __retag_and_push_image MRSTUB_IMAGE |
| 71 | if [ $? -ne 0 ]; then |
| 72 | exit 1 |
| 73 | fi |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 74 | else |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame] | 75 | echo -e $RED" Build Failed"$ERED |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 76 | ((RES_CONF_FAIL++)) |
| 77 | cat .dockererr |
| 78 | echo -e $RED"Exiting...."$ERED |
| 79 | exit 1 |
| 80 | fi |
| 81 | } |
| 82 | |
| 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 |
| 88 | } |
| 89 | |
| 90 | # Generate a string for each included image using the app display name and a docker images format string |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame] | 91 | # If a custom image repo is used then also the source image from the local repo is listed |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 92 | # arg: <docker-images-format-string> <file-to-append> |
| 93 | __MR_image_data() { |
| 94 | echo -e "$MR_STUB_DISPLAY_NAME\t$(docker images --format $1 $MRSTUB_IMAGE)" >> $2 |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame] | 95 | if [ ! -z "$MRSTUB_IMAGE_SOURCE" ]; then |
| 96 | echo -e "-- source image --\t$(docker images --format $1 $MRSTUB_IMAGE_SOURCE)" >> $2 |
| 97 | fi |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | # Generate a string for each included image using the app display name and a docker images format string |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame] | 101 | # If a custom image repo is used then also the source image from the local repo is listed |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 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 |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame] | 105 | if [ ! -z "$ONAP_DMAAPMR_IMAGE_SOURCE" ]; then |
| 106 | echo -e "-- source image --\t$(docker images --format $1 $ONAP_DMAAPMR_IMAGE_SOURCE)" >> $2 |
| 107 | fi |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 108 | echo -e "ZooKeeper\t$(docker images --format $1 $ONAP_ZOOKEEPER_IMAGE)" >> $2 |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame] | 109 | if [ ! -z "$ONAP_ZOOKEEPER_IMAGE_SOURCE" ]; then |
| 110 | echo -e "-- source image --\t$(docker images --format $1 $ONAP_ZOOKEEPER_IMAGE_SOURCE)" >> $2 |
| 111 | fi |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 112 | echo -e "Kafka\t$(docker images --format $1 $ONAP_KAFKA_IMAGE)" >> $2 |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame] | 113 | if [ ! -z "$ONAP_KAFKA_IMAGE_SOURCE" ]; then |
| 114 | echo -e "-- source image --\t$(docker images --format $1 $ONAP_KAFKA_IMAGE_SOURCE)" >> $2 |
| 115 | fi |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 116 | } |
| 117 | |
| 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 |
| 123 | } |
| 124 | |
| 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 |
| 130 | } |
| 131 | |
| 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" |
| 136 | } |
| 137 | |
| 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" |
| 142 | } |
| 143 | |
| 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 |
| 148 | } |
| 149 | |
| 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 |
| 154 | } |
| 155 | |
| 156 | # Store docker logs |
| 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 |
| 161 | } |
| 162 | |
| 163 | # Store docker logs |
| 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 |
| 170 | } |
| 171 | |
| 172 | ####################################################### |
| 173 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 174 | ## Access to Message Router |
| 175 | # Host name may be changed if app started by kube |
| 176 | # Direct access from script |
| 177 | MR_HTTPX="http" |
| 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 |
| 188 | fi |
| 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 |
| 192 | fi |
| 193 | else |
| 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 |
| 198 | fi |
| 199 | fi |
| 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 |
| 202 | |
| 203 | |
| 204 | ##################### |
| 205 | ### MR stub functions |
| 206 | ##################### |
| 207 | |
| 208 | use_mr_http() { |
| 209 | echo -e $BOLD"MR protocol setting"$EBOLD |
| 210 | echo -e " Using $BOLD http $EBOLD towards MR" |
| 211 | MR_HTTPX="http" |
| 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 |
| 220 | fi |
| 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 |
| 224 | fi |
| 225 | else |
| 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 |
| 230 | fi |
| 231 | fi |
| 232 | echo "" |
| 233 | } |
| 234 | |
| 235 | use_mr_https() { |
| 236 | echo -e $BOLD"MR protocol setting"$EBOLD |
| 237 | echo -e " Using $BOLD https $EBOLD towards MR" |
| 238 | MR_HTTPX="https" |
| 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 |
| 247 | fi |
| 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 |
| 251 | fi |
| 252 | else |
| 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 |
| 257 | fi |
| 258 | fi |
| 259 | echo "" |
| 260 | } |
| 261 | |
| 262 | # Create a dmaap mr topic |
| 263 | # args: <topic name> <topic-description> |
| 264 | __create_topic() { |
| 265 | echo -ne " Creating read topic: $1"$SAMELINE |
| 266 | |
| 267 | json_topic="{\"topicName\":\"$1\",\"partitionCount\":\"2\", \"replicationCount\":\"3\", \"transactionEnabled\":\"false\",\"topicDescription\":\"$2\"}" |
| 268 | echo $json_topic > ./tmp/$1.json |
| 269 | |
| 270 | curlString="$MR_DMAAP_PATH/topics/create -X POST -H Content-Type:application/json -d@./tmp/$1.json" |
| 271 | topic_retries=5 |
| 272 | while [ $topic_retries -gt 0 ]; do |
| 273 | let topic_retries=topic_retries-1 |
| 274 | result=$(__do_curl "$curlString") |
| 275 | if [ $? -eq 0 ]; then |
| 276 | topic_retries=0 |
| 277 | echo -e " Creating read topic: $1 $GREEN OK $EGREEN" |
| 278 | fi |
| 279 | if [ $? -ne 0 ]; then |
| 280 | if [ $topic_retries -eq 0 ]; then |
| 281 | echo -e " Creating read topic: $1 $RED Failed $ERED" |
| 282 | ((RES_CONF_FAIL++)) |
| 283 | return 1 |
| 284 | else |
| 285 | sleep 1 |
| 286 | fi |
| 287 | fi |
| 288 | done |
| 289 | return 0 |
| 290 | } |
| 291 | |
| 292 | # Do a pipeclean of a topic - to overcome dmaap mr bug... |
| 293 | # args: <topic> <post-url> <read-url> |
| 294 | __dmaap_pipeclean() { |
| 295 | pipeclean_retries=50 |
| 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 |
| 303 | sleep 1 |
| 304 | else |
| 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" |
| 310 | return 0 |
| 311 | |
| 312 | else |
| 313 | sleep 1 |
| 314 | fi |
| 315 | fi |
| 316 | fi |
| 317 | done |
| 318 | echo -e "Doing dmaap-mr pipe cleaning on topic: $1 $RED Failed $ERED" |
| 319 | return 1 |
| 320 | } |
| 321 | |
| 322 | # Start the Message Router stub interface in the simulator group |
| 323 | # args: - |
| 324 | # (Function for test scripts) |
| 325 | start_mr() { |
| 326 | |
| 327 | echo -e $BOLD"Starting $MR_DMAAP_DISPLAY_NAME and/or $MR_STUB_DISPLAY_NAME"$EBOLD |
| 328 | |
| 329 | if [ $RUNMODE == "KUBE" ]; then |
| 330 | |
| 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 |
| 335 | |
| 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 |
| 343 | |
| 344 | __check_prestarted_image 'MR' |
| 345 | retcode_prestarted_mr=$? |
| 346 | __check_included_image 'MR' |
| 347 | retcode_included_mr=$? |
| 348 | |
| 349 | __check_prestarted_image 'DMAAPMR' |
| 350 | retcode_prestarted_dmaapmr=$? |
| 351 | __check_included_image 'DMAAPMR' |
| 352 | retcode_included_dmaapmr=$? |
| 353 | |
| 354 | paramerror=1 |
| 355 | |
| 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 |
| 358 | paramerror=0 |
| 359 | fi |
| 360 | fi |
| 361 | |
| 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 |
| 364 | paramerror=0 |
| 365 | fi |
| 366 | fi |
| 367 | |
| 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 |
| 370 | paramerror=0 |
| 371 | fi |
| 372 | fi |
| 373 | |
| 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" |
| 378 | exit |
| 379 | fi |
| 380 | |
| 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 |
| 384 | fi |
| 385 | |
| 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 |
| 396 | |
| 397 | export MR_KAFKA_BWDS_NAME=akfak-bwds |
| 398 | export KUBE_ONAP_NAMESPACE |
| 399 | |
| 400 | export MR_ZOOKEEPER_APP_NAME |
| 401 | export ONAP_ZOOKEEPER_IMAGE |
| 402 | |
| 403 | #Check if onap namespace exists, if not create it |
| 404 | __kube_create_namespace $KUBE_ONAP_NAMESPACE |
| 405 | |
| 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 |
| 412 | |
| 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 |
| 417 | |
| 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 |
| 422 | |
| 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 |
| 428 | |
| 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 |
| 434 | |
| 435 | # Create service |
| 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 |
| 439 | |
| 440 | # Create app |
| 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 |
| 444 | |
| 445 | |
| 446 | echo " Retrieving host and ports for service..." |
| 447 | MR_DMAAP_HOST_NAME=$(__kube_get_service_host $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE) |
| 448 | |
| 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") |
| 451 | |
| 452 | echo " Host IP, http port, https port: $MR_DMAAP_APP_NAME $MR_EXT_PORT $MR_EXT_SECURE_PORT" |
| 453 | MR_SERVICE_PATH="" |
| 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 |
| 457 | else |
| 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 |
| 460 | fi |
| 461 | |
| 462 | __check_service_start $MR_DMAAP_APP_NAME $MR_DMAAP_PATH$MR_DMAAP_ALIVE_URL |
| 463 | |
| 464 | fi |
| 465 | |
| 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 |
| 470 | export MRSTUB_IMAGE |
| 471 | export MR_INTERNAL_PORT |
| 472 | export MR_INTERNAL_SECURE_PORT |
| 473 | export MR_EXTERNAL_PORT |
| 474 | export MR_EXTERNAL_SECURE_PORT |
| 475 | |
| 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" |
| 479 | else |
| 480 | export TOPIC_READ="" |
| 481 | export TOPIC_WRITE="" |
| 482 | fi |
| 483 | |
| 484 | #Check if onap namespace exists, if not create it |
| 485 | __kube_create_namespace $KUBE_ONAP_NAMESPACE |
| 486 | |
| 487 | # Create service |
| 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 |
| 491 | |
| 492 | # Create app |
| 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 |
| 496 | |
| 497 | |
| 498 | fi |
| 499 | |
| 500 | |
| 501 | echo " Retrieving host and ports for service..." |
| 502 | MR_STUB_HOST_NAME=$(__kube_get_service_host $MR_STUB_APP_NAME $KUBE_ONAP_NAMESPACE) |
| 503 | |
| 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") |
| 506 | |
| 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 |
| 512 | fi |
| 513 | else |
| 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 |
| 517 | fi |
| 518 | fi |
| 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 |
| 521 | |
| 522 | __check_service_start $MR_STUB_APP_NAME $MR_STUB_PATH$MR_STUB_ALIVE_URL |
| 523 | |
| 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" |
| 528 | else |
| 529 | echo -e " Service $MR_STUB_APP_NAME - reset $GREEN OK $EGREEN" |
| 530 | fi |
| 531 | |
| 532 | |
| 533 | else |
| 534 | |
| 535 | __check_included_image 'DMAAPMR' |
| 536 | retcode_dmaapmr=$? |
| 537 | __check_included_image 'MR' |
| 538 | retcode_mr=$? |
| 539 | |
| 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" |
| 544 | exit |
| 545 | fi |
| 546 | |
| 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" |
| 551 | exit |
| 552 | fi |
| 553 | |
| 554 | export TOPIC_READ="" |
| 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" |
| 559 | fi |
| 560 | |
| 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 |
| 572 | |
| 573 | if [ $retcode_dmaapmr -eq 0 ]; then |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 574 | __start_container $MR_DMAAP_COMPOSE_DIR "" NODOCKERARGS 1 $MR_DMAAP_APP_NAME |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 575 | |
| 576 | __check_service_start $MR_DMAAP_APP_NAME $MR_DMAAP_PATH$MR_DMAAP_ALIVE_URL |
| 577 | |
| 578 | |
| 579 | __create_topic $MR_READ_TOPIC "Topic for reading policy messages" |
| 580 | |
| 581 | __create_topic $MR_WRITE_TOPIC "Topic for writing policy messages" |
| 582 | |
elinuxhenrik | 7fbe885 | 2021-04-23 13:07:42 +0200 | [diff] [blame] | 583 | __dmaap_pipeclean $MR_READ_TOPIC "/events/$MR_READ_TOPIC" "/events/$MR_READ_TOPIC/users/policy-agent?timeout=1000&limit=100" |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 584 | |
elinuxhenrik | 7fbe885 | 2021-04-23 13:07:42 +0200 | [diff] [blame] | 585 | __dmaap_pipeclean $MR_WRITE_TOPIC "/events/$MR_WRITE_TOPIC" "/events/$MR_WRITE_TOPIC/users/mr-stub?timeout=1000&limit=100" |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 586 | |
| 587 | echo " Current topics:" |
| 588 | curlString="$MR_DMAAP_PATH/topics" |
| 589 | result=$(__do_curl "$curlString") |
| 590 | echo $result | indent2 |
| 591 | fi |
| 592 | |
| 593 | export DOCKER_SIM_NWNAME |
| 594 | export MR_STUB_APP_NAME |
| 595 | export MRSTUB_IMAGE |
| 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 |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 601 | export MR_STUB_DISPLAY_NAME |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 602 | |
| 603 | if [ $retcode_mr -eq 0 ]; then |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 604 | __start_container $MR_STUB_COMPOSE_DIR "" NODOCKERARGS 1 $MR_STUB_APP_NAME |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 605 | |
| 606 | __check_service_start $MR_STUB_APP_NAME $MR_STUB_PATH$MR_STUB_ALIVE_URL |
| 607 | fi |
| 608 | |
| 609 | fi |
| 610 | echo "" |
| 611 | return 0 |
| 612 | } |
| 613 | |
| 614 | ### Generic test cases for varaible checking |
| 615 | |
| 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 |
| 621 | # value or not. |
| 622 | # (Function for test scripts) |
| 623 | mr_equal() { |
| 624 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
| 625 | __var_test "MR" $MR_STUB_PATH/counter/ $1 "=" $2 $3 |
| 626 | else |
| 627 | ((RES_CONF_FAIL++)) |
| 628 | __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@ |
| 629 | fi |
| 630 | } |
| 631 | |
| 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 |
| 637 | # value or not. |
| 638 | # (Function for test scripts) |
| 639 | mr_greater() { |
| 640 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
| 641 | __var_test "MR" $MR_STUB_PATH/counter/ $1 ">" $2 $3 |
| 642 | else |
| 643 | ((RES_CONF_FAIL++)) |
| 644 | __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" $@ |
| 645 | fi |
| 646 | } |
| 647 | |
| 648 | # Read a variable value from MR sim and send to stdout. Arg: <variable-name> |
| 649 | mr_read() { |
| 650 | echo "$(__do_curl $MR_STUB_PATH/counter/$1)" |
| 651 | } |
| 652 | |
| 653 | # Print a variable value from the MR stub. |
| 654 | # arg: <variable-name> |
| 655 | # (Function for test scripts) |
| 656 | mr_print() { |
| 657 | if [ $# != 1 ]; then |
| 658 | ((RES_CONF_FAIL++)) |
| 659 | __print_err "need one arg, <mr-param>" $@ |
| 660 | exit 1 |
| 661 | fi |
| 662 | echo -e $BOLD"INFO(${BASH_LINENO[0]}): mrstub, $1 = $(__do_curl $MR_STUB_PATH/counter/$1)"$EBOLD |
| 663 | } |