Add support for puppetlabs-mysql 2.2

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

Change-Id: Icdc787e325f3e86572f6930f1ab8c3d5291e67c9
This commit is contained in:
Michael Chapman 2014-02-18 01:45:00 +11:00
parent 6c870fd847
commit 4aa86af2fc
8 changed files with 98 additions and 31 deletions

View File

@ -103,6 +103,8 @@ Limitations
* Only supports configuring the file, swift and rbd storage backends.
* The Glance 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

@ -134,6 +134,11 @@
# (optional) CA certificate file to use to verify connecting clients
# Defaults to false, not set
#
# [*mysql_module*]
# (optional) Mysql puppet module version to use
# Tested versions include 0.9 and 2.2
# Defaults to '0.9'.
#
class glance::api(
$keystone_password,
$verbose = false,
@ -165,7 +170,8 @@ class glance::api(
$purge_config = false,
$cert_file = false,
$key_file = false,
$ca_file = false
$ca_file = false,
$mysql_module = '0.9',
) inherits glance {
require keystone::python
@ -192,7 +198,12 @@ class glance::api(
}
if($sql_connection =~ /mysql:\/\/\S+:\S+@\S+\/\S+/) {
require 'mysql::python'
if ($mysql_module >= 2.2) {
require 'mysql::bindings'
require 'mysql::bindings::python'
} else {
require 'mysql::python'
}
} elsif($sql_connection =~ /postgresql:\/\/\S+:\S+@\S+\/\S+/) {
} elsif($sql_connection =~ /sqlite:\/\//) {

View File

@ -2,6 +2,11 @@
# I should change this to mysql
# for consistency
#
# [*mysql_module*]
# (optional) The mysql puppet module version to use. Tested
# versions include 0.9 and 2.2
# Default to '0.9'
#
class glance::db::mysql(
$password,
$dbname = 'glance',
@ -9,20 +14,38 @@ class glance::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['glance::db::mysql'] -> Exec<| title == 'glance-manage db_sync' |>
Database[$dbname] ~> Exec<| title == 'glance-manage db_sync' |>
require mysql::python
if ($mysql_module >= 2.2) {
require mysql::bindings
require mysql::bindings::python
Mysql_database[$dbname] ~> Exec<| title == 'glance-manage db_sync' |>
mysql::db { $dbname:
user => $user,
password => $password,
host => $host,
charset => $charset,
require => Class['mysql::config'],
mysql::db { $dbname:
user => $user,
password => $password,
host => $host,
charset => $charset,
collate => $collate,
require => Class['mysql::server'],
}
} else {
require mysql::python
Database[$dbname] ~> Exec<| title == 'glance-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
@ -37,9 +60,10 @@ class glance::db::mysql(
if $real_allowed_hosts {
# TODO this class should be in the mysql namespace
glance::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 glance mysql DB
#
define glance::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 glance::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),
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

@ -95,6 +95,11 @@
# (optional) CA certificate file to use to verify connecting clients
# Defaults to false, not set
#
# [*mysql_module*]
# (optional) The version of puppet-mysql to use. Tested versions
# include 0.9 and 2.2
# Defaults to '0.9'
#
class glance::registry(
$keystone_password,
$verbose = false,
@ -120,7 +125,8 @@ class glance::registry(
$purge_config = false,
$cert_file = false,
$key_file = false,
$ca_file = false
$ca_file = false,
$mysql_module = '0.9',
) inherits glance {
require keystone::python
@ -141,7 +147,11 @@ class glance::registry(
}
if($sql_connection =~ /mysql:\/\/\S+:\S+@\S+\/\S+/) {
require mysql::python
if ($mysql_module >= 2.2) {
require mysql::bindings::python
} else {
require mysql::python
}
} elsif($sql_connection =~ /postgresql:\/\/\S+:\S+@\S+\/\S+/) {
} elsif($sql_connection =~ /sqlite:\/\//) {

View File

@ -33,7 +33,8 @@ describe 'glance::api' do
:sql_idle_timeout => '3600',
:sql_connection => 'sqlite:///var/lib/glance/glance.sqlite',
:show_image_direct_url => false,
:purge_config => false
:purge_config => false,
:mysql_module => '0.9'
}
end

View File

@ -14,11 +14,12 @@ describe 'glance::db::mysql' do
describe "with default params" do
let :params do
{
:password => 'glancepass1'
:password => 'glancepass1',
:mysql_module => '0.9'
}
end
it { should contain_class('mysql::python') }
it { should contain_class('mysql::python') }
it { should contain_mysql__db('glance').with(
:password => 'glancepass1',

View File

@ -26,7 +26,8 @@ describe 'glance::registry' do
:keystone_tenant => 'services',
:keystone_user => 'glance',
:keystone_password => 'ChangeMe',
:purge_config => false
:purge_config => false,
:mysql_module => '0.9'
}
end