summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@chef.io>2019-10-10 13:52:00 -0700
committerGitHub <noreply@github.com>2019-10-10 13:52:00 -0700
commit424bed13569aca061b7d1ea540edcac91823b8e7 (patch)
tree18b6948afd3f5ea465e368c30a9b3c6146d42bdb
parentaf84331d25595728e0521a7d4dee816d310846e4 (diff)
parenta9ff83a73d06fb6a94c0b782ec80a49ca56d7fc9 (diff)
downloadchef-424bed13569aca061b7d1ea540edcac91823b8e7.tar.gz
Fix yum & dnf shellout if exit with nonzero status (#8972)
Fix yum & dnf shellout if exit with nonzero status
-rw-r--r--lib/chef/provider/package/dnf/python_helper.rb11
-rw-r--r--lib/chef/provider/package/yum/python_helper.rb11
2 files changed, 16 insertions, 6 deletions
diff --git a/lib/chef/provider/package/dnf/python_helper.rb b/lib/chef/provider/package/dnf/python_helper.rb
index c5edbfbc3a..176ed55d3d 100644
--- a/lib/chef/provider/package/dnf/python_helper.rb
+++ b/lib/chef/provider/package/dnf/python_helper.rb
@@ -38,9 +38,14 @@ class Chef
def dnf_command
# platform-python is used for system tools on RHEL 8 and is installed under /usr/libexec
- @dnf_command ||= which("platform-python", "python", "python3", "python2", "python2.7", extra_path: "/usr/libexec") do |f|
- shell_out("#{f} -c 'import dnf'").exitstatus == 0
- end + " #{DNF_HELPER}"
+ @dnf_command ||= begin
+ cmd = which("platform-python", "python", "python3", "python2", "python2.7", extra_path: "/usr/libexec") do |f|
+ shell_out("#{f} -c 'import dnf'").exitstatus == 0
+ end
+ raise Chef::Exceptions::Package, "cannot find dnf libraries, you may need to use yum_package" unless cmd
+
+ "#{cmd} #{DNF_HELPER}"
+ end
end
def start
diff --git a/lib/chef/provider/package/yum/python_helper.rb b/lib/chef/provider/package/yum/python_helper.rb
index f99b17bcce..c893827a60 100644
--- a/lib/chef/provider/package/yum/python_helper.rb
+++ b/lib/chef/provider/package/yum/python_helper.rb
@@ -40,9 +40,14 @@ class Chef
YUM_HELPER = ::File.expand_path(::File.join(::File.dirname(__FILE__), "yum_helper.py")).freeze
def yum_command
- @yum_command ||= which("platform-python", "python", "python2", "python2.7", extra_path: "/usr/libexec") do |f|
- shell_out("#{f} -c 'import yum'").exitstatus == 0
- end + " #{YUM_HELPER}"
+ @yum_command ||= begin
+ cmd = which("platform-python", "python", "python2", "python2.7", extra_path: "/usr/libexec") do |f|
+ shell_out("#{f} -c 'import yum'").exitstatus == 0
+ end
+ raise Chef::Exceptions::Package, "cannot find yum libraries, you may need to use dnf_package" unless cmd
+
+ "#{cmd} #{YUM_HELPER}"
+ end
end
def start