[Pkg-puppet-devel] [SCM] Packaging of Facter for debian branch, upstream, updated. 51bcebe38cab6088c901f1006339bbe40a36d161
Paul Nasrat
pnasrat at googlemail.com
Wed Aug 18 05:55:42 UTC 2010
The following commit has been merged in the upstream branch:
commit 86447c884a47948a4ef6757ff7e7d2e0faf93ff5
Author: Paul Nasrat <pnasrat at googlemail.com>
Date: Sun Feb 28 13:50:52 2010 +0000
Revert "use popen3 in Resolution.exec"
This reverts commit 33fb7709404e706801683e6c47ab7a0a5a1884b1.
This has broken master for some facts (eg OS X facts), it also breaks facter
platform support on win32 as popen3 does not work there.
I'd like to get master working, backlog of patches applied and revisit exec.
Paul
diff --git a/lib/facter/util/resolution.rb b/lib/facter/util/resolution.rb
index f6afce6..b9e28e8 100644
--- a/lib/facter/util/resolution.rb
+++ b/lib/facter/util/resolution.rb
@@ -7,7 +7,6 @@ require 'facter/util/confine'
require 'timeout'
require 'rbconfig'
-require 'open3'
class Facter::Util::Resolution
attr_accessor :interpreter, :code, :name, :timeout
@@ -43,27 +42,17 @@ class Facter::Util::Resolution
end
out = nil
- err = nil
begin
- Open3.popen3(code) do |stdin,stdout,stderr|
- out = self.parse_output(stdout.readlines)
- err = self.parse_output(stderr.readlines)
- end
+ out = %x{#{code}}.chomp
rescue => detail
$stderr.puts detail
return nil
end
- Facter.warn(err)
-
- return nil if out == ""
- out
- end
-
- def self.parse_output(output)
- return nil unless output and output.size > 0
- result = output.collect{|line| line.chomp }
- return result.first unless result.size > 1
- result
+ if out == ""
+ return nil
+ else
+ return out
+ end
end
# Add a new confine to the resolution mechanism.
diff --git a/spec/unit/util/resolution.rb b/spec/unit/util/resolution.rb
index 27cb150..d4bb781 100755
--- a/spec/unit/util/resolution.rb
+++ b/spec/unit/util/resolution.rb
@@ -227,54 +227,10 @@ describe Facter::Util::Resolution do
Facter::Util::Resolution.should respond_to(:exec)
end
- it "should have a class method to parse output" do
- Facter::Util::Resolution.should respond_to(:parse_output)
- end
-
# It's not possible, AFAICT, to mock %x{}, so I can't really test this bit.
describe "when executing code" do
it "should fail if any interpreter other than /bin/sh is requested" do
lambda { Facter::Util::Resolution.exec("/something", "/bin/perl") }.should raise_error(ArgumentError)
end
-
- it "should produce stderr content as a warning" do
- stdout = stdin = stub('fh', :readlines => ["aaa\n"])
- stderr = stub('stderr', :readlines => %w{my content})
- Open3.expects(:popen3).with("/bin/true").yields(stdin, stdout, stderr)
-
- Facter.expects(:warn).with(['my','content'])
- Facter::Util::Resolution.exec("/bin/true").should == 'aaa'
- end
-
- it "should produce nil as a warning if nothing is printed to stderr" do
- stdout = stdin = stub('fh', :readlines => ["aaa\n"])
- stderr = stub('stderr', :readlines => [])
- Open3.expects(:popen3).with("/bin/true").yields(stdin, stdout, stderr)
-
- Facter.expects(:warn).with(nil)
- Facter::Util::Resolution.exec("/bin/true").should == 'aaa'
- end
- end
-
- describe "when parsing output" do
- it "should return nil on nil" do
- Facter::Util::Resolution.parse_output(nil).should be_nil
- end
-
- it "should return nil on empty string" do
- Facter::Util::Resolution.parse_output('').should be_nil
- end
-
- it "should return nil on an empty array" do
- Facter::Util::Resolution.parse_output([]).should be_nil
- end
-
- it "should return a string on a 1 size array" do
- Facter::Util::Resolution.parse_output(["aaa\n"]).should == "aaa"
- end
-
- it "should return an array with chomped new lines on an array" do
- result = Facter::Util::Resolution.parse_output(["aaa\n","bbb\n","ccc\n"]).should == [ "aaa", "bbb", "ccc" ]
- end
end
end
--
Packaging of Facter for debian
More information about the Pkg-puppet-devel
mailing list