From 8aab6f82ded5acd20925712259eac1d796b257be Mon Sep 17 00:00:00 2001 From: Roger Luethi Date: Sat, 9 Aug 2014 08:23:03 +0200 Subject: [PATCH] labs: unified login/password handling The labs scripts need two sets of login/password for each service: one for the (MySQL) database used by the service, and one for authentication with keystone. For the labs scripts login names and passwords are simple functions of the service names: for the first set (database), we have ${service}User/${service}Pass, for the second set (keystone auth) ${service}/${service}_pass. This changeset adds two functions for producing the second set of credentials and renames the existing functions (as well as related variables) for producing the first set. This prevents us from having to store login names and passwords in the service scripts. It also keeps those things in one location where they can be changed easily should we ever want to do so. Implements: blueprint openstack-training-labs Change-Id: I730eab475bee843767984b6c64bab88a94c0156e --- labs/lib/functions.guest | 26 +++++++++++++++++++++----- labs/scripts/setup_keystone.sh | 6 +++--- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/labs/lib/functions.guest b/labs/lib/functions.guest index b826db0b..4472f1f4 100644 --- a/labs/lib/functions.guest +++ b/labs/lib/functions.guest @@ -155,22 +155,38 @@ function mysql_exe { function setup_database { local service=$1 - local user_name=$(service_to_user_name $service) - local user_password=$(service_to_user_password $service) + local db_user=$(service_to_db_user $service) + local db_password=$(service_to_db_password $service) mysql_exe "CREATE DATABASE $service" - mysql_exe "GRANT ALL ON ${service}.* TO '$user_name'@'%' IDENTIFIED BY '$user_password';" + mysql_exe "GRANT ALL ON ${service}.* TO '$db_user'@'%' IDENTIFIED BY '$db_password';" } -function service_to_user_name { +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Users for service-specific MySQL databases + +function service_to_db_user { local service_name=$1 echo "${service_name}User" } -function service_to_user_password { +function service_to_db_password { local service_name=$1 echo "${service_name}Pass" } +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Service-specific users in keystone + +function service_to_user_name { + local service_name=$1 + echo "${service_name}" +} + +function service_to_user_password { + local service_name=$1 + echo "${service_name}_pass" +} + #------------------------------------------------------------------------------- # Network configuration #------------------------------------------------------------------------------- diff --git a/labs/scripts/setup_keystone.sh b/labs/scripts/setup_keystone.sh index b0b34fa4..95819e9b 100755 --- a/labs/scripts/setup_keystone.sh +++ b/labs/scripts/setup_keystone.sh @@ -22,11 +22,11 @@ echo "Setting up database for keystone." setup_database keystone function get_database_url { - local user_name=$(service_to_user_name keystone) - local user_password=$(service_to_user_password keystone) + local db_user=$(service_to_db_user keystone) + local db_password=$(service_to_db_password keystone) local database_host=controller-mgmt - echo "mysql://$user_name:$user_password@$database_host/keystone" + echo "mysql://$db_user:$db_password@$database_host/keystone" } database_url=$(get_database_url)