-
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.
Fixes #36578 - ensure puppet/qpidd are present before restore
(cherry picked from commit 80cbb53)
- Loading branch information
Showing
5 changed files
with
119 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Procedures::Restore | ||
class RequiredPackages < ForemanMaintain::Procedure | ||
metadata do | ||
description 'Ensure required packages are installed before restore' | ||
|
||
param :backup_dir, | ||
'Path to backup directory', | ||
:required => true | ||
end | ||
|
||
def run | ||
backup = ForemanMaintain::Utils::Backup.new(@backup_dir) | ||
required_packages = [] | ||
required_packages << 'puppetserver' if backup.with_puppetserver? | ||
required_packages << 'qpid-cpp-server' if backup.with_qpidd? | ||
if required_packages.any? | ||
with_spinner('Installing required packages') do | ||
ForemanMaintain.package_manager.install(required_packages, assumeyes: true) | ||
end | ||
end | ||
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
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
58 changes: 58 additions & 0 deletions
58
test/definitions/procedures/restore/required_packages_test.rb
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require 'test_helper' | ||
|
||
describe Procedures::Restore::RequiredPackages do | ||
include DefinitionsTestHelper | ||
|
||
subject do | ||
Procedures::Restore::RequiredPackages.new(:backup_dir => '.') | ||
end | ||
|
||
it 'installs puppetserver if it was in the backup' do | ||
ForemanMaintain::Utils::Backup.any_instance.stubs(:with_puppetserver?).returns(true) | ||
ForemanMaintain.package_manager.expects(:install). | ||
with(['puppetserver'], assumeyes: true).once | ||
result = run_procedure(subject) | ||
assert result.success?, 'the procedure was expected to succeed' | ||
end | ||
|
||
it 'doesnt install puppetserver if it wasnt in the backup' do | ||
ForemanMaintain::Utils::Backup.any_instance.stubs(:with_puppetserver?).returns(false) | ||
ForemanMaintain.package_manager.expects(:install). | ||
with(['puppetserver'], assumeyes: true).never | ||
result = run_procedure(subject) | ||
assert result.success?, 'the procedure was expected to succeed' | ||
end | ||
|
||
it 'installs qpidd if it was in the backup' do | ||
ForemanMaintain::Utils::Backup.any_instance.stubs(:with_qpidd?).returns(true) | ||
ForemanMaintain.package_manager.expects(:install). | ||
with(['qpid-cpp-server'], assumeyes: true).once | ||
result = run_procedure(subject) | ||
assert result.success?, 'the procedure was expected to succeed' | ||
end | ||
|
||
it 'doesnt install qpidd if it wasnt in the backup' do | ||
ForemanMaintain::Utils::Backup.any_instance.stubs(:with_qpidd?).returns(false) | ||
ForemanMaintain.package_manager.expects(:install). | ||
with(['qpid-cpp-server'], assumeyes: true).never | ||
result = run_procedure(subject) | ||
assert result.success?, 'the procedure was expected to succeed' | ||
end | ||
|
||
it 'installs puppetserver and qpidd if it was in the backup' do | ||
ForemanMaintain::Utils::Backup.any_instance.stubs(:with_puppetserver?).returns(true) | ||
ForemanMaintain::Utils::Backup.any_instance.stubs(:with_qpidd?).returns(true) | ||
ForemanMaintain.package_manager.expects(:install). | ||
with(['puppetserver', 'qpid-cpp-server'], assumeyes: true).once | ||
result = run_procedure(subject) | ||
assert result.success?, 'the procedure was expected to succeed' | ||
end | ||
|
||
it 'doesnt install anything if it was not in the backup' do | ||
ForemanMaintain::Utils::Backup.any_instance.stubs(:with_puppetserver?).returns(false) | ||
ForemanMaintain::Utils::Backup.any_instance.stubs(:with_qpidd?).returns(false) | ||
ForemanMaintain.package_manager.expects(:install).never | ||
result = run_procedure(subject) | ||
assert result.success?, 'the procedure was expected to succeed' | ||
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