Skip to content

Commit b1a7ce5

Browse files
committed
(PE-38948) Respect rich_data in compileCatalog
Previously, when using the compileCatalog method of Puppet::Server::Master compilation would fail to serialize rich data. This occurred because during serialization we introspect the Puppet.context for the rich_data value (the setting itself defaults to true & and strict now defaults to error, throwing an error when we encounter an object that requires rich_data to serialize). Normal catalog compilation works because the value of rich_data in the Puppet.context is overridden by the caller of the serialization code for indirected routes, using whatever is set in the environment and if unset in the environment then falling back to the actually rich_data setting. In the compileCatalog method however we do not use the indirected routes for serialization, instead calling `to_data_hash` on the catalog and serializing that ourselves (we explicitly only support JSON via that endpoint). This means the value in the Puppet.context is the default value which at the present is `false` regardless of what the user has configured (or our own settings defaults). This commit attempts to fix this by overriding the Puppet.context's rich_data value with the Puppet setting for rich_data. Which now defaults to true and will honor whatever the user puts in their puppet.conf. This however does not support rich_data per environment. I believe the optimal point to override rich_data is at the overall compileCatalog level but we do not have the "current" environment at that point, neccessitating a much larger rewrite of the compileCatalog function to work. The fact that you can even set rich_data in the environment.conf at this time is an undocumented feature, which leads me to believe a larger rewrite of the compileCatalog function is not a good investment.
1 parent 99684b5 commit b1a7ce5

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/ruby/puppetserver-lib/puppet/server/master.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,19 @@ def handleRequest(request)
9797
end
9898

9999
def compileCatalog(request_data)
100-
Puppet.override(lookup_key_recorder: create_recorder) do
100+
Puppet.override(
101+
lookup_key_recorder: create_recorder,
102+
# rich_data was moved to the context because determining if it should be true, in
103+
# some code paths, needs to inspect the global settings, per-environment settings,
104+
# and the request's content-type. For the `handleRequest` endpoint this logic is
105+
# handled by the indirector. We need to provide some value, as the default in
106+
# Puppet's context is, as of Puppet 8.9.0, hardcoded to be false, which will cause
107+
# any rich_data in a catalog to fail via this endpoint (but likely not via the
108+
# indirected endpoint). So here we set it to the global setting value, as the
109+
# per-environment settings logic is fairly complicated to implement and have never
110+
# gotten user facing documentation anyways.
111+
rich_data: Puppet[:rich_data]
112+
) do
101113
@catalog_compiler.compile(convert_java_args_to_ruby(request_data))
102114
end
103115
end

test/integration/puppetlabs/services/master/master_service_test.clj

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,29 @@
724724
(finally
725725
(jruby-testutils/return-instance jruby-service jruby-instance :facts-upload-endpoint-test)))))))
726726

727+
(deftest ^:integration rich-data-is-honored
728+
(let [tmpdir (fs/tmpdir)]
729+
(fs/mkdir (str tmpdir "/yaml"))
730+
(bootstrap-testutils/with-puppetserver-running
731+
app
732+
{:jruby-puppet {:gem-path gem-path
733+
:max-active-instances 1
734+
:server-code-dir test-resources-code-dir
735+
:server-conf-dir master-service-test-runtime-dir
736+
:server-var-dir (fs/tmpdir)}}
737+
(let [jruby-service (tk-app/get-service app :JRubyPuppetService)
738+
jruby-instance (jruby-testutils/borrow-instance jruby-service :rich-data-test)]
739+
(try
740+
(let [container (:scripting-container jruby-instance)
741+
puppet-instance (:jruby-puppet jruby-instance)
742+
catalog-compiler (.runScriptlet container "o = Object.new; o.define_singleton_method(:compile) {|args| Puppet.lookup(:rich_data) }; o")
743+
_ (.callMethodWithArgArray container puppet-instance "instance_variable_set" (into-array Object ["@catalog_compiler" catalog-compiler]) Object)
744+
rich-data (.callMethodWithArgArray container puppet-instance "compileCatalog" (into-array Object [{}]) Boolean)]
745+
(testing "rich_data is true by default"
746+
(is (= true rich-data))))
747+
(finally
748+
(jruby-testutils/return-instance jruby-service jruby-instance :rich-data-test)))))))
749+
727750
(deftest ^:integration v4-queue-limit
728751
(bootstrap-testutils/with-puppetserver-running
729752
app

0 commit comments

Comments
 (0)