diff --git a/README.md b/README.md index 85a0769e..416c0e5e 100644 --- a/README.md +++ b/README.md @@ -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 ----------- diff --git a/manifests/api.pp b/manifests/api.pp index c480303a..846bc257 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -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:\/\//) { diff --git a/manifests/db/mysql.pp b/manifests/db/mysql.pp index c190912e..a4748efc 100644 --- a/manifests/db/mysql.pp +++ b/manifests/db/mysql.pp @@ -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, } } } diff --git a/manifests/db/mysql/host_access.pp b/manifests/db/mysql/host_access.pp index 6c18a041..2bbcfe70 100644 --- a/manifests/db/mysql/host_access.pp +++ b/manifests/db/mysql/host_access.pp @@ -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}"] + } } } diff --git a/manifests/registry.pp b/manifests/registry.pp index fd6b3d64..bb86a8ee 100644 --- a/manifests/registry.pp +++ b/manifests/registry.pp @@ -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:\/\//) { diff --git a/spec/classes/glance_api_spec.rb b/spec/classes/glance_api_spec.rb index 7c91dd1a..1fb7575a 100644 --- a/spec/classes/glance_api_spec.rb +++ b/spec/classes/glance_api_spec.rb @@ -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 diff --git a/spec/classes/glance_db_mysql_spec.rb b/spec/classes/glance_db_mysql_spec.rb index 4393d6d7..e8914368 100644 --- a/spec/classes/glance_db_mysql_spec.rb +++ b/spec/classes/glance_db_mysql_spec.rb @@ -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', diff --git a/spec/classes/glance_registry_spec.rb b/spec/classes/glance_registry_spec.rb index 1cd30745..4bc1bc07 100644 --- a/spec/classes/glance_registry_spec.rb +++ b/spec/classes/glance_registry_spec.rb @@ -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