diff options
author | Thom May <thom@may.lt> | 2015-11-12 10:08:53 +0000 |
---|---|---|
committer | Thom May <thom@may.lt> | 2015-11-12 10:08:53 +0000 |
commit | 8ca5eb3981a630aa11e8431ec8d7dd34236ebc36 (patch) | |
tree | a4755572ace1395e84c5dbbf98e5abfb461927e4 | |
parent | f4a47f9e248d99fe6c284bcbff7c2b05d6dd0484 (diff) | |
parent | a65408a6d005ec5ca9270b0efd42fec74c7b7087 (diff) | |
download | chef-8ca5eb3981a630aa11e8431ec8d7dd34236ebc36.tar.gz |
Merge pull request #4142 from tas50/master
Use the proper python interpretor for yum-dump.py on Fedora 21+
-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} |