From 8a7308249783fc75d450fc2428cba52a5ad30a10 Mon Sep 17 00:00:00 2001 From: Rein Henrichs Date: Tue, 13 Oct 2009 18:21:06 -0700 Subject: Fix #2707 config_version fails more helpfully Use Puppet::Util.execute to run the config_version command and reraise its potential Puppet::ExecutionFailure exception as a more useful Pupppet::ParseError --- lib/puppet/parser/parser_support.rb | 5 ++++- spec/unit/parser/parser.rb | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb index 4fe2a5a0d..7a8fa812a 100644 --- a/lib/puppet/parser/parser_support.rb +++ b/lib/puppet/parser/parser_support.rb @@ -484,7 +484,10 @@ class Puppet::Parser::Parser return @version end - @version = %x{#{Puppet[:config_version]}}.chomp + @version = Puppet::Util.execute([Puppet[:config_version]]).strip + + rescue Puppet::ExecutionFailure => e + raise Puppet::ParseError, "Unable to set config_version: #{e.message}" end # Add a new file to be checked when we're checking to see if we should be diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb index 842dc1904..78caf18b0 100755 --- a/spec/unit/parser/parser.rb +++ b/spec/unit/parser/parser.rb @@ -324,9 +324,17 @@ describe Puppet::Parser do it "should use the output of the config_version setting if one is provided" do Puppet.settings.stubs(:[]).with(:config_version).returns("/my/foo") - @parser.expects(:`).with("/my/foo").returns "output\n" + Puppet::Util.expects(:execute).with(["/my/foo"]).returns "output\n" @parser.version.should == "output" end + + it "should raise a puppet parser error if executing config_version fails" do + Puppet.settings.stubs(:[]).with(:config_version).returns("test") + Puppet::Util.expects(:execute).raises(Puppet::ExecutionFailure.new("msg")) + + lambda { @parser.version }.should raise_error(Puppet::ParseError) + end + end describe Puppet::Parser,"when looking up definitions" do -- cgit