From 3c8acf4f3b26a5055362b091aec2dfeb8b06d89d Mon Sep 17 00:00:00 2001 From: Derek Higgins Date: Wed, 9 Dec 2020 16:51:17 +0000 Subject: [PATCH] Wait for expected number of drivers starting API Currently the API will start even if the conductor is still starting up, which can lead to failures if you try to deploy nodes as soon as the API is accessible. Co-Author: Steven Hardy --- runironic-api.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/runironic-api.sh b/runironic-api.sh index 5dfcdd4dd..6857aec20 100755 --- a/runironic-api.sh +++ b/runironic-api.sh @@ -4,4 +4,14 @@ export IRONIC_DEPLOYMENT="API" . /bin/configure-ironic.sh +# Wait for ironic to load all expected drivers +# the DB query returns the number of unique hardware_type in the conductor_hardware_interfaces table +CONF_DRIVERS=$(crudini --get /etc/ironic/ironic.conf DEFAULT enabled_hardware_types | tr ',' '\n' | wc -l) +while true ; do + DB_DRIVERS=$(mysql -p$MARIADB_PASSWORD -u ironic -h 127.0.0.1 ironic -e 'select count( DISTINCT hardware_type) from conductor_hardware_interfaces' -B -s --ssl || echo 0) + [ "$DB_DRIVERS" -ge "$CONF_DRIVERS" ] && break + echo "Waiting for $CONF_DRIVERS expected drivers" + sleep 5 +done + exec /usr/bin/ironic-api --config-file /usr/share/ironic/ironic-dist.conf ${IRONIC_CONFIG_OPTIONS}