blob: 4aea3bb4105c8c611d432c10868ef43f3bc7391e [file] [log] [blame]
Yuli Shlosberg0566f582017-11-26 19:05:23 +02001#!/bin/bash
2
3
4function usage {
Michael Landoa5445102018-03-04 14:53:33 +02005 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 +02006}
7
Yuli Shlosberg0566f582017-11-26 19:05:23 +02008function cleanup {
Michael Landoa5445102018-03-04 14:53:33 +02009 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 Shlosberg0566f582017-11-26 19:05:23 +020015}
16
17
18function dir_perms {
Michael Landoa5445102018-03-04 14:53:33 +020019 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 Shlosberg0566f582017-11-26 19:05:23 +020022}
23
24function monitor_docker {
25
Michael Landoa5445102018-03-04 14:53:33 +020026 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 Shlosberg0566f582017-11-26 19:05:23 +020032
Michael Landoa5445102018-03-04 14:53:33 +020033 MATCH=`docker logs --tail 30 $1 | grep "DOCKER STARTED"`
34 echo MATCH is -- $MATCH
Yuli Shlosberg0566f582017-11-26 19:05:23 +020035
Michael Landoa5445102018-03-04 14:53:33 +020036 if [ -n "$MATCH" ]; then
37 echo DOCKER start finished in $TIME seconds
38 break
39 fi
Yuli Shlosberg0566f582017-11-26 19:05:23 +020040
Michael Landoa5445102018-03-04 14:53:33 +020041 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 Shlosberg0566f582017-11-26 19:05:23 +020045
Michael Landoa5445102018-03-04 14:53:33 +020046 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 Shlosberg0566f582017-11-26 19:05:23 +020049
50}
51
Michael Landoa5445102018-03-04 14:53:33 +020052function 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
76function 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 Shlosberg0566f582017-11-26 19:05:23 +0200101
102RELEASE=latest
103LOCAL=false
Michael Landoa5445102018-03-04 14:53:33 +0200104RUNTESTS=true
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200105DEBUG_PORT="--publish 4000:4000"
106
Michael Landoa5445102018-03-04 14:53:33 +0200107while [ $# -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
140done
141
142
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200143[ -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 Landoa5445102018-03-04 14:53:33 +0200146[ -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 Shlosberg0566f582017-11-26 19:05:23 +0200147[ -f /opt/config/nexus_username.txt ] && docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
148
Michael Landoa5445102018-03-04 14:53:33 +0200149
150cleanup
151
152
153export IP=`ip route get 8.8.8.8 | awk '/src/{ print $7 }'`
154export PREFIX=${NEXUS_DOCKER_REPO}'/onap'
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200155
156if [ ${LOCAL} = true ]; then
Michael Landoa5445102018-03-04 14:53:33 +0200157 PREFIX='onap'
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200158fi
159
Michael Landoa5445102018-03-04 14:53:33 +0200160echo ""
161
162healthCheck
163
164# sanityDocker
165if [[ (${RUNTESTS} = true) && (${healthCheck_http_code} == 200) ]]; then
166 echo "docker run sdc-sanity..."
167 echo "Triger sanity docker, please wait..."
168
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200169 if [ ${LOCAL} = false ]; then
Michael Landoa5445102018-03-04 14:53:33 +0200170 docker pull ${PREFIX}/sdc-sanity:${RELEASE}
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200171 fi
Michael Landoa5445102018-03-04 14:53:33 +0200172
173docker 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}
174echo "please wait while SANITY is starting....."
175monitor_docker sdc-sanity
176
177fi