From 074675b1ac53abdf493d50263676a00e89612ab1 Mon Sep 17 00:00:00 2001 From: Michael Chapman Date: Tue, 18 Feb 2014 13:16:15 +1100 Subject: [PATCH] Add support for puppetlabs-mysql 2.2 Puppetlabs-mysql has been rewritten to be much cleaner. This patch adds a new parameter for the heat mysql and init classes allowing users to use the new version. Previous behavior will continue as normal when using the old version (0.9) Change-Id: I4d268d793740c31493acd5999dd3f8501cc1d281 --- README.md | 2 ++ manifests/db/mysql.pp | 42 +++++++++++++++++++++++------- manifests/db/mysql/host_access.pp | 37 +++++++++++++++++--------- manifests/init.pp | 13 ++++++++- spec/classes/heat_db_mysql_spec.rb | 11 ++++---- spec/classes/heat_init_spec.rb | 3 ++- 6 files changed, 80 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 456d3c1b..5237845b 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,8 @@ puppet-heat is a combination of Puppet manifest and ruby code to delivery config 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. + Development ----------- diff --git a/manifests/db/mysql.pp b/manifests/db/mysql.pp index 30cc8328..9042112f 100644 --- a/manifests/db/mysql.pp +++ b/manifests/db/mysql.pp @@ -23,6 +23,16 @@ # [*charset*] # the database charset. Optional. Defaults to 'latin1' # +# [*collate*] +# the database collate. Optional. Only used with mysql modules +# >= 2.2 +# Defaults to 'latin1_swedish_ci' +# +# [*mysql_module*] +# The version of the mysql puppet module to use. +# Tested versions include 0.9 and 2.2 +# Defaults to '0.9'. +# class heat::db::mysql( $password = false, $dbname = 'heat', @@ -30,6 +40,8 @@ class heat::db::mysql( $host = 'localhost', $allowed_hosts = undef, $charset = 'latin1', + $collate = 'latin1_swedish_ci', + $mysql_module = '0.9' ) { validate_string($password) @@ -37,12 +49,23 @@ class heat::db::mysql( Class['heat::db::mysql'] -> Exec<| title == 'heat-manage db_sync' |> Mysql::Db[$dbname] ~> Exec<| title == 'heat-manage db_sync' |> - mysql::db { $dbname: - user => $user, - password => $password, - host => $host, - charset => $charset, - require => Class['mysql::config'], + if ($mysql_module >= 2.2) { + mysql::db { $dbname: + user => $user, + password => $password, + host => $host, + charset => $charset, + collate => $collate, + require => Service['mysql'], + } + } else { + mysql::db { $dbname: + user => $user, + password => $password, + host => $host, + charset => $charset, + require => Class['mysql::config'], + } } # Check allowed_hosts to avoid duplicate resource declarations @@ -54,9 +77,10 @@ class heat::db::mysql( if $real_allowed_hosts { heat::db::mysql::host_access { $real_allowed_hosts: - user => $user, - password => $password, - database => $dbname, + user => $user, + password => $password, + database => $dbname, + mysql_module => $mysql_module, } } } diff --git a/manifests/db/mysql/host_access.pp b/manifests/db/mysql/host_access.pp index c59414f1..66b0ba85 100644 --- a/manifests/db/mysql/host_access.pp +++ b/manifests/db/mysql/host_access.pp @@ -13,18 +13,31 @@ # [*database*] # the database name # -define heat::db::mysql::host_access ($user, $password, $database) { +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], + } - 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}"] + 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}"] + } } } diff --git a/manifests/init.pp b/manifests/init.pp index f1bf286d..1e121ca9 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -69,6 +69,11 @@ # (optional) Syslog facility to receive log lines # Defaults to LOG_USER # +# [*mysql_module*] +# (optional) The mysql puppet module version. +# Tested versions include 0.9 and 2.2 +# Defaults to '0.9' +# class heat( $auth_uri = false, $package_ensure = 'present', @@ -106,6 +111,7 @@ class heat( $database_idle_timeout = 3600, $use_syslog = false, $log_facility = 'LOG_USER', + $mysql_module = '0.9', ) { include heat::params @@ -234,7 +240,12 @@ class heat( case $sql_connection { /^mysql:\/\//: { $backend_package = false - include mysql::python + if ($mysql_module >= 2.2) { + require mysql::bindings + require mysql::bindings::python + } else { + include mysql::python + } } /^postgresql:\/\//: { $backend_package = 'python-psycopg2' diff --git a/spec/classes/heat_db_mysql_spec.rb b/spec/classes/heat_db_mysql_spec.rb index 560b2114..289d1ab4 100644 --- a/spec/classes/heat_db_mysql_spec.rb +++ b/spec/classes/heat_db_mysql_spec.rb @@ -6,11 +6,12 @@ describe 'heat::db::mysql' do end let :params do - { :password => 's3cr3t', - :dbname => 'heat', - :user => 'heat', - :host => 'localhost', - :charset => 'latin1' + { :password => 's3cr3t', + :dbname => 'heat', + :user => 'heat', + :host => 'localhost', + :charset => 'latin1', + :mysql_module => '0.9' } end diff --git a/spec/classes/heat_init_spec.rb b/spec/classes/heat_init_spec.rb index a2b0467c..c9b1aaee 100644 --- a/spec/classes/heat_init_spec.rb +++ b/spec/classes/heat_init_spec.rb @@ -16,7 +16,8 @@ describe 'heat' do :sql_connection => 'mysql://user@host/database', :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' + :keystone_ec2_uri => 'http://127.0.0.1:5000/v2.0/ec2tokens', + :mysql_module => '0.9' } end