summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-02-27 14:26:27 -0800
committerTim Smith <tsmith84@gmail.com>2020-02-27 14:26:27 -0800
commitdeb4635c18e3bb68557b8f9691ea2df12b98ee66 (patch)
treecab8d0c5c52ae465fffa38da621a34b2735f3020
parent81e3a990bb1960392700f76153f896132d3ca7ed (diff)
downloadchef-deb4635c18e3bb68557b8f9691ea2df12b98ee66.tar.gz
Make sure we don't break the world in RHEL 9
I was thinking about how to accomplish this a bit. At first I figured we should use the which helper and maybe just make a dnf? question helper, but we really care about RHEL 8 here and not RHEL 7 if it has DNF. Also since this only works on Redhat we don't have to worry about all the other platforms that also have DNF since they don't apply to this resource. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/rhsm_errata.rb8
-rw-r--r--lib/chef/resource/rhsm_errata_level.rb8
-rw-r--r--lib/chef/resource/rhsm_register.rb10
3 files changed, 20 insertions, 6 deletions
diff --git a/lib/chef/resource/rhsm_errata.rb b/lib/chef/resource/rhsm_errata.rb
index 8be53340dc..aa08847d10 100644
--- a/lib/chef/resource/rhsm_errata.rb
+++ b/lib/chef/resource/rhsm_errata.rb
@@ -37,11 +37,17 @@ class Chef
description "Installs a package for a specific errata ID."
execute "Install errata packages for #{new_resource.errata_id}" do
- command "{rhel8? ? 'dnf' : 'yum'} update --advisory #{new_resource.errata_id} -y"
+ command "#{package_manager_command} update --advisory #{new_resource.errata_id} -y"
default_env true
action :run
end
end
+
+ action_class do
+ def package_manager_command
+ node["platform_version"].to_i >= 8 ? "dnf" : "yum"
+ end
+ end
end
end
end
diff --git a/lib/chef/resource/rhsm_errata_level.rb b/lib/chef/resource/rhsm_errata_level.rb
index 47b43055f9..4ab2d8662d 100644
--- a/lib/chef/resource/rhsm_errata_level.rb
+++ b/lib/chef/resource/rhsm_errata_level.rb
@@ -41,11 +41,17 @@ class Chef
end
execute "Install any #{new_resource.errata_level} errata" do
- command "{rhel8? ? 'dnf' : 'yum'} update --sec-severity=#{new_resource.errata_level.capitalize} -y"
+ command "#{package_manager_command} update --sec-severity=#{new_resource.errata_level.capitalize} -y"
default_env true
action :run
end
end
+
+ action_class do
+ def package_manager_command
+ node["platform_version"].to_i >= 8 ? "dnf" : "yum"
+ end
+ end
end
end
end
diff --git a/lib/chef/resource/rhsm_register.rb b/lib/chef/resource/rhsm_register.rb
index 7d1523ce72..322dfdf701 100644
--- a/lib/chef/resource/rhsm_register.rb
+++ b/lib/chef/resource/rhsm_register.rb
@@ -70,13 +70,11 @@ class Chef
remote_file "#{Chef::Config[:file_cache_path]}/katello-package.rpm" do
source "http://#{new_resource.satellite_host}/pub/katello-ca-consumer-latest.noarch.rpm"
action :create
- notifies :install, "{rhel8? ? 'dnf' : 'yum'}_package[katello-ca-consumer-latest]", :immediately
+ notifies :install, "#{package_resource}[katello-ca-consumer-latest]", :immediately
not_if { katello_cert_rpm_installed? }
end
- resource_type = rhel8? ? :dnf_package : :yum_package
-
- declare_resource(resource_type, "katello-ca-consumer-latest") do
+ declare_resource(package_resource.to_sym, "katello-ca-consumer-latest") do
options "--nogpgcheck"
source "#{Chef::Config[:file_cache_path]}/katello-package.rpm"
action :nothing
@@ -119,6 +117,10 @@ class Chef
end
action_class do
+ def package_resource
+ node["platform_version"].to_i >= 8 ? "dnf_package" : "yum_package"
+ end
+
def registered_with_rhsm?
cmd = Mixlib::ShellOut.new("subscription-manager status", env: { LANG: "en_US" })
cmd.run_command