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
diff --git a/lib/ceilometer b/lib/ceilometer
index f6280d9..04f68ac 100644
--- a/lib/ceilometer
+++ b/lib/ceilometer
@@ -262,7 +262,7 @@
 
     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 c106424..4b98bd9 100644
--- a/lib/cinder
+++ b/lib/cinder
@@ -376,7 +376,7 @@
 
     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 366d2b3..a25c21a 100644
--- a/lib/database
+++ b/lib/database
@@ -98,11 +98,9 @@
 
 # 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 d39d966..673d867 100644
--- a/lib/databases/mysql
+++ b/lib/databases/mysql
@@ -43,9 +43,8 @@
 
 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 76491c4..ad8cdc7 100644
--- a/lib/databases/postgresql
+++ b/lib/databases/postgresql
@@ -37,10 +37,9 @@
 
 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 8cda6be..8768761 100644
--- a/lib/glance
+++ b/lib/glance
@@ -279,7 +279,7 @@
     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 49ed533..3c20b2f 100644
--- a/lib/heat
+++ b/lib/heat
@@ -170,7 +170,7 @@
 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 3f7ae21..acbffaf 100644
--- a/lib/ironic
+++ b/lib/ironic
@@ -380,7 +380,7 @@
 # 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 071dc90..fa6f346 100644
--- a/lib/keystone
+++ b/lib/keystone
@@ -448,7 +448,7 @@
     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 6c9d7b9..08bd43b 100755
--- a/lib/neutron
+++ b/lib/neutron
@@ -592,7 +592,7 @@
 
 # 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 cbfbdfa..f8d36ce 100644
--- a/lib/nova
+++ b/lib/nova
@@ -623,16 +623,13 @@
     # 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 c902d38..8573ee8 100644
--- a/lib/sahara
+++ b/lib/sahara
@@ -143,7 +143,7 @@
         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 d889b05..e0a3831 100644
--- a/lib/trove
+++ b/lib/trove
@@ -201,7 +201,7 @@
 # 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