Browse code

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

Ihar Hrachyshka authored on 2014/10/06 20:29:39
Showing 14 changed files
... ...
@@ -131,7 +131,7 @@ function configure_tuskar {
131 131
 function init_tuskar {
132 132
 
133 133
     # (re)create tuskar database
134
-    recreate_database tuskar utf8
134
+    recreate_database tuskar
135 135
 
136 136
     tuskar-dbsync --config-file $TUSKAR_CONF
137 137
     create_tuskar_cache_dir
... ...
@@ -262,7 +262,7 @@ function init_ceilometer {
262 262
 
263 263
     if is_service_enabled mysql postgresql; then
264 264
         if [ "$CEILOMETER_BACKEND" = 'mysql' ] || [ "$CEILOMETER_BACKEND" = 'postgresql' ] ; then
265
-            recreate_database ceilometer utf8
265
+            recreate_database ceilometer
266 266
             $CEILOMETER_BIN_DIR/ceilometer-dbsync
267 267
         fi
268 268
     fi
... ...
@@ -376,7 +376,7 @@ function init_cinder {
376 376
 
377 377
     if is_service_enabled $DATABASE_BACKENDS; then
378 378
         # (Re)create cinder database
379
-        recreate_database cinder utf8
379
+        recreate_database cinder
380 380
 
381 381
         # Migrate cinder database
382 382
         $CINDER_BIN_DIR/cinder-manage db sync
... ...
@@ -98,11 +98,9 @@ function initialize_database_backends {
98 98
 
99 99
 # Recreate a given database
100 100
 #  $1 The name of the database
101
-#  $2 The character set/encoding of the database
102 101
 function recreate_database {
103 102
     local db=$1
104
-    local charset=$2
105
-    recreate_database_$DATABASE_TYPE $db $charset
103
+    recreate_database_$DATABASE_TYPE $db
106 104
 }
107 105
 
108 106
 # Install the database
... ...
@@ -43,9 +43,8 @@ function cleanup_database_mysql {
43 43
 
44 44
 function recreate_database_mysql {
45 45
     local db=$1
46
-    local charset=$2
47 46
     mysql -u$DATABASE_USER -p$DATABASE_PASSWORD -h$MYSQL_HOST -e "DROP DATABASE IF EXISTS $db;"
48
-    mysql -u$DATABASE_USER -p$DATABASE_PASSWORD -h$MYSQL_HOST -e "CREATE DATABASE $db CHARACTER SET $charset;"
47
+    mysql -u$DATABASE_USER -p$DATABASE_PASSWORD -h$MYSQL_HOST -e "CREATE DATABASE $db CHARACTER SET utf8;"
49 48
 }
50 49
 
51 50
 function configure_database_mysql {
... ...
@@ -37,10 +37,9 @@ function cleanup_database_postgresql {
37 37
 
38 38
 function recreate_database_postgresql {
39 39
     local db=$1
40
-    local charset=$2
41 40
     # Avoid unsightly error when calling dropdb when the database doesn't exist
42 41
     psql -h$DATABASE_HOST -U$DATABASE_USER -dtemplate1 -c "DROP DATABASE IF EXISTS $db"
43
-    createdb -h $DATABASE_HOST -U$DATABASE_USER -l C -T template0 -E $charset $db
42
+    createdb -h $DATABASE_HOST -U$DATABASE_USER -l C -T template0 -E utf8 $db
44 43
 }
45 44
 
46 45
 function configure_database_postgresql {
... ...
@@ -279,7 +279,7 @@ function init_glance {
279 279
     mkdir -p $GLANCE_CACHE_DIR
280 280
 
281 281
     # (Re)create glance database
282
-    recreate_database glance utf8
282
+    recreate_database glance
283 283
 
284 284
     # Migrate glance database
285 285
     $GLANCE_BIN_DIR/glance-manage db_sync
... ...
@@ -170,7 +170,7 @@ function configure_heat {
170 170
 function init_heat {
171 171
 
172 172
     # (re)create heat database
173
-    recreate_database heat utf8
173
+    recreate_database heat
174 174
 
175 175
     $HEAT_DIR/bin/heat-manage db_sync
176 176
     create_heat_cache_dir
... ...
@@ -380,7 +380,7 @@ function create_ironic_accounts {
380 380
 # init_ironic() - Initialize databases, etc.
381 381
 function init_ironic {
382 382
     # (Re)create  ironic database
383
-    recreate_database ironic utf8
383
+    recreate_database ironic
384 384
 
385 385
     # Migrate ironic database
386 386
     $IRONIC_BIN_DIR/ironic-dbsync --config-file=$IRONIC_CONF_FILE
... ...
@@ -448,7 +448,7 @@ function init_keystone {
448 448
     fi
449 449
 
450 450
     # (Re)create keystone database
451
-    recreate_database keystone utf8
451
+    recreate_database keystone
452 452
 
453 453
     # Initialize keystone database
454 454
     $KEYSTONE_DIR/bin/keystone-manage db_sync
... ...
@@ -592,7 +592,7 @@ function create_neutron_initial_network {
592 592
 
593 593
 # init_neutron() - Initialize databases, etc.
594 594
 function init_neutron {
595
-    recreate_database $Q_DB_NAME utf8
595
+    recreate_database $Q_DB_NAME
596 596
     # Run Neutron db migrations
597 597
     $NEUTRON_BIN_DIR/neutron-db-manage --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE upgrade head
598 598
 }
... ...
@@ -623,16 +623,13 @@ function init_nova {
623 623
     # Only do this step once on the API node for an entire cluster.
624 624
     if is_service_enabled $DATABASE_BACKENDS && is_service_enabled n-api; then
625 625
         # (Re)create nova database
626
-        # Explicitly use latin1: to avoid lp#829209, nova expects the database to
627
-        # use latin1 by default, and then upgrades the database to utf8 (see the
628
-        # 082_essex.py in nova)
629
-        recreate_database nova latin1
626
+        recreate_database nova
630 627
 
631 628
         # Migrate nova database
632 629
         $NOVA_BIN_DIR/nova-manage db sync
633 630
 
634 631
         if is_service_enabled n-cell; then
635
-            recreate_database $NOVA_CELLS_DB latin1
632
+            recreate_database $NOVA_CELLS_DB
636 633
         fi
637 634
     fi
638 635
 
... ...
@@ -143,7 +143,7 @@ function configure_sahara {
143 143
         setup_colorized_logging $SAHARA_CONF_FILE DEFAULT
144 144
     fi
145 145
 
146
-    recreate_database sahara utf8
146
+    recreate_database sahara
147 147
     $SAHARA_BIN_DIR/sahara-db-manage --config-file $SAHARA_CONF_FILE upgrade head
148 148
 }
149 149
 
... ...
@@ -201,7 +201,7 @@ function install_trove {
201 201
 # init_trove() - Initializes Trove Database as a Service
202 202
 function init_trove {
203 203
     # (Re)Create trove db
204
-    recreate_database trove utf8
204
+    recreate_database trove
205 205
 
206 206
     # Initialize the trove database
207 207
     $TROVE_BIN_DIR/trove-manage db_sync