Allow check_for_* functions to be consumed by wait_for

In order for the `check_for_*` functions to be consumed by `wait_for`,
they should notify of their success but not exit.

As a consequence, the previous behavior is restored by the fail_unless_*
companion functions.

With this change, it is now possible to do:

    wait_for 30 1 check_for_os_service_running keystone

Change-Id: I16ddf8913027030c3ccb5487713d172904508fd6
This commit is contained in:
Martin André 2015-03-30 10:14:03 +09:00
parent cf3086ed3b
commit 34872c1c2f
21 changed files with 74 additions and 64 deletions
docker
barbican
base
ceilometer
ceilometer-api
ceilometer-central
ceilometer-compute
cinder
glance
glance-api
glance-registry
heat
heat-api
heat-base
heat-engine
horizon
keystone
neutron/neutron-server
nova-controller
nova-api
nova-conductor
nova-scheduler
swift
swift-account
swift-container
swift-object
zaqar

View File

@ -15,8 +15,8 @@ fi
check_required_vars KEYSTONE_ADMIN_TOKEN KEYSTONE_ADMIN_SERVICE_HOST \
KEYSTONE_ADMIN_SERVICE_PORT BARBICAN_ADMIN_PASSWORD
check_for_db
check_for_keystone
fail_unless_db
fail_unless_os_service_running keystone
mysql -h ${MARIADB_SERVICE_HOST} -u root -p"${DB_ROOT_PASSWORD}" mysql <<EOF
CREATE DATABASE IF NOT EXISTS ${BARBICAN_DB_NAME};

View File

@ -103,43 +103,46 @@ wait_for_output() {
wait_for_output_unless $expected_output '' $@
}
# Exit unless we receive a successful response from corresponding OpenStack
# service.
check_for_os_service() {
# Check if we receive a successful response from corresponding OpenStack
# service endpoint.
check_for_os_service_endpoint() {
local name=$1
local host_var=$2
local port=$3
local port_var=$3
local api_version=$4
check_required_vars $host_var
check_required_vars $host_var $port_var
local endpoint="http://${!host_var}:$port/$api_version"
local endpoint="http://${!host_var}:${!port_var}/$api_version"
curl -sf -o /dev/null "$endpoint" || {
echo "ERROR: $name is not available @ $endpoint" >&2
exit 1
return 1
}
echo "$name is active @ $endpoint"
}
check_for_glance() {
check_for_os_service glance GLANCE_API_SERVICE_HOST 9292
check_for_os_service_running() {
local service=$1
local args=
case $service in
("glance") args="GLANCE_API_SERVICE_HOST GLANCE_API_SERVICE_PORT" ;;
("keystone") args="KEYSTONE_PUBLIC_SERVICE_HOST KEYSTONE_PUBLIC_SERVICE_PORT v2.0" ;;
("neutron") args="NEUTRON_SERVER_SERVICE_HOST NEUTRON_SERVER_SERVICE_PORT" ;;
("nova") args="NOVA_API_SERVICE_HOST NOVA_API_SERVICE_PORT" ;;
(*)
echo "Unknown service $service"
return 1 ;;
esac
check_for_os_service_endpoint $service $args
}
check_for_keystone() {
check_for_os_service keystone KEYSTONE_PUBLIC_SERVICE_HOST 5000 v2.0
fail_unless_os_service_running() {
check_for_os_service_running $@ || exit $?
}
check_for_nova() {
check_for_os_service nova NOVA_API_SERVICE_HOST 8774
}
check_for_neutron() {
check_for_os_service neutron NEUTRON_SERVER_SERVICE_HOST 9696
}
# Exit unless we receive a successful response from the database server.
# Check if we receive a successful response from the database server.
# Optionally takes a database name to check for. Defaults to 'mysql'.
check_for_db() {
local database=${1:-mysql}
@ -148,12 +151,16 @@ check_for_db() {
mysql -h ${MARIADB_SERVICE_HOST} -u root -p"${DB_ROOT_PASSWORD}" \
-e "select 1" $database > /dev/null 2>&1 || {
echo "ERROR: database $database is not available @ $MARIADB_SERVICE_HOST" >&2
exit 1
return 1
}
echo "database is active @ ${MARIADB_SERVICE_HOST}"
}
fail_unless_db() {
check_for_db $@ || exit $?
}
# Dump shell environment to a file
dump_vars() {
set -o posix

View File

@ -12,8 +12,8 @@ check_required_vars CEILOMETER_DB_USER CEILOMETER_DB_NAME \
CEILOMETER_KEYSTONE_USER CEILOMETER_ADMIN_PASSWORD \
CEILOMETER_API_SERVICE_HOST PUBLIC_IP
check_for_keystone
check_for_db
fail_unless_os_service_running keystone
fail_unless_db
#TODO(pkilambi): Add mongodb support

View File

@ -6,7 +6,7 @@
check_required_vars KEYSTONE_ADMIN_TOKEN KEYSTONE_AUTH_PROTOCOL \
KEYSTONE_ADMIN_SERVICE_HOST KEYSTONE_ADMIN_SERVICE_PORT
check_for_keystone
fail_unless_os_service_running keystone
export SERVICE_TOKEN="${KEYSTONE_ADMIN_TOKEN}"
export SERVICE_ENDPOINT="${KEYSTONE_AUTH_PROTOCOL}://${KEYSTONE_ADMIN_SERVICE_HOST}:${KEYSTONE_ADMIN_SERVICE_PORT}/v2.0"

View File

@ -6,7 +6,7 @@
check_required_vars KEYSTONE_ADMIN_TOKEN RABBITMQ_SERVICE_HOST RABBIT_PASSWORD
check_for_keystone
fail_unless_os_service_running keystone
# Nova conf settings
crudini --set /etc/nova/nova.conf DEFAULT instance_usage_audit True

View File

@ -1,4 +1,4 @@
#!/bin/bash -e
#!/bin/bash -e
: ${CINDER_DB_USER:=cinder}
: ${CINDER_DB_NAME:=cinder}
@ -13,49 +13,49 @@ fi
check_required_vars KEYSTONE_ADMIN_TOKEN KEYSTONE_ADMIN_SERVICE_HOST \
CINDER_ADMIN_PASSWORD
check_for_db
fail_unless_db
mysql -h ${MARIADB_SERVICE_HOST} -u root -p"${DB_ROOT_PASSWORD}" mysql <<EOF
CREATE DATABASE IF NOT EXISTS ${CINDER_DB_NAME};
GRANT ALL PRIVILEGES ON glance* TO
'${CINDER_DB_USER}'@'%' IDENTIFIED BY '${CINDER_DB_PASSWORD}'
CREATE DATABASE IF NOT EXISTS ${CINDER_DB_NAME};
GRANT ALL PRIVILEGES ON glance* TO
'${CINDER_DB_USER}'@'%' IDENTIFIED BY '${CINDER_DB_PASSWORD}'
EOF
#-----Cinder.conf setup-----
# Cinder database
crudini --set /etc/cinder/cinder.conf \
crudini --set /etc/cinder/cinder.conf \
DEFAULT \
db_driver \
"cinder.db"
# Rabbit
crudini --set /etc/cinder/cinder.conf \
crudini --set /etc/cinder/cinder.conf \
DEFAULT \
rabbit_host \
"127.0.0.1"
crudini --set /etc/cinder/cinder.conf \
crudini --set /etc/cinder/cinder.conf \
DEFAULT \
rabbit_port \
"5672"
crudini --set /etc/cinder/cinder.conf \
crudini --set /etc/cinder/cinder.conf \
DEFAULT \
rabbit_hosts \
"127.0.0.1:5672"
crudini --set /etc/cinder/cinder.conf \
crudini --set /etc/cinder/cinder.conf \
DEFAULT \
rabbit_userid \
"guest"
crudini --set /etc/cinder/cinder.conf \
crudini --set /etc/cinder/cinder.conf \
DEFAULT \
rabbit_password \
"guest"
crudini --set /etc/cinder/cinder.conf \
crudini --set /etc/cinder/cinder.conf \
DEFAULT \
rabbit_virtual_host \
"/"
crudini --set /etc/cinder/cinder.conf \
DEFAULT \
crudini --set /etc/cinder/cinder.conf \
DEFAULT \
rabbit_ha_queues \
"False"

View File

@ -15,7 +15,7 @@ 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
fail_unless_os_service_running keystone
export SERVICE_TOKEN="${KEYSTONE_ADMIN_TOKEN}"
export SERVICE_ENDPOINT="http://${KEYSTONE_ADMIN_SERVICE_HOST}:35357/v2.0"

View File

@ -8,7 +8,7 @@ set -e
check_required_vars GLANCE_DB_NAME GLANCE_DB_USER GLANCE_DB_PASSWORD
# lets wait for the DB to be available
wait_for 25 1 mysql -h ${MARIADB_SERVICE_HOST} -u root -p"${DB_ROOT_PASSWORD}" -e 'status;'
check_for_db
fail_unless_db
mysql -h ${MARIADB_SERVICE_HOST} -u root -p${DB_ROOT_PASSWORD} mysql <<EOF
CREATE DATABASE IF NOT EXISTS ${GLANCE_DB_NAME} DEFAULT CHARACTER SET utf8;

View File

@ -9,7 +9,7 @@ check_required_vars KEYSTONE_ADMIN_TOKEN KEYSTONE_ADMIN_SERVICE_HOST \
KEYSTONE_AUTH_PROTOCOL ADMIN_TENANT_NAME \
HEAT_API_SERVICE_HOST PUBLIC_IP
check_for_keystone
fail_unless_os_service_running keystone
export SERVICE_TOKEN="${KEYSTONE_ADMIN_TOKEN}"
export SERVICE_ENDPOINT="${KEYSTONE_AUTH_PROTOCOL}://${KEYSTONE_ADMIN_SERVICE_HOST}:35357/v2.0"

View File

@ -16,7 +16,7 @@ set -e
check_required_vars HEAT_DB_PASSWORD HEAT_KEYSTONE_PASSWORD \
KEYSTONE_PUBLIC_SERVICE_HOST RABBITMQ_SERVICE_HOST
check_for_db
fail_unless_db
dump_vars
cat > /openrc <<EOF

View File

@ -4,7 +4,7 @@
. /opt/kolla/config-heat.sh
check_required_vars HEAT_DB_NAME HEAT_DB_USER HEAT_DB_PASSWORD
check_for_db
fail_unless_db
mysql -h ${MARIADB_SERVICE_HOST} -u root -p${DB_ROOT_PASSWORD} mysql <<EOF
CREATE DATABASE IF NOT EXISTS ${HEAT_DB_NAME} DEFAULT CHARACTER SET utf8;

View File

@ -5,9 +5,9 @@ set -e
. /opt/kolla/kolla-common.sh
check_for_keystone
check_for_glance
check_for_nova
fail_unless_os_service_running keystone
fail_unless_os_service_running glance
fail_unless_os_service_running nova
export SERVICE_TOKEN="${KEYSTONE_ADMIN_TOKEN}"
export SERVICE_ENDPOINT="${KEYSTONE_AUTH_PROTOCOL}://${KEYSTONE_ADMIN_SERVICE_HOST}:35357/v2.0"

View File

@ -37,7 +37,7 @@ echo "Running the kolla-common script"
## Check DB connectivity and required variables
echo "Checking connectivity to the DB"
check_for_db
fail_unless_db
echo "Checking for required variables"
check_required_vars KEYSTONE_ADMIN_TOKEN KEYSTONE_DB_PASSWORD \
KEYSTONE_ADMIN_PASSWORD ADMIN_TENANT_NAME \

View File

@ -11,8 +11,8 @@ check_required_vars KEYSTONE_ADMIN_TOKEN KEYSTONE_ADMIN_SERVICE_HOST \
NEUTRON_KEYSTONE_USER NEUTRON_KEYSTONE_PASSWORD \
ADMIN_TENANT_NAME NEUTRON_SERVER_SERVICE_HOST \
PUBLIC_IP NEUTRON_DB_PASSWORD
check_for_keystone
check_for_db
fail_unless_os_service_running keystone
fail_unless_db
mysql -h ${MARIADB_SERVICE_HOST} -u root -p${DB_ROOT_PASSWORD} mysql <<EOF
CREATE DATABASE IF NOT EXISTS ${NEUTRON_DB_NAME} DEFAULT CHARACTER SET utf8;

View File

@ -8,8 +8,8 @@ check_required_vars KEYSTONE_ADMIN_TOKEN KEYSTONE_ADMIN_SERVICE_HOST \
NOVA_KEYSTONE_USER NOVA_KEYSTONE_PASSWORD \
ADMIN_TENANT_NAME NOVA_API_SERVICE_HOST \
NOVA_EC2_API_SERVICE_HOST PUBLIC_IP NOVA_DB_NAME
check_for_keystone
check_for_db $NOVA_DB_NAME
fail_unless_os_service_running keystone
fail_unless_db $NOVA_DB_NAME
export SERVICE_TOKEN="${KEYSTONE_ADMIN_TOKEN}"
export SERVICE_ENDPOINT="http://${KEYSTONE_ADMIN_SERVICE_HOST}:35357/v2.0"

View File

@ -5,7 +5,7 @@ set -e
. /opt/kolla/config-nova.sh
check_required_vars NOVA_DB_NAME NOVA_DB_USER NOVA_DB_PASSWORD
check_for_db
fail_unless_db
mysql -h ${MARIADB_SERVICE_HOST} -u root \
-p${DB_ROOT_PASSWORD} mysql <<EOF

View File

@ -5,6 +5,6 @@ set -e
. /opt/kolla/config-nova.sh
check_required_vars NOVA_DB_NAME
check_for_db $NOVA_DB_NAME
fail_unless_db $NOVA_DB_NAME
exec /usr/bin/nova-scheduler

View File

@ -8,8 +8,8 @@
check_required_vars KEYSTONE_ADMIN_TOKEN KEYSTONE_ADMIN_SERVICE_HOST \
SWIFT_ADMIN_PASSWORD
check_for_db
check_for_keystone
fail_unless_db
fail_unless_os_service_running keystone
if ! [ "$SWIFT_DB_PASSWORD" ]; then
SWIFT_DB_PASSWORD=$(openssl rand -hex 15)

View File

@ -8,8 +8,8 @@
check_required_vars KEYSTONE_ADMIN_TOKEN KEYSTONE_ADMIN_SERVICE_HOST \
SWIFT_ADMIN_PASSWORD
check_for_db
check_for_keystone
fail_unless_db
fail_unless_os_service_running keystone
if ! [ "$SWIFT_DB_PASSWORD" ]; then
SWIFT_DB_PASSWORD=$(openssl rand -hex 15)

View File

@ -8,8 +8,8 @@
check_required_vars KEYSTONE_ADMIN_TOKEN KEYSTONE_ADMIN_SERVICE_HOST \
SWIFT_ADMIN_PASSWORD
check_for_db
check_for_keystone
fail_unless_db
fail_unless_os_service_running keystone
if ! [ "$SWIFT_DB_PASSWORD" ]; then
SWIFT_DB_PASSWORD=$(openssl rand -hex 15)

View File

@ -13,8 +13,9 @@ check_required_vars ZAQAR_KEYSTONE_PASSWORD ZAQAR_SERVER_SERVICE_HOST \
PUBLIC_IP
dump_vars
#check_for_mongodb
check_for_keystone
# TODO Check for mongodb availability
# https://bugs.launchpad.net/kolla/+bug/1394727
fail_unless_os_service_running keystone
cat > /openrc <<EOF
export OS_AUTH_URL="http://${KEYSTONE_PUBLIC_SERVICE_HOST}:5000/v2.0"
@ -30,6 +31,8 @@ crudini --set $cfg DEFAULT log_file \
crudini --set $cfg DEFAULT use_stderr \
true
# TODO Switch to mongodb
# https://bugs.launchpad.net/kolla/+bug/1394727
crudini --set $cfg drivers storage \
sqlite