From a95a9435dcb5f4b24b2e53213fe05b5466b46d6a Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Fri, 11 Jul 2014 10:40:32 -0700 Subject: [PATCH] Migrate mysql backend to use openstacklib::db::mysql Implements: blueprint commmon-openstack-database-resource Change-Id: I71e1bf084139524e41276e5cbd7f5be02d07e825 --- .fixtures.yml | 1 + Modulefile | 2 +- README.md | 2 +- manifests/db/mysql.pp | 56 +++++++++--------------------- manifests/db/mysql/host_access.pp | 43 ----------------------- manifests/init.pp | 18 +++++----- spec/classes/heat_db_mysql_spec.rb | 33 ++++-------------- spec/classes/heat_init_spec.rb | 1 - 8 files changed, 33 insertions(+), 123 deletions(-) delete mode 100644 manifests/db/mysql/host_access.pp diff --git a/.fixtures.yml b/.fixtures.yml index e0210534..40e23e9e 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: "heat": "#{source_dir}" diff --git a/Modulefile b/Modulefile index 37800583..89184d9e 100644 --- a/Modulefile +++ b/Modulefile @@ -8,6 +8,6 @@ project_page 'https://launchpad.net/puppet-heat' source 'https://github.com/stackforge/puppet-heat' dependency 'puppetlabs/inifile', '>= 1.0.0 <2.0.0' -dependency 'puppetlabs/mysql', '>=0.9.0 <3.0.0' dependency 'puppetlabs/keystone', '>=4.0.0 <5.0.0' dependency 'puppetlabs/stdlib', '>= 3.2.0' +dependency 'stackforge/openstacklib', '>=5.0.0' diff --git a/README.md b/README.md index ed29043c..5e2d02a6 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ extra functionality through types and providers. 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. +None Development ----------- diff --git a/manifests/db/mysql.pp b/manifests/db/mysql.pp index 3bdcfc98..f477b593 100644 --- a/manifests/db/mysql.pp +++ b/manifests/db/mysql.pp @@ -29,58 +29,34 @@ # Defaults to 'utf8_unicode_ci' # # [*mysql_module*] -# The version of the mysql puppet module to use. -# Tested versions include 0.9 and 2.2 -# Defaults to '2.2'. +# (optional) Deprecated. Does nothing. # class heat::db::mysql( $password = false, $dbname = 'heat', $user = 'heat', - $host = 'localhost', + $host = '127.0.0.1', $allowed_hosts = undef, $charset = 'utf8', $collate = 'utf8_unicode_ci', - $mysql_module = '2.2' + $mysql_module = undef ) { + if $mysql_module { + warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.') + } + validate_string($password) - Class['heat::db::mysql'] -> Exec<| title == 'heat-dbsync' |> - Mysql::Db[$dbname] ~> Exec<| title == 'heat-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'], - } + ::openstacklib::db::mysql { 'heat': + user => $user, + password_hash => mysql_password($password), + dbname => $dbname, + host => $host, + charset => $charset, + collate => $collate, + allowed_hosts => $allowed_hosts, } - # 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 - } - - if $real_allowed_hosts { - heat::db::mysql::host_access { $real_allowed_hosts: - user => $user, - password => $password, - database => $dbname, - mysql_module => $mysql_module, - } - } + ::Openstacklib::Db::Mysql['heat'] ~> Exec<| title == 'heat-dbsync' |> } diff --git a/manifests/db/mysql/host_access.pp b/manifests/db/mysql/host_access.pp deleted file mode 100644 index 66b0ba85..00000000 --- a/manifests/db/mysql/host_access.pp +++ /dev/null @@ -1,43 +0,0 @@ -# Allow a user to access the heat database -# -# == Namevar -# The host to allow -# -# == Parameters -# [*user*] -# username to allow -# -# [*password*] -# user password -# -# [*database*] -# the database name -# -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], - } - - 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 3e8e1c98..a48218ea 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -89,9 +89,7 @@ # Defaults to LOG_USER # # [*mysql_module*] -# (optional) The mysql puppet module version. -# Tested versions include 0.9 and 2.2 -# Defaults to '2.2' +# (optional) Deprecated. Does nothing. # class heat( $auth_uri = false, @@ -136,7 +134,8 @@ class heat( $database_idle_timeout = 3600, $use_syslog = false, $log_facility = 'LOG_USER', - $mysql_module = '2.2', + #Deprecated parameters + $mysql_module = undef, ) { include heat::params @@ -153,6 +152,9 @@ class heat( if ($kombu_ssl_certfile and !$kombu_ssl_keyfile) or ($kombu_ssl_keyfile and !$kombu_ssl_certfile) { fail('The kombu_ssl_certfile and kombu_ssl_keyfile parameters must be used together') } + if $mysql_module { + warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.') + } File { require => Package['heat-common'], @@ -317,12 +319,8 @@ class heat( case $sql_connection { /^mysql:\/\//: { $backend_package = false - if ($mysql_module >= 2.2) { - require mysql::bindings - require mysql::bindings::python - } else { - include mysql::python - } + require mysql::bindings + require mysql::bindings::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 2d4febb7..1f2803a3 100644 --- a/spec/classes/heat_db_mysql_spec.rb +++ b/spec/classes/heat_db_mysql_spec.rb @@ -11,7 +11,6 @@ describe 'heat::db::mysql' do :user => 'heat', :host => 'localhost', :charset => 'utf8', - :mysql_module => '0.9' } end @@ -23,12 +22,12 @@ describe 'heat::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], + :require => 'Class[Mysql::Config]' ) end end @@ -41,16 +40,6 @@ describe 'heat::db::mysql' do } end - it {should_not contain_heat__db__mysql__host_access("localhost").with( - :user => 'heat', - :password => 'heatpass', - :database => 'heat' - )} - it {should contain_heat__db__mysql__host_access("%").with( - :user => 'heat', - :password => 'heatpass', - :database => 'heat' - )} end describe "overriding allowed_hosts param to string" do @@ -61,11 +50,6 @@ describe 'heat::db::mysql' do } end - it {should contain_heat__db__mysql__host_access("192.168.1.1").with( - :user => 'heat', - :password => 'heatpass2', - :database => 'heat' - )} end describe "overriding allowed_hosts param equals to host param " do @@ -76,10 +60,5 @@ describe 'heat::db::mysql' do } end - it {should_not contain_heat__db__mysql__host_access("localhost").with( - :user => 'heat', - :password => 'heatpass2', - :database => 'heat' - )} end end diff --git a/spec/classes/heat_init_spec.rb b/spec/classes/heat_init_spec.rb index 0c8add72..82daadf4 100644 --- a/spec/classes/heat_init_spec.rb +++ b/spec/classes/heat_init_spec.rb @@ -17,7 +17,6 @@ describe 'heat' do :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', - :mysql_module => '2.2' } end