Hello
Working on upgrading from 0.25 to 3.x, I faced a regression regarding Service ensure behavior.
In 0.25, this code, on a RedHat system:
service { 'ntpd':
enable => false,
hasstatus => true;
}
would trigger:
/sbin/chkconfig ntpd
and NO:
service ntpd status
Starting from 2.6 and up to 3.x, both commands are run, the service status is checked (service ntpd status is run), even if ensure is not set (or set to "undef").
On some systems, we have up to 50 services checked, and this is a huge performance impact on our Puppet runs to launch this command when we do not care.
(some services could be quite long to be checked).
I tracked down this behavior change up to this (old) patch:
commit 3f6c9481ce9ac59fb3a84ab6792543d039ee403f
Author: Luke Kanies <lu...@reductivelabs.com>
Date: Tue Jan 19 18:24:15 2010 -0800
Changing Transaction to use the new ResourceHarness
This is a much messier commit than I would like,
mostly because of how 'file' works. I had to
fix multiple special cases, and I had to move others.
The whole system appears to now work, though, and we're
ready to change reports to receive resource status
instances rather than events.
Signed-off-by: Luke Kanies <lu...@reductivelabs.com>
And I quickly workaround this using this oneliner patch:
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 1933097..bf09fdb 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -681,7 +681,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 ensure_prop.should
result[:ensure] = ensure_state = ensure_prop.retrieve
else
ensure_state = nil
What do you think of this?
Aurélien
--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/52B070D5.9040303%40cea.fr.
For more options, visit https://groups.google.com/groups/opt_out.
On Tue, Dec 17, 2013 at 7:42 AM, DEGREMONT Aurelien <aurelien....@cea.fr> wrote:
And I quickly workaround this using this oneliner patch:
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 1933097..bf09fdb 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -681,7 +681,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 ensure_prop.should
result[:ensure] = ensure_state = ensure_prop.retrieve
else
ensure_state = nil
What do you think of this?
I tried it out. After unfortunately it changes the behavior of how puppet detects the current state of a resource on the system. You can see this pretty clearly when you use the "puppet resource" command to inspect something:
--
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+...@googlegroups.com.To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/d757615b-f8a0-4a23-983e-f04301f950bc%40googlegroups.com.
--
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/52B2D933.9030902%40alumni.tu-berlin.de.
For more options, visit https://groups.google.com/groups/opt_out.
On 12/19/2013 12:15 PM, Erik Dalén wrote:Hmm, I think not.
> If that behaviour is changed, wouldn't this break the resources type?
Purging of unmanaged resources is pretty much all that the resources
type is currently capable of. If a resource is not "present" in the
ensure sense, it should not get generated in the first place. If it does
get generated, it implicitly requires purging if it's not managed.
Populating the ensure property should not be strictly required.
This is me guessing mostly, I'm not entirely sure.
Regards,
Felix
--
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/52B2D933.9030902%40alumni.tu-berlin.de.
For more options, visit https://groups.google.com/groups/opt_out.
I took a quick look and I think the resource type is fine. However, since this patch means that we never retrieve the ensure value of the instance the logic around checking how to manage parameters (https://github.com/puppetlabs/puppet/blob/master/lib/puppet/transaction/resource_harness.rb#L80-83) would end up trying to manage resources that might be absent, where it should have done nothing. So for instance, if the service resource in the example
service { 'ntpd:enable => false,hasstatus => true,}
I think would fail if the ntpd service didn't exist on the system, whereas right now it would be skipped. Disclaimer: I haven't tried this out yet, but reading the code leads me to think this is the case.
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'm not sure how far down inside the APIs that functionality needs to be preserved; however, since the retrieve method has had the current behavior for ~4 years, I'm willing to bet that there are systems that use retrieve directly and expect the current behavior.
On 12/19/2013 01:20 PM, Erik Dal�n wrote:
> You could run it on the service type though to stop services you haven't
> explicitly set to run. For services even the stopped ones are present on
> the system.
Ahh, via ensure => stopped in the resources instance? Is ensure a
metaparameter? I wasn't aware this was possible - fascinating.
Le 20/12/2013 16:03, Felix Frank a écrit :
On 12/20/2013 03:41 PM, DEGREMONT Aurelien wrote:
Assuming this patch is clean/adapted, is this something Puppet couldI can't really give a well founded comment on this.
accept? or there is still other problems?
Agreed, but I think guidance from Puppet developers is needed for that.I like Jeff's approach in spirit, but as far as execution is concerned,
my gut says that something more object oriented would be preferable.
What I'm saying is, instead of enriching interfaces with values that
need passing, an approach based on inheritance and method overrides
might lead to better maintainability later on.
As far as I'm concern, I do not think I know the puppet code well enough to do this alone.
Aurélien
--
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+unsubscribe@googlegroups.com.To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/52B45E67.2010709%40cea.fr.
+1 - doing a rescue because I can't figure out where Type.retrieve_resource is going for the retrieve method when called from puppet agent is a pretty sure warning sign that this isn't the cleanest approach. I also noticed that my patch breaks application of stored resources in modules, probably because that's using the RAL resource indirector as well.
On 12/20/2013 10:03 AM, Felix Frank wrote:
On 12/20/2013 03:41 PM, DEGREMONT Aurelien wrote:
Assuming this patch is clean/adapted, is this something Puppet couldI can't really give a well founded comment on this.
accept? or there is still other problems?
I like Jeff's approach in spirit, but as far as execution is concerned,
my gut says that something more object oriented would be preferable.
What I'm saying is, instead of enriching interfaces with values that
need passing, an approach based on inheritance and method overrides
might lead to better maintainability later on.
As an aside, I tested Aurelien's original patch with the mcollective and datacat_collector modules and noticed the same breakage my patch exhibited: if ensure is not present in the resources returned from Type.retrieve, then modules using collected resources will break.
To resolve problems with the patch would I think be intensive, as anything dealing with stored resources would need to set ignoreensure=true. It'd be better to go from the opposite direction and default to the current behavior, but have manifest application invoke retrieve in a different way (or define its own retrieve).
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+unsubscribe@googlegroups.com.To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/52B46617.8080202%40bericotechnologies.com.
--
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/d846f39c-753f-4aaa-99f0-947822791c50%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
if ensure_prop = property(:ensure) or (self.class.needs_ensure_retrieved and self.class.validattr?(:ensure) and ensure_prop = newattr(:ensure))
# Retrieve ensure
else
# Don't retrieve ensure
end
if ... and ensure_prop.should
if ... and (ignoreensure or ensure_prop.should)
As an aside, I tested Aurelien's original patch with the mcollective and
datacat_collector modules and noticed the same breakage my patch
exhibited: if ensure is not present in the resources returned from
Type.retrieve, then modules using collected resources will break.