Add waiting for monasca-api before starting in docker

Story: 2001694
Task: 30534

Change-Id: I6794b9c71ac86427a2abaa812c3a4039bab75e8a
This commit is contained in:
Dobroslaw Zybort 2019-04-16 13:10:01 +02:00
parent 3ea749dda1
commit 546fc67584
3 changed files with 44 additions and 11 deletions

View File

@ -1,4 +1,4 @@
ARG DOCKER_IMAGE=monasca/tempest ARG DOCKER_IMAGE=monasca/tempest-tests
ARG APP_REPO=https://git.openstack.org/openstack/monasca-tempest-plugin ARG APP_REPO=https://git.openstack.org/openstack/monasca-tempest-plugin
# Branch, tag or git hash to build from. # Branch, tag or git hash to build from.
@ -6,7 +6,7 @@ ARG REPO_VERSION=master
ARG CONSTRAINTS_BRANCH=master ARG CONSTRAINTS_BRANCH=master
# Extra Python3 dependencies. # Extra Python3 dependencies.
ARG EXTRA_DEPS="python-openstackclient" ARG EXTRA_DEPS="python-openstackclient python-monascaclient"
# Always start from `monasca-base` image and use specific tag of it. # Always start from `monasca-base` image and use specific tag of it.
ARG BASE_TAG=master ARG BASE_TAG=master
@ -14,7 +14,6 @@ FROM monasca/base:$BASE_TAG
# Environment variables used for our service or wait scripts. # Environment variables used for our service or wait scripts.
ENV \ ENV \
MONASCA_URI=http://monasca:8070 \
KEYSTONE_IDENTITY_URI=http://keystone:35357 \ KEYSTONE_IDENTITY_URI=http://keystone:35357 \
USE_DYNAMIC_CREDS=True \ USE_DYNAMIC_CREDS=True \
KEYSTONE_ADMIN_USER=mini-mon \ KEYSTONE_ADMIN_USER=mini-mon \
@ -26,6 +25,9 @@ ENV \
OS_PASSWORD=password \ OS_PASSWORD=password \
OS_TENANT_NAME=mini-mon \ OS_TENANT_NAME=mini-mon \
OS_DOMAIN_NAME=Default \ OS_DOMAIN_NAME=Default \
MONASCA_WAIT_FOR_API=true \
MONASCA_API_WAIT_RETRIES=24 \
MONASCA_API_WAIT_INTERVAL=5 \
STAY_ALIVE_ON_FAILURE=false STAY_ALIVE_ON_FAILURE=false
# Copy all neccessary files to proper locations. # Copy all neccessary files to proper locations.

View File

@ -47,7 +47,6 @@ Example command to run tempest tests with custom variables::
In this example you configure all environment variables in ``tempest_con.env`` In this example you configure all environment variables in ``tempest_con.env``
file:: file::
MONASCA_URI=172.17.0.1:8070
KEYSTONE_IDENTITY_URI=http://172.17.0.1:35357 KEYSTONE_IDENTITY_URI=http://172.17.0.1:35357
USE_DYNAMIC_CREDS=True USE_DYNAMIC_CREDS=True
KEYSTONE_ADMIN_USER=mini-mon KEYSTONE_ADMIN_USER=mini-mon
@ -60,6 +59,13 @@ file::
OS_PROJECT_NAME=mini-mon OS_PROJECT_NAME=mini-mon
OS_DOMAIN_NAME=Default OS_DOMAIN_NAME=Default
In order to run in docker-compose add this section to docker-compose.yaml::
tempest-tests:
image: monasca/tempest-tests:master
environment:
KEYSTONE_IDENTITY_URI: "http://keystone:35357"
Environment variables Environment variables
~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~
@ -85,12 +91,14 @@ STAY_ALIVE_ON_FAILURE false If true, container runs
Wait scripts environment variables Wait scripts environment variables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
========================= ============================== ========================================== ========================= =========================== =============================================
Variable Default Description Variable Default Description
========================= ============================== ========================================== ========================= =========================== =============================================
MONASCA_URI http://monasca:8070 The metric pipeline endpoint KEYSTONE_IDENTITY_URI http://keystone:35357 URI to Keystone admin endpoint
KEYSTONE_IDENTITY_URI http://keystone:35357 URI to Keystone admin endpoint MONASCA_WAIT_FOR_API true If true, ensure Monasca API is available
========================= ============================== ========================================== MONASCA_API_WAIT_RETRIES 24 Retries for Monasca API availability checks
MONASCA_API_WAIT_INTERVAL 5 Sleep time between Monasca API retries
========================= =========================== =============================================
Scripts Scripts

View File

@ -22,9 +22,32 @@ set -eo pipefail # Exit the script if any statement returns error.
# Test services we need before starting our service. # Test services we need before starting our service.
echo "Start script: waiting for needed services" echo "Start script: waiting for needed services"
/wait_for.sh "$MONASCA_URI"
/wait_for.sh "$KEYSTONE_IDENTITY_URI" /wait_for.sh "$KEYSTONE_IDENTITY_URI"
if [ "$MONASCA_WAIT_FOR_API" = "true" ]; then
echo "Waiting for Monasca API to become available..."
success="false"
for i in $(seq "$MONASCA_API_WAIT_RETRIES"); do
if monasca --os-user-domain-name "${OS_DOMAIN_NAME}" \
--os-project-name "${OS_TENANT_NAME}" --os-auth-url "${OS_AUTH_URL}" \
--os-username "${OS_USERNAME}" --os-password "${OS_PASSWORD}" \
alarm-list --limit 1; then
success="true"
break
else
echo "Monasca API not yet ready (attempt $i of $MONASCA_API_WAIT_RETRIES)"
sleep "$MONASCA_API_WAIT_INTERVAL"
fi
done
if [ "$success" != "true" ]; then
echo "Monasca API failed to become ready, exiting..."
sleep 1
exit 1
fi
fi
# Template all config files before start, it will use env variables. # Template all config files before start, it will use env variables.
# Read usage examples: https://pypi.org/project/Templer/ # Read usage examples: https://pypi.org/project/Templer/
echo "Start script: creating config files from templates" echo "Start script: creating config files from templates"