Commit 9b612df0 authored by Andrew Roetker's avatar Andrew Roetker

(PDB-1855) Add flag for filtering unchanged resources in the terminus

Previously we had now way of sending unchanged resources in the
terminus. This commit adds a boolean flag to the terminus config file,
`include_unchanged_resources=<boolean>`, which will _not_ filter
unchanged resources from a report when set to `true`.
parent 43bb0819
......@@ -76,9 +76,8 @@ Puppet::Reports.register_report(:puppetdb) do
def build_resources_list
profile("Build resources list (count: #{resource_statuses.count})",
[:puppetdb, :resources_list, :build]) do
include_unchanged_resources = false
resources = resource_statuses.values.map { |resource| resource_status_to_hash(resource) }
if ! include_unchanged_resources
if ! config.include_unchanged_resources?
resources.select{ |resource| (! resource["events"].empty?) or resource["skipped"] }
else
resources
......
......@@ -12,7 +12,8 @@ module Puppet::Util::Puppetdb
:server => "puppetdb",
:port => 8081,
:soft_write_failure => false,
:server_url_timeout => 30
:server_url_timeout => 30,
:include_unchanged_resources => false,
}
config_file ||= File.join(Puppet[:confdir], "puppetdb.conf")
......@@ -55,6 +56,7 @@ module Puppet::Util::Puppetdb
!([:server,
:port,
:ignore_blacklisted_events,
:include_unchanged_resources,
:soft_write_failure,
:server_urls,
:server_url_timeout].include?(k))
......@@ -70,6 +72,7 @@ module Puppet::Util::Puppetdb
config_hash[:server_urls] = convert_and_validate_urls(config_hash[:server_urls])
config_hash[:server_url_timeout] = config_hash[:server_url_timeout].to_i
config_hash[:include_unchanged_resources] = Puppet::Util::Puppetdb.to_bool(config_hash[:include_unchanged_resources])
config_hash[:soft_write_failure] = Puppet::Util::Puppetdb.to_bool(config_hash[:soft_write_failure])
self.new(config_hash, uses_server_urls)
......@@ -106,6 +109,10 @@ module Puppet::Util::Puppetdb
config[:server_url_timeout]
end
def include_unchanged_resources?
config[:include_unchanged_resources]
end
def soft_write_failure
config[:soft_write_failure]
end
......
......@@ -197,6 +197,45 @@ describe processor do
end
end
end
context "with unchanged resources turned on" do
let (:config) {
Puppet::Util::Puppetdb.config
}
before :each do
config.stubs(:include_unchanged_resources?).returns(true)
notify_resource =
stub("notify_resource",
{ :pathbuilder => ["foo", "bar", "baz"],
:path => "foo",
:file => "foo",
:line => "foo",
:tags => [],
:type => "Notify",
:title => "Hello there" })
notify_status = Puppet::Resource::Status.new(notify_resource)
notify_status.changed = false
subject.add_resource_status(notify_status)
end
context "with an unchanged resource" do
it "should include the actual event" do
result = subject.send(:report_to_hash)
result["resources"].length.should == 2
resource = result["resources"][1]
resource["resource_type"].should == "Notify"
resource["resource_title"].should == "Hello there"
resource["file"].should == "foo"
resource["line"].should == "foo"
resource["containment_path"].should == ["foo", "bar", "baz"]
resource["events"].length.should == 0
end
end
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment