2a5ef4db3489bfb84a07a717c315b8a4bcda5f1a
[integration/csit.git] / plans / ccsdk / healthcheck / setup.sh
1 #!/bin/bash
2 #
3 # Copyright 2016-2017 Huawei Technologies Co., Ltd.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 # Modifications copyright (c) 2017 AT&T Intellectual Property
18 # Modifications copyright (c) 2020 Samsung Electronics Co., Ltd.
19 #
20 # Place the scripts in run order:
21 export MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
22 export NEXUS_DOCKER_REPO="nexus3.onap.org:10001"
23 export NEXUS_USERNAME=docker
24 export NEXUS_PASSWD=docker
25 export DMAAP_TOPIC=AUTO
26 export CCSDK_DOCKER_IMAGE_VERSION=1.1-STAGING-latest
27
28 if [ "$MTU" == "" ]; then
29           export MTU="1450"
30 fi
31
32 # Clone CCSDK repo to get docker-compose for CCSDK
33 mkdir -p $WORKSPACE/archives/ccsdk
34 cd $WORKSPACE/archives
35 git clone -b master --single-branch http://gerrit.onap.org/r/ccsdk/distribution.git ccsdk
36 cd $WORKSPACE/archives/ccsdk
37 git pull
38 unset http_proxy https_proxy
39 cd $WORKSPACE/archives/ccsdk/src/main/yaml
40
41 sed -i "s/DMAAP_TOPIC_ENV=.*/DMAAP_TOPIC_ENV="AUTO"/g" docker-compose.yml
42 docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
43
44 docker pull $NEXUS_DOCKER_REPO/onap/ccsdk-odlsli-alpine-image:$CCSDK_DOCKER_IMAGE_VERSION
45
46 docker pull $NEXUS_DOCKER_REPO/onap/ccsdk-dgbuilder-image:$CCSDK_DOCKER_IMAGE_VERSION
47
48 # start CCSDK containers with docker compose and configuration from docker-compose.yml
49 curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` > docker-compose
50 chmod +x docker-compose
51 ./docker-compose up -d
52
53 # WAIT 5 minutes maximum and check karaf.log for readiness every 10 seconds
54
55 TIME_OUT=300
56 INTERVAL=10
57 TIME=0
58 while [ "$TIME" -lt "$TIME_OUT" ]; do
59
60 docker exec ccsdk_odlsli_container cat /opt/opendaylight/data/log/karaf.log | grep 'warp coils'
61
62   if [ $? == 0 ] ; then
63     echo CCSDK karaf started in $TIME seconds
64     break;
65   fi
66
67   echo Sleep $INTERVAL seconds before testing if CCSDK is up. Total wait time up until now is $TIME seconds. Timeout is $TIME_OUT seconds
68   sleep $INTERVAL
69   TIME=$(($TIME+$INTERVAL))
70 done
71
72 if [ "$TIME" -ge "$TIME_OUT" ]; then
73    echo TIME OUT: karaf session not started in $TIME_OUT seconds, setup failed
74    exit 1;
75 fi
76
77 num_bundles=$(docker exec -i ccsdk_odlsli_container /opt/opendaylight/current/bin/client bundle:list | tail -1 | cut -d' ' -f1)
78
79   if [ "$num_bundles" -ge 333 ]; then
80     num_bundles=$(docker exec -i ccsdk_odlsli_container /opt/opendaylight/current/bin/client bundle:list | tail -1 | cut -d' ' -f1)
81     num_failed_bundles=$(docker exec -i ccsdk_odlsli_container /opt/opendaylight/current/bin/client bundle:list | grep Failure | wc -l)
82     failed_bundles=$(docker exec -i ccsdk_odlsli_container /opt/opendaylight/current/bin/client bundle:list | grep Failure)
83     echo There is/are $num_failed_bundles failed bundles out of $num_bundles installed bundles.
84   fi
85
86 if [ "$num_failed_bundles" -ge 1 ]; then
87   echo "The following bundle(s) are in a failed state: "
88   echo "  $failed_bundles"
89 fi
90
91 # Pass any variables required by Robot test suites in ROBOT_VARIABLES
92 ROBOT_VARIABLES="-v SCRIPTS:${SCRIPTS}"
93