From: David Garcia Date: Mon, 2 Mar 2020 13:17:26 +0000 (+0100) Subject: Fix bug 1022: Fix database checking, and wait for keystone hostname to be available X-Git-Tag: release-v8.0-start~53 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=58b0e32533ce1494953bbe994171d080859831de;p=osm%2Fdevops.git Fix bug 1022: Fix database checking, and wait for keystone hostname to be available Change-Id: I56abf156eb187a3bc7f3272a2137017aea39fed2 Signed-off-by: David Garcia --- diff --git a/docker/Keystone/Dockerfile b/docker/Keystone/Dockerfile index f92f36e9..3880e96d 100644 --- a/docker/Keystone/Dockerfile +++ b/docker/Keystone/Dockerfile @@ -35,7 +35,7 @@ RUN apt-get update && \ apt-get install -y software-properties-common && \ add-apt-repository -y cloud-archive:pike && \ apt-get update && apt dist-upgrade -y && \ - apt-get install -y python-openstackclient keystone apache2 libapache2-mod-wsgi net-tools mysql-client && \ + apt-get install -y python-openstackclient keystone apache2 libapache2-mod-wsgi net-tools mysql-client dnsutils && \ apt-get install -y python-pip build-essential python-dev libldap2-dev libsasl2-dev libssl-dev libffi-dev libxml2-dev libxslt1-dev zlib1g-dev ldap-utils && \ pip install python-ldap ldappool && \ rm -rf /var/lib/apt/lists/* && \ diff --git a/docker/Keystone/scripts/start.sh b/docker/Keystone/scripts/start.sh index 90ff68b2..78c7820a 100755 --- a/docker/Keystone/scripts/start.sh +++ b/docker/Keystone/scripts/start.sh @@ -41,6 +41,24 @@ function wait_db(){ return 0 } +function wait_keystone_host(){ + attempt=0 + timeout=2 + echo "Wait until Keystone hostname can be resolved " + while ! nslookup $KEYSTONE_HOST; do + #wait 120 sec + if [ $attempt -ge $max_attempts ]; then + echo + echo "Can not resolve ${KEYSTONE_HOST} during $max_attempts sec" + return 1 + fi + attempt=$[$attempt+1] + echo -n "." + sleep 1 + done + return 0 +} + function is_db_created() { db_host=$1 db_port=$2 @@ -66,17 +84,17 @@ if [ -z $DB_EXISTS ]; then mysql -h"$DB_HOST" -P"$DB_PORT" -u"$ROOT_DB_USER" -p"$ROOT_DB_PASSWORD" --default_character_set utf8 -e "GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' IDENTIFIED BY '$KEYSTONE_DB_PASSWORD'" mysql -h"$DB_HOST" -P"$DB_PORT" -u"$ROOT_DB_USER" -p"$ROOT_DB_PASSWORD" --default_character_set utf8 -e "GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' IDENTIFIED BY '$KEYSTONE_DB_PASSWORD'" else - if [ $(mysql -h"$DB_HOST" -P"$DB_PORT" -u"$ROOT_DB_USER" -p"$ROOT_DB_PASSWORD" --default_character_set utf8 -sse "SELECT COUNT(*) FROM keystone;") -gt 0 ]; then + if [ $(mysql -h"$DB_HOST" -P"$DB_PORT" -u"$ROOT_DB_USER" -p"$ROOT_DB_PASSWORD" --default_character_set utf8 -sse "SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'keystone';") -gt 0 ]; then echo "DB keystone is empty" DB_NOT_EMPTY="y" fi fi # Setting Keystone database connection -sed -i "721s%.*%connection = mysql+pymysql://keystone:$KEYSTONE_DB_PASSWORD@$DB_HOST:$DB_PORT/keystone%" /etc/keystone/keystone.conf +sed -i '/^\[database\]$/,/^\[/ s/^connection = .*/connection = mysql+pymysql:\/\/keystone:'$KEYSTONE_DB_PASSWORD'@'$DB_HOST':'$DB_PORT'\/keystone/' /etc/keystone/keystone.conf # Setting Keystone tokens -sed -i "2934s%.*%provider = fernet%" /etc/keystone/keystone.conf +sed -i '/^\[token\]$/,/^\[/ s/^.*provider = .*/provider = fernet/' /etc/keystone/keystone.conf # Use LDAP authentication for Identity @@ -157,6 +175,8 @@ fi keystone-manage fernet_setup --keystone-user keystone --keystone-group keystone keystone-manage credential_setup --keystone-user keystone --keystone-group keystone +wait_keystone_host + # Bootstrap Keystone service if [ -z $DB_EXISTS ] || [ -z $DB_NOT_EMPTY ]; then keystone-manage bootstrap \ @@ -169,6 +189,7 @@ if [ -z $DB_EXISTS ] || [ -z $DB_NOT_EMPTY ]; then --bootstrap-region-id "$REGION_ID" fi +echo "ServerName $KEYSTONE_HOST" >> /etc/apache2/apache2.conf # Restart Apache Service service apache2 restart