Skip to content

Commit

Permalink
also update satellite-maintain package as part of an update run
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Oct 17, 2024
1 parent 3319775 commit e813214
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 28 deletions.
14 changes: 8 additions & 6 deletions lib/foreman_maintain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,22 @@ def command_name

def perform_self_upgrade
package_name, command = pkg_and_cmd_name
packages_to_update = [package_name, main_package_name].uniq
packages_to_update_str = packages_to_update.join(', ')

puts "Checking for new version of #{package_name}..."
puts "Checking for new version of #{packages_to_update_str}..."

enable_maintenance_module
package_manager = ForemanMaintain.package_manager

if package_manager.update_available?(main_package_name)
puts "\nUpdating #{package_name} package."
package_manager.update(main_package_name, :assumeyes => true)
puts "\nThe #{package_name} package successfully updated."\
if package_manager.update_available?(packages_to_update)
puts "\nUpdating #{packages_to_update_str}."
package_manager.update(packages_to_update, :assumeyes => true)
puts "\nSuccessfully updated #{packages_to_update_str}."\
"\nRe-run #{command} with required options!"
exit 75
end
puts "Nothing to update, can't find new version of #{package_name}."
puts "Nothing to update, can't find new version of #{packages_to_update_str}."
end

def enable_maintenance_module
Expand Down
43 changes: 32 additions & 11 deletions test/lib/cli/update_command_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,26 @@ module ForemanMaintain

