diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-02-07 05:58:00 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-02-07 05:58:00 +0000 |
commit | 6affe220db1248cee8489347dc7d7ac071a534e4 (patch) | |
tree | e885f7ac374336c818374556065da70036b71211 | |
parent | 59c7b02f8fb0c5f2820577f11c9c34935ac16a0a (diff) | |
download | puppet-6affe220db1248cee8489347dc7d7ac071a534e4.tar.gz puppet-6affe220db1248cee8489347dc7d7ac071a534e4.tar.xz puppet-6affe220db1248cee8489347dc7d7ac071a534e4.zip |
Committing both the finalization of the config code, plus all of the code necessary to get basic isomorphism from code to transportables and back. Mostly keyword and autoname stuff.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@871 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r-- | lib/puppet/config.rb | 143 | ||||
-rw-r--r-- | lib/puppet/parser/ast/classdef.rb | 7 | ||||
-rw-r--r-- | lib/puppet/parser/ast/compdef.rb | 17 | ||||
-rw-r--r-- | lib/puppet/parser/ast/component.rb | 9 | ||||
-rw-r--r-- | lib/puppet/parser/ast/node.rb | 1 | ||||
-rw-r--r-- | lib/puppet/parser/ast/nodedef.rb | 9 | ||||
-rw-r--r-- | lib/puppet/parser/ast/objectdef.rb | 15 | ||||
-rw-r--r-- | lib/puppet/parser/grammar.ra | 6 | ||||
-rw-r--r-- | lib/puppet/parser/parser.rb | 44 | ||||
-rw-r--r-- | lib/puppet/parser/scope.rb | 12 | ||||
-rw-r--r-- | lib/puppet/transportable.rb | 35 | ||||
-rwxr-xr-x | test/language/ast.rb | 6 | ||||
-rwxr-xr-x | test/language/scope.rb | 2 | ||||
-rwxr-xr-x | test/other/config.rb | 3 | ||||
-rw-r--r-- | test/other/transactions.rb | 1 | ||||
-rw-r--r-- | test/parser/parser.rb | 4 | ||||
-rwxr-xr-x | test/puppet/conffiles.rb | 16 |
17 files changed, 259 insertions, 71 deletions
diff --git a/lib/puppet/config.rb b/lib/puppet/config.rb index 22e3ef003..84ebb6a55 100644 --- a/lib/puppet/config.rb +++ b/lib/puppet/config.rb @@ -58,6 +58,7 @@ class Config # Parse a configuration file. def parse(file) text = nil + @file = file begin text = File.read(file) @@ -150,21 +151,120 @@ class Config } end - def to_manifest - fest = "" + # Convert our list of objects into a component that can be applied. + def to_component + transport = self.to_transportable + return transport.to_type +# comp = Puppet.type(:component).create( +# :name => "PuppetConfig" +# ) +# self.to_objects.each { |hash| +# type = hash[:type] +# hash.delete(:name) +# comp.push Puppet.type(type).create(hash) +# } +# +# return comp + end + + # Convert our configuration into a list of transportable objects. + def to_transportable + objects = [] + done = { + :user => [], + :group => [], + } + sections = {} + sectionlist = [] self.each { |name, obj| - [:user, :group].each { |type| - if obj.respond_to? type and val = obj.send(type) - fest += "#{type.to_s} { \"#{val}\": ensure => exists }\n\n" + section = obj.section || "puppet" + sections[section] ||= [] + unless sectionlist.include?(section) + sectionlist << section + end + sections[section] << obj + } + + topbucket = Puppet::TransBucket.new + if defined? @file and @file + topbucket.name = @file + else + topbucket.name = "configtop" + end + topbucket.type = "puppetconfig" + topbucket.top = true + topbucket.autoname = true + sectionlist.each { |section| + objects = [] + sections[section].each { |obj| + Puppet.notice "changing %s" % obj.name + [:user, :group].each { |type| + if obj.respond_to? type and val = obj.send(type) + # Skip users and groups we've already done, but tag them with + # our section if necessary + if done[type].include?(val) + next unless defined? @section and @section + + tags = done[type][val].tags + unless tags.include?(@section) + done[type][val].tags = tags << @section + end + else + newobj = TransObject.new(val, type.to_s) + newobj[:ensure] = "exists" + done[type] << newobj + end + end + } + + if obj.respond_to? :to_transportable + objects << obj.to_transportable + else + Puppet.notice "%s is not transportable" % obj.name end } - if obj.respond_to? :to_manifest - fest += obj.to_manifest + "\n" - end + bucket = Puppet::TransBucket.new + bucket.autoname = true + bucket.name = "autosection-%s" % bucket.object_id + bucket.type = section + bucket.push(*objects) + bucket.keyword = "class" + + topbucket.push bucket } +# self.each { |name, obj| +# [:user, :group].each { |type| +# if obj.respond_to? type and val = obj.send(type) +# # Skip users and groups we've already done, but tag them with +# # our section if necessary +# if done[type].include?(val) +# next unless defined? @section and @section +# +# tags = done[type][val].tags +# unless tags.include?(@section) +# done[type][val].tags = tags << @section +# end +# else +# obj = TransObject.new(val, type.to_s) +# obj[:ensure] = "exists" +# done[type] << obj +# end +# end +# } +# +# if obj.respond_to? :to_transportable +# objects << obj.to_transportable +# end +# } - fest + topbucket + end + + # Convert to a parseable manifest + def to_manifest + transport = self.to_transportable + return transport.to_manifest end # The base element type. @@ -236,26 +336,33 @@ class Config end end - # Set the type appropriately. Yep, a hack. + # Set the type appropriately. Yep, a hack. This supports either naming + # the variable 'dir', or adding a slash at the end. def munge(value) - if @name.to_s =~ /dir/ + if value.to_s =~ /dir/ @type = :directory + elsif value =~ /\/$/ + @type = :directory + return value.sub(/\/$/, '') else @type = :file end return value end - def to_manifest - hash = {"ensure" => self.type} - %w{user group mode}.each { |var| + def to_transportable + Puppet.notice "transportabling %s" % self.name + obj = Puppet::TransObject.new(self.value, "file") + obj[:ensure] = self.type + [:user, :group, :mode].each { |var| if value = self.send(var) - hash[var] = value + obj[var] = value end } - "file { \"#{self.value}\":\n %s\n}" % hash.collect { |p, v| - "#{p} => \"#{v}\"" - }.join(",\n ") + if self.section + obj.tags = ["puppet", "configuration", self.section] + end + obj end # Make sure any provided variables look up to something. diff --git a/lib/puppet/parser/ast/classdef.rb b/lib/puppet/parser/ast/classdef.rb index 7386b25eb..147ab88e5 100644 --- a/lib/puppet/parser/ast/classdef.rb +++ b/lib/puppet/parser/ast/classdef.rb @@ -36,9 +36,9 @@ class Puppet::Parser::AST # [name,args]) begin - scope.settype(name, - HostClass.new(arghash) - ) + hclass = HostClass.new(arghash) + hclass.keyword = self.keyword + scope.settype(name, hclass) rescue Puppet::ParseError => except except.line = self.line except.file = self.file @@ -54,6 +54,7 @@ class Puppet::Parser::AST def initialize(hash) @parentclass = nil + @keyword = "class" super end diff --git a/lib/puppet/parser/ast/compdef.rb b/lib/puppet/parser/ast/compdef.rb index 4118c7184..ef099eff8 100644 --- a/lib/puppet/parser/ast/compdef.rb +++ b/lib/puppet/parser/ast/compdef.rb @@ -9,7 +9,7 @@ class Puppet::Parser::AST # encounter an error if the component is instantiated more than # once. class CompDef < AST::Branch - attr_accessor :name, :args, :code + attr_accessor :name, :args, :code, :keyword def each [@name,@args,@code].each { |child| yield child } @@ -21,13 +21,13 @@ class Puppet::Parser::AST args = @args.safeevaluate(scope) begin - scope.settype(name, - AST::Component.new( - :name => name, - :args => args, - :code => @code - ) + comp = AST::Component.new( + :name => name, + :args => args, + :code => @code ) + comp.keyword = self.keyword + scope.settype(name, comp) rescue Puppet::ParseError => except except.line = self.line except.file = self.file @@ -43,6 +43,9 @@ class Puppet::Parser::AST def initialize(hash) @parentclass = nil + + # Set a default keyword + @keyword = "define" super #Puppet.debug "Defining type %s" % @name.value diff --git a/lib/puppet/parser/ast/component.rb b/lib/puppet/parser/ast/component.rb index 841977b2f..f5105c44b 100644 --- a/lib/puppet/parser/ast/component.rb +++ b/lib/puppet/parser/ast/component.rb @@ -10,7 +10,7 @@ class Puppet::Parser::AST # The class name @name = :component - attr_accessor :name, :args, :code, :scope + attr_accessor :name, :args, :code, :scope, :autoname, :keyword def evaluate(scope,hash,objtype,objname) @@ -23,6 +23,13 @@ class Puppet::Parser::AST # been dynamically generated. This is almost never used scope.name = objname + scope.keyword = self.keyword + + # Retain the fact that we were autonamed, if so + if self.autoname + scope.autoname = true + end + #if self.is_a?(Node) # scope.isnodescope #end diff --git a/lib/puppet/parser/ast/node.rb b/lib/puppet/parser/ast/node.rb index 18d7f8aa7..2e33eb672 100644 --- a/lib/puppet/parser/ast/node.rb +++ b/lib/puppet/parser/ast/node.rb @@ -16,6 +16,7 @@ class Puppet::Parser::AST # string. scope.type = @name scope.name = @name + scope.keyword = @keyword # Mark this scope as a nodescope, so that classes will be # singletons within it diff --git a/lib/puppet/parser/ast/nodedef.rb b/lib/puppet/parser/ast/nodedef.rb index c0e1ee63e..da93069b2 100644 --- a/lib/puppet/parser/ast/nodedef.rb +++ b/lib/puppet/parser/ast/nodedef.rb @@ -3,7 +3,7 @@ class Puppet::Parser::AST # specified node, and this parse tree is only ever looked up when # a client connects. class NodeDef < AST::Branch - attr_accessor :names, :code, :parentclass + attr_accessor :names, :code, :parentclass, :keyword def each [@names,@code].each { |child| yield child } @@ -30,9 +30,9 @@ class Puppet::Parser::AST end begin - scope.setnode(name, - Node.new(arghash) - ) + node = Node.new(arghash) + node.keyword = true + scope.setnode(name, node) rescue Puppet::ParseError => except except.line = self.line except.file = self.file @@ -48,6 +48,7 @@ class Puppet::Parser::AST def initialize(hash) @parentclass = nil + @keyword = "node" super end diff --git a/lib/puppet/parser/ast/objectdef.rb b/lib/puppet/parser/ast/objectdef.rb index 844b7a71d..dc355be77 100644 --- a/lib/puppet/parser/ast/objectdef.rb +++ b/lib/puppet/parser/ast/objectdef.rb @@ -52,7 +52,7 @@ class Puppet::Parser::AST self.typecheck(objtype) end - # See if our object was defined + # See if our object type was defined begin object = scope.lookuptype(objtype) rescue Puppet::ParseError => except @@ -81,11 +81,13 @@ class Puppet::Parser::AST end + autonamed = false # Autogenerate the name if one was not passed. if defined? @name objnames = @name.safeevaluate(scope) else objnames = self.autoname(objtype, object) + autonamed = true end # it's easier to always use an array, even for only one name @@ -106,7 +108,8 @@ class Puppet::Parser::AST # if someone passed an array as the name, then we act # just like the called us many times objnames.collect { |objname| - # If the object is a class, that means it's a builtin type + # If the object is a class, that means it's a builtin type, so + # we just store it in the scope if object.is_a?(Class) begin #Puppet.debug( @@ -138,7 +141,13 @@ class Puppet::Parser::AST # one of those, evaluate that with our arguments #Puppet.debug("Calling object '%s' with arguments %s" % # [object.name, hash.inspect]) - object.safeevaluate(scope,hash,objtype,objname) + obj = object.safeevaluate(scope,hash,objtype,objname) + + # Retain any name generation stuff + obj.autoname = autonamed + + # and pass the result on + obj end }.reject { |obj| obj.nil? } end diff --git a/lib/puppet/parser/grammar.ra b/lib/puppet/parser/grammar.ra index 3630d27ef..bd32f2c5b 100644 --- a/lib/puppet/parser/grammar.ra +++ b/lib/puppet/parser/grammar.ra @@ -483,6 +483,7 @@ definition: DEFINE NAME argumentlist LBRACE statements RBRACE { :args => val[2], :file => @lexer.file, :line => @lexer.line, + :keyword => val[0], :code => val[4] ) } | DEFINE NAME argumentlist LBRACE RBRACE { @@ -491,6 +492,7 @@ definition: DEFINE NAME argumentlist LBRACE statements RBRACE { :args => val[2], :file => @lexer.file, :line => @lexer.line, + :keyword => val[0], :code => AST::ASTArray.new( :line => @lexer.line, :file => @lexer.file, @@ -506,6 +508,7 @@ hostclass: CLASS NAME parent LBRACE statements RBRACE { :name => AST::Name.new(:value => val[1], :line => @lexer.line), :file => @lexer.file, :line => @lexer.line, + :keyword => val[0], :code => val[4] } # It'll be an ASTArray if we didn't get a parent @@ -518,6 +521,7 @@ hostclass: CLASS NAME parent LBRACE statements RBRACE { :name => AST::Name.new(:value => val[1], :line => @lexer.line), :file => @lexer.file, :line => @lexer.line, + :keyword => val[0], :code => AST::ASTArray.new( :line => @lexer.line, :file => @lexer.file, @@ -543,6 +547,7 @@ nodedef: NODE names parent LBRACE statements RBRACE { :file => @lexer.file, :line => @lexer.line, :names => val[1], + :keyword => val[0], :code => val[4] } if val[2].is_a?(AST::Name) @@ -560,6 +565,7 @@ nodedef: NODE names parent LBRACE statements RBRACE { args = { :file => @lexer.file, :line => @lexer.line, + :keyword => val[0], :names => val[1], :code => AST::ASTArray.new( :line => @lexer.line, diff --git a/lib/puppet/parser/parser.rb b/lib/puppet/parser/parser.rb index 582283704..43fa51119 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..idc16574e75e', 'grammar.ra', 697 +module_eval <<'..end grammar.ra modeval..id3b98377f5e', 'grammar.ra', 703 attr_reader :file attr_accessor :files @@ -144,7 +144,7 @@ def string=(string) end # $Id$ -..end grammar.ra modeval..idc16574e75e +..end grammar.ra modeval..id3b98377f5e ##### racc 1.4.4 generates ### @@ -1162,26 +1162,28 @@ module_eval <<'.,.,', 'grammar.ra', 478 end .,., -module_eval <<'.,.,', 'grammar.ra', 488 +module_eval <<'.,.,', 'grammar.ra', 489 def _reduce_71( val, _values, result ) result = AST::CompDef.new( :name => AST::Name.new(:value => val[1], :line => @lexer.line), :args => val[2], :file => @lexer.file, :line => @lexer.line, + :keyword => val[0], :code => val[4] ) result end .,., -module_eval <<'.,.,', 'grammar.ra', 500 +module_eval <<'.,.,', 'grammar.ra', 502 def _reduce_72( val, _values, result ) result = AST::CompDef.new( :name => AST::Name.new(:value => val[1], :line => @lexer.line), :args => val[2], :file => @lexer.file, :line => @lexer.line, + :keyword => val[0], :code => AST::ASTArray.new( :line => @lexer.line, :file => @lexer.file, @@ -1192,13 +1194,14 @@ module_eval <<'.,.,', 'grammar.ra', 500 end .,., -module_eval <<'.,.,', 'grammar.ra', 516 +module_eval <<'.,.,', 'grammar.ra', 519 def _reduce_73( val, _values, result ) #:args => val[2], args = { :name => AST::Name.new(:value => val[1], :line => @lexer.line), :file => @lexer.file, :line => @lexer.line, + :keyword => val[0], :code => val[4] } # It'll be an ASTArray if we didn't get a parent @@ -1210,12 +1213,13 @@ module_eval <<'.,.,', 'grammar.ra', 516 end .,., -module_eval <<'.,.,', 'grammar.ra', 532 +module_eval <<'.,.,', 'grammar.ra', 536 def _reduce_74( val, _values, result ) args = { :name => AST::Name.new(:value => val[1], :line => @lexer.line), :file => @lexer.file, :line => @lexer.line, + :keyword => val[0], :code => AST::ASTArray.new( :line => @lexer.line, :file => @lexer.file, @@ -1231,7 +1235,7 @@ module_eval <<'.,.,', 'grammar.ra', 532 end .,., -module_eval <<'.,.,', 'grammar.ra', 552 +module_eval <<'.,.,', 'grammar.ra', 557 def _reduce_75( val, _values, result ) unless val[1].is_a?(AST::ASTArray) val[1] = AST::ASTArray.new( @@ -1244,6 +1248,7 @@ module_eval <<'.,.,', 'grammar.ra', 552 :file => @lexer.file, :line => @lexer.line, :names => val[1], + :keyword => val[0], :code => val[4] } if val[2].is_a?(AST::Name) @@ -1254,7 +1259,7 @@ module_eval <<'.,.,', 'grammar.ra', 552 end .,., -module_eval <<'.,.,', 'grammar.ra', 574 +module_eval <<'.,.,', 'grammar.ra', 580 def _reduce_76( val, _values, result ) unless val[1].is_a?(AST::ASTArray) val[1] = AST::ASTArray.new( @@ -1266,6 +1271,7 @@ module_eval <<'.,.,', 'grammar.ra', 574 args = { :file => @lexer.file, :line => @lexer.line, + :keyword => val[0], :names => val[1], :code => AST::ASTArray.new( :line => @lexer.line, @@ -1283,7 +1289,7 @@ module_eval <<'.,.,', 'grammar.ra', 574 # reduce 77 omitted -module_eval <<'.,.,', 'grammar.ra', 588 +module_eval <<'.,.,', 'grammar.ra', 594 def _reduce_78( val, _values, result ) if val[0].is_a?(AST::ASTArray) result = val[0] @@ -1299,7 +1305,7 @@ module_eval <<'.,.,', 'grammar.ra', 588 end .,., -module_eval <<'.,.,', 'grammar.ra', 596 +module_eval <<'.,.,', 'grammar.ra', 602 def _reduce_79( val, _values, result ) result = AST::ASTArray.new( :line => @lexer.line, @@ -1312,14 +1318,14 @@ module_eval <<'.,.,', 'grammar.ra', 596 # reduce 80 omitted -module_eval <<'.,.,', 'grammar.ra', 601 +module_eval <<'.,.,', 'grammar.ra', 607 def _reduce_81( val, _values, result ) result = val[1] result end .,., -module_eval <<'.,.,', 'grammar.ra', 612 +module_eval <<'.,.,', 'grammar.ra', 618 def _reduce_82( val, _values, result ) if val[1].is_a?(AST::ASTArray) result = val[1] @@ -1336,7 +1342,7 @@ module_eval <<'.,.,', 'grammar.ra', 612 # reduce 83 omitted -module_eval <<'.,.,', 'grammar.ra', 626 +module_eval <<'.,.,', 'grammar.ra', 632 def _reduce_84( val, _values, result ) if val[0].instance_of?(AST::ASTArray) val[0].push(val[2]) @@ -1352,7 +1358,7 @@ module_eval <<'.,.,', 'grammar.ra', 626 end .,., -module_eval <<'.,.,', 'grammar.ra', 634 +module_eval <<'.,.,', 'grammar.ra', 640 def _reduce_85( val, _values, result ) result = AST::CompArgument.new( :line => @lexer.line, @@ -1363,7 +1369,7 @@ module_eval <<'.,.,', 'grammar.ra', 634 end .,., -module_eval <<'.,.,', 'grammar.ra', 641 +module_eval <<'.,.,', 'grammar.ra', 647 def _reduce_86( val, _values, result ) result = AST::CompArgument.new( :line => @lexer.line, @@ -1376,7 +1382,7 @@ module_eval <<'.,.,', 'grammar.ra', 641 # reduce 87 omitted -module_eval <<'.,.,', 'grammar.ra', 650 +module_eval <<'.,.,', 'grammar.ra', 656 def _reduce_88( val, _values, result ) result = AST::Name.new( :value => val[1], @@ -1387,7 +1393,7 @@ module_eval <<'.,.,', 'grammar.ra', 650 end .,., -module_eval <<'.,.,', 'grammar.ra', 659 +module_eval <<'.,.,', 'grammar.ra', 665 def _reduce_89( val, _values, result ) name = val[0].sub(/^\$/,'') result = AST::Variable.new( @@ -1399,7 +1405,7 @@ module_eval <<'.,.,', 'grammar.ra', 659 end .,., -module_eval <<'.,.,', 'grammar.ra', 671 +module_eval <<'.,.,', 'grammar.ra', 677 def _reduce_90( val, _values, result ) if val[1].is_a?(AST::ASTArray) result = val[1] @@ -1420,7 +1426,7 @@ module_eval <<'.,.,', 'grammar.ra', 671 # reduce 93 omitted -module_eval <<'.,.,', 'grammar.ra', 676 +module_eval <<'.,.,', 'grammar.ra', 682 def _reduce_94( val, _values, result ) result = nil result diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 9392d6cf9..3e88490e3 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -8,7 +8,9 @@ module Puppet class Scope include Enumerable attr_accessor :parent, :level, :interp - attr_accessor :name, :type, :topscope, :base + attr_accessor :name, :type, :topscope, :base, :keyword, :autoname + + attr_accessor :top # This is probably not all that good of an idea, but... # This way a parent can share its tables with all of its children. @@ -210,6 +212,9 @@ module Puppet objects.classes = nodescope.classlist end + if objects.is_a?(Puppet::TransBucket) + objects.top = true + end # I should do something to add the node as an object with tags # but that will possibly end up with far too many tags. #self.logtags @@ -262,6 +267,7 @@ module Puppet } objects = self.to_trans + objects.top = true # Add our class list unless self.classlist.empty? @@ -733,6 +739,10 @@ module Puppet raise Puppet::ParseError, "No type for scope %s" % @name end + + if defined? @keyword + bucket.keyword = @keyword + end #Puppet.debug( # "TransBucket with name %s and type %s in scope %s" % # [@name,@type,self.object_id] diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb index cbc60450d..405179808 100644 --- a/lib/puppet/transportable.rb +++ b/lib/puppet/transportable.rb @@ -27,6 +27,7 @@ module Puppet @name = name @params = {"name" => name} #self.class.add(self) + @tags = [] end def longname @@ -45,6 +46,12 @@ module Puppet return "%s(%s) => %s" % [@type,self[:name],super] end + def to_manifest + "#{self.type.to_s} { \"#{self.name}\":\n%s\n}" % @params.collect { |p, v| + " #{p} => \"#{v}\"" + }.join(",\n") + end + def to_yaml_properties instance_variables #%w{ @type @name @file @line @tags }.find_all { |v| @@ -84,7 +91,7 @@ module Puppet class TransBucket include Enumerable - attr_accessor :name, :type, :file, :line, :classes + attr_accessor :name, :type, :file, :line, :classes, :autoname, :keyword, :top %w{delete shift include? length empty? << []}.each { |method| define_method(method) do |*args| @@ -118,6 +125,32 @@ module Puppet #Puppet.warning @children.inspect end + # Convert to a parseable manifest + def to_manifest + unless self.top + unless defined? @keyword and @keyword + raise Puppet::DevError, "No keyword; cannot convert to manifest" + end + end + + str = nil + if self.top + str = "%s" + else + str = "#{@keyword} #{@type} {\n%s\n}" + end + str % @children.collect { |child| + Puppet.info "manifesting %s" % child.name + child.to_manifest + }.collect { |str| + if self.top + str + else + str.gsub(/^/, " ") # indent everything once + end + }.join("\n\n") # and throw in a blank line + end + def to_yaml_properties instance_variables end diff --git a/test/language/ast.rb b/test/language/ast.rb index 3dc5fd582..b5497eb0d 100755 --- a/test/language/ast.rb +++ b/test/language/ast.rb @@ -172,6 +172,10 @@ class TestAST < Test::Unit::TestCase scope = nil assert_nothing_raised("Could not evaluate node") { scope = Puppet::Parser::Scope.new() + scope.name = "nodetest" + scope.type = "nodetest" + scope.keyword = "nodetest" + scope.top = true top.evaluate(scope) } @@ -339,7 +343,7 @@ class TestAST < Test::Unit::TestCase end # Test that node inheritance works correctly - def test_znodeinheritance + def test_nodeinheritance children = [] # create the base node diff --git a/test/language/scope.rb b/test/language/scope.rb index 67792daae..707372d1a 100755 --- a/test/language/scope.rb +++ b/test/language/scope.rb @@ -396,6 +396,8 @@ class TestScope < Test::Unit::TestCase scope = nil assert_nothing_raised("Could not evaluate") { scope = Puppet::Parser::Scope.new() + scope.name = "topscope" + scope.type = "topscope" objects = scope.evaluate(top) } diff --git a/test/other/config.rb b/test/other/config.rb index 849fa1c97..298480484 100755 --- a/test/other/config.rb +++ b/test/other/config.rb @@ -137,6 +137,7 @@ yay = /a/path assert_equal("value", c[:attr]) assert_equal("/some/dir", c[:attr2]) + assert_equal(:directory, c.element(:attr2).type) assert_equal("/some/dir/other", c[:attr3]) elem = nil @@ -146,8 +147,6 @@ yay = /a/path assert(elem) assert_equal("puppet", elem.user) - - puts c.to_manifest end end diff --git a/test/other/transactions.rb b/test/other/transactions.rb index ed6843104..862a28b85 100644 --- a/test/other/transactions.rb +++ b/test/other/transactions.rb @@ -124,6 +124,7 @@ class TestTransactions < Test::Unit::TestCase file[:mode] = "755" } trans = assert_events([:file_changed, :file_changed], component) + file.retrieve assert_rollback_events(trans, [:file_changed, :file_changed], "file") diff --git a/test/parser/parser.rb b/test/parser/parser.rb index 68209a0d2..13b8a2e85 100644 --- a/test/parser/parser.rb +++ b/test/parser/parser.rb @@ -95,7 +95,7 @@ class TestParser < Test::Unit::TestCase } end - def test_zdefaults + def test_defaults basedir = File.join(tmpdir(), "defaulttesting") @@tmpfiles << basedir Dir.mkdir(basedir) @@ -151,6 +151,8 @@ class TestParser < Test::Unit::TestCase scope = nil assert_nothing_raised("Could not evaluate defaults parse tree") { scope = Puppet::Parser::Scope.new() + scope.name = "parsetest" + scope.type = "parsetest" objects = scope.evaluate(ast) } diff --git a/test/puppet/conffiles.rb b/test/puppet/conffiles.rb index f966322f7..49da5fa46 100755 --- a/test/puppet/conffiles.rb +++ b/test/puppet/conffiles.rb @@ -27,11 +27,6 @@ class TestConfFiles < Test::Unit::TestCase "boo" => { "eb" => "fb" }, - "rah" => { - "aa" => "this is a sentence", - "ca" => "dk", - "ea" => "fk" - }, }, { "puppet" => { @@ -41,7 +36,7 @@ class TestConfFiles < Test::Unit::TestCase "okay" => "rah" }, "back" => { - "okay" => "rah" + "yayness" => "rah" }, } ] @@ -54,7 +49,7 @@ class TestConfFiles < Test::Unit::TestCase data = data.dup str += "[puppet]\n" data["puppet"].each { |var, value| - str += "%s %s\n" % [var, value] + str += "%s = %s\n" % [var, value] } data.delete("puppet") end @@ -62,7 +57,7 @@ class TestConfFiles < Test::Unit::TestCase data.each { |type, settings| str += "[%s]\n" % type settings.each { |var, value| - str += "%s %s\n" % [var, value] + str += "%s = %s\n" % [var, value] } } @@ -85,14 +80,15 @@ class TestConfFiles < Test::Unit::TestCase File.open(path, "w") { |f| f.print data2config(data) } config = nil assert_nothing_raised { - config = Puppet::Config.new(path) + config = Puppet::Config.new + config.parse(path) } data.each { |section, hash| hash.each { |var, value| assert_equal( data[section][var], - config[section][var], + config[var], "Got different values at %s/%s" % [section, var] ) } |