If we delete a resource, do we not report what the properties were at
the time of deletion?  That is, if I wanted to recreate the resource
from the reported info, could I?

-- 
Luke Kanies | +1-615-594-8199

On Jan 3, 2011, at 11:32, Jesse Wolfe <[email protected]> wrote:

> If a resource is absent, then reporting that its properties are all
> ":absent" is not particularly correct. This patch makes the `inspect`
> application's reports behave more like `apply` reports, and skip
> properties other than :ensure for absent resources.
>
> Reviewed-By: Nick Lewis <[email protected]>
> Signed-off-by: Jesse Wolfe <[email protected]>
> ---
> lib/puppet/application/inspect.rb     |    8 ++++++--
> lib/puppet/reports/http.rb            |    2 +-
> spec/unit/application/inspect_spec.rb |   25 ++++++++++++++++++++++++-
> 3 files changed, 31 insertions(+), 4 deletions(-)
>
> diff --git a/lib/puppet/application/inspect.rb 
> b/lib/puppet/application/inspect.rb
> index caa32a7..342b8da 100644
> --- a/lib/puppet/application/inspect.rb
> +++ b/lib/puppet/application/inspect.rb
> @@ -64,8 +64,12 @@ class Puppet::Application::Inspect < Puppet::Application
>
>       status = Puppet::Resource::Status.new(ral_resource)
>       audited_attributes.each do |name|
> -        event = ral_resource.event(:previous_value => 
> audited_resource[name], :property => name, :status => "audit", :message => 
> "inspected value is #{audited_resource[name].inspect}")
> -        status.add_event(event)
> +        next if audited_resource[name].nil?
> +        # Skip :absent properties of :absent resources. Really, it would be 
> nicer if the RAL returned nil for those, but it doesn't. ~JW
> +        if name == :ensure or audited_resource[:ensure] != :absent or 
> audited_resource[name] != :absent
> +          event = ral_resource.event(:previous_value => 
> audited_resource[name], :property => name, :status => "audit", :message => 
> "inspected value is #{audited_resource[name].inspect}")
> +          status.add_event(event)
> +        end
>       end
>       @report.add_resource_status(status)
>     end
> diff --git a/lib/puppet/reports/http.rb b/lib/puppet/reports/http.rb
> index 7ac54df..101c8e0 100644
> --- a/lib/puppet/reports/http.rb
> +++ b/lib/puppet/reports/http.rb
> @@ -15,7 +15,7 @@ Puppet::Reports.register_report(:http) do
>     req = Net::HTTP::Post.new(url.path)
>     req.body = self.to_yaml
>     req.content_type = "application/x-yaml"
> -    Net::HTTP.new(url.host, url.port).start {|http|
> +    p Net::HTTP.new(url.host, url.port).start {|http|
>       http.request(req)
>     }
>   end
> diff --git a/spec/unit/application/inspect_spec.rb 
> b/spec/unit/application/inspect_spec.rb
> index a3cc74d..b931708 100644
> --- a/spec/unit/application/inspect_spec.rb
> +++ b/spec/unit/application/inspect_spec.rb
> @@ -51,7 +51,7 @@ describe Puppet::Application::Inspect do
>       catalog = Puppet::Resource::Catalog.new
>       file = Tempfile.new("foo")
>       file.puts("file contents")
> -      file.flush
> +      file.close
>       resource = Puppet::Resource.new(:file, file.path, :parameters => 
> {:audit => "all"})
>       catalog.add_resource(resource)
>       
> Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(catalog)
> @@ -69,6 +69,29 @@ describe Puppet::Application::Inspect do
>       end
>       properties["ensure"].should == :file
>       properties["content"].should == "{md5}#{Digest::MD5.hexdigest("file 
> contents\n")}"
> +      properties.has_key?("target").should == false
> +    end
> +
> +    it "should not report irrelevent attributes if the resource is absent" do
> +      catalog = Puppet::Resource::Catalog.new
> +      file = Tempfile.new("foo")
> +      resource = Puppet::Resource.new(:file, file.path, :parameters => 
> {:audit => "all"})
> +      file.delete
> +      catalog.add_resource(resource)
> +      
> Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(catalog)
> +
> +      events = nil
> +
> +      Puppet::Transaction::Report::Rest.any_instance.expects(:save).with do 
> |request|
> +        events = request.instance.resource_statuses.values.first.events
> +      end
> +
> +      @inspect.run_command
> +
> +      properties = events.inject({}) do |property_values, event|
> +        property_values.merge(event.property => event.previous_value)
> +      end
> +      properties.should == {"ensure" => :absent}
>     end
>   end
>
> --
> 1.7.0.4
>
> --
> 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.
>

-- 
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.

Reply via email to