From 157c84b8766ae67f6868f26505ce9a5d7291730b Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Mon, 6 Oct 2014 13:29:39 +0200 Subject: [PATCH] Enforce UTF-8 encoding when creating databases We use InnoDB everywhere, so there should be no issues with long unicode keys. Dropped charset parameter for recreate_database since it's not needed anymore. Change-Id: Ib768402a9337c918309030a92ab81da17269f4f6 --- extras.d/70-tuskar.sh | 2 +- lib/ceilometer | 2 +- lib/cinder | 2 +- lib/database | 4 +--- lib/databases/mysql | 3 +-- lib/databases/postgresql | 3 +-- lib/glance | 2 +- lib/heat | 2 +- lib/ironic | 2 +- lib/keystone | 2 +- lib/neutron | 2 +- lib/nova | 7 ++----- lib/sahara | 2 +- lib/trove | 2 +- 14 files changed, 15 insertions(+), 22 deletions(-) diff --git a/extras.d/70-tuskar.sh b/extras.d/70-tuskar.sh index e77c504db0..56f26fff33 100644 --- a/extras.d/70-tuskar.sh +++ b/extras.d/70-tuskar.sh @@ -131,7 +131,7 @@ function configure_tuskar { function init_tuskar { # (re)create tuskar database - recreate_database tuskar utf8 + recreate_database tuskar tuskar-dbsync --config-file $TUSKAR_CONF create_tuskar_cache_dir diff --git a/lib/ceilometer b/lib/ceilometer index f6280d9d3b..04f68acada 100644 --- a/lib/ceilometer +++ b/lib/ceilometer @@ -262,7 +262,7 @@ function init_ceilometer { if is_service_enabled mysql postgresql; then if [ "$CEILOMETER_BACKEND" = 'mysql' ] || [ "$CEILOMETER_BACKEND" = 'postgresql' ] ; then - recreate_database ceilometer utf8 + recreate_database ceilometer $CEILOMETER_BIN_DIR/ceilometer-dbsync fi fi diff --git a/lib/cinder b/lib/cinder index c106424378..4b98bd9640 100644 --- a/lib/cinder +++ b/lib/cinder @@ -376,7 +376,7 @@ function init_cinder { if is_service_enabled $DATABASE_BACKENDS; then # (Re)create cinder database - recreate_database cinder utf8 + recreate_database cinder # Migrate cinder database $CINDER_BIN_DIR/cinder-manage db sync diff --git a/lib/database b/lib/database index 366d2b3d2c..a25c21a6d3 100644 --- a/lib/database +++ b/lib/database @@ -98,11 +98,9 @@ function initialize_database_backends { # Recreate a given database # $1 The name of the database -# $2 The character set/encoding of the database function recreate_database { local db=$1 - local charset=$2 - recreate_database_$DATABASE_TYPE $db $charset + recreate_database_$DATABASE_TYPE $db } # Install the database diff --git a/lib/databases/mysql b/lib/databases/mysql index d39d9667fc..673d867d8f 100644 --- a/lib/databases/mysql +++ b/lib/databases/mysql @@ -43,9 +43,8 @@ function cleanup_database_mysql { function recreate_database_mysql { local db=$1 - local charset=$2 mysql -u$DATABASE_USER -p$DATABASE_PASSWORD -h$MYSQL_HOST -e "DROP DATABASE IF EXISTS $db;" - mysql -u$DATABASE_USER -p$DATABASE_PASSWORD -h$MYSQL_HOST -e "CREATE DATABASE $db CHARACTER SET $charset;" + mysql -u$DATABASE_USER -p$DATABASE_PASSWORD -h$MYSQL_HOST -e "CREATE DATABASE $db CHARACTER SET utf8;" } function configure_database_mysql { diff --git a/lib/databases/postgresql b/lib/databases/postgresql index 76491c479d..ad8cdc77a2 100644 --- a/lib/databases/postgresql +++ b/lib/databases/postgresql @@ -37,10 +37,9 @@ function cleanup_database_postgresql { function recreate_database_postgresql { local db=$1 - local charset=$2 # Avoid unsightly error when calling dropdb when the database doesn't exist psql -h$DATABASE_HOST -U$DATABASE_USER -dtemplate1 -c "DROP DATABASE IF EXISTS $db" - createdb -h $DATABASE_HOST -U$DATABASE_USER -l C -T template0 -E $charset $db + createdb -h $DATABASE_HOST -U$DATABASE_USER -l C -T template0 -E utf8 $db } function configure_database_postgresql { diff --git a/lib/glance b/lib/glance index 8cda6be00a..87687613cd 100644 --- a/lib/glance +++ b/lib/glance @@ -279,7 +279,7 @@ function init_glance { mkdir -p $GLANCE_CACHE_DIR # (Re)create glance database - recreate_database glance utf8 + recreate_database glance # Migrate glance database $GLANCE_BIN_DIR/glance-manage db_sync diff --git a/lib/heat b/lib/heat index 49ed5331aa..3c20b2ffe9 100644 --- a/lib/heat +++ b/lib/heat @@ -170,7 +170,7 @@ function configure_heat { function init_heat { # (re)create heat database - recreate_database heat utf8 + recreate_database heat $HEAT_DIR/bin/heat-manage db_sync create_heat_cache_dir diff --git a/lib/ironic b/lib/ironic index 3f7ae2111c..acbffafdfb 100644 --- a/lib/ironic +++ b/lib/ironic @@ -380,7 +380,7 @@ function create_ironic_accounts { # init_ironic() - Initialize databases, etc. function init_ironic { # (Re)create ironic database - recreate_database ironic utf8 + recreate_database ironic # Migrate ironic database $IRONIC_BIN_DIR/ironic-dbsync --config-file=$IRONIC_CONF_FILE diff --git a/lib/keystone b/lib/keystone index 071dc908ae..fa6f346c30 100644 --- a/lib/keystone +++ b/lib/keystone @@ -448,7 +448,7 @@ function init_keystone { fi # (Re)create keystone database - recreate_database keystone utf8 + recreate_database keystone # Initialize keystone database $KEYSTONE_DIR/bin/keystone-manage db_sync diff --git a/lib/neutron b/lib/neutron index 6c9d7b9a9e..08bd43b6c0 100755 --- a/lib/neutron +++ b/lib/neutron @@ -592,7 +592,7 @@ function create_neutron_initial_network { # init_neutron() - Initialize databases, etc. function init_neutron { - recreate_database $Q_DB_NAME utf8 + recreate_database $Q_DB_NAME # Run Neutron db migrations $NEUTRON_BIN_DIR/neutron-db-manage --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE upgrade head } diff --git a/lib/nova b/lib/nova index cbfbdfa69f..f8d36ce640 100644 --- a/lib/nova +++ b/lib/nova @@ -623,16 +623,13 @@ function init_nova { # Only do this step once on the API node for an entire cluster. if is_service_enabled $DATABASE_BACKENDS && is_service_enabled n-api; then # (Re)create nova database - # Explicitly use latin1: to avoid lp#829209, nova expects the database to - # use latin1 by default, and then upgrades the database to utf8 (see the - # 082_essex.py in nova) - recreate_database nova latin1 + recreate_database nova # Migrate nova database $NOVA_BIN_DIR/nova-manage db sync if is_service_enabled n-cell; then - recreate_database $NOVA_CELLS_DB latin1 + recreate_database $NOVA_CELLS_DB fi fi diff --git a/lib/sahara b/lib/sahara index c902d385d1..8573ee83c8 100644 --- a/lib/sahara +++ b/lib/sahara @@ -143,7 +143,7 @@ function configure_sahara { setup_colorized_logging $SAHARA_CONF_FILE DEFAULT fi - recreate_database sahara utf8 + recreate_database sahara $SAHARA_BIN_DIR/sahara-db-manage --config-file $SAHARA_CONF_FILE upgrade head } diff --git a/lib/trove b/lib/trove index d889b056e8..e0a3831bc0 100644 --- a/lib/trove +++ b/lib/trove @@ -201,7 +201,7 @@ function install_trove { # init_trove() - Initializes Trove Database as a Service function init_trove { # (Re)Create trove db - recreate_database trove utf8 + recreate_database trove # Initialize the trove database $TROVE_BIN_DIR/trove-manage db_sync