diff options
author | Tim Smith <tsmith84@gmail.com> | 2015-11-05 10:00:05 -0800 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2015-11-05 10:00:05 -0800 |
commit | a65408a6d005ec5ca9270b0efd42fec74c7b7087 (patch) | |
tree | 1a869612a94fff06c897ec60955f7527fd6165bc | |
parent | 5020cc6df7cffe45eddddbedcc2a1e18c55cf1e5 (diff) | |
download | chef-a65408a6d005ec5ca9270b0efd42fec74c7b7087.tar.gz |
Use the proper python interpretor for yum-dump.py on Fedora 21+
Fedora 21+ use dnf as the primary package manager. Lamont added code in
12.5 to allow for a yum compat mode. This doesn't entirely work though
as we need yum-dump.py to correctly run. We were parsing the shabang in
the yum binary to find the path to python. On a dnf system the yum
binary is a bash script though so we were trying to run yum-dump.py
using bash which obviously fails. I added a fallback method to use
python if the shebang parsing returns bash. With this in place AND the
yum package installed you can use the package resource on Fedora.
-rw-r--r-- | lib/chef/provider/package/yum.rb | 14 | ||||
-rw-r--r-- | spec/unit/provider/package/yum_spec.rb | 6 |
2 files changed, 18 insertions, 2 deletions
diff --git a/lib/chef/provider/package/yum.rb b/lib/chef/provider/package/yum.rb index aff8dc9326..6258472a65 100644 --- a/lib/chef/provider/package/yum.rb +++ b/lib/chef/provider/package/yum.rb @@ -785,7 +785,7 @@ class Chef def python_bin yum_executable = which(yum_binary) if yum_executable && shabang?(yum_executable) - extract_interpreter(yum_executable) + shabang_or_fallback(extract_interpreter(yum_executable)) else Chef::Log.warn("Yum executable not found or doesn't start with #!. Using default python.") "/usr/bin/python" @@ -797,7 +797,17 @@ class Chef end def extract_interpreter(file) - ::File.open(file, 'r', &:readline)[2..-1].chomp + ::File.open(file, 'r', &:readline)[2..-1].strip + end + + # dnf based systems have a yum shim that has /bin/bash as the interpreter. Don't use this. + def shabang_or_fallback(interpreter) + if interpreter == '/bin/bash' + Chef::Log.warn("Yum executable interpreter is /bin/bash. Falling back to default python.") + "/usr/bin/python" + else + interpreter + end end def shabang?(file) diff --git a/spec/unit/provider/package/yum_spec.rb b/spec/unit/provider/package/yum_spec.rb index 3fc0b807c9..b37a675bf2 100644 --- a/spec/unit/provider/package/yum_spec.rb +++ b/spec/unit/provider/package/yum_spec.rb @@ -1844,6 +1844,12 @@ EOF expect(@yc.python_bin).to eq("/usr/bin/python") end + it "should return /usr/bin/python if the interpreter is /bin/bash" do + other = StringIO.new("#!/bin/bash\n# The yum executable redirecting to dnf from dnf-yum compatible package.") + allow(::File).to receive(:open).with("/usr/bin/yum", "r") { |&b| r = b.call(other); other.rewind; r} + expect(@yc.python_bin).to eq("/usr/bin/python") + end + it "should return the interpreter for yum" do other = StringIO.new("#!/usr/bin/super_python\n\nlasjdfdsaljf\nlasdjfs") allow(::File).to receive(:open).with("/usr/bin/yum", "r") { |&b| r = b.call(other); other.rewind; r} |