Skip to content

Commit

Permalink
don't restore dumps when we already restored pgsql_data
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni authored and ehelms committed Jun 11, 2024
1 parent f4c6d5a commit 438499b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion definitions/scenarios/restore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def compose
add_step_with_context(Procedures::Service::Stop)
add_steps_with_context(Procedures::Restore::ExtractFiles) if backup.tar_backups_exist?

if backup.sql_dump_files_exist?
if backup.sql_needs_dump_restore?
add_steps_with_context(Procedures::Restore::DropDatabases)
restore_sql_dumps(backup)
end
Expand Down
8 changes: 8 additions & 0 deletions lib/foreman_maintain/utils/backup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,20 @@ def tar_backups_exist?
file_map[:pgsql_data][:present]
end

def sql_tar_files_exist?
file_map[:pgsql_data][:present]
end

def sql_dump_files_exist?
file_map[:foreman_dump][:present] ||
file_map[:candlepin_dump][:present] ||
file_map[:pulpcore_dump][:present]
end

def sql_needs_dump_restore?
!sql_tar_files_exist? && sql_dump_files_exist?
end

def incremental?
!!metadata.fetch('incremental', false)
end
Expand Down
28 changes: 26 additions & 2 deletions test/definitions/scenarios/restore_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module Scenarios
refute_scenario_has_step(scenario, Procedures::Restore::ReindexDatabases)
end

it 'drops and restores DB dumps if present' do
it 'drops and restores DB dumps if present and no DB data present' do
assume_feature_present(:foreman_database, :configuration => {})
assume_feature_present(:candlepin_database, :configuration => {})
assume_feature_present(:pulpcore_database, :configuration => {})
Expand All @@ -63,17 +63,41 @@ module Scenarios
:candlepin_dump => { :present => true },
:pulpcore_dump => { :present => true },
:pulp_data => { :present => true },
:pgsql_data => { :present => true },
:pgsql_data => { :present => false },
:metadata => { :present => false },
}
)

assert_scenario_has_step(scenario, Procedures::Restore::ExtractFiles)
assert_scenario_has_step(scenario, Procedures::Restore::DropDatabases)
assert_scenario_has_step(scenario, Procedures::Restore::ForemanDump)
assert_scenario_has_step(scenario, Procedures::Restore::CandlepinDump)
assert_scenario_has_step(scenario, Procedures::Restore::PulpcoreDump)
end

it 'does not try to drop/restore DB dumps if present and DB data present' do
assume_feature_present(:foreman_database, :configuration => {})
assume_feature_present(:candlepin_database, :configuration => {})
assume_feature_present(:pulpcore_database, :configuration => {})

ForemanMaintain::Utils::Backup.any_instance.stubs(:file_map).returns(
{
:foreman_dump => { :present => true },
:candlepin_dump => { :present => true },
:pulpcore_dump => { :present => true },
:pulp_data => { :present => true },
:pgsql_data => { :present => true },
:metadata => { :present => false },
}
)

assert_scenario_has_step(scenario, Procedures::Restore::ExtractFiles)
refute_scenario_has_step(scenario, Procedures::Restore::DropDatabases)
refute_scenario_has_step(scenario, Procedures::Restore::ForemanDump)
refute_scenario_has_step(scenario, Procedures::Restore::CandlepinDump)
refute_scenario_has_step(scenario, Procedures::Restore::PulpcoreDump)
end

it 'does not try to drop/restore DB dumps when these are absent' do
assume_feature_present(:foreman_database, :configuration => {})
assume_feature_present(:candlepin_database, :configuration => {})
Expand Down

0 comments on commit 438499b

Please sign in to comment.