Bartek Grzybowski | b7f2099 | 2020-04-02 03:57:07 -0700 | [diff] [blame] | 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 | |
Bartek Grzybowski | 4d63be5 | 2020-04-02 07:40:59 -0700 | [diff] [blame] | 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" |
Bartek Grzybowski | b7f2099 | 2020-04-02 03:57:07 -0700 | [diff] [blame] | 21 | |
| 22 | set -e # Exit with zero only if all commands succeed |
| 23 | |
Bartek Grzybowski | b7f2099 | 2020-04-02 03:57:07 -0700 | [diff] [blame] | 24 | DOCKER_COMPOSE_LOG="/tmp/docker-compose.log" |
Bartek Grzybowski | 21c3b2e | 2020-04-09 03:43:41 -0700 | [diff] [blame] | 25 | DOCKER_COMPOSE_LOG_MSG=( "success:" "entered RUNNING state" ) |
Bartek Grzybowski | c574439 | 2020-04-03 03:47:09 -0700 | [diff] [blame] | 26 | DOCKER_COMPOSE_SLEEP_INTERVAL=60 |
Bartek Grzybowski | b7f2099 | 2020-04-02 03:57:07 -0700 | [diff] [blame] | 27 | |
Bartek Grzybowski | 4d63be5 | 2020-04-02 07:40:59 -0700 | [diff] [blame] | 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 | |
Bartek Grzybowski | b7f2099 | 2020-04-02 03:57:07 -0700 | [diff] [blame] | 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 |
Bartek Grzybowski | 4d63be5 | 2020-04-02 07:40:59 -0700 | [diff] [blame] | 41 | supervisord_services=($(docker-compose exec -T ${NETCONF_SIM_SERVICE_NAME} /bin/sh -c \ |
Bartek Grzybowski | b7f2099 | 2020-04-02 03:57:07 -0700 | [diff] [blame] | 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 |