aboutsummaryrefslogtreecommitdiffstats
path: root/test/csit/scripts/externalapi-nbi/start_nbi_containers.sh
diff options
context:
space:
mode:
authorQuoc Nghia Nguyen <quocnghia.nguyen@orange.com>2018-05-02 18:39:20 +0200
committerQuoc Nghia Nguyen <quocnghia.nguyen@orange.com>2018-05-03 10:03:50 +0200
commit2cb13e679ee07fa0d964f639248eeb29973545d2 (patch)
tree981b5851cbf781ee437c0fc98bb47980177d0f66 /test/csit/scripts/externalapi-nbi/start_nbi_containers.sh
parent4f8447a10386657ff83118908de686777f5ff061 (diff)
Fix nbi container init error
- start_nbi_containers: wait for the db services to be fully initialized before launching the nbi Change-Id: I5ce856c69f74db5425ea4506d392a52c07e12bda Issue-ID: EXTAPI-76 Signed-off-by: Quoc Nghia Nguyen <quocnghia.nguyen@orange.com>
Diffstat (limited to 'test/csit/scripts/externalapi-nbi/start_nbi_containers.sh')
-rw-r--r--test/csit/scripts/externalapi-nbi/start_nbi_containers.sh23
1 files changed, 19 insertions, 4 deletions
diff --git a/test/csit/scripts/externalapi-nbi/start_nbi_containers.sh b/test/csit/scripts/externalapi-nbi/start_nbi_containers.sh
index 7237a1fbc..24de74099 100644
--- a/test/csit/scripts/externalapi-nbi/start_nbi_containers.sh
+++ b/test/csit/scripts/externalapi-nbi/start_nbi_containers.sh
@@ -34,18 +34,33 @@ docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
docker pull $NEXUS_DOCKER_REPO/onap/externalapi/nbi:$DOCKER_IMAGE_VERSION
# Start nbi, MariaDB and MongoDB containers with docker compose and nbi/docker-compose.yml
-docker-compose up -d mariadb mongo && sleep 5 # to ensure that these services are ready for connections
+docker-compose up -d mariadb mongo
+
+# inject a script to ensure that these services are ready for connections
+docker-compose run --rm --entrypoint='/bin/sh' nbi -c '\
+ attempt=1; \
+ while ! nc -z mariadb 3306 || ! nc -z mongo 27017; do \
+ if [ $attempt = 30 ]; then \
+ echo "Timed out!"; \
+ exit 1; \
+ fi; \
+ echo "waiting for db services (attempt #$attempt)..."; \
+ sleep 1; \
+ attempt=$(( attempt + 1)); \
+ done; \
+ echo "all db services are ready for connections!" \
+'
+
docker-compose up -d nbi
NBI_CONTAINER_NAME=$(docker-compose ps 2> /dev/null | tail -n+3 | tr -s ' ' | cut -d' ' -f1 | grep _nbi_)
-NBI_IP=$(docker inspect $NBI_CONTAINER_NAME --format='{{ range .NetworkSettings.Networks }}{{ .IPAddress }}{{ end }}')
+NBI_IP=$(docker inspect --format='{{ range .NetworkSettings.Networks }}{{ .IPAddress }}{{ end }}' ${NBI_CONTAINER_NAME})
echo "IP address for NBI main container ($NBI_CONTAINER_NAME) is set to ${NBI_IP}."
# Wait for initialization
for i in {1..30}; do
- curl -sS ${NBI_IP}:8080 > /dev/null 2>&1 && break
+ curl -sS ${NBI_IP}:8080 > /dev/null 2>&1 && echo 'nbi initialized' && break
echo sleep $i
sleep $i
done
-