Skip to content

Commit

Permalink
(PUP-5120) Add supported_checksum_types setting
Browse files Browse the repository at this point in the history
Adds a `supported_checksum_types` setting for reporting supported
checksum types to a master for use with file resources in a static
catalog. The `checksum_type` catalog request query parameter will be set
to a dot-separated munging of the list specified in
`supported_checksum_types`.
  • Loading branch information
Michael Smith committed Jan 27, 2016
1 parent 1ecacd2 commit c9161d7
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 9 deletions.
5 changes: 3 additions & 2 deletions api/docs/http_catalog.md
Expand Up @@ -40,7 +40,8 @@ doubly-escaped (it should just be singly-escaped). To keep backward compatibili
escaping is still used/supported.
- `transaction_uuid`: a transaction uuid identifying the entire transaction (shows up in the report as well)
- `static_catalog`: a boolean requesting a static catalog if available; should always be `true`
- `checksum_type`: a checksum type supported by the agent, for use in file resources of a static catalog.
- `checksum_type`: a dot-separated list of checksum types supported by the agent, for use in file resources of a static
catalog. The order signifies preference, highest first.

An optional parameter can be provided to the POST or GET to notify a node classifier that the client requested a specific
environment, which might differ from what the client believes is its current environment:
Expand All @@ -53,7 +54,7 @@ environment, which might differ from what the client believes is its current env

POST /puppet/v3/catalog/elmo.mydomain.com

environment=env&configured_environment=canary_env&facts_format=pson&facts=%7B%22name%22%3A%22elmo.mydomain.com%22%2C%22values%22%3A%7B%22architecture%22%3A%22x86_64%22%7D&transaction_uuid=aff261a2-1a34-4647-8c20-ff662ec11c4c&static_catalog=true&checksum_type=md5
environment=env&configured_environment=canary_env&facts_format=pson&facts=%7B%22name%22%3A%22elmo.mydomain.com%22%2C%22values%22%3A%7B%22architecture%22%3A%22x86_64%22%7D&transaction_uuid=aff261a2-1a34-4647-8c20-ff662ec11c4c&static_catalog=true&checksum_type=md5.sha256

HTTP 200 OK
Content-Type: text/pson
Expand Down
7 changes: 5 additions & 2 deletions lib/puppet/configurer.rb
Expand Up @@ -51,7 +51,7 @@ def initialize(factory = Puppet::Configurer::DownloaderFactory.new)
@environment = Puppet[:environment]
@transaction_uuid = SecureRandom.uuid
@static_catalog = true
@checksum_type = Puppet[:digest_algorithm]
@checksum_type = Puppet[:supported_checksum_types]
@handler = Puppet::Configurer::PluginHandler.new(factory)
end

Expand Down Expand Up @@ -115,7 +115,10 @@ def prepare_and_retrieve_catalog(options, query_options)
options[:report].host = Puppet[:node_name_value]
query_options[:transaction_uuid] = @transaction_uuid
query_options[:static_catalog] = @static_catalog
query_options[:checksum_type] = @checksum_type

# Query params don't enforce ordered evaluation, so munge this list into a
# dot-separated string.
query_options[:checksum_type] = @checksum_type.join('.')

unless catalog = (options.delete(:catalog) || retrieve_catalog(query_options))
Puppet.err "Could not retrieve catalog; skipping run"
Expand Down
14 changes: 14 additions & 0 deletions lib/puppet/defaults.rb
Expand Up @@ -786,6 +786,20 @@ def self.default_diffargs
:values => ["md5", "sha256"],
:desc => 'Which digest algorithm to use for file resources and the filebucket.
Valid values are md5, sha256. Default is md5.',
},
:supported_checksum_types => {
:default => ['md5', 'sha256'],
:type => :array,
:desc => 'Checksum types supported by this agent for use in file resources of a static
catalog. Valid types are md5, md5lite, sha256, sha256lite, sha1, sha1lite, mtime, ctime.',
:hook => proc do |value|
values = munge(value)
valid = ['md5', 'md5lite', 'sha256', 'sha256lite', 'sha1', 'sha1lite', 'mtime', 'ctime']
invalid = values.reject {|alg| valid.include?(alg)}
if not invalid.empty?
raise ArgumentError, "Unrecognized checksum types #{invalid} are not supported. Valid values are #{valid}."
end
end
}
)

Expand Down
11 changes: 6 additions & 5 deletions spec/unit/configurer_spec.rb
Expand Up @@ -388,21 +388,22 @@
@agent.run
end

it "sets the checksum_type query param to the default digest_algorithm in a catalog request" do
Puppet::Resource::Catalog.indirection.expects(:find).with(anything, has_entries(:checksum_type => 'md5'))
it "sets the checksum_type query param to the default supported_checksum_types in a catalog request" do
Puppet::Resource::Catalog.indirection.expects(:find).with(anything,
has_entries(:checksum_type => 'md5.sha256'))
@agent.run
end

it "sets the checksum_type query param to the digest_algorithm setting in a catalog request" do
it "sets the checksum_type query param to the supported_checksum_types setting in a catalog request" do
# Regenerate the agent to pick up the new setting
Puppet[:digest_algorithm] = 'sha256'
Puppet[:supported_checksum_types] = ['sha256']
@agent = Puppet::Configurer.new
@agent.stubs(:init_storage)
@agent.stubs(:download_plugins)
@agent.stubs(:send_report)
@agent.stubs(:save_last_run_summary)

Puppet::Resource::Catalog.indirection.expects(:find).with(anything, has_entries(:checksum_type => Puppet[:digest_algorithm]))
Puppet::Resource::Catalog.indirection.expects(:find).with(anything, has_entries(:checksum_type => 'sha256'))
@agent.run
end

Expand Down
15 changes: 15 additions & 0 deletions spec/unit/defaults_spec.rb
Expand Up @@ -71,4 +71,19 @@
end

end

describe 'supported_checksum_types' do
it 'should default to md5,sha256' do
expect(Puppet.settings[:supported_checksum_types]).to eq(['md5', 'sha256'])
end

it 'should raise an error on an unsupported checksum type' do
expect { Puppet.settings[:supported_checksum_types] = ['md5', 'foo'] }.to raise_exception ArgumentError, 'Unrecognized checksum types ["foo"] are not supported. Valid values are ["md5", "md5lite", "sha256", "sha256lite", "sha1", "sha1lite", "mtime", "ctime"].'
end

it 'should not raise an error on setting a valid list of checksum types' do
Puppet.settings[:supported_checksum_types] = ['sha256', 'md5lite', 'mtime']
expect(Puppet.settings[:supported_checksum_types]).to eq(['sha256', 'md5lite', 'mtime'])
end
end
end
6 changes: 6 additions & 0 deletions spec/unit/type/file/checksum_spec.rb
Expand Up @@ -76,4 +76,10 @@
expect(sum).to eq("something")
end
end

it 'should use values allowed by the supported_checksum_types setting' do
values = checksum.value_collection.values.reject {|v| v == :none}.map {|v| v.to_s}
Puppet.settings[:supported_checksum_types] = values
expect(Puppet.settings[:supported_checksum_types]).to eq(values)
end
end

0 comments on commit c9161d7

Please sign in to comment.