Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

also update satellite-maintain package as part of an update run #944

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading