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

(PDB-2126) Add catalog_uuid (and fix code_id) for catalog in terminus

This commit fixes the handling of code_id and adds handling for
catalog_uuid in the PuppetDB terminus so that we now get both from the
Puppet catalog and send both on the wire to PuppetDB in a new command
version (v8).
parent 445c17fb
......@@ -24,7 +24,6 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
:transaction_uuid => request.options[:transaction_uuid],
:environment => request.environment.to_s,
:producer_timestamp => request.options[:producer_timestamp] || Time.now.iso8601(5),
:code_id => request.options[:code_id],
}
end
......@@ -39,6 +38,8 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
catalog.to_data_hash
end
add_code_id_if_missing(data)
add_catalog_uuid_if_missing(data, extra_request_data[:transaction_uuid])
add_parameters_if_missing(data)
add_namevar_aliases(data, catalog)
stringify_titles(data)
......@@ -47,12 +48,11 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
sort_unordered_metaparams(data)
munge_edges(data)
synthesize_edges(data, catalog)
change_name_to_certname(data)
filter_keys(data)
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])
change_name_to_certname(data)
add_code_id(data, extra_request_data[:code_id])
data
end
......@@ -119,11 +119,22 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
# Include code_id in hash, returning the complete hash.
#
# @param hash [Hash] original data hash
# @param code_id [String] code_id
# @return [Hash] returns original hash augmented with transaction_uuid
# @return [Hash] returns original hash with a gaurunteed code_id key
# @api private
def add_code_id_if_missing(hash)
hash['code_id'] = hash['code_id']
hash
end
# Include code_id in hash, returning the complete hash.
#
# @param hash [Hash] original data hash
# @param default [String] default catalog_uuid to use if hash doesn't have one
# @return [Hash] returns original hash with a gaurunteed catalog_uuid key/value
# @api private
def add_code_id(hash, code_id)
hash['code_id'] = code_id
def add_catalog_uuid_if_missing(hash, default)
hash['catalog_uuid'] = hash['catalog_uuid'] || default
hash
end
......@@ -380,7 +391,12 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
profile("Filter extraneous keys from the catalog",
[:puppetdb, :keys, :filter_extraneous]) do
hash.delete_if do |k,v|
! ['name', 'version', 'edges', 'resources'].include?(k)
! ['certname',
'version',
'edges',
'resources',
'code_id',
'catalog_uuid'].include?(k)
end
end
end
......
......@@ -22,7 +22,6 @@ describe Puppet::Resource::Catalog::Puppetdb do
cat
end
let(:options) {{
:code_id => 'my_git_sha1',
:transaction_uuid => 'abcdefg',
:environment => 'my_environment',
:producer_timestamp => "a test",
......@@ -84,6 +83,27 @@ describe Puppet::Resource::Catalog::Puppetdb do
end
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
end
describe "#add_code_id_if_missing" do
it "should add the code_id key" do
result = subject.add_code_id_if_missing(catalog_data_hash)
result.has_key?('code_id').should be_truthy
result['code_id'].should be_nil
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)
......@@ -648,7 +668,7 @@ 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"]
'transaction_uuid', 'environment', 'producer_timestamp', "code_id", "catalog_uuid"]
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