-
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.
Fail self-upgrade if current and target version are different
- Loading branch information
Showing
6 changed files
with
171 additions
and
28 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,121 @@ | ||
require 'test_helper' | ||
require_relative '../test_helper' | ||
require_relative '../../../definitions/scenarios/self_upgrade' | ||
|
||
module Scenarios | ||
describe ForemanMaintain::Scenarios::SelfUpgradeBase do | ||
include DefinitionsTestHelper | ||
describe ForemanMaintain::Scenarios::SelfUpgradeBase do | ||
include ::DefinitionsTestHelper | ||
|
||
describe 'with default params' do | ||
let(:scenario) do | ||
ForemanMaintain::Scenarios::SelfUpgradeBase.new | ||
end | ||
before do | ||
File.stubs(:exist?).with('/etc/redhat-release').returns(true) | ||
end | ||
|
||
let(:scenario) do | ||
ForemanMaintain::Scenarios::SelfUpgradeBase.new | ||
end | ||
|
||
it 'computes the target version correctly for downstream' do | ||
assume_satellite_present | ||
|
||
assert_equal '6.16', scenario.target_version | ||
end | ||
|
||
it 'returns target version correctly for upstream' do | ||
assume_feature_present(:foreman_install) | ||
|
||
assert_equal '3.11', scenario.target_version | ||
end | ||
|
||
it 'allow upgrade when versions are equal' do | ||
assume_satellite_present | ||
scenario.expects(:current_version).returns('6.16') | ||
scenario.expects(:target_version).returns('6.16') | ||
|
||
assert scenario.upgrade_allowed? | ||
end | ||
|
||
it 'does not allow upgrade when versions are off by 1' do | ||
assume_satellite_present | ||
scenario.expects(:current_version).returns('6.15') | ||
scenario.expects(:target_version).returns('6.16') | ||
|
||
refute scenario.upgrade_allowed? | ||
end | ||
|
||
it 'computes the target version correctly coming from normal release 6.10.0' do | ||
assume_satellite_present do |feature_class| | ||
feature_class.any_instance.stubs(:current_version => version('6.10.0')) | ||
end | ||
it 'does not allow upgrade when versions are off by 2 or more' do | ||
assume_satellite_present | ||
scenario.expects(:current_version).returns('6.14') | ||
scenario.expects(:target_version).returns('6.16') | ||
|
||
assert_equal '6.11', scenario.target_version | ||
end | ||
refute scenario.upgrade_allowed? | ||
end | ||
end | ||
|
||
describe ForemanMaintain::Scenarios::SelfUpgrade do | ||
include ::DefinitionsTestHelper | ||
|
||
before do | ||
File.stubs(:exist?).with('/etc/redhat-release').returns(true) | ||
end | ||
|
||
it 'runs successfully for downstream Satellite' do | ||
ForemanMaintain. | ||
package_manager. | ||
expects(:find_installed_package). | ||
with('satellite', "%{VERSION}"). | ||
returns('6.16.0') | ||
assume_feature_present(:satellite) | ||
scenario = ForemanMaintain::Scenarios::SelfUpgrade.new | ||
scenario.expects(:target_version).twice.returns('6.16') | ||
scenario.compose | ||
|
||
assert run_step(scenario) | ||
end | ||
|
||
it 'runs successfully for downstream Capsule' do | ||
ForemanMaintain. | ||
package_manager. | ||
expects(:find_installed_package). | ||
with('satellite-capsule', "%{VERSION}"). | ||
returns('6.16.0') | ||
assume_feature_present(:capsule) | ||
scenario = ForemanMaintain::Scenarios::SelfUpgrade.new | ||
scenario.expects(:target_version).twice.returns('6.16') | ||
scenario.compose | ||
|
||
assert run_step(scenario) | ||
end | ||
|
||
it 'fails if versions are off 1' do | ||
ForemanMaintain. | ||
package_manager. | ||
expects(:find_installed_package). | ||
with('satellite', "%{VERSION}"). | ||
returns('6.15.0') | ||
assume_feature_present(:satellite) | ||
|
||
msg = "self-upgrade has already been executed, and is ready to upgrade to 6.16" | ||
assert_raises(ForemanMaintain::Error::Warn, msg) do | ||
scenario = ForemanMaintain::Scenarios::SelfUpgrade.new | ||
scenario.expects(:target_version).twice.returns('6.16') | ||
scenario.compose | ||
end | ||
end | ||
|
||
it 'computes the target version correctly coming from an async release 6.11.1.1' do | ||
assume_satellite_present do |feature_class| | ||
feature_class.any_instance.stubs(:current_version => version('6.11.1.1')) | ||
end | ||
it 'fails if versions are off 2 or more' do | ||
ForemanMaintain. | ||
package_manager. | ||
expects(:find_installed_package). | ||
with('satellite', "%{VERSION}"). | ||
returns('6.14.0') | ||
assume_feature_present(:satellite) | ||
|
||
assert_equal '6.12', scenario.target_version | ||
end | ||
msg = "foreman-maintain is too many versions ahead, given the " \ | ||
"target version is 6.16. Please rollback foreman-maintain " \ | ||
"to the proper version." | ||
assert_raises(ForemanMaintain::Error::Warn, msg) do | ||
scenario = ForemanMaintain::Scenarios::SelfUpgrade.new | ||
scenario.expects(:target_version).twice.returns('6.16') | ||
scenario.compose | ||
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