mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
Upgrade php from 5.4.* to 5.5.*
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'mysql::server::account_security class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
describe 'running puppet code' do
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': remove_default_accounts => true }
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
|
||||
end
|
||||
|
||||
describe 'accounts' do
|
||||
it 'should delete accounts' do
|
||||
shell("mysql -e 'show grants for root@127.0.0.1;'", :acceptable_exit_codes => 1)
|
||||
end
|
||||
|
||||
it 'should delete databases' do
|
||||
shell("mysql -e 'show databases;' |grep test", :acceptable_exit_codes => 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,64 @@
|
||||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'mysql::server::backup class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
context 'should work with no errors' do
|
||||
it 'when configuring mysql backups' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': root_password => 'password' }
|
||||
mysql::db { 'backup1':
|
||||
user => 'backup',
|
||||
password => 'secret',
|
||||
}
|
||||
|
||||
class { 'mysql::server::backup':
|
||||
backupuser => 'myuser',
|
||||
backuppassword => 'mypassword',
|
||||
backupdir => '/tmp/backups',
|
||||
backupcompress => true,
|
||||
postscript => [
|
||||
'rm -rf /var/tmp/mysqlbackups',
|
||||
'rm -f /var/tmp/mysqlbackups.done',
|
||||
'cp -r /tmp/backups /var/tmp/mysqlbackups',
|
||||
'touch /var/tmp/mysqlbackups.done',
|
||||
],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stderr).to eq("")
|
||||
end
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stderr).to eq("")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'mysqlbackup.sh' do
|
||||
it 'should run mysqlbackup.sh with no errors' do
|
||||
shell("/usr/local/sbin/mysqlbackup.sh") do |r|
|
||||
expect(r.stderr).to eq("")
|
||||
end
|
||||
end
|
||||
|
||||
it 'should dump all databases to single file' do
|
||||
shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r|
|
||||
expect(r.stdout).to match(/1/)
|
||||
expect(r.exit_code).to be_zero
|
||||
end
|
||||
end
|
||||
|
||||
context 'should create one file per database per run' do
|
||||
it 'executes mysqlbackup.sh a second time' do
|
||||
shell('sleep 1')
|
||||
shell('/usr/local/sbin/mysqlbackup.sh')
|
||||
end
|
||||
|
||||
it 'creates at least one backup tarball' do
|
||||
shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r|
|
||||
expect(r.stdout).to match(/2/)
|
||||
expect(r.exit_code).to be_zero
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,117 @@
|
||||
require 'spec_helper_acceptance'
|
||||
|
||||
osfamily = fact('osfamily')
|
||||
operatingsystem = fact('operatingsystem')
|
||||
|
||||
case osfamily
|
||||
when 'RedHat'
|
||||
java_package = 'mysql-connector-java'
|
||||
perl_package = 'perl-DBD-MySQL'
|
||||
php_package = 'php-mysql'
|
||||
python_package = 'MySQL-python'
|
||||
ruby_package = 'ruby-mysql'
|
||||
when 'Suse'
|
||||
java_package = 'mysql-connector-java'
|
||||
perl_package = 'perl-DBD-mysql'
|
||||
php_package = 'apache2-mod_php53'
|
||||
python_package = 'python-mysql'
|
||||
case operatingsystem
|
||||
when /OpenSuSE/
|
||||
ruby_package = 'rubygem-mysql'
|
||||
when /(SLES|SLED)/
|
||||
ruby_package = 'ruby-mysql'
|
||||
end
|
||||
when 'Debian'
|
||||
java_package = 'libmysql-java'
|
||||
perl_package = 'libdbd-mysql-perl'
|
||||
php_package = 'php5-mysql'
|
||||
python_package = 'python-mysqldb'
|
||||
ruby_package = 'libmysql-ruby'
|
||||
when 'FreeBSD'
|
||||
java_package = 'databases/mysql-connector-java'
|
||||
perl_package = 'p5-DBD-mysql'
|
||||
php_package = 'php5-mysql'
|
||||
python_package = 'databases/py-MySQLdb'
|
||||
ruby_package = 'ruby-mysql'
|
||||
else
|
||||
case operatingsystem
|
||||
when 'Amazon'
|
||||
java_package = 'mysql-connector-java'
|
||||
perl_package = 'perl-DBD-MySQL'
|
||||
php_package = 'php5-mysql'
|
||||
python_package = 'MySQL-python'
|
||||
ruby_package = 'ruby-mysql'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'mysql::bindings class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
|
||||
describe 'running puppet code' do
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::bindings': }
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
|
||||
end
|
||||
end
|
||||
|
||||
describe 'all parameters' do
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::bindings':
|
||||
java_enable => true,
|
||||
perl_enable => true,
|
||||
php_enable => true,
|
||||
python_enable => true,
|
||||
ruby_enable => true,
|
||||
java_package_ensure => present,
|
||||
perl_package_ensure => present,
|
||||
php_package_ensure => present,
|
||||
python_package_ensure => present,
|
||||
ruby_package_ensure => present,
|
||||
java_package_name => #{java_package},
|
||||
perl_package_name => #{perl_package},
|
||||
php_package_name => #{php_package},
|
||||
python_package_name => #{python_package},
|
||||
ruby_package_name => #{ruby_package},
|
||||
java_package_provider => undef,
|
||||
perl_package_provider => undef,
|
||||
php_package_provider => undef,
|
||||
python_package_provider => undef,
|
||||
ruby_package_provider => undef,
|
||||
}
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
|
||||
end
|
||||
|
||||
describe package(java_package) do
|
||||
it { should be_installed }
|
||||
end
|
||||
|
||||
describe package(perl_package) do
|
||||
it { should be_installed }
|
||||
end
|
||||
|
||||
# This package is not available out of the box and adding in other repos
|
||||
# is a bit much for the scope of this test.
|
||||
unless fact('osfamily') == 'RedHat'
|
||||
describe package(php_package) do
|
||||
it { should be_installed }
|
||||
end
|
||||
end
|
||||
|
||||
describe package(python_package) do
|
||||
it { should be_installed }
|
||||
end
|
||||
|
||||
describe package(ruby_package) do
|
||||
it { should be_installed }
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,49 @@
|
||||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'mysql::db define', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
describe 'creating a database' do
|
||||
# Using puppet_apply as a helper
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': root_password => 'password' }
|
||||
mysql::db { 'spec1':
|
||||
user => 'root1',
|
||||
password => 'password',
|
||||
}
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
expect(shell("mysql -e 'show databases;'|grep spec1").exit_code).to be_zero
|
||||
end
|
||||
end
|
||||
|
||||
describe 'creating a database with post-sql' do
|
||||
# Using puppet_apply as a helper
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': override_options => { 'root_password' => 'password' } }
|
||||
file { '/tmp/spec.sql':
|
||||
ensure => file,
|
||||
content => 'CREATE TABLE table1 (id int);',
|
||||
before => Mysql::Db['spec2'],
|
||||
}
|
||||
mysql::db { 'spec2':
|
||||
user => 'root1',
|
||||
password => 'password',
|
||||
sql => '/tmp/spec.sql',
|
||||
}
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
|
||||
it 'should have the table' do
|
||||
expect(shell("mysql -e 'show tables;' spec2|grep table1").exit_code).to be_zero
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,47 @@
|
||||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'config location', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
it 'creates the file elsewhere' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
config_file => '/etc/testmy.cnf',
|
||||
}
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
describe file('/etc/testmy.cnf') do
|
||||
it { should be_file }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'manage_config_file', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
it 'wont reset the location of my.cnf' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
config_file => '/etc/my.cnf',
|
||||
manage_config_file => false,
|
||||
service_manage => false,
|
||||
}
|
||||
EOS
|
||||
# Make sure this doesn't exist so we can test if puppet
|
||||
# readded it. It may not exist in the first place on
|
||||
# some platforms.
|
||||
shell('rm /etc/my.cnf', :acceptable_exit_codes => [0,1,2])
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
describe file('/etc/my.cnf') do
|
||||
it { should_not be_file }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'resets', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
it 'cleans up' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': }
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
shell('rm /etc/testmy.cnf')
|
||||
end
|
||||
end
|
@@ -0,0 +1,22 @@
|
||||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'mysql::server::monitor class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': root_password => 'password' }
|
||||
|
||||
class { 'mysql::server::monitor':
|
||||
mysql_monitor_username => 'monitoruser',
|
||||
mysql_monitor_password => 'monitorpass',
|
||||
mysql_monitor_hostname => 'localhost',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
|
||||
end
|
||||
|
||||
it 'should run mysqladmin ping with no errors' do
|
||||
expect(shell("mysqladmin -u monitoruser -pmonitorpass -h localhost ping").stdout).to match(/mysqld is alive/)
|
||||
end
|
||||
end
|
@@ -0,0 +1,71 @@
|
||||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'mysql::server::root_password class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
|
||||
describe 'reset' do
|
||||
it 'shuts down mysql' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': service_enabled => false }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'deletes the /root/.my.cnf password' do
|
||||
shell('rm -rf /root/.my.cnf')
|
||||
end
|
||||
|
||||
it 'deletes all databases' do
|
||||
case fact('osfamily')
|
||||
when 'RedHat', 'Suse'
|
||||
shell('rm -rf `grep datadir /etc/my.cnf | cut -d" " -f 3`/*')
|
||||
when 'Debian'
|
||||
shell('rm -rf `grep datadir /etc/mysql/my.cnf | cut -d" " -f 3`/*')
|
||||
shell('mysql_install_db')
|
||||
end
|
||||
end
|
||||
|
||||
it 'starts up mysql' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': service_enabled => true }
|
||||
EOS
|
||||
|
||||
puppet_apply(pp, :catch_failures => true)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when unset' do
|
||||
it 'should work' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': root_password => 'test' }
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when set' do
|
||||
it 'should work' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': root_password => 'new', old_root_password => 'test' }
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Debian relies on a debian-sys-maint@ account to do almost everything.
|
||||
# Without recreating this account we can't even stop the service in future
|
||||
# tests.
|
||||
if fact('osfamily') == 'Debian'
|
||||
describe 'readd debian user' do
|
||||
it 'readds the user' do
|
||||
shell("MYSQL_PASSWORD=`head -5 /etc/mysql/debian.cnf | grep password | cut -d' ' -f 3`; mysql -NBe \"GRANT ALL PRIVILEGES ON *.* to 'debian-sys-maint'@'localhost' IDENTIFIED BY '${MYSQL_PASSWORD}' WITH GRANT OPTION;\"")
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,281 @@
|
||||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'mysql class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
case fact('osfamily')
|
||||
when 'RedHat'
|
||||
package_name = 'mysql-server'
|
||||
service_name = 'mysqld'
|
||||
service_provider = 'undef'
|
||||
mycnf = '/etc/my.cnf'
|
||||
when 'Suse'
|
||||
case fact('operatingsystem')
|
||||
when 'OpenSuSE'
|
||||
package_name = 'mysql-community-server'
|
||||
service_name = 'mysql'
|
||||
service_provider = 'undef'
|
||||
mycnf = '/etc/my.cnf'
|
||||
when 'SLES'
|
||||
package_name = 'mysql'
|
||||
service_name = 'mysql'
|
||||
service_provider = 'undef'
|
||||
mycnf = '/etc/my.cnf'
|
||||
end
|
||||
when 'Debian'
|
||||
package_name = 'mysql-server'
|
||||
service_name = 'mysql'
|
||||
service_provider = 'undef'
|
||||
mycnf = '/etc/mysql/my.cnf'
|
||||
when 'Ubuntu'
|
||||
package_name = 'mysql-server'
|
||||
service_name = 'mysql'
|
||||
service_provider = 'upstart'
|
||||
mycnf = '/etc/mysql/my.cnf'
|
||||
end
|
||||
|
||||
describe 'running puppet code' do
|
||||
# Using puppet_apply as a helper
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': }
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
|
||||
end
|
||||
|
||||
describe package(package_name) do
|
||||
it { should be_installed }
|
||||
end
|
||||
|
||||
describe service(service_name) do
|
||||
it { should be_running }
|
||||
it { should be_enabled }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'mycnf' do
|
||||
it 'should contain sensible values' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': }
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
describe file(mycnf) do
|
||||
it { should contain 'key_buffer_size = 16M' }
|
||||
it { should contain 'max_binlog_size = 100M' }
|
||||
it { should contain 'query_cache_size = 16M' }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'my.cnf changes' do
|
||||
it 'sets values' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
override_options => { 'mysqld' =>
|
||||
{ 'key_buffer' => '32M',
|
||||
'max_binlog_size' => '200M',
|
||||
'query_cache_size' => '32M',
|
||||
}
|
||||
}
|
||||
}
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
describe file(mycnf) do
|
||||
it { should contain 'key_buffer = 32M' }
|
||||
it { should contain 'max_binlog_size = 200M' }
|
||||
it { should contain 'query_cache_size = 32M' }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'my.cnf should contain multiple instances of the same option' do
|
||||
it 'sets multiple values' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
override_options => { 'mysqld' =>
|
||||
{ 'replicate-do-db' => ['base1', 'base2', 'base3'], }
|
||||
}
|
||||
}
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
describe file(mycnf) do
|
||||
it { should contain 'replicate-do-db = base1' }
|
||||
it { should contain 'replicate-do-db = base2' }
|
||||
it { should contain 'replicate-do-db = base3' }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'package_ensure => absent' do
|
||||
it 'uninstalls mysql' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
service_enabled => false,
|
||||
package_ensure => absent,
|
||||
package_name => #{package_name}
|
||||
}
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
describe package(package_name) do
|
||||
it { should_not be_installed }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'package_ensure => present' do
|
||||
it 'installs mysql' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
package_ensure => present,
|
||||
package_name => #{package_name}
|
||||
}
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
describe package(package_name) do
|
||||
it { should be_installed }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'purge_conf_dir' do
|
||||
|
||||
it 'purges the conf dir' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
purge_conf_dir => true
|
||||
}
|
||||
EOS
|
||||
shell('touch /etc/mysql/conf.d/test.conf')
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
describe file('/etc/mysql/conf.d/test.conf') do
|
||||
it { should_not be_file }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'restart' do
|
||||
it 'restart => true' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
restart => true,
|
||||
override_options => { 'mysqldump' => { 'default-character-set' => 'UTF-8' } }
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.exit_code).to eq(2)
|
||||
expect(r.stdout).to match(/Scheduling refresh/)
|
||||
end
|
||||
end
|
||||
it 'restart => false' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
restart => false,
|
||||
override_options => { 'mysqldump' => { 'default-character-set' => 'UTF-16' } }
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.exit_code).to eq(2)
|
||||
expect(r.stdout).to_not match(/Scheduling refresh/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'root_group' do
|
||||
it 'creates a group' do
|
||||
pp = "group { 'test': ensure => present }"
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'sets the group of files' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
root_group => 'test',
|
||||
config_file => '/tmp/mysql_group_test',
|
||||
}
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
describe file('/tmp/mysql_group_test') do
|
||||
it { should be_grouped_into 'test' }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'service parameters' do
|
||||
it 'calls all parameters' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
service_enabled => true,
|
||||
service_manage => true,
|
||||
service_name => #{service_name},
|
||||
service_provider => #{service_provider}
|
||||
}
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'users, grants, and databases' do
|
||||
it 'are created' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
users => {
|
||||
'zerg1@localhost' => {
|
||||
ensure => 'present',
|
||||
max_connections_per_hour => '0',
|
||||
max_queries_per_hour => '0',
|
||||
max_updates_per_hour => '0',
|
||||
max_user_connections => '0',
|
||||
password_hash => '*F3A2A51A9B0F2BE2468926B4132313728C250DBF',
|
||||
}
|
||||
},
|
||||
grants => {
|
||||
'zerg1@localhost/zergdb.*' => {
|
||||
ensure => 'present',
|
||||
options => ['GRANT'],
|
||||
privileges => ['SELECT', 'INSERT', 'UPDATE', 'DELETE'],
|
||||
table => 'zergdb.*',
|
||||
user => 'zerg1@localhost',
|
||||
}
|
||||
},
|
||||
databases => {
|
||||
'zergdb' => {
|
||||
ensure => 'present',
|
||||
charset => 'utf8',
|
||||
}
|
||||
},
|
||||
}
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'has a user' do
|
||||
shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'zerg1@localhost'\"") do |r|
|
||||
expect(r.stdout).to match(/^1$/)
|
||||
expect(r.stderr).to be_empty
|
||||
end
|
||||
end
|
||||
it 'has a grant' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR zerg1@localhost\"") do |r|
|
||||
expect(r.stdout).to match(/GRANT SELECT, INSERT, UPDATE, DELETE ON `zergdb`.* TO 'zerg1'@'localhost' WITH GRANT OPTION/)
|
||||
expect(r.stderr).to be_empty
|
||||
end
|
||||
end
|
||||
it 'has a database' do
|
||||
shell("mysql -NBe \"SHOW DATABASES LIKE 'zergdb'\"") do |r|
|
||||
expect(r.stdout).to match(/zergdb/)
|
||||
expect(r.stderr).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,12 @@
|
||||
HOSTS:
|
||||
centos-64-x64:
|
||||
roles:
|
||||
- master
|
||||
- database
|
||||
- dashboard
|
||||
platform: el-6-x86_64
|
||||
box : centos-64-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: pe
|
@@ -0,0 +1,10 @@
|
||||
HOSTS:
|
||||
centos-64-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: el-6-x86_64
|
||||
box : centos-64-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: foss
|
@@ -0,0 +1,10 @@
|
||||
HOSTS:
|
||||
fedora-18-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: fedora-18-x86_64
|
||||
box : fedora-18-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/fedora-18-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: foss
|
@@ -0,0 +1,10 @@
|
||||
HOSTS:
|
||||
sles-11-x64.local:
|
||||
roles:
|
||||
- master
|
||||
platform: sles-11-x64
|
||||
box : sles-11sp1-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/sles-11sp1-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: foss
|
@@ -0,0 +1,10 @@
|
||||
HOSTS:
|
||||
ubuntu-server-10044-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: ubuntu-10.04-amd64
|
||||
box : ubuntu-server-10044-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-10044-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: foss
|
@@ -0,0 +1,10 @@
|
||||
HOSTS:
|
||||
ubuntu-server-12042-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: ubuntu-12.04-amd64
|
||||
box : ubuntu-server-12042-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: foss
|
@@ -0,0 +1,64 @@
|
||||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'mysql_database', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
describe 'setup' do
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'creating database' do
|
||||
it 'should work without errors' do
|
||||
pp = <<-EOS
|
||||
mysql_database { 'spec_db':
|
||||
ensure => present,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should find the database' do
|
||||
shell("mysql -NBe \"SHOW DATABASES LIKE 'spec_db'\"") do |r|
|
||||
expect(r.stdout).to match(/^spec_db$/)
|
||||
expect(r.stderr).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'charset and collate' do
|
||||
it 'should create two db of different types idempotently' do
|
||||
pp = <<-EOS
|
||||
mysql_database { 'spec_latin1':
|
||||
charset => 'latin1',
|
||||
collate => 'latin1_swedish_ci',
|
||||
}
|
||||
mysql_database { 'spec_utf8':
|
||||
charset => 'utf8',
|
||||
collate => 'utf8_general_ci',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
|
||||
it 'should find latin1 db' do
|
||||
shell("mysql -NBe \"SHOW VARIABLES LIKE '%_database'\" spec_latin1") do |r|
|
||||
expect(r.stdout).to match(/^character_set_database\tlatin1\ncollation_database\tlatin1_swedish_ci$/)
|
||||
expect(r.stderr).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
it 'should find utf8 db' do
|
||||
shell("mysql -NBe \"SHOW VARIABLES LIKE '%_database'\" spec_utf8") do |r|
|
||||
expect(r.stdout).to match(/^character_set_database\tutf8\ncollation_database\tutf8_general_ci$/)
|
||||
expect(r.stderr).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,308 @@
|
||||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'mysql_grant', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
|
||||
describe 'setup' do
|
||||
it 'setup mysql::server' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'missing privileges for user' do
|
||||
it 'should fail' do
|
||||
pp = <<-EOS
|
||||
mysql_grant { 'test1@tester/test.*':
|
||||
ensure => 'present',
|
||||
table => 'test.*',
|
||||
user => 'test1@tester',
|
||||
}
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/privileges parameter is required/)
|
||||
end
|
||||
|
||||
it 'should not find the user' do
|
||||
expect(shell("mysql -NBe \"SHOW GRANTS FOR test1@tester\"", { :acceptable_exit_codes => 1}).stderr).to match(/There is no such grant defined for user 'test1' on host 'tester'/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'missing table for user' do
|
||||
it 'should fail' do
|
||||
pp = <<-EOS
|
||||
mysql_grant { 'atest@tester/test.*':
|
||||
ensure => 'present',
|
||||
user => 'atest@tester',
|
||||
privileges => ['ALL'],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :expect_failures => true)
|
||||
end
|
||||
|
||||
it 'should not find the user' do
|
||||
expect(shell("mysql -NBe \"SHOW GRANTS FOR atest@tester\"", {:acceptable_exit_codes => 1}).stderr).to match(/There is no such grant defined for user 'atest' on host 'tester'/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'adding privileges' do
|
||||
it 'should work without errors' do
|
||||
pp = <<-EOS
|
||||
mysql_grant { 'test2@tester/test.*':
|
||||
ensure => 'present',
|
||||
table => 'test.*',
|
||||
user => 'test2@tester',
|
||||
privileges => ['SELECT', 'UPDATE'],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should find the user' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR test2@tester\"") do |r|
|
||||
expect(r.stdout).to match(/GRANT SELECT, UPDATE.*TO 'test2'@'tester'/)
|
||||
expect(r.stderr).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'adding option' do
|
||||
it 'should work without errors' do
|
||||
pp = <<-EOS
|
||||
mysql_grant { 'test3@tester/test.*':
|
||||
ensure => 'present',
|
||||
table => 'test.*',
|
||||
user => 'test3@tester',
|
||||
options => ['GRANT'],
|
||||
privileges => ['SELECT', 'UPDATE'],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should find the user' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR test3@tester\"") do |r|
|
||||
expect(r.stdout).to match(/GRANT SELECT, UPDATE ON `test`.* TO 'test3'@'tester' WITH GRANT OPTION$/)
|
||||
expect(r.stderr).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'adding all privileges without table' do
|
||||
it 'should fail' do
|
||||
pp = <<-EOS
|
||||
mysql_grant { 'test4@tester/test.*':
|
||||
ensure => 'present',
|
||||
user => 'test4@tester',
|
||||
options => ['GRANT'],
|
||||
privileges => ['SELECT', 'UPDATE', 'ALL'],
|
||||
}
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/table parameter is required./)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'adding all privileges' do
|
||||
it 'should only try to apply ALL' do
|
||||
pp = <<-EOS
|
||||
mysql_grant { 'test4@tester/test.*':
|
||||
ensure => 'present',
|
||||
table => 'test.*',
|
||||
user => 'test4@tester',
|
||||
options => ['GRANT'],
|
||||
privileges => ['SELECT', 'UPDATE', 'ALL'],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should find the user' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR test4@tester\"") do |r|
|
||||
expect(r.stdout).to match(/GRANT ALL PRIVILEGES ON `test`.* TO 'test4'@'tester' WITH GRANT OPTION/)
|
||||
expect(r.stderr).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Test combinations of user@host to ensure all cases work.
|
||||
describe 'short hostname' do
|
||||
it 'should apply' do
|
||||
pp = <<-EOS
|
||||
mysql_grant { 'test@short/test.*':
|
||||
ensure => 'present',
|
||||
table => 'test.*',
|
||||
user => 'test@short',
|
||||
privileges => 'ALL',
|
||||
}
|
||||
mysql_grant { 'test@long.hostname.com/test.*':
|
||||
ensure => 'present',
|
||||
table => 'test.*',
|
||||
user => 'test@long.hostname.com',
|
||||
privileges => 'ALL',
|
||||
}
|
||||
mysql_grant { 'test@192.168.5.6/test.*':
|
||||
ensure => 'present',
|
||||
table => 'test.*',
|
||||
user => 'test@192.168.5.6',
|
||||
privileges => 'ALL',
|
||||
}
|
||||
mysql_grant { 'test@2607:f0d0:1002:0051:0000:0000:0000:0004/test.*':
|
||||
ensure => 'present',
|
||||
table => 'test.*',
|
||||
user => 'test@2607:f0d0:1002:0051:0000:0000:0000:0004',
|
||||
privileges => 'ALL',
|
||||
}
|
||||
mysql_grant { 'test@::1/128/test.*':
|
||||
ensure => 'present',
|
||||
table => 'test.*',
|
||||
user => 'test@::1/128',
|
||||
privileges => 'ALL',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'finds short hostname' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR test@short\"") do |r|
|
||||
expect(r.stdout).to match(/GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'short'/)
|
||||
expect(r.stderr).to be_empty
|
||||
end
|
||||
end
|
||||
it 'finds long hostname' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'long.hostname.com'\"") do |r|
|
||||
expect(r.stdout).to match(/GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'long.hostname.com'/)
|
||||
expect(r.stderr).to be_empty
|
||||
end
|
||||
end
|
||||
it 'finds ipv4' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'192.168.5.6'\"") do |r|
|
||||
expect(r.stdout).to match(/GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'192.168.5.6'/)
|
||||
expect(r.stderr).to be_empty
|
||||
end
|
||||
end
|
||||
it 'finds ipv6' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'2607:f0d0:1002:0051:0000:0000:0000:0004'\"") do |r|
|
||||
expect(r.stdout).to match(/GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'2607:f0d0:1002:0051:0000:0000:0000:0004'/)
|
||||
expect(r.stderr).to be_empty
|
||||
end
|
||||
end
|
||||
it 'finds short ipv6' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'::1/128'\"") do |r|
|
||||
expect(r.stdout).to match(/GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'::1\/128'/)
|
||||
expect(r.stderr).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'complex test' do
|
||||
it 'setup mysql::server' do
|
||||
pp = <<-EOS
|
||||
$dbSubnet = '10.10.10.%'
|
||||
|
||||
mysql_database { 'foo':
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
exec { 'mysql-create-table':
|
||||
command => '/usr/bin/mysql -NBe "CREATE TABLE foo.bar (name VARCHAR(20))"',
|
||||
environment => "HOME=${::root_home}",
|
||||
unless => '/usr/bin/mysql -NBe "SELECT 1 FROM foo.bar LIMIT 1;"',
|
||||
require => Mysql_database['foo'],
|
||||
}
|
||||
|
||||
Mysql_grant {
|
||||
ensure => present,
|
||||
options => ['GRANT'],
|
||||
privileges => ['ALL'],
|
||||
table => '*.*',
|
||||
require => [ Mysql_database['foo'], Exec['mysql-create-table'] ],
|
||||
}
|
||||
|
||||
mysql_grant { "user1@${dbSubnet}/*.*":
|
||||
user => "user1@${dbSubnet}",
|
||||
}
|
||||
mysql_grant { "user2@${dbSubnet}/foo.bar":
|
||||
privileges => ['SELECT', 'INSERT', 'UPDATE'],
|
||||
user => "user2@${dbSubnet}",
|
||||
table => 'foo.bar',
|
||||
}
|
||||
mysql_grant { "user3@${dbSubnet}/foo.*":
|
||||
privileges => ['SELECT', 'INSERT', 'UPDATE'],
|
||||
user => "user3@${dbSubnet}",
|
||||
table => 'foo.*',
|
||||
}
|
||||
mysql_grant { 'web@%/*.*':
|
||||
user => 'web@%',
|
||||
}
|
||||
mysql_grant { "web@${dbSubnet}/*.*":
|
||||
user => "web@${dbSubnet}",
|
||||
}
|
||||
mysql_grant { "web@${fqdn}/*.*":
|
||||
user => "web@${fqdn}",
|
||||
}
|
||||
mysql_grant { 'web@localhost/*.*':
|
||||
user => 'web@localhost',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'lower case privileges' do
|
||||
it 'create ALL privs' do
|
||||
pp = <<-EOS
|
||||
mysql_grant { 'lowercase@localhost/*.*':
|
||||
user => 'lowercase@localhost',
|
||||
privileges => 'ALL',
|
||||
table => '*.*',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'create lowercase all privs' do
|
||||
pp = <<-EOS
|
||||
mysql_grant { 'lowercase@localhost/*.*':
|
||||
user => 'lowercase@localhost',
|
||||
privileges => 'all',
|
||||
table => '*.*',
|
||||
}
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :catch_failures => true).exit_code).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'adding procedure privileges' do
|
||||
it 'should work without errors' do
|
||||
pp = <<-EOS
|
||||
mysql_grant { 'test2@tester/PROCEDURE test.simpleproc':
|
||||
ensure => 'present',
|
||||
table => 'PROCEDURE test.simpleproc',
|
||||
user => 'test2@tester',
|
||||
privileges => ['EXECUTE'],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should find the user' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR test2@tester\"") do |r|
|
||||
expect(r.stdout).to match(/GRANT EXECUTE ON PROCEDURE `test`.`simpleproc` TO 'test2'@'tester'/)
|
||||
expect(r.stderr).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,32 @@
|
||||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'mysql_user', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
describe 'setup' do
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'adding user' do
|
||||
it 'should work without errors' do
|
||||
pp = <<-EOS
|
||||
mysql_user { 'ashp@localhost':
|
||||
password_hash => '6f8c114b58f2ce9e',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should find the user' do
|
||||
shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r|
|
||||
expect(r.stdout).to match(/^1$/)
|
||||
expect(r.stderr).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,10 @@
|
||||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'unsupported distributions and OSes', :if => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
it 'should fail' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': }
|
||||
EOS
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/unsupported osfamily/i)
|
||||
end
|
||||
end
|
@@ -0,0 +1,58 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'mysql::bindings' do
|
||||
let(:params) {{
|
||||
'java_enable' => true,
|
||||
'perl_enable' => true,
|
||||
'php_enable' => true,
|
||||
'python_enable' => true,
|
||||
'ruby_enable' => true,
|
||||
}}
|
||||
|
||||
shared_examples 'bindings' do |osfamily, operatingsystem, java_name, perl_name, php_name, python_name, ruby_name|
|
||||
let :facts do
|
||||
{ :osfamily => osfamily, :operatingsystem => operatingsystem, :root_home => '/root'}
|
||||
end
|
||||
it { should contain_package('mysql-connector-java').with(
|
||||
:name => java_name,
|
||||
:ensure => 'present'
|
||||
)}
|
||||
it { should contain_package('perl_mysql').with(
|
||||
:name => perl_name,
|
||||
:ensure => 'present'
|
||||
)}
|
||||
it { should contain_package('python-mysqldb').with(
|
||||
:name => python_name,
|
||||
:ensure => 'present'
|
||||
)}
|
||||
it { should contain_package('ruby_mysql').with(
|
||||
:name => ruby_name,
|
||||
:ensure => 'present'
|
||||
)}
|
||||
end
|
||||
|
||||
context 'Debian' do
|
||||
it_behaves_like 'bindings', 'Debian', 'Debian', 'libmysql-java', 'libdbd-mysql-perl', 'php5-mysql', 'python-mysqldb', 'libmysql-ruby'
|
||||
it_behaves_like 'bindings', 'Debian', 'Ubuntu', 'libmysql-java', 'libdbd-mysql-perl', 'php5-mysql', 'python-mysqldb', 'libmysql-ruby'
|
||||
end
|
||||
|
||||
context 'freebsd' do
|
||||
it_behaves_like 'bindings', 'FreeBSD', 'FreeBSD', 'databases/mysql-connector-java', 'p5-DBD-mysql', 'databases/php5-mysql', 'databases/py-MySQLdb', 'databases/ruby-mysql'
|
||||
end
|
||||
|
||||
context 'redhat' do
|
||||
it_behaves_like 'bindings', 'RedHat', 'RedHat', 'mysql-connector-java', 'perl-DBD-MySQL', 'php-mysql', 'MySQL-python', 'ruby-mysql'
|
||||
it_behaves_like 'bindings', 'RedHat', 'OpenSuSE', 'mysql-connector-java', 'perl-DBD-MySQL', 'php-mysql', 'MySQL-python', 'ruby-mysql'
|
||||
end
|
||||
|
||||
describe 'on any other os' do
|
||||
let :facts do
|
||||
{:osfamily => 'foo', :root_home => '/root'}
|
||||
end
|
||||
|
||||
it 'should fail' do
|
||||
expect { subject }.to raise_error(/Unsupported osfamily: foo/)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,16 @@
|
||||
describe 'mysql::client' do
|
||||
let(:facts) {{ :osfamily => 'RedHat' }}
|
||||
|
||||
context 'with defaults' do
|
||||
it { should_not contain_class('mysql::bindings') }
|
||||
it { should contain_package('mysql_client') }
|
||||
end
|
||||
|
||||
context 'with bindings enabled' do
|
||||
let(:params) {{ :bindings_enable => true }}
|
||||
|
||||
it { should contain_class('mysql::bindings') }
|
||||
it { should contain_package('mysql_client') }
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,41 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'mysql::server::account_security' do
|
||||
|
||||
let :facts do {
|
||||
:fqdn => 'myhost.mydomain',
|
||||
:hostname => 'myhost',
|
||||
:root_home => '/root'
|
||||
}
|
||||
end
|
||||
|
||||
it 'should remove Mysql_User[root@myhost.mydomain]' do
|
||||
should contain_mysql_user('root@myhost.mydomain').with_ensure('absent')
|
||||
end
|
||||
it 'should remove Mysql_User[root@myhost]' do
|
||||
should contain_mysql_user('root@myhost').with_ensure('absent')
|
||||
end
|
||||
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 Mysql_User[root@::1]' do
|
||||
should contain_mysql_user('root@::1').with_ensure('absent')
|
||||
end
|
||||
it 'should remove Mysql_User[@myhost.mydomain]' do
|
||||
should contain_mysql_user('@myhost.mydomain').with_ensure('absent')
|
||||
end
|
||||
it 'should remove Mysql_User[@myhost]' do
|
||||
should contain_mysql_user('@myhost').with_ensure('absent')
|
||||
end
|
||||
it 'should remove Mysql_User[@localhost]' do
|
||||
should contain_mysql_user('@localhost').with_ensure('absent')
|
||||
end
|
||||
it 'should remove Mysql_User[@%]' do
|
||||
should contain_mysql_user('@%').with_ensure('absent')
|
||||
end
|
||||
|
||||
it 'should remove Mysql_database[test]' do
|
||||
should contain_mysql_database('test').with_ensure('absent')
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,183 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'mysql::server::backup' do
|
||||
|
||||
let(:default_params) {
|
||||
{ 'backupuser' => 'testuser',
|
||||
'backuppassword' => 'testpass',
|
||||
'backupdir' => '/tmp',
|
||||
'backuprotate' => '25',
|
||||
'delete_before_dump' => true,
|
||||
}
|
||||
}
|
||||
context 'standard conditions' do
|
||||
let(:params) { default_params }
|
||||
|
||||
it { should contain_mysql_user('testuser@localhost').with(
|
||||
:require => 'Class[Mysql::Server::Root_password]'
|
||||
)}
|
||||
|
||||
it { should contain_mysql_grant('testuser@localhost/*.*').with(
|
||||
:privileges => ["SELECT", "RELOAD", "LOCK TABLES", "SHOW VIEW"]
|
||||
)}
|
||||
|
||||
it { should contain_cron('mysql-backup').with(
|
||||
:command => '/usr/local/sbin/mysqlbackup.sh',
|
||||
:ensure => 'present'
|
||||
)}
|
||||
|
||||
it { should contain_file('mysqlbackup.sh').with(
|
||||
:path => '/usr/local/sbin/mysqlbackup.sh',
|
||||
:ensure => 'present'
|
||||
) }
|
||||
|
||||
it { should contain_file('mysqlbackupdir').with(
|
||||
:path => '/tmp',
|
||||
:ensure => 'directory'
|
||||
)}
|
||||
|
||||
it 'should have compression by default' do
|
||||
verify_contents(subject, 'mysqlbackup.sh', [
|
||||
' --all-databases | bzcat -zc > ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql.bz2',
|
||||
])
|
||||
end
|
||||
it 'should skip backing up events table by default' do
|
||||
verify_contents(subject, 'mysqlbackup.sh', [
|
||||
'EVENTS="--ignore-table=mysql.event"',
|
||||
])
|
||||
end
|
||||
|
||||
it 'should have 25 days of rotation' do
|
||||
# MySQL counts from 0 I guess.
|
||||
should contain_file('mysqlbackup.sh').with_content(/.*ROTATE=24.*/)
|
||||
end
|
||||
end
|
||||
|
||||
context 'custom ownership and mode for backupdir' do
|
||||
let(:params) do
|
||||
{ :backupdirmode => '0750',
|
||||
:backupdirowner => 'testuser',
|
||||
:backupdirgroup => 'testgrp',
|
||||
}.merge(default_params)
|
||||
end
|
||||
|
||||
it { should contain_file('mysqlbackupdir').with(
|
||||
:path => '/tmp',
|
||||
:ensure => 'directory',
|
||||
:mode => '0750',
|
||||
:owner => 'testuser',
|
||||
:group => 'testgrp'
|
||||
) }
|
||||
end
|
||||
|
||||
context 'with compression disabled' do
|
||||
let(:params) do
|
||||
{ :backupcompress => false }.merge(default_params)
|
||||
end
|
||||
|
||||
it { should contain_file('mysqlbackup.sh').with(
|
||||
:path => '/usr/local/sbin/mysqlbackup.sh',
|
||||
:ensure => 'present'
|
||||
) }
|
||||
|
||||
it 'should be able to disable compression' do
|
||||
verify_contents(subject, 'mysqlbackup.sh', [
|
||||
' --all-databases > ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql',
|
||||
])
|
||||
end
|
||||
end
|
||||
|
||||
context 'with mysql.events backedup' do
|
||||
let(:params) do
|
||||
{ :ignore_events => false }.merge(default_params)
|
||||
end
|
||||
|
||||
it { should contain_file('mysqlbackup.sh').with(
|
||||
:path => '/usr/local/sbin/mysqlbackup.sh',
|
||||
:ensure => 'present'
|
||||
) }
|
||||
|
||||
it 'should be able to backup events table' do
|
||||
verify_contents(subject, 'mysqlbackup.sh', [
|
||||
'EVENTS="--events"',
|
||||
])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'with database list specified' do
|
||||
let(:params) do
|
||||
{ :backupdatabases => ['mysql'] }.merge(default_params)
|
||||
end
|
||||
|
||||
it { should contain_file('mysqlbackup.sh').with(
|
||||
:path => '/usr/local/sbin/mysqlbackup.sh',
|
||||
:ensure => 'present'
|
||||
) }
|
||||
|
||||
it 'should have a backup file for each database' do
|
||||
content = subject.resource('file','mysqlbackup.sh').send(:parameters)[:content]
|
||||
content.should match(' mysql | bzcat -zc \${DIR}\\\${PREFIX}mysql_`date')
|
||||
# verify_contents(subject, 'mysqlbackup.sh', [
|
||||
# ' mysql | bzcat -zc ${DIR}/${PREFIX}mysql_`date +%Y%m%d-%H%M%S`.sql',
|
||||
# ])
|
||||
end
|
||||
end
|
||||
|
||||
context 'with file per database' do
|
||||
let(:params) do
|
||||
default_params.merge({ :file_per_database => true })
|
||||
end
|
||||
|
||||
it 'should loop through backup all databases' do
|
||||
verify_contents(subject, 'mysqlbackup.sh', [
|
||||
'mysql -s -r -N -e \'SHOW DATABASES\' | while read dbname',
|
||||
'do',
|
||||
' mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \\',
|
||||
' ${EVENTS} \\',
|
||||
' ${dbname} | bzcat -zc > ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql.bz2',
|
||||
'done',
|
||||
])
|
||||
end
|
||||
|
||||
context 'with compression disabled' do
|
||||
let(:params) do
|
||||
default_params.merge({ :file_per_database => true, :backupcompress => false })
|
||||
end
|
||||
|
||||
it 'should loop through backup all databases without compression' do
|
||||
verify_contents(subject, 'mysqlbackup.sh', [
|
||||
' ${dbname} > ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql',
|
||||
])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with postscript' do
|
||||
let(:params) do
|
||||
default_params.merge({ :postscript => 'rsync -a /tmp backup01.local-lan:' })
|
||||
end
|
||||
|
||||
it 'should be add postscript' do
|
||||
verify_contents(subject, 'mysqlbackup.sh', [
|
||||
'rsync -a /tmp backup01.local-lan:',
|
||||
])
|
||||
end
|
||||
end
|
||||
|
||||
context 'with postscripts' do
|
||||
let(:params) do
|
||||
default_params.merge({ :postscript => [
|
||||
'rsync -a /tmp backup01.local-lan:',
|
||||
'rsync -a /tmp backup02.local-lan:',
|
||||
]})
|
||||
end
|
||||
|
||||
it 'should be add postscript' do
|
||||
verify_contents(subject, 'mysqlbackup.sh', [
|
||||
'rsync -a /tmp backup01.local-lan:',
|
||||
'rsync -a /tmp backup02.local-lan:',
|
||||
])
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,31 @@
|
||||
require 'spec_helper'
|
||||
describe 'mysql::server::monitor' do
|
||||
let :facts do
|
||||
{ :osfamily => 'Debian', :root_home => '/root' }
|
||||
end
|
||||
let :pre_condition do
|
||||
"include 'mysql::server'"
|
||||
end
|
||||
|
||||
let :default_params do
|
||||
{
|
||||
:mysql_monitor_username => 'monitoruser',
|
||||
:mysql_monitor_password => 'monitorpass',
|
||||
:mysql_monitor_hostname => 'monitorhost',
|
||||
}
|
||||
end
|
||||
|
||||
let :params do
|
||||
default_params
|
||||
end
|
||||
|
||||
it { should contain_mysql_user('monitoruser@monitorhost')}
|
||||
|
||||
it { should contain_mysql_grant('monitoruser@monitorhost/*.*').with(
|
||||
:ensure => 'present',
|
||||
:user => 'monitoruser@monitorhost',
|
||||
:table => '*.*',
|
||||
:privileges => ["PROCESS", "SUPER"],
|
||||
:require => 'Mysql_user[monitoruser@monitorhost]'
|
||||
)}
|
||||
end
|
@@ -0,0 +1,5 @@
|
||||
describe 'mysql::server::mysqltuner' do
|
||||
|
||||
it { should contain_file('/usr/local/bin/mysqltuner') }
|
||||
|
||||
end
|
@@ -0,0 +1,193 @@
|
||||
require 'spec_helper'
|
||||
describe 'mysql::server' do
|
||||
let(:facts) {{:osfamily => 'RedHat', :root_home => '/root'}}
|
||||
|
||||
context 'with defaults' do
|
||||
it { should contain_class('mysql::server::install') }
|
||||
it { should contain_class('mysql::server::config') }
|
||||
it { should contain_class('mysql::server::service') }
|
||||
it { should contain_class('mysql::server::root_password') }
|
||||
it { should contain_class('mysql::server::providers') }
|
||||
end
|
||||
|
||||
# make sure that overriding the mysqld settings keeps the defaults for everything else
|
||||
context 'with overrides' do
|
||||
let(:params) {{ :override_options => { 'mysqld' => { 'socket' => '/var/lib/mysql/mysql.sock' } } }}
|
||||
it do
|
||||
should contain_file('/etc/my.cnf').with({
|
||||
:mode => '0644',
|
||||
}).with_content(/basedir/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with multiple instance of an option' do
|
||||
let(:params) {{ :override_options => { 'mysqld' => { 'replicate-do-db' => ['base1', 'base2', 'base3'], } }}}
|
||||
it do
|
||||
should contain_file('/etc/my.cnf').with_content(
|
||||
/^replicate-do-db = base1$/
|
||||
).with_content(
|
||||
/^replicate-do-db = base2$/
|
||||
).with_content(
|
||||
/^replicate-do-db = base3$/
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'an option set to true' do
|
||||
let(:params) {
|
||||
{ :override_options => { 'mysqld' => { 'ssl' => true } }}
|
||||
}
|
||||
it do
|
||||
should contain_file('/etc/my.cnf').with_content(/^\s*ssl\s*(?:$|= true)/m)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'an option set to false' do
|
||||
let(:params) {
|
||||
{ :override_options => { 'mysqld' => { 'ssl' => false } }}
|
||||
}
|
||||
it do
|
||||
should contain_file('/etc/my.cnf').with_content(/^\s*ssl = false/m)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with remove_default_accounts set' do
|
||||
let (:params) {{ :remove_default_accounts => true }}
|
||||
it { should contain_class('mysql::server::account_security') }
|
||||
end
|
||||
|
||||
context 'mysql::server::install' do
|
||||
let(:params) {{ :package_ensure => 'present', :name => 'mysql-server' }}
|
||||
it do
|
||||
should contain_package('mysql-server').with({
|
||||
:ensure => :present,
|
||||
:name => 'mysql-server',
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
context 'mysql::server::config' do
|
||||
it do
|
||||
should contain_file('/etc/mysql').with({
|
||||
:ensure => :directory,
|
||||
:mode => '0755',
|
||||
})
|
||||
end
|
||||
|
||||
it do
|
||||
should contain_file('/etc/mysql/conf.d').with({
|
||||
:ensure => :directory,
|
||||
:mode => '0755',
|
||||
})
|
||||
end
|
||||
|
||||
it do
|
||||
should contain_file('/etc/my.cnf').with({
|
||||
:mode => '0644',
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
context 'mysql::server::service' do
|
||||
context 'with defaults' do
|
||||
it { should contain_service('mysqld') }
|
||||
end
|
||||
|
||||
context 'service_enabled set to false' do
|
||||
let(:params) {{ :service_enabled => false }}
|
||||
|
||||
it do
|
||||
should contain_service('mysqld').with({
|
||||
:ensure => :stopped
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'mysql::server::root_password' do
|
||||
describe 'when defaults' do
|
||||
it { should_not contain_mysql_user('root@localhost') }
|
||||
it { should_not contain_file('/root/.my.cnf') }
|
||||
end
|
||||
describe 'when set' do
|
||||
let(:params) {{:root_password => 'SET' }}
|
||||
it { should contain_mysql_user('root@localhost') }
|
||||
it { should contain_file('/root/.my.cnf') }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'mysql::server::providers' do
|
||||
describe 'with users' do
|
||||
let(:params) {{:users => {
|
||||
'foo@localhost' => {
|
||||
'max_connections_per_hour' => '1',
|
||||
'max_queries_per_hour' => '2',
|
||||
'max_updates_per_hour' => '3',
|
||||
'max_user_connections' => '4',
|
||||
'password_hash' => '*F3A2A51A9B0F2BE2468926B4132313728C250DBF'
|
||||
},
|
||||
'foo2@localhost' => {}
|
||||
}}}
|
||||
it { should contain_mysql_user('foo@localhost').with(
|
||||
:max_connections_per_hour => '1',
|
||||
:max_queries_per_hour => '2',
|
||||
:max_updates_per_hour => '3',
|
||||
:max_user_connections => '4',
|
||||
:password_hash => '*F3A2A51A9B0F2BE2468926B4132313728C250DBF'
|
||||
)}
|
||||
it { should contain_mysql_user('foo2@localhost').with(
|
||||
:max_connections_per_hour => nil,
|
||||
:max_queries_per_hour => nil,
|
||||
:max_updates_per_hour => nil,
|
||||
:max_user_connections => nil,
|
||||
:password_hash => ''
|
||||
)}
|
||||
end
|
||||
|
||||
describe 'with grants' do
|
||||
let(:params) {{:grants => {
|
||||
'foo@localhost/somedb.*' => {
|
||||
'user' => 'foo@localhost',
|
||||
'table' => 'somedb.*',
|
||||
'privileges' => ["SELECT", "UPDATE"],
|
||||
'options' => ["GRANT"],
|
||||
},
|
||||
'foo2@localhost/*.*' => {
|
||||
'user' => 'foo2@localhost',
|
||||
'table' => '*.*',
|
||||
'privileges' => ["SELECT"],
|
||||
},
|
||||
}}}
|
||||
it { should contain_mysql_grant('foo@localhost/somedb.*').with(
|
||||
:user => 'foo@localhost',
|
||||
:table => 'somedb.*',
|
||||
:privileges => ["SELECT", "UPDATE"],
|
||||
:options => ["GRANT"]
|
||||
)}
|
||||
it { should contain_mysql_grant('foo2@localhost/*.*').with(
|
||||
:user => 'foo2@localhost',
|
||||
:table => '*.*',
|
||||
:privileges => ["SELECT"],
|
||||
:options => nil
|
||||
)}
|
||||
end
|
||||
|
||||
describe 'with databases' do
|
||||
let(:params) {{:databases => {
|
||||
'somedb' => {
|
||||
'charset' => 'latin1',
|
||||
'collate' => 'latin1',
|
||||
},
|
||||
'somedb2' => {}
|
||||
}}}
|
||||
it { should contain_mysql_database('somedb').with(
|
||||
:charset => 'latin1',
|
||||
:collate => 'latin1'
|
||||
)}
|
||||
it { should contain_mysql_database('somedb2')}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,51 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'mysql::db', :type => :define do
|
||||
let(:facts) {{ :osfamily => 'RedHat' }}
|
||||
let(:title) { 'test_db' }
|
||||
|
||||
let(:params) {
|
||||
{ 'user' => 'testuser',
|
||||
'password' => 'testpass',
|
||||
}
|
||||
}
|
||||
|
||||
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_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('Mysql_database[test_db]')
|
||||
end
|
||||
|
||||
it 'should only import sql script on creation if not enforcing' do
|
||||
params.merge!({'sql' => 'test_sql', 'enforce_sql' => false})
|
||||
should contain_exec('test_db-import').with_refreshonly(true)
|
||||
end
|
||||
|
||||
it 'should import sql script on creation if enforcing' 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_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
|
6
resources/vagrant/vms/phraseanet-php55-nginx/puphpet/puppet/modules/mysql/spec/spec.opts
vendored
Normal file
6
resources/vagrant/vms/phraseanet-php55-nginx/puphpet/puppet/modules/mysql/spec/spec.opts
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
--format
|
||||
s
|
||||
--colour
|
||||
--loadby
|
||||
mtime
|
||||
--backtrace
|
@@ -0,0 +1,5 @@
|
||||
require 'simplecov'
|
||||
SimpleCov.start do
|
||||
add_filter "/spec/"
|
||||
end
|
||||
require 'puppetlabs_spec_helper/module_spec_helper'
|
@@ -0,0 +1,48 @@
|
||||
require 'beaker-rspec'
|
||||
|
||||
UNSUPPORTED_PLATFORMS = [ 'Windows', 'Solaris', 'AIX' ]
|
||||
|
||||
unless ENV['RS_PROVISION'] == 'no'
|
||||
hosts.each do |host|
|
||||
# Install Puppet
|
||||
if host.is_pe?
|
||||
install_pe
|
||||
else
|
||||
install_package host, 'rubygems'
|
||||
on host, 'gem install puppet --no-ri --no-rdoc'
|
||||
on host, "mkdir -p #{host['distmoduledir']}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.configure do |c|
|
||||
# Project root
|
||||
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
||||
|
||||
# Readable test descriptions
|
||||
c.formatter = :documentation
|
||||
|
||||
# Configure all nodes in nodeset
|
||||
c.before :suite do
|
||||
# Install module and dependencies
|
||||
puppet_module_install(:source => proj_root, :module_name => 'mysql')
|
||||
hosts.each do |host|
|
||||
# Required for binding tests.
|
||||
if fact('osfamily') == 'RedHat'
|
||||
version = fact("operatingsystemmajrelease")
|
||||
shell("yum localinstall -y http://yum.puppetlabs.com/puppetlabs-release-el-#{version}.noarch.rpm")
|
||||
if version == '6'
|
||||
shell("yum localinstall -y http://mirror.pnl.gov/epel/6/i386/epel-release-6-8.noarch.rpm")
|
||||
elsif version == '5'
|
||||
shell("yum localinstall -y http://mirrors.servercentral.net/fedora/epel/5/i386/epel-release-5-4.noarch.rpm")
|
||||
else
|
||||
puts "Sorry, this version is not supported."
|
||||
exit
|
||||
end
|
||||
end
|
||||
|
||||
shell("/bin/touch #{default['distmoduledir']}/hiera.yaml")
|
||||
shell('puppet module install puppetlabs-stdlib --version 3.2.0', { :acceptable_exit_codes => [0,1] })
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,25 @@
|
||||
require 'rspec-system/spec_helper'
|
||||
require 'rspec-system-puppet/helpers'
|
||||
require 'rspec-system-serverspec/helpers'
|
||||
|
||||
include RSpecSystemPuppet::Helpers
|
||||
|
||||
RSpec.configure do |c|
|
||||
# Project root
|
||||
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
||||
|
||||
# Enable colour
|
||||
c.tty = true
|
||||
|
||||
c.include RSpecSystemPuppet::Helpers
|
||||
|
||||
# This is where we 'setup' the nodes before running our tests
|
||||
c.before :suite do
|
||||
# Install puppet
|
||||
puppet_install
|
||||
|
||||
# Install modules and dependencies
|
||||
puppet_module_install(:source => proj_root, :module_name => 'mysql')
|
||||
shell('puppet module install puppetlabs-stdlib')
|
||||
end
|
||||
end
|
@@ -0,0 +1,35 @@
|
||||
require 'spec_helper_system'
|
||||
|
||||
describe 'mysql::server::account_security class' do
|
||||
|
||||
describe 'running puppet code' do
|
||||
# Using puppet_apply as a helper
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': remove_default_accounts => true }
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
puppet_apply(pp) do |r|
|
||||
r.exit_code.should_not == 1
|
||||
r.refresh
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
|
||||
describe 'accounts' do
|
||||
it 'should delete accounts' do
|
||||
shell("mysql -e 'show grants for root@127.0.01;'") do |s|
|
||||
s.exit_code.should == 1
|
||||
end
|
||||
end
|
||||
|
||||
it 'should delete databases' do
|
||||
shell("mysql -e 'show databases;' |grep test") do |s|
|
||||
s.exit_code.should == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,62 @@
|
||||
require 'spec_helper_system'
|
||||
|
||||
describe 'mysql::server::backup class' do
|
||||
context 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': override_options => { 'root_password' => 'password' } }
|
||||
mysql::db { 'backup1':
|
||||
user => 'backup',
|
||||
password => 'secret',
|
||||
}
|
||||
|
||||
class { 'mysql::server::backup':
|
||||
backupuser => 'myuser',
|
||||
backuppassword => 'mypassword',
|
||||
backupdir => '/tmp/backups',
|
||||
backupcompress => true,
|
||||
postscript => [
|
||||
'rm -rf /var/tmp/mysqlbackups',
|
||||
'rm -f /var/tmp/mysqlbackups.done',
|
||||
'cp -r /tmp/backups /var/tmp/mysqlbackups',
|
||||
'touch /var/tmp/mysqlbackups.done',
|
||||
],
|
||||
}
|
||||
EOS
|
||||
|
||||
context puppet_apply(pp) do
|
||||
its(:stderr) { should be_empty }
|
||||
its(:exit_code) { should_not == 1 }
|
||||
its(:refresh) { should be_nil }
|
||||
its(:stderr) { should be_empty }
|
||||
its(:exit_code) { should be_zero }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'mysqlbackup.sh' do
|
||||
context 'should run mysqlbackup.sh with no errors' do
|
||||
context shell("/usr/local/sbin/mysqlbackup.sh") do
|
||||
its(:exit_code) { should be_zero }
|
||||
its(:stderr) { should be_empty }
|
||||
end
|
||||
end
|
||||
|
||||
context 'should dump all databases to single file' do
|
||||
describe command('ls /tmp/backups/ | grep -c "mysql_backup_[0-9][0-9]*-[0-9][0-9]*.sql.bz2"') do
|
||||
it { should return_stdout /1/ }
|
||||
it { should return_exit_status 0 }
|
||||
end
|
||||
end
|
||||
|
||||
context 'should create one file per database per run' do
|
||||
context shell("/usr/local/sbin/mysqlbackup.sh") do
|
||||
its(:exit_code) { should be_zero }
|
||||
its(:stderr) { should be_empty }
|
||||
end
|
||||
|
||||
describe command('ls /tmp/backups/ | grep -c "mysql_backup_backup1_[0-9][0-9]*-[0-9][0-9]*.sql.bz2"') do
|
||||
it { should return_stdout /2/ }
|
||||
it { should return_exit_status 0 }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,90 @@
|
||||
require 'spec_helper_system'
|
||||
|
||||
describe 'mysql::bindings class' do
|
||||
let(:os) {
|
||||
node.facts['osfamily']
|
||||
}
|
||||
|
||||
case node.facts['osfamily']
|
||||
when 'RedHat'
|
||||
java_package = 'mysql-connector-java'
|
||||
perl_package = 'perl-DBD-MySQL'
|
||||
python_package = 'MySQL-python'
|
||||
ruby_package = 'ruby-mysql'
|
||||
when 'Suse'
|
||||
java_package = 'mysql-connector-java'
|
||||
perl_package = 'perl-DBD-MySQL'
|
||||
python_package = 'python-mysql'
|
||||
case node.facts['operatingsystem']
|
||||
when /OpenSuSE/
|
||||
ruby_package = 'rubygem-mysql'
|
||||
when /(SLES|SLED)/
|
||||
ruby_package = 'ruby-mysql'
|
||||
end
|
||||
when 'Debian'
|
||||
java_package = 'libmysql-java'
|
||||
perl_package = 'libdbd-mysql-perl'
|
||||
python_package = 'python-mysqldb'
|
||||
ruby_package = 'libmysql-ruby'
|
||||
when 'FreeBSD'
|
||||
java_package = 'databases/mysql-connector-java'
|
||||
perl_package = 'p5-DBD-mysql'
|
||||
python_package = 'databases/py-MySQLdb'
|
||||
ruby_package = 'ruby-mysql'
|
||||
else
|
||||
case node.facts['operatingsystem']
|
||||
when 'Amazon'
|
||||
java_package = 'mysql-connector-java'
|
||||
perl_package = 'perl-DBD-MySQL'
|
||||
python_package = 'MySQL-python'
|
||||
ruby_package = 'ruby-mysql'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'running puppet code' do
|
||||
# Using puppet_apply as a helper
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::bindings': }
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
puppet_apply(pp) do |r|
|
||||
r.exit_code.should_not == 1
|
||||
r.refresh
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'enabling bindings' do
|
||||
it 'should work with no errors' do
|
||||
puppet_apply(%{
|
||||
class { 'mysql::bindings':
|
||||
java_enable => true,
|
||||
perl_enable => true,
|
||||
python_enable => true,
|
||||
ruby_enable => true,
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
describe package(java_package) do
|
||||
it { should be_installed }
|
||||
end
|
||||
|
||||
describe package(perl_package) do
|
||||
it { should be_installed }
|
||||
end
|
||||
|
||||
describe package(python_package) do
|
||||
it { should be_installed }
|
||||
end
|
||||
|
||||
describe package(ruby_package) do
|
||||
it { should be_installed }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,61 @@
|
||||
require 'spec_helper_system'
|
||||
|
||||
describe 'mysql::db define' do
|
||||
describe 'creating a database' do
|
||||
# Using puppet_apply as a helper
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': override_options => { 'root_password' => 'password' } }
|
||||
mysql::db { 'spec1':
|
||||
user => 'root1',
|
||||
password => 'password',
|
||||
}
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
puppet_apply(pp) do |r|
|
||||
[0,2].should include r.exit_code
|
||||
r.refresh
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
|
||||
it 'should have the database' do
|
||||
shell("mysql -e 'show databases;'|grep spec1") do |s|
|
||||
s.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'creating a database with post-sql' do
|
||||
# Using puppet_apply as a helper
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': override_options => { 'root_password' => 'password' } }
|
||||
file { '/tmp/spec.sql':
|
||||
ensure => file,
|
||||
content => 'CREATE TABLE table1 (id int);',
|
||||
before => Mysql::Db['spec2'],
|
||||
}
|
||||
mysql::db { 'spec2':
|
||||
user => 'root1',
|
||||
password => 'password',
|
||||
sql => '/tmp/spec.sql',
|
||||
}
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
puppet_apply(pp) do |r|
|
||||
[0,2].should include r.exit_code
|
||||
r.refresh
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
|
||||
it 'should have the table' do
|
||||
shell("mysql -e 'show tables;' spec2|grep table1") do |s|
|
||||
s.exit_code.should == 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,30 @@
|
||||
require 'spec_helper_system'
|
||||
|
||||
describe 'mysql::server::monitor class' do
|
||||
context 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': root_password => 'password' }
|
||||
|
||||
class { 'mysql::server::monitor':
|
||||
mysql_monitor_username => 'monitoruser',
|
||||
mysql_monitor_password => 'monitorpass',
|
||||
mysql_monitor_hostname => 'localhost',
|
||||
}
|
||||
EOS
|
||||
|
||||
context puppet_apply(pp) do
|
||||
its(:stderr) { should be_empty }
|
||||
its(:exit_code) { should_not == 1 }
|
||||
its(:refresh) { should be_nil }
|
||||
its(:stderr) { should be_empty }
|
||||
its(:exit_code) { should be_zero }
|
||||
end
|
||||
|
||||
context 'should run mysqladmin ping with no errors' do
|
||||
describe command("mysqladmin -u monitoruser -pmonitorpass -h localhost ping") do
|
||||
it { should return_stdout /mysqld is alive/ }
|
||||
it { should return_exit_status 0 }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,71 @@
|
||||
require 'spec_helper_system'
|
||||
|
||||
describe 'mysql::server::root_password class' do
|
||||
|
||||
describe 'reset' do
|
||||
it 'shuts down mysql' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': service_enabled => false }
|
||||
EOS
|
||||
|
||||
puppet_apply(pp) do |r|
|
||||
r.exit_code.should_not == 1
|
||||
end
|
||||
end
|
||||
|
||||
it 'deletes the /root/.my.cnf password' do
|
||||
shell('rm -rf /root/.my.cnf')
|
||||
end
|
||||
|
||||
it 'deletes all databases' do
|
||||
case node.facts['osfamily']
|
||||
when 'RedHat'
|
||||
shell('rm -rf `grep datadir /etc/my.cnf | cut -d" " -f 3`/*')
|
||||
when 'Debian'
|
||||
shell('rm -rf `grep datadir /etc/mysql/my.cnf | cut -d" " -f 3`/*')
|
||||
shell('mysql_install_db')
|
||||
end
|
||||
end
|
||||
|
||||
it 'starts up mysql' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': service_enabled => true }
|
||||
EOS
|
||||
|
||||
puppet_apply(pp) do |r|
|
||||
r.exit_code.should_not == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when unset' do
|
||||
it 'should work' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': root_password => 'test' }
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
puppet_apply(pp) do |r|
|
||||
r.exit_code.should_not == 1
|
||||
r.refresh
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when set' do
|
||||
it 'should work' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': root_password => 'new', old_root_password => 'test' }
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
puppet_apply(pp) do |r|
|
||||
r.exit_code.should_not == 1
|
||||
r.refresh
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,106 @@
|
||||
require 'spec_helper_system'
|
||||
|
||||
describe 'mysql class' do
|
||||
case node.facts['osfamily']
|
||||
when 'RedHat'
|
||||
package_name = 'mysql-server'
|
||||
service_name = 'mysqld'
|
||||
mycnf = '/etc/my.cnf'
|
||||
when 'Suse'
|
||||
package_name = 'mysql-community-server'
|
||||
service_name = 'mysql'
|
||||
mycnf = '/etc/my.cnf'
|
||||
when 'Debian'
|
||||
package_name = 'mysql-server'
|
||||
service_name = 'mysql'
|
||||
mycnf = '/etc/mysql/my.cnf'
|
||||
end
|
||||
|
||||
describe 'running puppet code' do
|
||||
# Using puppet_apply as a helper
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': }
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
puppet_apply(pp) do |r|
|
||||
r.exit_code.should_not == 1
|
||||
r.refresh
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
|
||||
describe package(package_name) do
|
||||
it { should be_installed }
|
||||
end
|
||||
|
||||
describe service(service_name) do
|
||||
it { should be_running }
|
||||
it { should be_enabled }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'mycnf' do
|
||||
it 'should contain sensible values' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': }
|
||||
EOS
|
||||
puppet_apply(pp) do |r|
|
||||
r.exit_code.should_not == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe file(mycnf) do
|
||||
it { should contain 'key_buffer = 16M' }
|
||||
it { should contain 'max_binlog_size = 100M' }
|
||||
it { should contain 'query_cache_size = 16M' }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'my.cnf changes' do
|
||||
it 'sets values' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
override_options => { 'mysqld' =>
|
||||
{ 'key_buffer' => '32M',
|
||||
'max_binlog_size' => '200M',
|
||||
'query_cache_size' => '32M',
|
||||
}
|
||||
}
|
||||
}
|
||||
EOS
|
||||
puppet_apply(pp) do |r|
|
||||
r.exit_code.should_not == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe file(mycnf) do
|
||||
it { should contain 'key_buffer = 32M' }
|
||||
it { should contain 'max_binlog_size = 200M' }
|
||||
it { should contain 'query_cache_size = 32M' }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'my.cnf should contain multiple instances of the same option' do
|
||||
it 'sets multiple values' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server':
|
||||
override_options => { 'mysqld' =>
|
||||
{ 'replicate-do-db' => ['base1', 'base2', 'base3'], }
|
||||
}
|
||||
}
|
||||
EOS
|
||||
puppet_apply(pp) do |r|
|
||||
r.exit_code.should_not == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe file(mycnf) do
|
||||
it { should contain 'replicate-do-db = base1' }
|
||||
it { should contain 'replicate-do-db = base2' }
|
||||
it { should contain 'replicate-do-db = base3' }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,314 @@
|
||||
require 'spec_helper_system'
|
||||
|
||||
describe 'mysql_grant' do
|
||||
|
||||
describe 'setup' do
|
||||
it 'setup mysql::server' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': }
|
||||
EOS
|
||||
|
||||
puppet_apply(pp)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'missing privileges for user' do
|
||||
it 'should fail' do
|
||||
pp = <<-EOS
|
||||
mysql_grant { 'test1@tester/test.*':
|
||||
ensure => 'present',
|
||||
table => 'test.*',
|
||||
user => 'test1@tester',
|
||||
}
|
||||
EOS
|
||||
|
||||
puppet_apply(pp) do |r|
|
||||
r.stderr.should =~ /privileges parameter is required/
|
||||
end
|
||||
end
|
||||
|
||||
it 'should not find the user' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR test1@tester\"") do |r|
|
||||
r.stderr.should =~ /There is no such grant defined for user 'test1' on host 'tester'/
|
||||
r.exit_code.should eq 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'missing table for user' do
|
||||
it 'should fail' do
|
||||
pp = <<-EOS
|
||||
mysql_grant { 'atest@tester/test.*':
|
||||
ensure => 'present',
|
||||
user => 'atest@tester',
|
||||
privileges => ['ALL'],
|
||||
}
|
||||
EOS
|
||||
|
||||
puppet_apply(pp) do |r|
|
||||
r.exit_code.should eq 1
|
||||
end
|
||||
end
|
||||
|
||||
it 'should not find the user' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR atest@tester\"") do |r|
|
||||
r.stderr.should =~ /There is no such grant defined for user 'atest' on host 'tester'/
|
||||
r.exit_code.should eq 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'adding privileges' do
|
||||
it 'should work without errors' do
|
||||
pp = <<-EOS
|
||||
mysql_grant { 'test2@tester/test.*':
|
||||
ensure => 'present',
|
||||
table => 'test.*',
|
||||
user => 'test2@tester',
|
||||
privileges => ['SELECT', 'UPDATE'],
|
||||
}
|
||||
EOS
|
||||
|
||||
puppet_apply(pp)
|
||||
end
|
||||
|
||||
it 'should find the user' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR test2@tester\"") do |r|
|
||||
r.stdout.should =~ /GRANT SELECT, UPDATE.*TO 'test2'@'tester'/
|
||||
r.stderr.should be_empty
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'adding option' do
|
||||
it 'should work without errors' do
|
||||
pp = <<-EOS
|
||||
mysql_grant { 'test3@tester/test.*':
|
||||
ensure => 'present',
|
||||
table => 'test.*',
|
||||
user => 'test3@tester',
|
||||
options => ['GRANT'],
|
||||
privileges => ['SELECT', 'UPDATE'],
|
||||
}
|
||||
EOS
|
||||
|
||||
puppet_apply(pp)
|
||||
end
|
||||
|
||||
it 'should find the user' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR test3@tester\"") do |r|
|
||||
r.stdout.should =~ /GRANT SELECT, UPDATE ON `test`.* TO 'test3'@'tester' WITH GRANT OPTION$/
|
||||
r.stderr.should be_empty
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'adding all privileges without table' do
|
||||
it 'should fail' do
|
||||
pp = <<-EOS
|
||||
mysql_grant { 'test4@tester/test.*':
|
||||
ensure => 'present',
|
||||
user => 'test4@tester',
|
||||
options => ['GRANT'],
|
||||
privileges => ['SELECT', 'UPDATE', 'ALL'],
|
||||
}
|
||||
EOS
|
||||
|
||||
puppet_apply(pp) do |r|
|
||||
r.stderr.should =~ /table parameter is required./
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
describe 'adding all privileges' do
|
||||
it 'should only try to apply ALL' do
|
||||
pp = <<-EOS
|
||||
mysql_grant { 'test4@tester/test.*':
|
||||
ensure => 'present',
|
||||
table => 'test.*',
|
||||
user => 'test4@tester',
|
||||
options => ['GRANT'],
|
||||
privileges => ['SELECT', 'UPDATE', 'ALL'],
|
||||
}
|
||||
EOS
|
||||
|
||||
puppet_apply(pp)
|
||||
end
|
||||
|
||||
it 'should find the user' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR test4@tester\"") do |r|
|
||||
r.stdout.should =~ /GRANT ALL PRIVILEGES ON `test`.* TO 'test4'@'tester' WITH GRANT OPTION/
|
||||
r.stderr.should be_empty
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Test combinations of user@host to ensure all cases work.
|
||||
describe 'short hostname' do
|
||||
it 'should apply' do
|
||||
pp = <<-EOS
|
||||
mysql_grant { 'test@short/test.*':
|
||||
ensure => 'present',
|
||||
table => 'test.*',
|
||||
user => 'test@short',
|
||||
privileges => 'ALL',
|
||||
}
|
||||
mysql_grant { 'test@long.hostname.com/test.*':
|
||||
ensure => 'present',
|
||||
table => 'test.*',
|
||||
user => 'test@long.hostname.com',
|
||||
privileges => 'ALL',
|
||||
}
|
||||
mysql_grant { 'test@192.168.5.6/test.*':
|
||||
ensure => 'present',
|
||||
table => 'test.*',
|
||||
user => 'test@192.168.5.6',
|
||||
privileges => 'ALL',
|
||||
}
|
||||
mysql_grant { 'test@2607:f0d0:1002:0051:0000:0000:0000:0004/test.*':
|
||||
ensure => 'present',
|
||||
table => 'test.*',
|
||||
user => 'test@2607:f0d0:1002:0051:0000:0000:0000:0004',
|
||||
privileges => 'ALL',
|
||||
}
|
||||
mysql_grant { 'test@::1/128/test.*':
|
||||
ensure => 'present',
|
||||
table => 'test.*',
|
||||
user => 'test@::1/128',
|
||||
privileges => 'ALL',
|
||||
}
|
||||
EOS
|
||||
|
||||
puppet_apply(pp)
|
||||
end
|
||||
|
||||
it 'finds short hostname' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR test@short\"") do |r|
|
||||
r.stdout.should =~ /GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'short'/
|
||||
r.stderr.should be_empty
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
it 'finds long hostname' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'long.hostname.com'\"") do |r|
|
||||
r.stdout.should =~ /GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'long.hostname.com'/
|
||||
r.stderr.should be_empty
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
it 'finds ipv4' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'192.168.5.6'\"") do |r|
|
||||
r.stdout.should =~ /GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'192.168.5.6'/
|
||||
r.stderr.should be_empty
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
it 'finds ipv6' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'2607:f0d0:1002:0051:0000:0000:0000:0004'\"") do |r|
|
||||
r.stdout.should =~ /GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'2607:f0d0:1002:0051:0000:0000:0000:0004'/
|
||||
r.stderr.should be_empty
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
it 'finds short ipv6' do
|
||||
shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'::1/128'\"") do |r|
|
||||
r.stdout.should =~ /GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'::1\/128'/
|
||||
r.stderr.should be_empty
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'complex test' do
|
||||
it 'setup mysql::server' do
|
||||
pp = <<-EOS
|
||||
$dbSubnet = '10.10.10.%'
|
||||
|
||||
mysql_database { 'foo':
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
exec { 'mysql-create-table':
|
||||
command => '/usr/bin/mysql -NBe "CREATE TABLE foo.bar (name VARCHAR(20))"',
|
||||
environment => "HOME=${::root_home}",
|
||||
unless => '/usr/bin/mysql -NBe "SELECT 1 FROM foo.bar LIMIT 1;"',
|
||||
require => Mysql_database['foo'],
|
||||
}
|
||||
|
||||
Mysql_grant {
|
||||
ensure => present,
|
||||
options => ['GRANT'],
|
||||
privileges => ['ALL'],
|
||||
table => '*.*',
|
||||
require => [ Mysql_database['foo'], Exec['mysql-create-table'] ],
|
||||
}
|
||||
|
||||
mysql_grant { "user1@${dbSubnet}/*.*":
|
||||
user => "user1@${dbSubnet}",
|
||||
}
|
||||
mysql_grant { "user2@${dbSubnet}/foo.bar":
|
||||
privileges => ['SELECT', 'INSERT', 'UPDATE'],
|
||||
user => "user2@${dbSubnet}",
|
||||
table => 'foo.bar',
|
||||
}
|
||||
mysql_grant { "user3@${dbSubnet}/foo.*":
|
||||
privileges => ['SELECT', 'INSERT', 'UPDATE'],
|
||||
user => "user3@${dbSubnet}",
|
||||
table => 'foo.*',
|
||||
}
|
||||
mysql_grant { 'web@%/*.*':
|
||||
user => 'web@%',
|
||||
}
|
||||
mysql_grant { "web@${dbSubnet}/*.*":
|
||||
user => "web@${dbSubnet}",
|
||||
}
|
||||
mysql_grant { "web@${fqdn}/*.*":
|
||||
user => "web@${fqdn}",
|
||||
}
|
||||
mysql_grant { 'web@localhost/*.*':
|
||||
user => 'web@localhost',
|
||||
}
|
||||
EOS
|
||||
|
||||
puppet_apply(pp) do |r|
|
||||
r.exit_code.should_not == 1
|
||||
r.refresh
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'lower case privileges' do
|
||||
it 'create ALL privs' do
|
||||
pp = <<-EOS
|
||||
mysql_grant { 'lowercase@localhost/*.*':
|
||||
user => 'lowercase@localhost',
|
||||
privileges => 'ALL',
|
||||
table => '*.*',
|
||||
}
|
||||
EOS
|
||||
|
||||
puppet_apply(pp)
|
||||
end
|
||||
|
||||
it 'create lowercase all privs' do
|
||||
pp = <<-EOS
|
||||
mysql_grant { 'lowercase@localhost/*.*':
|
||||
user => 'lowercase@localhost',
|
||||
privileges => 'all',
|
||||
table => '*.*',
|
||||
}
|
||||
EOS
|
||||
|
||||
puppet_apply(pp) do |r|
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,35 @@
|
||||
require 'spec_helper_system'
|
||||
|
||||
describe 'mysql_user' do
|
||||
|
||||
describe 'setup' do
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': }
|
||||
EOS
|
||||
|
||||
puppet_apply(pp)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'adding user' do
|
||||
it 'should work without errors' do
|
||||
pp = <<-EOS
|
||||
mysql_user { 'ashp@localhost':
|
||||
password_hash => '6f8c114b58f2ce9e',
|
||||
}
|
||||
EOS
|
||||
|
||||
puppet_apply(pp)
|
||||
end
|
||||
|
||||
it 'should find the user' do
|
||||
shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r|
|
||||
r.stdout.should =~ /^1$/
|
||||
r.stderr.should be_empty
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,27 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'the mysql_password function' do
|
||||
before :all do
|
||||
Puppet::Parser::Functions.autoloader.loadall
|
||||
end
|
||||
|
||||
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
||||
|
||||
it 'should exist' do
|
||||
Puppet::Parser::Functions.function('mysql_password').should == 'function_mysql_password'
|
||||
end
|
||||
|
||||
it 'should raise a ParseError if there is less than 1 arguments' do
|
||||
lambda { scope.function_mysql_password([]) }.should( raise_error(Puppet::ParseError))
|
||||
end
|
||||
|
||||
it 'should raise a ParseError if there is more than 1 arguments' do
|
||||
lambda { scope.function_mysql_password(%w(foo bar)) }.should( raise_error(Puppet::ParseError))
|
||||
end
|
||||
|
||||
it 'should convert password into a hash' do
|
||||
result = scope.function_mysql_password(%w(password))
|
||||
result.should(eq('*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19'))
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,91 @@
|
||||
#! /usr/bin/env ruby -S rspec
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Puppet::Parser::Functions.function(:mysql_deepmerge) do
|
||||
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
||||
|
||||
describe 'when calling mysql_deepmerge from puppet' do
|
||||
it "should not compile when no arguments are passed" do
|
||||
pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
|
||||
Puppet[:code] = '$x = mysql_deepmerge()'
|
||||
expect {
|
||||
scope.compiler.compile
|
||||
}.to raise_error(Puppet::ParseError, /wrong number of arguments/)
|
||||
end
|
||||
|
||||
it "should not compile when 1 argument is passed" do
|
||||
pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
|
||||
Puppet[:code] = "$my_hash={'one' => 1}\n$x = mysql_deepmerge($my_hash)"
|
||||
expect {
|
||||
scope.compiler.compile
|
||||
}.to raise_error(Puppet::ParseError, /wrong number of arguments/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when calling mysql_deepmerge on the scope instance' do
|
||||
it 'should require all parameters are hashes' do
|
||||
expect { new_hash = scope.function_mysql_deepmerge([{}, '2'])}.to raise_error(Puppet::ParseError, /unexpected argument type String/)
|
||||
expect { new_hash = scope.function_mysql_deepmerge([{}, 2])}.to raise_error(Puppet::ParseError, /unexpected argument type Fixnum/)
|
||||
end
|
||||
|
||||
it 'should accept empty strings as puppet undef' do
|
||||
expect { new_hash = scope.function_mysql_deepmerge([{}, ''])}.not_to raise_error
|
||||
end
|
||||
|
||||
it 'should be able to mysql_deepmerge two hashes' do
|
||||
new_hash = scope.function_mysql_deepmerge([{'one' => '1', 'two' => '1'}, {'two' => '2', 'three' => '2'}])
|
||||
new_hash['one'].should == '1'
|
||||
new_hash['two'].should == '2'
|
||||
new_hash['three'].should == '2'
|
||||
end
|
||||
|
||||
it 'should mysql_deepmerge multiple hashes' do
|
||||
hash = scope.function_mysql_deepmerge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}])
|
||||
hash['one'].should == '3'
|
||||
end
|
||||
|
||||
it 'should accept empty hashes' do
|
||||
scope.function_mysql_deepmerge([{},{},{}]).should == {}
|
||||
end
|
||||
|
||||
it 'should mysql_deepmerge subhashes' do
|
||||
hash = scope.function_mysql_deepmerge([{'one' => 1}, {'two' => 2, 'three' => { 'four' => 4 } }])
|
||||
hash['one'].should == 1
|
||||
hash['two'].should == 2
|
||||
hash['three'].should == { 'four' => 4 }
|
||||
end
|
||||
|
||||
it 'should append to subhashes' do
|
||||
hash = scope.function_mysql_deepmerge([{'one' => { 'two' => 2 } }, { 'one' => { 'three' => 3 } }])
|
||||
hash['one'].should == { 'two' => 2, 'three' => 3 }
|
||||
end
|
||||
|
||||
it 'should append to subhashes 2' do
|
||||
hash = scope.function_mysql_deepmerge([{'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } }, {'two' => 'dos', 'three' => { 'five' => 5 } }])
|
||||
hash['one'].should == 1
|
||||
hash['two'].should == 'dos'
|
||||
hash['three'].should == { 'four' => 4, 'five' => 5 }
|
||||
end
|
||||
|
||||
it 'should append to subhashes 3' do
|
||||
hash = scope.function_mysql_deepmerge([{ 'key1' => { 'a' => 1, 'b' => 2 }, 'key2' => { 'c' => 3 } }, { 'key1' => { 'b' => 99 } }])
|
||||
hash['key1'].should == { 'a' => 1, 'b' => 99 }
|
||||
hash['key2'].should == { 'c' => 3 }
|
||||
end
|
||||
|
||||
it 'should equate keys mod dash and underscore' do
|
||||
hash = scope.function_mysql_deepmerge([{ 'a-b-c' => 1 } , { 'a_b_c' => 10 }])
|
||||
hash['a_b_c'].should == 10
|
||||
hash.should_not have_key('a-b-c')
|
||||
end
|
||||
|
||||
it 'should keep style of the last when keys are euqal mod dash and underscore' do
|
||||
hash = scope.function_mysql_deepmerge([{ 'a-b-c' => 1, 'b_c_d' => { 'c-d-e' => 2, 'e-f-g' => 3 }} , { 'a_b_c' => 10, 'b-c-d' => { 'c_d_e' => 12 } }])
|
||||
hash['a_b_c'].should == 10
|
||||
hash.should_not have_key('a-b-c')
|
||||
hash['b-c-d'].should == { 'e-f-g' => 3, 'c_d_e' => 12 }
|
||||
hash.should_not have_key('b_c_d')
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,86 @@
|
||||
require 'spec_helper'
|
||||
|
||||
provider_class = Puppet::Type.type(:database).provider(:mysql)
|
||||
|
||||
describe provider_class do
|
||||
subject { provider_class }
|
||||
|
||||
let(:root_home) { '/root' }
|
||||
let(:defaults_file) { '--defaults-extra-file=/root/.my.cnf' }
|
||||
|
||||
let(:raw_databases) do
|
||||
<<-SQL_OUTPUT
|
||||
information_schema
|
||||
mydb
|
||||
mysql
|
||||
performance_schema
|
||||
test
|
||||
SQL_OUTPUT
|
||||
end
|
||||
|
||||
let(:parsed_databases) { %w(information_schema mydb mysql performance_schema test) }
|
||||
|
||||
before :each do
|
||||
@resource = Puppet::Type::Database.new(
|
||||
{ :charset => 'utf8', :name => 'new_database' }
|
||||
)
|
||||
@provider = provider_class.new(@resource)
|
||||
Facter.stubs(:value).with(:root_home).returns(root_home)
|
||||
Puppet::Util.stubs(:which).with('mysql').returns('/usr/bin/mysql')
|
||||
subject.stubs(:which).with('mysql').returns('/usr/bin/mysql')
|
||||
subject.stubs(:defaults_file).returns('--defaults-extra-file=/root/.my.cnf')
|
||||
end
|
||||
|
||||
describe 'self.instances' do
|
||||
it 'returns an array of databases' do
|
||||
subject.stubs(:mysql).with([defaults_file, '-NBe', 'show databases']).returns(raw_databases)
|
||||
|
||||
databases = subject.instances.collect {|x| x.name }
|
||||
parsed_databases.should match_array(databases)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'create' do
|
||||
it 'makes a user' do
|
||||
subject.expects(:mysql).with([defaults_file, '-NBe', "create database `#{@resource[:name]}` character set #{@resource[:charset]}"])
|
||||
@provider.create
|
||||
end
|
||||
end
|
||||
|
||||
describe 'destroy' do
|
||||
it 'removes a user if present' do
|
||||
subject.expects(:mysqladmin).with([defaults_file, '-f', 'drop', "#{@resource[:name]}"])
|
||||
@provider.destroy
|
||||
end
|
||||
end
|
||||
|
||||
describe 'charset' do
|
||||
it 'returns a charset' do
|
||||
subject.expects(:mysql).with([defaults_file, '-NBe', "show create database `#{@resource[:name]}`"]).returns('mydbCREATE DATABASE `mydb` /*!40100 DEFAULT CHARACTER SET utf8 */')
|
||||
@provider.charset.should == 'utf8'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'charset=' do
|
||||
it 'changes the charset' do
|
||||
subject.expects(:mysql).with([defaults_file, '-NBe', "alter database `#{@resource[:name]}` CHARACTER SET blah"]).returns('0')
|
||||
|
||||
@provider.charset=('blah')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'exists?' do
|
||||
it 'checks if user exists' do
|
||||
subject.expects(:mysql).with([defaults_file, '-NBe', 'show databases']).returns('information_schema\nmydb\nmysql\nperformance_schema\ntest')
|
||||
@provider.exists?
|
||||
end
|
||||
end
|
||||
|
||||
describe 'self.defaults_file' do
|
||||
it 'sets --defaults-extra-file' do
|
||||
File.stubs(:file?).with('#{root_home}/.my.cnf').returns(true)
|
||||
@provider.defaults_file.should == '--defaults-extra-file=/root/.my.cnf'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,95 @@
|
||||
require 'puppet'
|
||||
require 'mocha/api'
|
||||
require 'spec_helper'
|
||||
RSpec.configure do |config|
|
||||
config.mock_with :mocha
|
||||
end
|
||||
provider_class = Puppet::Type.type(:database_grant).provider(:mysql)
|
||||
describe provider_class do
|
||||
let(:root_home) { '/root' }
|
||||
|
||||
before :each do
|
||||
@resource = Puppet::Type::Database_grant.new(
|
||||
{ :privileges => 'all', :provider => 'mysql', :name => 'user@host'}
|
||||
)
|
||||
@provider = provider_class.new(@resource)
|
||||
Facter.stubs(:value).with(:root_home).returns(root_home)
|
||||
File.stubs(:file?).with("#{root_home}/.my.cnf").returns(true)
|
||||
end
|
||||
|
||||
it 'should query privileges from the database' do
|
||||
provider_class.expects(:mysql) .with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-Be', 'describe user']).returns <<-EOT
|
||||
Field Type Null Key Default Extra
|
||||
Host char(60) NO PRI
|
||||
User char(16) NO PRI
|
||||
Password char(41) NO
|
||||
Select_priv enum('N','Y') NO N
|
||||
Insert_priv enum('N','Y') NO N
|
||||
Update_priv enum('N','Y') NO N
|
||||
EOT
|
||||
provider_class.expects(:mysql).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-Be', 'describe db']).returns <<-EOT
|
||||
Field Type Null Key Default Extra
|
||||
Host char(60) NO PRI
|
||||
Db char(64) NO PRI
|
||||
User char(16) NO PRI
|
||||
Select_priv enum('N','Y') NO N
|
||||
Insert_priv enum('N','Y') NO N
|
||||
Update_priv enum('N','Y') NO N
|
||||
EOT
|
||||
provider_class.user_privs.should == %w(Select_priv Insert_priv Update_priv)
|
||||
provider_class.db_privs.should == %w(Select_priv Insert_priv Update_priv)
|
||||
end
|
||||
|
||||
it 'should query set privileges' do
|
||||
provider_class.expects(:mysql).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-Be', "select * from mysql.user where user='user' and host='host'"]).returns <<-EOT
|
||||
Host User Password Select_priv Insert_priv Update_priv
|
||||
host user Y N Y
|
||||
EOT
|
||||
@provider.privileges.should == %w(Select_priv Update_priv)
|
||||
end
|
||||
|
||||
it 'should recognize when all privileges are set' do
|
||||
provider_class.expects(:mysql).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-Be', "select * from mysql.user where user='user' and host='host'"]).returns <<-EOT
|
||||
Host User Password Select_priv Insert_priv Update_priv
|
||||
host user Y Y Y
|
||||
EOT
|
||||
@provider.all_privs_set?.should == true
|
||||
end
|
||||
|
||||
it 'should recognize when all privileges are not set' do
|
||||
provider_class.expects(:mysql).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-Be', "select * from mysql.user where user='user' and host='host'"]).returns <<-EOT
|
||||
Host User Password Select_priv Insert_priv Update_priv
|
||||
host user Y N Y
|
||||
EOT
|
||||
@provider.all_privs_set?.should == false
|
||||
end
|
||||
|
||||
it 'should be able to set all privileges' do
|
||||
provider_class.expects(:mysql).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-NBe', "SELECT '1' FROM user WHERE user='user' AND host='host'"]).returns "1\n"
|
||||
provider_class.expects(:mysql).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'Y', Update_priv = 'Y' where user='user' and host='host'"])
|
||||
provider_class.expects(:mysqladmin).with(%W(--defaults-extra-file=#{root_home}/.my.cnf flush-privileges))
|
||||
@provider.privileges=(%w(all))
|
||||
end
|
||||
|
||||
it 'should be able to set partial privileges' do
|
||||
provider_class.expects(:mysql).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-NBe', "SELECT '1' FROM user WHERE user='user' AND host='host'"]).returns "1\n"
|
||||
provider_class.expects(:mysql).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'N', Update_priv = 'Y' where user='user' and host='host'"])
|
||||
provider_class.expects(:mysqladmin).with(%W(--defaults-extra-file=#{root_home}/.my.cnf flush-privileges))
|
||||
@provider.privileges=(%w(Select_priv Update_priv))
|
||||
end
|
||||
|
||||
it 'should be case insensitive' do
|
||||
provider_class.expects(:mysql).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-NBe', "SELECT '1' FROM user WHERE user='user' AND host='host'"]).returns "1\n"
|
||||
provider_class.expects(:mysql).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'Y', Update_priv = 'Y' where user='user' and host='host'"])
|
||||
provider_class.expects(:mysqladmin).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'flush-privileges'])
|
||||
@provider.privileges=(%w(SELECT_PRIV insert_priv UpDaTe_pRiV))
|
||||
end
|
||||
|
||||
it 'should not pass --defaults-extra-file if $root_home/.my.cnf is absent' do
|
||||
File.stubs(:file?).with("#{root_home}/.my.cnf").returns(false)
|
||||
provider_class.expects(:mysql).with(['mysql', '-NBe', "SELECT '1' FROM user WHERE user='user' AND host='host'"]).returns "1\n"
|
||||
provider_class.expects(:mysql).with(['mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'N', Update_priv = 'Y' where user='user' and host='host'"])
|
||||
provider_class.expects(:mysqladmin).with(%w(flush-privileges))
|
||||
@provider.privileges=(%w(Select_priv Update_priv))
|
||||
end
|
||||
end
|
@@ -0,0 +1,119 @@
|
||||
require 'spec_helper'
|
||||
|
||||
provider_class = Puppet::Type.type(:database_user).provider(:mysql)
|
||||
|
||||
describe provider_class do
|
||||
subject { provider_class }
|
||||
|
||||
let(:root_home) { '/root' }
|
||||
let(:defaults_file) { '--defaults-extra-file=/root/.my.cnf' }
|
||||
let(:newhash) { '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5' }
|
||||
|
||||
let(:raw_users) do
|
||||
<<-SQL_OUTPUT
|
||||
root@127.0.0.1
|
||||
root@::1
|
||||
@localhost
|
||||
debian-sys-maint@localhost
|
||||
root@localhost
|
||||
usvn_user@localhost
|
||||
@vagrant-ubuntu-raring-64
|
||||
SQL_OUTPUT
|
||||
end
|
||||
|
||||
let(:parsed_users) { %w(root@127.0.0.1 root@::1 debian-sys-maint@localhost root@localhost usvn_user@localhost) }
|
||||
|
||||
before :each do
|
||||
# password hash = mypass
|
||||
@resource = Puppet::Type::Database_user.new(
|
||||
{ :password_hash => '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4',
|
||||
:name => 'joe@localhost',
|
||||
:max_user_connections => '10'
|
||||
}
|
||||
)
|
||||
@provider = provider_class.new(@resource)
|
||||
Facter.stubs(:value).with(:root_home).returns(root_home)
|
||||
Puppet::Util.stubs(:which).with('mysql').returns('/usr/bin/mysql')
|
||||
subject.stubs(:which).with('mysql').returns('/usr/bin/mysql')
|
||||
subject.stubs(:defaults_file).returns('--defaults-extra-file=/root/.my.cnf')
|
||||
end
|
||||
|
||||
describe 'self.instances' do
|
||||
it 'returns an array of users' do
|
||||
subject.stubs(:mysql).with([defaults_file, 'mysql', "-BNeselect concat(User, '@',Host) as User from mysql.user"]).returns(raw_users)
|
||||
|
||||
usernames = subject.instances.collect {|x| x.name }
|
||||
parsed_users.should match_array(usernames)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'create' do
|
||||
it 'makes a user' do
|
||||
subject.expects(:mysql).with([defaults_file, 'mysql', '-e', "grant usage on *.* to 'joe'@'localhost' identified by PASSWORD
|
||||
'*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4' with max_user_connections 10"])
|
||||
@provider.expects(:exists?).returns(true)
|
||||
@provider.create.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'destroy' do
|
||||
it 'removes a user if present' do
|
||||
subject.expects(:mysql).with([defaults_file, 'mysql', '-e', "drop user 'joe'@'localhost'"])
|
||||
@provider.expects(:exists?).returns(false)
|
||||
@provider.destroy.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'password_hash' do
|
||||
it 'returns a hash' do
|
||||
subject.expects(:mysql).with([defaults_file, 'mysql', '-NBe', "select password from mysql.user where CONCAT(user, '@', host) = 'joe@localhost'"]).returns('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4')
|
||||
@provider.password_hash.should == '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'password_hash=' do
|
||||
it 'changes the hash' do
|
||||
subject.expects(:mysql).with([defaults_file, 'mysql', '-e', "SET PASSWORD FOR 'joe'@'localhost' = '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5'"]).returns('0')
|
||||
|
||||
@provider.expects(:password_hash).returns('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5')
|
||||
@provider.password_hash=('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'max_user_connections' do
|
||||
it 'returns max user connections' do
|
||||
subject.expects(:mysql).with([defaults_file, 'mysql', '-NBe', "select max_user_connections from mysql.user where CONCAT(user, '@', host) = 'joe@localhost'"]).returns('10')
|
||||
@provider.max_user_connections.should == '10'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'max_user_connections=' do
|
||||
it 'changes max user connections' do
|
||||
subject.expects(:mysql).with([defaults_file, 'mysql', '-e', "grant usage on *.* to 'joe'@'localhost' with max_user_connections 42"]).returns('0')
|
||||
@provider.expects(:max_user_connections).returns('42')
|
||||
@provider.max_user_connections=('42')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'exists?' do
|
||||
it 'checks if user exists' do
|
||||
subject.expects(:mysql).with([defaults_file, 'mysql', '-NBe', "select '1' from mysql.user where CONCAT(user, '@', host) = 'joe@localhost'"]).returns('1')
|
||||
@provider.exists?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'flush' do
|
||||
it 'removes cached privileges' do
|
||||
subject.expects(:mysqladmin).with([defaults_file, 'flush-privileges'])
|
||||
@provider.flush
|
||||
end
|
||||
end
|
||||
|
||||
describe 'self.defaults_file' do
|
||||
it 'sets --defaults-extra-file' do
|
||||
File.stubs(:file?).with('#{root_home}/.my.cnf').returns(true)
|
||||
@provider.defaults_file.should == '--defaults-extra-file=/root/.my.cnf'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,118 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Puppet::Type.type(:mysql_database).provider(:mysql) do
|
||||
|
||||
let(:defaults_file) { '--defaults-extra-file=/root/.my.cnf' }
|
||||
|
||||
let(:raw_databases) do
|
||||
<<-SQL_OUTPUT
|
||||
information_schema
|
||||
mydb
|
||||
mysql
|
||||
performance_schema
|
||||
test
|
||||
SQL_OUTPUT
|
||||
end
|
||||
|
||||
let(:parsed_databases) { %w(information_schema mydb mysql performance_schema test) }
|
||||
|
||||
let(:resource) { Puppet::Type.type(:mysql_database).new(
|
||||
{ :ensure => :present,
|
||||
:charset => 'latin1',
|
||||
:collate => 'latin1_swedish_ci',
|
||||
:name => 'new_database',
|
||||
:provider => described_class.name
|
||||
}
|
||||
)}
|
||||
let(:provider) { resource.provider }
|
||||
|
||||
before :each do
|
||||
Facter.stubs(:value).with(:root_home).returns('/root')
|
||||
Puppet::Util.stubs(:which).with('mysql').returns('/usr/bin/mysql')
|
||||
File.stubs(:file?).with('/root/.my.cnf').returns(true)
|
||||
provider.class.stubs(:mysql).with([defaults_file, '-NBe', 'show databases']).returns('new_database')
|
||||
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "show variables like '%_database'", 'new_database']).returns("character_set_database latin1\ncollation_database latin1_swedish_ci\nskip_show_database OFF")
|
||||
end
|
||||
|
||||
let(:instance) { provider.class.instances.first }
|
||||
|
||||
describe 'self.instances' do
|
||||
it 'returns an array of databases' do
|
||||
provider.class.stubs(:mysql).with([defaults_file, '-NBe', 'show databases']).returns(raw_databases)
|
||||
raw_databases.each_line do |db|
|
||||
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "show variables like '%_database'", db.chomp]).returns("character_set_database latin1\ncollation_database latin1_swedish_ci\nskip_show_database OFF")
|
||||
end
|
||||
databases = provider.class.instances.collect {|x| x.name }
|
||||
parsed_databases.should match_array(databases)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'self.prefetch' do
|
||||
it 'exists' do
|
||||
provider.class.instances
|
||||
provider.class.prefetch({})
|
||||
end
|
||||
end
|
||||
|
||||
describe 'create' do
|
||||
it 'makes a database' do
|
||||
provider.expects(:mysql).with([defaults_file, '-NBe', "create database if not exists `#{resource[:name]}` character set #{resource[:charset]} collate #{resource[:collate]}"])
|
||||
provider.expects(:exists?).returns(true)
|
||||
provider.create.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'destroy' do
|
||||
it 'removes a database if present' do
|
||||
provider.expects(:mysql).with([defaults_file, '-NBe', "drop database `#{resource[:name]}`"])
|
||||
provider.expects(:exists?).returns(false)
|
||||
provider.destroy.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'exists?' do
|
||||
it 'checks if database exists' do
|
||||
instance.exists?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'self.defaults_file' do
|
||||
it 'sets --defaults-extra-file' do
|
||||
File.stubs(:file?).with('/root/.my.cnf').returns(true)
|
||||
provider.defaults_file.should eq '--defaults-extra-file=/root/.my.cnf'
|
||||
end
|
||||
it 'fails if file missing' do
|
||||
File.stubs(:file?).with('/root/.my.cnf').returns(false)
|
||||
provider.defaults_file.should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'charset' do
|
||||
it 'returns a charset' do
|
||||
instance.charset.should == 'latin1'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'charset=' do
|
||||
it 'changes the charset' do
|
||||
provider.expects(:mysql).with([defaults_file, '-NBe', "alter database `#{resource[:name]}` CHARACTER SET blah"]).returns('0')
|
||||
|
||||
provider.charset=('blah')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'collate' do
|
||||
it 'returns a collate' do
|
||||
instance.collate.should == 'latin1_swedish_ci'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'collate=' do
|
||||
it 'changes the collate' do
|
||||
provider.expects(:mysql).with([defaults_file, '-NBe', "alter database `#{resource[:name]}` COLLATE blah"]).returns('0')
|
||||
|
||||
provider.collate=('blah')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,130 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Puppet::Type.type(:mysql_user).provider(:mysql) do
|
||||
let(:defaults_file) { '--defaults-extra-file=/root/.my.cnf' }
|
||||
let(:newhash) { '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5' }
|
||||
|
||||
let(:raw_users) do
|
||||
<<-SQL_OUTPUT
|
||||
root@127.0.0.1
|
||||
root@::1
|
||||
@localhost
|
||||
debian-sys-maint@localhost
|
||||
root@localhost
|
||||
usvn_user@localhost
|
||||
@vagrant-ubuntu-raring-64
|
||||
SQL_OUTPUT
|
||||
end
|
||||
|
||||
let(:parsed_users) { %w(root@127.0.0.1 root@::1 @localhost debian-sys-maint@localhost root@localhost usvn_user@localhost @vagrant-ubuntu-raring-64) }
|
||||
|
||||
let(:resource) { Puppet::Type.type(:mysql_user).new(
|
||||
{ :ensure => :present,
|
||||
:password_hash => '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4',
|
||||
:name => 'joe@localhost',
|
||||
:max_user_connections => '10',
|
||||
:max_connections_per_hour => '10',
|
||||
:max_queries_per_hour => '10',
|
||||
:max_updates_per_hour => '10',
|
||||
:provider => described_class.name
|
||||
}
|
||||
)}
|
||||
let(:provider) { resource.provider }
|
||||
|
||||
before :each do
|
||||
# Set up the stubs for an instances call.
|
||||
Facter.stubs(:value).with(:root_home).returns('/root')
|
||||
Puppet::Util.stubs(:which).with('mysql').returns('/usr/bin/mysql')
|
||||
File.stubs(:file?).with('/root/.my.cnf').returns(true)
|
||||
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns('joe@localhost')
|
||||
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, PASSWORD FROM mysql.user WHERE CONCAT(user, '@', host) = 'joe@localhost'"]).returns('10 10 10 10 *6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4')
|
||||
end
|
||||
|
||||
let(:instance) { provider.class.instances.first }
|
||||
|
||||
describe 'self.instances' do
|
||||
it 'returns an array of users' do
|
||||
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns(raw_users)
|
||||
parsed_users.each do |user|
|
||||
provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, PASSWORD FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ')
|
||||
end
|
||||
|
||||
usernames = provider.class.instances.collect {|x| x.name }
|
||||
parsed_users.should match_array(usernames)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'self.prefetch' do
|
||||
it 'exists' do
|
||||
provider.class.instances
|
||||
provider.class.prefetch({})
|
||||
end
|
||||
end
|
||||
|
||||
describe 'create' do
|
||||
it 'makes a user' do
|
||||
provider.expects(:mysql).with([defaults_file, '-e', "GRANT USAGE ON *.* TO 'joe'@'localhost' IDENTIFIED BY PASSWORD '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4' WITH MAX_USER_CONNECTIONS 10 MAX_CONNECTIONS_PER_HOUR 10 MAX_QUERIES_PER_HOUR 10 MAX_UPDATES_PER_HOUR 10"])
|
||||
provider.expects(:exists?).returns(true)
|
||||
provider.create.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'destroy' do
|
||||
it 'removes a user if present' do
|
||||
provider.expects(:mysql).with([defaults_file, '-e', "DROP USER 'joe'@'localhost'"])
|
||||
provider.expects(:exists?).returns(false)
|
||||
provider.destroy.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'exists?' do
|
||||
it 'checks if user exists' do
|
||||
instance.exists?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'self.defaults_file' do
|
||||
it 'sets --defaults-extra-file' do
|
||||
File.stubs(:file?).with('/root/.my.cnf').returns(true)
|
||||
provider.defaults_file.should eq '--defaults-extra-file=/root/.my.cnf'
|
||||
end
|
||||
it 'fails if file missing' do
|
||||
File.expects(:file?).with('/root/.my.cnf').returns(false)
|
||||
provider.defaults_file.should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'password_hash' do
|
||||
it 'returns a hash' do
|
||||
instance.password_hash.should == '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'password_hash=' do
|
||||
it 'changes the hash' do
|
||||
provider.expects(:mysql).with([defaults_file, '-e', "SET PASSWORD FOR 'joe'@'localhost' = '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5'"]).returns('0')
|
||||
|
||||
provider.expects(:password_hash).returns('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5')
|
||||
provider.password_hash=('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5')
|
||||
end
|
||||
end
|
||||
|
||||
['max_user_connections', 'max_connections_per_hour', 'max_queries_per_hour',
|
||||
'max_updates_per_hour'].each do |property|
|
||||
|
||||
describe property do
|
||||
it "returns #{property}" do
|
||||
instance.send("#{property}".to_sym).should == '10'
|
||||
end
|
||||
end
|
||||
|
||||
describe "#{property}=" do
|
||||
it "changes #{property}" do
|
||||
provider.expects(:mysql).with([defaults_file, '-e', "GRANT USAGE ON *.* TO 'joe'@'localhost' WITH #{property.upcase} 42"]).returns('0')
|
||||
provider.expects(property.to_sym).returns('42')
|
||||
provider.send("#{property}=".to_sym, '42')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,29 @@
|
||||
require 'puppet'
|
||||
require 'puppet/type/mysql_database'
|
||||
describe Puppet::Type.type(:mysql_database) do
|
||||
|
||||
before :each do
|
||||
@user = Puppet::Type.type(:mysql_database).new(:name => 'test', :charset => 'utf8', :collate => 'utf8_blah_ci')
|
||||
end
|
||||
|
||||
it 'should accept a database name' do
|
||||
@user[:name].should == 'test'
|
||||
end
|
||||
|
||||
it 'should accept a charset' do
|
||||
@user[:charset] = 'latin1'
|
||||
@user[:charset].should == 'latin1'
|
||||
end
|
||||
|
||||
it 'should accept a collate' do
|
||||
@user[:collate] = 'latin1_swedish_ci'
|
||||
@user[:collate].should == 'latin1_swedish_ci'
|
||||
end
|
||||
|
||||
it 'should require a name' do
|
||||
expect {
|
||||
Puppet::Type.type(:mysql_database).new({})
|
||||
}.to raise_error(Puppet::Error, 'Title or name must be provided')
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,44 @@
|
||||
require 'puppet'
|
||||
require 'puppet/type/mysql_grant'
|
||||
describe Puppet::Type.type(:mysql_grant) do
|
||||
|
||||
before :each do
|
||||
@user = Puppet::Type.type(:mysql_grant).new(:name => 'foo@localhost/*.*', :privileges => ['ALL', 'PROXY'], :table => ['*.*','@'], :user => 'foo@localhost')
|
||||
end
|
||||
|
||||
it 'should accept a grant name' do
|
||||
@user[:name].should == 'foo@localhost/*.*'
|
||||
end
|
||||
|
||||
it 'should accept ALL privileges' do
|
||||
@user[:privileges] = 'ALL'
|
||||
@user[:privileges].should == ['ALL']
|
||||
end
|
||||
|
||||
it 'should accept PROXY privilege' do
|
||||
@user[:privileges] = 'PROXY'
|
||||
@user[:privileges].should == ['PROXY']
|
||||
end
|
||||
|
||||
it 'should accept a table' do
|
||||
@user[:table] = '*.*'
|
||||
@user[:table].should == '*.*'
|
||||
end
|
||||
|
||||
it 'should accept @ for table' do
|
||||
@user[:table] = '@'
|
||||
@user[:table].should == '@'
|
||||
end
|
||||
|
||||
it 'should accept a user' do
|
||||
@user[:user] = 'foo@localhost'
|
||||
@user[:user].should == 'foo@localhost'
|
||||
end
|
||||
|
||||
it 'should require a name' do
|
||||
expect {
|
||||
Puppet::Type.type(:mysql_grant).new({})
|
||||
}.to raise_error(Puppet::Error, 'Title or name must be provided')
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,30 @@
|
||||
require 'puppet'
|
||||
require 'puppet/type/mysql_user'
|
||||
describe Puppet::Type.type(:mysql_user) do
|
||||
|
||||
before :each do
|
||||
@user = Puppet::Type.type(:mysql_user).new(:name => 'foo@localhost', :password_hash => 'pass')
|
||||
end
|
||||
|
||||
it 'should accept a user name' do
|
||||
@user[:name].should == 'foo@localhost'
|
||||
end
|
||||
|
||||
it 'should fail with a long user name' do
|
||||
expect {
|
||||
Puppet::Type.type(:mysql_user).new({:name => '12345678901234567@localhost', :password_hash => 'pass'})
|
||||
}.to raise_error /MySQL usernames are limited to a maximum of 16 characters/
|
||||
end
|
||||
|
||||
it 'should accept a password' do
|
||||
@user[:password_hash] = 'foo'
|
||||
@user[:password_hash].should == 'foo'
|
||||
end
|
||||
|
||||
it 'should require a name' do
|
||||
expect {
|
||||
Puppet::Type.type(:mysql_user).new({})
|
||||
}.to raise_error(Puppet::Error, 'Title or name must be provided')
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user