aboutsummaryrefslogtreecommitdiff
path: root/docker/base/kolla-common.sh
diff options
context:
space:
mode:
authorRyan Hallisey <rhallise@redhat.com>2015-03-11 09:35:00 -0400
committerRyan Hallisey <rhallise@redhat.com>2015-03-18 10:33:42 -0400
commit4075c851edc3339adee8ef02bcc291e21b8a738c (patch)
tree0c5e56fd03bfc014a1f2dbf5f4ad8b511eca57b6 /docker/base/kolla-common.sh
parent53d7e3b6fa12169463688410202e4f47e358fc06 (diff)
downloadkolla-4075c851edc3339adee8ef02bcc291e21b8a738c.tar.gz
kolla-4075c851edc3339adee8ef02bcc291e21b8a738c.zip
The wait_for function needs to be added into all the images
This affects both fedora and the centos base images. Wait_for will be intregrated into kolla-common. Co-authored by: Charles Crouch <charcrou@cisco.com> Change-Id: Ide2304b787d4c3bf6fb3949f09e2cf1f450c2173
Diffstat (limited to 'docker/base/kolla-common.sh')
-rw-r--r--docker/base/kolla-common.sh35
1 files changed, 35 insertions, 0 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() {