Feat!: Update JJB version to 6x
[ci-management.git] / jjb / integration / netconf-pnp-simulator-verify.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 # Script verifies if all services in Netconf simulator's docker
18 # service container were launched successfully.
19
20 echo "---> netconf-pnp-simulator-verify.sh"
21
22 set -e # Exit with zero only if all commands succeed
23
24 DOCKER_COMPOSE_LOG="/tmp/docker-compose.log"
25 DOCKER_COMPOSE_LOG_MSG=( "success:" "entered RUNNING state" )
26 DOCKER_COMPOSE_SLEEP_INTERVAL=60
27
28 if [ -z "$NETCONF_SIM_SERVICE_NAME" ];
29 then
30     echo "ERROR: netconf-pnp-simulator service name not set."
31     exit 1
32 fi
33
34 pushd $DOCKER_ROOT
35
36 # Dump container logs
37 sleep "$DOCKER_COMPOSE_SLEEP_INTERVAL" # Hang for a while so the services settle
38 docker-compose logs --no-color > "$DOCKER_COMPOSE_LOG"
39
40 # Get the supervisord services running within container
41 supervisord_services=($(docker-compose exec -T "$NETCONF_SIM_SERVICE_NAME" /bin/sh -c \
42     '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
45 for service in "${{supervisord_services[@]}}";
46 do
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
52 done