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

Jesse Wolfe jes5199 at gmail.com
Thu Mar 17 10:49:42 UTC 2011


The following commit has been merged in the upstream branch:
commit 658bdb72bee3ad664627a71793213e6540afd5cb
Merge: 4c9bd43bc2f5fde9d86196e8689dced929d39aad 02b311113df84646406737ccfad961c5b6df4ae8
Author: Jesse Wolfe <jes5199 at gmail.com>
Date:   Tue Mar 15 17:04:49 2011 -0700

    Merge branch 'ticket/2.6.x/5605' of git://github.com/stschulte/puppet into 2.6.next

diff --combined lib/puppet/resource.rb
index 2145169,a527968..0f4e24c
--- a/lib/puppet/resource.rb
+++ b/lib/puppet/resource.rb
@@@ -5,11 -5,6 +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'
@@@ -51,10 -46,6 +51,10 @@@
      resource
    end
  
 +  def inspect
 +    "#{@type}[#{@title}]#{to_hash.inspect}"
 +  end
 +
    def to_pson_data_hash
      data = ([:type, :title, :tags] + ATTRIBUTES).inject({}) do |hash, param|
        next hash unless value = self.send(param)
@@@ -92,7 -83,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
@@@ -109,7 -100,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
  
@@@ -117,13 -108,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)
@@@ -145,11 -136,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
@@@ -175,6 -166,14 +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 = {}
@@@ -201,14 -200,9 +201,14 @@@
      tag(self.type)
      tag(self.title) if valid_tag?(self.title)
  
 -    @reference = Reference.new(@type, at title) # for serialization compatibility with 0.25.x
 -
 -    raise ArgumentError, "Invalid resource type #{type}" if strict? and ! resource_type
 +    @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}"
 +      else
 +        raise ArgumentError, "Invalid resource type #{type}"
 +      end
 +    end
    end
  
    def ref
@@@ -231,7 -225,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
@@@ -243,35 -237,29 +243,40 @@@
      h = self.to_hash
      h[namevar] ||= h[:name]
      h[:name]   ||= h[namevar]
-     h.values_at(*key_attributes.sort_by { |k| k.to_s })
+     # Simulate the same behaviour like Type#uniqueness_key
+     if key_attributes.size == 1
+       h[namevar]
+     else
+       h.values_at(*key_attributes)
+     end
    end
  
    def key_attributes
-     return(resource_type.respond_to? :key_attributes) ? resource_type.key_attributes : [:name]
+     resource_type.respond_to?(:key_attributes) ? resource_type.key_attributes : [:name]
    end
  
    # 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_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]
 +      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
@@@ -430,10 -418,4 +435,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 lib/puppet/transaction.rb
index aa650ee,0bb98f8..6c816f1
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@@ -6,6 -6,7 +6,6 @@@ require 'puppet/util/tagging
  require 'puppet/application'
  
  class Puppet::Transaction
 -  require 'puppet/transaction/change'
    require 'puppet/transaction/event'
    require 'puppet/transaction/event_manager'
    require 'puppet/transaction/resource_harness'
@@@ -221,6 -222,12 +221,6 @@@
      end
    end
  
 -  # Generate a transaction report.
 -  def generate_report
 -    @report.calculate_metrics
 -    @report
 -  end
 -
    # Should we ignore tags?
    def ignore_tags?
      ! (@catalog.host_config? or Puppet[:name] == "puppet")
@@@ -231,7 -238,7 +231,7 @@@
    def initialize(catalog)
      @catalog = catalog
  
 -    @report = Report.new
 +    @report = Report.new("apply", catalog.version)
  
      @event_manager = Puppet::Transaction::EventManager.new(self)
  
@@@ -245,7 -252,7 +245,7 @@@
      @catalog.vertices.each do |resource|
        if provider = resource.provider and provider.class.respond_to?(:prefetch)
          prefetchers[provider.class] ||= {}
