Add support for puppetlabs-mysql 2.2

Puppetlabs-mysql has been rewritten to be much
cleaner. This patch adds a new parameter for the
cinder mysql class allowing users to use the new
version. Previous behavior will continue as normal
when using the old version (0.9)

Change-Id: Ie0011102d9f4dfcd50f24afcb73072090c914011
This commit is contained in:
Michael Chapman 2014-02-18 01:05:27 +11:00
parent 4d4017cb63
commit 62f92f9888
5 changed files with 79 additions and 24 deletions

View File

@ -161,6 +161,7 @@ Limitations
* Setup of storage nodes is limited to Linux and LVM, i.e. Puppet won't configure a Nexenta appliance but nova can be configured to use the Nexenta driver with Class['cinder::volume::nexenta'].
* The Cinder 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.
Development
-----------

View File

@ -1,3 +1,7 @@
# [*mysql_module*]
# (optional) The puppet-mysql module version to use.
# Tested versions include 0.9 and 2.2
# Defaults to '0.9'
#
class cinder::db::mysql (
$password,
@ -6,20 +10,38 @@ class cinder::db::mysql (
$host = '127.0.0.1',
$allowed_hosts = undef,
$charset = 'latin1',
$cluster_id = 'localzone'
$collate = 'latin1_swedish_ci',
$cluster_id = 'localzone',
$mysql_module = '0.9'
) {
Class['cinder::db::mysql'] -> Exec<| title == 'cinder-manage db_sync' |>
Database[$dbname] ~> Exec<| title == 'cinder-manage db_sync' |>
mysql::db { $dbname:
user => $user,
password => $password,
host => $host,
charset => $charset,
require => Class['mysql::config'],
if ($mysql_module >= 2.2) {
Mysql_database[$dbname] ~> Exec<| title == 'cinder-manage db_sync' |>
mysql::db { $dbname:
user => $user,
password => $password,
host => $host,
charset => $charset,
collate => $collate,
require => Class['mysql::server'],
}
} else {
Database[$dbname] ~> Exec<| title == 'cinder-manage db_sync' |>
mysql::db { $dbname:
user => $user,
password => $password,
host => $host,
charset => $charset,
require => Class['mysql::config'],
}
}
# 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)
@ -30,9 +52,10 @@ class cinder::db::mysql (
if $real_allowed_hosts {
# TODO this class should be in the mysql namespace
cinder::db::mysql::host_access { $real_allowed_hosts:
user => $user,
password => $password,
database => $dbname,
user => $user,
password => $password,
database => $dbname,
mysql_module => $mysql_module,
}
}

View File

@ -1,16 +1,33 @@
#
# Used to grant access to the cinder mysql DB
#
define cinder::db::mysql::host_access ($user, $password, $database) {
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}"]
define cinder::db::mysql::host_access ($user, $password, $database, $mysql_module = '0.9') {
if ($mysql_module >= 2.2) {
mysql_user { "${user}@${name}":
password_hash => mysql_password($password),
provider => 'mysql',
require => Mysql_database[$database],
}
mysql_grant { "${user}@${name}/${database}.*":
privileges => ['ALL'],
options => ['GRANT'],
provider => 'mysql',
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

@ -18,6 +18,11 @@
# If set to boolean false, it will not log to any directory.
# Defaults to '/var/log/cinder'
#
# [*mysql_module*]
# (optional) Puppetlabs-mysql module version to use
# Tested versions include 0.9 and 2.2
# Defaults to '0.9'
#
class cinder (
$sql_connection,
$sql_idle_timeout = '3600',
@ -49,7 +54,8 @@ class cinder (
$log_facility = 'LOG_USER',
$log_dir = '/var/log/cinder',
$verbose = false,
$debug = false
$debug = false,
$mysql_module = '0.9'
) {
include cinder::params
@ -153,6 +159,13 @@ class cinder (
'DEFAULT/rpc_backend': value => $rpc_backend;
}
if $mysql_module >= 2.2 {
require mysql::bindings
require mysql::bindings::python
} else {
require mysql::python
}
if $log_dir {
cinder_config {
'DEFAULT/log_dir': value => $log_dir;

View File

@ -3,7 +3,8 @@ require 'spec_helper'
describe 'cinder::db::mysql' do
let :req_params do
{:password => 'pw'}
{:password => 'pw',
:mysql_module => '0.9'}
end
let :facts do