Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | |
| 4 | function usage { |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 5 | echo "usage: sanity_run.sh [ -r|--release <RELEASE-NAME> ] [ -e|--environment <ENV-NAME> ] [ -p|--port <Docker-hub-port>] [ -l|--local <Run-without-pull>] [ -t|--runTests <Run-with-sanityDocker>] [ -h|--help ]" |
Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 6 | } |
| 7 | |
Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 8 | function cleanup { |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 9 | echo "performing old dockers cleanup" |
| 10 | docker_ids=`docker ps -a | egrep -v "onap/sdc-simulator" | egrep "ecomp-nexus:${PORT}/sdc|sdc-sanity|Exit" | awk '{print $1}'` |
| 11 | for X in ${docker_ids} |
| 12 | do |
| 13 | docker rm -f ${X} |
| 14 | done |
Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 15 | } |
| 16 | |
| 17 | |
| 18 | function dir_perms { |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 19 | mkdir -p ${WORKSPACE}/data/logs/BE/SDC/SDC-BE |
| 20 | mkdir -p ${WORKSPACE}/data/logs/FE/SDC/SDC-FE |
| 21 | chmod -R 777 ${WORKSPACE}/data/logs |
Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | function monitor_docker { |
| 25 | |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 26 | echo monitor $1 Docker |
| 27 | sleep 5 |
| 28 | TIME_OUT=900 |
| 29 | INTERVAL=20 |
| 30 | TIME=0 |
| 31 | while [ "$TIME" -lt "$TIME_OUT" ]; do |
Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 32 | |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 33 | MATCH=`docker logs --tail 30 $1 | grep "DOCKER STARTED"` |
| 34 | echo MATCH is -- $MATCH |
Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 35 | |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 36 | if [ -n "$MATCH" ]; then |
| 37 | echo DOCKER start finished in $TIME seconds |
| 38 | break |
| 39 | fi |
Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 40 | |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 41 | echo Sleep: $INTERVAL seconds before testing if $1 DOCKER is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds |
| 42 | sleep $INTERVAL |
| 43 | TIME=$(($TIME+$INTERVAL)) |
| 44 | done |
Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 45 | |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 46 | if [ "$TIME" -ge "$TIME_OUT" ]; then |
| 47 | echo -e "\e[1;31mTIME OUT: DOCKER was NOT fully started in $TIME_OUT seconds... Could cause problems ...\e[0m" |
| 48 | fi |
Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 49 | |
| 50 | } |
| 51 | |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 52 | function healthCheck { |
| 53 | curl localhost:9200/_cluster/health?pretty=true |
| 54 | |
| 55 | echo "BE health-Check:" |
| 56 | curl http://localhost:8080/sdc2/rest/healthCheck |
| 57 | |
| 58 | echo "" |
| 59 | echo "" |
| 60 | echo "FE health-Check:" |
| 61 | curl http://localhost:8181/sdc1/rest/healthCheck |
| 62 | |
| 63 | |
| 64 | echo "" |
| 65 | echo "" |
| 66 | healthCheck_http_code=$(curl -o /dev/null -w '%{http_code}' -H "Accept: application/json" -H "Content-Type: application/json" -H "USER_ID: jh0003" http://localhost:8080/sdc2/rest/v1/user/demo;) |
| 67 | if [[ ${healthCheck_http_code} != 200 ]] |
| 68 | then |
| 69 | echo "Error [${healthCheck_http_code}] while user existance check" |
| 70 | return ${healthCheck_http_code} |
| 71 | fi |
| 72 | echo "check user existance: OK" |
| 73 | return ${healthCheck_http_code} |
| 74 | } |
| 75 | |
| 76 | function elasticHealthCheck { |
| 77 | echo "Elastic Health-Check:" |
| 78 | |
| 79 | COUNTER=0 |
| 80 | while [ $COUNTER -lt 20 ]; do |
| 81 | echo "Waiting ES docker to start" |
| 82 | health_Check_http_code=$(curl -o /dev/null -w '%{http_code}' http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=120s) |
| 83 | if [[ "$health_Check_http_code" -eq 200 ]] |
| 84 | then |
| 85 | break |
| 86 | fi |
| 87 | let COUNTER=COUNTER+1 |
| 88 | sleep 4 |
| 89 | done |
| 90 | |
| 91 | healthCheck_http_code=$(curl -o /dev/null -w '%{http_code}' http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=120s) |
| 92 | if [[ "$health_Check_http_code" != 200 ]] |
| 93 | then |
| 94 | echo "Error [${healthCheck_http_code}] ES NOT started correctly" |
| 95 | exit ${healthCheck_http_code} |
| 96 | fi |
| 97 | echo "ES started correctly" |
| 98 | curl localhost:9200/_cluster/health?pretty=true |
| 99 | return ${healthCheck_http_code} |
| 100 | } |
Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 101 | |
| 102 | RELEASE=latest |
| 103 | LOCAL=false |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 104 | RUNTESTS=true |
Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 105 | DEBUG_PORT="--publish 4000:4000" |
| 106 | |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 107 | while [ $# -gt 0 ]; do |
| 108 | case $1 in |
| 109 | # -r | --release - The specific docker version to pull and deploy |
| 110 | -r | --release ) |
| 111 | shift 1 ; |
| 112 | RELEASE=$1; |
| 113 | shift 1;; |
| 114 | # -e | --environment - The environment name you want to deploy |
| 115 | -e | --environment ) |
| 116 | shift 1; |
| 117 | DEP_ENV=$1; |
| 118 | shift 1 ;; |
| 119 | # -p | --port - The port from which to connect to the docker nexus |
| 120 | -p | --port ) |
| 121 | shift 1 ; |
| 122 | PORT=$1; |
| 123 | shift 1 ;; |
| 124 | # -l | --local - Use this for deploying your local dockers without pulling them first |
| 125 | -l | --local ) |
| 126 | LOCAL=true; |
| 127 | shift 1;; |
| 128 | # -t | --runTests - Use this for running the sanity tests docker after all other dockers have been deployed |
| 129 | -t | --runTests ) |
| 130 | RUNTESTS=true; |
| 131 | shift 1 ;; |
| 132 | # -h | --help - Display the help message with all the available run options |
| 133 | -h | --help ) |
| 134 | usage; |
| 135 | exit 0;; |
| 136 | * ) |
| 137 | usage; |
| 138 | exit 1;; |
| 139 | esac |
| 140 | done |
| 141 | |
| 142 | |
Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 143 | [ -f /opt/config/env_name.txt ] && DEP_ENV=$(cat /opt/config/env_name.txt) || DEP_ENV=__ENV-NAME__ |
| 144 | [ -f /opt/config/nexus_username.txt ] && NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt) || NEXUS_USERNAME=release |
| 145 | [ -f /opt/config/nexus_password.txt ] && NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt) || NEXUS_PASSWD=sfWU3DFVdBr7GVxB85mTYgAW |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 146 | [ -f /opt/config/nexus_docker_repo.txt ] && NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt) || NEXUS_DOCKER_REPO=nexus3.onap.org:${PORT} |
Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 147 | [ -f /opt/config/nexus_username.txt ] && docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO |
| 148 | |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 149 | |
| 150 | cleanup |
| 151 | |
| 152 | |
| 153 | export IP=`ip route get 8.8.8.8 | awk '/src/{ print $7 }'` |
| 154 | export PREFIX=${NEXUS_DOCKER_REPO}'/onap' |
Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 155 | |
| 156 | if [ ${LOCAL} = true ]; then |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 157 | PREFIX='onap' |
Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 158 | fi |
| 159 | |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 160 | echo "" |
| 161 | |
| 162 | healthCheck |
| 163 | |
| 164 | # sanityDocker |
| 165 | if [[ (${RUNTESTS} = true) && (${healthCheck_http_code} == 200) ]]; then |
| 166 | echo "docker run sdc-sanity..." |
| 167 | echo "Triger sanity docker, please wait..." |
| 168 | |
Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 169 | if [ ${LOCAL} = false ]; then |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 170 | docker pull ${PREFIX}/sdc-sanity:${RELEASE} |
Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 171 | fi |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 172 | |
| 173 | docker run --detach --name sdc-sanity --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --env http_proxy=${http_proxy} --env https_proxy=${https_proxy} --env no_proxy=${no_proxy} --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --memory 1500m --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume ${WORKSPACE}/data/logs/sdc-sanity/target:/var/lib/tests/target --volume ${WORKSPACE}/data/logs/sdc-sanity/ExtentReport:/var/lib/tests/ExtentReport --volume ${WORKSPACE}/data/logs/sdc-sanity/outputCsar:/var/lib/tests/outputCsar --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments --publish 9560:9560 ${PREFIX}/sdc-sanity:${RELEASE} |
| 174 | echo "please wait while SANITY is starting....." |
| 175 | monitor_docker sdc-sanity |
| 176 | |
| 177 | fi |