fix odl patches
[ccsdk/distribution.git] / csit / plans / 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-2021 Samsung Electronics Co., Ltd.
19 #
20
21 export MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
22 export DMAAP_TOPIC=AUTO
23
24 # TODO: any reason to ever read the version from version.properties? 
25 export CCSDK_DOCKER_IMAGE_VERSION=latest
26
27 if [ "$MTU" == "" ]; then
28           export MTU="1450"
29 fi
30
31 # Copy default docker-compose.yaml to archives for CSIT modification
32 mkdir -p $WORKSPACE/archives/yaml
33 cp $WORKSPACE/../src/main/yaml/docker-compose.yml $WORKSPACE/archives/yaml
34 cd $WORKSPACE/archives/yaml
35 unset http_proxy https_proxy
36
37 sed -i "s/DMAAP_TOPIC_ENV=.*/DMAAP_TOPIC_ENV="AUTO"/g" docker-compose.yml
38
39 # TODO: is there ever need to pull the images from Nexus?
40 # run-csit.sh already logins to nexus3.onap.org:10001 so this now works only if
41 # NEXUS_DOCKER_REPO is not defined at all (in which case the images must be available
42 # locally without any repository prefix) or if its value is nexus3.onap.org:10001
43
44 if [ "$NEXUS_DOCKER_REPO" != "" ]; then
45    docker pull $NEXUS_DOCKER_REPO/onap/ccsdk-odlsli-alpine-image:$CCSDK_DOCKER_IMAGE_VERSION
46    docker pull $NEXUS_DOCKER_REPO/onap/ccsdk-dgbuilder-image:$CCSDK_DOCKER_IMAGE_VERSION
47    # Add trailing slash for docker-compose
48    export NEXUS_DOCKER_REPO=$NEXUS_DOCKER_REPO/
49 fi
50
51 # start CCSDK containers with docker compose and configuration from docker-compose.yml
52 curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` > docker-compose
53 chmod +x docker-compose
54 ./docker-compose up -d
55
56 # WAIT 5 minutes maximum and check karaf.log for readiness every 10 seconds
57
58 TIME_OUT=360
59 INTERVAL=10
60 TIME=0
61 while [ "$TIME" -lt "$TIME_OUT" ]; do
62
63 docker exec ccsdk_odlsli_container cat /opt/opendaylight/data/log/karaf.log | grep 'warp coils'
64
65   if [ $? == 0 ] ; then
66     echo CCSDK karaf started in $TIME seconds
67     break;
68   fi
69
70   echo Sleep $INTERVAL seconds before testing if CCSDK is up. Total wait time up until now is $TIME seconds. Timeout is $TIME_OUT seconds
71   sleep $INTERVAL
72   TIME=$(($TIME+$INTERVAL))
73 done
74
75 if [ "$TIME" -ge "$TIME_OUT" ]; then
76    echo TIME OUT: karaf session not started in $TIME_OUT seconds, setup failed
77    echo "karaf.log follows:"
78    docker exec ccsdk_odlsli_container cat /opt/opendaylight/data/log/karaf.log
79    exit 1;
80 fi
81
82 echo "*TRACE* bundle list : $(docker exec -i ccsdk_odlsli_container /opt/opendaylight/current/bin/client bundle:list)"
83
84 num_bundles=$(docker exec -i ccsdk_odlsli_container /opt/opendaylight/current/bin/client bundle:list | tail -1 | cut -d' ' -f1)
85
86   if [ "$num_bundles" -ge 333 ]; then
87     num_bundles=$(docker exec -i ccsdk_odlsli_container /opt/opendaylight/current/bin/client bundle:list | tail -1 | cut -d' ' -f1)
88     num_failed_bundles=$(docker exec -i ccsdk_odlsli_container /opt/opendaylight/current/bin/client bundle:list | grep Failure | wc -l)
89     failed_bundles=$(docker exec -i ccsdk_odlsli_container /opt/opendaylight/current/bin/client bundle:list | grep Failure)
90     echo There is/are $num_failed_bundles failed bundles out of $num_bundles installed bundles.
91   fi
92
93 if [ "$num_failed_bundles" -ge 1 ]; then
94   echo "The following bundle(s) are in a failed state: "
95   echo "  $failed_bundles"
96 fi
97
98 # Pass any variables required by Robot test suites in ROBOT_VARIABLES
99 ROBOT_VARIABLES="-v SCRIPTS:${SCRIPTS}"
100