Skip to content

Commit

Permalink
Convert all code to use DNF
Browse files Browse the repository at this point in the history
  • Loading branch information
ehelms committed Sep 7, 2023
1 parent c4d7755 commit 1e20bbd
Show file tree
Hide file tree
Showing 22 changed files with 366 additions and 484 deletions.
5 changes: 2 additions & 3 deletions definitions/checks/check_hotfix_installed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ class Checks::CheckHotfixInstalled < ForemanMaintain::Check
description 'Check to verify if any hotfix installed on system'
tags :pre_upgrade
preparation_steps do
[Checks::Repositories::CheckNonRhRepository.new,
Procedures::Packages::Install.new(:packages => %w[yum-utils])]
[Checks::Repositories::CheckNonRhRepository.new]
end

confine do
Expand Down Expand Up @@ -45,7 +44,7 @@ def modified_files(package)

def installed_packages
packages = []
IO.popen(['repoquery', '-a', '--installed', '--qf', query_format]) do |io|
IO.popen(['dnf', 'repoquery', '-a', '--installed', '--qf', query_format]) do |io|
io.each do |line|
repo, pkg = line.chomp.split
next if repo.nil? || pkg.nil?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Checks::PackageManager
module Yum
class ValidateYumConfig < ForemanMaintain::Check
module Dnf
class ValidateDnfConfig < ForemanMaintain::Check
metadata do
label :validate_yum_config
description 'Check to validate yum configuration before upgrade'
label :validate_dnf_config
description 'Check to validate dnf configuration before upgrade'
tags :pre_upgrade
end

Expand All @@ -17,30 +17,32 @@ def run

private

# rubocop:disable Metrics/LineLength
def failure_message(final_result)
verb_string = final_result[:matched_keys].length > 1 ? 'are' : 'is'

"#{final_result[:matched_keys].join(',')} #{verb_string} set in /etc/yum.conf as below:"\
"#{final_result[:matched_keys].join(',')} #{verb_string} set in /etc/dnf/dnf.conf as below:"\
"\n#{final_result[:grep_output]}"\
"\nUnset this configuration as it is risky while yum update or upgrade!"
"\nUnset this configuration as it is risky while dnf update or upgrade!"
end
# rubocop:enable Metrics/LineLength

def verify_config_options
result = {}
combined_regex = yum_config_options.values.join('|')
combined_regex = dnf_config_options.values.join('|')
result[:grep_output] = execute_grep_cmd(combined_regex)
result[:matched_keys] = yum_config_options.keys.select do |key|
result[:matched_keys] = dnf_config_options.keys.select do |key|
result[:grep_output].include?(key)
end
result
end

def execute_grep_cmd(regex_string)
execute_with_status("grep -iE '#{regex_string}' /etc/yum.conf")[1]
execute_with_status("grep -iE '#{regex_string}' /etc/dnf/dnf.conf")[1]
end

def yum_config_options
@yum_config_options ||= {
def dnf_config_options
@dnf_config_options ||= {
'exclude' => '^exclude\s*=\s*\S+.*$',
}
end
Expand Down
3 changes: 1 addition & 2 deletions definitions/checks/repositories/check_upstream_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ class Checks::CheckUpstreamRepository < ForemanMaintain::Check
description 'Check if any upstream repositories are enabled on system'
tags :pre_upgrade
preparation_steps do
[Checks::Repositories::CheckNonRhRepository.new,
Procedures::Packages::Install.new(:packages => %w[yum-utils])]
[Checks::Repositories::CheckNonRhRepository.new]
end
confine do
feature(:instance).downstream
Expand Down
2 changes: 1 addition & 1 deletion definitions/procedures/packages/installer_confirmation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class InstallerConfirmation < ForemanMaintain::Procedure

def run
question = "\nWARNING: This script runs #{feature(:installer).installer_command} " \
"after the yum execution \n" \
"after the dnf execution \n" \
"to ensure the #{feature(:instance).product_name} " \
"is in a consistent state.\n" \
"As a result some of your services may be restarted. \n\n" \
Expand Down
6 changes: 3 additions & 3 deletions definitions/procedures/packages/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ 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 => []
param :dnf_options, 'Extra dnf options if any', :array => true, :default => []
end

def run
assumeyes_val = @assumeyes.nil? ? assumeyes? : @assumeyes
package_manager.clean_cache(:assumeyes => assumeyes_val)
opts = { :assumeyes => assumeyes_val, :yum_options => @yum_options }
opts = { :assumeyes => assumeyes_val, :dnf_options => @dnf_options }
packages_action(:update, @packages, opts)
rescue ForemanMaintain::Error::ExecutionError => e
if @warn_on_errors
Expand All @@ -27,7 +27,7 @@ def necessary?
end

def description
if @yum_options.include?('--downloadonly')
if @dnf_options.include?('--downloadonly')
"Download package(s) #{@packages.join(', ')}"
else
"Update package(s) #{@packages.join(', ')}"
Expand Down
10 changes: 4 additions & 6 deletions definitions/scenarios/self_upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,11 @@ class SelfUpgrade < SelfUpgradeBase
def downstream_self_upgrade(pkgs_to_update)
ForemanMaintain.enable_maintenance_module

if check_min_version('foreman', '2.5') || check_min_version('foreman-proxy', '2.5')
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))
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))
end

