Skip to content

Added an option to specify db status. #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
fixtures:
repositories:
"stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib"
symlinks:
"mysql": "#{source_dir}"
1 change: 1 addition & 0 deletions Modulefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ license 'Apache 2.0'
summary 'Mysql module'
description 'Mysql module'
project_page 'http://github.com/puppetlabs/puppetlabs-mysql'
dependency 'puppetlabs/stdlib', '>= 2.2.1'
40 changes: 23 additions & 17 deletions manifests/db.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# [*grant*] - array of privileges to grant user.
# [*enforce_sql*] - whether to enforce or conditionally run sql on creation.
# [*sql*] - sql statement to run.
# [*ensure*] - specifies if a database is present or absent.
#
# Actions:
#
Expand All @@ -39,39 +40,44 @@
$host = 'localhost',
$grant = 'all',
$sql = '',
$enforce_sql = false
$enforce_sql = false,
$ensure = 'present'
) {

validate_re($ensure, [ '^present$', '^absent$' ],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as an FYI, this line broke this module on 2.6.x. I has been fixed in pull request #105.

"${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")

database { $name:
ensure => present,
ensure => $ensure,
charset => $charset,
provider => 'mysql',
require => Class['mysql::server'],
}

database_user { "${user}@${host}":
ensure => present,
ensure => $ensure,
password_hash => mysql_password($password),
provider => 'mysql',
require => Database[$name],
}

database_grant { "${user}@${host}/${name}":
privileges => $grant,
provider => 'mysql',
require => Database_user["${user}@${host}"],
}
if $ensure == 'present' {
database_grant { "${user}@${host}/${name}":
privileges => $grant,
provider => 'mysql',
require => Database_user["${user}@${host}"],
}

$refresh = ! $enforce_sql
$refresh = ! $enforce_sql

if $sql {
exec{ "${name}-import":
command => "/usr/bin/mysql ${name} < ${sql}",
logoutput => true,
refreshonly => $refresh,
require => Database_grant["${user}@${host}/${name}"],
subscribe => Database[$name],
if $sql {
exec{ "${name}-import":
command => "/usr/bin/mysql ${name} < ${sql}",
logoutput => true,
refreshonly => $refresh,
require => Database_grant["${user}@${host}/${name}"],
subscribe => Database[$name],
}
}
}

}
12 changes: 12 additions & 0 deletions spec/defines/mysql_db_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
}
}

it 'should report an error when ensure is not present or absent' do
params.merge!({'ensure' => 'invalid_val'})
expect { subject }.to raise_error(Puppet::Error,
/invalid_val is not supported for ensure\. Allowed values are 'present' and 'absent'\./)
end

it 'should not notify the import sql exec if no sql script was provided' do
should contain_database('test_db').without_notify
end
Expand All @@ -27,4 +33,10 @@
params.merge!({'sql' => 'test_sql', 'enforce_sql' => true})
should contain_exec('test_db-import').with_refreshonly(false)
end

it 'should not create database and database user' do
params.merge!({'ensure' => 'absent', 'host' => 'localhost'})
should contain_database('test_db').with_ensure('absent')
should contain_database_user('testuser@localhost').with_ensure('absent')
end
end