diff --git a/definitions/procedures/packages/update.rb b/definitions/procedures/packages/update.rb index 6ddac302f..468d7f906 100644 --- a/definitions/procedures/packages/update.rb +++ b/definitions/procedures/packages/update.rb @@ -6,12 +6,14 @@ class Update < ForemanMaintain::Procedure param :force, 'Do not skip if package is installed', :flag => true, :default => false param :warn_on_errors, 'Do not interrupt scenario on failure', :flag => true, :default => false + param :yum_options, 'Extra yum options if any', :array => true, :default => [] end def run assumeyes_val = @assumeyes.nil? ? assumeyes? : @assumeyes package_manager.clean_cache(:assumeyes => assumeyes_val) - packages_action(:update, @packages, :assumeyes => assumeyes_val) + opts = { :assumeyes => assumeyes_val, :yum_options => @yum_options } + packages_action(:update, @packages, opts) rescue ForemanMaintain::Error::ExecutionError => e if @warn_on_errors set_status(:warning, e.message) diff --git a/definitions/scenarios/self_upgrade.rb b/definitions/scenarios/self_upgrade.rb index ee27f68be..8191a5ac7 100644 --- a/definitions/scenarios/self_upgrade.rb +++ b/definitions/scenarios/self_upgrade.rb @@ -1,18 +1,6 @@ module ForemanMaintain::Scenarios class SelfUpgradeBase < ForemanMaintain::Scenario include ForemanMaintain::Concerns::Downstream - def enabled_system_repos_id - repository_manager.enabled_repos.keys - end - - def enable_repos(repo_ids = stored_enabled_repos_ids) - add_step(Procedures::Repositories::Enable.new(repos: repo_ids)) - end - - def disable_repos(repo_ids = stored_enabled_repos_ids) - add_step(Procedures::Repositories::Disable.new(repos: repo_ids)) - end - def target_version current_full_version = feature(:instance).downstream.current_version @target_version ||= current_full_version.bump @@ -44,36 +32,6 @@ def maintenance_repo(version) end end - def maintenance_repo_version - return '6' if current_version == '6.10' - - current_version - end - - def stored_enabled_repos_ids - @stored_enabled_repos_ids ||= begin - path = File.expand_path('enabled_repos.yml', ForemanMaintain.config.backup_dir) - @stored_enabled_repos_ids = File.file?(path) ? YAML.load(File.read(path)) : [] - end - end - - def all_maintenance_repos - repo_regex = if el7? - /rhel-\d-server-satellite-maintenance-\d.\d-rpms/ - else - /satellite-maintenance-\d.\d-for-rhel-\d-x86_64-rpms/ - end - stored_enabled_repos_ids.select { |id| !id.match(repo_regex).nil? } - end - - def repos_ids_to_reenable - repos_ids_to_reenable = stored_enabled_repos_ids - all_maintenance_repos - if use_rhsm? - repos_ids_to_reenable << maintenance_repo(maintenance_repo_version) - end - repos_ids_to_reenable - end - def use_rhsm? return false if maintenance_repo_label @@ -100,30 +58,11 @@ class SelfUpgrade < SelfUpgradeBase def compose if check_min_version('foreman', '2.5') || check_min_version('foreman-proxy', '2.5') pkgs_to_update = %w[satellite-maintain rubygem-foreman_maintain] - add_step(Procedures::Repositories::BackupEnabledRepos.new) - disable_repos - add_step(Procedures::Repositories::Enable.new(repos: req_repos_to_update_pkgs, - use_rhsm: use_rhsm?)) - add_step(Procedures::Packages::Update.new(packages: pkgs_to_update, assumeyes: true)) - disable_repos('*') - enable_repos(repos_ids_to_reenable) - end - end - end - - class SelfUpgradeRescue < SelfUpgradeBase - metadata do - label :rescue_self_upgrade - description 'Disables all version specific maintenance repositories and,'\ - "\nenables the repositories which were configured prior to self upgrade" - manual_detection - run_strategy :fail_slow - end - - def compose - if check_min_version('foreman', '2.5') || check_min_version('foreman-proxy', '2.5') - disable_repos('*') - enable_repos(repos_ids_to_reenable) + yum_options = req_repos_to_update_pkgs.map do |id| + "--enablerepo=#{id}" + end + add_step(Procedures::Packages::Update.new(packages: pkgs_to_update, assumeyes: true, + yum_options: yum_options)) end end end diff --git a/lib/foreman_maintain/cli/self_upgrade_command.rb b/lib/foreman_maintain/cli/self_upgrade_command.rb index f63837c8a..32be39a97 100644 --- a/lib/foreman_maintain/cli/self_upgrade_command.rb +++ b/lib/foreman_maintain/cli/self_upgrade_command.rb @@ -5,7 +5,7 @@ class SelfUpgradeCommand < Base 'Repository label from which packages should be updated.'\ 'This can be used when standard CDN repositories are unavailable.' def execute - run_scenario(upgrade_scenario, upgrade_rescue_scenario) + run_scenario(upgrade_scenario) end def upgrade_scenario @@ -13,12 +13,6 @@ def upgrade_scenario maintenance_repo_label: maintenance_repo_label ) end - - def upgrade_rescue_scenario - Scenarios::SelfUpgradeRescue.new( - maintenance_repo_label: maintenance_repo_label - ) - end end end end diff --git a/lib/foreman_maintain/concerns/system_helpers.rb b/lib/foreman_maintain/concerns/system_helpers.rb index 736019e62..94f00b883 100644 --- a/lib/foreman_maintain/concerns/system_helpers.rb +++ b/lib/foreman_maintain/concerns/system_helpers.rb @@ -100,12 +100,13 @@ def server? end def packages_action(action, packages, options = {}) - options.validate_options!(:assumeyes) + options.validate_options!(:assumeyes, :yum_options) case action when :install package_manager.install(packages, :assumeyes => options[:assumeyes]) when :update - package_manager.update(packages, :assumeyes => options[:assumeyes]) + package_manager.update(packages, :assumeyes => options[:assumeyes], + :yum_options => options[:yum_options]) when :remove package_manager.remove(packages, :assumeyes => options[:assumeyes]) else diff --git a/lib/foreman_maintain/package_manager/yum.rb b/lib/foreman_maintain/package_manager/yum.rb index bc84a1e10..56cfcd7aa 100644 --- a/lib/foreman_maintain/package_manager/yum.rb +++ b/lib/foreman_maintain/package_manager/yum.rb @@ -55,8 +55,8 @@ def remove(packages, assumeyes: false) yum_action('remove', packages, :assumeyes => assumeyes) end - def update(packages = [], assumeyes: false) - yum_action('update', packages, :assumeyes => assumeyes) + def update(packages = [], assumeyes: false, yum_options: []) + yum_action('update', packages, :assumeyes => assumeyes, :yum_options => yum_options) end def clean_cache(assumeyes: false) @@ -116,8 +116,12 @@ def setup_protector(enabled) File.open(protector_config_file, 'w') { |file| file.puts config } end - def yum_action(action, packages, with_status: false, assumeyes: false, valid_exit_statuses: [0]) - yum_options = [] + # rubocop:disable Metrics/AbcSize, Metrics/MethodLength + def yum_action(action, packages, options) + with_status = options.fetch(:with_status, false) + assumeyes = options.fetch(:assumeyes, false) + valid_exit_statuses = options.fetch(:valid_exit_statuses, [0]) + yum_options = options.fetch(:yum_options, []) packages = [packages].flatten(1) yum_options << '-y' if assumeyes yum_options << '--disableplugin=foreman-protector' diff --git a/test/definitions/scenarios/self_upgrade_test.rb b/test/definitions/scenarios/self_upgrade_test.rb deleted file mode 100644 index d9e04e0ae..000000000 --- a/test/definitions/scenarios/self_upgrade_test.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'test_helper' - -module Scenarios - describe ForemanMaintain::Scenarios::SelfUpgrade do - include DefinitionsTestHelper - - let(:scenario) do - ForemanMaintain::Scenarios::SelfUpgrade.new - end - - describe 'using CDN' do - it 'reenables maintenance repo' do - scenario.stubs(:stored_enabled_repos_ids).returns([]) - scenario.stubs(:current_version).returns('6.10') - scenario.stubs(:el_major_version).returns(7) - assert_equal ['rhel-7-server-satellite-maintenance-6-rpms'], scenario.repos_ids_to_reenable - end - end - - describe 'using custom repos' do - it 'does not reenable maintenance repo if it was disabled' do - scenario.stubs(:stored_enabled_repos_ids).returns([]) - scenario.stubs(:current_version).returns('6.10') - scenario.stubs(:el_major_version).returns(7) - scenario.stubs(:maintenance_repo_label).returns('custom-maintenance') - assert_equal [], scenario.repos_ids_to_reenable - end - - it 'reenables maintenance repo if it was enabled' do - scenario.stubs(:stored_enabled_repos_ids).returns(['custom-maintenance']) - scenario.stubs(:current_version).returns('6.10') - scenario.stubs(:el_major_version).returns(7) - scenario.stubs(:maintenance_repo_label).returns('custom-maintenance') - assert_equal ['custom-maintenance'], scenario.repos_ids_to_reenable - end - end - end -end