Skip to content

Commit cdc389b

Browse files
committed
(maint) Allow not applying settings catalog on startup
On initialization of a JRuby instance, Puppet will compile and apply a catalog containing resources for the configured directories specified in the appropriate settings sections. The goal of this is to ensure any directories Puppet requires exist. In practice this should be managed by our packages. Attempting to apply a catalog every time a JRuby instance is unnecessary, slow, and causes race conditions when attempting to instantiate JRuby instances in parallel. Puppet has a setting "settings_catalog" that controls this behavior. This PR addresses issues that arise when we set "settings_catalog" to `false`: 1. In code the process of compiling a settings catalog brings most of Puppet's ruby code into scope. When not compiling a settings catalog we must actually declare our dependencies. 2. The $yamldir/facts directory is not created by packages despite being used by default.
1 parent e7b9b2b commit cdc389b

File tree

9 files changed

+58
-90
lines changed

9 files changed

+58
-90
lines changed

dev-resources/puppetlabs/services/master/master_service_test/ca_files_test/puppet.conf

Lines changed: 0 additions & 20 deletions
This file was deleted.

dev/puppetserver.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ jruby-puppet: {
8989
# For testing running requests through a single JRuby instance. DO NOT ENABLE unless
9090
# explicitly testing this functionality.
9191
# multithreaded: true
92+
93+
# (optional) When (re)filling a pool one instance will be initialized first, then
94+
# the remaining instances will be initialized at the specified level of concurrency.
95+
# Set to one for the previous serialized behavior. Default is three.
96+
# instance-creation-concurrency: 1
9297
}
9398

9499
# Settings related to HTTP client requests made by Puppet Server.

project.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@
100100
:puppet-platform-version 8
101101
:java-args ~(str "-Xms2g -Xmx2g "
102102
"-Djruby.logger.class=com.puppetlabs.jruby_utils.jruby.Slf4jLogger")
103-
:create-dirs ["/opt/puppetlabs/server/data/puppetserver/jars"]
103+
:create-dirs ["/opt/puppetlabs/server/data/puppetserver/jars"
104+
"/opt/puppetlabs/server/data/puppetserver/yaml"]
104105
:repo-target "puppet8"
105106
:nonfinal-repo-target "puppet8-nightly"
106107
:bootstrap-source :services-d

spec/puppet-server-lib/puppet/jvm/logging_spec.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55

66
describe Puppet::Server::Logging do
77
context 'when setting the log level' do
8-
before :each do
9-
Puppet::Server::PuppetConfig.initialize_puppet(puppet_config: {})
8+
it 'flush logging queue' do
9+
# The logger will queue any old log messages, creating a logging destination
10+
# will force the pending queue to be flushed to this logger. We don't care
11+
# about these messages so we discard the logger, but we do not want them to
12+
# interfere with the next tests.
13+
_, _ = Puppet::Server::Logging.capture_logs('debug') do; end
1014
end
1115

1216
it 'correctly filters messages' do

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'puppet/util/log'
2+
13
module Puppet
24
module Server
35
# Log to an array, just for testing.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'puppet'
2+
require 'puppet/util'
13
require 'puppet/server'
24
require 'java'
35

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'puppet'
2+
require 'puppet/util/log'
13
require 'puppet/server/log_collector'
24

35
module Puppet

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
require 'puppet/server'
22
require 'puppet/server/logger'
33
require 'puppet/server/http_client'
4+
require 'puppet/indirector/indirection'
5+
require 'puppet/file_serving/content'
6+
require 'puppet/file_serving/metadata'
7+
require 'puppet/file_bucket/file'
8+
require 'puppet/node'
9+
require 'puppet/application_support'
10+
require 'puppet/ssl/oids'
411

512
class Puppet::Server::PuppetConfig
613

@@ -88,6 +95,8 @@ def self.initialize_puppet(puppet_config:)
8895
Puppet.push_context(dummy_ssl_context)
8996
end
9097

98+
# We have no added support for setting "settings_catalog" to false in the puppet.conf.
99+
# We should default to not applying the settings catalog and remove this line in Puppet 9.
91100
Puppet.settings.use :main, :server, :ssl, :metrics
92101

93102
if Puppet::Indirector::Indirection.method_defined?(:set_global_setting)

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

Lines changed: 30 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -316,45 +316,6 @@
316316
(+ (:duration-millis requested-instance)
317317
(:time requested-instance))))))))))))))
318318

319-
(deftest ^:integration ca-files-test
320-
(testing "CA settings from puppet are honored and the CA
321-
files are created when the service starts up"
322-
(let [ca-files-test-runtime-dir (str master-service-test-runtime-dir
323-
"/ca-files-test")
324-
ca-files-test-puppet-conf (fs/file test-resources-path
325-
"ca_files_test/puppet.conf")]
326-
(fs/delete-dir ca-files-test-runtime-dir)
327-
(testutils/with-puppet-conf-files
328-
{"puppet.conf" ca-files-test-puppet-conf}
329-
ca-files-test-runtime-dir
330-
(logutils/with-test-logging
331-
(bootstrap-testutils/with-puppetserver-running
332-
app
333-
{:jruby-puppet {:gem-path gem-path
334-
:server-conf-dir ca-files-test-runtime-dir
335-
:max-active-instances 1}
336-
:webserver {:port 8081}}
337-
(let [jruby-service (tk-app/get-service app :JRubyPuppetService)]
338-
(jruby-service/with-jruby-puppet
339-
jruby-puppet jruby-service :ca-files-test
340-
(letfn [(test-path!
341-
[setting expected-path]
342-
(is (= (ks/absolute-path expected-path)
343-
(.getSetting jruby-puppet setting)))
344-
(is (fs/exists? (ks/absolute-path expected-path))))]
345-
346-
(test-path! "capub" (str ca-files-test-runtime-dir "/ca/ca_pub.pem"))
347-
(test-path! "cakey" (str ca-files-test-runtime-dir "/ca/ca_key.pem"))
348-
(test-path! "cacert" (str ca-files-test-runtime-dir "/ca/ca_crt.pem"))
349-
(test-path! "localcacert" (str ca-files-test-runtime-dir "/ca/ca.pem"))
350-
(test-path! "cacrl" (str ca-files-test-runtime-dir "/ca/ca_crl.pem"))
351-
(test-path! "hostcrl" (str ca-files-test-runtime-dir "/ca/crl.pem"))
352-
(test-path! "hostpubkey" (str ca-files-test-runtime-dir "/public_keys/localhost.pem"))
353-
(test-path! "hostprivkey" (str ca-files-test-runtime-dir "/private_keys/localhost.pem"))
354-
(test-path! "hostcert" (str ca-files-test-runtime-dir "/certs/localhost.pem"))
355-
(test-path! "serial" (str ca-files-test-runtime-dir "/certs/serial"))
356-
(test-path! "cert_inventory" (str ca-files-test-runtime-dir "/inventory.txt")))))))))))
357-
358319
(def graphite-enabled-config
359320
{:metrics {:server-id "localhost"
360321
:reporters {:graphite {:update-interval-seconds 5000
@@ -729,34 +690,36 @@
729690
(is (= 404 (:status resp)))))))
730691

731692
(deftest ^:integration facts-upload-api
732-
(bootstrap-testutils/with-puppetserver-running
733-
app
734-
{:jruby-puppet {:gem-path gem-path
735-
:max-active-instances 2 ; we need 2 jruby-instances since processing the upload uses an instance
736-
:server-code-dir test-resources-code-dir
737-
:server-conf-dir master-service-test-runtime-dir
738-
:server-var-dir (fs/tmpdir)}}
739-
(let [jruby-service (tk-app/get-service app :JRubyPuppetService)
740-
jruby-instance (jruby-testutils/borrow-instance jruby-service :facts-upload-endpoint-test)
741-
container (:scripting-container jruby-instance)]
742-
(try
743-
(let [facts (.runScriptlet container "facts = Puppet::Node::Facts.new('puppet.node.test')
744-
facts.values['foo'] = 'bar'
745-
facts.to_json")
746-
response (http-put "/puppet/v3/facts/puppet.node.test?environment=production" facts)]
747-
748-
(testing "Puppet Server responds to PUT requests for /puppet/v3/facts"
749-
(is (= 200 (:status response))))
750-
751-
(testing "Puppet Server saves facts to the configured facts terminus"
752-
;; Ensure the test is configured properly
753-
(is (= "yaml" (.runScriptlet container "Puppet::Node::Facts.indirection.terminus_class")))
754-
(let [stored-facts (-> (.runScriptlet container "facts = Puppet::Node::Facts.indirection.find('puppet.node.test')
755-
(facts.nil? ? {} : facts).to_json")
756-
(json/parse-string))]
757-
(is (= "bar" (get-in stored-facts ["values" "foo"]))))))
758-
(finally
759-
(jruby-testutils/return-instance jruby-service jruby-instance :facts-upload-endpoint-test))))))
693+
(let [tmpdir (fs/tmpdir)]
694+
(fs/mkdir (str tmpdir "/yaml"))
695+
(bootstrap-testutils/with-puppetserver-running
696+
app
697+
{:jruby-puppet {:gem-path gem-path
698+
:max-active-instances 2 ; we need 2 jruby-instances since processing the upload uses an instance
699+
:server-code-dir test-resources-code-dir
700+
:server-conf-dir master-service-test-runtime-dir
701+
:server-var-dir (fs/tmpdir)}}
702+
(let [jruby-service (tk-app/get-service app :JRubyPuppetService)
703+
jruby-instance (jruby-testutils/borrow-instance jruby-service :facts-upload-endpoint-test)
704+
container (:scripting-container jruby-instance)]
705+
(try
706+
(let [facts (.runScriptlet container "facts = Puppet::Node::Facts.new('puppet.node.test')
707+
facts.values['foo'] = 'bar'
708+
facts.to_json")
709+
response (http-put "/puppet/v3/facts/puppet.node.test?environment=production" facts)]
710+
711+
(testing "Puppet Server responds to PUT requests for /puppet/v3/facts"
712+
(is (= 200 (:status response))))
713+
714+
(testing "Puppet Server saves facts to the configured facts terminus"
715+
;; Ensure the test is configured properly
716+
(is (= "yaml" (.runScriptlet container "Puppet::Node::Facts.indirection.terminus_class")))
717+
(let [stored-facts (-> (.runScriptlet container "facts = Puppet::Node::Facts.indirection.find('puppet.node.test')
718+
(facts.nil? ? {} : facts).to_json")
719+
(json/parse-string))]
720+
(is (= "bar" (get-in stored-facts ["values" "foo"]))))))
721+
(finally
722+
(jruby-testutils/return-instance jruby-service jruby-instance :facts-upload-endpoint-test)))))))
760723

761724
(deftest ^:integration v4-queue-limit
762725
(bootstrap-testutils/with-puppetserver-running

0 commit comments

Comments
 (0)