Browse Source

Add waiting for monasca-api before starting in docker

Story: 2001694
Task: 30534

Change-Id: I6794b9c71ac86427a2abaa812c3a4039bab75e8a
Dobroslaw Zybort 4 days ago
parent
commit
546fc67584
3 changed files with 44 additions and 11 deletions
  1. 5
    3
      docker/Dockerfile
  2. 15
    7
      docker/README.rst
  3. 24
    1
      docker/start.sh

+ 5
- 3
docker/Dockerfile View File

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

+ 15
- 7
docker/README.rst View File

@@ -47,7 +47,6 @@ Example command to run tempest tests with custom variables::
47 47
 In this example you configure all environment variables in ``tempest_con.env``
48 48
 file::
49 49
 
50
-    MONASCA_URI=172.17.0.1:8070
51 50
     KEYSTONE_IDENTITY_URI=http://172.17.0.1:35357
52 51
     USE_DYNAMIC_CREDS=True
53 52
     KEYSTONE_ADMIN_USER=mini-mon
@@ -60,6 +59,13 @@ file::
60 59
     OS_PROJECT_NAME=mini-mon
61 60
     OS_DOMAIN_NAME=Default
62 61
 
62
+In order to run in docker-compose add this section to docker-compose.yaml::
63
+
64
+    tempest-tests:
65
+      image: monasca/tempest-tests:master
66
+      environment:
67
+        KEYSTONE_IDENTITY_URI: "http://keystone:35357"
68
+
63 69
 
64 70
 Environment variables
65 71
 ~~~~~~~~~~~~~~~~~~~~~
@@ -85,12 +91,14 @@ STAY_ALIVE_ON_FAILURE     false                          If true, container runs
85 91
 
86 92
 Wait scripts environment variables
87 93
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
88
-========================= ============================== ==========================================
89
-Variable                  Default                        Description
90
-========================= ============================== ==========================================
91
-MONASCA_URI               http://monasca:8070            The metric pipeline endpoint
92
-KEYSTONE_IDENTITY_URI     http://keystone:35357          URI to Keystone admin endpoint
93
-========================= ============================== ==========================================
94
+========================= =========================== =============================================
95
+Variable                  Default                     Description
96
+========================= =========================== =============================================
97
+KEYSTONE_IDENTITY_URI     http://keystone:35357       URI to Keystone admin endpoint
98
+MONASCA_WAIT_FOR_API      true                        If true, ensure Monasca API is available
99
+MONASCA_API_WAIT_RETRIES  24                          Retries for Monasca API availability checks
100
+MONASCA_API_WAIT_INTERVAL 5                           Sleep time between Monasca API retries
101
+========================= =========================== =============================================
94 102
 
95 103
 
96 104
 Scripts

+ 24
- 1
docker/start.sh View File

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

Loading…
Cancel
Save