-         prefetchers[provider.class][resource.name] = resource
+         prefetchers[provider.class][resource.uniqueness_key] = resource
        end
      end
  
@@@ -278,6 -285,26 +278,6 @@@
      catalog.relationship_graph
    end
  
 -  # Send off the transaction report.
 -  def send_report
 -    begin
 -      report = generate_report
 -    rescue => detail
 -      Puppet.err "Could not generate report: #{detail}"
 -      return
 -    end
 -
 -    puts report.summary if Puppet[:summarize]
 -
 -    if Puppet[:report]
 -      begin
 -        report.save
 -      rescue => detail
 -        Puppet.err "Reporting failed: #{detail}"
 -      end
 -    end
 -  end
 -
    def add_resource_status(status)
      report.add_resource_status status
    end
diff --combined lib/puppet/type.rb
index 205d809,c50f8de..c8d8688
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@@ -200,7 -200,13 +200,13 @@@ class Typ
    end
  
    def uniqueness_key
-     to_resource.uniqueness_key
+     # If we have only one namevar use that one (res.uniqueness_key behaves
+     # like res[:name] in that case). Otherwise use an array of all keyattributes
+     if name_var
+       self[:name]
+     else
+       @parameters.values_at(*self.class.key_attributes).collect {|p| p.value }
+     end
    end
  
    # Create a new parameter.  Requires a block and a name, stores it in the
@@@ -382,8 -388,8 +388,8 @@@
  
      fail("Invalid parameter #{name}(#{name.inspect})") unless self.class.validattr?(name)
  
 -    if name == :name
 -      name = name_var
 +    if name == :name && nv = name_var
 +      name = nv
      end
  
      if obj = @parameters[name]
@@@ -403,8 -409,8 +409,8 @@@
  
      fail("Invalid parameter #{name}") unless self.class.validattr?(name)
  
 -    if name == :name
 -      name = name_var
 +    if name == :name && nv = name_var
 +      name = nv
      end
      raise Puppet::Error.new("Got nil value for #{name}") if value.nil?
  
@@@ -446,7 -452,7 +452,7 @@@
    # Create a transaction event.  Called by Transaction or by
    # a property.
    def event(options = {})
 -    Puppet::Transaction::Event.new({:resource => self, :file => file, :line => line, :tags => tags, :version => version}.merge(options))
 +    Puppet::Transaction::Event.new({:resource => self, :file => file, :line => line, :tags => tags}.merge(options))
    end
  
    # Let the catalog determine whether a given cached value is
@@@ -648,7 -654,7 +654,7 @@@
            "The is value is not in the is array for '#{property.name}'"
        end
        ensureis = is[property]
 -      if property.insync?(ensureis) and property.should == :absent
 +      if property.safe_insync?(ensureis) and property.should == :absent
          return true
        end
      end
@@@ -660,7 -666,7 +666,7 @@@
        end
  
        propis = is[property]
 -      unless property.insync?(propis)
 +      unless property.safe_insync?(propis)
          property.debug("Not in sync: #{propis.inspect} vs #{property.should.inspect}")
          insync = false
        #else
@@@ -957,25 -963,12 +963,25 @@@
    end
  
    newmetaparam(:audit) do
 -    desc "Audit specified attributes of resources over time, and report if any have changed.
 -      This attribute can be used to track changes to any resource over time, and can
 -      provide an audit trail of every change that happens on any given machine.
 -
 -      Note that you cannot both audit and manage an attribute - managing it guarantees
 -      the value, and any changes already get logged."
 +    desc "Marks a subset of this resource's unmanaged attributes for auditing. Accepts an
 +      attribute name or a list of attribute names.
 +
 +      Auditing a resource attribute has two effects: First, whenever a catalog
 +      is applied with puppet apply or puppet agent, Puppet will check whether
 +      that attribute of the resource has been modified, comparing its current
 +      value to the previous run; any change will be logged alongside any actions
 +      performed by Puppet while applying the catalog.
 +
 +      Secondly, marking a resource attribute for auditing will include that
 +      attribute in inspection reports generated by puppet inspect; see the
 +      puppet inspect documentation for more details.
 +
 +      Managed attributes for a resource can also be audited, but note that
 +      changes made by Puppet will be logged as additional modifications. (I.e.
 +      if a user manually edits a file whose contents are audited and managed,
 +      puppet agent's next two runs will both log an audit notice: the first run
 +      will log the user's edit and then revert the file to the desired state,
 +      and the second run will log the edit made by Puppet.)"
  
      validate do |list|
        list = Array(list).collect {|p| p.to_sym}
