On Sep 30, 2009, at 3:06 PM, Markus Roberts wrote:
>
> Refactor to not generate explicit resources and to not bail out if
> one of a set can not be ensured absend.
>
> Signed-off-by: Markus Roberts <[email protected]>
> ---
> lib/puppet/type/resources.rb | 34 +++++++++++++++++-----------------
> 1 files changed, 17 insertions(+), 17 deletions(-)
>
> diff --git a/lib/puppet/type/resources.rb b/lib/puppet/type/
> resources.rb
> index ab564a1..87bde97 100644
> --- a/lib/puppet/type/resources.rb
> +++ b/lib/puppet/type/resources.rb
> @@ -85,33 +85,33 @@ Puppet::Type.newtype(:resources) do
> end
> end
>
> + def able_to_ensure_absent?(resource)
> + begin
> + resource[:ensure] = :absent
> + rescue ArgumentError, Puppet::Error => detail
> + err "The 'ensure' attribute on #{self[:name]} resources
> does not accept 'absent' as a value"
> + false
> + end
> + end
I like the idea of pulling this into a method, but I'd prefer (given
you're doing that) to just use validparameter? on the class:
def able_to_ensure_absent?(resource)
resource.class.validparameter?(:ensure)
end
>
> # Generate any new resources we need to manage. This is pretty
> hackish
> # right now, because it only supports purging.
> def generate
> return [] unless self.purge?
> - hascheck = false
> - method =
> - resource_type.instances.find_all do |resource|
> - ! resource.managed?
> - end.find_all do |resource|
> - check(resource)
> - end.each do |resource|
> - begin
> - resource[:ensure] = :absent
> - rescue ArgumentError, Puppet::Error => detail
> - err "The 'ensure' attribute on %s resources does
> not accept 'absent' as a value" %
> - [self[:name]]
> - return []
> - end
> + resource_type.instances.
> + reject { |r| managed? }.
> + reject { |r| catalog.resources.include? r.ref }.
> + select { |r| check(r) }.
> + select { |r| able_to_ensure_absent?(r) }.
> + each { |resource|
> @parameters.each do |name, param|
> - next unless param.metaparam?
> - resource[name] = param.value
> + resource[name] = param.value if param.metaparam?
> end
>
> # Mark that we're purging, so transactions can handle
> relationships
> # correctly
> resource.purging
> - end
> + }
> end
>
> def resource_type
Are there any testing repercussions for this patch?
--
Somewhere on this globe, every ten seconds, there is a woman giving
birth to a child. She must be found and stopped. -- Sam Levenson
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---