blob: 28e8ae3b694bc1a2f2f4321f3132d21abd36f703 [file] [log] [blame]
Bartek Grzybowskib7f20992020-04-02 03:57:07 -07001#!/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
Bartek Grzybowski4d63be52020-04-02 07:40:59 -070017# Script verifies if all services in Netconf simulator's docker
18# service container were launched successfully.
19
20echo "---> netconf-pnp-simulator-verify.sh"
Bartek Grzybowskib7f20992020-04-02 03:57:07 -070021
22set -e # Exit with zero only if all commands succeed
23
Bartek Grzybowskib7f20992020-04-02 03:57:07 -070024DOCKER_COMPOSE_LOG="/tmp/docker-compose.log"
Bartek Grzybowski21c3b2e2020-04-09 03:43:41 -070025DOCKER_COMPOSE_LOG_MSG=( "success:" "entered RUNNING state" )
Bartek Grzybowskic5744392020-04-03 03:47:09 -070026DOCKER_COMPOSE_SLEEP_INTERVAL=60
Bartek Grzybowskib7f20992020-04-02 03:57:07 -070027
Bartek Grzybowski4d63be52020-04-02 07:40:59 -070028if [ -z ${NETCONF_SIM_SERVICE_NAME} ];
29then
30 echo "ERROR: netconf-pnp-simulator service name not set."
31 exit 1
32fi
33
Bartek Grzybowskib7f20992020-04-02 03:57:07 -070034pushd $DOCKER_ROOT
35
36# Dump container logs
37sleep ${DOCKER_COMPOSE_SLEEP_INTERVAL} # Hang for a while so the services settle
38docker-compose logs --no-color > ${DOCKER_COMPOSE_LOG}
39
40# Get the supervisord services running within container
Bartek Grzybowski4d63be52020-04-02 07:40:59 -070041supervisord_services=($(docker-compose exec -T ${NETCONF_SIM_SERVICE_NAME} /bin/sh -c \
Bartek Grzybowskib7f20992020-04-02 03:57:07 -070042 'cat /etc/supervisord.conf /etc/supervisord.d/*' | grep -ho "program:[-a-zA-Z0-9]*" | cut -d: -f 2))
43
44# Check all services are running and fail if not
45for service in ${supervisord_services[@]};
46do
47 if ! grep -q "${DOCKER_COMPOSE_LOG_MSG[0]} $service ${DOCKER_COMPOSE_LOG_MSG[1]}" ${DOCKER_COMPOSE_LOG};
48 then
49 echo "ERROR: Service $service is not running, failing the build."
50 exit 1
51 fi
52done