diff --combined spec/unit/resource_spec.rb
index 345ccd0,092ae8c..6f94409
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@@ -98,14 -98,6 +98,14 @@@ describe Puppet::Resource d
      lambda { Puppet::Resource.new("foo") }.should raise_error(ArgumentError)
    end
  
 +  it 'should fail if strict is set and type does not exist' do
 +    lambda { Puppet::Resource.new('foo', 'title', {:strict=>true}) }.should raise_error(ArgumentError, 'Invalid resource type foo')
 +  end
 +
 +  it 'should fail if strict is set and class does not exist' do
 +    lambda { Puppet::Resource.new('Class', 'foo', {:strict=>true}) }.should raise_error(ArgumentError, 'Could not find declared class foo')
 +  end
 +
    it "should fail if the title is a hash and the type is not a valid resource reference string" do
      lambda { Puppet::Resource.new({:type => "foo", :title => "bar"}) }.should raise_error(ArgumentError,
        'Puppet::Resource.new does not take a hash as the first argument. Did you mean ("foo", "bar") ?'
@@@ -276,7 -268,7 +276,7 @@@
    describe "when referring to a resource with name canonicalization" do
      it "should canonicalize its own name" do
        res = Puppet::Resource.new("file", "/path/")
-       res.uniqueness_key.should == ["/path"]
+       res.uniqueness_key.should == "/path"
        res.ref.should == "File[/path/]"
      end
    end
@@@ -463,28 -455,6 +463,28 @@@
      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")
@@@ -508,23 -478,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")
 +      @resource = Puppet::Resource.new("one::two", "/my/file",
 +        :parameters => {
 +          :noop => true,
 +          :foo => %w{one two},
 +          :ensure => 'present',
 +        }
 +      )
      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']")
 +    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
  
@@@ -619,7 -585,9 +619,7 @@@
      end
    end
  
 -  describe "when converting to pson" do
 -    confine "Missing 'pson' library" => Puppet.features.pson?
 -
 +  describe "when converting to pson", :if => Puppet.features.pson? do
      def pson_output_should
        @resource.class.expects(:pson_create).with { |hash| yield hash }
      end
@@@ -698,7 -666,9 +698,7 @@@
      end
    end
  
 -  describe "when converting from pson" do
 -    confine "Missing 'pson' library" => Puppet.features.pson?
 -
 +  describe "when converting from pson", :if => Puppet.features.pson? do
      def pson_result_should
        Puppet::Resource.expects(:new).with { |hash| yield hash }
      end
@@@ -800,7 -770,14 +800,14 @@@
    end
  
    describe "when generating the uniqueness key" do
-     it "should include all of the key_attributes in alphabetical order by attribute name" do
+ 
+     it "should use namevar if there is only one key_attribute" do
+       Puppet::Type.type(:file).stubs(:key_attributes).returns [:path]
+       res = Puppet::Resource.new("file", "/my/file", :parameters => {:owner => 'root', :content => 'hello'})
+       res.uniqueness_key.should == '/my/file'
+     end
+ 
+     it "should include all of the key_attributes" do
        Puppet::Type.type(:file).stubs(:key_attributes).returns [:myvar, :owner, :path]
        Puppet::Type.type(:file).stubs(:title_patterns).returns(
          [ [ /(.*)/, [ [:path, lambda{|x| x} ] ] ] ]

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list