summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorSteven Danna <steve@opscode.com>2015-03-30 14:56:27 +0100
committerSteven Danna <steve@opscode.com>2015-03-31 12:01:13 +0100
commit9c5deecf8da150ca44b0494573f8c6b0d80d40fa (patch)
tree27a65ef665f803dd2a8bf088668f1c4898287020 /spec
parenteaa56e53be8d71665a5b9a828db54898b7b36fc8 (diff)
downloadchef-9c5deecf8da150ca44b0494573f8c6b0d80d40fa.tar.gz
Use the same python interpreter as yum when possiblessd/find-python
We rely on a system python installation with the correct python libraries. To improve the chances that the python interpreter we call has the yum libary available, we use the same interpreter as yum uses. Fixes #3143
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/provider/package/yum_spec.rb36
1 files changed, 35 insertions, 1 deletions
diff --git a/spec/unit/provider/package/yum_spec.rb b/spec/unit/provider/package/yum_spec.rb
index 865dce23fa..8f4bde7f62 100644
--- a/spec/unit/provider/package/yum_spec.rb
+++ b/spec/unit/provider/package/yum_spec.rb
@@ -17,6 +17,7 @@
#
require 'spec_helper'
+require 'securerandom'
describe Chef::Provider::Package::Yum do
before(:each) do
@@ -1659,6 +1660,14 @@ describe Chef::Provider::Package::Yum::YumCache do
end
end
+ let(:yum_exe) {
+ StringIO.new("#!/usr/bin/python\n\naldsjfa\ldsajflkdsjf\lajsdfj")
+ }
+
+ let(:bin_exe) {
+ StringIO.new(SecureRandom.random_bytes)
+ }
+
before(:each) do
@stdin = double("STDIN", :nil_object => true)
@stdout = double("STDOUT", :nil_object => true)
@@ -1704,12 +1713,19 @@ file: file://///etc/yum.repos.d/CentOS-Base.repo, line: 12
'qeqwewe\n'
EOF
@status = double("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_good, :stderr => @stderr)
-
# new singleton each time
Chef::Provider::Package::Yum::YumCache.reset_instance
@yc = Chef::Provider::Package::Yum::YumCache.instance
# load valid data
allow(@yc).to receive(:shell_out!).and_return(@status)
+ allow_any_instance_of(described_class).to receive(:which).with("yum").and_return("/usr/bin/yum")
+ allow(::File).to receive(:open).with("/usr/bin/yum", "r") do |&block|
+ res = block.call(yum_exe)
+ # a bit of a hack. rewind this since it seem that no matter what
+ # I do, we get the same StringIO objects on multiple calls to
+ # ::File.open
+ yum_exe.rewind; res
+ end
end
describe "initialize" do
@@ -1726,6 +1742,24 @@ EOF
end
end
+ describe "python_bin" do
+ it "should return the default python if an error occurs" do
+ allow(::File).to receive(:open).with("/usr/bin/yum", "r").and_raise(StandardError)
+ expect(@yc.python_bin).to eq("/usr/bin/python")
+ end
+
+ it "should return the default python if the yum-executable doesn't start with #!" do
+ allow(::File).to receive(:open).with("/usr/bin/yum", "r") { |&b| r = b.call(bin_exe); bin_exe.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}
+ expect(@yc.python_bin).to eq("/usr/bin/super_python")
+ end
+ end
+
describe "refresh" do
it "should implicitly call yum-dump.py only once by default after being instantiated" do
expect(@yc).to receive(:shell_out!).once