def upstream_self_upgrade(pkgs_to_update)
Expand Down
2 changes: 1 addition & 1 deletion definitions/scenarios/upgrade_to_capsule_6_15.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def compose
modules_to_enable = ["satellite-capsule:#{el_short_name}"]
add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable))
add_step(Procedures::Packages::Update.new(:assumeyes => true,
:yum_options => ['--downloadonly']))
:dnf_options => ['--downloadonly']))
add_step(Procedures::Service::Stop.new)
add_step(Procedures::Packages::Update.new(:assumeyes => true))
add_step_with_context(Procedures::Installer::Upgrade)
Expand Down
2 changes: 1 addition & 1 deletion definitions/scenarios/upgrade_to_capsule_6_15_z.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def compose
modules_to_enable = ["satellite-capsule:#{el_short_name}"]
add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable))
add_step(Procedures::Packages::Update.new(:assumeyes => true,
:yum_options => ['--downloadonly']))
:dnf_options => ['--downloadonly']))
add_step(Procedures::Service::Stop.new)
add_step(Procedures::Packages::Update.new(:assumeyes => true))
add_step_with_context(Procedures::Installer::Upgrade)
Expand Down
2 changes: 1 addition & 1 deletion definitions/scenarios/upgrade_to_katello_nightly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def compose
modules_to_enable = ["katello:#{el_short_name}", "pulpcore:#{el_short_name}"]
add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable))
add_step(Procedures::Packages::Update.new(:assumeyes => true,
:yum_options => ['--downloadonly']))
:dnf_options => ['--downloadonly']))
add_step(Procedures::Service::Stop.new)
add_step(Procedures::Packages::Update.new(:assumeyes => true))
add_step_with_context(Procedures::Installer::Upgrade)
Expand Down
2 changes: 1 addition & 1 deletion definitions/scenarios/upgrade_to_satellite_6_15.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def compose
modules_to_enable = ["satellite:#{el_short_name}"]
add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable))
add_step(Procedures::Packages::Update.new(:assumeyes => true,
:yum_options => ['--downloadonly']))
:dnf_options => ['--downloadonly']))
add_step(Procedures::Service::Stop.new)
add_step(Procedures::Packages::Update.new(:assumeyes => true))
add_step_with_context(Procedures::Installer::Upgrade)
Expand Down
2 changes: 1 addition & 1 deletion definitions/scenarios/upgrade_to_satellite_6_15_z.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def compose
modules_to_enable = ["satellite:#{el_short_name}"]
add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable))
add_step(Procedures::Packages::Update.new(:assumeyes => true,
:yum_options => ['--downloadonly']))
:dnf_options => ['--downloadonly']))
add_step(Procedures::Service::Stop.new)
add_step(Procedures::Packages::Update.new(:assumeyes => true))
add_step_with_context(Procedures::Installer::Upgrade)
Expand Down
2 changes: 1 addition & 1 deletion extras/foreman_protector/foreman-protector.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[main]
enabled = 0
whitelist = /etc/yum/pluginconf.d/foreman-protector.whitelist
whitelist = /etc/dnf/plugins/foreman-protector.whitelist
86 changes: 0 additions & 86 deletions extras/foreman_protector/yum/foreman-protector.py

This file was deleted.

4 changes: 2 additions & 2 deletions lib/foreman_maintain/concerns/system_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ def server?
end

def packages_action(action, packages, options = {})
options.validate_options!(:assumeyes, :yum_options)
options.validate_options!(:assumeyes, :dnf_options)
case action
when :install
package_manager.install(packages, :assumeyes => options[:assumeyes])
when :update
package_manager.update(packages, :assumeyes => options[:assumeyes],
:yum_options => options[:yum_options])
:dnf_options => options[:dnf_options])
when :remove
package_manager.remove(packages, :assumeyes => options[:assumeyes])
else
Expand Down
1 change: 0 additions & 1 deletion lib/foreman_maintain/package_manager.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'foreman_maintain/package_manager/base'
require 'foreman_maintain/package_manager/yum'
require 'foreman_maintain/package_manager/dnf'
require 'foreman_maintain/package_manager/apt'

Expand Down
Loading

0 comments on commit 1e20bbd

Please sign in to comment.