Skip to content

Commit

Permalink
Fixes #36668 - only reindex DB when the OS changes
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Aug 11, 2023
1 parent 3b30b83 commit e42761d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
4 changes: 3 additions & 1 deletion definitions/scenarios/restore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def compose
add_step(Procedures::Service::Stop.new(:only => ['postgresql']))
end

if feature(:instance).postgresql_local? && !backup.online_backup?
if feature(:instance).postgresql_local? &&
!backup.online_backup? &&
backup.different_source_os?
add_step_with_context(Procedures::Restore::ReindexDatabases)
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 @@ -265,6 +265,14 @@ def with_puppetserver?
def with_qpidd?
installed_rpms.any? { |rpm| rpm.start_with?('qpid-cpp-server-') }
end

def source_os_version
metadata.fetch('os_version', 'unknown')
end

def different_source_os?
source_os_version != "#{os_name} #{os_version}"
end
end
end
end
12 changes: 11 additions & 1 deletion test/definitions/scenarios/restore_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,30 @@ module Scenarios
assert_scenario_has_step(scenario, Procedures::Restore::Configs)
end

it 'reindexes the DB if DB is local and offline backup' do
it 'reindexes the DB if DB is local and offline backup and OS change' do
assume_feature_present(:instance, :postgresql_local? => true)
ForemanMaintain::Utils::Backup.any_instance.stubs(:online_backup?).returns(false)
ForemanMaintain::Utils::Backup.any_instance.stubs(:different_source_os?).returns(true)
assert_scenario_has_step(scenario, Procedures::Restore::ReindexDatabases)
end

it 'doesnt reindex the DB if DB is local and offline backup and no OS change' do
assume_feature_present(:instance, :postgresql_local? => true)
ForemanMaintain::Utils::Backup.any_instance.stubs(:online_backup?).returns(false)
ForemanMaintain::Utils::Backup.any_instance.stubs(:different_source_os?).returns(false)
refute_scenario_has_step(scenario, Procedures::Restore::ReindexDatabases)
end

it 'doesnt reindex the DB if DB is local and online backup' do
assume_feature_present(:instance, :postgresql_local? => false)
ForemanMaintain::Utils::Backup.any_instance.stubs(:online_backup?).returns(true)
ForemanMaintain::Utils::Backup.any_instance.stubs(:different_source_os?).returns(true)
refute_scenario_has_step(scenario, Procedures::Restore::ReindexDatabases)
end

it 'doesnt reindex the DB if it is remote' do
assume_feature_present(:instance, :postgresql_local? => false)
ForemanMaintain::Utils::Backup.any_instance.stubs(:different_source_os?).returns(true)
refute_scenario_has_step(scenario, Procedures::Restore::ReindexDatabases)
end
end
Expand Down
16 changes: 16 additions & 0 deletions test/lib/utils/backup_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,5 +302,21 @@ def feature_with_local_method(label, return_value)
backup.stubs(:metadata).returns('rpms' => ['qpid-cpp-client-1.36.0-32.el7_9amq.x86_64'])
refute backup.with_qpidd?
end

it 'detects backup from different OS' do
backup = subject.new(katello_standard)
backup.stubs(:metadata).returns('os_version' => 'TestOS 1.2')
backup.stubs(:os_name).returns('TestOS')
backup.stubs(:os_version).returns('2.0')
assert backup.different_source_os?
end

it 'detects backup from the same OS' do
backup = subject.new(katello_standard)
backup.stubs(:metadata).returns('os_version' => 'TestOS 1.2')
backup.stubs(:os_name).returns('TestOS')
backup.stubs(:os_version).returns('1.2')
refute backup.different_source_os?
end
end
end

0 comments on commit e42761d

Please sign in to comment.