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

Jesse Wolfe jes5199 at gmail.com
Tue May 10 07:59:13 UTC 2011


The following commit has been merged in the experimental branch:
commit c6e824ad5144957e351892a1d745a127b02f34b3
Merge: 2e189d5166430b9ed37d9289a746b73e8673cab6 f95006148c3a0b4d7e8ee1812b1993b674f050e4
Author: Jesse Wolfe <jes5199 at gmail.com>
Date:   Sat Oct 2 01:09:29 2010 -0700

    Partial merge to 2.6.2rc1 : Merge commit 'f950061' into next
    
    Some specs were in conflict, as they had been recently modified to use
    the API functionality that f950061 removes. This merge commit simply
    restores the verson of those specs from f950061.
    
    Manually Resolved Conflicts:
    	spec/unit/dsl/resource_type_api_spec.rb

diff --combined lib/puppet/parser/parser_support.rb
index 41bebe42,c90c197..288abb5
--- a/lib/puppet/parser/parser_support.rb
+++ b/lib/puppet/parser/parser_support.rb
@@@ -29,9 -29,18 +29,9 @@@ 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
@@@ -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,49 -174,50 +145,51 @@@
  
    # 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$/
 +      parse_ruby_file
 +      main = nil
 +    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
  
    def parse_ruby_file
-     require self.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))
    end
  
    def string=(string)
diff --combined spec/unit/parser/parser_spec.rb
index bf4ef0c,f73e07a..b4e1518
--- a/spec/unit/parser/parser_spec.rb
+++ b/spec/unit/parser/parser_spec.rb
@@@ -52,15 -52,6 +52,6 @@@ describe Puppet::Parser d
        @parser.file = "/my/file.rb"
        @parser.parse
      end
- 
-     describe "in ruby" do
-       it "should use the ruby interpreter to load the file" do
-         @parser.file = "/my/file.rb"
-         @parser.expects(:require).with "/my/file.rb"
- 
-         @parser.parse_ruby_file
-       end
-     end
    end
  
    describe "when parsing append operator" do
@@@ -73,16 -64,14 +64,16 @@@
        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
@@@ -143,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)
        }
@@@ -161,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
@@@ -295,6 -281,24 +286,6 @@@
      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")
@@@ -347,28 -351,30 +338,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
  
@@@ -385,37 -391,13 +376,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