From e1b90581c0da0a9bb1b3d5d1b82ca11eb9cfad31 Mon Sep 17 00:00:00 2001 From: Martin André Date: Tue, 2 Dec 2014 17:34:37 +0900 Subject: Reduce code duplication in kolla-common.sh Introduce a generic check_for_os_service function that exits unless it receives a successful response from the corresponding OpenStack service. Additionally use the local keyword to not leak local variables, and fix check for non-existing NEUTRON_API_SERVICE_HOST variable in check_for_neutron(). Change-Id: I67dff2b16a99bc44e928cd6a679dff8cc6a99b39 --- docker/fedora-rdo-base/kolla-common.sh | 61 ++++++++++++---------------------- 1 file changed, 21 insertions(+), 40 deletions(-) (limited to 'docker') diff --git a/docker/fedora-rdo-base/kolla-common.sh b/docker/fedora-rdo-base/kolla-common.sh index b917ebd68..c0031fb21 100644 --- a/docker/fedora-rdo-base/kolla-common.sh +++ b/docker/fedora-rdo-base/kolla-common.sh @@ -17,59 +17,40 @@ check_required_vars() { done } -# Exit unless we receive a successful response from the Glance API. -check_for_glance() { - check_required_vars GLANCE_API_SERVICE_HOST - GLANCE_API_URL="http://${GLANCE_API_SERVICE_HOST}:9292/" - - curl -sf -o /dev/null "$GLANCE_API_URL" || { - echo "ERROR: glance is not available @ $GLANCE_API_URL" >&2 - exit 1 - } +# Exit unless we receive a successful response from corresponding OpenStack +# service. +check_for_os_service() { + local name=$1 + local host_var=$2 + local port=$3 + local api_version=$4 - echo "glance is active @ $GLANCE_API_URL" -} + check_required_vars $host_var -# Exit unless we receive a successful response from the Keystone API. -check_for_keystone() { - check_required_vars KEYSTONE_PUBLIC_SERVICE_HOST + local endpoint="http://${!host_var}:$port/$api_version" - KEYSTONE_URL="http://${KEYSTONE_PUBLIC_SERVICE_HOST}:5000/v2.0" - - curl -sf -o /dev/null "$KEYSTONE_URL" || { - echo "ERROR: keystone is not available @ $KEYSTONE_URL" >&2 + curl -sf -o /dev/null "$endpoint" || { + echo "ERROR: $name is not available @ $endpoint" >&2 exit 1 } - echo "keystone is active @ $KEYSTONE_URL" + echo "$name is active @ $endpoint" } -# Exit unless we receive a successful response from the Nova API. -check_for_nova() { - check_required_vars NOVA_API_SERVICE_HOST - - NOVA_API_URL="http://${NOVA_API_SERVICE_HOST}:8774" +check_for_glance() { + check_for_os_service glance GLANCE_API_SERVICE_HOST 9292 +} - curl -sf -o /dev/null "$NOVA_API_URL" || { - echo "ERROR: nova is not available @ $NOVA_API_URL" >&2 - exit 1 - } +check_for_keystone() { + check_for_os_service keystone KEYSTONE_PUBLIC_SERVICE_HOST 5000 v2.0 +} - echo "nova is active @ $NOVA_API_URL" +check_for_nova() { + check_for_os_service nova NOVA_API_SERVICE_HOST 8774 } -# Exit unless we receive a successful response from the Neutron API. check_for_neutron() { - check_required_vars NEUTRON_API_SERVICE_HOST - - NEUTRON_API_URL="http://${NEUTRON_SERVER_SERVICE_HOST}:9696" - - curl -sf -o /dev/null "$NEUTRON_API_URL" || { - echo "ERROR: neutron is not available @ $NEUTRON_API_URL" >&2 - exit 1 - } - - echo "neutron is active @ $NEUTRON_API_URL" + check_for_os_service neutron NEUTRON_SERVER_SERVICE_HOST 9696 } # Exit unless we receive a successful response from the database server. -- cgit v1.2.3