aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-03-18 22:56:44 +0000
committerGerrit Code Review <review@openstack.org>2015-03-18 22:56:44 +0000
commitf2a38c55bd8672c57402efdcf4d59ff428fe780f (patch)
tree33ba404df97d7af76071ca4510ee6df4698eb081
parent16076af97a383368dc45a2c7df1cbc5ed603e19c (diff)
parent4075c851edc3339adee8ef02bcc291e21b8a738c (diff)
downloadkolla-f2a38c55bd8672c57402efdcf4d59ff428fe780f.tar.gz
kolla-f2a38c55bd8672c57402efdcf4d59ff428fe780f.zip
Merge "The wait_for function needs to be added into all the images"
-rw-r--r--docker/base/kolla-common.sh35
-rw-r--r--docker/centos-rdo-base/Dockerfile1
-rw-r--r--docker/fedora-rdo-base/Dockerfile1
-rwxr-xr-xdocker/fedora-rdo-base/wait_for85
-rwxr-xr-xdocker/glance/glance-api/start.sh8
-rw-r--r--docs/wait-for.md18
6 files changed, 58 insertions, 90 deletions
diff --git a/docker/base/kolla-common.sh b/docker/base/kolla-common.sh
index 56c658c43..75058e521 100644
--- a/docker/base/kolla-common.sh
+++ b/docker/base/kolla-common.sh
@@ -19,6 +19,41 @@ check_required_vars() {
done
}
+wait_for() {
+ local loops=${1:-""}
+ local sleeptime=${2:-""}
+ local fail_match_output=${fail_match_output:-""}
+ local successful_match_output=${successful_match_output:-""}
+ shift 2 || true
+ local command="$@"
+
+ if [ -z "$loops" -o -z "$sleeptime" -o -z "$command" ]; then
+ echo "Incorrect call of wait_for. Refer to docs/wait-for.md for help"
+ fi
+
+ local i=0
+ while [ $i -lt $loops ]; do
+ i=$((i + 1))
+ local status=0
+ local output=$(eval $command 2>&1) || status=$?
+ if [[ -n "$successful_match_output" ]] \
+ && [[ $output =~ $successful_match_output ]]; then
+ break
+ elif [[ -n "$fail_match_output" ]] \
+ && [[ $output =~ $fail_match_output ]]; then
+ echo "Command output matched '$fail_match_output'."
+ continue
+ elif [[ -z "$successful_match_output" ]] && [[ $status -eq 0 ]]; then
+ break
+ fi
+ sleep $sleeptime
+ done
+ local seconds=$((loops * sleeptime))
+ printf 'Timing out after %d seconds:\ncommand=%s\nOUTPUT=%s\n' \
+ "$seconds" "$command" "$output"
+ exit 1
+}
+
# Exit unless we receive a successful response from corresponding OpenStack
# service.
check_for_os_service() {
diff --git a/docker/centos-rdo-base/Dockerfile b/docker/centos-rdo-base/Dockerfile
index a0ce5248b..b613033ea 100644
--- a/docker/centos-rdo-base/Dockerfile
+++ b/docker/centos-rdo-base/Dockerfile
@@ -95,3 +95,4 @@ RUN yum install -y \
RUN mkdir -p /opt/kolla
ADD service_hosts.sh /opt/kolla/service_hosts.sh
ADD kolla-common.sh /opt/kolla/kolla-common.sh
+ADD wait_for /opt/kolla/wait_for
diff --git a/docker/fedora-rdo-base/Dockerfile b/docker/fedora-rdo-base/Dockerfile
index f40c5a96b..19a4b72a1 100644
--- a/docker/fedora-rdo-base/Dockerfile
+++ b/docker/fedora-rdo-base/Dockerfile
@@ -94,4 +94,3 @@ RUN yum install -y \
RUN mkdir -p /opt/kolla
ADD service_hosts.sh /opt/kolla/service_hosts.sh
ADD kolla-common.sh /opt/kolla/kolla-common.sh
-
diff --git a/docker/fedora-rdo-base/wait_for b/docker/fedora-rdo-base/wait_for
deleted file mode 100755
index 16f2cc8c8..000000000
--- a/docker/fedora-rdo-base/wait_for
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/bin/bash
-# Based on
-# https://raw.githubusercontent.com/openstack/tripleo-incubator/6931c1fc7ed98ce36998c5b82750a880b0365445/scripts/wait_for
-#
-# Copyright 2013 Red Hat
-# All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-set -e # exit on the first non-zero status
-set -u # exit on unset variables
-#set -x # setting this actually breaks the scripts function
-
-SCRIPT_NAME=$(basename $0)
-
-
-function show_options() {
- echo "Usage: $SCRIPT_NAME LOOPS_NUMBER SLEEP_TIME ARGS"
- echo
- echo "ARGS are read and concatenated together into a single command."
- echo "Execute the command in a loop until it succeeds or the number"
- echo "of attempts exceeds LOOPS_NUMBER value. After each failure"
- echo "pause for SLEEP_TIME seconds."
- echo
- echo "An optional FAIL_MATCH_OUTPUT variable may also be set to control "
- echo "if the loop exits early if the commands stdout/stderr matches the "
- echo "supplied regex string."
- echo
- echo "Examples:"
- echo " wait_for 30 10 ping -c 1 192.0.2.2"
- echo " wait_for 10 1 ls file_we_are_waiting_for"
- echo " wait_for 10 3 date \| grep 8"
- echo " FAIL_MATCH_OUTPUT=CREATE_FAILED wait_for 30 10 heat stack-show undercloud"
- echo " SUCCESSFUL_MATCH_OUTPUT=CREATE_COMPLETE wait_for 30 10 heat stack-show undercloud"
- exit 1
-}
-
-
-LOOPS=${1:-""}
-SLEEPTIME=${2:-""}
-FAIL_MATCH_OUTPUT=${FAIL_MATCH_OUTPUT:-""}
-SUCCESSFUL_MATCH_OUTPUT=${SUCCESSFUL_MATCH_OUTPUT:-""}
-shift 2 || true
-COMMAND="$@"
-
-if [ -z "$LOOPS" -o -z "$SLEEPTIME" -o -z "$COMMAND" ]; then
- show_options
-fi
-
-
-i=0
-while [ $i -lt $LOOPS ]; do
- i=$((i + 1))
- STATUS=0
- OUTPUT=$(eval $COMMAND 2>&1) || STATUS=$?
- if [[ -n "$SUCCESSFUL_MATCH_OUTPUT" ]] \
- && [[ $OUTPUT =~ $SUCCESSFUL_MATCH_OUTPUT ]]; then
- exit 0
- elif [[ -n "$FAIL_MATCH_OUTPUT" ]] \
- && [[ $OUTPUT =~ $FAIL_MATCH_OUTPUT ]]; then
- echo "Command output matched '$FAIL_MATCH_OUTPUT'. Exiting..."
- exit 1
- elif [[ -z "$SUCCESSFUL_MATCH_OUTPUT" ]] && [[ $STATUS -eq 0 ]]; then
- # The command successfully completed and we aren't testing against
- # it's output so we have finished waiting.
- exit 0
- fi
-
- sleep $SLEEPTIME
-done
-SECONDS=$((LOOPS * SLEEPTIME))
-printf 'Timing out after %d seconds:\nCOMMAND=%s\nOUTPUT=%s\n' \
- "$SECONDS" "$COMMAND" "$OUTPUT"
-exit 1
-
diff --git a/docker/glance/glance-api/start.sh b/docker/glance/glance-api/start.sh
index 851835449..5dd1da5b3 100755
--- a/docker/glance/glance-api/start.sh
+++ b/docker/glance/glance-api/start.sh
@@ -11,10 +11,10 @@ check_required_vars KEYSTONE_ADMIN_TOKEN KEYSTONE_ADMIN_SERVICE_HOST \
ADMIN_TENANT_NAME GLANCE_API_SERVICE_HOST \
PUBLIC_IP
-/opt/kolla/wait_for 30 1 keystone \
- --os-auth-url=http://${KEYSTONE_PUBLIC_SERVICE_HOST}:35357/v2.0 \
- --os-username=admin --os-tenant-name=${ADMIN_TENANT_NAME} \
- --os-password=${KEYSTONE_ADMIN_PASSWORD} endpoint-list
+wait_for 30 1 keystone \
+ --os-auth-url=http://${KEYSTONE_PUBLIC_SERVICE_HOST}:35357/v2.0 \
+ --os-username=admin --os-tenant-name=${ADMIN_TENANT_NAME} \
+ --os-password=${KEYSTONE_ADMIN_PASSWORD} endpoint-list
check_for_keystone
export SERVICE_TOKEN="${KEYSTONE_ADMIN_TOKEN}"
diff --git a/docs/wait-for.md b/docs/wait-for.md
new file mode 100644
index 000000000..3317c315f
--- /dev/null
+++ b/docs/wait-for.md
@@ -0,0 +1,18 @@
+# Wait-for function
+
+The usage of the wait_for function looks like the following
+ $ SCRIPT_NAME LOOPS_NUMBER SLEEP_TIME ARGS
+
+The ARGS are read and concatenated together into a single command
+and the command is executed in a loop until it succeeds or reaches
+the max number of attempts (LOOPS_NUMBER).
+
+An optional FAIL_MATCH_OUTPUT variable may also be set to control
+if the loop exits early if the commands stdout/stderr matches the
+supplied regex string.
+Examples:
+ $ wait_for 30 10 ping -c 1 192.0.2.2
+ $ wait_for 10 1 ls file_we_are_waiting_for
+ $ wait_for 10 3 date \| grep 8
+ $ FAIL_MATCH_OUTPUT=CREATE_FAILED wait_for 30 10 heat stack-show undercloud
+ $ SUCCESSFUL_MATCH_OUTPUT=CREATE_COMPLETE wait_for 30 10 heat stack-show undercloud