Use new provider names in manifests.

Modify manifests and tests to handle the renamed providers.
This commit is contained in:
Ashley Penney 2013-08-17 20:54:02 -04:00
parent 16770faa29
commit 369c83126b
9 changed files with 53 additions and 40 deletions

View file

@ -110,22 +110,24 @@ Installs a mysql backup script, cronjob, and privileged backup user.
MySQL provider supports puppet resources command:
$ puppet resource database
database { 'information_schema':
mysql_database { 'information_schema':
ensure => 'present',
charset => 'utf8',
collate => 'utf8_swedish_ci',
}
database { 'mysql':
mysql_database { 'mysql':
ensure => 'present',
charset => 'latin1',
collate => 'latin1_swedish_ci',
}
The custom resources can be used in any other manifests:
database { 'mydb':
mysql_database { 'mydb':
charset => 'latin1',
}
database_user { 'bob@localhost':
mysql_user { 'bob@localhost':
password_hash => mysql_password('foo')
}
@ -137,6 +139,6 @@ The custom resources can be used in any other manifests:
A resource default can be specified to handle dependency:
Database {
Mysql_database {
require => Class['mysql::server'],
}

View file

@ -39,7 +39,7 @@ class mysql::backup (
$ensure = 'present'
) {
database_user { "${backupuser}@localhost":
mysql_user { "${backupuser}@localhost":
ensure => $ensure,
password_hash => mysql_password($backuppassword),
provider => 'mysql',

View file

@ -11,6 +11,7 @@
# [*title*] - mysql database name.
# [*user*] - username to create and grant access.
# [*password*] - user's password.
# [*collate*] - database charset.
# [*charset*] - database charset.
# [*host*] - host for assigning privileges to user.
# [*grant*] - array of privileges to grant user.
@ -37,6 +38,7 @@ define mysql::db (
$user,
$password,
$charset = 'utf8',
$collate = 'utf8_general_ci',
$host = 'localhost',
$grant = 'all',
$sql = '',
@ -47,12 +49,13 @@ define mysql::db (
validate_re($ensure, '^(present|absent)$',
"${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
database { $name:
mysql_database { $name:
ensure => $ensure,
charset => $charset,
collate => $collate,
provider => 'mysql',
require => [Class['mysql::server'],Package['mysql_client']],
before => Database_user["${user}@${host}"],
before => Mysql_user["${user}@${host}"],
}
$user_resource = {
@ -60,13 +63,13 @@ define mysql::db (
password_hash => mysql_password($password),
provider => 'mysql'
}
ensure_resource('database_user', "${user}@${host}", $user_resource)
ensure_resource('mysql_user', "${user}@${host}", $user_resource)
if $ensure == 'present' {
database_grant { "${user}@${host}/${name}":
privileges => $grant,
provider => 'mysql',
require => Database_user["${user}@${host}"],
require => Mysql_user["${user}@${host}"],
}
$refresh = ! $enforce_sql
@ -78,7 +81,7 @@ define mysql::db (
environment => "HOME=${root_home}",
refreshonly => $refresh,
require => Database_grant["${user}@${host}/${name}"],
subscribe => Database[$name],
subscribe => Mysql_database[$name],
}
}
}

View file

@ -1,7 +1,7 @@
# Some installations have some default users which are not required.
# We remove them here. You can subclass this class to overwrite this behavior.
class mysql::server::account_security {
database_user {
mysql_user {
[ "root@${::fqdn}",
'root@127.0.0.1',
'root@::1',
@ -12,12 +12,12 @@ class mysql::server::account_security {
require => Class['mysql::config'],
}
if ($::fqdn != $::hostname) {
database_user { ["root@${::hostname}", "@${::hostname}"]:
mysql_user { ["root@${::hostname}", "@${::hostname}"]:
ensure => 'absent',
require => Class['mysql::config'],
}
}
database { 'test':
mysql_database { 'test':
ensure => 'absent',
require => Class['mysql::config'],
}

View file

@ -8,7 +8,7 @@ class mysql::server::monitor (
Class['mysql::server'] -> Class['mysql::server::monitor']
database_user{ "${mysql_monitor_username}@${mysql_monitor_hostname}":
mysql_user{ "${mysql_monitor_username}@${mysql_monitor_hostname}":
ensure => present,
password_hash => mysql_password($mysql_monitor_password),
}

View file

@ -13,7 +13,7 @@ describe 'mysql::backup' do
context 'standard conditions' do
let(:params) { default_params }
it { should contain_database_user('testuser@localhost')}
it { should contain_mysql_user('testuser@localhost')}
it { should contain_database_grant('testuser@localhost').with(
:privileges => %w(Select_priv Reload_priv Lock_tables_priv Show_view_priv)

View file

@ -9,33 +9,33 @@ describe 'mysql::server::account_security' do
}
end
it 'should remove Database_User[root@myhost.mydomain]' do
should contain_database_user('root@myhost.mydomain').with_ensure('absent')
it 'should remove Mysql_User[root@myhost.mydomain]' do
should contain_mysql_user('root@myhost.mydomain').with_ensure('absent')
end
it 'should remove Database_User[root@myhost]' do
should contain_database_user('root@myhost').with_ensure('absent')
it 'should remove Mysql_User[root@myhost]' do
should contain_mysql_user('root@myhost').with_ensure('absent')
end
it 'should remove Database_User[root@127.0.0.1]' do
should contain_database_user('root@127.0.0.1').with_ensure('absent')
it 'should remove Mysql_User[root@127.0.0.1]' do
should contain_mysql_user('root@127.0.0.1').with_ensure('absent')
end
it 'should remove Database_User[root@::1]' do
should contain_database_user('root@::1').with_ensure('absent')
it 'should remove Mysql_User[root@::1]' do
should contain_mysql_user('root@::1').with_ensure('absent')
end
it 'should remove Database_User[@myhost.mydomain]' do
should contain_database_user('@myhost.mydomain').with_ensure('absent')
it 'should remove Mysql_User[@myhost.mydomain]' do
should contain_mysql_user('@myhost.mydomain').with_ensure('absent')
end
it 'should remove Database_User[@myhost]' do
should contain_database_user('@myhost').with_ensure('absent')
it 'should remove Mysql_User[@myhost]' do
should contain_mysql_user('@myhost').with_ensure('absent')
end
it 'should remove Database_User[@localhost]' do
should contain_database_user('@localhost').with_ensure('absent')
it 'should remove Mysql_User[@localhost]' do
should contain_mysql_user('@localhost').with_ensure('absent')
end
it 'should remove Database_User[@%]' do
should contain_database_user('@%').with_ensure('absent')
it 'should remove Mysql_User[@%]' do
should contain_mysql_user('@%').with_ensure('absent')
end
it 'should remove Database[test]' do
should contain_database('test').with_ensure('absent')
it 'should remove Mysql_database[test]' do
should contain_mysql_database('test').with_ensure('absent')
end
end

View file

@ -14,5 +14,5 @@ describe 'mysql::server::monitor' do
}
end
it { should contain_database_user('monitoruser@monitorhost')}
it { should contain_mysql_user('monitoruser@monitorhost')}
end

View file

@ -16,12 +16,12 @@ describe 'mysql::db', :type => :define do
end
it 'should not notify the import sql exec if no sql script was provided' do
should contain_database('test_db').without_notify
should contain_mysql_database('test_db').without_notify
end
it 'should subscribe to database if sql script is given' do
params.merge!({'sql' => 'test_sql'})
should contain_exec('test_db-import').with_subscribe('Database[test_db]')
should contain_exec('test_db-import').with_subscribe('Mysql_database[test_db]')
end
it 'should only import sql script on creation if not enforcing' do
@ -33,10 +33,18 @@ describe 'mysql::db', :type => :define do
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')
should contain_mysql_database('test_db').with_ensure('absent')
should contain_mysql_user('testuser@localhost').with_ensure('absent')
end
it 'should create with an appropriate collate and charset' do
params.merge!({'charset' => 'utf8', 'collate' => 'utf8_danish_ci'})
should contain_mysql_database('test_db').with({
'charset' => 'utf8',
'collate' => 'utf8_danish_ci',
})
end
end