-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ensure that the backup types match when doing incremental backups
- Loading branch information
Showing
5 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Checks::Backup | ||
class IncrementalParentType < ForemanMaintain::Check | ||
metadata do | ||
description 'Check if the incremental backup has the right type' | ||
tags :backup | ||
param :incremental_dir, 'Path to existing backup directory' | ||
param :online_backup, 'Select for online backup', :flag => true, :default => false | ||
param :sql_tar, 'Will backup include PostgreSQL tarball', :flag => true, :default => false | ||
manual_detection | ||
end | ||
|
||
def run | ||
return unless @incremental_dir | ||
|
||
backup = ForemanMaintain::Utils::Backup.new(@incremental_dir) | ||
|
||
existing_type = backup.backup_type | ||
new_type = if @online_backup | ||
ForemanMaintain::Utils::Backup::ONLINE_BACKUP | ||
else | ||
ForemanMaintain::Utils::Backup::OFFLINE_BACKUP | ||
end | ||
msg = "The existing backup is an #{existing_type} backup, "\ | ||
"but an #{new_type} backup was requested." | ||
assert(existing_type == new_type, msg) | ||
|
||
unless @online_backup | ||
existing_sql = backup.sql_tar_files_exist? ? 'tarball' : 'dump' | ||
new_sql = @sql_tar ? 'tarball' : 'dump' | ||
msg = "The existing backup has PostgreSQL as a #{existing_sql}, "\ | ||
"but the new one will have a #{new_sql}." | ||
assert(existing_sql == new_sql, msg) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
test/definitions/checks/backup/incremental_parent_type_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
require 'test_helper' | ||
|
||
describe Checks::Backup::IncrementalParentType do | ||
include DefinitionsTestHelper | ||
|
||
context 'without incremental_dir' do | ||
subject do | ||
Checks::Backup::IncrementalParentType.new | ||
end | ||
|
||
it 'passes without performing any checks' do | ||
ForemanMaintain::Utils::Backup.any_instance.expects(:online_backup?).never | ||
result = run_check(subject) | ||
assert result.success?, 'Check expected to succeed' | ||
end | ||
end | ||
|
||
context 'for offline backup with local PostreSQL tarballs' do | ||
subject do | ||
Checks::Backup::IncrementalParentType.new(:incremental_dir => '.', :online_backup => false, | ||
:sql_tar => true) | ||
end | ||
|
||
it 'passes when existing backup is offline with tarballs' do | ||
ForemanMaintain::Utils::Backup.any_instance.expects(:online_backup?).returns(false) | ||
ForemanMaintain::Utils::Backup.any_instance.expects(:sql_tar_files_exist?).returns(true) | ||
result = run_check(subject) | ||
assert result.success?, 'Check expected to succeed' | ||
end | ||
|
||
it 'fails when existing backup is online' do | ||
ForemanMaintain::Utils::Backup.any_instance.expects(:online_backup?).returns(true) | ||
result = run_check(subject) | ||
refute result.success?, 'Check expected to fail' | ||
expected = 'The existing backup is an online backup, but an offline backup was requested.' | ||
assert_equal expected, result.output | ||
end | ||
|
||
it 'fails when existing backup uses dumps' do | ||
ForemanMaintain::Utils::Backup.any_instance.expects(:online_backup?).returns(false) | ||
ForemanMaintain::Utils::Backup.any_instance.expects(:sql_tar_files_exist?).returns(false) | ||
result = run_check(subject) | ||
refute result.success?, 'Check expected to fail' | ||
expected = 'The existing backup has PostgreSQL as a dump, '\ | ||
'but the new one will have a tarball.' | ||
assert_equal expected, result.output | ||
end | ||
end | ||
|
||
context 'for offline backup with remote PostgreSQL dumps' do | ||
subject do | ||
Checks::Backup::IncrementalParentType.new(:incremental_dir => '.', :online_backup => false, | ||
:sql_tar => false) | ||
end | ||
|
||
it 'passes when existing backup is offline' do | ||
ForemanMaintain::Utils::Backup.any_instance.expects(:online_backup?).returns(false) | ||
ForemanMaintain::Utils::Backup.any_instance.expects(:sql_tar_files_exist?).returns(false) | ||
result = run_check(subject) | ||
assert result.success?, 'Check expected to succeed' | ||
end | ||
|
||
it 'fails when existing backup is online' do | ||
ForemanMaintain::Utils::Backup.any_instance.expects(:online_backup?).returns(true) | ||
result = run_check(subject) | ||
refute result.success?, 'Check expected to fail' | ||
expected = 'The existing backup is an online backup, but an offline backup was requested.' | ||
assert_equal expected, result.output | ||
end | ||
|
||
it 'fails when existing backup uses psql_data.tar' do | ||
ForemanMaintain::Utils::Backup.any_instance.expects(:online_backup?).returns(false) | ||
ForemanMaintain::Utils::Backup.any_instance.expects(:sql_tar_files_exist?).returns(true) | ||
result = run_check(subject) | ||
refute result.success?, 'Check expected to fail' | ||
expected = 'The existing backup has PostgreSQL as a tarball, '\ | ||
'but the new one will have a dump.' | ||
assert_equal expected, result.output | ||
end | ||
end | ||
|
||
context 'for online backup' do | ||
subject do | ||
Checks::Backup::IncrementalParentType.new(:incremental_dir => '.', :online_backup => true) | ||
end | ||
|
||
it 'passes when existing backup is online' do | ||
ForemanMaintain::Utils::Backup.any_instance.expects(:online_backup?).returns(true) | ||
result = run_check(subject) | ||
assert result.success?, 'Check expected to succeed' | ||
end | ||
|
||
it 'fails when existing backup is offline' do | ||
ForemanMaintain::Utils::Backup.any_instance.expects(:online_backup?).returns(false) | ||
result = run_check(subject) | ||
refute result.success?, 'Check expected to fail' | ||
expected = 'The existing backup is an offline backup, but an online backup was requested.' | ||
assert_equal expected, result.output | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters