blob: 8898b92a81a519c7a88c850a9585b634caa56d05 [file] [log] [blame]
Yuli Shlosberg0566f582017-11-26 19:05:23 +02001#!/bin/bash
2
dekstroza83520062018-05-03 16:47:08 +01003#Define this as variable, so it can be excluded in run commands on Docker for OSX, as /etc/localtime cant be mounted there.
4LOCAL_TIME_MOUNT_CMD="--volume /etc/localtime:/etc/localtime:ro"
5# If os is OSX, unset this, so /etc/localtime is not mounted, otherwise leave it be
6if [[ "$OSTYPE" == "darwin"* ]]; then
7 LOCAL_TIME_MOUNT_CMD=""
8fi
Yuli Shlosberg0566f582017-11-26 19:05:23 +02009
10function usage {
Michael Landoa5445102018-03-04 14:53:33 +020011 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 Shlosberg0566f582017-11-26 19:05:23 +020012}
13
Yuli Shlosberg0566f582017-11-26 19:05:23 +020014function cleanup {
Michael Landoa5445102018-03-04 14:53:33 +020015 echo "performing old dockers cleanup"
16 docker_ids=`docker ps -a | egrep -v "onap/sdc-simulator" | egrep "ecomp-nexus:${PORT}/sdc|sdc-sanity|Exit" | awk '{print $1}'`
17 for X in ${docker_ids}
18 do
19 docker rm -f ${X}
20 done
Yuli Shlosberg0566f582017-11-26 19:05:23 +020021}
22
23
24function dir_perms {
Michael Landoa5445102018-03-04 14:53:33 +020025 mkdir -p ${WORKSPACE}/data/logs/BE/SDC/SDC-BE
26 mkdir -p ${WORKSPACE}/data/logs/FE/SDC/SDC-FE
27 chmod -R 777 ${WORKSPACE}/data/logs
Yuli Shlosberg0566f582017-11-26 19:05:23 +020028}
29
30function monitor_docker {
31
Michael Landoa5445102018-03-04 14:53:33 +020032 echo monitor $1 Docker
33 sleep 5
34 TIME_OUT=900
35 INTERVAL=20
36 TIME=0
37 while [ "$TIME" -lt "$TIME_OUT" ]; do
Yuli Shlosberg0566f582017-11-26 19:05:23 +020038
Michael Landoa5445102018-03-04 14:53:33 +020039 MATCH=`docker logs --tail 30 $1 | grep "DOCKER STARTED"`
40 echo MATCH is -- $MATCH
Yuli Shlosberg0566f582017-11-26 19:05:23 +020041
Michael Landoa5445102018-03-04 14:53:33 +020042 if [ -n "$MATCH" ]; then
43 echo DOCKER start finished in $TIME seconds
44 break
45 fi
Yuli Shlosberg0566f582017-11-26 19:05:23 +020046
Michael Landoa5445102018-03-04 14:53:33 +020047 echo Sleep: $INTERVAL seconds before testing if $1 DOCKER is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
48 sleep $INTERVAL
49 TIME=$(($TIME+$INTERVAL))
50 done
Yuli Shlosberg0566f582017-11-26 19:05:23 +020051
Michael Landoa5445102018-03-04 14:53:33 +020052 if [ "$TIME" -ge "$TIME_OUT" ]; then
53 echo -e "\e[1;31mTIME OUT: DOCKER was NOT fully started in $TIME_OUT seconds... Could cause problems ...\e[0m"
54 fi
Yuli Shlosberg0566f582017-11-26 19:05:23 +020055
56}
57
Michael Landoa5445102018-03-04 14:53:33 +020058function healthCheck {
59 curl localhost:9200/_cluster/health?pretty=true
60
61 echo "BE health-Check:"
62 curl http://localhost:8080/sdc2/rest/healthCheck
63
64 echo ""
65 echo ""
66 echo "FE health-Check:"
67 curl http://localhost:8181/sdc1/rest/healthCheck
68
69
70 echo ""
71 echo ""
72 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;)
73 if [[ ${healthCheck_http_code} != 200 ]]
74 then
75 echo "Error [${healthCheck_http_code}] while user existance check"
76 return ${healthCheck_http_code}
77 fi
78 echo "check user existance: OK"
79 return ${healthCheck_http_code}
80}
81
82function elasticHealthCheck {
83 echo "Elastic Health-Check:"
84
85 COUNTER=0
86 while [ $COUNTER -lt 20 ]; do
87 echo "Waiting ES docker to start"
88 health_Check_http_code=$(curl -o /dev/null -w '%{http_code}' http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=120s)
89 if [[ "$health_Check_http_code" -eq 200 ]]
90 then
91 break
92 fi
93 let COUNTER=COUNTER+1
94 sleep 4
95 done
96
97 healthCheck_http_code=$(curl -o /dev/null -w '%{http_code}' http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=120s)
98 if [[ "$health_Check_http_code" != 200 ]]
99 then
100 echo "Error [${healthCheck_http_code}] ES NOT started correctly"
101 exit ${healthCheck_http_code}
102 fi
103 echo "ES started correctly"
104 curl localhost:9200/_cluster/health?pretty=true
105 return ${healthCheck_http_code}
106}
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200107
108RELEASE=latest
109LOCAL=false
Michael Landoa5445102018-03-04 14:53:33 +0200110RUNTESTS=true
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200111DEBUG_PORT="--publish 4000:4000"
112
Michael Landoa5445102018-03-04 14:53:33 +0200113while [ $# -gt 0 ]; do
114 case $1 in
115 # -r | --release - The specific docker version to pull and deploy
116 -r | --release )
117 shift 1 ;
118 RELEASE=$1;
119 shift 1;;
120 # -e | --environment - The environment name you want to deploy
121 -e | --environment )
122 shift 1;
123 DEP_ENV=$1;
124 shift 1 ;;
125 # -p | --port - The port from which to connect to the docker nexus
126 -p | --port )
127 shift 1 ;
128 PORT=$1;
129 shift 1 ;;
130 # -l | --local - Use this for deploying your local dockers without pulling them first
131 -l | --local )
132 LOCAL=true;
133 shift 1;;
134 # -t | --runTests - Use this for running the sanity tests docker after all other dockers have been deployed
135 -t | --runTests )
136 RUNTESTS=true;
137 shift 1 ;;
138 # -h | --help - Display the help message with all the available run options
139 -h | --help )
140 usage;
141 exit 0;;
142 * )
143 usage;
144 exit 1;;
145 esac
146done
147
148
dekstroza83520062018-05-03 16:47:08 +0100149[ -f ${WORKSPACE}/opt/config/env_name.txt ] && DEP_ENV=$(cat ${WORKSPACE}/opt/config/env_name.txt) || DEP_ENV=__ENV-NAME__
150[ -f ${WORKSPACE}/opt/config/nexus_username.txt ] && NEXUS_USERNAME=$(cat ${WORKSPACE}/opt/config/nexus_username.txt) || NEXUS_USERNAME=release
151[ -f ${WORKSPACE}/opt/config/nexus_password.txt ] && NEXUS_PASSWD=$(cat ${WORKSPACE}/opt/config/nexus_password.txt) || NEXUS_PASSWD=sfWU3DFVdBr7GVxB85mTYgAW
152[ -f ${WORKSPACE}/opt/config/nexus_docker_repo.txt ] && NEXUS_DOCKER_REPO=$(cat ${WORKSPACE}/opt/config/nexus_docker_repo.txt) || NEXUS_DOCKER_REPO=nexus3.onap.org:${PORT}
153[ -f ${WORKSPACE}/opt/config/nexus_username.txt ] && docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200154
Michael Landoa5445102018-03-04 14:53:33 +0200155
156cleanup
157
158
159export IP=`ip route get 8.8.8.8 | awk '/src/{ print $7 }'`
dekstroza83520062018-05-03 16:47:08 +0100160#If OSX, then use this to get IP
161if [[ "$OSTYPE" == "darwin"* ]]; then
162 export IP=$(ipconfig getifaddr en0)
163fi
Michael Landoa5445102018-03-04 14:53:33 +0200164export PREFIX=${NEXUS_DOCKER_REPO}'/onap'
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200165
166if [ ${LOCAL} = true ]; then
Michael Landoa5445102018-03-04 14:53:33 +0200167 PREFIX='onap'
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200168fi
169
Michael Landoa5445102018-03-04 14:53:33 +0200170echo ""
171
172healthCheck
173
174# sanityDocker
175if [[ (${RUNTESTS} = true) && (${healthCheck_http_code} == 200) ]]; then
176 echo "docker run sdc-sanity..."
177 echo "Triger sanity docker, please wait..."
178
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200179 if [ ${LOCAL} = false ]; then
Michael Landoa5445102018-03-04 14:53:33 +0200180 docker pull ${PREFIX}/sdc-sanity:${RELEASE}
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200181 fi
Michael Landoa5445102018-03-04 14:53:33 +0200182
dekstroza83520062018-05-03 16:47:08 +0100183docker 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 $LOCAL_TIME_MOUNT_CMD --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}
Michael Landoa5445102018-03-04 14:53:33 +0200184echo "please wait while SANITY is starting....."
185monitor_docker sdc-sanity
186
187fi