diff --git a/lib/puppet.rb b/lib/puppet.rb index 484fda4c4ef..d8a0ec00114 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -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 diff --git a/lib/puppet/application/resource.rb b/lib/puppet/application/resource.rb index 0c39a6c1aae..8a7d97bcbe3 100644 --- a/lib/puppet/application/resource.rb +++ b/lib/puppet/application/resource.rb @@ -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 end.inject(:merge!) text = YAML.dump(type.downcase => data) else diff --git a/spec/integration/application/apply_spec.rb b/spec/integration/application/apply_spec.rb index 9f159dbec70..adea37ed406 100644 --- a/spec/integration/application/apply_spec.rb +++ b/spec/integration/application/apply_spec.rb @@ -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)] diff --git a/spec/unit/application/resource_spec.rb b/spec/unit/application/resource_spec.rb index 901fb4a9bb0..ecc82f60075 100644 --- a/spec/unit/application/resource_spec.rb +++ b/spec/unit/application/resource_spec.rb @@ -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 diff --git a/spec/unit/resource/catalog_spec.rb b/spec/unit/resource/catalog_spec.rb index 9c462f72d25..7abca7e7b58 100644 --- a/spec/unit/resource/catalog_spec.rb +++ b/spec/unit/resource/catalog_spec.rb @@ -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 diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index c527358e3f6..28d634991a3 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -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 + 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) + end + end + describe "when converting from json" do before do @data = {