From e8132143c13e442323958e05f2a9bc1928aead01 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Thu, 17 Oct 2024 08:49:13 +0200 Subject: [PATCH] also update satellite-maintain package as part of an update run --- lib/foreman_maintain.rb | 14 +++++---- test/lib/cli/update_command_test.rb | 43 +++++++++++++++++++++------- test/lib/cli/upgrade_command_test.rb | 22 +++++++------- 3 files changed, 51 insertions(+), 28 deletions(-) diff --git a/lib/foreman_maintain.rb b/lib/foreman_maintain.rb index 1a8d4ebd4..c36b565f5 100644 --- a/lib/foreman_maintain.rb +++ b/lib/foreman_maintain.rb @@ -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 diff --git a/test/lib/cli/update_command_test.rb b/test/lib/cli/update_command_test.rb index 4291e5920..c43fc731a 100644 --- a/test/lib/cli/update_command_test.rb +++ b/test/lib/cli/update_command_test.rb @@ -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 @@ -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) @@ -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 @@ -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 @@ -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 diff --git a/test/lib/cli/upgrade_command_test.rb b/test/lib/cli/upgrade_command_test.rb index c6fc0c8ed..a875741e2 100644 --- a/test/lib/cli/upgrade_command_test.rb +++ b/test/lib/cli/upgrade_command_test.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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