Skip to content

Commit ae55600

Browse files
committed
[#9470] Respect environment/settings in base context rich_data value
1 parent 7739378 commit ae55600

File tree

6 files changed

+41
-6
lines changed

6 files changed

+41
-6
lines changed

lib/puppet.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def self.base_context(settings)
237237
:ssl_context => proc { Puppet.runtime[:http].default_ssl_context },
238238
:http_session => proc { Puppet.runtime[:http].create_session },
239239
:plugins => proc { Puppet::Plugins::Configuration.load_plugins },
240-
:rich_data => false
240+
:rich_data => Puppet[:rich_data]
241241
}
242242
end
243243

lib/puppet/application/resource.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ def main
155155

156156
if options[:to_yaml]
157157
data = resources.map do |resource|
158-
resource.prune_parameters(:parameters_to_include => @extra_params).to_hiera_hash
158+
Puppet.override(rich_data: false) do
159+
resource.prune_parameters(:parameters_to_include => @extra_params).to_hiera_hash
160+
end
159161
end.inject(:merge!)
160162
text = YAML.dump(type.downcase => data)
161163
else

spec/integration/application/apply_spec.rb

+6
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,12 @@ def bogus()
447447
Puppet[:strict] = :warning
448448
end
449449

450+
around :each do |test|
451+
Puppet.override(rich_data: false) do
452+
test.run
453+
end
454+
end
455+
450456
it 'will notify a string that is the result of Regexp#inspect (from Runtime3xConverter)' do
451457
catalog = compile_to_catalog(execute, node)
452458
apply.command_line.args = ['--catalog', file_containing('manifest', catalog.to_json)]

spec/unit/application/resource_spec.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,13 @@ def string
170170
expect { @resource_app.main }.not_to raise_error
171171
end
172172

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

180182
it "should ensure all values to be printed are in the external encoding" do

spec/unit/resource/catalog_spec.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -965,10 +965,15 @@ class {'multi_param_class':
965965

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

971+
around(:each) do |test|
972+
Puppet.override(rich_data: false) do
973+
test.run
974+
end
975+
end
976+
972977
let(:catalog_w_regexp) { compile_to_catalog("notify {'foo': message => /[a-z]+/ }") }
973978

974979
it 'should not generate rich value hash for parameter values that are not Data' do

spec/unit/resource_spec.rb

+20
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,26 @@ def inject_and_set_defaults(resource, scope)
906906
# Note: to_stringified_spec.rb has tests for all other data types
907907
end
908908

909+
describe 'when serializing resources' do
910+
require 'puppet_spec/compiler'
911+
include PuppetSpec::Compiler
912+
913+
it 'should do something' do
914+
resource = compile_to_catalog('notify {"foo": message => Deferred("func", ["a", "b", "c"])}')
915+
916+
# This should be true by default
917+
if Puppet[:rich_data]
918+
expect(resource.to_data_hash.class).to be(Hash)
919+
end
920+
921+
expect {
922+
Puppet.override(rich_data: false) do
923+
resource.to_data_hash
924+
end
925+
}.to raise_error(Puppet::PreformattedError)
926+
end
927+
end
928+
909929
describe "when converting from json" do
910930
before do
911931
@data = {

0 commit comments

Comments
 (0)