def foreman_maintain_update_available
PackageManagerTestHelper.mock_package_manager
FakePackageManager.any_instance.stubs(:update).with('rubygem-foreman_maintain',
FakePackageManager.any_instance.stubs(:update).with(['rubygem-foreman_maintain'],
:assumeyes => true).returns(true)
# rubocop:disable Layout/LineLength
FakePackageManager.any_instance.stubs(:update_available?).with('rubygem-foreman_maintain').returns(true)
FakePackageManager.any_instance.stubs(:update_available?).with(['rubygem-foreman_maintain']).returns(true)
# rubocop:enable Layout/LineLength
end

def satellite_maintain_update_available
ForemanMaintain.stubs(:pkg_and_cmd_name).returns(%w[satellite-maintain satellite-maintain])
PackageManagerTestHelper.mock_package_manager
FakePackageManager.any_instance.stubs(:update).
with(['satellite-maintain', 'rubygem-foreman_maintain'], :assumeyes => true).returns(true)
FakePackageManager.any_instance.stubs(:update_available?).
with(['satellite-maintain', 'rubygem-foreman_maintain']).returns(true)
end

def foreman_maintain_update_unavailable
PackageManagerTestHelper.mock_package_manager
# rubocop:disable Layout/LineLength
FakePackageManager.any_instance.stubs(:update_available?).with('rubygem-foreman_maintain').returns(false)
FakePackageManager.any_instance.stubs(:update_available?).with(['rubygem-foreman_maintain']).returns(false)
# rubocop:enable Layout/LineLength
end

Expand Down Expand Up @@ -66,13 +75,25 @@ def foreman_maintain_update_unavailable
assert_cmd <<~OUTPUT
Checking for new version of rubygem-foreman_maintain...
Updating rubygem-foreman_maintain package.
Updating rubygem-foreman_maintain.
The rubygem-foreman_maintain package successfully updated.
Successfully updated rubygem-foreman_maintain.
Re-run foreman-maintain with required options!
OUTPUT
end

it 'run self update if update available for satellite-maintain' do
satellite_maintain_update_available
assert_cmd <<~OUTPUT
Checking for new version of satellite-maintain, rubygem-foreman_maintain...
Updating satellite-maintain, rubygem-foreman_maintain.
Successfully updated satellite-maintain, rubygem-foreman_maintain.
Re-run satellite-maintain with required options!
OUTPUT
end

it 'runs the update checks when update is not available for foreman-maintain' do
foreman_maintain_update_unavailable
UpdateRunner.any_instance.expects(:run_phase).with(:pre_update_checks)
Expand Down Expand Up @@ -122,9 +143,9 @@ def foreman_maintain_update_unavailable
assert_cmd <<~OUTPUT
Checking for new version of rubygem-foreman_maintain...
Updating rubygem-foreman_maintain package.
Updating rubygem-foreman_maintain.
The rubygem-foreman_maintain package successfully updated.
Successfully updated rubygem-foreman_maintain.
Re-run foreman-maintain with required options!
OUTPUT
end
Expand Down Expand Up @@ -171,9 +192,9 @@ def foreman_maintain_update_unavailable
assert_cmd <<~OUTPUT
Checking for new version of rubygem-foreman_maintain...
Updating rubygem-foreman_maintain package.
Updating rubygem-foreman_maintain.
The rubygem-foreman_maintain package successfully updated.
Successfully updated rubygem-foreman_maintain.
Re-run foreman-maintain with required options!
OUTPUT

Expand All @@ -182,9 +203,9 @@ def foreman_maintain_update_unavailable
assert_cmd(<<~OUTPUT)
Checking for new version of rubygem-foreman_maintain...
Updating rubygem-foreman_maintain package.
Updating rubygem-foreman_maintain.
The rubygem-foreman_maintain package successfully updated.
Successfully updated rubygem-foreman_maintain.
Re-run foreman-maintain with required options!
OUTPUT
end
Expand Down
22 changes: 11 additions & 11 deletions test/lib/cli/upgrade_command_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ module ForemanMaintain

def foreman_maintain_update_available
PackageManagerTestHelper.mock_package_manager
FakePackageManager.any_instance.stubs(:update).with('rubygem-foreman_maintain',
FakePackageManager.any_instance.stubs(:update).with(['rubygem-foreman_maintain'],
:assumeyes => true).returns(true)
# rubocop:disable Layout/LineLength
FakePackageManager.any_instance.stubs(:update_available?).with('rubygem-foreman_maintain').returns(true)
FakePackageManager.any_instance.stubs(:update_available?).with(['rubygem-foreman_maintain']).returns(true)
# rubocop:enable Layout/LineLength
end

def foreman_maintain_update_unavailable
PackageManagerTestHelper.mock_package_manager
# rubocop:disable Layout/LineLength
FakePackageManager.any_instance.stubs(:update_available?).with('rubygem-foreman_maintain').returns(false)
FakePackageManager.any_instance.stubs(:update_available?).with(['rubygem-foreman_maintain']).returns(false)
# rubocop:enable Layout/LineLength
end

Expand Down Expand Up @@ -61,9 +61,9 @@ def foreman_maintain_update_unavailable
assert_cmd <<~OUTPUT
Checking for new version of rubygem-foreman_maintain...
Updating rubygem-foreman_maintain package.
Updating rubygem-foreman_maintain.
The rubygem-foreman_maintain package successfully updated.
Successfully updated rubygem-foreman_maintain.
Re-run foreman-maintain with required options!
OUTPUT
end
Expand Down Expand Up @@ -113,9 +113,9 @@ def foreman_maintain_update_unavailable
assert_cmd <<~OUTPUT
Checking for new version of rubygem-foreman_maintain...
Updating rubygem-foreman_maintain package.
Updating rubygem-foreman_maintain.
The rubygem-foreman_maintain package successfully updated.
Successfully updated rubygem-foreman_maintain.
Re-run foreman-maintain with required options!
OUTPUT
end
Expand Down Expand Up @@ -158,9 +158,9 @@ def foreman_maintain_update_unavailable
assert_cmd <<~OUTPUT
Checking for new version of rubygem-foreman_maintain...
Updating rubygem-foreman_maintain package.
Updating rubygem-foreman_maintain.
The rubygem-foreman_maintain package successfully updated.
Successfully updated rubygem-foreman_maintain.
Re-run foreman-maintain with required options!
OUTPUT

Expand All @@ -171,9 +171,9 @@ def foreman_maintain_update_unavailable
assert_cmd(<<~OUTPUT, [])
Checking for new version of rubygem-foreman_maintain...
Updating rubygem-foreman_maintain package.
Updating rubygem-foreman_maintain.
The rubygem-foreman_maintain package successfully updated.
Successfully updated rubygem-foreman_maintain.
Re-run foreman-maintain with required options!
OUTPUT
end
Expand Down

0 comments on commit e813214

Please sign in to comment.