b69d3c0f83be9be573de14883622d9a3bbc1bb7b
[ci-management.git] / jjb / integration / emssimulator-swm-netconf_post.sh
1 #!/bin/bash
2
3 # Copyright 2020 Samsung Electronics 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 echo "---> emssimulator-swm-netconf_post.sh"
18
19 set -e # Exit with zero only if all commands succeed
20
21 SERVICE_NAME="ems-netconf-swm"
22 DOCKER_COMPOSE_LOG="/tmp/docker-compose.log"
23 DOCKER_COMPOSE_LOG_MSG=( "INFO success:" "entered RUNNING state" )
24 DOCKER_COMPOSE_SLEEP_INTERVAL=4
25
26 pushd $DOCKER_ROOT
27
28 # Dump container logs
29 sleep ${DOCKER_COMPOSE_SLEEP_INTERVAL} # Hang for a while so the services settle
30 docker-compose logs --no-color > ${DOCKER_COMPOSE_LOG}
31
32 # Get the supervisord services running within container
33 supervisord_services=($(docker-compose exec -T ${SERVICE_NAME} /bin/sh -c \
34     'cat /etc/supervisord.conf /etc/supervisord.d/*' | grep -ho "program:[-a-zA-Z0-9]*" | cut -d: -f 2))
35
36 # Check all services are running and fail if not
37 for service in ${supervisord_services[@]};
38 do
39     if ! grep -q "${DOCKER_COMPOSE_LOG_MSG[0]} $service ${DOCKER_COMPOSE_LOG_MSG[1]}" ${DOCKER_COMPOSE_LOG};
40     then
41         echo "ERROR: Service $service is not running, failing the build."
42         exit 1
43     fi
44 done