Migrate mysql backend to use openstacklib::db::mysql

Implements: blueprint commmon-openstack-database-resource
Change-Id: I71e1bf084139524e41276e5cbd7f5be02d07e825
This commit is contained in:
Colleen Murphy 2014-07-11 10:40:32 -07:00
parent a4a20a9012
commit a95a9435dc
8 changed files with 33 additions and 123 deletions

View File

@ -6,6 +6,7 @@ fixtures:
repo: 'git://github.com/puppetlabs/puppetlabs-mysql.git'
ref: 'origin/2.2.x'
"nova": "git://github.com/stackforge/puppet-nova.git"
'openstacklib': 'git://github.com/stackforge/puppet-openstacklib.git'
"stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
symlinks:
"heat": "#{source_dir}"

View File

@ -8,6 +8,6 @@ project_page 'https://launchpad.net/puppet-heat'
source 'https://github.com/stackforge/puppet-heat'
dependency 'puppetlabs/inifile', '>= 1.0.0 <2.0.0'
dependency 'puppetlabs/mysql', '>=0.9.0 <3.0.0'
dependency 'puppetlabs/keystone', '>=4.0.0 <5.0.0'
dependency 'puppetlabs/stdlib', '>= 3.2.0'
dependency 'stackforge/openstacklib', '>=5.0.0'

View File

@ -51,7 +51,7 @@ extra functionality through types and providers.
Limitations
-----------
The Heat Openstack service depends on a sqlalchemy database. If you are using puppetlabs-mysql to achieve this, there is a parameter called mysql_module that can be used to swap between the two supported versions: 0.9 and 2.2. This is needed because the puppetlabs-mysql module was rewritten and the custom type names have changed between versions.
None
Development
-----------

View File

