Skip to content

Commit 6e66cdb

Browse files
authored
Merge pull request #7983 from joshcooper/64x_master_mergeup
(maint) Merge 6.4.x to master
2 parents 2b84935 + b11ecb9 commit 6e66cdb

File tree

9 files changed

+146
-57
lines changed

9 files changed

+146
-57
lines changed

lib/puppet.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
require 'puppet/external/pson/version'
2323
require 'puppet/external/pson/pure'
2424
require 'puppet/gettext/config'
25+
require 'puppet/defaults'
2526

2627

2728
#------------------------------------------------------------
@@ -95,6 +96,7 @@ def self.[](param)
9596

9697
# Store a new default value.
9798
def self.define_settings(section, hash)
99+
Puppet.deprecation_warning('The method Puppet.define_settings is deprecated and will be removed in a future release')
98100
@@settings.define_settings(section, hash)
99101
end
100102

@@ -129,8 +131,9 @@ def self.run_mode
129131
Puppet::Util::RunMode[@@settings.preferred_run_mode]
130132
end
131133

132-
# Load all of the settings.
133-
require 'puppet/defaults'
134+
# Modify the settings with defaults defined in `initialize_default_settings` method in puppet/defaults.rb. This can
135+
# be used in the initialization of new Puppet::Settings objects in the puppetserver project.
136+
Puppet.initialize_default_settings!(settings)
134137

135138
# Now that settings are loaded we have the code loaded to be able to issue
136139
# deprecation warnings. Warn if we're on a deprecated ruby version.

lib/puppet/defaults.rb

Lines changed: 66 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,30 @@ def self.default_vendormoduledir
6565

6666
AS_DURATION = %q{This setting can be a time interval in seconds (30 or 30s), minutes (30m), hours (6h), days (2d), or years (5y).}
6767

68-
define_settings(:main,
69-
:facterng => {
68+
# @api public
69+
# @param args [Puppet::Settings] the settings object to define default settings for
70+
# @return void
71+
def self.initialize_default_settings!(settings)
72+
settings.define_settings(:main,
73+
:facterng => {
7074
:default => false,
7175
:type => :boolean,
7276
:desc => 'Whether to enable a pre-Facter 4.0 release of Facter (distributed as
7377
the "facter-ng" gem). This is not necessary if Facter 3.x or later is installed.
7478
This setting is still experimental.',
7579
:hook => proc do |value|
76-
if value
77-
begin
78-
ORIGINAL_FACTER = Object.const_get(:Facter)
79-
Object.send(:remove_const, :Facter)
80-
require 'facter-ng'
81-
rescue LoadError
82-
Object.const_set(:Facter, ORIGINAL_FACTER)
83-
raise ArgumentError, 'facter-ng could not be loaded'
84-
end
85-
end
86-
end
87-
}
88-
)
89-
90-
define_settings(:main,
80+
if value
81+
begin
82+
original_facter = Object.const_get(:Facter)
83+
Object.send(:remove_const, :Facter)
84+
require 'facter-ng'
85+
rescue LoadError
86+
Object.const_set(:Facter, original_facter)
87+
raise ArgumentError, 'facter-ng could not be loaded'
88+
end
89+
end
90+
end
91+
},
9192
:confdir => {
9293
:default => nil,
9394
:type => :directory,
@@ -124,7 +125,7 @@ def self.default_vendormoduledir
124125
}
125126
)
126127

