diff options
author | Luke Kanies <luke@madstop.com> | 2008-02-13 16:27:35 -0600 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-02-13 16:27:35 -0600 |
commit | 0cfa1d2b7ae38020d3b845d7713cb10cda7facef (patch) | |
tree | fcfa2861cb0174ab610235a14c69909d094de4a8 | |
parent | 8367fdfab25aacb56f16444f5763b347e6a907ab (diff) | |
download | puppet-0cfa1d2b7ae38020d3b845d7713cb10cda7facef.tar.gz puppet-0cfa1d2b7ae38020d3b845d7713cb10cda7facef.tar.xz puppet-0cfa1d2b7ae38020d3b845d7713cb10cda7facef.zip |
Fixed #968 again, this time with tests -- parseonly works,
including not compiling the configurations, and also storeconfigs
is no longer required during parse-testing.
-rw-r--r-- | CHANGELOG | 4 | ||||
-rwxr-xr-x | bin/puppet | 12 | ||||
-rw-r--r-- | lib/puppet/parser/grammar.ra | 4 | ||||
-rw-r--r-- | lib/puppet/parser/interpreter.rb | 40 | ||||
-rw-r--r-- | lib/puppet/parser/lexer.rb | 6 | ||||
-rw-r--r-- | lib/puppet/parser/parser.rb | 9 | ||||
-rwxr-xr-x | test/executables/puppetbin.rb | 17 |
7 files changed, 63 insertions, 29 deletions
@@ -1,3 +1,7 @@ + Fixed #968 again, this time with tests -- parseonly works, + including not compiling the configurations, and also storeconfigs + is no longer required during parse-testing. + Fixed #1021 -- the problem was that my method of determining the in-degree sometimes resulted in a lower number than the number of in-edges. diff --git a/bin/puppet b/bin/puppet index f5d230a7a..952ffcbf8 100755 --- a/bin/puppet +++ b/bin/puppet @@ -171,6 +171,16 @@ else Puppet[:manifest] = ARGV.shift end +if Puppet[:parseonly] + begin + Puppet::Parser::Interpreter.new.parser(Puppet[:environment]) + rescue => detail + Puppet.err detail + exit 1 + end + exit 0 +end + # Collect our facts. facts = Puppet::Node::Facts.find("me") facts.name = facts.values["hostname"] @@ -198,8 +208,6 @@ begin # Compile our catalog catalog = Puppet::Node::Catalog.find(node) - exit(0) if Puppet[:parseonly] - # Translate it to a RAL catalog catalog = catalog.to_ral diff --git a/lib/puppet/parser/grammar.ra b/lib/puppet/parser/grammar.ra index 0fd644b3a..484efe83c 100644 --- a/lib/puppet/parser/grammar.ra +++ b/lib/puppet/parser/grammar.ra @@ -151,7 +151,7 @@ resourceoverride: resourceref LBRACE anyparams endcomma RBRACE { virtualresource: at resource { type = val[0] - if type == :exported and ! Puppet[:storeconfigs] + if (type == :exported and ! Puppet[:storeconfigs]) and ! Puppet[:parseonly] error "You cannot collect without storeconfigs being set" end @@ -192,7 +192,7 @@ collection: classref collectrhand { else args[:form] = val[1] end - if args[:form] == :exported and ! Puppet[:storeconfigs] + if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] error "You cannot collect exported resources without storeconfigs being set" end result = ast AST::Collection, args diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb index 1d93193dd..d4b7449fb 100644 --- a/lib/puppet/parser/interpreter.rb +++ b/lib/puppet/parser/interpreter.rb @@ -42,6 +42,26 @@ class Puppet::Parser::Interpreter @parsers = {} end + # Return the parser for a specific environment. + def parser(environment) + if ! @parsers[environment] or @parsers[environment].reparse? + # This will throw an exception if it does not succeed. We only + # want to get rid of the old parser if we successfully create a new + # one. + begin + tmp = create_parser(environment) + @parsers[environment].clear if @parsers[environment] + @parsers[environment] = tmp + rescue => detail + # If a parser already exists, than assume that we logged the + # exception elsewhere and reuse the parser. If one doesn't + # exist, then reraise. + raise detail unless @parsers[environment] + end + end + @parsers[environment] + end + private # Create a new parser object and pre-parse the configuration. @@ -67,24 +87,4 @@ class Puppet::Parser::Interpreter raise error end end - - # Return the parser for a specific environment. - def parser(environment) - if ! @parsers[environment] or @parsers[environment].reparse? - # This will throw an exception if it does not succeed. We only - # want to get rid of the old parser if we successfully create a new - # one. - begin - tmp = create_parser(environment) - @parsers[environment].clear if @parsers[environment] - @parsers[environment] = tmp - rescue => detail - # If a parser already exists, than assume that we logged the - # exception elsewhere and reuse the parser. If one doesn't - # exist, then reraise. - raise detail unless @parsers[environment] - end - end - @parsers[environment] - end end diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb index 6661650ba..51026ea1b 100644 --- a/lib/puppet/parser/lexer.rb +++ b/lib/puppet/parser/lexer.rb @@ -33,7 +33,11 @@ class Puppet::Parser::Lexer end def to_s - "Lexer token %s" % @name.to_s + if self.string + @string + else + @name.to_s + end end end diff --git a/lib/puppet/parser/parser.rb b/lib/puppet/parser/parser.rb index c3279d4e7..e27a209fc 100644 --- a/lib/puppet/parser/parser.rb +++ b/lib/puppet/parser/parser.rb @@ -29,7 +29,7 @@ module Puppet class Parser < Racc::Parser -module_eval <<'..end grammar.ra modeval..id9134b179f4', 'grammar.ra', 638 +module_eval <<'..end grammar.ra modeval..idfef5d70c9f', 'grammar.ra', 638 # It got too annoying having code in a file that needs to be compiled. require 'puppet/parser/parser_support' @@ -39,8 +39,9 @@ require 'puppet/parser/parser_support' # mode: ruby # End: +# $Id$ -..end grammar.ra modeval..id9134b179f4 +..end grammar.ra modeval..idfef5d70c9f ##### racc 1.4.5 generates ### @@ -956,7 +957,7 @@ module_eval <<'.,.,', 'grammar.ra', 174 def _reduce_38( val, _values, result ) type = val[0] - if type == :exported and ! Puppet[:storeconfigs] + if (type == :exported and ! Puppet[:storeconfigs]) and ! Puppet[:parseonly] error "You cannot collect without storeconfigs being set" end @@ -1009,7 +1010,7 @@ module_eval <<'.,.,', 'grammar.ra', 199 else args[:form] = val[1] end - if args[:form] == :exported and ! Puppet[:storeconfigs] + if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] error "You cannot collect exported resources without storeconfigs being set" end result = ast AST::Collection, args diff --git a/test/executables/puppetbin.rb b/test/executables/puppetbin.rb index 218787c92..08329efb6 100755 --- a/test/executables/puppetbin.rb +++ b/test/executables/puppetbin.rb @@ -83,5 +83,22 @@ class TestPuppetBin < Test::Unit::TestCase assert(FileTest.exists?(path), "Failed to create config'ed file") end + + def test_parseonly + path = tempfile() + manifest = tempfile() + puppet = %x{which puppet}.chomp + if puppet == "" + Puppet.info "cannot find puppet; cannot test parseonly" + return + end + code = 'File <<| |>> + include nosuchclass' + + assert_nothing_raised { + IO.popen("#{puppet} --parseonly", 'w') { |p| p.puts code } + } + assert($? == 0, "parseonly test exited with code %s" % $?.to_i) + end end |