From: sousaedu Date: Wed, 28 Jul 2021 10:08:43 +0000 (+0200) Subject: Fix bug 1600 - checking for db user keystone creation X-Git-Tag: release-v11.0-start~42 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=87c408507eb5c78e482cfcf20ba479a406dbfbaa;p=osm%2Fdevops.git Fix bug 1600 - checking for db user keystone creation Change-Id: Ibe382eaec6b2afefe3743cc818a75f60983bfcaa Signed-off-by: sousaedu --- diff --git a/docker/Keystone/scripts/start.sh b/docker/Keystone/scripts/start.sh index 5cdeddf3..66b3830a 100755 --- a/docker/Keystone/scripts/start.sh +++ b/docker/Keystone/scripts/start.sh @@ -19,6 +19,7 @@ ## DB_EXISTS="" +USER_DB_EXISTS="" DB_NOT_EMPTY="" max_attempts=120 @@ -75,14 +76,31 @@ function is_db_created() { fi } +function is_user_db_created() { + db_host=$1 + db_port=$2 + db_user=$3 + db_pswd=$4 + db_user_to_check=$5 + + user_count=$(mysql -h"$db_host" -P"$db_port" -u"$db_user" -p"$db_pswd" --default_character_set utf8 -sse "SELECT COUNT(*) FROM mysql.user WHERE user='$db_user_to_check' AND host='%';") + + if [ $user_count -gt 0 ]; then + echo "DB User $db_name exists" + return 0 + else + echo "DB User$db_name does not exist" + return 1 + fi +} + wait_db "$DB_HOST" "$DB_PORT" || exit 1 is_db_created "$DB_HOST" "$DB_PORT" "$ROOT_DB_USER" "$ROOT_DB_PASSWORD" "keystone" && DB_EXISTS="Y" +is_user_db_created "$DB_HOST" "$DB_PORT" "$ROOT_DB_USER" "$ROOT_DB_PASSWORD" "keystone" && USER_DB_EXISTS="Y" 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 "CREATE DATABASE keystone" - 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 INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'keystone';") -gt 0 ]; then echo "DB keystone is empty" @@ -90,6 +108,11 @@ else fi fi +if [ -z $USER_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'" +fi + # Setting Keystone database connection sed -i '/^\[database\]$/,/^\[/ s/^connection = .*/connection = mysql+pymysql:\/\/keystone:'$KEYSTONE_DB_PASSWORD'@'$DB_HOST':'$DB_PORT'\/keystone/' /etc/keystone/keystone.conf