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

Fix self-upgrade by adding enabled-repos support to dnf #859

Merged
merged 1 commit into from
Jun 4, 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
2 changes: 2 additions & 0 deletions definitions/procedures/packages/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 1 addition & 4 deletions definitions/scenarios/self_upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
ehelms marked this conversation as resolved.
Show resolved Hide resolved
enabled_repos: req_repos_to_update_pkgs))
end

def upstream_self_upgrade(pkgs_to_update)
Expand Down
5 changes: 3 additions & 2 deletions lib/foreman_maintain/concerns/system_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,16 @@ 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])
when :update
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])
Expand Down
4 changes: 3 additions & 1 deletion lib/foreman_maintain/package_manager/apt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 10 additions & 5 deletions lib/foreman_maintain/package_manager/dnf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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?
Expand All @@ -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) : ''
Expand Down
Loading