Add database charset during create

When using MySQL, the database charset should be utf-8.

And the default charset is latin1, which will cause glance db sync
failed.

Closes-bug: #1356887
Change-Id: I50e299410de8068150d1c405994ecb96918fbc7d
This commit is contained in:
Chen Zhiwei 2014-08-15 01:00:28 +00:00
parent 2ea0234b1f
commit f0e55b8742
5 changed files with 25 additions and 4 deletions

View File

@ -1,6 +1,9 @@
# CHANGELOG for cookbook-openstack-common
This file is used to list changes made in each version of cookbook-openstack-common.
## 10.0.2
* Add database charset during create
## 10.0.1
* Add an option to allow configuring rabbitmq use_ssl

View File

@ -80,12 +80,22 @@ default['openstack']['endpoints']['db']['bind_interface'] = nil
# Default database attributes
default['openstack']['db']['server_role'] = 'os-ops-database'
default['openstack']['db']['service_type'] = 'mysql'
# Database charset during create database
default['openstack']['db']['charset'] = {
mysql: 'utf8',
postgresql: nil,
pgsql: nil,
sqlite: nil,
db2: 'utf8',
nosql: nil
}
# Database connection options. Should include starting '?'
default['openstack']['db']['options'] = {
mysql: '?charset=utf8',
mysql: "?charset=#{node['openstack']['db']['charset']['mysql']}",
postgresql: '',
sqlite: '',
db2: '?charset=utf8',
db2: "?charset=#{node['openstack']['db']['charset']['db2']}",
nosql: ''
}

View File

@ -91,6 +91,7 @@ module ::Openstack # rubocop:disable Documentation
provider db_prov
connection connection_info
database_name db_name
encoding node['openstack']['db']['charset'][type]
action :create
end

View File

@ -4,7 +4,7 @@ maintainer_email 'cookbooks@lists.tfoundry.com'
license 'Apache 2.0'
description 'Common OpenStack attributes, libraries and recipes.'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '10.0.1'
version '10.0.2'
recipe 'openstack-common', 'Installs/Configures common recipes'
recipe 'openstack-common::set_endpoints_by_interface', 'Set endpoints by interface'

View File

@ -25,7 +25,14 @@ describe 'openstack-common::default' do
end
it 'returns db info and creates database with user when service found' do
allow(subject).to receive(:database).and_return({})
['mysql', 'pgsql', 'postgresql'].each do |db_type|
encoding = node['openstack']['db']['charset'][db_type]
if encoding.nil?
allow(subject).to receive(:database).and_return({})
else
allow(subject).to receive(:database).with(encoding: encoding).and_return({})
end
end
allow(subject).to receive(:database_user).and_return({})
result = subject.db_create_with_user('compute', 'user', 'pass')
expect(result['host']).to eq('127.0.0.1')