diff --git a/definitions/procedures/packages/update.rb b/definitions/procedures/packages/update.rb index 19ab9dbb6..c33795968 100644 --- a/definitions/procedures/packages/update.rb +++ b/definitions/procedures/packages/update.rb @@ -8,6 +8,7 @@ class Update < ForemanMaintain::Procedure :flag => true, :default => false param :download_only, 'Download and cache packages only', :flag => true, :default => false param :clean_cache, 'If true will cause a DNF cache clean', :flag => true, :default => true + param :enabled_repos, 'List of repositories to enable', :array => true end def run @@ -16,6 +17,7 @@ def run opts = { :assumeyes => assumeyes_val, :download_only => @download_only, + :enabled_repos => @enabled_repos, } packages_action(:update, @packages, opts) rescue ForemanMaintain::Error::ExecutionError => e diff --git a/definitions/scenarios/self_upgrade.rb b/definitions/scenarios/self_upgrade.rb index 84cf770aa..841d5876d 100644 --- a/definitions/scenarios/self_upgrade.rb +++ b/definitions/scenarios/self_upgrade.rb @@ -67,11 +67,8 @@ class SelfUpgrade < SelfUpgradeBase def downstream_self_upgrade(pkgs_to_update) ForemanMaintain.enable_maintenance_module - dnf_options = req_repos_to_update_pkgs.map do |id| - "--enablerepo=#{id}" - end add_step(Procedures::Packages::Update.new(packages: pkgs_to_update, assumeyes: true, - dnf_options: dnf_options)) + enabled_repos: req_repos_to_update_pkgs)) end def upstream_self_upgrade(pkgs_to_update) diff --git a/lib/foreman_maintain/concerns/system_helpers.rb b/lib/foreman_maintain/concerns/system_helpers.rb index 22813ea90..ad1fe81ef 100644 --- a/lib/foreman_maintain/concerns/system_helpers.rb +++ b/lib/foreman_maintain/concerns/system_helpers.rb @@ -100,7 +100,7 @@ def server? end def packages_action(action, packages, options = {}) - options.validate_options!(:assumeyes, :options, :download_only) + options.validate_options!(:assumeyes, :options, :download_only, :enabled_repos) case action when :install package_manager.install(packages, :assumeyes => options[:assumeyes]) @@ -108,7 +108,8 @@ def packages_action(action, packages, options = {}) package_manager.update( packages, :assumeyes => options[:assumeyes], - :download_only => options[:download_only] + :download_only => options[:download_only], + :enabled_repos => options[:enabled_repos] ) when :remove package_manager.remove(packages, :assumeyes => options[:assumeyes]) diff --git a/lib/foreman_maintain/package_manager/apt.rb b/lib/foreman_maintain/package_manager/apt.rb index 345859a31..79a73ef8e 100644 --- a/lib/foreman_maintain/package_manager/apt.rb +++ b/lib/foreman_maintain/package_manager/apt.rb @@ -19,10 +19,12 @@ def remove(packages, assumeyes: false) apt_action('remove', packages, :assumeyes => assumeyes) end - def update(packages = [], assumeyes: false, download_only: false) + # rubocop:disable Lint/UnusedMethodArgument + def update(packages = [], assumeyes: false, download_only: false, enabled_repos: []) action = packages.any? ? '--only-upgrade install' : 'upgrade' apt_action(action, packages, :assumeyes => assumeyes, :download_only => download_only) end + # rubocop:enable Lint/UnusedMethodArgument def clean_cache(assumeyes: false) apt_action('clean', [], :assumeyes => assumeyes) diff --git a/lib/foreman_maintain/package_manager/dnf.rb b/lib/foreman_maintain/package_manager/dnf.rb index b7bcdee21..e2c95718b 100644 --- a/lib/foreman_maintain/package_manager/dnf.rb +++ b/lib/foreman_maintain/package_manager/dnf.rb @@ -59,12 +59,13 @@ def remove(packages, assumeyes: false) dnf_action('remove', packages, assumeyes: assumeyes) end - def update(packages = [], assumeyes: false, download_only: false) + def update(packages = [], assumeyes: false, download_only: false, enabled_repos: []) dnf_action( 'update', packages, assumeyes: assumeyes, - download_only: download_only + download_only: download_only, + enabled_repos: enabled_repos ) end @@ -132,14 +133,18 @@ def reboot_required? private - # rubocop:disable Layout/LineLength, Metrics/ParameterLists - def dnf_action(action, packages, with_status: false, assumeyes: false, dnf_options: [], valid_exit_statuses: [0], download_only: false) + # rubocop:disable Layout/LineLength, Metrics/ParameterLists, Metrics/MethodLength + def dnf_action(action, packages, with_status: false, assumeyes: false, dnf_options: [], valid_exit_statuses: [0], download_only: false, enabled_repos: []) packages = [packages].flatten(1) dnf_options << '-y' if assumeyes dnf_options << '--downloadonly' if download_only dnf_options << '--disableplugin=foreman-protector' + enabled_repos.map do |id| + dnf_options << "--enablerepo=#{id}" + end + command = ['dnf', dnf_options.join(' '), action] command.push(packages.join(' ')) unless packages.empty? @@ -158,7 +163,7 @@ def dnf_action(action, packages, with_status: false, assumeyes: false, dnf_optio ) end end - # rubocop:enable Layout/LineLength, Metrics/ParameterLists + # rubocop:enable Layout/LineLength, Metrics/ParameterLists, Metrics/MethodLength def protector_config File.exist?(protector_config_file) ? File.read(protector_config_file) : ''