[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5

Paul Berry paul at puppetlabs.com
Tue May 10 08:01:40 UTC 2011


The following commit has been merged in the experimental branch:
commit e6ec6468c4a9eec58dc155858665a70eee4dfb8c
Merge: fb2b9e65990477e81728402afa1aab6fbe4a9c7e 53bb805f118ccaca5598e60afadfa6b777410a0f
Author: Paul Berry <paul at puppetlabs.com>
Date:   Wed Nov 17 15:19:15 2010 -0800

    Merge commit '2.6.3' into next
    
    Resolved conflicts manually:
    	spec/integration/indirector/bucket_file/rest_spec.rb
    	spec/integration/indirector/certificate_revocation_list/rest_spec.rb

diff --combined lib/puppet/defaults.rb
index 7ae5538,4521a59..c4d8d51
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@@ -115,17 -115,7 +115,17 @@@ module Puppe
      :node_terminus => ["plain", "Where to find information about nodes."],
      :catalog_terminus => ["compiler", "Where to get node catalogs.  This is useful to change if, for instance,
        you'd like to pre-compile catalogs and store them in memcached or some other easily-accessed store."],
 -    :facts_terminus => [Puppet.application_name.to_s == "master" ? 'yaml' : 'facter', "The node facts terminus."],
 +    :facts_terminus => {
 +      :default => Puppet.application_name.to_s == "master" ? 'yaml' : 'facter', 
 +      :desc => "The node facts terminus.",
 +      :hook => proc do |value|
 +        require 'puppet/node/facts'
 +        if value.to_s == "rest"
 +          Puppet::Node::Facts.cache_class = :yaml
 +        end
 +      end
 +    },
 +    :inventory_terminus => [ "$facts_terminus", "Should usually be the same as the facts terminus" ],
      :httplog => { :default => "$logdir/http.log",
        :owner => "root",
        :mode => 0640,
@@@ -588,17 -578,11 +588,17 @@@
        end
      },
      :report_server => ["$server",
 -      "The server to which to send transaction reports."
 +      "The server to send transaction reports to."
      ],
      :report_port => ["$masterport",
        "The port to communicate with the report_server."
      ],
 +    :inventory_server => ["$server",
 +      "The server to send facts to."
 +    ],
 +    :inventory_port => ["$masterport",
 +      "The port to communicate with the inventory_server."
 +    ],
      :report => [false,
        "Whether to send reports after every transaction."
      ],
@@@ -656,7 -640,7 +656,7 @@@
      setdefaults(
      :tagmail,
      :tagmap => ["$confdir/tagmail.conf", "The mapping between reporting tags and email addresses."],
-     :sendmail => [%x{which sendmail 2>/dev/null}.chomp, "Where to find the sendmail binary with which to send email."],
+     :sendmail => [which('sendmail') || '', "Where to find the sendmail binary with which to send email."],
  
      :reportfrom => ["report@" + [Facter["hostname"].value, Facter["domain"].value].join("."), "The 'from' email address for the reports."],
      :smtpserver => ["none", "The server through which to send email reports."]
@@@ -682,11 -666,10 +682,10 @@@
        used when networked databases are used."],
      :dbpassword => [ "puppet", "The database password for caching. Only
        used when networked databases are used."],
+     :dbconnections => [ '', "The number of database connections for networked
+       databases.  Will be ignored unless the value is a positive integer."],
      :dbsocket => [ "", "The database socket location. Only used when networked
        databases are used.  Will be ignored if the value is an empty string."],
-     :dbconnections => [ 0, "The number of database connections. Only used when
-       networked databases are used.  Will be ignored if the value is an empty
-       string or is less than 1."],
      :railslog => {:default => "$logdir/rails.log",
        :mode => 0600,
        :owner => "service",
diff --combined lib/puppet/indirector/catalog/compiler.rb
index 1e1ae12,6375e80..78be4ca
--- a/lib/puppet/indirector/catalog/compiler.rb
+++ b/lib/puppet/indirector/catalog/compiler.rb
@@@ -22,7 -22,6 +22,7 @@@ class Puppet::Resource::Catalog::Compil
      else
        facts = Puppet::Node::Facts.convert_from(format, text_facts)
      end
 +    facts.add_timestamp
      facts.save
    end
  
@@@ -108,10 -107,14 +108,14 @@@
        return node
      end
  
-     # If the request is authenticated, then the 'node' info will
-     # be available; if not, then we use the passed-in key.  We rely
-     # on our authorization system to determine whether this is allowed.
-     name = request.node || request.key
+     # We rely on our authorization system to determine whether the connected
+     # node is allowed to compile the catalog's node referenced by key.
+     # By default the REST authorization system makes sure only the connected node
+     # can compile his catalog.
+     # This allows for instance monitoring systems or puppet-load to check several
+     # node's catalog with only one certificate and a modification to auth.conf 
+     # If no key is provided we can only compile the currently connected node.
+     name = request.key || request.node
      if node = find_node(name)
        return node
      end
diff --combined lib/puppet/network/handler/fileserver.rb
index 8844ab9,1531f4f..9abc7ee
--- a/lib/puppet/network/handler/fileserver.rb
+++ b/lib/puppet/network/handler/fileserver.rb
@@@ -4,11 -4,11 +4,13 @@@ require 'webrick/httpstatus
  require 'cgi'
  require 'delegate'
  require 'sync'
 +require 'xmlrpc/server'
  
+ require 'puppet/network/handler'
+ require 'puppet/network/xmlrpc/server'
  require 'puppet/file_serving'
  require 'puppet/file_serving/metadata'
 +require 'puppet/network/handler'
  
  class Puppet::Network::Handler
    AuthStoreError = Puppet::AuthStoreError
diff --combined lib/puppet/node/environment.rb
index 3d55ac1,b64fb8a..7877b7f
--- a/lib/puppet/node/environment.rb
+++ b/lib/puppet/node/environment.rb
@@@ -81,7 -81,7 +81,7 @@@ class Puppet::Node::Environmen
      Thread.current[:known_resource_types] ||= synchronize {
        if @known_resource_types.nil? or @known_resource_types.stale?
          @known_resource_types = Puppet::Resource::TypeCollection.new(self)
 -        @known_resource_types.perform_initial_import
 +        @known_resource_types.import_ast(perform_initial_import, '')
        end
        @known_resource_types
      }
@@@ -124,6 -124,10 +124,10 @@@
      name.to_s
    end
  
+   def to_sym
+     to_s.to_sym
+   end
+ 
    # The only thing we care about when serializing an environment is its 
    # identity; everything else is ephemeral and should not be stored or
    # transmitted.
@@@ -143,31 -147,5 +147,31 @@@
      end
    end
  
 +  private
 +
 +  def perform_initial_import
 +    return empty_parse_result if Puppet.settings[:ignoreimport]
 +    parser = Puppet::Parser::Parser.new(self)
 +    if code = Puppet.settings.uninterpolated_value(:code, name.to_s) and code != ""
 +      parser.string = code
 +    else
 +      file = Puppet.settings.value(:manifest, name.to_s)
 +      return empty_parse_result unless File.exist?(file)
 +      parser.file = file
 +    end
 +    parser.parse
 +  rescue => detail
 +    msg = "Could not parse for environment #{self}: #{detail}"
 +    error = Puppet::Error.new(msg)
 +    error.set_backtrace(detail.backtrace)
 +    raise error
 +  end
 +
 +  def empty_parse_result
 +    # Return an empty toplevel hostclass to use as the result of
 +    # perform_initial_import when no file was actually loaded.
 +    return Puppet::Parser::AST::Hostclass.new('')
 +  end
 +
    @root = new(:'*root*')
  end
diff --combined lib/puppet/parser/parser_support.rb
index 16cd0ee,7bbebb1..746aa0f
--- a/lib/puppet/parser/parser_support.rb
+++ b/lib/puppet/parser/parser_support.rb
@@@ -29,20 -29,29 +29,20 @@@ class Puppet::Parser::Parse
      message
    end
  
 -  # Create an AST array out of all of the args
 -  def aryfy(*args)
 -    if args[0].instance_of?(AST::ASTArray)
 -      result = args.shift
 -      args.each { |arg|
 -        result.push arg
 -      }
 -    else
 -      result = ast AST::ASTArray, :children => args
 -    end
 -
 -    result
 +  # Create an AST array containing a single element
 +  def aryfy(arg)
 +    ast AST::ASTArray, :children => [arg]
    end
  
    # Create an AST object, and automatically add the file and line information if
    # available.
    def ast(klass, hash = {})
-     klass.new ast_context(klass.use_docs).merge(hash)
+     klass.new ast_context(klass.use_docs, hash[:line]).merge(hash)
    end
  
-   def ast_context(include_docs = false)
+   def ast_context(include_docs = false, ast_line = nil)
      result = {
-       :line => lexer.line,
+       :line => ast_line || lexer.line,
        :file => lexer.file
      }
      result[:doc] = lexer.getcomment(result[:line]) if include_docs
@@@ -59,13 -68,13 +59,13 @@@
    end
  
    # Raise a Parse error.
 -  def error(message)
 +  def error(message, options = {})
      if brace = @lexer.expected
        message += "; expected '%s'"
      end
      except = Puppet::ParseError.new(message)
 -    except.line = @lexer.line
 -    except.file = @lexer.file if @lexer.file
 +    except.line = options[:line] || @lexer.line
 +    except.file = options[:file] || @lexer.file
  
      raise except
    end
@@@ -94,11 -103,11 +94,11 @@@
    end
  
    def find_hostclass(namespace, name)
 -    known_resource_types.find_or_load(namespace, name, :hostclass)
 +    known_resource_types.find_hostclass(namespace, name)
    end
  
    def find_definition(namespace, name)
 -    known_resource_types.find_or_load(namespace, name, :definition)
 +    known_resource_types.find_definition(namespace, name)
    end
  
    def import(file)
@@@ -124,6 -133,26 +124,6 @@@
      return ns, n
    end
  
 -  # Create a new class, or merge with an existing class.
 -  def newclass(name, options = {})
 -    known_resource_types.add Puppet::Resource::Type.new(:hostclass, name, ast_context(true).merge(options))
 -  end
 -
 -  # Create a new definition.
 -  def newdefine(name, options = {})
 -    known_resource_types.add Puppet::Resource::Type.new(:definition, name, ast_context(true).merge(options))
 -  end
 -
 -  # Create a new node.  Nodes are special, because they're stored in a global
 -  # table, not according to namespaces.
 -  def newnode(names, options = {})
 -    names = [names] unless names.instance_of?(Array)
 -    context = ast_context(true)
 -    names.collect do |name|
 -      known_resource_types.add(Puppet::Resource::Type.new(:node, name, context.merge(options)))
 -    end
 -  end
 -
    def on_error(token,value,stack)
      if token == 0 # denotes end of file
        value = 'end of file'
@@@ -145,42 -174,42 +145,42 @@@
  
    # how should I do error handling here?
    def parse(string = nil)
 -    return parse_ruby_file if self.file =~ /\.rb$/
 -    self.string = string if string
 -    begin
 -      @yydebug = false
 -      main = yyparse(@lexer,:scan)
 -    rescue Racc::ParseError => except
 -      error = Puppet::ParseError.new(except)
 -      error.line = @lexer.line
 -      error.file = @lexer.file
 -      error.set_backtrace except.backtrace
 -      raise error
 -    rescue Puppet::ParseError => except
 -      except.line ||= @lexer.line
 -      except.file ||= @lexer.file
 -      raise except
 -    rescue Puppet::Error => except
 -      # and this is a framework error
 -      except.line ||= @lexer.line
 -      except.file ||= @lexer.file
 -      raise except
 -    rescue Puppet::DevError => except
 -      except.line ||= @lexer.line
 -      except.file ||= @lexer.file
 -      raise except
 -    rescue => except
 -      error = Puppet::DevError.new(except.message)
 -      error.line = @lexer.line
 -      error.file = @lexer.file
 -      error.set_backtrace except.backtrace
 -      raise error
 -    end
 -    if main
 -      # Store the results as the top-level class.
 -      newclass("", :code => main)
 +    if self.file =~ /\.rb$/
 +      main = parse_ruby_file
 +    else
 +      self.string = string if string
 +      begin
 +        @yydebug = false
 +        main = yyparse(@lexer,:scan)
 +      rescue Racc::ParseError => except
 +        error = Puppet::ParseError.new(except)
 +        error.line = @lexer.line
 +        error.file = @lexer.file
 +        error.set_backtrace except.backtrace
 +        raise error
 +      rescue Puppet::ParseError => except
 +        except.line ||= @lexer.line
 +        except.file ||= @lexer.file
 +        raise except
 +      rescue Puppet::Error => except
 +        # and this is a framework error
 +        except.line ||= @lexer.line
 +        except.file ||= @lexer.file
 +        raise except
 +      rescue Puppet::DevError => except
 +        except.line ||= @lexer.line
 +        except.file ||= @lexer.file
 +        raise except
 +      rescue => except
 +        error = Puppet::DevError.new(except.message)
 +        error.line = @lexer.line
 +        error.file = @lexer.file
 +        error.set_backtrace except.backtrace
 +        raise error
 +      end
      end
 -    return known_resource_types
 +    # Store the results as the top-level class.
 +    return Puppet::Parser::AST::Hostclass.new('', :code => main)
    ensure
      @lexer.clear
    end
@@@ -188,11 -217,7 +188,11 @@@
    def parse_ruby_file
      # Execute the contents of the file inside its own "main" object so
      # that it can call methods in the resource type API.
 -    Puppet::DSL::ResourceTypeAPI.new.instance_eval(File.read(self.file))
 +    main_object = Puppet::DSL::ResourceTypeAPI.new
 +    main_object.instance_eval(File.read(self.file))
 +
 +    # Then extract any types that were created.
 +    Puppet::Parser::AST::ASTArray.new :children => main_object.instance_eval { @__created_ast_objects__ }
    end
  
    def string=(string)
diff --combined lib/puppet/util/zaml.rb
index ae4da86,9fda5ae..2155e98
--- a/lib/puppet/util/zaml.rb
+++ b/lib/puppet/util/zaml.rb
@@@ -29,8 -29,7 +29,8 @@@ class ZAM
      @result = []
      @indent = nil
      @structured_key_prefix = nil
 -    Label.counter_reset
 +    @previously_emitted_object = {}
 +    @next_free_label_number = 0
      emit('--- ')
    end
    def nested(tail='  ')
@@@ -56,29 -55,31 +56,29 @@@
      #    which we will encounter a reference to the object as we serialize
      #    it can be handled).
      #
 -    def self.counter_reset
 -      @@previously_emitted_object = {}
 -      @@next_free_label_number = 0
 -    end
 +    attr_accessor :this_label_number
      def initialize(obj,indent)
        @indent = indent
        @this_label_number = nil
 -      @@previously_emitted_object[obj.object_id] = self
      end
      def to_s
        @this_label_number ? ('&id%03d%s' % [@this_label_number, @indent]) : ''
      end
      def reference
 -      @this_label_number ||= (@@next_free_label_number += 1)
        @reference         ||= '*id%03d' % @this_label_number
      end
 -    def self.for(obj)
 -      @@previously_emitted_object[obj.object_id]
 -    end
 +  end
 +  def label_for(obj)
 +    @previously_emitted_object[obj.object_id]
    end
    def new_label_for(obj)
 -    Label.new(obj,(Hash === obj || Array === obj) ? "#{@indent || "\n"}  " : ' ')
 +    label = Label.new(obj,(Hash === obj || Array === obj) ? "#{@indent || "\n"}  " : ' ')
 +    @previously_emitted_object[obj.object_id] = label
 +    label
    end
    def first_time_only(obj)
 -    if label = Label.for(obj)
 +    if label = label_for(obj)
 +      label.this_label_number ||= (@next_free_label_number += 1)
        emit(label.reference)
      else
        if @structured_key_prefix and not obj.is_a? String
@@@ -119,6 -120,9 +119,9 @@@ class Objec
    def to_yaml_properties
      instance_variables.sort        # Default YAML behavior
    end
+   def yaml_property_munge(x)
+     x
+   end
    def zamlized_class_name(root)
      cls = self.class
      "!ruby/#{root.name.downcase}#{cls == root ? '' : ":#{cls.respond_to?(:name) ? cls.name : cls}"}"
@@@ -135,7 -139,7 +138,7 @@@
              z.nl
              v[1..-1].to_zaml(z)       # Remove leading '@'
              z.emit(': ')
-             instance_variable_get(v).to_zaml(z)
+             yaml_property_munge(instance_variable_get(v)).to_zaml(z)
            }
          end
        }
diff --combined spec/unit/application/apply_spec.rb
index edb41b5,877c47b..22ac471
--- a/spec/unit/application/apply_spec.rb
+++ b/spec/unit/application/apply_spec.rb
@@@ -142,16 -142,17 +142,16 @@@ describe Puppet::Application::Apply d
  
      describe "the parseonly command" do
        before :each do
 -        Puppet.stubs(:[]).with(:environment)
 +        @environment = Puppet::Node::Environment.new("env")
 +        Puppet.stubs(:[]).with(:environment).returns(@environment)
          Puppet.stubs(:[]).with(:manifest).returns("site.pp")
          Puppet.stubs(:err)
          @apply.stubs(:exit)
          @apply.options.stubs(:[]).with(:code).returns "some code"
 -        @collection = stub_everything
 -        Puppet::Resource::TypeCollection.stubs(:new).returns(@collection)
        end
  
 -      it "should use a Puppet Resource Type Collection to parse the file" do
 -        @collection.expects(:perform_initial_import)
 +      it "should use the environment to parse the file" do
 +        @environment.stubs(:perform_initial_import)
          @apply.parseonly
        end
  
@@@ -161,7 -162,7 +161,7 @@@
        end
  
        it "should exit with exit code 1 if error" do
 -        @collection.stubs(:perform_initial_import).raises(Puppet::ParseError)
 +        @environment.stubs(:perform_initial_import).raises(Puppet::ParseError)
          @apply.expects(:exit).with(1)
          @apply.parseonly
        end
@@@ -311,7 -312,7 +311,7 @@@
        end
  
        it "should apply the catalog" do
-         @catalog.expects(:apply).returns(stub_everything 'transaction')
+         @catalog.expects(:apply).returns(stub_everything('transaction'))
  
          @apply.main
        end
diff --combined spec/unit/indirector/catalog/compiler_spec.rb
index f998080,6c950b6..49b8986
--- a/spec/unit/indirector/catalog/compiler_spec.rb
+++ b/spec/unit/indirector/catalog/compiler_spec.rb
@@@ -6,10 -6,10 +6,11 @@@
  require File.dirname(__FILE__) + '/../../../spec_helper'
  
  require 'puppet/indirector/catalog/compiler'
+ require 'puppet/rails'
  
  describe Puppet::Resource::Catalog::Compiler do
    before do
 +    require 'puppet/rails'
      Puppet::Rails.stubs(:init)
      Facter.stubs(:to_hash).returns({})
      Facter.stubs(:value).returns(Facter::Util::Fact.new("something"))
@@@ -34,8 -34,8 +35,8 @@@
        Puppet::Node.stubs(:find).with('node1').returns(node1)
        Puppet::Node.stubs(:find).with('node2').returns(node2)
  
-       compiler.find(stub('request', :node => 'node1', :options => {}))
-       compiler.find(stub('node2request', :node => 'node2', :options => {}))
+       compiler.find(stub('request', :key => 'node1', :node => 'node1', :options => {}))
+       compiler.find(stub('node2request', :key => 'node2', :node => 'node2', :options => {}))
      end
  
      it "should provide a method for determining if the catalog is networked" do
@@@ -71,7 -71,7 +72,7 @@@
        @node = Puppet::Node.new @name
        @node.stubs(:merge)
        Puppet::Node.stubs(:find).returns @node
-       @request = stub 'request', :key => "does not matter", :node => @name, :options => {}
+       @request = stub 'request', :key => @name, :node => @name, :options => {}
      end
  
      it "should directly use provided nodes" do
@@@ -81,14 -81,14 +82,14 @@@
        @compiler.find(@request)
      end
  
-     it "should use the request's node name if no explicit node is provided" do
+     it "should use the authenticated node name if no request key is provided" do
+       @request.stubs(:key).returns(nil)
        Puppet::Node.expects(:find).with(@name).returns(@node)
        @compiler.expects(:compile).with(@node)
        @compiler.find(@request)
      end
  
-     it "should use the provided node name if no explicit node is provided and no authenticated node information is available" do
-       @request.expects(:node).returns nil
+     it "should use the provided node name by default" do
        @request.expects(:key).returns "my_node"
  
        Puppet::Node.expects(:find).with("my_node").returns @node
@@@ -156,8 -156,7 +157,8 @@@
        @compiler = Puppet::Resource::Catalog::Compiler.new
        @request = stub 'request', :options => {}
  
 -      @facts = stub 'facts', :save => nil
 +      @facts = Puppet::Node::Facts.new('hostname', "fact" => "value", "architecture" => "i386")
 +      @facts.stubs(:save).returns(nil)
      end
  
      it "should do nothing if no facts are provided" do
@@@ -167,17 -166,12 +168,17 @@@
        @compiler.extract_facts_from_request(@request)
      end
  
 -    it "should use the Facts class to deserialize the provided facts" do
 +    it "should use the Facts class to deserialize the provided facts and update the timestamp" do
        @request.options[:facts_format] = "foo"
        @request.options[:facts] = "bar"
        Puppet::Node::Facts.expects(:convert_from).returns @facts
  
 +      @facts.timestamp = Time.parse('2010-11-01')
 +      @now = Time.parse('2010-11-02')
 +      Time.expects(:now).returns(@now)
 +
        @compiler.extract_facts_from_request(@request)
 +      @facts.timestamp.should == @now
      end
  
      it "should use the provided fact format" do
@@@ -205,7 -199,7 +206,7 @@@
        @compiler = Puppet::Resource::Catalog::Compiler.new
        @name = "me"
        @node = mock 'node'
-       @request = stub 'request', :node => @name, :options => {}
+       @request = stub 'request', :key => @name, :options => {}
        @compiler.stubs(:compile)
      end
  
@@@ -224,7 -218,7 +225,7 @@@
        @compiler = Puppet::Resource::Catalog::Compiler.new
        @name = "me"
        @node = mock 'node'
-       @request = stub 'request', :node => @name, :options => {}
+       @request = stub 'request', :key => @name, :options => {}
        @compiler.stubs(:compile)
        Puppet::Node.stubs(:find).with(@name).returns(@node)
      end
diff --combined spec/unit/parser/ast/resource_spec.rb
index 3ed7b3e,721c31a..3f7fa22
--- a/spec/unit/parser/ast/resource_spec.rb
+++ b/spec/unit/parser/ast/resource_spec.rb
@@@ -11,15 -11,14 +11,15 @@@ describe Puppet::Parser::AST::Resource 
        @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("mynode"))
        @scope = Puppet::Parser::Scope.new(:compiler => @compiler)
        @scope.stubs(:resource).returns(stub_everything)
 -      @resource = ast::Resource.new(:title => @title, :type => "file", :parameters => ast::ASTArray.new(:children => []) )
 +      @instance = ast::ResourceInstance.new(:title => @title, :parameters => ast::ASTArray.new(:children => []))
 +      @resource = ast::Resource.new(:type => "file", :instances => ast::ASTArray.new(:children => [@instance]))
        @resource.stubs(:qualified_type).returns("Resource")
      end
  
      it "should evaluate all its parameters" do
        param = stub 'param'
        param.expects(:safeevaluate).with(@scope).returns Puppet::Parser::Resource::Param.new(:name => "myparam", :value => "myvalue", :source => stub("source"))
 -      @resource.stubs(:parameters).returns [param]
 +      @instance.stubs(:parameters).returns [param]
  
        @resource.evaluate(@scope)
      end
@@@ -36,7 -35,7 +36,7 @@@
  
        array = Puppet::Parser::AST::ASTArray.new(:children => titles)
  
 -      @resource.title = array
 +      @instance.title = array
        result = @resource.evaluate(@scope).collect { |r| r.title }
        result.should be_include("one")
        result.should be_include("two")
@@@ -50,19 -49,12 +50,19 @@@
  
        array = Puppet::Parser::AST::ASTArray.new(:children => titles)
  
 -      @resource.title = array
 +      @instance.title = array
        result = @resource.evaluate(@scope).collect { |r| r.title }
        result.should be_include("one")
        result.should be_include("two")
      end
  
 +    it "should implicitly iterate over instances" do
 +      new_title = Puppet::Parser::AST::String.new(:value => "other_title")
 +      new_instance = ast::ResourceInstance.new(:title => new_title, :parameters => ast::ASTArray.new(:children => []))
 +      @resource.instances.push(new_instance)
 +      @resource.evaluate(@scope).collect { |r| r.title }.should == ["mytitle", "other_title"]
 +    end
 +
      it "should handover resources to the compiler" do
        titles = []
        %w{one two}.each do |title|
@@@ -71,7 -63,7 +71,7 @@@
  
        array = Puppet::Parser::AST::ASTArray.new(:children => titles)
  
 -      @resource.title = array
 +      @instance.title = array
        result = @resource.evaluate(@scope)
  
        result.each do |res|
@@@ -99,19 -91,16 +99,19 @@@
        before do
          @scope = Puppet::Parser::Scope.new :compiler => Puppet::Parser::Compiler.new(Puppet::Node.new("mynode"))
          @parser = Puppet::Parser::Parser.new(Puppet::Node::Environment.new)
 -        @parser.newdefine "one"
 -        @parser.newdefine "one::two"
 -        @parser.newdefine "three"
 +        ["one", "one::two", "three"].each do |name|
 +          @parser.environment.known_resource_types.add(Puppet::Resource::Type.new(:definition, name, {}))
 +        end
          @twoscope = @scope.newscope(:namespace => "one")
          @twoscope.resource = @scope.resource
        end
  
        def resource(type, params = nil)
          params ||= Puppet::Parser::AST::ASTArray.new(:children => [])
 -        Puppet::Parser::AST::Resource.new(:type => type, :title => Puppet::Parser::AST::String.new(:value => "myresource"), :parameters => params)
 +        instance = Puppet::Parser::AST::ResourceInstance.new(
 +                                                             :title => Puppet::Parser::AST::String.new(:value => "myresource"), :parameters => params)
 +        Puppet::Parser::AST::Resource.new(:type => type,
 +                                          :instances => Puppet::Parser::AST::ASTArray.new(:children => [instance]))
        end
  
        it "should be able to generate resources with fully qualified type information" do
@@@ -152,8 -141,7 +152,8 @@@
        @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("mynode"))
        @scope = Puppet::Parser::Scope.new(:compiler => @compiler)
        @scope.stubs(:resource).returns(stub_everything)
 -      @resource = ast::Resource.new(:title => @title, :type => "Class", :parameters => ast::ASTArray.new(:children => []) )
 +      @instance = ast::ResourceInstance.new(:title => @title, :parameters => ast::ASTArray.new(:children => []))
 +      @resource = ast::Resource.new(:type => "Class", :instances => ast::ASTArray.new(:children => [@instance]))
        @resource.stubs(:qualified_type).returns("Resource")
        @type = Puppet::Resource::Type.new(:hostclass, "classname")
        @compiler.known_resource_types.add(@type)
@@@ -164,7 -152,7 +164,7 @@@
        result = @resource.evaluate(@scope)
        result.length.should == 1
        result.first.ref.should == "Class[Classname]"
-       @compiler.catalog.resource("Class[Classname]").should equal result.first
+       @compiler.catalog.resource("Class[Classname]").should equal(result.first)
      end
  
      it "should cause its parent to be evaluated" do
@@@ -175,7 -163,7 +175,7 @@@
        result = @resource.evaluate(@scope)
        result.length.should == 1
        result.first.ref.should == "Class[Classname]"
-       @compiler.catalog.resource("Class[Classname]").should equal result.first
+       @compiler.catalog.resource("Class[Classname]").should equal(result.first)
        @compiler.catalog.resource("Class[Parentname]").should be_instance_of(Puppet::Parser::Resource)
      end
  
diff --combined spec/unit/parser/parser_spec.rb
index b4e1518,07e2d22..75f505e
--- a/spec/unit/parser/parser_spec.rb
+++ b/spec/unit/parser/parser_spec.rb
@@@ -64,16 -64,14 +64,16 @@@ describe Puppet::Parser d
        lambda { @parser.parse("$var += ") }.should raise_error
      end
  
 -    it "should call ast::VarDef with append=true" do
 -      ast::VarDef.expects(:new).with { |h| h[:append] == true }
 -      @parser.parse("$var += 2")
 +    it "should create ast::VarDef with append=true" do
 +      vardef = @parser.parse("$var += 2").code[0]
 +      vardef.should be_a(Puppet::Parser::AST::VarDef)
 +      vardef.append.should == true
      end
  
      it "should work with arrays too" do
 -      ast::VarDef.expects(:new).with { |h| h[:append] == true }
 -      @parser.parse("$var += ['test']")
 +      vardef = @parser.parse("$var += ['test']").code[0]
 +      vardef.should be_a(Puppet::Parser::AST::VarDef)
 +      vardef.append.should == true
      end
  
    end
@@@ -134,6 -132,7 +134,6 @@@
      end
  
      it "should create an ast::ResourceReference" do
 -      ast::Resource.stubs(:new)
        ast::ResourceReference.expects(:new).with { |arg|
          arg[:line]==1 and arg[:type]=="File" and arg[:title].is_a?(ast::ASTArray)
        }
@@@ -152,14 -151,10 +152,14 @@@
      end
  
      it "should create an ast::ResourceOverride" do
 -      ast::ResourceOverride.expects(:new).with { |arg|
 -        arg[:line]==1 and arg[:object].is_a?(ast::ResourceReference) and arg[:parameters].is_a?(ast::ResourceParam)
 -      }
 -      @parser.parse('Resource["title1","title2"] { param => value }')
 +      #ast::ResourceOverride.expects(:new).with { |arg|
 +      #  arg[:line]==1 and arg[:object].is_a?(ast::ResourceReference) and arg[:parameters].is_a?(ast::ResourceParam)
 +      #}
 +      ro = @parser.parse('Resource["title1","title2"] { param => value }').code[0]
 +      ro.should be_a(ast::ResourceOverride)
 +      ro.line.should == 1
 +      ro.object.should be_a(ast::ResourceReference)
 +      ro.parameters[0].should be_a(ast::ResourceParam)
      end
  
    end
@@@ -274,18 -269,43 +274,25 @@@
  
      it "should prefer provided options over AST context" do
        @class.expects(:new).with { |opts| opts[:file] == "/bar" }
-       @parser.expects(:ast_context).returns :file => "/foo"
+       @lexer.expects(:file).returns "/foo"
        @parser.ast(@class, :file => "/bar")
      end
  
      it "should include docs when the AST class uses them" do
        @class.expects(:use_docs).returns true
        @class.stubs(:new)
-       @parser.expects(:ast_context).with(true).returns({})
+       @parser.expects(:ast_context).with{ |a| a[0] == true }.returns({})
        @parser.ast(@class, :file => "/bar")
      end
+ 
+     it "should get docs from lexer using the correct AST line number" do
+       @class.expects(:use_docs).returns true
+       @class.stubs(:new).with{ |a| a[:doc] == "doc" }
+       @lexer.expects(:getcomment).with(12).returns "doc"
+       @parser.ast(@class, :file => "/bar", :line => 12)
+     end
    end
  
 -  describe "when creating a node" do
 -    before :each do
 -      @lexer = stub 'lexer'
 -      @lexer.stubs(:getcomment)
 -      @parser.stubs(:lexer).returns(@lexer)
 -      @node = stub_everything 'node'
 -      @parser.stubs(:ast_context).returns({})
 -      @parser.stubs(:node).returns(nil)
 -
 -      @nodename = stub 'nodename', :is_a? => false, :value => "foo"
 -      @nodename.stubs(:is_a?).with(Puppet::Parser::AST::HostName).returns(true)
 -    end
 -
 -    it "should return an array of nodes" do
 -      @parser.newnode(@nodename).should be_instance_of(Array)
 -    end
 -  end
 -
    describe "when retrieving a specific node" do
      it "should delegate to the known_resource_types node" do
        @known_resource_types.expects(:node).with("node")
@@@ -338,28 -358,30 +345,28 @@@
        @parser.stubs(:known_resource_types).returns @krt
      end
  
 -    it "should create new classes" do
 -      @parser.parse("class foobar {}")
 -      @krt.hostclass("foobar").should be_instance_of(Puppet::Resource::Type)
 +    it "should not create new classes" do
 +      @parser.parse("class foobar {}").code[0].should be_a(Puppet::Parser::AST::Hostclass)
 +      @krt.hostclass("foobar").should be_nil
      end
  
      it "should correctly set the parent class when one is provided" do
 -      @parser.parse("class foobar inherits yayness {}")
 -      @krt.hostclass("foobar").parent.should == "yayness"
 +      @parser.parse("class foobar inherits yayness {}").code[0].instantiate('')[0].parent.should == "yayness"
      end
  
      it "should correctly set the parent class for multiple classes at a time" do
 -      @parser.parse("class foobar inherits yayness {}\nclass boo inherits bar {}")
 -      @krt.hostclass("foobar").parent.should == "yayness"
 -      @krt.hostclass("boo").parent.should == "bar"
 +      statements = @parser.parse("class foobar inherits yayness {}\nclass boo inherits bar {}").code
 +      statements[0].instantiate('')[0].parent.should == "yayness"
 +      statements[1].instantiate('')[0].parent.should == "bar"
      end
  
      it "should define the code when some is provided" do
 -      @parser.parse("class foobar { $var = val }")
 -      @krt.hostclass("foobar").code.should_not be_nil
 +      @parser.parse("class foobar { $var = val }").code[0].code.should_not be_nil
      end
  
      it "should define parameters when provided" do
 -      @parser.parse("class foobar($biz,$baz) {}")
 -      @krt.hostclass("foobar").arguments.should == {"biz" => nil, "baz" => nil}
 +      foobar = @parser.parse("class foobar($biz,$baz) {}").code[0].instantiate('')[0]
 +      foobar.arguments.should == {"biz" => nil, "baz" => nil}
      end
    end
  
@@@ -376,37 -398,13 +383,37 @@@
      end
  
      it "should correctly mark exported resources as exported" do
 -      @parser.parse("@@file { '/file': }")
 -      @krt.hostclass("").code[0].exported.should be_true
 +      @parser.parse("@@file { '/file': }").code[0].exported.should be_true
      end
  
      it "should correctly mark virtual resources as virtual" do
 -      @parser.parse("@file { '/file': }")
 -      @krt.hostclass("").code[0].virtual.should be_true
 +      @parser.parse("@file { '/file': }").code[0].virtual.should be_true
 +    end
 +  end
 +
 +  describe "when parsing nodes" do
 +    it "should be able to parse a node with a single name" do
 +      node = @parser.parse("node foo { }").code[0]
 +      node.should be_a Puppet::Parser::AST::Node
 +      node.names.length.should == 1
 +      node.names[0].value.should == "foo"
 +    end
 +
 +    it "should be able to parse a node with two names" do
 +      node = @parser.parse("node foo, bar { }").code[0]
 +      node.should be_a Puppet::Parser::AST::Node
 +      node.names.length.should == 2
 +      node.names[0].value.should == "foo"
 +      node.names[1].value.should == "bar"
 +    end
 +
 +    it "should be able to parse a node with three names" do
 +      node = @parser.parse("node foo, bar, baz { }").code[0]
 +      node.should be_a Puppet::Parser::AST::Node
 +      node.names.length.should == 3
 +      node.names[0].value.should == "foo"
 +      node.names[1].value.should == "bar"
 +      node.names[2].value.should == "baz"
      end
    end
  end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list