-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ensure that the backup types match when doing incremental backups #891
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This parameter is required right? So can this ever be true? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This parameter can be |
||
|
||
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 |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the supposition that if this is not set, it defaults to offline backup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes