Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PUP-12077) Respect rich_data setting in base context #9471

Merged
merged 5 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/puppet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def self.base_context(settings)
:ssl_context => proc { Puppet.runtime[:http].default_ssl_context },
:http_session => proc { Puppet.runtime[:http].create_session },
:plugins => proc { Puppet::Plugins::Configuration.load_plugins },
:rich_data => false
:rich_data => Puppet[:rich_data]
}
end

Expand Down
4 changes: 3 additions & 1 deletion lib/puppet/application/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ def main

if options[:to_yaml]
data = resources.map do |resource|
resource.prune_parameters(:parameters_to_include => @extra_params).to_hiera_hash
Puppet.override(rich_data: false) do
resource.prune_parameters(:parameters_to_include => @extra_params).to_hiera_hash
end
joshcooper marked this conversation as resolved.
Show resolved Hide resolved
end.inject(:merge!)
text = YAML.dump(type.downcase => data)
else
Expand Down
6 changes: 6 additions & 0 deletions spec/integration/application/apply_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,12 @@ def bogus()
Puppet[:strict] = :warning
end

around :each do |test|
Puppet.override(rich_data: false) do
test.run
end
end

it 'will notify a string that is the result of Regexp#inspect (from Runtime3xConverter)' do
catalog = compile_to_catalog(execute, node)
apply.command_line.args = ['--catalog', file_containing('manifest', catalog.to_json)]
Expand Down
8 changes: 5 additions & 3 deletions spec/unit/application/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,13 @@ def string
expect { @resource_app.main }.not_to raise_error
end

it "should raise an error when printing yaml by default" do
it "should raise an error when printing yaml if rich_data is off" do
@resource_app.options[:to_yaml] = true
allow(@resource_app.command_line).to receive(:args).and_return(['stringify', 'hello', 'ensure=present', 'string=asd'])
expect { @resource_app.main }.to raise_error( Puppet::PreformattedError,
/Stringify\[hello\]\['string'\] contains a Puppet::Util::Execution::ProcessOutput value. It will be converted to the String 'test'/)
Puppet.override(rich_data: false) do
expect { @resource_app.main }.to raise_error( Puppet::PreformattedError,
/Stringify\[hello\]\['string'\] contains a Puppet::Util::Execution::ProcessOutput value. It will be converted to the String 'test'/)
end
end

it "should ensure all values to be printed are in the external encoding" do
Expand Down
7 changes: 6 additions & 1 deletion spec/unit/resource/catalog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -965,10 +965,15 @@ class {'multi_param_class':

context 'and rich_data is disabled' do
before(:each) do
Puppet[:rich_data] = false
Puppet[:strict] = :warning # do not want to stub out behavior in tests
end

around(:each) do |test|
Puppet.override(rich_data: false) do
test.run
end
end

let(:catalog_w_regexp) { compile_to_catalog("notify {'foo': message => /[a-z]+/ }") }

it 'should not generate rich value hash for parameter values that are not Data' do
Expand Down
20 changes: 20 additions & 0 deletions spec/unit/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,26 @@ def inject_and_set_defaults(resource, scope)
# Note: to_stringified_spec.rb has tests for all other data types
end

describe 'when serializing resources' do
require 'puppet_spec/compiler'
include PuppetSpec::Compiler

it 'should do something' do
joshcooper marked this conversation as resolved.
Show resolved Hide resolved
resource = compile_to_catalog('notify {"foo": message => Deferred("func", ["a", "b", "c"])}')

# This should be true by default
if Puppet[:rich_data]
expect(resource.to_data_hash.class).to be(Hash)
end

expect {
Puppet.override(rich_data: false) do
resource.to_data_hash
end
}.to raise_error(Puppet::PreformattedError)
joshcooper marked this conversation as resolved.
Show resolved Hide resolved
end
end

describe "when converting from json" do
before do
@data = {
Expand Down