diff --git a/definitions/scenarios/restore.rb b/definitions/scenarios/restore.rb index 28cc76c13..0ebb4d907 100644 --- a/definitions/scenarios/restore.rb +++ b/definitions/scenarios/restore.rb @@ -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 diff --git a/lib/foreman_maintain/utils/backup.rb b/lib/foreman_maintain/utils/backup.rb index 3fa11f8ba..908684c20 100644 --- a/lib/foreman_maintain/utils/backup.rb +++ b/lib/foreman_maintain/utils/backup.rb @@ -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 diff --git a/test/definitions/scenarios/restore_test.rb b/test/definitions/scenarios/restore_test.rb index e200311b0..be9fb5b5f 100644 --- a/test/definitions/scenarios/restore_test.rb +++ b/test/definitions/scenarios/restore_test.rb @@ -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 diff --git a/test/lib/utils/backup_test.rb b/test/lib/utils/backup_test.rb index 410697e7f..842daa38d 100644 --- a/test/lib/utils/backup_test.rb +++ b/test/lib/utils/backup_test.rb @@ -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