In the end, even just the behavior change to "puppet resource" makes the patch a non-starter because it is a widely used feature.

I understand this feature should be kept, but that a pity this should impact other even more useful feature like "apply" or "agent".

Could it be possible that "puppet resource" and other like "apply" or "agent" retrieves only what they need? In apply/agent case, this come from a transaction being applied. For "puppet resource" I assume this is not the case. Could method parameter solve this case? And this could even keep the compat if this param is not specified


I spent all day (because my Ruby is bad) doing a proof of concept with this. It touches type.rb and indirector/resource/ral.rb to add a seemingly transparent method variable flagging whether ensure should be ignored for the purpose of retrieving resources. It defaults to false (don't ignore ensure), which should cause the speedup Aurelien is needing. The resource RAL indirector is aware of the method parameter and sets it to true (ignoreensure), thereby exhibiting the old behavior when puppet resource is called from the command line.

There is a nasty bit that I'm unsure of in the retrieve_resource method. I discovered that when running puppet agent -t --noop, if I tried to use my newly defined method parameter that parsing would choke - apparently in that state the retrieve method is targeting another method. I worked around it by putting in a rescue statement and falling back to the old way of calling retrieve which should, eventually, still hit the retrieve with Aurelien's improved conditional logic.

Anyway, please find attached a diff containing the changes in question. Feel free to refine and submit it as a PR, my Ruby really isn't up for my doing so myself.

Jeff


--
You received this message because you are subscribed to the Google Groups "Puppet 
Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-dev/52B3758A.5000406%40bericotechnologies.com.
For more options, visit https://groups.google.com/groups/opt_out.
diff --git a/lib/puppet/indirector/resource/ral.rb b/lib/puppet/indirector/resource/ral.rb
index 30c8623..5fa1a9f 100644
--- a/lib/puppet/indirector/resource/ral.rb
+++ b/lib/puppet/indirector/resource/ral.rb
@@ -10,7 +10,7 @@ class Puppet::Resource::Ral < Puppet::Indirector::Code
     res   = type(request).instances.find { |o| o.name == resource_name(request) }
     res ||= type(request).new(:name => resource_name(request), :audit => type(request).properties.collect { |s| s.name })
 
-    res.to_resource
+    res.to_resource(ignoreensure=true)
   end
 
   def search( request )
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 55b4a5f..37845d7 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -1009,7 +1009,7 @@ class Type
   #   methods that also "gets" properties/parameters/etc. ?
   # @return [Puppet::Resource] array of all property values (mix of types)
   # @raise [fail???] if there is a provider and it is not suitable for the host this is evaluated for.
-  def retrieve
+  def retrieve(ignoreensure=false)
     fail "Provider #{provider.class.name} is not functional on this host" if self.provider.is_a?(Puppet::Provider) and ! provider.class.suitable?
 
     result = Puppet::Resource.new(type, title)
@@ -1017,7 +1017,7 @@ class Type
     # Provide the name, so we know we'll always refer to a real thing
     result[:name] = self[:name] unless self[:name] == title
 
-    if ensure_prop = property(:ensure) or (self.class.validattr?(:ensure) and ensure_prop = newattr(:ensure))
+    if ensure_prop = property(:ensure) or (self.class.validattr?(:ensure) and ensure_prop = newattr(:ensure)) and (ignoreensure or ensure_prop.should)
       result[:ensure] = ensure_state = ensure_prop.retrieve
     else
       ensure_state = nil
@@ -1045,7 +1045,9 @@ class Type
   #   of the system.
   #
   # @api private
-  def retrieve_resource
+  def retrieve_resource(ignoreensure=false)
+    resource = retrieve(ignoreensure)
+    rescue
     resource = retrieve
     resource = Resource.new(type, title, :parameters => resource) if resource.is_a? Hash
     resource
@@ -2389,8 +2391,8 @@ class Type
   # @todo What to resource? Which one of the resource forms is prroduced? returned here?
   # @return [??? Resource] a resource that WHAT???
   #
-  def to_resource
-    resource = self.retrieve_resource
+  def to_resource(ignoreensure=false)
+    resource = self.retrieve_resource(ignoreensure)
     resource.tag(*self.tags)
 
     @parameters.each do |name, param|

Reply via email to