Rebuild the acceptance tests.

This commit is contained in:
Ashley Penney 2014-07-25 14:32:00 -04:00
parent 574d5d9dff
commit 994ac1a058
15 changed files with 68 additions and 682 deletions

View file

@ -1,5 +1,6 @@
fixtures:
repositories:
"stdlib": "https://github.com/puppetlabs/puppetlabs-stdlib"
"puppet_facts": "https://github.com/apenney/puppet_facts"
symlinks:
"mysql": "#{source_dir}"

View file

@ -1,25 +0,0 @@
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

View file

@ -1,6 +1,6 @@
require 'spec_helper_acceptance'
describe 'mysql::server::backup class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'mysql::server::backup class' do
context 'should work with no errors' do
it 'when configuring mysql backups' do
pp = <<-EOS
@ -13,10 +13,6 @@ describe 'mysql::server::backup class', :unless => UNSUPPORTED_PLATFORMS.include
password => 'secret',
}
package { 'bzip2':
ensure => present,
}
class { 'mysql::server::backup':
backupuser => 'myuser',
backuppassword => 'mypassword',
@ -29,7 +25,6 @@ describe 'mysql::server::backup class', :unless => UNSUPPORTED_PLATFORMS.include
'touch /var/tmp/mysqlbackups.done',
],
execpath => '/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin',
require => Package['bzip2'],
}
EOS

View file

@ -1,157 +0,0 @@
require 'spec_helper_acceptance'
osfamily = fact('osfamily')
operatingsystem = fact('operatingsystem')
ruby_package_provider = 'undef'
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'
if fact('operatingsystemmajrelease') == '7'
ruby_package_provider = 'gem'
end
client_dev_package = 'undef'
daemon_dev_package = 'mysql-devel'
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
client_dev_package = 'libmysqlclient-devel'
daemon_dev_package = 'mysql-devel'
when 'Debian'
java_package = 'libmysql-java'
perl_package = 'libdbd-mysql-perl'
php_package = 'php5-mysql'
python_package = 'python-mysqldb'
if fact('lsbdistcodename') == 'trusty'
ruby_package = 'ruby-mysql'
else
ruby_package = 'libmysql-ruby'
end
client_dev_package = 'libmysqlclient-dev'
daemon_dev_package = 'libmysqld-dev'
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'
client_dev_package = 'undef'
daemon_dev_package = 'undef'
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'
client_dev_package = 'undef'
daemon_dev_package = 'undef'
end
end
describe 'mysql::bindings class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
if fact('osfamily') == 'RedHat' and fact('operatingsystemmajrelease') =~ /(5|6)/
it 'adds epel' do
pp = "class { 'epel': }"
apply_manifest(pp, :catch_failures => true)
end
end
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,
client_dev => true,
daemon_dev => true,
java_package_ensure => present,
perl_package_ensure => present,
php_package_ensure => present,
python_package_ensure => present,
ruby_package_ensure => present,
client_dev_package_ensure => present,
daemon_dev_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},
client_dev_package_name => #{client_dev_package},
daemon_dev_package_name => #{daemon_dev_package},
java_package_provider => undef,
perl_package_provider => undef,
php_package_provider => undef,
python_package_provider => undef,
ruby_package_provider => #{ruby_package_provider},
client_dev_package_provider => undef,
daemon_dev_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
# ruby-mysql is installed via gem on RHEL7, be_installed doesn't know how to check that
if fact('osfamily') == 'RedHat' && fact('operatingsystemmajrelease') == '7'
describe package(ruby_package) do
it { should_not be_installed }
end
else
describe package(ruby_package) do
it { should be_installed }
end
end
end
end

View file