@ -29,58 +29,34 @@
# Defaults to 'utf8_unicode_ci'
#
# [*mysql_module*]
# The version of the mysql puppet module to use.
# Tested versions include 0.9 and 2.2
# Defaults to '2.2'.
# (optional) Deprecated. Does nothing.
#
class heat::db::mysql(
$password = false,
$dbname = 'heat',
$user = 'heat',
$host = 'localhost',
$host = '127.0.0.1',
$allowed_hosts = undef,
$charset = 'utf8',
$collate = 'utf8_unicode_ci',
$mysql_module = '2.2'
$mysql_module = undef
) {
if $mysql_module {
warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.')
}
validate_string($password)
Class['heat::db::mysql'] -> Exec<| title == 'heat-dbsync' |>
Mysql::Db[$dbname] ~> Exec<| title == 'heat-dbsync' |>
if ($mysql_module >= 2.2) {
mysql::db { $dbname:
user => $user,
password => $password,
host => $host,
charset => $charset,
collate => $collate,
require => Class['mysql::server'],
}
} else {
mysql::db { $dbname:
user => $user,
password => $password,
host => $host,
charset => $charset,
require => Class['mysql::config'],
}
::openstacklib::db::mysql { 'heat':
user => $user,
password_hash => mysql_password($password),
dbname => $dbname,
host => $host,
charset => $charset,
collate => $collate,
allowed_hosts => $allowed_hosts,
}
# Check allowed_hosts to avoid duplicate resource declarations
if is_array($allowed_hosts) and delete($allowed_hosts,$host) != [] {
$real_allowed_hosts = delete($allowed_hosts,$host)
} elsif is_string($allowed_hosts) and ($allowed_hosts != $host) {
$real_allowed_hosts = $allowed_hosts
}
if $real_allowed_hosts {
heat::db::mysql::host_access { $real_allowed_hosts:
user => $user,
password => $password,
database => $dbname,
mysql_module => $mysql_module,
}
}
::Openstacklib::Db::Mysql['heat'] ~> Exec<| title == 'heat-dbsync' |>
}

View File

@ -1,43 +0,0 @@
# Allow a user to access the heat database
#
# == Namevar
# The host to allow
#
# == Parameters
# [*user*]
# username to allow
#
# [*password*]
# user password
#
# [*database*]
# the database name
#
define heat::db::mysql::host_access ($user, $password, $database, $mysql_module) {
if ($mysql_module >= 2.2) {
mysql_user { "${user}@${name}":
password_hash => mysql_password($password),
require => Mysql_database[$database],
}
mysql_grant { "${user}@${name}/${database}.*":
privileges => ['ALL'],
options => ['GRANT'],
table => "${database}.*",
require => Mysql_user["${user}@${name}"],
user => "${user}@${name}"
}
} else {
database_user { "${user}@${name}":
password_hash => mysql_password($password),
provider => 'mysql',
require => Database[$database],
}
database_grant { "${user}@${name}/${database}":
# TODO figure out which privileges to grant.
privileges => 'all',
provider => 'mysql',
require => Database_user["${user}@${name}"]
}
}
}

View File

@ -89,9 +89,7 @@
# Defaults to LOG_USER
#
# [*mysql_module*]
# (optional) The mysql puppet module version.
# Tested versions include 0.9 and 2.2
# Defaults to '2.2'
# (optional) Deprecated. Does nothing.
#
class heat(
$auth_uri = false,
@ -136,7 +134,8 @@ class heat(
$database_idle_timeout = 3600,
$use_syslog = false,
$log_facility = 'LOG_USER',
$mysql_module = '2.2',
#Deprecated parameters
$mysql_module = undef,
) {
include heat::params
@ -153,6 +152,9 @@ class heat(
if ($kombu_ssl_certfile and !$kombu_ssl_keyfile) or ($kombu_ssl_keyfile and !$kombu_ssl_certfile) {
fail('The kombu_ssl_certfile and kombu_ssl_keyfile parameters must be used together')
}
if $mysql_module {
warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.')
}
File {
require => Package['heat-common'],
@ -317,12 +319,8 @@ class heat(
case $sql_connection {
/^mysql:\/\//: {
$backend_package = false
if ($mysql_module >= 2.2) {
require mysql::bindings
require mysql::bindings::python
} else {
include mysql::python
}
require mysql::bindings
require mysql::bindings::python
}
/^postgresql:\/\//: {
$backend_package = 'python-psycopg2'

View File

@ -11,7 +11,6 @@ describe 'heat::db::mysql' do
:user => 'heat',
:host => 'localhost',
:charset => 'utf8',
:mysql_module => '0.9'
}
end
@ -23,12 +22,12 @@ describe 'heat::db::mysql' do
end
it 'creates a mysql database' do
should contain_mysql__db( params[:dbname] ).with(
:user => params[:user],
:password => params[:password],
:host => params[:host],
:charset => params[:charset],
:require => 'Class[Mysql::Config]'
should contain_openstacklib__db__mysql( params[:dbname] ).with(
:user => params[:user],
:password_hash => '*58C036CDA51D8E8BBBBF2F9EA5ABF111ADA444F0',
:host => params[:host],
:charset => params[:charset],
:require => 'Class[Mysql::Config]'
)
end
end
@ -41,16 +40,6 @@ describe 'heat::db::mysql' do
}
end
it {should_not contain_heat__db__mysql__host_access("localhost").with(
:user => 'heat',
:password => 'heatpass',
:database => 'heat'
)}
it {should contain_heat__db__mysql__host_access("%").with(
:user => 'heat',
:password => 'heatpass',
:database => 'heat'
)}
end
describe "overriding allowed_hosts param to string" do
@ -61,11 +50,6 @@ describe 'heat::db::mysql' do
}
end
it {should contain_heat__db__mysql__host_access("192.168.1.1").with(
:user => 'heat',
:password => 'heatpass2',
:database => 'heat'
)}
end
describe "overriding allowed_hosts param equals to host param " do
@ -76,10 +60,5 @@ describe 'heat::db::mysql' do
}
end
it {should_not contain_heat__db__mysql__host_access("localhost").with(
:user => 'heat',
:password => 'heatpass2',
:database => 'heat'
)}
end
end

View File

@ -17,7 +17,6 @@ describe 'heat' do
:database_idle_timeout => 3600,
:auth_uri => 'http://127.0.0.1:5000/v2.0',
:keystone_ec2_uri => 'http://127.0.0.1:5000/v2.0/ec2tokens',
:mysql_module => '2.2'
}
end