From 546fc67584a8bd01af1a5c46d5f94a08bc720c8a Mon Sep 17 00:00:00 2001 From: Dobroslaw Zybort Date: Tue, 16 Apr 2019 13:10:01 +0200 Subject: [PATCH] Add waiting for monasca-api before starting in docker Story: 2001694 Task: 30534 Change-Id: I6794b9c71ac86427a2abaa812c3a4039bab75e8a --- docker/Dockerfile | 8 +++++--- docker/README.rst | 22 +++++++++++++++------- docker/start.sh | 25 ++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 240bfd5..f85e823 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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 # Branch, tag or git hash to build from. @@ -6,7 +6,7 @@ ARG REPO_VERSION=master ARG CONSTRAINTS_BRANCH=master # 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. ARG BASE_TAG=master @@ -14,7 +14,6 @@ FROM monasca/base:$BASE_TAG # Environment variables used for our service or wait scripts. ENV \ - MONASCA_URI=http://monasca:8070 \ KEYSTONE_IDENTITY_URI=http://keystone:35357 \ USE_DYNAMIC_CREDS=True \ KEYSTONE_ADMIN_USER=mini-mon \ @@ -26,6 +25,9 @@ ENV \ OS_PASSWORD=password \ OS_TENANT_NAME=mini-mon \ OS_DOMAIN_NAME=Default \ + MONASCA_WAIT_FOR_API=true \ + MONASCA_API_WAIT_RETRIES=24 \ + MONASCA_API_WAIT_INTERVAL=5 \ STAY_ALIVE_ON_FAILURE=false # Copy all neccessary files to proper locations. diff --git a/docker/README.rst b/docker/README.rst index 64f4388..0989348 100644 --- a/docker/README.rst +++ b/docker/README.rst @@ -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`` file:: - MONASCA_URI=172.17.0.1:8070 KEYSTONE_IDENTITY_URI=http://172.17.0.1:35357 USE_DYNAMIC_CREDS=True KEYSTONE_ADMIN_USER=mini-mon @@ -60,6 +59,13 @@ file:: OS_PROJECT_NAME=mini-mon 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 ~~~~~~~~~~~~~~~~~~~~~ @@ -85,12 +91,14 @@ STAY_ALIVE_ON_FAILURE false If true, container runs Wait scripts environment variables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -========================= ============================== ========================================== -Variable Default Description -========================= ============================== ========================================== -MONASCA_URI http://monasca:8070 The metric pipeline endpoint -KEYSTONE_IDENTITY_URI http://keystone:35357 URI to Keystone admin endpoint -========================= ============================== ========================================== +========================= =========================== ============================================= +Variable Default Description +========================= =========================== ============================================= +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 diff --git a/docker/start.sh b/docker/start.sh index 5fee2a8..16e1948 100644 --- a/docker/start.sh +++ b/docker/start.sh @@ -22,9 +22,32 @@ set -eo pipefail # Exit the script if any statement returns error. # Test services we need before starting our service. echo "Start script: waiting for needed services" -/wait_for.sh "$MONASCA_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. # Read usage examples: https://pypi.org/project/Templer/ echo "Start script: creating config files from templates"