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

(PDB-2126) (PDB-2269) Add catalog_uuid etc. to reports in the terminus

This commit adds three fields (catalog_uuid, cached_catalog_reason,
code_id) to reports in the PuppetDB terminus.
parent 9c2fbb47
......@@ -10,7 +10,7 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
def save(request)
profile("catalog#save", [:puppetdb, :catalog, :save, request.key]) do
catalog = munge_catalog(request.instance, extract_extra_request_data(request))
submit_command(request.key, catalog, CommandReplaceCatalog, 7)
submit_command(request.key, catalog, CommandReplaceCatalog, 8)
end
end
......
......@@ -19,7 +19,7 @@ Puppet::Reports.register_report(:puppetdb) do
# @return [void]
def process
profile("report#process", [:puppetdb, :report, :process]) do
submit_command(self.host, report_to_hash, CommandStoreReport, 6)
submit_command(self.host, report_to_hash, CommandStoreReport, 7)
end
nil
......@@ -40,21 +40,28 @@ Puppet::Reports.register_report(:puppetdb) do
resources = build_resources_list
is_noop = resources.any? { |rs| has_noop_event?(rs) } and resources.none? { |rs| has_failed_event?(rs) }
defaulted_catalog_uuid = defined?(catalog_uuid) ? catalog_uuid : transaction_uuid
defaulted_code_id = defined?(code_id) ? code_id : nil
defaulted_cached_catalog_status = defined?(cached_catalog_status) ? cached_catalog_status : nil
{
"certname" => host,
"puppet_version" => puppet_version,
"report_format" => report_format,
"configuration_version" => configuration_version.to_s,
"producer_timestamp" => Puppet::Util::Puppetdb.to_wire_time(Time.now),
"start_time" => Puppet::Util::Puppetdb.to_wire_time(time),
"end_time" => Puppet::Util::Puppetdb.to_wire_time(time + run_duration),
"environment" => environment,
"transaction_uuid" => transaction_uuid,
"status" => status,
"noop" => is_noop,
"logs" => build_logs_list,
"metrics" => build_metrics_list,
"resources" => resources,
"certname" => host,
"puppet_version" => puppet_version,
"report_format" => report_format,
"configuration_version" => configuration_version.to_s,
"producer_timestamp" => Puppet::Util::Puppetdb.to_wire_time(Time.now),
"start_time" => Puppet::Util::Puppetdb.to_wire_time(time),
"end_time" => Puppet::Util::Puppetdb.to_wire_time(time + run_duration),
"environment" => environment,
"transaction_uuid" => transaction_uuid,
"status" => status,
"noop" => is_noop,
"logs" => build_logs_list,
"metrics" => build_metrics_list,
"resources" => resources,
"catalog_uuid" => defaulted_catalog_uuid,
"code_id" => defaulted_code_id,
"cached_catalog_status" => defaulted_cached_catalog_status,
}
end
end
......
......@@ -6,6 +6,8 @@ require 'puppet/indirector/catalog/puppetdb'
require 'puppet/util/puppetdb'
require 'puppet/util/puppetdb/command_names'
require 'json'
require 'puppet/resource/catalog'
require 'puppet/version'
describe Puppet::Resource::Catalog::Puppetdb do
before :each do
......@@ -84,16 +86,19 @@ describe Puppet::Resource::Catalog::Puppetdb do
end
describe "#add_catalog_uuid_if_missing" do
it "should add the given default if missing" do
result = subject.add_catalog_uuid_if_missing(catalog_data_hash, 'abc123')
result['catalog_uuid'].should == 'abc123'
end
it "should not add change the catalog_uuid if one was present" do
# TODO FIXME PLEASE I need a real test for a different version of Puppet
result = subject.add_catalog_uuid_if_missing(catalog_data_hash, 'abc123')
result['catalog_uuid'].should == 'abc123'
end
it "should not change the catalog_uuid if one was present" do
# Puppet v4.3.2 doesn't actually have catalog_uuid, it will be 4.3.3
# which has the change but until they bump the development version we
# need this extra `and` clause
if (Gem::Version.new(Puppet.version) >= Gem::Version.new('4.3.2') and
catalog_data_hash.has_key?('catalog_uuid')) then
result = subject.add_catalog_uuid_if_missing(catalog_data_hash, 'abc123')
result['catalog_uuid'].should_not == 'abc123'
else
result = subject.add_catalog_uuid_if_missing(catalog_data_hash, 'abc123')
result['catalog_uuid'].should == 'abc123'
end
end
end
describe "#add_code_id_if_missing" do
......
......@@ -71,8 +71,42 @@ describe processor do
it "should include the transaction uuid or nil" do
subject.transaction_uuid = 'abc123'
if defined?(subject.catalog_uuid) then
subject.catalog_uuid = 'bde432'
end
result = subject.send(:report_to_hash)
result["transaction_uuid"].should == 'abc123'
# This won't be defined on < Puppet 4.3.3
if defined?(subject.catalog_uuid) then
result["catalog_uuid"].should == 'bde432'
else
result["catalog_uuid"].should == 'abc123'
end
end
it "should include the code_id or nil" do
if defined?(subject.code_id) then
subject.code_id = 'bde432'
end
result = subject.send(:report_to_hash)
if defined?(subject.code_id) then
result["code_id"].should == 'bde432'
else
result["code_id"].should == nil
end
end
it "should include the cached_catalog_status or nil" do
if defined?(subject.cached_catalog_status) then
subject.cached_catalog_status = 'not_used'
end
result = subject.send(:report_to_hash)
if defined?(subject.cached_catalog_status) then
result["cached_catalog_status"].should == 'not_used'
else
result["cached_catalog_status"].should == nil
end
end
context "start/end time" do
......
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