Skip to content

Commit

Permalink
Merge pull request #2875 from justinstoller/thats_rich
Browse files Browse the repository at this point in the history
(PE-38948) Respect rich_data in compileCatalog
  • Loading branch information
mcdonaldseanp committed Sep 11, 2024
2 parents 6e2f08a + b1a7ce5 commit bbec082
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/ruby/puppetserver-lib/puppet/server/master.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,19 @@ def handleRequest(request)
end

def compileCatalog(request_data)
Puppet.override(lookup_key_recorder: create_recorder) do
Puppet.override(
lookup_key_recorder: create_recorder,
# rich_data was moved to the context because determining if it should be true, in
# some code paths, needs to inspect the global settings, per-environment settings,
# and the request's content-type. For the `handleRequest` endpoint this logic is
# handled by the indirector. We need to provide some value, as the default in
# Puppet's context is, as of Puppet 8.9.0, hardcoded to be false, which will cause
# any rich_data in a catalog to fail via this endpoint (but likely not via the
# indirected endpoint). So here we set it to the global setting value, as the
# per-environment settings logic is fairly complicated to implement and have never
# gotten user facing documentation anyways.
rich_data: Puppet[:rich_data]
) do
@catalog_compiler.compile(convert_java_args_to_ruby(request_data))
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,29 @@
(finally
(jruby-testutils/return-instance jruby-service jruby-instance :facts-upload-endpoint-test)))))))

(deftest ^:integration rich-data-is-honored
(let [tmpdir (fs/tmpdir)]
(fs/mkdir (str tmpdir "/yaml"))
(bootstrap-testutils/with-puppetserver-running
app
{:jruby-puppet {:gem-path gem-path
:max-active-instances 1
:server-code-dir test-resources-code-dir
:server-conf-dir master-service-test-runtime-dir
:server-var-dir (fs/tmpdir)}}
(let [jruby-service (tk-app/get-service app :JRubyPuppetService)
jruby-instance (jruby-testutils/borrow-instance jruby-service :rich-data-test)]
(try
(let [container (:scripting-container jruby-instance)
puppet-instance (:jruby-puppet jruby-instance)
catalog-compiler (.runScriptlet container "o = Object.new; o.define_singleton_method(:compile) {|args| Puppet.lookup(:rich_data) }; o")
_ (.callMethodWithArgArray container puppet-instance "instance_variable_set" (into-array Object ["@catalog_compiler" catalog-compiler]) Object)
rich-data (.callMethodWithArgArray container puppet-instance "compileCatalog" (into-array Object [{}]) Boolean)]
(testing "rich_data is true by default"
(is (= true rich-data))))
(finally
(jruby-testutils/return-instance jruby-service jruby-instance :rich-data-test)))))))

(deftest ^:integration v4-queue-limit
(bootstrap-testutils/with-puppetserver-running
app
Expand Down

0 comments on commit bbec082

Please sign in to comment.