From 15ab1a6e27f27bd973971efd71d3c8c47ad9a4cf Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Thu, 31 Jul 2014 11:11:26 -0700 Subject: [PATCH] Migrate mysql backend to use openstacklib::db::mysql Implements: blueprint commmon-openstack-database-resource Change-Id: Iaa4f1cfb6a26795112117e2d3230b4a11250e2df --- .fixtures.yml | 1 + Modulefile | 2 +- manifests/db.pp | 16 +++---- manifests/db/mysql.pp | 57 +++++++----------------- manifests/db/mysql/host_access.pp | 47 ------------------- spec/classes/ceilometer_db_mysql_spec.rb | 32 +++---------- 6 files changed, 30 insertions(+), 125 deletions(-) delete mode 100644 manifests/db/mysql/host_access.pp diff --git a/.fixtures.yml b/.fixtures.yml index 08b2b2d..cf0f5e5 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -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: 'ceilometer': "#{source_dir}" diff --git a/Modulefile b/Modulefile index 53dbc1d..aa446a0 100644 --- a/Modulefile +++ b/Modulefile @@ -9,5 +9,5 @@ source 'https://github.com/stackforge/puppet-ceilometer' dependency 'puppetlabs/inifile', '>=1.0.0 <2.0.0' dependency 'puppetlabs/keystone', '>=4.0.0 <5.0.0' -dependency 'puppetlabs/mysql', '>=0.9.0 <3.0.0' dependency 'puppetlabs/stdlib', '>= 3.2.0' +dependency 'stackforge/openstacklib', '>=5.0.0' diff --git a/manifests/db.pp b/manifests/db.pp index 0f17bf8..3bed0c1 100644 --- a/manifests/db.pp +++ b/manifests/db.pp @@ -10,18 +10,20 @@ # enable dbsync. # # [*mysql_module*] -# (optional) Mysql puppet module version to use. Tested versions -# are 0.9 and 2.2 -# Defaults to '2.2' +# (optional) Deprecated. Does nothing. # class ceilometer::db ( $database_connection = 'mysql://ceilometer:ceilometer@localhost/ceilometer', $sync_db = true, - $mysql_module = '2.2', + $mysql_module = undef, ) { include ceilometer::params + if $mysql_module { + warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.') + } + Package<| title == 'ceilometer-common' |> -> Class['ceilometer::db'] validate_re($database_connection, @@ -31,11 +33,7 @@ class ceilometer::db ( /^mysql:\/\//: { $backend_package = false - if ($mysql_module >= 2.2) { - include mysql::bindings::python - } else { - include mysql::python - } + include mysql::bindings::python } /^postgres:\/\//: { $backend_package = $::ceilometer::params::psycopg_package_name diff --git a/manifests/db/mysql.pp b/manifests/db/mysql.pp index 728ea96..6fd47c4 100644 --- a/manifests/db/mysql.pp +++ b/manifests/db/mysql.pp @@ -27,59 +27,34 @@ # the database collation. Optional. Defaults to 'utf8_unicode_ci' # # [*mysql_module*] -# (optional) Mysql module version to use. Tested versions -# are 0.9 and 2.2 -# Defaults to '2.2' +# (optional) Deprecated. Does nothing. # class ceilometer::db::mysql( $password = false, $dbname = 'ceilometer', $user = 'ceilometer', - $host = 'localhost', + $host = '127.0.0.1', $allowed_hosts = undef, $charset = 'utf8', $collate = 'utf8_unicode_ci', - $mysql_module = '2.2', + $mysql_module = undef, ) { - validate_string($password) - - Class['mysql::server'] -> Class['ceilometer::db::mysql'] - Class['ceilometer::db::mysql'] -> Exec<| title == 'ceilometer-dbsync' |> - Mysql::Db[$dbname] ~> Exec<| title == 'ceilometer-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'], - } + if $mysql_module { + warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.') } - # 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 - } + validate_string($password) - if $real_allowed_hosts { - ceilometer::db::mysql::host_access { $real_allowed_hosts: - user => $user, - password => $password, - database => $dbname, - mysql_module => $mysql_module, - } + ::openstacklib::db::mysql { 'ceilometer': + user => $user, + password_hash => mysql_password($password), + dbname => $dbname, + host => $host, + charset => $charset, + collate => $collate, + allowed_hosts => $allowed_hosts, } + + ::Openstacklib::Db::Mysql['ceilometer'] ~> Exec<| title == 'ceilometer-dbsync' |> } diff --git a/manifests/db/mysql/host_access.pp b/manifests/db/mysql/host_access.pp deleted file mode 100644 index e91a551..0000000 --- a/manifests/db/mysql/host_access.pp +++ /dev/null @@ -1,47 +0,0 @@ -# Allow a user to access the ceilometer database -# -# == Namevar -# The host to allow -# -# == Parameters -# [*user*] -# username to allow -# -# [*password*] -# user password -# -# [*database*] -# the database name -# -define ceilometer::db::mysql::host_access ($user, $password, $database, $mysql_module='2.2') { - # New types for mysql module v2.0+ - 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', - provider => 'mysql', - table => "${database}.*", - user => "${user}@${name}", - require => Mysql_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/spec/classes/ceilometer_db_mysql_spec.rb b/spec/classes/ceilometer_db_mysql_spec.rb index 30d97c6..5d32aba 100644 --- a/spec/classes/ceilometer_db_mysql_spec.rb +++ b/spec/classes/ceilometer_db_mysql_spec.rb @@ -13,7 +13,6 @@ describe 'ceilometer::db::mysql' do :host => 'localhost', :charset => 'utf8', :collate => 'utf8_unicode_ci', - :mysql_module => '0.9', } end @@ -25,12 +24,11 @@ describe 'ceilometer::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] ) end end @@ -62,16 +60,6 @@ describe 'ceilometer::db::mysql' do } end - it {should_not contain_ceilometer__db__mysql__host_access("localhost").with( - :user => 'ceilometer', - :password => 'ceilometerpass', - :database => 'ceilometer' - )} - it {should contain_ceilometer__db__mysql__host_access("%").with( - :user => 'ceilometer', - :password => 'ceilometerpass', - :database => 'ceilometer' - )} end describe "overriding allowed_hosts param to string" do @@ -85,11 +73,6 @@ describe 'ceilometer::db::mysql' do } end - it {should contain_ceilometer__db__mysql__host_access("192.168.1.1").with( - :user => 'ceilometer', - :password => 'ceilometerpass2', - :database => 'ceilometer' - )} end describe "overriding allowed_hosts param equals to host param " do @@ -103,10 +86,5 @@ describe 'ceilometer::db::mysql' do } end - it {should_not contain_ceilometer__db__mysql__host_access("localhost").with( - :user => 'ceilometer', - :password => 'ceilometerpass2', - :database => 'ceilometer' - )} end end -- 2.45.2