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 Signed-off-by: Paul Nasrat <pnas...@googlemail.com> --- lib/facter/util/resolution.rb | 23 +++++--------------- spec/unit/util/resolution.rb | 44 ----------------------------------------- 2 files changed, 6 insertions(+), 61 deletions(-) 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 -- 1.6.4.2 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to puppet-...@googlegroups.com. To unsubscribe from this group, send email to puppet-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.