Commit 60e8ac81 authored by Molly Waggett's avatar Molly Waggett

(PE-15612) Add "producer" to terminus reports/catalogs/factsets

This commit adds "producer" key to reports, catalogs, and factsets
in the terminus.
parent ff68ee71
require 'json'
puppetdb_query_url = "http://localhost:8080/pdb/query"
test_name "validate producer in agent report" do
step "setup a test manifest for the master and perform agent runs" do
manifest = <<-MANIFEST
node default {
@@notify { "exported_resource": }
notify { "non_exported_resource": }
}
MANIFEST
run_agents_with_new_site_pp(master, manifest)
end
# Wait until all the commands have been processed
sleep_until_queue_empty database
# Query for all of the reports, but we only care about there being at least one
result = on database, %Q|curl -G #{puppetdb_query_url}/v4/reports --data 'query=["=",%20"producer",%20"#{master.node_name}"]'|
report = JSON.parse(result.stdout)[0]
assert_not_nil(report, "Should have found at least one report with producer equal to #{master.node_name}")
producer = report['producer']
assert_equal(producer, master.node_name, 'Producer should equal the master certname')
end
......@@ -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, 8)
submit_command(request.key, catalog, CommandReplaceCatalog, 9)
end
end
......@@ -53,6 +53,7 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
add_transaction_uuid(data, extra_request_data[:transaction_uuid])
add_environment(data, extra_request_data[:environment])
add_producer_timestamp(data, extra_request_data[:producer_timestamp])
add_producer(data, Puppet[:node_name_value])
data
end
......@@ -142,6 +143,18 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
hash
end
# Include producer in hash, returning the complete hash.
#
# @param hash [Hash] original data hash
# @param producer [String or nil] producer
# @return [Hash] returns original hash augmented with producer
# @api private
def add_producer(hash, producer)
hash['producer'] = producer
hash
end
# Version is an integer (time since epoch in millis). The wire
# format specifies version should be a string
#
......
......@@ -31,10 +31,11 @@ class Puppet::Node::Facts::Puppetdb < Puppet::Indirector::REST
# legacy storeconfigs.
"environment" => request.options[:environment] || request.environment.to_s,
"producer_timestamp" => request.options[:producer_timestamp] || Time.now.iso8601(5),
"producer" => Puppet[:node_name_value]
}
end
submit_command(request.key, payload, CommandReplaceFacts, 4)
submit_command(request.key, payload, CommandReplaceFacts, 5)
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, 7)
submit_command(self.host, report_to_hash, CommandStoreReport, 8)
end
nil
......@@ -62,6 +62,7 @@ Puppet::Reports.register_report(:puppetdb) do
"catalog_uuid" => defaulted_catalog_uuid,
"code_id" => defaulted_code_id,
"cached_catalog_status" => defaulted_cached_catalog_status,
"producer" => Puppet[:node_name_value]
}
end
end
......
......@@ -109,6 +109,14 @@ describe Puppet::Resource::Catalog::Puppetdb do
end
end
describe "#add_producer" do
it "should add the producer key" do
result = subject.add_producer(catalog_data_hash, "foo")
result.has_key?('producer').should be_truthy
result['producer'].should == "foo"
end
end
describe "#add_parameters_if_missing" do
it "should create an empty parameters hash if none exists" do
result = subject.add_parameters_if_missing(catalog_data_hash)
......@@ -673,7 +681,8 @@ describe Puppet::Resource::Catalog::Puppetdb do
result = subject.munge_catalog(catalog)
result.keys.should =~ ['certname', 'version', 'edges', 'resources',
'transaction_uuid', 'environment', 'producer_timestamp', "code_id", "catalog_uuid"]
'transaction_uuid', 'environment', 'producer_timestamp', "code_id",
"catalog_uuid", "producer"]
end
end
end
......
......@@ -42,12 +42,14 @@ describe Puppet::Node::Facts::Puppetdb do
trusted_data = {"foo" => "foobar", "certname" => "testing_posting"}
subject.stubs(:get_trusted_info).returns trusted_data
Puppet[:node_name_value] = "mom"
payload = {
"certname" => facts.name,
"values" => facts.values.merge({"trusted" => trusted_data}),
"environment" => "my_environment",
"producer_timestamp" => "a test",
"producer" => "mom"
}.to_pson
http.expects(:post).with do |uri, body, headers|
......
......@@ -97,6 +97,12 @@ describe processor do
end
end
it "should include the producer or nil" do
Puppet[:node_name_value] = "foo"
result = subject.send(:report_to_hash)
result["producer"].should == "foo"
end
it "should include the cached_catalog_status or nil" do
if defined?(subject.cached_catalog_status) then
subject.cached_catalog_status = 'not_used'
......
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