Skip to content

Commit 7730e27

Browse files
committed
MODULES-10023 add acceptance tests for xtrabackup
1 parent 815d79d commit 7730e27

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

spec/acceptance/mysql_backup_spec.rb

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,133 @@ class { 'mysql::server::backup':
134134
# rubocop:enable RSpec/MultipleExpectations, RSpec/ExampleLength
135135
end
136136
end
137+
138+
context 'with xtrabackup enabled' do
139+
context 'should work with no errors' do
140+
pp = <<-MANIFEST
141+
class { 'mysql::server': root_password => 'password' }
142+
mysql::db { [
143+
'backup1',
144+
'backup2'
145+
]:
146+
user => 'backup',
147+
password => 'secret',
148+
}
149+
yumrepo { 'percona':
150+
descr => 'CentOS $releasever - Percona',
151+
baseurl => 'http://repo.percona.com/release/$releasever/RPMS/$basearch',
152+
gpgkey => 'https://www.percona.com/downloads/RPM-GPG-KEY-percona https://repo.percona.com/yum/PERCONA-PACKAGING-KEY',
153+
enabled => 1,
154+
gpgcheck => 1,
155+
}
156+
class { 'mysql::server::backup':
157+
backupuser => 'myuser',
158+
backuppassword => 'mypassword',
159+
backupdir => '/tmp/xtrabackups',
160+
provider => 'xtrabackup',
161+
execpath => '/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin',
162+
}
163+
MANIFEST
164+
it 'when configuring mysql backup' do
165+
idempotent_apply(pp)
166+
end
167+
end
168+
169+
describe 'xtrabackup.sh', if: Gem::Version.new(mysql_version) < Gem::Version.new('5.7.0') do
170+
before(:all) do
171+
pre_run
172+
end
173+
174+
it 'runs xtrabackup.sh full backup with no errors' do
175+
run_shell('/usr/local/sbin/xtrabackup.sh --target-dir=/tmp/xtrabackups/$(date +%F)_full --backup 2>&1 | tee /tmp/xtrabackup_full.log') do |r|
176+
expect(r.exit_code).to be_zero
177+
end
178+
end
179+
180+
it 'xtrabackup reports success for the full backup' do
181+
run_shell('grep "completed OK" /tmp/xtrabackup_full.log') do |r|
182+
expect(r.exit_code).to be_zero
183+
end
184+
end
185+
186+
it 'creates a subdirectory for the full backup' do
187+
run_shell('find /tmp/xtrabackups -mindepth 1 -maxdepth 1 -type d -name $(date +%Y)\*full | wc -l') do |r|
188+
expect(r.stdout).to match(%r{1})
189+
expect(r.exit_code).to be_zero
190+
end
191+
end
192+
193+
it 'runs xtrabackup.sh incremental backup with no errors' do
194+
run_shell('sleep 1')
195+
run_shell('/usr/local/sbin/xtrabackup.sh --incremental-basedir=/tmp/xtrabackups/$(date +%F)_full --target-dir=/tmp/xtrabackups/$(date +%F_%H-%M-%S) --backup 2>&1 | tee /tmp/xtrabackup_inc.log') do |r| # rubocop:disable Metrics/LineLength
196+
expect(r.exit_code).to be_zero
197+
end
198+
end
199+
200+
it 'xtrabackup reports success for the incremental backup' do
201+
run_shell('grep "completed OK" /tmp/xtrabackup_inc.log') do |r|
202+
expect(r.exit_code).to be_zero
203+
end
204+
end
205+
206+
it 'creates a new subdirectory for each backup' do
207+
run_shell('find /tmp/xtrabackups -mindepth 1 -maxdepth 1 -type d -name $(date +%Y)\* | wc -l') do |r|
208+
expect(r.stdout).to match(%r{2})
209+
expect(r.exit_code).to be_zero
210+
end
211+
end
212+
end
213+
# rubocop:enable RSpec/MultipleExpectations, RSpec/ExampleLength
214+
end
215+
216+
context 'with xtrabackup enabled and incremental backups disabled' do
217+
context 'should work with no errors' do
218+
pp = <<-MANIFEST
219+
class { 'mysql::server': root_password => 'password' }
220+
mysql::db { [
221+
'backup1',
222+
'backup2'
223+
]:
224+
user => 'backup',
225+
password => 'secret',
226+
}
227+
yumrepo { 'percona':
228+
descr => 'CentOS $releasever - Percona',
229+
baseurl => 'http://repo.percona.com/release/$releasever/RPMS/$basearch',
230+
gpgkey => 'https://www.percona.com/downloads/RPM-GPG-KEY-percona https://repo.percona.com/yum/PERCONA-PACKAGING-KEY',
231+
enabled => 1,
232+
gpgcheck => 1,
233+
}
234+
class { 'mysql::server::backup':
235+
backupuser => 'myuser',
236+
backuppassword => 'mypassword',
237+
backupdir => '/tmp/xtrabackups',
238+
provider => 'xtrabackup',
239+
incremental_backups => false,
240+
execpath => '/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin',
241+
}
242+
MANIFEST
243+
it 'when configuring mysql backup' do
244+
idempotent_apply(pp)
245+
end
246+
end
247+
248+
describe 'xtrabackup.sh', if: Gem::Version.new(mysql_version) < Gem::Version.new('5.7.0') do
249+
before(:all) do
250+
pre_run
251+
end
252+
253+
it 'runs xtrabackup.sh with no errors' do
254+
run_shell('/usr/local/sbin/xtrabackup.sh --target-dir=/tmp/xtrabackups/$(date +%F_%H-%M-%S) --backup 2>&1 | tee /tmp/xtrabackup.log') do |r|
255+
expect(r.exit_code).to be_zero
256+
end
257+
end
258+
259+
it 'xtrabackup reports success for the backup' do
260+
run_shell('grep "completed OK" /tmp/xtrabackup.log') do |r|
261+
expect(r.exit_code).to be_zero
262+
end
263+
end
264+
end
265+
# rubocop:enable RSpec/MultipleExpectations, RSpec/ExampleLength
266+
end

0 commit comments

Comments
 (0)