127-
define_settings(:main,
128+
settings.define_settings(:main,
128129
:logdir => {
129130
:default => nil,
130131
:type => :directory,
@@ -228,7 +229,7 @@ def self.default_vendormoduledir
228229
}
229230
)
230231

231-
define_settings(:main,
232+
settings.define_settings(:main,
232233
:priority => {
233234
:default => nil,
234235
:type => :priority,
@@ -551,12 +552,12 @@ def self.default_vendormoduledir
551552
:hiera_config => {
552553
:default => lambda do
553554
config = nil
554-
codedir = Puppet.settings[:codedir]
555+
codedir = settings[:codedir]
555556
if codedir.is_a?(String)
556557
config = File.expand_path(File.join(codedir, 'hiera.yaml'))
557558
config = nil unless Puppet::FileSystem.exist?(config)
558559
end
559-
config = File.expand_path(File.join(Puppet.settings[:confdir], 'hiera.yaml')) if config.nil?
560+
config = File.expand_path(File.join(settings[:confdir], 'hiera.yaml')) if config.nil?
560561
config
561562
end,
562563
:desc => "The hiera configuration file. Puppet only reads this file on startup, so you must restart the puppet master every time you edit it.",
@@ -620,7 +621,7 @@ def self.default_vendormoduledir
620621
:http_proxy_password =>{
621622
:default => "none",
622623
:hook => proc do |value|
623-
if Puppet.settings[:http_proxy_password] =~ /[@!# \/]/
624+
if settings[:http_proxy_password] =~ /[@!# \/]/
624625
raise "Passwords set in the http_proxy_password setting must be valid as part of a URL, and any reserved characters must be URL-encoded. We received: #{value}"
625626
end
626627
end,
@@ -764,7 +765,7 @@ def self.default_vendormoduledir
764765
}
765766
)
766767

767-
Puppet.define_settings(:module_tool,
768+
settings.define_settings(:module_tool,
768769
:module_repository => {
769770
:default => 'https://forgeapi.puppet.com',
770771
:desc => "The module repository",
@@ -783,7 +784,7 @@ def self.default_vendormoduledir
783784
}
784785
)
785786

786-
Puppet.define_settings(
787+
settings.define_settings(
787788
:main,
788789

789790
# We have to downcase the fqdn, because the current ssl stuff (as opposed to in master) doesn't have good facilities for
@@ -1094,7 +1095,7 @@ def self.default_vendormoduledir
10941095
}
10951096
)
10961097

1097-
define_settings(
1098+
settings.define_settings(
10981099
:ca,
10991100
:ca_name => {
11001101
:default => "Puppet CA: $certname",
@@ -1212,7 +1213,7 @@ def self.default_vendormoduledir
12121213

12131214
# Define the config default.
12141215

1215-
define_settings(:application,
1216+
settings.define_settings(:application,
12161217
:config_file_name => {
12171218
:type => :string,
12181219
:default => Puppet::Settings.default_config_file_name,
@@ -1237,7 +1238,7 @@ def self.default_vendormoduledir
12371238
},
12381239
)
12391240

1240-
define_settings(:environment,
1241+
settings.define_settings(:environment,
12411242
:manifest => {
12421243
:default => nil,
12431244
:type => :file_or_directory,
@@ -1280,7 +1281,7 @@ def self.default_vendormoduledir
12801281
}
12811282
)
12821283

1283-
define_settings(:master,
1284+
settings.define_settings(:master,
12841285
:user => {
12851286
:default => "puppet",
12861287
:desc => "The user Puppet Server will run as. Used to ensure
@@ -1337,13 +1338,23 @@ def self.default_vendormoduledir
13371338
overridden by more specific settings (see `ca_port`, `report_port`).",
13381339
},
13391340
:node_name => {
1340-
:default => "cert",
1341+
:default => 'cert',
1342+
:type => :enum,
1343+
:values => ['cert', 'facter'],
1344+
:deprecated => :completely,
1345+
:hook => proc { |val|
1346+
if val != 'cert'
1347+
Puppet.deprecation_warning("The node_name setting is deprecated and will be removed in a future release.")
1348+
end
1349+
},
13411350
:desc => "How the puppet master determines the client's identity
13421351
and sets the 'hostname', 'fqdn' and 'domain' facts for use in the manifest,
13431352
in particular for determining which 'node' statement applies to the client.
13441353
Possible values are 'cert' (use the subject's CN in the client's
13451354
certificate) and 'facter' (use the hostname that the client
1346-
reported in its facts)",
1355+
reported in its facts).
1356+
1357+
This setting is deprecated, please use explicit fact matching for classification.",
13471358
},
13481359
:bucketdir => {
13491360
:default => "$vardir/bucket",
@@ -1466,14 +1477,23 @@ def self.default_vendormoduledir
14661477
:desc => "Where the fileserver configuration is stored.",
14671478
},
14681479
:strict_hostname_checking => {
1469-
:default => false,
1480+
:default => true,
1481+
:type => :boolean,
14701482
:desc => "Whether to only search for the complete
1471-
hostname as it is in the certificate when searching for node information
1472-
in the catalogs.",
1483+
hostname as it is in the certificate when searching for node information
1484+
in the catalogs or to match dot delimited segments of the cert's certname
1485+
and the hostname, fqdn, and/or domain facts.
1486+
1487+
This setting is deprecated and will be removed in a future release.",
1488+
:hook => proc { |val|
1489+
if val != true
1490+
Puppet.deprecation_warning("Setting strict_hostname_checking to false is deprecated and will be removed in a future release. Please use regular expressions in your node declarations or explicit fact matching for classification (though be warned that fact based classification may be considered insecure).")
1491+
end
1492+
}
14731493
}
14741494
)
14751495

1476-
define_settings(:device,
1496+
settings.define_settings(:device,
14771497
:devicedir => {
14781498
:default => "$vardir/devices",
14791499
:type => :directory,
@@ -1488,7 +1508,7 @@ def self.default_vendormoduledir
14881508
}
14891509
)
14901510

1491-
define_settings(:agent,
1511+
settings.define_settings(:agent,
14921512
:node_name_value => {
14931513
:default => "$certname",
14941514
:desc => "The explicit value used for the node name for all requests the agent
@@ -1841,7 +1861,7 @@ def self.default_vendormoduledir
18411861

18421862
# Plugin information.
18431863

1844-
define_settings(
1864+
settings.define_settings(
18451865
:main,
18461866
:plugindest => {
18471867
:type => :directory,
@@ -1884,7 +1904,7 @@ def self.default_vendormoduledir
18841904

18851905
# Central fact information.
18861906

1887-
define_settings(
1907+
settings.define_settings(
18881908
:main,
18891909
:factpath => {
18901910
:type => :path,
@@ -1901,7 +1921,7 @@ def self.default_vendormoduledir
19011921
}
19021922
)
19031923

1904-
define_settings(
1924+
settings.define_settings(
19051925
:transaction,
19061926
:tags => {
19071927
:default => "",
@@ -1929,7 +1949,7 @@ def self.default_vendormoduledir
19291949
}
19301950
)
19311951

1932-
define_settings(
1952+
settings.define_settings(
19331953
:main,
19341954
:external_nodes => {
19351955
:default => "none",
@@ -1954,7 +1974,7 @@ def self.default_vendormoduledir
19541974
}
19551975
)
19561976

1957-
define_settings(
1977+
settings.define_settings(
19581978
:ldap,
19591979
:ldapssl => {
19601980
:default => false,
@@ -2023,7 +2043,7 @@ def self.default_vendormoduledir
20232043
}
20242044
)
20252045

2026-
define_settings(:master,
2046+
settings.define_settings(:master,
20272047
:storeconfigs => {
20282048
:default => false,
20292049
:type => :boolean,
@@ -2041,7 +2061,7 @@ def self.default_vendormoduledir
20412061
require 'puppet/node/facts'
20422062
if value
20432063
Puppet::Resource::Catalog.indirection.set_global_setting(:cache_class, :store_configs)
2044-
Puppet.settings.override_default(:catalog_cache_terminus, :store_configs)
2064+
settings.override_default(:catalog_cache_terminus, :store_configs)
20452065
Puppet::Node::Facts.indirection.set_global_setting(:cache_class, :store_configs)
20462066
Puppet::Resource.indirection.set_global_setting(:terminus_class, :store_configs)
20472067
end
@@ -2056,7 +2076,7 @@ def self.default_vendormoduledir
20562076
}
20572077
)
20582078

2059-
define_settings(:parser,
2079+
settings.define_settings(:parser,
20602080
:max_errors => {
20612081
:default => 10,
20622082
:desc => <<-'EOT'
@@ -2108,7 +2128,7 @@ def self.default_vendormoduledir
21082128
EOT
21092129
}
21102130
)
2111-
define_settings(:puppetdoc,
2131+
settings.define_settings(:puppetdoc,
21122132
:document_all => {
21132133
:default => false,
21142134
:type => :boolean,
@@ -2117,7 +2137,7 @@ def self.default_vendormoduledir
21172137
}
21182138
)
21192139

2120-
define_settings(
2140+
settings.define_settings(
21212141
:main,
21222142
:rich_data => {
21232143
:default => true,
@@ -2134,5 +2154,5 @@ def self.default_vendormoduledir
21342154
EOT
21352155
}
21362156
)
2137-
2157+
end
21382158
end

lib/puppet/network/http/connection.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ def do_request(request, options)
213213
current_request[header] = value
214214
end
215215
when 429, 503
216+
if connection.started?
217+
Puppet.debug("Closing connection for #{current_site}")
218+
connection.finish
219+
end
216220
response = handle_retry_after(current_response)
217221
else
218222
response = current_response

lib/puppet/network/http/nocache_pool.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def with_connection(site, verifier, &block)
1515
begin
1616
yield http
1717
ensure
18+
return unless http.started?
1819
Puppet.debug("Closing connection for #{site}")
1920
http.finish
2021
end

lib/puppet/network/http/pool.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def with_connection(site, verifier, &block)
3333
reuse = false
3434
raise detail
3535
ensure
36-
if reuse
36+
if reuse && http.started?
3737
release(site, verifier, http)
3838
else
3939
close_connection(site, http)
@@ -56,13 +56,17 @@ def pool
5656
end
5757

5858
# Safely close a persistent connection.
59+
# Don't try to close a connection that's already closed.
5960
#
6061
# @api private
6162
def close_connection(site, http)
63+
return false unless http.started?
6264
Puppet.debug("Closing connection for #{site}")
6365
http.finish
66+
true
6467
rescue => detail
6568
Puppet.log_exception(detail, _("Failed to close connection for %{site}: %{detail}") % { site: site, detail: detail })
69+
nil
6670
end
6771

6872
# Borrow and take ownership of a persistent connection. If a new

0 commit comments

Comments
 (0)