2013-10-15 23:16:40 +02:00
|
|
|
require 'spec_helper_acceptance'
|
2015-05-11 22:40:28 +02:00
|
|
|
require 'puppet'
|
|
|
|
require 'puppet/util/package'
|
2013-10-15 23:16:40 +02:00
|
|
|
|
2014-07-25 20:32:00 +02:00
|
|
|
describe 'mysql::server::backup class' do
|
2015-05-11 22:40:28 +02:00
|
|
|
|
|
|
|
def pre_run
|
|
|
|
apply_manifest("class { 'mysql::server': root_password => 'password' }", :catch_failures => true)
|
|
|
|
@mysql_version = (on default, 'mysql --version').output.chomp.match(/\d+\.\d+\.\d+/)[0]
|
|
|
|
end
|
|
|
|
|
|
|
|
def version_is_greater_than(version)
|
|
|
|
return Puppet::Util::Package.versioncmp(@mysql_version, version) > 0
|
|
|
|
end
|
|
|
|
|
2013-10-15 23:16:40 +02:00
|
|
|
context 'should work with no errors' do
|
|
|
|
it 'when configuring mysql backups' do
|
|
|
|
pp = <<-EOS
|
2013-12-11 00:21:57 +01:00
|
|
|
class { 'mysql::server': root_password => 'password' }
|
2014-03-02 13:30:30 +01:00
|
|
|
mysql::db { [
|
|
|
|
'backup1',
|
|
|
|
'backup2'
|
|
|
|
]:
|
2013-10-15 23:16:40 +02:00
|
|
|
user => 'backup',
|
|
|
|
password => 'secret',
|
|
|
|
}
|
|
|
|
|
|
|
|
class { 'mysql::server::backup':
|
|
|
|
backupuser => 'myuser',
|
|
|
|
backuppassword => 'mypassword',
|
|
|
|
backupdir => '/tmp/backups',
|
|
|
|
backupcompress => true,
|
2014-02-06 16:44:07 +01:00
|
|
|
postscript => [
|
|
|
|
'rm -rf /var/tmp/mysqlbackups',
|
|
|
|
'rm -f /var/tmp/mysqlbackups.done',
|
|
|
|
'cp -r /tmp/backups /var/tmp/mysqlbackups',
|
|
|
|
'touch /var/tmp/mysqlbackups.done',
|
|
|
|
],
|
2014-02-20 17:17:41 +01:00
|
|
|
execpath => '/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin',
|
2013-10-15 23:16:40 +02:00
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
2014-05-29 20:49:00 +02:00
|
|
|
apply_manifest(pp, :catch_failures => true)
|
|
|
|
apply_manifest(pp, :catch_failures => true)
|
2013-10-15 23:16:40 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'mysqlbackup.sh' do
|
|
|
|
it 'should run mysqlbackup.sh with no errors' do
|
|
|
|
shell("/usr/local/sbin/mysqlbackup.sh") do |r|
|
2014-02-06 17:21:49 +01:00
|
|
|
expect(r.stderr).to eq("")
|
2013-10-15 23:16:40 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should dump all databases to single file' do
|
2013-12-11 00:21:57 +01:00
|
|
|
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
|
2013-10-15 23:16:40 +02:00
|
|
|
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
|
2013-12-11 00:21:57 +01:00
|
|
|
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
|
2013-10-15 23:16:40 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-08-24 03:51:18 +02:00
|
|
|
|
|
|
|
context 'with one file per database' 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',
|
|
|
|
'backup2'
|
|
|
|
]:
|
|
|
|
user => 'backup',
|
|
|
|
password => 'secret',
|
|
|
|
}
|
|
|
|
|
|
|
|
class { 'mysql::server::backup':
|
|
|
|
backupuser => 'myuser',
|
|
|
|
backuppassword => 'mypassword',
|
|
|
|
backupdir => '/tmp/backups',
|
|
|
|
backupcompress => true,
|
|
|
|
file_per_database => 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',
|
|
|
|
],
|
|
|
|
execpath => '/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin',
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
|
|
|
apply_manifest(pp, :catch_failures => true)
|
|
|
|
apply_manifest(pp, :catch_failures => true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'mysqlbackup.sh' do
|
|
|
|
it 'should run mysqlbackup.sh with no errors without root credentials' do
|
|
|
|
shell("HOME=/tmp/dontreadrootcredentials /usr/local/sbin/mysqlbackup.sh") do |r|
|
|
|
|
expect(r.stderr).to eq("")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create one file per database' do
|
|
|
|
['backup1', 'backup2'].each do |database|
|
|
|
|
shell("ls -l /tmp/backups/mysql_backup_#{database}_*-*.sql.bz2 | wc -l") do |r|
|
|
|
|
expect(r.stdout).to match(/1/)
|
|
|
|
expect(r.exit_code).to be_zero
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'should create one file per database per run' do
|
|
|
|
it 'executes mysqlbackup.sh a second time' do
|
|
|
|
shell('sleep 1')
|
|
|
|
shell('HOME=/tmp/dontreadrootcredentials /usr/local/sbin/mysqlbackup.sh')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has one file per database per run' do
|
|
|
|
['backup1', 'backup2'].each do |database|
|
|
|
|
shell("ls -l /tmp/backups/mysql_backup_#{database}_*-*.sql.bz2 | wc -l") do |r|
|
|
|
|
expect(r.stdout).to match(/2/)
|
|
|
|
expect(r.exit_code).to be_zero
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-04-29 15:52:37 +02:00
|
|
|
|
|
|
|
context 'with triggers and routines' do
|
|
|
|
it 'when configuring mysql backups with triggers and routines' do
|
2015-05-11 22:40:28 +02:00
|
|
|
pre_run
|
2015-04-29 15:52:37 +02:00
|
|
|
pp = <<-EOS
|
|
|
|
class { 'mysql::server': root_password => 'password' }
|
|
|
|
mysql::db { [
|
|
|
|
'backup1',
|
|
|
|
'backup2'
|
|
|
|
]:
|
|
|
|
user => 'backup',
|
|
|
|
password => 'secret',
|
|
|
|
}
|
|
|
|
package { 'bzip2':
|
|
|
|
ensure => present,
|
|
|
|
}
|
|
|
|
class { 'mysql::server::backup':
|
|
|
|
backupuser => 'myuser',
|
|
|
|
backuppassword => 'mypassword',
|
|
|
|
backupdir => '/tmp/backups',
|
|
|
|
backupcompress => true,
|
|
|
|
file_per_database => true,
|
2015-05-11 22:40:28 +02:00
|
|
|
include_triggers => #{version_is_greater_than('5.1.5')},
|
2015-04-29 15:52:37 +02:00
|
|
|
include_routines => 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',
|
|
|
|
],
|
|
|
|
execpath => '/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin',
|
|
|
|
require => Package['bzip2'],
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
apply_manifest(pp, :catch_failures => true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should run mysqlbackup.sh with no errors' do
|
|
|
|
shell("/usr/local/sbin/mysqlbackup.sh") do |r|
|
|
|
|
expect(r.stderr).to eq("")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-10-15 23:16:40 +02:00
|
|
|
end
|