@ -1,6 +1,6 @@
require 'spec_helper_acceptance'
describe 'mysql::db define', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'mysql::db define' do
describe 'creating a database' do
# Using puppet_apply as a helper
it 'should work with no errors' do
@ -55,7 +55,7 @@ describe 'mysql::db define', :unless => UNSUPPORTED_PLATFORMS.include?(fact('ope
mysql::db { 'spec1':
user => 'root1',
password => 'password',
dbname => 'realdb',
dbname => 'realdb',
}
EOS

View file

@ -1,87 +0,0 @@
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 'includedir location', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
it 'creates the file elsewhere' do
pp = <<-EOS
class { 'mysql::server':
includedir => '/etc/my.cnf.d',
config_file => '/etc/testmy.cnf',
}
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('rmdir /etc/my.cnf.d', :acceptable_exit_codes => [0,1,2])
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/my.cnf.d') do
it { should be_directory }
end
describe file('/etc/testmy.cnf') do
it { sould contain "!includedir /etc/my.cnf.d" }
end
end
describe 'no includedir location', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
it 'creates the file elsewhere' do
pp = <<-EOS
class { 'mysql::server':
includedir => '',
config_file => '/etc/testmy.cnf',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/testmy.cnf') do
it { should_not contain "includedir" }
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

View file

@ -1,22 +0,0 @@
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

View file

@ -1,71 +0,0 @@
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('grep -q datadir /etc/my.cnf && 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

View file

@ -1,304 +1,55 @@
require 'spec_helper_acceptance'
describe 'mysql class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
case fact('osfamily')
when 'RedHat'
if fact('operatingsystemmajrelease') == '7'
package_name = 'mariadb-server'
service_name = 'mariadb'
service_provider = 'undef'
mycnf = '/etc/my.cnf'
else
package_name = 'mysql-server'
service_name = 'mysqld'
service_provider = 'undef'
mycnf = '/etc/my.cnf'
end
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 'mysql 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': }
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
tmpdir = default.tmpdir('mysql')
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',
config_file => '#{tmpdir}/my.cnf',
includedir => '#{tmpdir}/include',
manage_config_file => 'true',
override_options => { 'mysqld' => { 'key_buffer_size' => '32M' }},
package_ensure => 'present',
purge_conf_dir => 'true',
remove_default_accounts => 'true',
restart => 'true',
root_group => 'root',
root_password => 'test',
service_enabled => 'true',
service_manage => 'true',
users => {
'someuser@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 => {
'someuser@localhost/somedb.*' => {
ensure => 'present',
options => ['GRANT'],
privileges => ['SELECT', 'INSERT', 'UPDATE', 'DELETE'],
table => 'somedb.*',
user => 'someuser@localhost',
},
},
databases => {
'somedb' => {
ensure => 'present',
charset => 'utf8',
},
}
},
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
describe 'creates the appropriate databases when datadir is set' do
tmpdir = default.tmpdir('mysql')
it 'sets up mysql' do
pp = <<-EOS
class { 'mysql::server':
override_options => { 'mysqld' => { 'datadir' => '#{tmpdir}/mysql' }},
}
}
EOS
shell("mkdir -p #{tmpdir}; chown -R mysql:mysql #{tmpdir}")
apply_manifest(pp, :catch_failures => true)
end
describe file("#{tmpdir}/mysql/mysql") do
it { should be_directory }
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
end
end

View file

@ -1,6 +1,6 @@
require 'spec_helper_acceptance'
describe 'mysql_database', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'mysql_database' do
describe 'setup' do
it 'should work with no errors' do
pp = <<-EOS

View file

@ -1,6 +1,6 @@
require 'spec_helper_acceptance'
describe 'mysql_grant', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'mysql_grant' do
describe 'setup' do
it 'setup mysql::server' do

View file

@ -1,6 +1,6 @@
require 'spec_helper_acceptance'
describe 'mysql_user', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'mysql_user' do
describe 'setup' do
it 'should work with no errors' do
pp = <<-EOS

View file

@ -1,10 +0,0 @@
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

View file

@ -1,16 +1,27 @@
describe 'mysql::client' do
let(:facts) {{ :osfamily => 'RedHat' }}
fail ArgumentError, "Puppet facts missing" if Dir["spec/fixtures/modules/puppet_facts/PE3.3/*"].empty?
Dir["spec/fixtures/modules/puppet_facts/PE3.3/*"].each do |facts|
platform_name = facts.gsub(/\.facts/, '')
describe "on #{platform_name}" do
hash = {}
File.read(facts).each_line do |line|
key, value = line.split(' => ')
hash[key.to_sym] = value.chomp unless value.nil?
end
let(:facts) { hash }
context 'with defaults' do
it { should_not contain_class('mysql::bindings') }
it { should contain_package('mysql_client') }
end
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 }}
context 'with bindings enabled' do
let(:params) {{ :bindings_enable => true }}
it { should contain_class('mysql::bindings') }
it { should contain_package('mysql_client') }
it { should contain_class('mysql::bindings') }
it { should contain_package('mysql_client') }
end
end
end
end