[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 2.6.5-303-gfcfa26a

Jacob Helwig jacob at puppetlabs.com
Thu Mar 17 10:49:32 UTC 2011


The following commit has been merged in the upstream branch:
commit a6d0e99e97d18b622793a807e985580cb65a8c7c
Merge: 5d3aa54d86a7b9a2c089b2dbff0778d928853666 4c1929952e7239f14aa1ab6a317d445a05d770c3
Author: Jacob Helwig <jacob at puppetlabs.com>
Date:   Tue Mar 15 11:25:01 2011 -0700

    Merge branch 'ticket/2.6.next/5428-handle-0.25.x-storedconfig-data' into 2.6.next
    
    * ticket/2.6.next/5428-handle-0.25.x-storedconfig-data:
      Remove extra trailing whitespace from lib/puppet/resource.rb
      (#5428) More fully "stub" Puppet::Resource::Reference for use with storedconfigs
    
    Conflicts:
    	lib/puppet/resource.rb

diff --combined lib/puppet/resource.rb
index a71675e,45ee2e9..2145169
--- a/lib/puppet/resource.rb
+++ b/lib/puppet/resource.rb
@@@ -5,6 -5,11 +5,11 @@@ require 'puppet/util/pson
  # The simplest resource class.  Eventually it will function as the
  # base class for all resource-like behaviour.
  class Puppet::Resource
+   # This stub class is only needed for serialization compatibility with 0.25.x.
+   # Specifically, it exists to provide a compatibility API when using YAML
+   # serialized objects loaded from StoreConfigs.
+   Reference = Puppet::Resource
+ 
    include Puppet::Util::Tagging
  
    require 'puppet/resource/type_collection_helper'
@@@ -87,7 -92,7 +92,7 @@@
    def yaml_property_munge(x)
      case x
      when Hash
-       x.inject({}) { |h,kv| 
+       x.inject({}) { |h,kv|
          k,v = kv
          h[k] = self.class.value_to_pson_data(v)
          h
@@@ -104,7 -109,7 +109,7 @@@
    # be overridden at some point, but this works for now.
    %w{has_key? keys length delete empty? <<}.each do |method|
      define_method(method) do |*args|
-       @parameters.send(method, *args)
+       parameters.send(method, *args)
      end
    end
  
@@@ -112,13 -117,13 +117,13 @@@
    # to lower-case symbols.
    def []=(param, value)
      validate_parameter(param) if validate_parameters
-     @parameters[parameter_name(param)] = value
+     parameters[parameter_name(param)] = value
    end
  
    # Return a given parameter's value.  Converts all passed names
    # to lower-case symbols.
    def [](param)
-     @parameters[parameter_name(param)]
+     parameters[parameter_name(param)]
    end
  
    def ==(other)
@@@ -140,11 -145,11 +145,11 @@@
  
    # Iterate over each param/value pair, as required for Enumerable.
    def each
-     @parameters.each { |p,v| yield p, v }
+     parameters.each { |p,v| yield p, v }
    end
  
    def include?(parameter)
-     super || @parameters.keys.include?( parameter_name(parameter) )
+     super || parameters.keys.include?( parameter_name(parameter) )
    end
  
    # These two methods are extracted into a Helper
@@@ -170,14 -175,6 +175,6 @@@
      end
    end
  
-   # This stub class is only needed for serialization compatibility with 0.25.x
-   class Reference
-     attr_accessor :type,:title
-     def initialize(type,title)
-       @type, at title = type,title
-     end
-   end
- 
    # Create our resource.
    def initialize(type, title = nil, attributes = {})
      @parameters = {}
@@@ -204,7 -201,7 +201,7 @@@
      tag(self.type)
      tag(self.title) if valid_tag?(self.title)
  
-     @reference = Reference.new(@type, at title) # for serialization compatibility with 0.25.x
+     @reference = self # for serialization compatibility with 0.25.x
      if strict? and ! resource_type
        if @type == 'Class'
          raise ArgumentError, "Could not find declared class #{title}"
@@@ -234,7 -231,7 +231,7 @@@
  
    # Produce a simple hash of our parameters.
    def to_hash
-     parse_title.merge @parameters
+     parse_title.merge parameters
    end
  
    def to_s
@@@ -255,26 -252,15 +252,26 @@@
  
    # Convert our resource to Puppet code.
    def to_manifest
 -    "%s { '%s':\n%s\n}" % [self.type.to_s.downcase, self.title,
 -      parameters.collect { |p, v|
 -        if v.is_a? Array
 -          "    #{p} => [\'#{v.join("','")}\']"
 -        else
 -          "    #{p} => \'#{v}\'"
 -        end
 -      }.join(",\n")
 -      ]
 +    # Collect list of attributes to align => and move ensure first
-     attr = @parameters.keys
++    attr = parameters.keys
 +    attr_max = attr.inject(0) { |max,k| k.to_s.length > max ? k.to_s.length : max }
 +
 +    attr.sort!
 +    if attr.first != :ensure  && attr.include?(:ensure)
 +      attr.delete(:ensure)
 +      attr.unshift(:ensure)
 +    end
 +
 +    attributes = attr.collect { |k|
-       v = @parameters[k]
++      v = parameters[k]
 +      if v.is_a? Array
 +        "  %-#{attr_max}s => %s,\n" % [ k, "[\'#{v.join("', '")}\']" ]
 +      else
 +        "  %-#{attr_max}s => %s,\n" % [ k, "\'#{v}\'" ]
 +      end
 +    }
 +
 +    "%s { '%s':\n%s}" % [self.type.to_s.downcase, self.title, attributes]
    end
  
    def to_ref
@@@ -433,4 -419,10 +430,10 @@@
        return { :name => title.to_s }
      end
    end
+ 
+   def parameters
+     # @parameters could have been loaded from YAML, causing it to be nil (by
+     # bypassing initialize).
+     @parameters ||= {}
+   end
  end
diff --combined spec/unit/resource_spec.rb
index eaa3d55,4c1dc49..345ccd0
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@@ -463,6 -463,28 +463,28 @@@ describe Puppet::Resource d
      end
    end
  
+   describe "when loading 0.25.x storedconfigs YAML" do
+     before :each do
+       @old_storedconfig_yaml = %q{--- !ruby/object:Puppet::Resource::Reference
+ builtin_type:
+ title: /tmp/bar
+ type: File
+ }
+     end
+ 
+     it "should deserialize a Puppet::Resource::Reference without exceptions" do
+       lambda { YAML.load(@old_storedconfig_yaml) }.should_not raise_error
+     end
+ 
+     it "should deserialize as a Puppet::Resource::Reference as a Puppet::Resource" do
+       YAML.load(@old_storedconfig_yaml).class.should == Puppet::Resource
+     end
+ 
+     it "should to_hash properly" do
+       YAML.load(@old_storedconfig_yaml).to_hash.should == { :path => "/tmp/bar" }
+     end
+   end
+ 
    describe "when converting to a RAL resource" do
      it "should use the resource type's :new method to create the resource if the resource is of a builtin type" do
        resource = Puppet::Resource.new("file", @basepath+"/my/file")
@@@ -486,23 -508,19 +508,23 @@@
  
    describe "when converting to puppet code" do
      before do
 -      @resource = Puppet::Resource.new("one::two", "/my/file", :parameters => {:noop => true, :foo => %w{one two}})
 -    end
 -
 -    it "should print the type and title" do
 -      @resource.to_manifest.should be_include("one::two { '/my/file':\n")
 -    end
 -
 -    it "should print each parameter, with the value single-quoted" do
 -      @resource.to_manifest.should be_include("    noop => 'true'")
 -    end
 -
 -    it "should print array values appropriately" do
 -      @resource.to_manifest.should be_include("    foo => ['one','two']")
 +      @resource = Puppet::Resource.new("one::two", "/my/file",
 +        :parameters => {
 +          :noop => true,
 +          :foo => %w{one two},
 +          :ensure => 'present',
 +        }
 +      )
 +    end
 +
 +    it "should align, sort and add trailing commas to attributes with ensure first" do
 +      @resource.to_manifest.should == <<-HEREDOC.gsub(/^\s{8}/, '').gsub(/\n$/, '')
 +        one::two { '/my/file':
 +          ensure => 'present',
 +          foo    => ['one', 'two'],
 +          noop   => 'true',
 +        }
 +      HEREDOC
      end
    end
  

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list